299 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			299 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						|
 | 
						|
    namespace WMarkDown\Modules;
 | 
						|
 | 
						|
    class CustomParameters extends \WMarkDown\Abstracts\Modules{
 | 
						|
 | 
						|
        private $menu = '';
 | 
						|
        private $title = '';
 | 
						|
        private $order = "";
 | 
						|
 | 
						|
        public function get_next_position($string){
 | 
						|
 | 
						|
            if(
 | 
						|
                $this->more &&
 | 
						|
                $this->from < 0 &&
 | 
						|
                $this->more = preg_match('/\[\[(header_level|html_data|post_data|data_dictionary|wdictionaries|wmonitor|ignore|links_groups?|i|icon|\!|wdoc|plain) ?(([^\]"\']+|[\r\n]+|"(([^\\\\"]+|\\\\(.|[\r\n]))*)"|\'(([^\\\\\']+|\\\\(.|[\r\n]))*)\'|\]([^\]]))+)\]\]/', $string, $this->matches, PREG_OFFSET_CAPTURE)
 | 
						|
            )
 | 
						|
                $this->from = $this->matches[0][1];
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        public function process($string, $modules, $level){
 | 
						|
 | 
						|
            $this->order = $this->matches[1][0];
 | 
						|
 | 
						|
            switch($key = strtolower($this->matches[1][0])){
 | 
						|
                case "header_level":
 | 
						|
                    try{
 | 
						|
                        $symbol = $this->matches[2][0][0];
 | 
						|
                        $level = $this->matches[2][0];
 | 
						|
                        if($string == "[[header_level 2]]")
 | 
						|
                            print_r([$symbol, $level]);
 | 
						|
                        $modules->menu_level = strpos("+-", $symbol) !== false ? $modules->menu_level + intval(substr($level, 1)) * ($symbol == "-" ? -1 : 1) : intval($level);
 | 
						|
                    }catch(\Exception $exception){};
 | 
						|
                    $this->html = '';
 | 
						|
                break;
 | 
						|
                case "html_data":
 | 
						|
                    try{
 | 
						|
                        $modules->html_data = json_decode(\WMarkDown::string_variables($this->matches[2][0], [
 | 
						|
                            "now" => (new \DateTime())->format('Ymd')
 | 
						|
                        ]), true);
 | 
						|
                    }catch(\Exception $exception){};
 | 
						|
                    $this->html = '';
 | 
						|
                break;
 | 
						|
                case "post_data":
 | 
						|
 | 
						|
                    $this->html = '';
 | 
						|
 | 
						|
                    try{
 | 
						|
 | 
						|
                        $data = json_decode(\WMarkDown::string_variables($this->matches[2][0], [
 | 
						|
                            "now" => (new \DateTime())->format('Ymd')
 | 
						|
                        ]), true);
 | 
						|
                        if(!isset($data["since"]))
 | 
						|
                            $data["since"] = (new \DateTime())->format('Ymd');
 | 
						|
                        foreach(["since", "version"] as $key)
 | 
						|
                            if(isset($data[$key]))
 | 
						|
                                $data[$key] = preg_replace('/^(\d{4})(\d{2})(\d{2})$/', "$1/$2/$3", $data[$key]);
 | 
						|
                        if(!isset($data["version"]))
 | 
						|
                            $data["version"] = $data["since"];
 | 
						|
                        if(!isset($data["author"]))
 | 
						|
                            $data["author"] = "Anonymous";
 | 
						|
                        $i18n_data = base64_encode(json_encode($data));
 | 
						|
 | 
						|
                        $this->html = \WMarkDown::string_variables(('
 | 
						|
                            <div class="header-file-note" data-i18n="post_created_by" data-i18n-variables="' . $i18n_data . '">
 | 
						|
                                Por {author}. Creado a fecha {since}. Última modificación a fecha {version}.
 | 
						|
                            </div>
 | 
						|
                        '), $data);
 | 
						|
 | 
						|
                    }catch(\Exception $exception){};
 | 
						|
                break;
 | 
						|
                case "data_dictionary":
 | 
						|
                    try{
 | 
						|
                        $this->html = json_decode($this->matches[2][0], true);
 | 
						|
                    }catch(\Exception $exception){};
 | 
						|
                    $this->html = $this->html ? '<input type="hidden" class="data-dictionary" data-json="' . base64_encode(preg_replace('/[\s\t]+|[\r\n]+|("(([^\\\\"]+|\\\\(.|[\r\n]))*)"|\'(([^\\\\\']+|\\\\(.|[\r\n]))*)\')/', "$1", $this->matches[2][0])) . '" />' : '';
 | 
						|
                break;
 | 
						|
                case "wdictionaries":
 | 
						|
 | 
						|
                    $this->html = '';
 | 
						|
 | 
						|
                    if(
 | 
						|
                        $this->matches[2][0] &&
 | 
						|
                        preg_match('/^([^"\' ]+|"(([^\\\\"]+|\\\\.)*)"|\'(([^\\\\\']+|\\\\.)*)\')((.+|[\r\n]+)+)?$/', $this->matches[2][0], $matches) &&
 | 
						|
                        count($matches) >= 6 &&
 | 
						|
                        !empty($files = preg_split('/([\s\t]+|[\r\n]+)+/', trim($matches[6])))
 | 
						|
                    )
 | 
						|
                        $this->html = $files ? ('
 | 
						|
                            ' . \WMarkDown\Modules::format($this->wmarkdown, '# ' . $matches[$matches[4] ? 4 : ($matches[2] ? 2 : 1)], ["wdictionaries", "paragraph"], $modules)["content"] . '
 | 
						|
                            <input type="hidden" class="wdictionary" data-json="' . base64_encode(json_encode($files)) . '" data-status="unloaded" />
 | 
						|
                        ') : '';
 | 
						|
 | 
						|
                break;
 | 
						|
                case "wmonitor":
 | 
						|
                    $this->html = $this->matches[2][0] ? '<span data-wmonitor="' . $this->matches[2][0] . '" data-status="unloaded">WMonitor</span>' : '';
 | 
						|
                break;
 | 
						|
                case "ignore":
 | 
						|
                    $this->html = '<span data-ignore="true">' . $this->matches[2][0] . '</span>';
 | 
						|
                break;
 | 
						|
                case "links_group":
 | 
						|
                case "links_groups":
 | 
						|
 | 
						|
                    $html = '<div class="links-group">';
 | 
						|
 | 
						|
                    try{
 | 
						|
                        if($json = json_decode($this->matches[2][0], true)){
 | 
						|
                            foreach($json as $link)
 | 
						|
                                $html .= ('
 | 
						|
                                    <a href="' . $link["link"] . '" class="multimedia-box links-group" target="_' . (isset($link["self"]) && $link["self"] ? "self" : "blank") . '" class="links-group-item" title="' . ($text = isset($link["text"]) ? $link["text"] : "") . '">
 | 
						|
                                        <span data-status="unloaded">
 | 
						|
                                            <img data-src="' . base64_encode(json_encode($link["images"])) . '" data-i="0" onerror="wmarkdown.multimedia.image_try_next(this, event);" />
 | 
						|
                                            <span class="image-style"></span>
 | 
						|
                                        </span>
 | 
						|
                                        <span class="text">' . $text . '</span>
 | 
						|
                                    </a>
 | 
						|
                                ');
 | 
						|
                        };
 | 
						|
                    }catch(\Exception $exception){};
 | 
						|
 | 
						|
                    $this->html = $html . '</div>';
 | 
						|
 | 
						|
                break;
 | 
						|
                case "i":
 | 
						|
                case "!":
 | 
						|
                case "icon":
 | 
						|
                    $this->html = preg_match('/^([^ ]+)( ((.+|[\r\n]+)+)?)?/', $this->matches[2][0], $matches) ? (
 | 
						|
                        '<span class="special-text-i" data-i18n="' . $matches[1] . '" data-i18n-without="true" title="' . $matches[1] . '">' .
 | 
						|
                            '<span data-icon="' . $matches[1] . '"></span>' .
 | 
						|
                            (empty($matches[3]) ? '' : '<span class="text">' . $matches[3] . '</span>') .
 | 
						|
                        '</span>'
 | 
						|
                    ) : $this->matches[0][0];
 | 
						|
                break;
 | 
						|
                case "wdoc":
 | 
						|
 | 
						|
                    $html = '';
 | 
						|
                    $name = 'UNKNOWN';
 | 
						|
                    $description = '';
 | 
						|
                    $attributes = [[]];
 | 
						|
                    $return = [null];
 | 
						|
                    $data = [];
 | 
						|
                    $language = "unknown";
 | 
						|
                    $deprecated = false;
 | 
						|
 | 
						|
                    preg_replace_callback('/([\@\#]([^\s\t\r\n]+)([ \t]+([^\s\t\r\n]+)([ \t]+([^\s\t\r\n]+)([ \t]+([^\r\n]*))?)?)?|[^\@\r\n][^\r\n]+)/', function($values) use(
 | 
						|
                        &$name,
 | 
						|
                        &$description,
 | 
						|
                        &$attributes,
 | 
						|
                        &$return,
 | 
						|
                        &$language,
 | 
						|
                        &$deprecated,
 | 
						|
                        &$data
 | 
						|
                    ){
 | 
						|
                        switch($values[0][0]){
 | 
						|
                            case "@":
 | 
						|
                                switch(strtolower($values[2])){
 | 
						|
                                    case "lang":
 | 
						|
                                        $language = $values[4];
 | 
						|
                                        $data[] = ["language", $values[4]];
 | 
						|
                                    break;
 | 
						|
                                    case "deprecated":
 | 
						|
                                        $deprecated = true;
 | 
						|
                                        $data[] = ["deprecated", true];
 | 
						|
                                    break;
 | 
						|
                                    case "name":
 | 
						|
                                        $name = $values[4];
 | 
						|
                                        $data[] = ["name", $values[4]];
 | 
						|
                                    break;
 | 
						|
                                    case "overload":
 | 
						|
                                        $attributes[] = [];
 | 
						|
                                        $return[] = null;
 | 
						|
                                    break;
 | 
						|
                                    case "see":
 | 
						|
                                        // Mirar porque algunos SEE salen mal.
 | 
						|
                                        count($values) >= 5 && ($data[] = [$values[2], '<a href="#' . $values[4] . '">' . $values[4] . '</a>']);
 | 
						|
                                    break;
 | 
						|
                                    default:
 | 
						|
                                        $data[] = [$values[2], count($values) > 3 ? $values[4] : null];
 | 
						|
                                    break;
 | 
						|
                                };
 | 
						|
                            break;
 | 
						|
                            case "#":
 | 
						|
                                switch(strtolower($values[2])){
 | 
						|
                                    case "return":
 | 
						|
                                        $return[count($attributes) - 1] = [$values[4], count($values) > 8 && $values[8] ? $values[8] : ''];
 | 
						|
                                    break;
 | 
						|
                                    default:
 | 
						|
 | 
						|
                                        $l = count($values);
 | 
						|
 | 
						|
                                        if($l > 5)
 | 
						|
                                            $attributes[count($attributes) - 1][] = [
 | 
						|
                                                $values[2],
 | 
						|
                                                $values[4],
 | 
						|
                                                $values[6],
 | 
						|
                                                $l > 8 && $values[8] ? $values[8] : ''
 | 
						|
                                            ];
 | 
						|
                                        else
 | 
						|
                                            $data[] = [$values[2], $l > 3 ? $values[4] : null];
 | 
						|
                                    break;
 | 
						|
                                };
 | 
						|
                            break;
 | 
						|
                            default:
 | 
						|
                                $description .= $values[0] . " ";
 | 
						|
                            break;
 | 
						|
                        };
 | 
						|
                    }, $this->matches[2][0]);
 | 
						|
 | 
						|
                    $l = count($attributes);
 | 
						|
                    $data_html = '';
 | 
						|
 | 
						|
                    foreach($data as $value){
 | 
						|
                        $is_bool = is_bool($value[1]) || $value[1] === null;
 | 
						|
                        if(is_string($value[1]))
 | 
						|
                            $value[1] = explode(",", $value[1]);
 | 
						|
                        $data_html .= (
 | 
						|
                            '<li data-name="' . $value[0] . '" data-hide="' . (!$is_bool || $value[1] ? "true" : "false") . '" data-ignore="true">' .
 | 
						|
                                '<span class="name">' . $value[0] . '</span>' .
 | 
						|
                                '<span class="value" data-with-value="' . ($is_bool ? "false" : "true") . '">' . (is_array($value[1]) ? '<span>' . implode('</span><span>', $value[1]) . '</span>' : $value[1]) . '</span>' .
 | 
						|
                            '</li>'
 | 
						|
                        );
 | 
						|
                    };
 | 
						|
 | 
						|
                    for($i = 0; $i < $l; $i ++){
 | 
						|
 | 
						|
                        $overload = $attributes[$i];
 | 
						|
                        $attributes_html = '';
 | 
						|
                        $return_type = $return[$i] ? $return[$i][0] : 'void';
 | 
						|
 | 
						|
                        foreach($attributes[$i] as $attribute)
 | 
						|
                            $attributes_html .= (
 | 
						|
                                '<span class="attribute" data-status="' . strtolower($attribute[2]) . '">' .
 | 
						|
                                    '<span class="attribute-name" data-ignore="true">' . $attribute[0] . '</span>' .
 | 
						|
                                    '<span class="attribute-type"><span>' . preg_replace('/,/', '</span><span>', $attribute[1] == "-" ? "ANY" : $attribute[1]) . '</span></span>' .
 | 
						|
                                    '<span class="attribute-status">' . $attribute[2] . '</span>' .
 | 
						|
                                    '<span class="attribute-description">' . ($attribute[3] ? $attribute[3] : '') . '</span>' .
 | 
						|
                                '</span>'
 | 
						|
                            );
 | 
						|
                        $attributes_html .= (
 | 
						|
                            '<span class="return">' .
 | 
						|
                                '<span class="return-text">return</span>' .
 | 
						|
                                '<span class="return-type">' . ($return_type == "-" ? "ANY" : $return_type) . '</span>' .
 | 
						|
                                '<span></span>' .
 | 
						|
                                '<span class="return-description">' . ($return[$i] && $return[$i][1] ? $return[$i][1] : '') . '</span>' .
 | 
						|
                            '</span>'
 | 
						|
                        );
 | 
						|
 | 
						|
                        $html .= (
 | 
						|
                            '<div class="overload">' .
 | 
						|
                                '<div class="structure">' .
 | 
						|
                                    '<span class="return-type">' . ($return_type == "-" ? "ANY" : $return_type) . '</span>' .
 | 
						|
                                    '<span class="name" data-ignore="true">' . $name . '</span>' .
 | 
						|
                                    '<span class="attributes">' . $attributes_html . '</span>' .
 | 
						|
                                '</div>' .
 | 
						|
                                '<div class="attributes-data">' . $attributes_html . '</div>' .
 | 
						|
                            '</div>'
 | 
						|
                        );
 | 
						|
 | 
						|
                    };
 | 
						|
 | 
						|
                    $this->html = (
 | 
						|
                        '<fieldset id="' . $name . '" class="wdoc" data-language="' . strtolower($language) . '" data-deprecated="' . ($deprecated ? 'true' : 'false') . '">' .
 | 
						|
                            '<legend>' .
 | 
						|
                                ($deprecated ? (
 | 
						|
                                    '<span class="deprecated">' .
 | 
						|
                                        '<span data-icon="deprecated"></span>' .
 | 
						|
                                        '<span data-i18n="deprecated">Deprecated</span>' .
 | 
						|
                                    '</span>'
 | 
						|
                                ) : '') .
 | 
						|
                                '<span class="name" data-ignore="true">' . $name . '</span>' .
 | 
						|
                                '<span class="language">' . $language . '</span>' .
 | 
						|
                            '</legend>' .
 | 
						|
                            '<p class="description">' . $description . '</p>' .
 | 
						|
                            $html .
 | 
						|
                            '<ul class="data">' . $data_html . '</ul>' .
 | 
						|
                        '</fieldset>'
 | 
						|
                    );
 | 
						|
 | 
						|
                break;
 | 
						|
                case "plain":
 | 
						|
                    $this->html = $this->matches[2][0];
 | 
						|
                break;
 | 
						|
                default:
 | 
						|
                    $this->html = $this->matches[0][0];
 | 
						|
                break;
 | 
						|
            };
 | 
						|
 | 
						|
            $this->length = strlen($this->matches[0][0]);
 | 
						|
            $this->to = $this->from + $this->length;
 | 
						|
            $this->content = $this->matches[2][0];
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
        public function get_menu(){return "" . $this->menu;}
 | 
						|
        public function get_title(){return "" . $this->title;}
 | 
						|
        public function get_order(){return "" . $this->order;}
 | 
						|
 | 
						|
    };
 |