Esempio n. 1
0
 public static function tokenDefault(&$token, &$text)
 {
     if ($token['type'] == 'text') {
         $text .= $token['data'];
     } else {
         if ($token['type'] == 'tag' && strtoupper($token['name']) == 'COMPONENT') {
             $name = $token['data']['name'];
             $component = SystemComponent::getComponentByName($name);
             if ($component !== null) {
                 $text .= '<?php $data = ' . var_export($token['data'], true) . '; $flags = ' . var_export($token['flags'], true) . '; ?>';
                 // Sustituyo esto:
                 //$text .= $component->getPHP();
                 // Por esto otro:
                 $html = $component->getPHP();
                 $ctokens = TreeScript::getParse($html);
                 $ctext = '';
                 foreach ($ctokens as $ctoken) {
                     RenderToken::tokenDefault($ctoken, $ctext);
                 }
                 $text .= $ctext;
                 // FIN
                 ControllerPage::requireComponent($name);
             }
         } else {
             if ($token['type'] == 'tag' && $token['name'] == '') {
                 $text .= '';
             } else {
                 //$text .= '';
             }
         }
     }
 }
Esempio n. 2
0
 private function appendJS($js, $component = null)
 {
     $tokens = TreeScript::getParse($js);
     foreach ($tokens as $token) {
         if ($token['type'] == 'tag' && $token['name'] == 'INCLUDE') {
             $this->requireComponent($token['data']['component']);
         } else {
             if ($token['type'] == 'tag' && $token['name'] == 'AJAX') {
                 if (Router::$language != Config::get('DEFAULT_LANGUAGE')) {
                     $this->js .= '/' . Router::$language;
                 }
                 $this->js .= '/__ajax__/' . $component . '/' . $token['data']['name'];
             } else {
                 if ($token['type'] == 'text') {
                     $this->js .= $token['data'];
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public function setJS($js)
 {
     //Procesar antes el js
     $tokens = TreeScript::getParse($js);
     $code = '';
     foreach ($tokens as $token) {
         if ($token['type'] == 'text') {
             $code .= $token['data'];
         } else {
             if (strtoupper($token['name']) == 'AJAX') {
                 $name = $token['data']['name'];
                 $autogenerate_list_ajax[$name] = '';
                 if (strlen($name)) {
                     if (!in_array($name, $this->getAjaxNames())) {
                         $this->setAjax($name, '<?php print_r($_POST); ?>');
                     }
                 } else {
                     $token['data']['warning'] = 'Missing attribute "name"';
                 }
             }
             $code .= RenderToken::tokenToString($token);
         }
     }
     $this->js = $code;
     return file_put_contents(self::$dir_base . '/' . $this->name . '/index.js', $code);
 }
Esempio n. 4
0
 public static function getParse(&$code, $encoding = 'UTF-8')
 {
     $treescript = new TreeScript($code, $encoding);
     $treescript->parse();
     return $treescript->tokens;
 }
Esempio n. 5
0
    $code = <<<F**K

[[NAME1 attribute:value]]

[[noparse a:b]]

[[NAME1 attribute:value]]

F**K;
    $reference = array(0 => array('type' => 'text', 'data' => "\n"), 1 => array('type' => 'tag', 'data' => array('attribute' => 'value'), 'name' => 'NAME1', 'flags' => array()), 2 => array('type' => 'text', 'data' => "\n\n"), 3 => array('type' => 'noparse', 'data' => array('a' => 'b'), 'name' => 'noparse', 'flags' => array()), 4 => array('type' => 'text', 'data' => "\n\n[[NAME1 attribute:value]]\n"));
    $result = TreeScript::getParse($code);
    var_export($result);
    return recursive_compare($reference, $result);
};
$tests['[[noparse a:b e]]'] = function () {
    echo time();
    $code = <<<F**K

[[NAME1 attribute:value]]

[[noparse a:b e]]

[[NAME1 attribute:value]]

F**K;
    $reference = array(0 => array('type' => 'text', 'data' => "\n"), 1 => array('type' => 'tag', 'data' => array('attribute' => 'value'), 'name' => 'NAME1', 'flags' => array()), 2 => array('type' => 'text', 'data' => "\n\n"), 3 => array('type' => 'noparse', 'data' => array('a' => 'b'), 'name' => 'noparse', 'flags' => array(0 => 'e')), 4 => array('type' => 'text', 'data' => "\n\n[[NAME1 attribute:value]]\n"));
    $result = TreeScript::getParse($code);
    var_export($result);
    return recursive_compare($reference, $result);
};
Test::addFunctions($tests);
Esempio n. 6
0
File: run.php Progetto: fulldump/8
\$id = 35;
\$str = "soy una cadena de texto";
\$lista = array(1,2,3);
\$objeto = new stdClass();
\$objeto->nombre = 'fulanito';
\$objeto->apellido = 'menganito';
?>

[[Blog val="soy un valor" persona=\$objeto id=\$id cadena=\$str lista=\$lista flag1 flag2 flag3]]

// texto de después

HEREDOC;
$output = '';
// var_export(TreeScript::getParse($code));
foreach (TreeScript::getParse($code) as $token) {
    $data = $token['data'];
    switch ($token['type']) {
        case 'text':
            $output .= $data;
            break;
        case 'tag':
            $name = $token['name'];
            $flags = $token['flags'];
            $output .= <<<HEREDOC
<?php function ___{$name}(\$data, \$flag) {
\tprint_r(\$data);
\tprint_r(\$flag);
} ?>

HEREDOC;