Beispiel #1
0
function comanche_parser(&$a, $s, $pass = 0)
{
    $matches = array();
    $cnt = preg_match_all("/\\[comment\\](.*?)\\[\\/comment\\]/ism", $s, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            $s = str_replace($mtch[0], '', $s);
        }
    }
    if ($pass == 0) {
        $cnt = preg_match("/\\[layout\\](.*?)\\[\\/layout\\]/ism", $s, $matches);
        if ($cnt) {
            $a->page['template'] = trim($matches[1]);
        }
        $cnt = preg_match("/\\[template=(.*?)\\](.*?)\\[\\/template\\]/ism", $s, $matches);
        if ($cnt) {
            $a->page['template'] = trim($matches[2]);
            $a->page['template_style'] = trim($matches[2]) . '_' . $matches[1];
        }
        $cnt = preg_match("/\\[template\\](.*?)\\[\\/template\\]/ism", $s, $matches);
        if ($cnt) {
            $a->page['template'] = trim($matches[1]);
        }
        $cnt = preg_match("/\\[theme=(.*?)\\](.*?)\\[\\/theme\\]/ism", $s, $matches);
        if ($cnt) {
            $a->layout['schema'] = trim($matches[1]);
            $a->layout['theme'] = trim($matches[2]);
        }
        $cnt = preg_match("/\\[theme\\](.*?)\\[\\/theme\\]/ism", $s, $matches);
        if ($cnt) {
            $a->layout['theme'] = trim($matches[1]);
        }
        $cnt = preg_match_all("/\\[webpage\\](.*?)\\[\\/webpage\\]/ism", $s, $matches, PREG_SET_ORDER);
        if ($cnt) {
            // only the last webpage definition is used if there is more than one
            foreach ($matches as $mtch) {
                $a->layout['webpage'] = comanche_webpage($a, $mtch[1]);
            }
        }
    } else {
        $cnt = preg_match_all("/\\[region=(.*?)\\](.*?)\\[\\/region\\]/ism", $s, $matches, PREG_SET_ORDER);
        if ($cnt) {
            foreach ($matches as $mtch) {
                $a->layout['region_' . $mtch[1]] = comanche_region($a, $mtch[2]);
            }
        }
    }
}
Beispiel #2
0
/**
 * @brief build the page.
 *
 * Build the page - now that we have all the components
 *
 * @param App &$a global application object
 */
function construct_page(&$a)
{
    exec_pdl($a);
    $comanche = count($a->layout) ? true : false;
    require_once theme_include('theme_init.php');
    $installing = false;
    if ($a->module == 'setup') {
        $installing = true;
    } else {
        nav($a);
    }
    if ($comanche) {
        if ($a->layout['nav']) {
            $a->page['nav'] = get_custom_nav($a, $a->layout['nav']);
        }
    }
    if (($p = theme_include(current_theme() . '.js')) != '') {
        head_add_js($p);
    }
    if (($p = theme_include('mod_' . $a->module . '.php')) != '') {
        require_once $p;
    }
    require_once 'include/js_strings.php';
    if (x($a->page, 'template_style')) {
        head_add_css($a->page['template_style'] . '.css');
    } else {
        head_add_css((x($a->page, 'template') ? $a->page['template'] : 'default') . '.css');
    }
    head_add_css('mod_' . $a->module . '.css');
    head_add_css(current_theme_url($installing));
    head_add_js('mod_' . $a->module . '.js');
    $a->build_pagehead();
    if ($a->page['pdl_content']) {
        $a->page['content'] = comanche_region($a, $a->page['content']);
    }
    // Let's say we have a comanche declaration '[region=nav][/region][region=content]$nav $content[/region]'.
    // The text 'region=' identifies a section of the layout by that name. So what we want to do here is leave
    // $a->page['nav'] empty and put the default content from $a->page['nav'] and $a->page['section']
    // into a new region called $a->data['content']. It is presumed that the chosen layout file for this comanche page
    // has a '<content>' element instead of a '<section>'.
    // This way the Comanche layout can include any existing content, alter the layout by adding stuff around it or changing the
    // layout completely with a new layout definition, or replace/remove existing content.
    if ($comanche) {
        $arr = array('module' => $a->module, 'layout' => $a->layout);
        call_hooks('construct_page', $arr);
        $a->layout = $arr['layout'];
        foreach ($a->layout as $k => $v) {
            if (strpos($k, 'region_') === 0 && strlen($v)) {
                if (strpos($v, '$region_') !== false) {
                    $v = preg_replace_callback('/\\$region_([a-zA-Z0-9]+)/ism', 'comanche_replace_region', $v);
                }
                // And a couple of convenience macros
                if (strpos($v, '$htmlhead') !== false) {
                    $v = str_replace('$htmlhead', $a->page['htmlhead'], $v);
                }
                if (strpos($v, '$nav') !== false) {
                    $v = str_replace('$nav', $a->page['nav'], $v);
                }
                if (strpos($v, '$content') !== false) {
                    $v = str_replace('$content', $a->page['content'], $v);
                }
                $a->page[substr($k, 7)] = $v;
            }
        }
    }
    if ($a->is_mobile || $a->is_tablet) {
        if (isset($_SESSION['show_mobile']) && !$_SESSION['show_mobile']) {
            $link = $a->get_baseurl() . '/toggle_mobile?f=&address=' . curPageURL();
        } else {
            $link = $a->get_baseurl() . '/toggle_mobile?f=&off=1&address=' . curPageURL();
        }
        if (isset($_SESSION) && $_SESSION['mobile_theme'] != '' && $_SESSION['mobile_theme'] != '---' || isset($a->config['system']['mobile_theme']) && !isset($_SESSION['mobile_theme'])) {
            $a->page['footer'] .= replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array('$toggle_link' => $link, '$toggle_text' => t('toggle mobile')));
        }
    }
    $page = $a->page;
    $profile = $a->profile;
    header("Content-type: text/html; charset=utf-8");
    require_once theme_include((x($a->page, 'template') ? $a->page['template'] : 'default') . '.php');
}