Esempio n. 1
0
    function testXmlReader()
    {
        $config = <<<XML
<config>
    <file dir="test/test1">*.*</file>
</config>
XML;
        $class = new ReflectionClass('preprocessor');
        $opt = $class->getProperty('store');
        $opt->setAccessible(true);
        $this->createTestFiles(4, 'test/test1');
        $preprocessor = preprocessor::instance();
        $preprocessor->xml_read($config);
        $store = $opt->getValue($preprocessor);
        $this->assertEquals(count($store), 4);
        $config = <<<XML1
<config>
    <remove>test1\\*1.tmp</remove>
</config>
XML1;
        $preprocessor->xml_read($config);
        $store = $opt->getValue($preprocessor);
        $this->assertEquals(count($store), 3);
        $this->removeTestFiles('test/test1');
    }
Esempio n. 2
0
 public function main()
 {
     $this->log('<%=$version%>', Project::MSG_INFO);
     // define a force tag
     $time = false;
     if ($this->force) {
         $xtime = strtotime($this->force);
         if (!$xtime) {
             $time = time();
             if ($this->force != 'force') {
                 $this->log('wrong date "' . $this->force . '"', Project::MSG_WARN);
             }
         } else {
             $time = $xtime;
         }
     }
     $this->preprocessor->cfg_time($time);
     $this->preprocessor->logLevel = $this->logLevel;
     // difine variable definitions
     foreach ($this->parameters as $v) {
         $file = $v->getFile();
         if (@is_readable($file)) {
             foreach (file($file) as $vv) {
                 if (preg_match('/^(?:\\;.*|\\#.*|([^=]+)=(.*))$/', $vv, $mm)) {
                     if (!empty($mm[1])) {
                         $this->preprocessor->export(trim($mm[1]), trim($mm[2]));
                     }
                 }
             }
         } else {
             $this->preprocessor->export($v->getName(), $v->getValue());
         }
     }
     //run it!
     if (!!$this->config) {
         $this->log('making "' . $this->config . '"', Project::MSG_WARN);
         POINT::clear();
         $this->preprocessor->xml_read($this->config);
         $this->preprocessor->process();
     } else {
         if (!empty($this->xconfigs)) {
             $config = '';
             foreach ($this->xconfigs as $v) {
                 $config .= $v->getText();
             }
             $this->log('making "' . $config . '"', Project::MSG_WARN);
             POINT::clear();
             $this->preprocessor->xml_read($config);
             $this->preprocessor->process();
         }
     }
 }
Esempio n. 3
0
<?php

/**
 * to call preprocesor - type   php -f preprocessor.php file_name
 * 
 * <%=point('hat','jscomment');%>
 */
include_once "../preprocessor.class.php";
include_once "../point.ext.php";
$paths = preprocessor::instance();
$par = array("/Dtarget=debug", "/Ddst=build", "config.xml");
for ($i = 1; $i < count($par); $i++) {
    if (preg_match('/^\\/D(\\w+)\\=(\\S+)$/', $par[$i], $m)) {
        $paths->export($m[1], $m[2]);
    } else {
        if (is_file($par[$i])) {
            $arg1 = pathinfo($par[$i]);
            if ($arg1['extension'] == 'xml') {
                $paths->xml_read($par[$i]);
            } else {
                $xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<config>
\t<files dstdir="build">
\t\t<file>{$par[$i]}</file>
\t</files>
</config>
XML;
                $paths->xml_read($xmlstr);
            }
        } else {
Esempio n. 4
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;
    }
Esempio n. 5
0
*/
$dir = dirname(__FILE__);
include_once $dir . "/preprocessor.class.php";
include_once $dir . "/point.ext.php";
date_default_timezone_set('Europe/Moscow');
/**
 * @param $p
 * @param $def
 * @return mixed
 * @tutorial preprocessor.pkg
 */
function pps(&$p, $def)
{
    return empty($p) ? $def : $p;
}
$preprocessor = preprocessor::instance();
foreach ($_ENV as $k => $v) {
    $preprocessor->export('env_' . $k, $v);
}
echo '<%=$version%>

';
$arg = '';
for ($i = 1; $i < $argc; $i++) {
    $arg .= ' ' . $argv[$i];
}
//echo $arg;
while (!empty($arg)) {
    //$preprocessor->debug($arg);
    if (preg_match('#^/force(?:\\s|\\=\'([^\']+)\')#', $arg, $m)) {
        $time = false;
Esempio n. 6
0
 public static function log($level = -1)
 {
     $preprocessor = preprocessor::instance();
     if ($preprocessor->logLevel < $level) {
         return;
     }
     $na = func_num_args();
     if ($na > 1) {
         for ($i = 1; $i < $na; $i++) {
             $v = func_get_arg($i);
             if (is_array($v)) {
                 $v = print_r($v, true);
             }
             $preprocessor->logs[] = array($level, $v);
         }
     }
     //if($na==0){ print_r($this->logs);}
     if ($preprocessor->obcnt == 0 && count($preprocessor->logs) > 0) {
         foreach ($preprocessor->logs as $v) {
             if (!empty($v[1])) {
                 echo $v[1];
             }
         }
         $preprocessor->logs = array();
     }
 }
Esempio n. 7
0
    /**
     * ловим ошибку - вставка кода в // комментарии
     */
    function testPOINTComment()
    {
        $data = <<<HTML
<?xml version='1.0' standalone='yes'?>
<config>
<files dstdir='tests'>
    <echo name="xx.txt"><![CDATA[
        /*
<% POINT::start('xxx');%>
    it's a text
<% POINT::finish();%>
 */
// <%=POINT::get('xxx');%>

## <%=POINT::get('xxx');%>
/* <%=POINT::get('xxx');%> */
]]></echo>
    </files>
</config>
HTML;
        $result = <<<HTML
//  ---- point::xxx ----
it's a text


##  ---- point::xxx ----
it's a text

/*  --- point::xxx --- */
it's a text
HTML;
        $preprocessor = preprocessor::instance();
        $preprocessor->xml_read($data);
        $preprocessor->process();
        $data = file_get_contents('tests/xx.txt');
        $this->assertEquals($this->nl2nl($result), $this->nl2nl($data));
        POINT::clear();
        unlink('tests/xx.txt');
    }