Beispiel #1
0
function prepareTemplate($filepath, $title)
{
    //load the template into DOM for manipulation. see 'domtemplate.php' for code and
    //<camendesign.com/dom_templating> for documentation
    $template = new DOMTemplate($filepath);
    //fix all absolute URLs (i.e. if NNF is running in a folder):
    //(this also fixes the forum-title home link "/" when NNF runs in a folder)
    foreach ($template->query('//*/@href, //*/@src') as $node) {
        if ($node->nodeValue[0] == '/') {
            //prepend the base path of the forum ('/' if on root, '/folder/' if running in a sub-folder)
            $node->nodeValue = FORUM_PATH . ltrim($node->nodeValue, '/');
        }
    }
    /* HTML <head>
       -------------------------------------------------------------------------------------------------------------- */
    $template->set(array('/html/head/title' => $title, '//meta[@name="application-name"]/@content' => SUBFORUM ? SUBFORUM : FORUM_NAME, '//meta[@name="msapplication-starturl"]/@content' => FORUM_URL . PATH_URL));
    //remove 'custom.css' stylesheet if 'custom.css' is missing
    if (!file_exists(FORUM_ROOT . FORUM_PATH . 'themes/' . FORUM_THEME . '/custom.css')) {
        $template->remove('//link[contains(@href,"custom.css")]');
    }
    /* site header
       -------------------------------------------------------------------------------------------------------------- */
    $template->set(array('.nnf_forum-name' => FORUM_NAME, '//input[@name="as_sitesearch"]/@value' => $_SERVER['HTTP_HOST'], '//form[@action="http://google.com/search"]/@action' => FORUM_HTTPS ? 'https://encrypted.google.com/search' : 'http://google.com/search'));
    //are we in a sub-folder? if so, build the breadcrumb navigation
    if (PATH) {
        for ($items = explode('/', trim(PATH, '/')), $item = $template->repeat('.nnf_breadcrumb'), $i = 0; $i < count($items); $i++) {
            $item->set(array('a.nnf_subforum-name' => $items[$i], 'a.nnf_subforum-name@href' => FORUM_PATH . implode('/', array_map('safeURL', array_slice($items, 0, $i + 1))) . '/'))->next();
        }
    }
    //not in a sub-folder? remove the breadcrumb navigation
    if (!PATH) {
        $template->remove('.nnf_breadcrumb');
    }
    /* site footer
       -------------------------------------------------------------------------------------------------------------- */
    //are there any local mods?	create the list of local mods
    if (!empty($MODS['LOCAL'])) {
        $template->setHTML('#nnf_mods-local-list', theme_nameList($MODS['LOCAL']));
    } else {
        $template->remove('#nnf_mods-local');
        //remove the local mods list section
    }
    //are there any site mods?	create the list of mods
    if (!empty($MODS['GLOBAL'])) {
        $template->setHTML('#nnf_mods-list', theme_nameList($MODS['GLOBAL']));
    } else {
        $template->remove('#nnf_mods');
        //remove the mods list section
    }
    //are there any members?	create the list of members
    if (!empty($MEMBERS)) {
        $template->setHTML('#nnf_members-list', theme_nameList($MEMBERS));
    } else {
        $template->remove('#nnf_members');
        //remove the members list section
    }
    //set the name of the signed-in user
    $template->setValue('.nnf_signed-in-name', NAME)->remove(HTTP_AUTH ? '.nnf_signed-out' : '.nnf_signed-in');
    return $template;
}