예제 #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;
}
예제 #2
0
function prepareTemplate($filepath, $canonical = '', $title = NULL)
{
    global $LANG, $MODS, $MEMBERS;
    //load the template into DOM for manipulation. see 'domtemplate.php' for code and
    //<camendesign.com/dom_templating> for documentation of this object
    $template = new DOMTemplate(file_get_contents($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, //*/@content') 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, '/');
        }
    }
    /* translate!
       ---------------------------------------------------------------------------------------------------------------*/
    //before we start changing element content, we run through the language translation, if necessary;
    //if the current user-chosen language is in the list of available language translations for this theme,
    //execute the array of XPath string replacements in the translation. see the 'lang.*.php' files for details
    if (isset($LANG[LANG]['strings'])) {
        $template->set($LANG[LANG]['strings'], true)->setValue('/html/@lang', LANG);
    }
    //template the language chooser
    if (THEME_LANGS) {
        $item = $template->repeat('.nnf_lang');
        //build the list for each additional language
        foreach ($LANG as $code => $lang) {
            $item->set(array('./@value' => $code, '.' => $lang['name']))->remove(array('./@selected' => !($code == LANG)))->next();
        }
    } else {
        $template->remove('#nnf_lang');
    }
    /* HTML <head>
       -------------------------------------------------------------------------------------------------------------- */
    //if no title is provided, the one already in the template remains (likely for translation purposes)
    if (!is_null($title)) {
        $template->setValue('/html/head/title', $title);
    }
    //remove 'custom.css' stylesheet if 'custom.css' is missing
    if (!file_exists(THEME_ROOT . 'custom.css')) {
        $template->remove('//link[contains(@href,"custom.css")]');
    }
    //set the canonical URL
    if ($canonical) {
        $template->setValue('/html/head/meta[@rel="canonical"]/@href', $canonical);
    }
    /* site header
       -------------------------------------------------------------------------------------------------------------- */
    //site title
    $template->setValue('.nnf_forum-name', FORUM_NAME);
    //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' => url(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->setValue('#nnf_mods-local-list', theme_nameList($MODS['LOCAL']), true);
    } 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->setValue('#nnf_mods-list', theme_nameList($MODS['GLOBAL']), true);
    } else {
        $template->remove('#nnf_mods');
        //remove the mods list section
    }
    //are there any members?        create the list of members
    if (!empty($MEMBERS)) {
        $template->setValue('#nnf_members-list', theme_nameList($MEMBERS), true);
    } 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(AUTH_HTTP ? '.nnf_signed-out' : '.nnf_signed-in');
    return $template;
}
예제 #3
0
function prepareTemplate($filepath, $title = NULL)
{
    global $LANG, $MODS, $MEMBERS;
    //load the template into DOM for manipulation. see 'domtemplate.php' for code and
    //<camendesign.com/dom_templating> for documentation of this object
    $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, '/');
        }
    }
    /* translate!
       ---------------------------------------------------------------------------------------------------------------*/
    //before we start changing element content, we run through the language translation, if necessary;
    //if the current user-chosen language is in the list of available language translations for this theme,
    //execute the array of XPath string replacements in the translation. see the 'lang.*.php' files for details
    if (@$LANG[LANG]) {
        $template->set($LANG[LANG]['strings'], true)->setValue('/html/@lang', LANG);
    }
    //template the language chooser
    if (THEME_LANGS) {
        //the first item in the template should be your default language (mark it as selected if LANG is not blank)
        $item = $template->repeat('.nnf_lang')->remove(array('./@selected' => LANG))->next();
        //build the list for each additional language
        foreach ($LANG as $code => $lang) {
            $item->set(array('./@value' => $code, '.' => $lang['name']))->remove(array('./@selected' => !($code == LANG)))->next();
        }
    } else {
        $template->remove('#nnf_lang');
    }
    /* HTML <head>
       -------------------------------------------------------------------------------------------------------------- */
    //if no title is provided, the one already in the template remains (likely for translation purposes)
    if (!is_null($title)) {
        $template->setValue('/html/head/title', $title);
    }
    //metadata for IE9+ pinned-sites: <msdn.microsoft.com/library/gg131029>
    $template->set(array('//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(THEME_ROOT . '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->setValue('#nnf_mods-local-list', theme_nameList($MODS['LOCAL']), true);
    } 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->setValue('#nnf_mods-list', theme_nameList($MODS['GLOBAL']), true);
    } else {
        $template->remove('#nnf_mods');
        //remove the mods list section
    }
    //are there any members?	create the list of members
    if (!empty($MEMBERS)) {
        $template->setValue('#nnf_members-list', theme_nameList($MEMBERS), true);
    } 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;
}