Beispiel #1
0
function handleIncludes($content = 'index.html')
{
    global $doc;
    require 'classes.php';
    $Cdom = new DOMParser($content, array('request' => 'include'));
    $includes = $Cdom->get('include', array('src', 'parts', 'id'));
    session_start();
    $_SESSION['cookie'];
    debug('in handleIncludes');
    while ($includes) {
        foreach ($includes as $include) {
            $Tdom = new DOMParser(pick($doc . $include['src'], 'parts.php'), array('request' => 'include'));
            if ($include['parts']) {
                foreach (explode(',', $include['parts']) as $part) {
                    $part = trim($part);
                    $rp = $Tdom->get("#{$part}", 'outerHTML', 'string');
                    $replaces = $replaces . $rp;
                }
                $Tdom = new DOMParser($replaces);
            }
            $cookie[$include['src']][pick($include['parts'], 'html')][] = '#' . $include['id'];
            //adapt to allow for more than one instance calling the same parts.
            //debug($Cdom->get('include[src='.$include['src'].']>[id]'), 'include ids');
            foreach ($Cdom->get('include[src=' . $include['src'] . ']>[id]', 'id', 'array', 'outerHTML') as $el) {
                //debug($el, 'el');
                $Tdom->set('#' . $el['id'], $el['content'], 'outerHTML');
                $cookie[$include['src']][pick($include['parts'], 'html')][] = '#' . $el['id'];
            }
            $Cdom->set('include[src=' . $include['src'] . ']', $Tdom->set(), 'outerHTML', 'queue');
            if (++$catch > 500) {
                echo "your loopy - Infinite loop alert #1!";
                break;
            }
        }
        $Cdom->set();
        $includes = $Cdom->get('include', array('src', 'parts'));
        if (++$catch > 500) {
            echo "You're loopy! - It is looping on line 54, as there is always another 'include tag'";
            break;
        }
        //debug('in while');
    }
    if ($cookie) {
        $_SESSION['cookie'] = $cookie;
    }
    //else echo "no cookie here";
    #$scripts =  array('php'=>'','css'=>'','head'=>'','foot'=>'');//debug($funcs['edit'], 'funcs[edit]');//debug($scripts, 'scripts, after first merge');
    #if($_GET['edit']) $scripts =array_merge_recursive($scripts, $funcs['edit']);
    $scripts = array();
    foreach ($_GET as $get => $truth) {
        //flags should be merged into same array
        if ($truth && ($loc = $funcs[$get]['url'])) {
            $funcs[$get][$loc] = $funcs[$get]['js'];
            $scripts = array_merge_recursive($scripts, $funcs[$get]);
            $scriptname .= $get;
        }
    }
    foreach ((array) $Cdom->get('[class^~=sr_]', array('class', 'id')) as $el) {
        $cs = explode('sr_', $el['class']);
        array_shift($cs);
        foreach ($cs as $c) {
            $c = array_shift(explode(' ', $c));
            if (!$funcs[$c]) {
                $funcs[$c] = array('php' => "{$c}/index.php", 'css' => "{$c}/styles.css", 'head' => "", 'foot' => array("{$c}/scripts.js", "{$c}/{$c}.js"));
            }
            $scripts = array_merge_recursive($scripts, $funcs[$c]);
            $scriptname .= $c;
        }
    }
    //debug($scripts, 'scripts');
    //debug($_GET, 'get');
    #if(file_exists($doc."siteroller/cache/$type/$scriptname.$extension")){}else{
    unset($scripts['js'], $scripts['url']);
    foreach ($scripts as $key => $val) {
        $scripts[$key] = array_unique((array) $val);
    }
    //debug($scripts, 'scripts');
    foreach ((array) array_shift($scripts) as $php) {
        if ($php) {
            include $doc . "siteroller/classes/{$php}";
        }
    }
    foreach ($scripts as $type => $script) {
        $data = '';
        $extension = $type == 'head' || $type == 'foot' ? 'js' : $type;
        foreach ($script as $add) {
            $data .= file_get_contents($doc . "siteroller/classes/{$add}");
        }
        file_put_contents($doc . "siteroller/cache/{$type}/{$scriptname}.{$extension}", $data);
        //debug($type, '$type');//debug($script, '$script');//debug($data, '$data');
    }
    #}
    if (!$Cdom->get('head')) {
    }
    //add head if it doesn't exist;
    $Cdom->set('head', 'bottom', "\n\t\t<script type='text/javascript' src='siteroller/cache/head/{$scriptname}.js'></script>\n\t\t<link rel='stylesheet' type='text/css' href='siteroller/cache/css/{$scriptname}.css'/> \n\t");
    //debug($Cdom->set('body', 'pickles'), 'body');
    $Cdom->set('body', 'bottom', "<div class='srRemove'><script type='text/javascript' src='siteroller/cache/foot/{$scriptname}.js'></script></div>");
    //ob_start('ob_gzhandler');
    echo $Cdom->set();
    //ob_end_flush();
}
Beispiel #2
0
 function template($content, $src)
 {
     $cont = new DOMParser($content, $opts);
     foreach ($cont->get("include[src='{$src}']>div[id]", array('properties' => 'id', 'action' => 'run')) as $item) {
         $this->set('#' . $item['id'], $item['content'], 'queue');
     }
     return $this->set();
 }