Example #1
0
/**
* Returns the site header
*
* This loads the proper templates, does variable substitution and returns the
* HTML for the site header with or without blocks depending on the value of $what
*
* Programming Note:
*
* The two functions COM_siteHeader and COM_siteFooter provide the framework for
* page display in Geeklog.  COM_siteHeader controls the display of the Header
* and left blocks and COM_siteFooter controls the dsiplay of the right blocks
* and the footer.  You use them like a sandwich.  Thus the following code will
* display a Geeklog page with both right and left blocks displayed.
*
* <code>
* <?php
* require_once 'lib-common.php';
* // Change to COM_siteHeader('none') to not display left blocks
* $display .= COM_siteHeader();
* $display .= "Here is your html for display";
* // Change to COM_siteFooter() to not display right blocks
* $display .= COM_siteFooter(true);
* echo $display;
* ? >
* </code>
*
* Note that the default for the header is to display the left blocks and the
* default of the footer is to not display the right blocks.
*
* This sandwich produces code like this (greatly simplified)
* <code>
* // COM_siteHeader
* <table><tr><td colspan="3">Header</td></tr>
* <tr><td>Left Blocks</td><td>
*
* // Your HTML goes here
* Here is your html for display
*
* // COM_siteFooter
* </td><td>Right Blocks</td></tr>
* <tr><td colspan="3">Footer</td></table>
* </code>
*
* @param    string  $what       If 'none' then no left blocks are returned, if 'menu' (default) then right blocks are returned
* @param    string  $pagetitle  optional content for the page's <title>
* @param    string  $headercode optional code to go into the page's <head>
* @return   string              Formatted HTML containing the site header
* @see function COM_siteFooter
*
*/
function COM_siteHeader($what = 'menu', $pagetitle = '', $headercode = '')
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG_BUTTONS, $LANG_DIRECTION, $_IMAGE_TYPE, $topic, $_COM_VERBOSE, $_SCRIPTS;
    // If the theme implemented this for us then call their version instead.
    $function = $_CONF['theme'] . '_siteHeader';
    if (function_exists($function)) {
        return $function($what, $pagetitle, $headercode);
    }
    // If we reach here then either we have the default theme OR
    // the current theme only needs the default variable substitutions
    switch ($_CONF['doctype']) {
        case 'html401transitional':
            $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
            break;
        case 'html401strict':
            $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
            break;
        case 'xhtml10transitional':
            $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
            break;
        case 'xhtml10strict':
            $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
            break;
        default:
            // fallback: HTML 4.01 Transitional w/o system identifier
            $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
            break;
    }
    // send out the charset header
    header('Content-Type: text/html; charset=' . COM_getCharset());
    if (!empty($_CONF['frame_options'])) {
        header('X-FRAME-OPTIONS: ' . $_CONF['frame_options']);
    }
    $header = COM_newTemplate($_CONF['path_layout']);
    $header->set_file(array('header' => 'header.thtml', 'menuitem' => 'menuitem.thtml', 'menuitem_last' => 'menuitem_last.thtml', 'menuitem_none' => 'menuitem_none.thtml', 'leftblocks' => 'leftblocks.thtml', 'rightblocks' => 'rightblocks.thtml'));
    $header->postprocess_fn = 'PLG_replaceTags';
    $header->set_var('doctype', $doctype);
    if (XHTML == '') {
        $header->set_var('xmlns', '');
    } else {
        $header->set_var('xmlns', ' xmlns="http://www.w3.org/1999/xhtml"');
    }
    // get topic if not on home page
    if (!isset($_GET['topic'])) {
        if (isset($_GET['story'])) {
            $sid = COM_applyFilter($_GET['story']);
        } elseif (isset($_GET['sid'])) {
            $sid = COM_applyFilter($_GET['sid']);
        } elseif (isset($_POST['story'])) {
            $sid = COM_applyFilter($_POST['story']);
        }
        if (empty($sid) && $_CONF['url_rewrite'] && strpos($_SERVER['PHP_SELF'], 'article.php') !== false) {
            COM_setArgNames(array('story', 'mode'));
            $sid = COM_applyFilter(COM_getArgument('story'));
        }
        if (!empty($sid)) {
            $topic = DB_getItem($_TABLES['stories'], 'tid', "sid='{$sid}'");
        }
    } else {
        $topic = COM_applyFilter($_GET['topic']);
    }
    $feed_url = array();
    if ($_CONF['backend'] == 1) {
        $baseurl = SYND_getFeedUrl();
        $sql = 'SELECT format, filename, title, language FROM ' . $_TABLES['syndication'] . " WHERE (header_tid = 'all')";
        if (!empty($topic)) {
            $sql .= " OR (header_tid = '" . addslashes($topic) . "')";
        }
        $result = DB_query($sql);
        $numRows = DB_numRows($result);
        for ($i = 0; $i < $numRows; $i++) {
            $A = DB_fetchArray($result);
            if (!empty($A['filename'])) {
                $format_type = SYND_getMimeType($A['format']);
                $format_name = SYND_getFeedType($A['format']);
                $feed_title = $format_name . ' Feed: ' . $A['title'];
                $feed_url[] = '<link rel="alternate" type="' . $format_type . '" hreflang="' . $A['language'] . '" href="' . $baseurl . $A['filename'] . '" title="' . htmlspecialchars($feed_title) . '"' . XHTML . '>';
            }
        }
    }
    $header->set_var('feed_url', implode(LB, $feed_url));
    // for backward compatibility only - use {feed_url} instead
    $feed = SYND_getDefaultFeedUrl();
    $header->set_var('rdf_file', $feed);
    $header->set_var('rss_url', $feed);
    $relLinks = array();
    if (COM_onFrontpage()) {
        $relLinks['canonical'] = '<link rel="canonical" href="' . $_CONF['site_url'] . '/"' . XHTML . '>';
    } else {
        $relLinks['home'] = '<link rel="home" href="' . $_CONF['site_url'] . '/" title="' . $LANG01[90] . '"' . XHTML . '>';
    }
    $loggedInUser = !COM_isAnonUser();
    if ($loggedInUser || $_CONF['loginrequired'] == 0 && $_CONF['searchloginrequired'] == 0) {
        if (substr($_SERVER['PHP_SELF'], -strlen('/search.php')) != '/search.php' || isset($_GET['mode'])) {
            $relLinks['search'] = '<link rel="search" href="' . $_CONF['site_url'] . '/search.php" title="' . $LANG01[75] . '"' . XHTML . '>';
        }
    }
    if ($loggedInUser || $_CONF['loginrequired'] == 0 && $_CONF['directoryloginrequired'] == 0) {
        if (strpos($_SERVER['PHP_SELF'], '/article.php') !== false) {
            $relLinks['contents'] = '<link rel="contents" href="' . $_CONF['site_url'] . '/directory.php" title="' . $LANG01[117] . '"' . XHTML . '>';
        }
    }
    if (!$_CONF['disable_webservices']) {
        $relLinks['service'] = '<link rel="service" ' . 'type="application/atomsvc+xml" ' . 'href="' . $_CONF['site_url'] . '/webservices/atom/?introspection" ' . 'title="' . $LANG01[130] . '"' . XHTML . '>';
    }
    // TBD: add a plugin API and a lib-custom.php function
    $header->set_var('rel_links', implode(LB, $relLinks));
    $pagetitle_siteslogan = false;
    if (empty($pagetitle)) {
        if (empty($topic)) {
            $pagetitle = $_CONF['site_slogan'];
            $pagetitle_siteslogan = true;
        } else {
            $pagetitle = stripslashes(DB_getItem($_TABLES['topics'], 'topic', "tid = '{$topic}'"));
        }
    }
    if (!empty($pagetitle)) {
        $header->set_var('page_site_splitter', ' - ');
    } else {
        $header->set_var('page_site_splitter', '');
    }
    $header->set_var('page_title', $pagetitle);
    $header->set_var('site_name', $_CONF['site_name']);
    if (COM_onFrontpage() or $pagetitle_siteslogan) {
        $title_and_name = $_CONF['site_name'];
        if (!empty($pagetitle)) {
            $title_and_name .= ' - ' . $pagetitle;
        }
    } else {
        $title_and_name = '';
        if (!empty($pagetitle)) {
            $title_and_name = $pagetitle . ' - ';
        }
        $title_and_name .= $_CONF['site_name'];
    }
    $header->set_var('page_title_and_site_name', $title_and_name);
    COM_setLangIdAndAttribute($header);
    $header->set_var('background_image', $_CONF['layout_url'] . '/images/bg.' . $_IMAGE_TYPE);
    $header->set_var('site_mail', "mailto:{$_CONF['site_mail']}");
    $header->set_var('site_name', $_CONF['site_name']);
    $header->set_var('site_slogan', $_CONF['site_slogan']);
    $msg = rtrim($LANG01[67]) . ' ' . $_CONF['site_name'];
    if (!empty($_USER['username'])) {
        $msg .= ', ' . COM_getDisplayName($_USER['uid'], $_USER['username'], $_USER['fullname']);
    }
    $curtime = COM_getUserDateTimeFormat();
    $header->set_var('welcome_msg', $msg);
    $header->set_var('datetime', $curtime[0]);
    $header->set_var('site_logo', $_CONF['layout_url'] . '/images/logo.' . $_IMAGE_TYPE);
    $header->set_var('theme', $_CONF['theme']);
    $header->set_var('charset', COM_getCharset());
    $header->set_var('direction', $LANG_DIRECTION);
    // Now add variables for buttons like e.g. those used by the Yahoo theme
    $header->set_var('button_home', $LANG_BUTTONS[1]);
    $header->set_var('button_contact', $LANG_BUTTONS[2]);
    $header->set_var('button_contribute', $LANG_BUTTONS[3]);
    $header->set_var('button_sitestats', $LANG_BUTTONS[7]);
    $header->set_var('button_personalize', $LANG_BUTTONS[8]);
    $header->set_var('button_search', $LANG_BUTTONS[9]);
    $header->set_var('button_advsearch', $LANG_BUTTONS[10]);
    $header->set_var('button_directory', $LANG_BUTTONS[11]);
    // Get plugin menu options
    $plugin_menu = PLG_getMenuItems();
    if ($_COM_VERBOSE) {
        COM_errorLog('num plugin menu items in header = ' . count($plugin_menu), 1);
    }
    // Now add nested template for menu items
    COM_renderMenu($header, $plugin_menu);
    if (count($plugin_menu) == 0) {
        $header->parse('plg_menu_elements', 'menuitem_none', true);
    } else {
        $count_plugin_menu = count($plugin_menu);
        for ($i = 1; $i <= $count_plugin_menu; $i++) {
            $header->set_var('menuitem_url', current($plugin_menu));
            $header->set_var('menuitem_text', key($plugin_menu));
            if ($i == $count_plugin_menu) {
                $header->parse('plg_menu_elements', 'menuitem_last', true);
            } else {
                $header->parse('plg_menu_elements', 'menuitem', true);
            }
            next($plugin_menu);
        }
    }
    // Call to plugins to set template variables in the header
    PLG_templateSetVars('header', $header);
    if ($_CONF['left_blocks_in_footer'] == 1) {
        $header->set_var('left_blocks', '');
        $header->set_var('geeklog_blocks', '');
    } else {
        $lblocks = '';
        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function
         * This can be used to take control over what blocks are then displayed
         */
        if (is_array($what)) {
            $function = $what[0];
            if (function_exists($function)) {
                $lblocks = $function($what[1], 'left');
            } else {
                $lblocks = COM_showBlocks('left', $topic);
            }
        } else {
            if ($what != 'none') {
                // Now show any blocks -- need to get the topic if not on home page
                $lblocks = COM_showBlocks('left', $topic);
            }
        }
        if (empty($lblocks)) {
            $header->set_var('left_blocks', '');
            $header->set_var('geeklog_blocks', '');
        } else {
            $header->set_var('geeklog_blocks', $lblocks);
            $header->parse('left_blocks', 'leftblocks', true);
            $header->set_var('geeklog_blocks', '');
        }
    }
    if ($_CONF['right_blocks_in_footer'] == 1) {
        $header->set_var('right_blocks', '');
        $header->set_var('geeklog_blocks', '');
    } else {
        $rblocks = '';
        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function
         * This can be used to take control over what blocks are then displayed
         */
        if (is_array($what)) {
            $function = $what[0];
            if (function_exists($function)) {
                $rblocks = $function($what[1], 'right');
            } else {
                $rblocks = COM_showBlocks('right', $topic);
            }
        } else {
            if ($what != 'none') {
                // Now show any blocks -- need to get the topic if not on home page
                $rblocks = COM_showBlocks('right', $topic);
            }
        }
        if (empty($rblocks)) {
            $header->set_var('right_blocks', '');
            $header->set_var('geeklog_blocks', '');
        } else {
            $header->set_var('geeklog_blocks', $rblocks, true);
            $header->parse('right_blocks', 'rightblocks', true);
        }
    }
    // Call any plugin that may want to include extra Meta tags
    // or Javascript functions
    $headercode .= PLG_getHeaderCode();
    // Meta Tags
    // 0 = Disabled, 1 = Enabled, 2 = Enabled but default just for homepage
    if ($_CONF['meta_tags'] > 0) {
        $meta_description = '';
        $meta_keywords = '';
        $no_meta_description = 1;
        $no_meta_keywords = 1;
        //Find out if the meta tag description or keywords already exist in the headercode
        if ($headercode != '') {
            $pattern = '/<meta ([^>]*)name="([^"\'>]*)"([^>]*)/im';
            if (preg_match_all($pattern, $headercode, $matches, PREG_SET_ORDER)) {
                // Loop through all meta tags looking for description and keywords
                for ($i = 0; $i < count($matches) && ($no_meta_description == 1 || $no_meta_keywords == 1); $i++) {
                    $str_matches = strtolower($matches[$i][0]);
                    $pos = strpos($str_matches, 'name=');
                    if (!(is_bool($pos) && !$pos)) {
                        $name = trim(substr($str_matches, $pos + 5), '"');
                        $pos = strpos($name, '"');
                        $name = substr($name, 0, $pos);
                        if (strcasecmp("description", $name) == 0) {
                            $pos = strpos($str_matches, 'content=');
                            if (!(is_bool($pos) && !$pos)) {
                                $no_meta_description = 0;
                            }
                        }
                        if (strcasecmp("keywords", $name) == 0) {
                            $pos = strpos($str_matches, 'content=');
                            if (!(is_bool($pos) && !$pos)) {
                                $no_meta_keywords = 0;
                            }
                        }
                    }
                }
            }
        }
        if (COM_onFrontpage() && $_CONF['meta_tags'] == 2) {
            // Display default meta tags only on home page
            if ($no_meta_description) {
                $meta_description = $_CONF['meta_description'];
            }
            if ($no_meta_keywords) {
                $meta_keywords = $_CONF['meta_keywords'];
            }
        } else {
            if ($_CONF['meta_tags'] == 1) {
                // Display default meta tags anywhere there are no tags
                if ($no_meta_description) {
                    $meta_description = $_CONF['meta_description'];
                }
                if ($no_meta_keywords) {
                    $meta_keywords = $_CONF['meta_keywords'];
                }
            }
        }
        if ($no_meta_description or $no_meta_keywords) {
            $headercode .= COM_createMetaTags($meta_description, $meta_keywords);
        }
    }
    $headercode = $_SCRIPTS->getHeader() . $headercode;
    $header->set_var('plg_headercode', $headercode);
    // The following lines allow users to embed PHP in their templates.  This
    // is almost a contradition to the reasons for using templates but this may
    // prove useful at times ...
    // Don't use PHP in templates if you can live without it!
    $tmp = $header->finish($header->parse('index_header', 'header'));
    $xml_declaration = '';
    if (get_cfg_var('short_open_tag') == '1') {
        if (preg_match('/(<\\?xml[^>]*>)(.*)/s', $tmp, $match)) {
            $xml_declaration = $match[1] . LB;
            $tmp = $match[2];
        }
    }
    ob_start();
    eval('?>' . $tmp);
    $retval = $xml_declaration . ob_get_contents();
    ob_end_clean();
    return $retval;
}
Example #2
0
function _createMailStory($sid)
{
    global $_CONF, $_TABLES, $LANG_DIRECTION, $LANG01, $LANG08;
    USES_lib_story();
    $story = new Story();
    $args = array('sid' => $sid, 'mode' => 'view');
    $output = STORY_LOADED_OK;
    $result = PLG_invokeService('story', 'get', $args, $output, $svc_msg);
    if ($result == PLG_RET_OK) {
        /* loadFromArray cannot be used, since it overwrites the timestamp */
        reset($story->_dbFields);
        while (list($fieldname, $save) = each($story->_dbFields)) {
            $varname = '_' . $fieldname;
            if (array_key_exists($fieldname, $output)) {
                $story->{$varname} = $output[$fieldname];
            }
        }
        $story->_username = $output['username'];
        $story->_fullname = $output['fullname'];
    }
    if ($output == STORY_PERMISSION_DENIED) {
        $display = COM_siteHeader('menu', $LANG_ACCESS['accessdenied']) . COM_showMessageText($LANG_ACCESS['storydenialmsg'], $LANG_ACCESS['accessdenied'], true, 'error') . COM_siteFooter();
        echo $display;
        exit;
    } elseif ($output == STORY_INVALID_SID) {
        COM_404();
    } else {
        $T = new Template($_CONF['path_layout'] . 'article');
        $T->set_file('article', 'mailable.thtml');
        list($cacheFile, $style_cache_url) = COM_getStyleCacheLocation();
        $T->set_var('direction', $LANG_DIRECTION);
        $T->set_var('css_url', $style_cache_url);
        $T->set_var('page_title', $_CONF['site_name'] . ': ' . $story->displayElements('title'));
        $T->set_var('story_title', $story->DisplayElements('title'));
        $T->set_var('story_subtitle', $story->DisplayElements('subtitle'));
        $story_image = $story->DisplayElements('story_image');
        if ($story_image != '') {
            $T->set_var('story_image', $story_image);
        } else {
            $T->unset_var('story_image');
        }
        if ($_CONF['hidestorydate'] != 1) {
            $T->set_var('story_date', $story->displayElements('date'));
        }
        if ($_CONF['contributedbyline'] == 1) {
            $T->set_var('lang_contributedby', $LANG01[1]);
            $authorname = COM_getDisplayName($story->displayElements('uid'));
            $T->set_var('author', $authorname);
            $T->set_var('story_author', $authorname);
            $T->set_var('story_author_username', $story->DisplayElements('username'));
        }
        $T->set_var('story_introtext', $story->DisplayElements('introtext'));
        $T->set_var('story_bodytext', $story->DisplayElements('bodytext'));
        $T->set_var('site_name', $_CONF['site_name']);
        $T->set_var('site_slogan', $_CONF['site_slogan']);
        $T->set_var('story_id', $story->getSid());
        $articleUrl = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
        if ($story->DisplayElements('commentcode') >= 0) {
            $commentsUrl = $articleUrl . '#comments';
            $comments = $story->DisplayElements('comments');
            $numComments = COM_numberFormat($comments);
            $T->set_var('story_comments', $numComments);
            $T->set_var('comments_url', $commentsUrl);
            $T->set_var('comments_text', $numComments . ' ' . $LANG01[3]);
            $T->set_var('comments_count', $numComments);
            $T->set_var('lang_comments', $LANG01[3]);
            $comments_with_count = sprintf($LANG01[121], $numComments);
            if ($comments > 0) {
                $comments_with_count = COM_createLink($comments_with_count, $commentsUrl);
            }
            $T->set_var('comments_with_count', $comments_with_count);
        }
        $T->set_var('lang_full_article', $LANG08[33]);
        $T->set_var('article_url', $articleUrl);
        COM_setLangIdAndAttribute($T);
        $T->parse('output', 'article');
        $htmlMsg = $T->finish($T->get_var('output'));
        return $htmlMsg;
    }
}
Example #3
0
         $story_template->set_var('story_comments', $numComments);
         $story_template->set_var('comments_url', $commentsUrl);
         $story_template->set_var('comments_text', $numComments . ' ' . $LANG01[3]);
         $story_template->set_var('comments_count', $numComments);
         $story_template->set_var('lang_comments', $LANG01[3]);
         $comments_with_count = sprintf($LANG01[121], $numComments);
         if ($comments > 0) {
             $comments_with_count = COM_createLink($comments_with_count, $commentsUrl);
         }
         $story_template->set_var('comments_with_count', $comments_with_count);
     }
     $story_template->set_var('lang_full_article', $LANG08[33]);
     $story_template->set_var('article_url', $articleUrl);
     $printable = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid() . '&amp;mode=print');
     $story_template->set_var('printable_url', $printable);
     COM_setLangIdAndAttribute($story_template);
     $story_template->parse('output', 'article');
     $display = $story_template->finish($story_template->get_var('output'));
 } else {
     // Set page title
     $pagetitle = $story->DisplayElements('page_title');
     if (empty($pagetitle)) {
         $pagetitle = $story->DisplayElements('title');
     }
     $headercode = '';
     $permalink = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
     $headercode .= '<link rel="canonical" href="' . $permalink . '"' . XHTML . '>';
     // Meta Tags
     if ($_CONF['meta_tags'] > 0) {
         $meta_description = $story->DisplayElements('meta_description');
         $meta_keywords = $story->DisplayElements('meta_keywords');
Example #4
0
/**
* Create and return the HTML document
*
* @param    string  $content        Main content for the page
* @param    array   $information    An array defining variables to be used when creating the output
*                       string  'what'          If 'none' then no left blocks are returned, if 'menu' (default) then right blocks are returned
*                       string  'pagetitle'     Optional content for the page's <title>
*                       string  'breadcrumbs'   Optional content for the page's breadcrumb
*                       string  'headercode'    Optional code to go into the page's <head>
*                       boolean 'rightblock'    Whether or not to show blocks on right hand side default is no (-1)
*                       array   'custom'        An array defining custom function to be used to format Rightblocks
* @see      function COM_siteHeader
* @see      function COM_siteFooter
* @return   string              Formated HTML document
*
*/
function COM_createHTMLDocument(&$content = '', $information = array())
{
    global $_CONF, $_TABLES, $_USER, $LANG01, $LANG_BUTTONS, $LANG_DIRECTION, $_IMAGE_TYPE, $topic, $_COM_VERBOSE, $_SCRIPTS, $_PAGE_TIMER, $relLinks;
    // Retrieve required variables from information array
    if (isset($information['what'])) {
        $what = $information['what'];
    } else {
        $what = 'menu';
    }
    if (isset($information['pagetitle'])) {
        $pagetitle = $information['pagetitle'];
    } else {
        $pagetitle = '';
    }
    if (isset($information['headercode'])) {
        $headercode = $information['headercode'];
    } else {
        $headercode = '';
    }
    if (isset($information['breadcrumbs'])) {
        $breadcrumbs = $information['breadcrumbs'];
    } else {
        $breadcrumbs = '';
    }
    if (isset($information['rightblock'])) {
        $rightblock = $information['rightblock'];
    } else {
        $rightblock = -1;
    }
    if (isset($information['custom'])) {
        $custom = $information['custom'];
    } else {
        $custom = '';
    }
    // If the theme does not support the CSS layout then call the legacy functions (Geeklog 1.8.1 and older).
    if ($_CONF['supported_version_theme'] == '1.8.1') {
        return COM_siteHeader($what, $pagetitle, $headercode) . $content . COM_siteFooter($rightblock, $custom);
    }
    // If the theme implemented this for us then call their version instead.
    $function = $_CONF['theme'] . '_createHTMLDocument';
    if (function_exists($function)) {
        return $function($content, $information);
    }
    // If we reach here then either we have the default theme OR
    // the current theme only needs the default variable substitutions
    switch ($_CONF['doctype']) {
        case 'html401transitional':
            $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
            break;
        case 'html401strict':
            $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
            break;
        case 'xhtml10transitional':
            $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
            break;
        case 'xhtml10strict':
            $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
            break;
        case 'html5':
        case 'xhtml5':
            $doctype = '<!DOCTYPE html>';
            break;
        default:
            // fallback: HTML 4.01 Transitional w/o system identifier
            $doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
            break;
    }
    // send out the charset header
    header('Content-Type: text/html; charset=' . COM_getCharset());
    if (!empty($_CONF['frame_options'])) {
        header('X-FRAME-OPTIONS: ' . $_CONF['frame_options']);
    }
    $header = COM_newTemplate($_CONF['path_layout']);
    $header->set_file(array('header' => 'header.thtml', 'menunavigation' => 'menunavigation.thtml', 'leftblocks' => 'leftblocks.thtml', 'rightblocks' => 'rightblocks.thtml'));
    $blocks = array('menuitem', 'menuitem_last', 'menuitem_none');
    foreach ($blocks as $block) {
        $header->set_block('menunavigation', $block);
    }
    $header->parse('menu_elements', 'menunavigation', true);
    $header->set_var('doctype', $doctype . LB);
    if (XHTML == '') {
        $header->set_var('xmlns', '');
    } else {
        $header->set_var('xmlns', ' xmlns="http://www.w3.org/1999/xhtml"');
    }
    $feed_url = array();
    if ($_CONF['backend'] == 1) {
        $baseurl = SYND_getFeedUrl();
        $sql = 'SELECT format, filename, title, language FROM ' . $_TABLES['syndication'] . " WHERE (header_tid = 'all')";
        if (!empty($topic)) {
            $sql .= " OR (header_tid = '" . DB_escapeString($topic) . "')";
        }
        $result = DB_query($sql);
        $numRows = DB_numRows($result);
        for ($i = 0; $i < $numRows; $i++) {
            $A = DB_fetchArray($result);
            if (!empty($A['filename'])) {
                $format_type = SYND_getMimeType($A['format']);
                $format_name = SYND_getFeedType($A['format']);
                $feed_title = $format_name . ' Feed: ' . $A['title'];
                $feed_url[] = '<link rel="alternate" type="' . $format_type . '" hreflang="' . $A['language'] . '" href="' . $baseurl . $A['filename'] . '" title="' . htmlspecialchars($feed_title) . '"' . XHTML . '>';
            }
        }
    }
    $header->set_var('feed_url', implode(LB, $feed_url));
    // for backward compatibility only - use {feed_url} instead
    $feed = SYND_getDefaultFeedUrl();
    if (COM_onFrontpage()) {
        $relLinks['canonical'] = '<link rel="canonical" href="' . $_CONF['site_url'] . '/"' . XHTML . '>';
    } else {
        $relLinks['home'] = '<link rel="home" href="' . $_CONF['site_url'] . '/" title="' . $LANG01[90] . '"' . XHTML . '>';
    }
    $loggedInUser = !COM_isAnonUser();
    if ($loggedInUser || $_CONF['loginrequired'] == 0 && $_CONF['searchloginrequired'] == 0) {
        if (substr($_SERVER['PHP_SELF'], -strlen('/search.php')) != '/search.php' || isset($_GET['mode'])) {
            $relLinks['search'] = '<link rel="search" href="' . $_CONF['site_url'] . '/search.php" title="' . $LANG01[75] . '"' . XHTML . '>';
        }
    }
    if ($loggedInUser || $_CONF['loginrequired'] == 0 && $_CONF['directoryloginrequired'] == 0) {
        if (strpos($_SERVER['PHP_SELF'], '/article.php') !== false) {
            $relLinks['contents'] = '<link rel="contents" href="' . $_CONF['site_url'] . '/directory.php" title="' . $LANG01[117] . '"' . XHTML . '>';
        }
    }
    if (!$_CONF['disable_webservices']) {
        $relLinks['service'] = '<link rel="service" ' . 'type="application/atomsvc+xml" ' . 'href="' . $_CONF['site_url'] . '/webservices/atom/?introspection" ' . 'title="' . $LANG01[130] . '"' . XHTML . '>';
    }
    // TBD: add a plugin API and a lib-custom.php function
    $header->set_var('rel_links', implode(LB, $relLinks));
    $pagetitle_siteslogan = false;
    if (empty($pagetitle)) {
        if (empty($topic)) {
            $pagetitle = $_CONF['site_slogan'];
            $pagetitle_siteslogan = true;
        } else {
            $pagetitle = stripslashes(DB_getItem($_TABLES['topics'], 'topic', "tid = '{$topic}'"));
        }
    }
    if (!empty($pagetitle)) {
        $header->set_var('page_site_splitter', ' - ');
    } else {
        $header->set_var('page_site_splitter', '');
    }
    $header->set_var('page_title', $pagetitle);
    $header->set_var('site_name', $_CONF['site_name']);
    if (COM_onFrontpage() or $pagetitle_siteslogan) {
        $title_and_name = $_CONF['site_name'];
        if (!empty($pagetitle)) {
            $title_and_name .= ' - ' . $pagetitle;
        }
    } else {
        $title_and_name = '';
        if (!empty($pagetitle)) {
            $title_and_name = $pagetitle . ' - ';
        }
        $title_and_name .= $_CONF['site_name'];
    }
    $header->set_var('page_title_and_site_name', $title_and_name);
    COM_setLangIdAndAttribute($header);
    $header->set_var('background_image', $_CONF['layout_url'] . '/images/bg.' . $_IMAGE_TYPE);
    $msg = rtrim($LANG01[67]) . ' ' . $_CONF['site_name'];
    if (!empty($_USER['username'])) {
        $msg .= ', ' . COM_getDisplayName($_USER['uid'], $_USER['username'], $_USER['fullname']);
    }
    $curtime = COM_getUserDateTimeFormat();
    $header->set_var('welcome_msg', $msg);
    $header->set_var('datetime', $curtime[0]);
    $header->set_var('site_logo', $_CONF['layout_url'] . '/images/logo.' . $_IMAGE_TYPE);
    $header->set_var('theme', $_CONF['theme']);
    $header->set_var('datetime_html5', strftime('%FT%T', $curtime[1]));
    $header->set_var('charset', COM_getCharset());
    $header->set_var('direction', $LANG_DIRECTION);
    $template_vars = array('rdf_file' => $feed, 'rss_url' => $feed, 'site_mail' => "mailto:{$_CONF['site_mail']}", 'site_name' => $_CONF['site_name'], 'site_slogan' => $_CONF['site_slogan'], 'button_home' => $LANG_BUTTONS[1], 'button_contact' => $LANG_BUTTONS[2], 'button_contribute' => $LANG_BUTTONS[3], 'button_sitestats' => $LANG_BUTTONS[7], 'button_personalize' => $LANG_BUTTONS[8], 'button_search' => $LANG_BUTTONS[9], 'button_advsearch' => $LANG_BUTTONS[10], 'button_directory' => $LANG_BUTTONS[11]);
    $header->set_var($template_vars);
    // Get plugin menu options
    $plugin_menu = PLG_getMenuItems();
    if ($_COM_VERBOSE) {
        COM_errorLog('num plugin menu items in header = ' . count($plugin_menu), 1);
    }
    // Now add nested template for menu items
    COM_renderMenu($header, $plugin_menu);
    if (count($plugin_menu) == 0) {
        $header->parse('plg_menu_elements', 'menuitem_none', true);
    } else {
        $count_plugin_menu = count($plugin_menu);
        for ($i = 1; $i <= $count_plugin_menu; $i++) {
            $header->set_var('menuitem_url', current($plugin_menu));
            $header->set_var('menuitem_text', key($plugin_menu));
            if ($i == $count_plugin_menu) {
                $header->parse('plg_menu_elements', 'menuitem_last', true);
            } else {
                $header->parse('plg_menu_elements', 'menuitem', true);
            }
            next($plugin_menu);
        }
    }
    // Call to plugins to set template variables in the header
    PLG_templateSetVars('header', $header);
    if ($_CONF['left_blocks_in_footer'] == 1) {
        $header->set_var('left_blocks', '');
        $header->set_var('geeklog_blocks', '');
    } else {
        $lblocks = '';
        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function
         * This can be used to take control over what blocks are then displayed
         */
        if (is_array($what)) {
            $function = $what[0];
            if (function_exists($function)) {
                $lblocks = $function($what[1], 'left');
            } else {
                $lblocks = COM_showBlocks('left', $topic);
            }
        } else {
            if ($what != 'none') {
                // Now show any blocks -- need to get the topic if not on home page
                $lblocks = COM_showBlocks('left', $topic);
            }
        }
        if (empty($lblocks)) {
            $header->set_var('left_blocks', '');
            $header->set_var('geeklog_blocks', '');
        } else {
            $header->set_var('geeklog_blocks', $lblocks);
            $header->parse('left_blocks', 'leftblocks', true);
            $header->set_var('geeklog_blocks', '');
        }
    }
    if ($_CONF['right_blocks_in_footer'] == 1) {
        $header->set_var('right_blocks', '');
        $header->set_var('geeklog_blocks', '');
    } else {
        $rblocks = '';
        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function
         * This can be used to take control over what blocks are then displayed
         */
        if (is_array($what)) {
            $function = $what[0];
            if (function_exists($function)) {
                $rblocks = $function($what[1], 'right');
            } else {
                $rblocks = COM_showBlocks('right', $topic);
            }
        } else {
            if ($what != 'none') {
                // Now show any blocks -- need to get the topic if not on home page
                $rblocks = COM_showBlocks('right', $topic);
            }
        }
        if (empty($rblocks)) {
            $header->set_var('right_blocks', '');
            $header->set_var('geeklog_blocks', '');
        } else {
            $header->set_var('geeklog_blocks', $rblocks, true);
            $header->parse('right_blocks', 'rightblocks', true);
        }
    }
    // Set last topic session variable
    if ($topic == TOPIC_ALL_OPTION) {
        $topic = '';
        // Do not save 'all' option. Nothing is the same thing
    }
    SESS_setVariable('topic', $topic);
    // Call any plugin that may want to include extra Meta tags
    // or Javascript functions
    $headercode .= PLG_getHeaderCode();
    // Meta Tags
    // 0 = Disabled, 1 = Enabled, 2 = Enabled but default just for homepage
    if ($_CONF['meta_tags'] > 0) {
        $meta_description = '';
        $meta_keywords = '';
        $no_meta_description = 1;
        $no_meta_keywords = 1;
        //Find out if the meta tag description or keywords already exist in the headercode
        if ($headercode != '') {
            $pattern = '/<meta ([^>]*)name="([^"\'>]*)"([^>]*)/im';
            if (preg_match_all($pattern, $headercode, $matches, PREG_SET_ORDER)) {
                // Loop through all meta tags looking for description and keywords
                for ($i = 0; $i < count($matches) && ($no_meta_description == 1 || $no_meta_keywords == 1); $i++) {
                    $str_matches = strtolower($matches[$i][0]);
                    $pos = strpos($str_matches, 'name=');
                    if (!(is_bool($pos) && !$pos)) {
                        $name = trim(substr($str_matches, $pos + 5), '"');
                        $pos = strpos($name, '"');
                        $name = substr($name, 0, $pos);
                        if (strcasecmp("description", $name) == 0) {
                            $pos = strpos($str_matches, 'content=');
                            if (!(is_bool($pos) && !$pos)) {
                                $no_meta_description = 0;
                            }
                        }
                        if (strcasecmp("keywords", $name) == 0) {
                            $pos = strpos($str_matches, 'content=');
                            if (!(is_bool($pos) && !$pos)) {
                                $no_meta_keywords = 0;
                            }
                        }
                    }
                }
            }
        }
        if (COM_onFrontpage() && $_CONF['meta_tags'] == 2) {
            // Display default meta tags only on home page
            if ($no_meta_description) {
                $meta_description = $_CONF['meta_description'];
            }
            if ($no_meta_keywords) {
                $meta_keywords = $_CONF['meta_keywords'];
            }
        } else {
            if ($_CONF['meta_tags'] == 1) {
                // Display default meta tags anywhere there are no tags
                if ($no_meta_description) {
                    $meta_description = $_CONF['meta_description'];
                }
                if ($no_meta_keywords) {
                    $meta_keywords = $_CONF['meta_keywords'];
                }
            }
        }
        if ($no_meta_description or $no_meta_keywords) {
            $headercode .= COM_createMetaTags($meta_description, $meta_keywords);
        }
    }
    $header->set_var('breadcrumb_trail', $breadcrumbs);
    COM_hit();
    // Set template directory
    $footer = COM_newTemplate($_CONF['path_layout']);
    // Set template file
    $footer->set_file(array('footer' => 'footer.thtml', 'rightblocks' => 'rightblocks.thtml', 'leftblocks' => 'leftblocks.thtml'));
    $year = date('Y');
    $copyrightyear = $year;
    if (!empty($_CONF['copyrightyear'])) {
        $copyrightyear = $_CONF['copyrightyear'];
    }
    if (!empty($_CONF['owner_name'])) {
        $copyrightname = $_CONF['owner_name'];
    } else {
        $copyrightname = $_CONF['site_name'];
    }
    $footer->set_var('copyright_notice', '&nbsp;' . $LANG01[93] . ' &copy; ' . $copyrightyear . ' ' . $copyrightname . '<br' . XHTML . '>&nbsp;' . $LANG01[94]);
    $footer->set_var('copyright_msg', $LANG01[93] . ' &copy; ' . $copyrightyear . ' ' . $_CONF['site_name']);
    $footer->set_var('current_year', $year);
    $footer->set_var('lang_copyright', $LANG01[93]);
    $footer->set_var('trademark_msg', $LANG01[94]);
    $footer->set_var('powered_by', $LANG01[95]);
    $footer->set_var('geeklog_url', 'http://www.geeklog.net/');
    $footer->set_var('geeklog_version', VERSION);
    $footer->set_var($template_vars);
    /* Right blocks. Argh. Don't talk to me about right blocks...
     * Right blocks will be displayed if Right_blocks_in_footer is set [1],
     * AND (this function has been asked to show them (first param) OR the
     * show_right_blocks conf variable has been set to override what the code
     * wants to do.
     *
     * If $custom sets an array (containing functionname and first argument)
     * then this is used instead of the default (COM_showBlocks) to render
     * the right blocks (and left).
     *
     * [1] - if it isn't, they'll be in the header already.
     *
     */
    $displayRightBlocks = true;
    if ($_CONF['right_blocks_in_footer'] == 1) {
        if ($rightblock < 0 || !$rightblock) {
            if (isset($_CONF['show_right_blocks'])) {
                $displayRightBlocks = $_CONF['show_right_blocks'];
            } else {
                $displayRightBlocks = false;
            }
        } else {
            $displayRightBlocks = true;
        }
    } else {
        $displayRightBlocks = false;
    }
    if ($displayRightBlocks) {
        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function.
         * This can be used to take control over what blocks are then displayed
         */
        if (is_array($custom)) {
            $function = $custom['0'];
            if (function_exists($function)) {
                $rblocks = $function($custom['1'], 'right');
            } else {
                $rblocks = COM_showBlocks('right', $topic);
            }
        } else {
            $rblocks = COM_showBlocks('right', $topic);
        }
        if (empty($rblocks)) {
            $footer->set_var('geeklog_blocks', '');
            $footer->set_var('right_blocks', '');
        } else {
            $footer->set_var('geeklog_blocks', $rblocks);
            $footer->parse('right_blocks', 'rightblocks', true);
            $footer->set_var('geeklog_blocks', '');
        }
    } else {
        $footer->set_var('geeklog_blocks', '');
        $footer->set_var('right_blocks', '');
    }
    if ($_CONF['left_blocks_in_footer'] == 1) {
        $lblocks = '';
        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function
         * This can be used to take control over what blocks are then displayed
         */
        if (is_array($custom)) {
            $function = $custom[0];
            if (function_exists($function)) {
                $lblocks = $function($custom[1], 'left');
            }
        } else {
            if ($what != 'none') {
                $lblocks = COM_showBlocks('left', $topic);
            }
        }
        if (empty($lblocks)) {
            $footer->set_var('left_blocks', '');
            $footer->set_var('geeklog_blocks', '');
        } else {
            $footer->set_var('geeklog_blocks', $lblocks);
            $footer->parse('left_blocks', 'leftblocks', true);
            $footer->set_var('geeklog_blocks', '');
        }
    }
    // Global centerspan variable set in index.php
    if (isset($GLOBALS['centerspan'])) {
        $footer->set_var('centerblockfooter-span', '</td></tr></table>');
    }
    $exectime = $_PAGE_TIMER->stopTimer();
    $exectext = $LANG01[91] . ' ' . $exectime . ' ' . $LANG01[92];
    $footer->set_var('execution_time', $exectime);
    $footer->set_var('execution_textandtime', $exectext);
    /* Check leftblocks and rightblocks */
    $layout_columns = 'left-center-right';
    $emptylblocks = empty($lblocks);
    $emptyrblocks = empty($rblocks);
    if (!$emptylblocks && $emptyrblocks) {
        $layout_columns = 'left-center';
    }
    if ($emptylblocks && !$emptyrblocks) {
        $layout_columns = 'center-right';
    }
    if ($emptylblocks && $emptyrblocks) {
        $layout_columns = 'center';
    }
    $header->set_var('layout_columns', $layout_columns);
    // All blocks, autotags, template files, etc, now have been rendered (since can be done in footer) so all scripts and css should be set now
    $headercode = $_SCRIPTS->getHeader() . $headercode;
    $header->set_var('plg_headercode', $headercode);
    $retval_header = $header->finish($header->parse('index_header', 'header'));
    // Call to plugins to set template variables in the footer
    PLG_templateSetVars('footer', $footer);
    // Call any plugin that may want to include extra JavaScript functions
    $plugin_footercode = PLG_getFooterCode();
    // Retrieve any JavaScript libraries, variables and functions
    $footercode = $_SCRIPTS->getFooter();
    // $_SCRIPTS code should be placed before plugin_footer_code but plugin_footer_code should still be allowed to set $_SCRIPTS
    $footercode .= $plugin_footercode;
    $footer->set_var('plg_footercode', $footercode);
    // Actually parse the template and make variable substitutions
    $footer->parse('index_footer', 'footer');
    return $retval_header . $content . $footer->finish($footer->get_var('index_footer'));
}