Esempio n. 1
0
 /**
  * Run a Tokenizer and Store its results and return the tree.
  * It should build a DOM Tree of the HTML
  *
  * @param   string $data         data to parse.
  * @param    array $options      see options array.
  *
  * @access   public
  * @return   base token (really a dummy token, which contains the tree)
  * @static
  */
 function construct($data, $options = array())
 {
     // local caching!
     $md5 = md5($data);
     if (isset($GLOBALS[__CLASS__]['cache'][$md5])) {
         return $GLOBALS[__CLASS__]['cache'][$md5];
     }
     $t = new HTML_Template_Flexy_Tree();
     $t->options = $t->options + $options;
     require_once 'HTML/Template/Flexy/Token.php';
     $t->tokens = array(new HTML_Template_Flexy_Token());
     $t->tokens[0]->id = 0;
     // process
     if (is_a($r = $t->tokenize($data), 'PEAR_Error')) {
         return $r;
     }
     $t->matchClosers();
     $t->buildChildren(0);
     //new Gtk_VarDump($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]);
     $GLOBALS[__CLASS__]['cache'][$md5] = $t->returnStart();
     return $GLOBALS[__CLASS__]['cache'][$md5];
 }
Esempio n. 2
0
<?php

/* Mini test suite */
require_once 'HTML/Template/Flexy/Tree.php';
function getAll()
{
    // loop through
    $ret = array();
    $dh = opendir(dirname(__FILE__) . '/templates/');
    while (false !== ($file = readdir($dh))) {
        if ($file[0] == '.') {
            continue;
        }
        if (is_dir(dirname(__FILE__) . '/templates/' . $file)) {
            continue;
        }
        $ret[] = $file;
    }
    return $ret;
}
require_once 'System.php';
System::mkdir(dirname(__FILE__) . "/trees");
foreach (getAll() as $file) {
    echo "Building tree for {$file}\n";
    $tree = HTML_Template_Flexy_Tree::construct(file_get_contents(dirname(__FILE__) . '/templates/' . $file));
    $fh = fopen(dirname(__FILE__) . "/trees/{$file}.tree", 'w');
    fwrite($fh, print_r($tree, true));
    fclose($fh);
}
// basic options..