From 2b39b68143ff44e88d730cf712f5bc1d238b96a2 Mon Sep 17 00:00:00 2001 From: Kenji ITO Date: Tue, 11 Oct 2016 14:36:21 +0900 Subject: [PATCH] Cosmetic --- public_html/lib-common.php | 447 +++++++++++++++++-------------------- 1 file changed, 203 insertions(+), 244 deletions(-) diff --git a/public_html/lib-common.php b/public_html/lib-common.php index 3695a4fd2..d6274a4df 100755 --- a/public_html/lib-common.php +++ b/public_html/lib-common.php @@ -156,7 +156,7 @@ } // Set the web server's timezone - TimeZoneConfig::setSystemTimeZone(); +TimeZoneConfig::setSystemTimeZone(); // Include multibyte functions require_once $_CONF['path_system'] . 'lib-mbyte.php'; @@ -170,9 +170,7 @@ require_once $_CONF['path_system'] . 'lib-plugins.php'; -/** - * Include page time -- used to time how fast each page was created - */ +// Include page time -- used to time how fast each page was created require_once $_CONF['path_system'] . 'classes/timer.class.php'; $_PAGE_TIMER = new timerobject(); $_PAGE_TIMER->startTimer(); @@ -329,9 +327,7 @@ $_IMAGE_TYPE = 'gif'; } -/** - * ensure XHTML constant is defined to avoid problems elsewhere - */ +// Ensure XHTML constant is defined to avoid problems elsewhere if (!defined('XHTML')) { switch ($_CONF['doctype']) { case 'xhtml10transitional': @@ -521,7 +517,7 @@ * templates for the block are specified, the default blockheader.html and * blockfooter.html will be used. * - * @param string $blockname corresponds to name field in block table + * @param string $blockName corresponds to name field in block table * @param string $which can be either 'header' or 'footer' for corresponding template * @param string $position can be 'left', 'right' or blank. If set, will be used to find a side specific * override template. @@ -531,18 +527,18 @@ * @see function COM_showBlock * @return string template name */ -function COM_getBlockTemplate($blockname, $which, $position = '') +function COM_getBlockTemplate($blockName, $which, $position = '') { global $_BLOCK_TEMPLATE, $_COM_VERBOSE, $_CONF; if ($_COM_VERBOSE) { - COM_errorLog("_BLOCK_TEMPLATE[$blockname] = " . $_BLOCK_TEMPLATE[$blockname], 1); + COM_errorLog("_BLOCK_TEMPLATE[$blockName] = " . $_BLOCK_TEMPLATE[$blockName], 1); } $template = ($which === 'header') ? 'blockheader.thtml' : 'blockfooter.thtml'; - if (!empty($_BLOCK_TEMPLATE[$blockname])) { + if (!empty($_BLOCK_TEMPLATE[$blockName])) { $i = ($which === 'header') ? 0 : 1; - $templates = explode(',', $_BLOCK_TEMPLATE[$blockname]); + $templates = explode(',', $_BLOCK_TEMPLATE[$blockName]); if (count($templates) === 2 && !empty($templates[$i])) { $template = $templates[$i]; } @@ -568,7 +564,7 @@ function COM_getBlockTemplate($blockname, $which, $position = '') } if ($_COM_VERBOSE) { - COM_errorLog("Block template for the $which of $blockname is: $template", 1); + COM_errorLog("Block template for the $which of $blockName is: $template", 1); } return $template; @@ -580,7 +576,7 @@ function COM_getBlockTemplate($blockname, $which, $position = '') * a list of all the theme names. * * @param boolean $all if true, return all themes even if users aren't allowed to change their default themes - * @return array All installed themes + * @return array All installed themes */ function COM_getThemes($all = false) { @@ -614,7 +610,7 @@ function COM_getThemes($all = false) * Create the menu, i.e. replace {menu_elements} in the site header with the * actual menu entries. * - * @param Template $header reference to the header template + * @param Template $header reference to the header template * @param array $plugin_menu array of plugin menu entries, if any */ function COM_renderMenu($header, $plugin_menu) @@ -1444,6 +1440,7 @@ function COM_siteFooter($rightBlock = -1, $custom = '') * @see function COM_siteHeader * @see function COM_siteFooter * @return string Formatted HTML document + * @throws Exception */ function COM_createHTMLDocument(&$content = '', $information = array()) { @@ -1451,41 +1448,21 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $_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 = ''; - } + $what = isset($information['what']) ? $information['what'] : 'menu'; + $pageTitle = isset($information['pagetitle']) ? $information['pagetitle'] : ''; + $headerCode = isset($information['headercode']) ? $information['headercode'] : ''; + $breadcrumbs = isset($information['breadcrumbs']) ? $information['breadcrumbs'] : ''; + $rightBlock = isset($information['rightblock']) ? $information['rightblock'] : -1; + $custom = isset($information['custom']) ? $information['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 ($_CONF['supported_version_theme'] === '1.8.1') { + if (is_callable('COM_siteHeader') && is_callable('COM_siteFooter')) { + return COM_siteHeader($what, $pageTitle, $headerCode) . $content + . COM_siteFooter($rightBlock, $custom); + } else { + throw new Exception('COM_siteHeader and COM_siteFooter are removed. Please use COM_createHTMLDocument instead.'); + } } // If the theme implemented this for us then call their version instead. @@ -1499,28 +1476,28 @@ function COM_createHTMLDocument(&$content = '', $information = array()) // the current theme only needs the default variable substitutions switch ($_CONF['doctype']) { case 'html401transitional': - $doctype = ''; + $docType = ''; break; case 'html401strict': - $doctype = ''; + $docType = ''; break; case 'xhtml10transitional': - $doctype = ''; + $docType = ''; break; case 'xhtml10strict': - $doctype = ''; + $docType = ''; break; case 'html5': case 'xhtml5': - $doctype = ''; + $docType = ''; break; default: // fallback: HTML 4.01 Transitional w/o system identifier - $doctype = ''; + $docType = ''; break; } @@ -1547,7 +1524,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $header->parse('menu_elements', 'menunavigation', true); - $header->set_var('doctype', $doctype . LB); + $header->set_var('doctype', $docType . LB); COM_setLangIdAndAttribute($header); $langId = $header->get_var('lang_id'); @@ -1560,7 +1537,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $feed_url = array(); if ($_CONF['backend'] == 1) { // add feed-link to header if applicable - $baseurl = SYND_getFeedUrl(); + $baseUrl = SYND_getFeedUrl(); $sql = 'SELECT format, filename, title, language FROM ' . $_TABLES['syndication'] . " WHERE (header_tid = 'all')"; @@ -1578,7 +1555,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $feed_url[] = ''; } } @@ -1589,27 +1566,19 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $feed = SYND_getDefaultFeedUrl(); if (COM_onFrontpage()) { - $relLinks['canonical'] = ''; + $relLinks['canonical'] = ''; } else { - $relLinks['home'] = ''; + $relLinks['home'] = ''; } $loggedInUser = !COM_isAnonUser(); - if ($loggedInUser || (($_CONF['loginrequired'] == 0) && - ($_CONF['searchloginrequired'] == 0)) - ) { - if ((substr($_SERVER['PHP_SELF'], -strlen('/search.php')) - != '/search.php') || isset($_GET['mode']) - ) { + if ($loggedInUser || (($_CONF['loginrequired'] == 0) && ($_CONF['searchloginrequired'] == 0))) { + if ((substr($_SERVER['PHP_SELF'], -strlen('/search.php')) !== '/search.php') || isset($_GET['mode'])) { $relLinks['search'] = ''; } } - if ($loggedInUser || (($_CONF['loginrequired'] == 0) && - ($_CONF['directoryloginrequired'] == 0)) - ) { + if ($loggedInUser || (($_CONF['loginrequired'] == 0) && ($_CONF['directoryloginrequired'] == 0))) { if (strpos($_SERVER['PHP_SELF'], '/article.php') !== false) { $relLinks['contents'] = 'set_var('page_site_splitter', ' - '); } else { $header->set_var('page_site_splitter', ''); } - $header->set_var('page_title', $pagetitle); + $header->set_var('page_title', $pageTitle); $header->set_var('site_name', $_CONF['site_name']); - if (COM_onFrontpage() || $pagetitle_siteslogan) { + if (COM_onFrontpage() || $pageTitle_siteSlogan) { $title_and_name = $_CONF['site_name']; - if (!empty($pagetitle)) { - $title_and_name .= ' - ' . $pagetitle; + if (!empty($pageTitle)) { + $title_and_name .= ' - ' . $pageTitle; } } else { $title_and_name = ''; - if (!empty($pagetitle)) { - $title_and_name = $pagetitle . ' - '; + if (!empty($pageTitle)) { + $title_and_name = $pageTitle . ' - '; } $title_and_name .= $_CONF['site_name']; } $header->set_var('page_title_and_site_name', $title_and_name); - $header->set_var('background_image', $_CONF['layout_url'] - . '/images/bg.' . $_IMAGE_TYPE); + $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']); + $msg .= ', ' . COM_getDisplayName($_USER['uid'], $_USER['username'], $_USER['fullname']); } - $curtime = COM_getUserDateTimeFormat(); + $currentTime = 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('datetime', $currentTime[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('datetime_html5', strftime('%FT%T', $currentTime[1])); $header->set_var('charset', COM_getCharset()); $header->set_var('direction', $LANG_DIRECTION); @@ -1731,7 +1696,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $header->set_var('left_blocks', ''); $header->set_var('geeklog_blocks', ''); } else { - $lblocks = ''; + $lBlocks = ''; /* Check if an array has been passed that includes the name of a plugin * function or custom function @@ -1740,20 +1705,20 @@ function COM_createHTMLDocument(&$content = '', $information = array()) if (is_array($what)) { $function = $what[0]; if (function_exists($function)) { - $lblocks = $function($what[1], 'left'); + $lBlocks = $function($what[1], 'left'); } else { - $lblocks = COM_showBlocks('left', $topic); + $lBlocks = COM_showBlocks('left', $topic); } } elseif ($what !== 'none') { // Now show any blocks -- need to get the topic if not on home page - $lblocks = COM_showBlocks('left', $topic); + $lBlocks = COM_showBlocks('left', $topic); } - if (empty($lblocks)) { + if (empty($lBlocks)) { $header->set_var('left_blocks', ''); $header->set_var('geeklog_blocks', ''); } else { - $header->set_var('geeklog_blocks', $lblocks); + $header->set_var('geeklog_blocks', $lBlocks); $header->parse('left_blocks', 'leftblocks', true); $header->set_var('geeklog_blocks', ''); } @@ -1763,7 +1728,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) $header->set_var('right_blocks', ''); $header->set_var('geeklog_blocks', ''); } else { - $rblocks = ''; + $rBlocks = ''; /* Check if an array has been passed that includes the name of a plugin * function or custom function @@ -1772,20 +1737,20 @@ function COM_createHTMLDocument(&$content = '', $information = array()) if (is_array($what)) { $function = $what[0]; if (function_exists($function)) { - $rblocks = $function($what[1], 'right'); + $rBlocks = $function($what[1], 'right'); } else { - $rblocks = COM_showBlocks('right', $topic); + $rBlocks = COM_showBlocks('right', $topic); } } elseif ($what !== 'none') { // Now show any blocks -- need to get the topic if not on home page - $rblocks = COM_showBlocks('right', $topic); + $rBlocks = COM_showBlocks('right', $topic); } - if (empty($rblocks)) { + if (empty($rBlocks)) { $header->set_var('right_blocks', ''); $header->set_var('geeklog_blocks', ''); } else { - $header->set_var('geeklog_blocks', $rblocks, true); + $header->set_var('geeklog_blocks', $rBlocks, true); $header->parse('right_blocks', 'rightblocks', true); } } @@ -1873,20 +1838,20 @@ function COM_createHTMLDocument(&$content = '', $information = array()) )); $year = date('Y'); - $copyrightyear = $year; + $copyrightYear = $year; if (!empty($_CONF['copyrightyear'])) { - $copyrightyear = $_CONF['copyrightyear']; + $copyrightYear = $_CONF['copyrightyear']; } if (!empty($_CONF['owner_name'])) { - $copyrightname = $_CONF['owner_name']; + $copyrightName = $_CONF['owner_name']; } else { - $copyrightname = $_CONF['site_name']; + $copyrightName = $_CONF['site_name']; } $footer->set_var('copyright_notice', ' ' . $LANG01[93] . ' © ' - . $copyrightyear . ' ' . $copyrightname . ' ' + . $copyrightYear . ' ' . $copyrightName . ' ' . $LANG01[94]); $footer->set_var('copyright_msg', $LANG01[93] . ' © ' - . $copyrightyear . ' ' . $_CONF['site_name']); + . $copyrightYear . ' ' . $_CONF['site_name']); $footer->set_var('current_year', $year); $footer->set_var('lang_copyright', $LANG01[93]); $footer->set_var('trademark_msg', $LANG01[94]); @@ -1930,19 +1895,19 @@ function COM_createHTMLDocument(&$content = '', $information = array()) if (is_array($custom)) { $function = $custom['0']; if (function_exists($function)) { - $rblocks = $function($custom['1'], 'right'); + $rBlocks = $function($custom['1'], 'right'); } else { - $rblocks = COM_showBlocks('right', $topic); + $rBlocks = COM_showBlocks('right', $topic); } } else { - $rblocks = COM_showBlocks('right', $topic); + $rBlocks = COM_showBlocks('right', $topic); } - if (empty($rblocks)) { + if (empty($rBlocks)) { $footer->set_var('geeklog_blocks', ''); $footer->set_var('right_blocks', ''); } else { - $footer->set_var('geeklog_blocks', $rblocks); + $footer->set_var('geeklog_blocks', $rBlocks); $footer->parse('right_blocks', 'rightblocks', true); $footer->set_var('geeklog_blocks', ''); } @@ -1952,7 +1917,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) } if ($_CONF['left_blocks_in_footer'] == 1) { - $lblocks = ''; + $lBlocks = ''; /* Check if an array has been passed that includes the name of a plugin * function or custom function @@ -1961,19 +1926,19 @@ function COM_createHTMLDocument(&$content = '', $information = array()) if (is_array($custom)) { $function = $custom[0]; if (function_exists($function)) { - $lblocks = $function($custom[1], 'left'); + $lBlocks = $function($custom[1], 'left'); } } else { if ($what !== 'none') { - $lblocks = COM_showBlocks('left', $topic); + $lBlocks = COM_showBlocks('left', $topic); } } - if (empty($lblocks)) { + if (empty($lBlocks)) { $footer->set_var('left_blocks', ''); $footer->set_var('geeklog_blocks', ''); } else { - $footer->set_var('geeklog_blocks', $lblocks); + $footer->set_var('geeklog_blocks', $lBlocks); $footer->parse('left_blocks', 'leftblocks', true); $footer->set_var('geeklog_blocks', ''); } @@ -1992,8 +1957,8 @@ function COM_createHTMLDocument(&$content = '', $information = array()) // Check leftblocks and rightblocks $layout_columns = 'left-center-right'; - $emptyLeftBlocks = empty($lblocks); - $emptyRightBlocks = empty($rblocks); + $emptyLeftBlocks = empty($lBlocks); + $emptyRightBlocks = empty($rBlocks); if (!$emptyLeftBlocks && $emptyRightBlocks) { $layout_columns = 'left-center'; } @@ -2043,7 +2008,7 @@ function COM_createHTMLDocument(&$content = '', $information = array()) * @param string $title Value to set block title to * @param string $helpFile Help file, if one exists * @param string $template HTML template file to use to format the block - * @return string Formatted HTML containing block header + * @return string Formatted HTML containing block header * @see COM_endBlock * @see COM_siteHeader */ @@ -2077,7 +2042,7 @@ function COM_startBlock($title = '', $helpFile = '', $template = 'blockheader.th $_SCRIPTS->setJavaScriptLibrary('jquery.ui.resizable'); $_SCRIPTS->setJavaScriptLibrary('jquery.ui.button'); - // Add Language valiables + // Add Language variables $_SCRIPTS->setLang(array('close' => $LANG32[60])); // Add JavaScript @@ -2089,7 +2054,7 @@ function COM_startBlock($title = '', $helpFile = '', $template = 'blockheader.th $helpContent = '?'; $helpAttr = array('class' => 'blocktitle', 'title' => "$title"); if (!stristr($helpFile, 'http://')) { - $help_url = $_CONF['site_url'] . "/help/$helpFile"; + $help_url = $_CONF['site_url'] . "/help/{$helpFile}"; } else { $help_url = $helpFile; } @@ -2106,8 +2071,8 @@ function COM_startBlock($title = '', $helpFile = '', $template = 'blockheader.th /** * Closes out COM_startBlock * - * @param string $template HTML template file used to format block footer - * @return string Formatted HTML to close block + * @param string $template HTML template file used to format block footer + * @return string Formatted HTML to close block * @see function COM_startBlock */ function COM_endBlock($template = 'blockfooter.thtml') @@ -2137,12 +2102,12 @@ function COM_endBlock($template = 'blockfooter.thtml') * and the second is the label to be displayed. This is used in a SQL statement and * can include DISTINCT to start. * @param string /array $selected Value (from $selection) to set to SELECTED or default - * @param int $sortcol Which field to sort option list by 0 (value) or 1 (label) + * @param int $sortCol Which field to sort option list by 0 (value) or 1 (label) * @param string $where Optional WHERE clause to use in the SQL Selection * @see function COM_checkList * @return string Formatted HTML of option values */ -function COM_optionList($table, $selection, $selected = '', $sortcol = 1, $where = '') +function COM_optionList($table, $selection, $selected = '', $sortCol = 1, $where = '') { global $_DB_table_prefix; @@ -2164,7 +2129,7 @@ function COM_optionList($table, $selection, $selected = '', $sortcol = 1, $where if ($where !== '') { $sql .= " WHERE {$where}"; } - $sql .= " ORDER BY {$select_set[$sortcol]}"; + $sql .= " ORDER BY {$select_set[$sortCol]}"; $result = DB_query($sql); $numRows = DB_numRows($result); @@ -2218,8 +2183,8 @@ function COM_topicList($selection, $selected = '', $sortCol = 1, $ignoreLang = f foreach ($topics as $tid => $topic) { $retval .= '