Esempio n. 1
0
    /**
     * вывод содержимого точки. При выводе применяются фильтры, которые позволяют вставляться
     * в комментарии (пустой фильтр), как часть комментария (фильтр comment), с текстовой обработкой (wiki)
     * @param $point_name
     * @param string $filters
     * @internal param string $filter
     * @return mixed|string
     */
    static function get($point_name, $filters = '')
    {
        global $preprocessor;
        $s = '';
        if (isset(self::$points[$point_name])) {
            $s = join(self::$points[$point_name], "\r\n");
        }
        foreach (explode('|', $filters) as $filter) {
            $fin_string = '';
            $start_string = '';
            if ($filter == '' || $filter == 'comment') {
                $ss = $preprocessor->obget();
                if (preg_match('~(?:(/\\*+)|(\\s\\*)|(//)|(\\#\\#\\s*)|(<!\\-+))[ \\t]*$~s', $ss, $m)) {
                    if (!empty($m[1])) {
                        // javascript comment
                        $filter = $filter == 'comment' ? 'jscomment' : 'php_comment';
                        $fin_string = '*/';
                        $start_string = '/*';
                    } elseif (!empty($m[2])) {
                        // javascript comment
                        $filter = $filter == 'comment' ? 'jscomment' : 'php_comment';
                    } elseif (!empty($m[3])) {
                        // javascript comment
                        $filter = $filter == 'comment' ? 'everyline_comment' : 'line_comment';
                    } elseif (!empty($m[4])) {
                        $filter = $filter == 'comment' ? 'tplcomment' : 'line_comment';
                    } elseif (!empty($m[5])) {
                        $filter = $filter == 'comment' ? 'tplcomment' : 'line_comment';
                        $fin_string = ' -->';
                        $start_string = '<!-- ';
                    }
                }
                preprocessor::log(4, 'point: ' . $point_name . ' filter :"' . $filter . '"' . "\n");
            }
            switch ($filter) {
                case 'wiki-txt':
                    include_once "wiki.ext.php";
                    $s = iconv('UTF-8', 'CP1251//IGNORE', $s);
                    $s = wiki_parcer::convert($s, 'txt');
                    break;
                case 'markdown-html':
                    $dir = dirname(__FILE__);
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/markdown.php';
                    $s = Markdown($s);
                    break;
                case 'mark-txt':
                    $dir = dirname(__FILE__);
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/MlObject.php';
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/markdown2ml.php';
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/ml2text.php';
                    $reader = new reader_MARKDOWN();
                    $writer = new writer_Text();
                    $s = $writer->writeText($reader->parseMarkdown($s));
                    break;
                case 'markdown-txt':
                    $dir = dirname(__FILE__);
                    //return 'xxx';
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/MlObject.php';
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/html2ml.php';
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/ml2text.php';
                    include_once $dir . DIRECTORY_SEPARATOR . 'markdown.filter/markdown.php';
                    $txt = '';
                    // try{
                    $reader = new reader_HTML();
                    $writer = new writer_Text();
                    $html = Markdown($s);
                    $ml = $reader->parseHtml($html);
                    $txt = $writer->writeText($ml);
                    // } catch (Exception $e){
                    //     echo($e->getMessage());
                    // }
                    $s = $txt;
                    break;
                case 'wiki-html':
                    include_once "wiki.ext.php";
                    $s = wiki_parcer::convert($s, 'html');
                    break;
                case 'line_comment':
                    // перед строкой стоит строковый комменарий - выводим с новой строки
                    $s = ' ---- point::' . $point_name . " ----" . (empty($fin_string) ? '' : ' ' . $fin_string) . "\r\n" . $s . "\r\n" . $start_string;
                    break;
                case 'everyline_comment':
                    // каждая строка начинается с комментария //
                    $s = trim(preg_replace(array('/\\n/'), array("\n// "), $s)) . "\r\n";
                    break;
                case 'tplcomment':
                    // каждая строка начинается с комментария ##
                    $s = trim(preg_replace(array('/\\n/'), array("\n## "), $s)) . "\r\n";
                    break;
                case 'jscomment':
                    $s = trim(preg_replace(array('/\\n/'), array("\n * "), $s)) . "\r\n";
                    break;
                case 'php_comment':
                    // выводим php код в окружении закрывающего - открывающего комментария
                    $s = ' --- point::' . $point_name . " --- " . $fin_string . '
' . $s . '
' . $start_string;
                    break;
                case 'html2js':
                    // выводим html для вставки в изображение строки с двойными кавычками.
                    // $scripts
                    // коррекция NL
                    $s = str_replace(array("\r\n", "\r"), array("\n", "\n"), $s);
                    // чистим шаблонные вставки
                    // чистим скрипты
                    $start = self::$curplaceloder;
                    $s = preg_replace_callback('#(<script[^>]*>)(.*?)(</script[^>]*>)#is', array('POINT', '_replace'), $s);
                    for (; $start < self::$curplaceloder; $start++) {
                        self::$placeholder[$start] = preg_replace_callback('#@(\\d+)@#', array('POINT', '_return'), preg_replace(array('#//.*$#m', '#/\\*.*?\\*/#s', "/\n/", '/"/', '/\\s+/', '#\\s*(\\\\n\\s*)+#'), array("", "", '\\n', '\\"', ' ', '\\n'), self::$placeholder[$start]));
                    }
                    //стили
                    $start = self::$curplaceloder;
                    $s = preg_replace_callback('#(<style[^>]*>)(.*?)(</style[^>]*>)#is', array('POINT', '_replace'), $s);
                    for (; $start < self::$curplaceloder; $start++) {
                        self::$placeholder[$start] = preg_replace_callback('#@(\\d+)@#', array('POINT', '_return'), preg_replace('#\\s+#', " ", preg_replace('#/\\*.*?\\*/#s', "", self::$placeholder[$start])));
                    }
                    // условные комментарии
                    $s = preg_replace_callback('#(<!--\\[)(.*?)(\\]-->)#is', array('POINT', '_replace'), $s);
                    // пробелы
                    $s = preg_replace(array('/<!--.*?-->/s', '/"/', '/\\\\/', '/\\s+/', '#\\s*(<|</)(body|div|br|script|style|option|dd|dt|dl|iframe)([^<]*>)\\s*#is'), array('', '\\"', '\\\\', ' ', '\\1\\2\\3'), $s);
                    $s = preg_replace_callback('#@(\\d+)@#', array('POINT', '_return'), $s);
                    break;
                case 'tplcompress':
                    // выводим html для вставки в изображение строки с двойными кавычками.
                    // $scripts
                    // коррекция NL
                    $s = str_replace(array("\r\n", "\r"), array("\n", "\n"), $s);
                    // чистим шаблонные вставки
                    // $start = self::$curplaceloder;
                    $s = preg_replace_callback('~^##.*?\\n~im', array('POINT', '_replace1'), $s);
                    $s = preg_replace_callback('~{{.*?}}|{%.*?%}|{#.*?#}~is', array('POINT', '_replace1'), $s);
                    // echo $s;
                    // условные комментарии
                    $s = preg_replace_callback('#(<!--\\[)(.*?)(\\]-->)#is', array('POINT', '_replace'), $s);
                    // чистим скрипты
                    $start = self::$curplaceloder;
                    $s = preg_replace_callback('#(<script[^>]*>)(.*?)(</script[^>]*>)#is', array('POINT', '_replace'), $s);
                    for (; $start < self::$curplaceloder; $start++) {
                        self::$placeholder[$start] = preg_replace_callback('#@(\\d+)@#', array('POINT', '_return'), self::filter(self::$placeholder[$start], 'jscompress'));
                    }
                    //стили
                    $start = self::$curplaceloder;
                    $s = preg_replace_callback('#(<style[^>]*>)(.*?)(</style[^>]*>)#is', array('POINT', '_replace'), $s);
                    for (; $start < self::$curplaceloder; $start++) {
                        self::$placeholder[$start] = preg_replace_callback('#@(\\d+)@#', array('POINT', '_return'), self::filter(self::$placeholder[$start], 'csscompress'));
                    }
                    // пробелы
                    $s = self::filter($s, 'htmlcompress');
                    $s = preg_replace_callback('#@(\\d+)@#', array('POINT', '_return'), $s);
                    break;
                case 'css2js':
                    // выводим css для вставки в изображение строки с двойными кавычками.
                    $s = self::filter(self::filter($s, 'csscompress'), '2js');
                    break;
                default:
                    $s = self::filter($s, $filter);
            }
        }
        return $s;
    }