----------------------------------------------------------------------------------------------
Text Formatted Code
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.3 |
// +---------------------------------------------------------------------------+
// | lib-common.php |
// | |
// | Geeklog common library. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2004 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony@tonybibbs.com |
// | Mark Limburg - mlimburg@users.sourceforge.net |
// | Jason Whittenburg - jwhitten@securitygeeks.com |
// | Dirk Haun - dirk@haun-online.de |
// | Vincent Furia - vinny01@users.sourceforge.net |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
//
// $Id: lib-common.php,v 1.408 2004/12/29 08:43:37 dhaun Exp $
// Prevent PHP from reporting uninitialized variables
error_reporting( E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR );
/**
* This is the common library for Geeklog. Through our code, you will see
* functions with the COM_ prefix (e.g. COM_siteHeader()). Any such functions
* can be found in this file. This file provides all configuration variables
* needed by Geeklog with a series of includes (see futher down).
*
* --- You only need to modify one line in this file! ---
*
* WARNING: put any custom hacks in lib-custom.php and not in here. This file is
* modified frequently by the Geeklog development team. If you put your hacks in
* lib-custom.php you will find upgrading much easier.
*
*/
/**
* Turn this on to get various debug messages from the code in this library
* @global Boolean $_COM_VERBOSE
*/
$_COM_VERBOSE = false;
/**
* Configuration Include: You should ONLY have to modify this line.
* Leave the rest of this file intact!
*
* Make sure to include the name of the config file,
* i.e. the path should end in .../config.php
*/
require_once( '/geeklog-1.3.11/config.php' );
// Before we do anything else, check to ensure site is enabled
if( isset( $_CONF['site_enabled'] ) && !$_CONF['site_enabled'] )
{
if( empty( $_CONF['site_disabled_msg'] ))
{
echo $_CONF['site_name'] . ' is temporarily down. Please check back soon';
}
else
{
// if the msg starts with http: assume it's a URL we should redirect to
if( preg_match( "/^(https?):/", $_CONF['site_disabled_msg'] ) === 1 )
{
echo COM_refresh( $_CONF['site_disabled_msg'] );
}
else
{
echo $_CONF['site_disabled_msg'];
}
}
exit;
}
// this file can't be used on its own - redirect to index.php
if( eregi( 'lib-common.php', $HTTP_SERVER_VARS['PHP_SELF'] ))
{
echo COM_refresh( $_CONF['site_url'] . '/index.php' );
exit;
}
// timezone hack - set the webserver's timezone
if( !empty( $_CONF['timezone'] ) && !ini_get( 'safe_mode' ) &&
function_exists( 'putenv' )) {
putenv( 'TZ=' . $_CONF['timezone'] );
}
// +---------------------------------------------------------------------------+
// | Library Includes: You shouldn't have to touch anything below here |
// +---------------------------------------------------------------------------+
/**
* If needed, add our PEAR path to the list of include paths
*
*/
if( !$_CONF['have_pear'] )
{
$curPHPIncludePath = ini_get( 'include_path' );
if( defined( 'PATH_SEPARATOR' ))
{
$separator = PATH_SEPARATOR;
}
else
{
// prior to PHP 4.3.0, we have to guess the correct separator ...
$separator = ';';
if( strpos( $curPHPIncludePath, $separator ) === false )
{
$separator = ':';
}
}
if( ini_set( 'include_path', $_CONF['path_pear'] . $separator
. $curPHPIncludePath ) === false )
{
COM_errorLog( 'ini_set failed - there may be problems using the PEAR classes.', 1);
}
}
/**
* This is necessary to ensure compatibility with PHP 4.1.x
*
*/
if( !function_exists( 'is_a' ))
{
require_once( 'PHP/Compat.php' );
PHP_Compat::loadFunction( 'is_a' );
}
/**
* 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();
/**
* Include URL class
*
* This provides optional URL rewriting functionality.
* Please note this code is still experimental and is only currently used by the
* staticpages plugin.
*/
require_once( $_CONF['path_system'] . 'classes/url.class.php' );
$_URL = new url( $_CONF['url_rewrite'] );
/**
* This is our HTML template class. It is the same one found in PHPLib and is
* licensed under the LGPL. See that file for details
*
*/
require_once( $_CONF['path_system'] . 'classes/template.class.php' );
/**
* This is the database library.
*
* Including this gives you a working connection to the database
*
*/
require_once( $_CONF['path_system'] . 'lib-database.php' );
/**
* This is the security library used for application security
*
*/
require_once( $_CONF['path_system'] . 'lib-security.php' );
/**
* This is the syndication library used to offer (RSS) feeds.
*
*/
require_once( $_CONF['path_system'] . 'lib-syndication.php' );
/**
* This is the custom library.
*
* It is the sandbox for every Geeklog Admin to play in.
* We will never modify this file. This should hold all custom
* hacks to make upgrading easier.
*
*/
require_once( $_CONF['path_system'] . 'lib-custom.php' );
/**
* Include plugin class.
* This is a poorly implemented class that was not very well thought out.
* Still very necessary
*
*/
require_once( $_CONF['path_system'] . 'lib-plugins.php' );
/**
* Session management library
*
*/
require_once( $_CONF['path_system'] . 'lib-sessions.php' );
/**
* Ulf Harnhammar's kses class
*
*/
require_once( $_CONF['path_system'] . 'classes/kses.class.php' );
// Set theme
// Need to modify this code to check if theme was cached in user cookie. That
// way if user logged in and set theme and then logged out we would still know
// which theme to show them.
if( !empty( $HTTP_POST_VARS['usetheme'] ) && is_dir( $_CONF['path_themes']
. $HTTP_POST_VARS['usetheme'] ))
{
$_CONF['theme'] = $HTTP_POST_VARS['usetheme'];
$_CONF['path_layout'] = $_CONF['path_themes'] . $_CONF['theme'] . '/';
$_CONF['layout_url'] = $_CONF['site_url'] . '/layout/' . $_CONF['theme'];
}
else if( $_CONF['allow_user_themes'] == 1 )
{
if( isset( $HTTP_COOKIE_VARS[$_CONF['cookie_theme']]) && empty($_USER['theme'] ))
{
if( is_dir( $_CONF['path_themes'] . $HTTP_COOKIE_VARS[$_CONF['cookie_theme']] ))
{
$_USER['theme'] = $HTTP_COOKIE_VARS[$_CONF['cookie_theme']];
}
}
if( !empty( $_USER['theme'] ))
{
if( is_dir( $_CONF['path_themes'] . $_USER['theme'] ))
{
$_CONF['theme'] = $_USER['theme'];
$_CONF['path_layout'] = $_CONF['path_themes'] . $_CONF['theme'] . '/';
$_CONF['layout_url'] = $_CONF['site_url'] . '/layout/' . $_CONF['theme'];
}
else
{
$_USER['theme'] = $_CONF['theme'];
}
}
}
/**
* Include theme functions file
*/
// Include theme functions file which may/may not do anything
if( file_exists( $_CONF['path_layout'] . 'functions.php' ))
{
require_once( $_CONF['path_layout'] . 'functions.php' );
}
// Similarly set language
if( isset( $HTTP_COOKIE_VARS[$_CONF['cookie_language']]) && empty( $_USER['language'] ))
{
if( is_file( $_CONF['path_language'] . $HTTP_COOKIE_VARS[$_CONF['cookie_language']] . '.php' ))
{
$_USER['language'] = $HTTP_COOKIE_VARS[$_CONF['cookie_language']];
$_CONF['language'] = $HTTP_COOKIE_VARS[$_CONF['cookie_language']];
}
}
else if( !empty( $_USER['language'] ))
{
if( is_file( $_CONF['path_language'] . $_USER['language'] . '.php' ))
{
$_CONF['language'] = $_USER['language'];
}
}
// Handle Who's Online block
if( empty( $_USER['uid'] ) OR $_USER['uid'] == 1 )
{
// The following code handles anonymous users so they show up properly
DB_query( "DELETE FROM {$_TABLES['sessions']} WHERE remote_ip = '{$HTTP_SERVER_VARS['REMOTE_ADDR']}' AND uid = 1" );
$tries = 0;
do
{
// Build a useless sess_id (needed for insert to work properly)
mt_srand(( double )microtime() * 1000000 );
$sess_id = mt_rand();
$curtime = time();
// Insert anonymous user session
$result = DB_query( "INSERT INTO {$_TABLES['sessions']} (sess_id, start_time, remote_ip, uid) VALUES ($sess_id, $curtime, '{$HTTP_SERVER_VARS['REMOTE_ADDR']}', 1)", 1 );
$tries++;
}
while(( $result === false) && ( $tries < 5 ));
}
// Clear out any expired sessions
DB_query( "DELETE FROM {$_TABLES['sessions']} WHERE uid = 1 AND start_time < " . ( time() - $_CONF['whosonline_threshold'] ));
/**
*
* Language include
*
*/
require_once( $_CONF['path_language'] . $_CONF['language'] . '.php' );
if( setlocale( LC_ALL, $_CONF['locale'] ) === false )
{
setlocale( LC_TIME, $_CONF['locale'] );
}
/**
* Global array of groups current user belongs to
*
* @global array $_GROUPS
*
*/
$_GROUPS = SEC_getUserGroups( $_USER['uid'] );
/**
* Global array of current user permissions [read,edit]
*
* @global array $_RIGHTS
*
*/
$_RIGHTS = explode( ',', SEC_getUserPermissions() );
if( isset( $HTTP_GET_VARS['topic'] ))
{
$topic = COM_applyFilter( $HTTP_GET_VARS['topic'] );
}
else if( isset( $HTTP_POST_VARS['topic'] ))
{
$topic = COM_applyFilter( $HTTP_POST_VARS['topic'] );
}
else
{
$topic = '';
}
// +---------------------------------------------------------------------------+
// | HTML WIDGETS |
// +---------------------------------------------------------------------------+
/**
* Return the file to use for a block template.
*
* This returns the template needed to build the HTML for a block. This function
* allows designers to give a block it's own custom look and feel. If no
* 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 $which can be either 'header' or 'footer' for corresponding template
* @see function COM_startBlock
* @see function COM_endBlock
* @see function COM_showBlocks
* @see function COM_showBlock
* @return string template name
*/
function COM_getBlockTemplate( $blockname, $which )
{
global $_BLOCK_TEMPLATE, $_COM_VERBOSE;
if( $_COM_VERBOSE )
{
COM_errorLog( "_BLOCK_TEMPLATE[$blockname] = " . $_BLOCK_TEMPLATE[$blockname], 1 );
}
if( !empty( $_BLOCK_TEMPLATE[$blockname] ))
{
$templates = explode( ',', $_BLOCK_TEMPLATE[$blockname] );
if( $which == 'header' )
{
if( !empty( $templates[0] ))
{
$template = $templates[0];
}
else
{
$template = 'blockheader.thtml';
}
}
else
{
if( !empty( $templates[1] ))
{
$template = $templates[1];
}
else
{
$template = 'blockfooter.thtml';
}
}
}
else
{
if( $which == 'header' )
{
$template = 'blockheader.thtml';
}
else
{
$template = 'blockfooter.thtml';
}
}
if( $_COM_VERBOSE )
{
COM_errorLog( "Block template for the $which of $blockname is: $template", 1 );
}
return $template;
}
/**
* Gets all installed themes
*
* Gets all directory names in /path/to/geeklog/themes/ and returns all the
* directories
*
* @return array All installed themes
*/
function COM_getThemes( $all = false )
{
global $_CONF;
$index = 1;
$themes = array();
$fd = opendir( $_CONF['path_themes'] );
// If users aren't allowed to change their theme then only return the default theme
if(( $_CONF['allow_user_themes'] == 0 ) && !$all )
{
$themes[$index] = $_CONF['theme'];
}
else
{
while(( $dir = @readdir( $fd )) == TRUE )
{
if( is_dir( $_CONF['path_themes'] . $dir) && $dir <> '.' && $dir <> '..' && $dir <> 'CVS' && substr( $dir, 0 , 1 ) <> '.' )
{
clearstatcache();
$themes[$index] = $dir;
$index++;
}
}
}
return $themes;
}
/**
* 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 array $plugin_menu array of plugin menu entries, if any
*
*/
function COM_renderMenu( &$header, $plugin_menu )
{
global $_CONF, $_USER, $LANG01, $topic;
if( empty( $_CONF['menu_elements'] ))
{
$_CONF['menu_elements'] = array( // default set of links
'contribute', 'links', 'polls', 'calendar', 'search', 'stats',
'plugins' );
}
$anon = ( empty( $_USER['uid'] ) || ( $_USER['uid'] <= 1 )) ? true : false;
$allowedCounter = 0;
$counter = 0;
$num_plugins = sizeof( $plugin_menu );
if( ( $num_plugins == 0 ) && in_array( 'plugins', $_CONF['menu_elements'] ))
{
$key = array_search( 'plugins', $_CONF['menu_elements'] );
unset( $_CONF['menu_elements'][$key] );
}
if( in_array( 'custom', $_CONF['menu_elements'] ))
{
$custom_entries = array();
if( function_exists( 'CUSTOM_menuEntries' ))
{
$custom_entries = CUSTOM_menuEntries();
}
if( sizeof( $custom_entries ) == 0 )
{
$key = array_search( 'custom', $_CONF['menu_elements'] );
unset( $_CONF['menu_elements'][$key] );
}
}
$num_elements = sizeof( $_CONF['menu_elements'] );
foreach( $_CONF['menu_elements'] as $item )
{
$counter++;
$allowed = true;
$last_entry = ( $counter == $num_elements ) ? true : false;
switch( $item )
{
case 'calendar':
$url = $_CONF['site_url'] . '/calendar.php';
$label = $LANG01[74];
if( $anon && ( $_CONF['loginrequired'] ||
$_CONF['calendarloginrequired'] ))
{
$allowed = false;
}
break;
case 'contribute':
if( empty( $topic ))
{
$url = $_CONF['site_url'] . '/submit.php?type=story';
$header->set_var( 'current_topic', '' );
}
else
{
$url = $_CONF['site_url']
. '/submit.php?type=story&topic=' . $topic;
$header->set_var( 'current_topic', '&topic=' . $topic );
}
$label = $LANG01[71];
if( $anon && ( $_CONF['loginrequired'] ||
$_CONF['submitloginrequired'] ))
{
$allowed = false;
}
break;
case 'custom':
$custom_count = 0;
$custom_size = sizeof( $custom_entries );
foreach( $custom_entries as $entry )
{
$custom_count++;
if( empty( $entry['url'] ) || empty( $entry['label'] ))
{
continue;
}
$header->set_var( 'menuitem_url', $entry['url'] );
$header->set_var( 'menuitem_text', $entry['label'] );
if( $last_entry && ( $custom_count == $custom_size ))
{
$header->parse( 'menu_elements', 'menuitem_last',
true );
}
else
{
$header->parse( 'menu_elements', 'menuitem', true );
}
}
$url = '';
$label = '';
break;
case 'home':
$url = $_CONF['site_url'] . '/';
$label = $LANG01[90];
break;
case 'links':
$url = $_CONF['site_url'] . '/links.php';
$label = $LANG01[72];
if( $anon &&
( $_CONF['loginrequired'] || $_CONF['linksloginrequired'] ))
{
$allowed = false;
}
break;
case 'plugins':
for( $i = 1; $i <= $num_plugins; $i++ )
{
$header->set_var( 'menuitem_url', current( $plugin_menu ));
$header->set_var( 'menuitem_text', key( $plugin_menu ));
if( $last_entry && ( $i == $num_plugins ))
{
$header->parse( 'menu_elements', 'menuitem_last',
true );
}
else
{
$header->parse( 'menu_elements', 'menuitem', true );
}
next( $plugin_menu );
}
$url = '';
$label = '';
break;
case 'polls':
$url = $_CONF['site_url'] . '/pollbooth.php';
$label = $LANG01[73];
if( $anon &&
( $_CONF['loginrequired'] || $_CONF['pollsloginrequired'] ))
{
$allowed = false;
}
break;
case 'prefs':
$url = $_CONF['site_url'] . '/usersettings.php?mode=edit';
$label = $LANG01[48];
break;
case 'search':
$url = $_CONF['site_url'] . '/search.php';
$label = $LANG01[75];
if( $anon && ( $_CONF['loginrequired'] ||
$_CONF['searchloginrequired'] ))
{
$allowed = false;
}
break;
case 'stats':
$url = $_CONF['site_url'] . '/stats.php';
$label = $LANG01[76];
if( $anon &&
( $_CONF['loginrequired'] || $_CONF['statsloginrequired'] ))
{
$allowed = false;
}
break;
}
if( !empty( $url ) && !empty( $label ))
{
$header->set_var( 'menuitem_url', $url );
$header->set_var( 'menuitem_text', $label );
if( $last_entry )
{
$header->parse( 'menu_elements', 'menuitem_last', true );
}
else
{
$header->parse( 'menu_elements', 'menuitem', true );
}
if( $allowed )
{
if( $last_entry )
{
$header->parse( 'allowed_menu_elements', 'menuitem_last',
true );
}
else
{
$header->parse( 'allowed_menu_elements', 'menuitem', true );
}
$allowedCounter++;
}
}
}
if( $allowedCounter == 0 )
{
$header->parse( 'allowed_menu_elements', 'menuitem_none', true );
}
}
/**
* 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.
*
* -------------------------------------------------------------------------------------
* <?php
* require_once('lib-common.php');
* $display .= COM_siteHeader(); //Change to COM_siteHeader('none') to not display left blocks
* $display .= "Here is your html for display";
* $display .= COM_siteFooter(true); // Change to COM_siteFooter() to not display right blocks
* echo $display;
* ? >
* ---------------------------------------------------------------------------------------
* 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)
*
* // 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>
*
* @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>
* @return string Formatted HTML containing the site header
* @see function COM_siteFooter
*
*/
function COM_siteHeader( $what = 'menu', $pagetitle = '' )
{
global $_CONF, $_TABLES, $_USER, $LANG01, $LANG_BUTTONS, $LANG_CHARSET,
$topic, $_COM_VERBOSE, $HTTP_POST_VARS, $HTTP_GET_VARS;
// If the theme implemented this for us then call their version instead.
$function = $_CONF['theme'] . '_siteHeader';
if( function_exists( $function ))
{
return $function( $what, $pagetitle );
}
// If we reach here then either we have the default theme OR
// the current theme only needs the default variable substitutions
$header = new Template( $_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'
));
// get topic if not on home page
if( !isset( $HTTP_GET_VARS['topic'] ))
{
if( isset( $HTTP_GET_VARS['story'] ))
{
$sid = COM_applyFilter( $HTTP_GET_VARS['story'] );
}
elseif( isset( $HTTP_GET_VARS['sid'] ))
{
$sid = COM_applyFilter( $HTTP_GET_VARS['sid'] );
}
elseif( isset( $HTTP_POST_VARS['story'] ))
{
$sid = COM_applyFilter( $HTTP_POST_VARS['story'] );
}
if( !empty( $sid ))
{
$topic = DB_getItem( $_TABLES['stories'], 'tid', "sid='$sid'" );
}
}
else
{
$topic = COM_applyFilter( $HTTP_GET_VARS['topic'] );
}
if( empty( $pagetitle ) && isset( $_CONF['pagetitle'] ))
{
$pagetitle = $_CONF['pagetitle'];
}
if( empty( $pagetitle ))
{
if( empty( $topic ))
{
$pagetitle = $_CONF['site_slogan'];
}
else
{
$pagetitle = DB_getItem( $_TABLES['topics'], 'topic',
"tid = '$topic'" );
}
}
if( !empty( $pagetitle ))
{
$pagetitle = ' - ' . $pagetitle;
}
$header->set_var( 'page_title', $_CONF['site_name'] . $pagetitle );
$header->set_var( 'background_image', $_CONF['layout_url'] . '/images/bg.gif' );
$header->set_var( 'site_url', $_CONF['site_url'] );
$header->set_var( 'layout_url', $_CONF['layout_url'] );
$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'] );
$rdf = substr_replace( $_CONF['rdf_file'], $_CONF['site_url'], 0,
strlen( $_CONF['path_html'] ) - 1 );
$header->set_var( 'rdf_file', $rdf );
$header->set_var( 'rss_url', $rdf );
$msg = $LANG01[67] . ' ' . $_CONF['site_name'];
if( !empty( $_USER['username'] ))
{
$msg .= ', ' . $_USER['username'];
}
$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.gif' );
$header->set_var( 'css_url', $_CONF['layout_url'] . '/style.css' );
$header->set_var( 'theme', $_CONF['theme'] );
if( empty( $LANG_CHARSET ))
{
$charset = $_CONF['default_charset'];
if( empty( $charset ))
{
$charset = 'iso-8859-1';
}
}
else
{
$charset = $LANG_CHARSET;
}
$header->set_var( 'charset', $charset );
// 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_links', $LANG_BUTTONS[4] );
$header->set_var( 'button_polls', $LANG_BUTTONS[5] );
$header->set_var( 'button_calendar', $LANG_BUTTONS[6] );
$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] );
// 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
{
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 );
}
}
if( $_CONF['left_blocks_in_footer'] == 1 )
{
$header->set_var( 'geeklog_blocks', '' );
$header->set_var( 'left_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 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( 'geeklog_blocks', '' );
$header->set_var( 'left_blocks', '' );
}
else
{
$header->set_var( 'geeklog_blocks', $lblocks );
$header->parse( 'left_blocks', 'leftblocks', true );
}
}
// Call any plugin that may want to include extra Meta tags
// or Javascript functions
$header->set_var( 'plg_headercode', PLG_getHeaderCode() );
// Call to plugins to set template variables in the header
PLG_templateSetVars( 'header', $header );
// 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->parse( 'index_header', 'header' );
ob_start();
eval( '?>' . $tmp );
$retval = ob_get_contents();
ob_end_clean();
return $retval;
}
/**
* Returns the site footer
*
* This loads the proper templates, does variable substitution and returns the
* HTML for the site footer.
*
* @param boolean $rightblock Whether or not to show blocks on right hand side default is no
* @param array $custom An array defining custom function to be used to format Rightblocks
* @see function COM_siteHeader
* @return string Formated HTML containing site footer and optionally right blocks
*
*/
function COM_siteFooter( $rightblock = false, $custom = '' )
{
global $_CONF, $_TABLES, $LANG01, $_PAGE_TIMER, $topic;
// If the theme implemented this for us then call their version instead.
$function = $_CONF['theme'] . '_siteFooter';
if( function_exists( $function ))
{
return $function( $rightblock );
}
// Set template directory
$footer = new Template( $_CONF['path_layout'] );
// Set template file
$footer->set_file( array(
'footer' => 'footer.thtml',
'rightblocks' => 'rightblocks.thtml',
'leftblocks' => 'leftblocks.thtml'
));
// Do variable assignments
DB_change( $_TABLES['vars'], 'value', 'value + 1', 'name', 'totalhits', '', true );
$footer->set_var( 'site_url', $_CONF['site_url']);
$footer->set_var( 'layout_url',$_CONF['layout_url']);
$footer->set_var( 'site_mail', "mailto:{$_CONF['site_mail']}" );
$footer->set_var( 'site_name', $_CONF['site_name'] );
$footer->set_var( 'site_slogan', $_CONF['site_slogan'] );
$rdf = substr_replace( $_CONF['rdf_file'], $_CONF['site_url'], 0,
strlen( $_CONF['path_html'] ) - 1 );
$footer->set_var( 'rdf_file', $rdf );
$footer->set_var( 'rss_url', $rdf );
$year = date( 'Y' );
$copyrightyear = $year;
if( !empty( $_CONF['copyrightyear'] ))
{
$copyrightyear = $_CONF['copyrightyear'];
}
$footer->set_var( 'copyright_notice', ' ' . $LANG01[93] . ' © '
. $copyrightyear . ' ' . $_CONF['site_name'] . '<br> '
. $LANG01[94] );
$footer->set_var( 'copyright_msg', $LANG01[93] . ' © '
. $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 );
/* 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' );
}
}
elseif( $rightblock )
{
$rblocks = COM_showBlocks( 'right', $topic );
}
if( $rightblock && !empty( $rblocks ))
{
$footer->set_var( 'geeklog_blocks', $rblocks );
$footer->parse( 'right_blocks', 'rightblocks', true );
}
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
{
$lblocks = COM_showBlocks( 'left', $topic );
}
if( empty( $lblocks ))
{
$footer->set_var( 'geeklog_blocks', '' );
$footer->set_var( 'left_blocks', '' );
}
else
{
$footer->set_var( 'geeklog_blocks', $lblocks );
$footer->parse( 'left_blocks', 'leftblocks', true );
}
}
// 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 );
// Actually parse the template and make variable substitutions
$footer->parse( 'index_footer', 'footer' );
// Return resulting HTML
return $footer->finish( $footer->get_var( 'index_footer' ));
}
/**
* Prints out standard block header
*
* Prints out standard block header but pulling header HTML formatting from
* the database.
*
* Programming Note: The two functions COM_startBlock and COM_endBlock are used
* to sandwich your block content. These functions are not used only for blocks
* but anything that uses that format, e.g. Stats page. They are used like
* COM_siteHeader and COM_siteFooter but for internal page elements.
*
*
* @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
* @see COM_endBlock
* @see COM_siteHeader For similiar construct
* @return string Formatted HTML containing block header
*
*/
function COM_startBlock( $title='', $helpfile='', $template='blockheader.thtml' )
{
global $_CONF, $LANG01;
$block = new Template( $_CONF['path_layout'] );
$block->set_file( 'block', $template );
$block->set_var( 'site_url', $_CONF['site_url'] );
$block->set_var( 'layout_url', $_CONF['layout_url'] );
$block->set_var( 'block_title', stripslashes( $title ));
if( !empty( $helpfile ))
{
if( !stristr( $helpfile, 'http://' ))
{
$help = '<a class="blocktitle" href="' . $_CONF['site_url'] . '/help/' . $helpfile
. '" target="_blank"><img src="' . $_CONF['layout_url']
. '/images/button_help.gif" border="0" alt="?"></a>';
}
else
{
$help = '<a class="blocktitle" href="' . $helpfile
. '" target="_blank"><img src="' . $_CONF['layout_url']
. '/images/button_help.gif" border="0" alt="?"></a>';
}
$block->set_var( 'block_help', $help );
}
$block->parse( 'startHTML', 'block' );
return $block->finish( $block->get_var( 'startHTML' ));
}
/**
* Closes out COM_startBlock
*
* @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' )
{
global $_CONF;
$block = new Template( $_CONF['path_layout'] );
$block->set_file( 'block', $template );
$block->set_var( 'site_url', $_CONF['site_url'] );
$block->set_var( 'layout_url', $_CONF['layout_url'] );
$block->parse( 'endHTML', 'block' );
return $block->finish( $block->get_var( 'endHTML' ));
}
/**
* Creates a <option> list from a database list for use in forms
*
* Creates option list form field using given arguments
*
* @param string $table Database Table to get data from
* @param string $selection Comma delimited string of fields to pull The first field is the value of the option 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 string $where Optional WHERE clause to use in the SQL Selection
* @see function COM_checkList
* @return string Formated HTML of option values
*
*/
function COM_optionList( $table, $selection, $selected='', $sortcol=1, $where='' )
{
$retval = '';
$tmp = str_replace( 'DISTINCT ', '', $selection );
$select_set = explode( ',', $tmp );
$sql = "SELECT $selection FROM $table";
if( $where != '' )
{
$sql .= " WHERE $where";
}
$sql .= " ORDER BY {$select_set[$sortcol]}";
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
for( $i = 0; $i < $nrows; $i++ )
{
$A = DB_fetchArray( $result, true );
$retval .= '<option value="' . $A[0] . '"';
if( is_array( $selected ) AND count( $selected ) > 0 )
{
foreach( $selected as $selected_item )
{
if( $A[0] == $selected_item )
{
$retval .= ' selected="selected"';
}
}
}
elseif( !is_array( $selected ) AND $A[0] == $selected )
{
$retval .= ' selected="selected"';
}
$retval .= '>' . $A[1] . '</option>' . LB;
}
return $retval;
}
/**
* Create and return a list of available topics
*
* This is a variation of COM_optionList() from lib-common.php. It will add
* only those topics to the option list which are accessible by the current
* user.
*
* @param string $selection Comma delimited string of fields to pull The first field is the value of the option and the second is the label to be displayed. This is used in a SQL statement and can include DISTINCT to start.
* @param string $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)
* @see function COM_optionList
* @return string Formated HTML of option values
*
*/
function COM_topicList( $selection, $selected='', $sortcol=1 )
{
global $_TABLES;
$retval = '';
$tmp = str_replace( 'DISTINCT ', '', $selection );
$select_set = explode( ',', $tmp );
$result = DB_query( "SELECT * FROM {$_TABLES['topics']}" . COM_getPermSQL()
. " ORDER BY $select_set[$sortcol]" );
$nrows = DB_numRows( $result );
for( $i = 0; $i < $nrows; $i++ )
{
$A = DB_fetchArray( $result, true );
$retval .= '<option value="' . $A[0] . '"';
if( $A[0] == $selected )
{
$retval .= ' selected';
}
$retval .= '>' . stripslashes( $A[1] ) . '</option>' . LB;
}
return $retval;
}
/**
* Creates a <input> checklist from a database list for use in forms
*
* Creates a group of checkbox form fields with given arguments
*
* @param string $table DB Table to pull data from
* @param string $selection Comma delimited list of fields to pull from table
* @param string $where Where clause of SQL statement
* @param string $selected Value to set to CHECKED
* @see function COM_optionList
* @return string HTML with Checkbox code
*
*/
function COM_checkList( $table, $selection, $where='', $selected='' )
{
global $_TABLES, $_COM_VERBOSE;
$retval = '';
$sql = "SELECT $selection FROM $table";
if( !empty( $where ))
{
$sql .= " WHERE $where";
}
$result = DB_query( $sql );
$nrows = DB_numRows( $result );
if( !empty( $selected ))
{
if( $_COM_VERBOSE )
{
COM_errorLog( "exploding selected array: $selected in COM_checkList", 1 );
}
$S = explode( ' ', $selected );
}
else
{
if( $_COM_VERBOSE)
{
COM_errorLog( 'selected string was empty COM_checkList', 1 );
}
$S = array();
}
for( $i = 0; $i < $nrows; $i++ )
{
$access = true;
$A = DB_fetchArray( $result, true );
if( $table == $_TABLES['topics'] AND SEC_hasTopicAccess( $A['tid'] ) == 0 )
{
$access = false;
}
if( $access )
{
$retval .= '<input type="checkbox" name="' . $table . '[]" value="' . $A[0] . '"';
for( $x = 0; $x < sizeof( $S ); $x++ )
{
if( $A[0] == $S[$x] )
{
$retval .= ' checked="checked"';
}
}
if(( $table == $_TABLES['blocks'] ) && isset( $A[2] ) && ( $A[2] == 'gldefault' ))
{
$retval .= '><b>' . stripslashes( $A[1] ) . '</b><br>' . LB;
}
else
{
$retval .= '>' . stripslashes( $A[1] ) . '<br>' . LB;
}
}
}
return $retval;
}
/**
* Prints out an associative array for debugging
*
* The core of this code has been lifted from phpweblog which is licenced
* under the GPL. This is not used very much in the code but you can use it
* if you see fit
*
* @param array $A Array to loop through and print values for
* @return string Formated HTML List
*
*/
function COM_debug( $A )
{
if( !empty( $A ))
{
$retval .= LB . '<pre><p>---- DEBUG ----</p>';
for( reset( $A ); $k = key( $A ); next( $A ))
{
$retval .= sprintf( "<li>%13s [%s]</li>n", $k, $A[$k] );
}
$retval .= '<p>---------------</p></pre>' . LB;
}
return $retval;
}
/**
*
* Checks to see if RDF file needs updating and updates it if so.
* Checks to see if we need to update the RDF as a result
* of an article with a future publish date reaching it's
* publish time and if so updates the RDF file.
*
* @see file lib-syndication.php
*
*/
function COM_rdfUpToDateCheck()
{
global $_CONF, $_TABLES;
if( $_CONF['backend'] > 0 )
{
$result = DB_query( "SELECT fid,type,topic,limits,update_info FROM {$_TABLES['syndication']} WHERE is_enabled = 1" );
$num = DB_numRows( $result );
for( $i = 0; $i < $num; $i++)
{
$A = DB_fetchArray( $result );
$is_current = true;
if( $A['type'] == 'geeklog' )
{
$is_current = SYND_feedUpdateCheck( $A['type'], $A['fid'],
$A['topic'], $A['update_info'], $A['limits'] );
}
else
{
$is_current = PLG_feedUpdateCheck( $A['type'], $A['fid'],
$A['topic'], $A['update_info'], $A['limits'] );
}
if( !$is_current )
{
SYND_updateFeed( $A['fid'] );
}
}
}
}
/**
* Checks and Updates the featured status of all articles.
*
* Checks to see if any articles that were published for the future have been
* published and, if so, will see if they are featured. If they are featured,
* this will set old featured article (if there is one) to normal
*
*/
function COM_featuredCheck()
{
global $_TABLES;
$curdate = date( "Y-m-d H:i:s", time() );
if( DB_getItem( $_TABLES['stories'], 'count(*)', "featured = 1 AND draft_flag = 0 AND date <= '$curdate'" ) > 1 )
{
// OK, we have two featured stories, fix that
$sid = DB_getItem( $_TABLES['stories'], 'sid', "featured = 1 AND draft_flag = 0 ORDER BY date LIMIT 1" );
DB_query( "UPDATE {$_TABLES['stories']} SET featured = 0 WHERE sid = '$sid'" );
}
}
/**
*
* Logs messages to error.log or the web page or both
*
* Prints a well formatted message to either the web page, error log
* or both.
*
* @param string $logentry Text to log to error log
* @param int $actionid 1 = write to log file, 2 = write to screen (default) both
* @see function COM_accessLog
* @return string If $actionid = 2 or '' then HTML formatted string (wrapped in block) else nothing
*
*/
function COM_errorLog( $logentry, $actionid = '' )
{
global $_CONF, $LANG01;
$retval = '';
if( !empty( $logentry ))
{
$timestamp = strftime( '%c' );
switch( $actionid )
{
case 1:
$logfile = $_CONF['path_log'] . 'error.log';
if( !$file = fopen( $logfile, 'a' ))
{
$retval .= $LANG01[33] . ' ' . $logfile . ' (' . $timestamp . ')<br>' . LB;
}
else
{
fputs( $file, "$timestamp - $logentry n" );
}
break;
case 2:
$retval .= COM_startBlock( $LANG01[55] . ' ' . $timestamp, '',
COM_getBlockTemplate( '_msg_block', 'header' ))
. nl2br( $logentry )
. COM_endBlock( COM_getBlockTemplate( '_msg_block',
'footer' ));
break;
default:
$logfile = $_CONF['path_log'] . 'error.log';
if( !$file = fopen( $logfile, 'a' ))
{
$retval .= $LANG01[33] . ' ' . $logfile . ' (' . $timestamp . ')<br>' . LB;
}
else
{
fputs( $file, "$timestamp - $logentry n" );
$retval .= COM_startBlock( $LANG01[34] . ' - ' . $timestamp,
'', COM_getBlockTemplate( '_msg_block',
'header' ))
. nl2br( $logentry )
. COM_endBlock( COM_getBlockTemplate( '_msg_block',
'footer' ));
}
break;
}
}
return $retval;
}
/**
* Logs message to access.log
*
* This will print a message to the Geeklog access log
*
* @param string $string Message to write to access log
* @see COM_errorLog
*
*/
function COM_accessLog( $logentry )
{
global $_CONF, $_USER, $LANG01, $HTTP_SERVER_VARS;
$retval = '';
$timestamp = strftime( '%c' );
$logfile = $_CONF['path_log'] . 'access.log';
if( !$file = fopen( $logfile, 'a' ))
{
return $LANG01[33] . $logfile . ' (' . $timestamp . ')<br>' . LB;
}
if( isset( $_USER['uid'] ))
{
$byuser = $_USER['uid'] . '@' . $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
else
{
$byuser = 'anon@' . $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
fputs( $file, "$timestamp ($byuser) - $logentryn" );
return $retval;
}
/**
* Shows a poll form
*
* Shows an HTML formatted poll for the given question ID
*
* @param string $qid ID for poll question
* @see function COM_pollResults
* @see function COM_showPoll
* @return string HTML Formatted Poll
*
*/
function COM_pollVote( $qid )
{
global $_CONF, $_TABLES, $LANG01, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS;
$retval = '';
$question = DB_query( "SELECT question,voters,commentcode,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['pollquestions']} WHERE qid='$qid'" );
$Q = DB_fetchArray( $question );
if( SEC_hasAccess( $Q['owner_id'], $Q['group_id'], $Q['perm_owner'], $Q['perm_group'], $Q['perm_members'], $Q['perm_anon'] ) == 0 )
{
return $retval;
}
$nquestion = DB_numRows( $question );
$fields = array( 'ipaddress', 'qid' );
$values = array( $HTTP_SERVER_VARS['REMOTE_ADDR'], $qid );
$id = DB_count( $_TABLES['pollvoters'], $fields, $values );
if( empty( $HTTP_COOKIE_VARS[$qid] ) && $id == 0 )
{
if( $nquestion == 1 )
{
$answers = DB_query( "SELECT answer,aid FROM {$_TABLES['pollanswers']} WHERE qid='$qid' ORDER BY aid" );
$nanswers = DB_numRows( $answers );
if( $nanswers > 0 )
{
$poll = new Template( $_CONF['path_layout'] . 'pollbooth' );
$poll->set_file( array( 'panswer' => 'pollanswer.thtml',
'block' => 'pollblock.thtml',
'comments' => 'pollcomments.thtml' ));
$poll->set_var( 'site_url', $_CONF['site_url'] );
$poll->set_var( 'layout_url', $_CONF['layout_url'] );
$poll->set_var( 'poll_question', $Q['question'] );
$poll->set_var( 'poll_id', $qid );
$poll->set_var( 'num_votes', $Q['voters'] );
$poll->set_var( 'poll_vote_url', $_CONF['site_url']
. '/pollbooth.php');
$poll->set_var( 'poll_results_url', $_CONF['site_url']
. '/pollbooth.php?qid=' . $qid . '&aid=-1');
$poll->set_var( 'lang_vote', $LANG01[56] );
$poll->set_var( 'lang_votes', $LANG01[8] );
$poll->set_var( 'lang_results', $LANG01[6] );
for( $i = 1; $i <= $nanswers; $i++ )
{
$A = DB_fetchArray( $answers );
$poll->set_var( 'answer_id', $A['aid'] );
$poll->set_var( 'answer_text', $A['answer'] );
$poll->parse( 'poll_answers', 'panswer', true );
}
if( $Q['commentcode'] >= 0 )
{
$poll->set_var( 'num_comments',
DB_count( $_TABLES['comments'], 'sid', $qid ));
$poll->set_var( 'lang_comments', $LANG01[3] );
$poll->set_var( 'poll_comments_url', $_CONF['site_url'] .
'/pollbooth.php?qid=' . $qid . '&aid=-1#comments');
$poll->parse( 'poll_comments', 'comments', true );
}
else
{
$poll->set_var( 'poll_comments', '' );
$poll->set_var( 'poll_comments_url', '' );
}
$title = DB_getItem( $_TABLES['blocks'], 'title',
"name='poll_block'" );
$retval = COM_startBlock( $title, '',
COM_getBlockTemplate( 'poll_block', 'header' ))
. $poll->finish( $poll->parse( 'output', 'block' ))
. COM_endBlock( COM_getBlockTemplate( 'poll_block', 'footer' )) . LB;
}
}
}
else
{
$retval .= COM_pollResults( $qid );
}
return $retval;
}
/**
* This shows a poll
*
* This will determine if a user needs to see the poll form OR the poll
* result.
*
* @param int $sise Size in pixels of poll results
* @param string $qid Question ID to show (optional)
* @see function COM_pollVote
* @see function COM_pollResults
* @return String HTML Formated string of Poll
*
*/
function COM_showPoll( $size, $qid='' )
{
global $_CONF, $_TABLES, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS;
$retval = '';
DB_query( "DELETE FROM {$_TABLES['pollvoters']} WHERE date < unix_timestamp() - {$_CONF['polladdresstime']}" );
if( !empty( $qid ))
{
$pcount = DB_count( $_TABLES['pollvoters'], array( 'ipaddress', 'qid' ),
array( $HTTP_SERVER_VARS['REMOTE_ADDR'], $qid ));
if( empty( $HTTP_COOKIE_VARS[$qid]) && $pcount == 0 )
{
$retval .= COM_pollVote( $qid );
}
else
{
$retval .= COM_pollResults( $qid, $size );
}
}
else
{
$result = DB_query( "SELECT qid from {$_TABLES['pollquestions']} WHERE display = 1 ORDER BY date DESC" );
$nrows = DB_numRows( $result );
if( $nrows > 0 )
{
for( $i = 1; $i <= $nrows; $i++ )
{
$Q = DB_fetchArray( $result );
$qid = $Q['qid'];
$id = array( 'ipaddress', 'qid' );
$value = array( $HTTP_SERVER_VARS['REMOTE_ADDR'], $qid );
$pcount = DB_count( $_TABLES['pollvoters'], $id, $value );
if( !isset( $HTTP_COOKIE_VARS[$qid]) && $pcount == 0 )
{
$retval .= COM_pollVote( $qid );
}
else
{
$retval .= COM_pollResults( $qid, $size );
}
}
}
}
return $retval;
}
/**
* Shows the results of a poll
*
* Shows the poll results for a give poll question
*
* @param string $qid ID for poll question to show
* @param int $scale Size in pixels to scale formatted results to
* @param string $order 'ASC' or 'DESC' for Comment ordering (SQL statment ordering)
* @param string $mode Comment Mode possible values 'nocomment', 'flat', 'nested', 'threaded'
* @see COM_pollVote
* @see COM_showPoll
* @return string HTML Formated Poll Results
*
*/
function COM_pollResults( $qid, $scale=400, $order='', $mode='' )
{
global $_TABLES, $LANG01, $LANG07, $_CONF, $_COM_VERBOSE;
$retval = '';
$question = DB_query( "SELECT question,voters,commentcode,owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['pollquestions']} WHERE qid='$qid'" );
$Q = DB_fetchArray( $question );
if( SEC_hasAccess( $Q['owner_id'], $Q['group_id'], $Q['perm_owner'], $Q['perm_group'], $Q['perm_members'], $Q['perm_anon']) == 0 )
{
return $retval;
}
$nquestion = DB_numRows( $question );
if( $nquestion == 1 )
{
if( $_CONF['answerorder'] == 'voteorder' )
{
$answers = DB_query( "SELECT votes,answer FROM {$_TABLES['pollanswers']} WHERE qid='$qid' ORDER BY votes DESC" );
}
else
{
$answers = DB_query( "SELECT votes,answer FROM {$_TABLES['pollanswers']} WHERE qid='$qid' ORDER BY aid" );
}
$nanswers = DB_numRows( $answers );
if( $_COM_VERBOSE )
{
COM_errorLog( "got $answers answers in COM_pollResults", 1 );
}
if( $nanswers > 0 )
{
$title = DB_getItem( $_TABLES['blocks'], 'title', "name='poll_block'" );
if( $scale < 120 ) // assume we're in the poll block
{
$retval .= COM_startBlock( $title, '',
COM_getBlockTemplate( 'poll_block', 'header' ));
}
else // assume we're in pollbooth.php
{
$retval .= COM_startBlock( $title );
}
$poll = new Template( $_CONF['path_layout'] . 'pollbooth' );
$poll->set_file( array( 'result' => 'pollresult.thtml',
'comments' => 'pollcomments.thtml',
'votes_bar' => 'pollvotes_bar.thtml',
'votes_num' => 'pollvotes_num.thtml' ));
$poll->set_var( 'site_url', $_CONF['site_url'] );
$poll->set_var( 'layout_url', $_CONF['layout_url'] );
$poll->set_var( 'poll_question', $Q['question'] );
$poll->set_var( 'poll_id', $qid );
$poll->set_var( 'num_votes', $Q['voters'] );
$poll->set_var( 'lang_votes', $LANG01[8] );
for( $i = 1; $i <= $nanswers; $i++ )
{
$A = DB_fetchArray( $answers );
if( $Q['voters'] == 0 )
{
$percent = 0;
}
else
{
$percent = $A['votes'] / $Q['voters'];
}
$poll->set_var( 'answer_text', $A['answer'] );
$poll->set_var( 'answer_counter', $i );
$poll->set_var( 'answer_odd', (( $i - 1 ) % 2 ));
$poll->set_var( 'answer_num', $A['votes'] );
$poll->set_var( 'answer_percent',
sprintf( '%.2f', $percent * 100 ));
if( $scale < 120 )
{
$poll->parse( 'poll_votes', 'votes_num', true );
}
else
{
$width = $percent * $scale;
$poll->set_var( 'bar_width', $width );
$poll->parse( 'poll_votes', 'votes_bar', true );
}
}
if( $Q['commentcode'] >= 0 )
{
$poll->set_var( 'num_comments',
DB_count( $_TABLES['comments'], 'sid', $qid ));
$poll->set_var( 'lang_comments', $LANG01[3] );
$poll->set_var( 'poll_comments_url', $_CONF['site_url'] .
'/pollbooth.php?qid=' . $qid . '&aid=-1#comments');
$poll->parse( 'poll_comments', 'comments', true );
}
else
{
$poll->set_var( 'poll_comments_url', '' );
$poll->set_var( 'poll_comments', '' );
}
$poll->set_var( 'lang_pollquestions', $LANG07[6] );
$retval .= $poll->finish( $poll->parse( 'output', 'result' ));
if( $scale < 120)
{
$retval .= COM_endBlock( COM_getBlockTemplate( 'poll_block',
'footer' ));
}
else
{
$retval .= COM_endBlock();
}
if( $scale > 399 && $Q['commentcode'] >= 0 )
{
$delete_option = ( SEC_hasRights( 'poll.edit' ) &&
SEC_hasAccess( $Q['owner_id'], $Q['group_id'],
$Q['perm_owner'], $Q['perm_group'], $Q['perm_members'],
$Q['perm_anon'] ) == 3 ? true : false );
$retval .= COM_userComments( $qid, $Q['question'], 'poll',
$order, $mode, 0, 1, false, $delete_option );
}
}
}
return $retval;
}
/**
* Shows all available topics
*
* Show the topics in the system the user has access to and prints them in HTML.
* This function is used to show the topics in the sections block.
*
* @param string $topic TopicID of currently selected
* @return string HTML formatted topic list
*
*/
function COM_showTopics( $topic='' )
{
global $_CONF, $_TABLES, $_USER, $LANG01, $HTTP_SERVER_VARS,
$_THEME_URL, $_BLOCK_TEMPLATE, $page, $newstories;
$sql = "SELECT tid,topic,imageurl FROM {$_TABLES['topics']}";
if( $_USER['uid'] > 1 )
{
$tids = DB_getItem( $_TABLES['userindex'], 'tids',
"uid = '{$_USER['uid']}'" );
if( !empty( $tids ))
{
$sql .= " WHERE (tid NOT IN ('" . str_replace( ' ', "','", $tids )
. "'))" . COM_getPermSQL( 'AND' );
}
else
{
$sql .= COM_getPermSQL();
}
}
else
{
$sql .= COM_getPermSQL();
}
if( $_CONF['sortmethod'] == 'alpha' )
{
$sql .= ' ORDER BY topic ASC';
}
else
{
$sql .= ' ORDER BY sortnum';
}
$result = DB_query( $sql );
$retval = '';
$sections = new Template( $_CONF['path_layout'] );
if( isset( $_BLOCK_TEMPLATE['topicoption'] ))
{
$templates = explode( ',', $_BLOCK_TEMPLATE['topicoption'] );
$sections->set_file( array( 'option' => $templates[0],
'current' => $templates[1] ));
}
else
{
$sections->set_file( array( 'option' => 'topicoption.thtml',
'inactive' => 'topicoption_off.thtml' ));
}
$sections->set_var( 'site_url', $_CONF['site_url'] );
$sections->set_var( 'layout_url', $_CONF['layout_url'] );
$sections->set_var( 'block_name', str_replace( '_', '-', 'section_block' ));
if( $_CONF['hide_home_link'] == 0 )
{
// Give a link to the homepage here since a lot of people use this for
// navigating the site
if( COM_isFrontpage() )
{
$sections->set_var( 'option_url',
$_CONF['site_url'] . '/index.php' );
$sections->set_var( 'option_label', $LANG01[90] );
$sections->set_var( 'option_count', '' );
$sections->set_var( 'topic_image', '' );
$retval .= $sections->parse( 'item', 'option' );
}
else
{
$sections->set_var( 'option_url', '' );
$sections->set_var( 'option_label', $LANG01[90] );
$sections->set_var( 'option_count', '' );
$sections->set_var( 'topic_image', '' );
$retval .= $sections->parse( 'item', 'inactive' );
}
}
if( $_CONF['showstorycount'] )
{
$sql = "SELECT tid, count(*) AS count FROM {$_TABLES['stories']} "
. 'WHERE (draft_flag = 0) AND (date <= NOW()) '
. COM_getPermSQL( 'AND' )
. ' GROUP BY tid';
$rcount = DB_query( $sql );
while( $C = DB_fetchArray( $rcount ))
{
$storycount[$C['tid']] = $C['count'];
}
}
if( $_CONF['showsubmissioncount'] )
{
$sql = "SELECT tid, count(*) AS count FROM {$_TABLES['storysubmission']} "
. ' GROUP BY tid';
$rcount = DB_query( $sql );
while( $C = DB_fetchArray( $rcount ))
{
$submissioncount[$C['tid']] = $C['count'];
}
}
while( $A = DB_fetchArray( $result ) )
{
$topicname = stripslashes( $A['topic'] );
$sections->set_var( 'option_url', $_CONF['site_url']
. '/index.php?topic=' . $A['tid'] );
$sections->set_var( 'option_label', $topicname );
$countstring = '';
if( $_CONF['showstorycount'] || $_CONF['showsubmissioncount'] )
{
$countstring .= '(';
if( $_CONF['showstorycount'] )
{
if( empty( $storycount[$A['tid']] ))
{
$countstring .= 0;
}
else
{
$countstring .= $storycount[$A['tid']];
}
}
if( $_CONF['showsubmissioncount'] )
{
if( $_CONF['showstorycount'] )
{
$countstring .= '/';
}
if( empty( $submissioncount[$A['tid']] ) ) {
$countstring .= 0;
} else {
$countstring .= $submissioncount[$A['tid']];
}
}
$countstring .= ')';
}
$sections->set_var( 'option_count', $countstring );
$topicimage = '';
if( !empty( $A['imageurl'] ))
{
if( isset( $_THEME_URL ))
{
$imagebase = $_THEME_URL;
}
else
{
$imagebase = $_CONF['site_url'];
}
$topicimage = '<img src="' . $imagebase . $A['imageurl'] . '" alt="'
. $topicname . '" title="' . $topicname . '">';
}
$sections->set_var( 'topic_image', $topicimage );
if(( $A['tid'] == $topic ) && ( $page == 1 ))
{
$retval .= $sections->parse( 'item', 'inactive' );
}
else
{
$retval .= $sections->parse( 'item', 'option' );
}
}
return $retval;
}
/**
* Shows the user their menu options
*
* This shows the average joe use their menu options. This is the user block on right side
*
* @param string $help Help file to show
* @param string $title Title of Menu
* @see function COM_adminMenu
*
*/
function COM_userMenu( $help='', $title='' )
{
global $_TABLES, $_USER, $_CONF, $LANG01, $_BLOCK_TEMPLATE, $HTTP_SERVER_VARS;
$retval = '';
if( $_USER['uid'] > 1 )
{
$usermenu = new Template( $_CONF['path_layout'] );
if( isset( $_BLOCK_TEMPLATE['useroption'] ))
{
$templates = explode( ',', $_BLOCK_TEMPLATE['useroption'] );
$usermenu->set_file( array( 'option' => $templates[0],
'current' => $templates[1] ));
}
else
{
$usermenu->set_file( array( 'option' => 'useroption.thtml',
'current' => 'useroption_off.thtml' ));
}
$usermenu->set_var( 'site_url', $_CONF['site_url'] );
$usermenu->set_var( 'layout_url', $_CONF['layout_url'] );
$usermenu->set_var( 'block_name', str_replace( '_', '-', 'user_block' ));
if( empty( $title ))
{
$title = DB_getItem( $_TABLES['blocks'], 'title', "name='user_block'" );
}
// what's our current URL?
$thisUrl = COM_getCurrentURL();
$retval .= COM_startBlock( $title, $help,
COM_getBlockTemplate( 'user_block', 'header' ));
if( $_CONF['personalcalendars'] == 1 )
{
$url = $_CONF['site_url'] . '/calendar.php?mode=personal';
$usermenu->set_var( 'option_label', $LANG01[66] );
$usermenu->set_var( 'option_count', '' );
$usermenu->set_var( 'option_url', $url );
if( $thisUrl == $url )
{
$retval .= $usermenu->parse( 'item', 'current' );
}
else
{
$retval .= $usermenu->parse( 'item', 'option' );
}
}
// This function will show the user options for all installed plugins
// (if any)
$plugin_options = PLG_getUserOptions();
$nrows = count( $plugin_options );
for( $i = 1; $i <= $nrows; $i++ )
{
$plg = current( $plugin_options );
$usermenu->set_var( 'option_label', $plg->adminlabel );
if( !empty( $plg->numsubmissions ))
{
$usermenu->set_var( 'option_count', '(' . $plg->numsubmissions . ')' );
}
else
{
$usermenu->set_var( 'option_count', '' );
}
$usermenu->set_var( 'option_url', $plg->adminurl );
if( $thisUrl == $plg->adminurl )
{
$retval .= $usermenu->parse( 'item', 'current' );
}
else
{
$retval .= $usermenu->parse( 'item', 'option' );
}
next( $plugin_options );
}
$url = $_CONF['site_url'] . '/usersettings.php?mode=edit';
$usermenu->set_var( 'option_label', $LANG01[48] );
$usermenu->set_var( 'option_count', '' );
$usermenu->set_var( 'option_url', $url );
if( $thisUrl == $url )
{
$retval .= $usermenu->parse( 'item', 'current' );
}
else
{
$retval .= $usermenu->parse( 'item', 'option' );
}
$url = $_CONF['site_url'] . '/usersettings.php?mode=preferences';
$usermenu->set_var( 'option_label', $LANG01[49] );
$usermenu->set_var( 'option_count', '' );
$usermenu->set_var( 'option_url', $url );
if( $thisUrl == $url )
{
$retval .= $usermenu->parse( 'item', 'current' );
}
else
{
$retval .= $usermenu->parse( 'item', 'option' );
}
$url = $_CONF['site_url'] . '/users.php?mode=logout';
$usermenu->set_var( 'option_label', $LANG01[19] );
$usermenu->set_var( 'option_count', '' );
$usermenu->set_var( 'option_url', $url );
$retval .= $usermenu->parse( 'item', 'option' );
$retval .= COM_endBlock( COM_getBlockTemplate( 'user_block', 'footer' ));
}
else
{
$retval .= COM_startBlock( $LANG01[47], $help,
COM_getBlockTemplate( 'user_block', 'header' ));
$login = new Template( $_CONF['path_layout'] );
$login->set_file( 'form', 'loginform.thtml' );
$login->set_var( 'site_url', $_CONF['site_url'] );
$login->set_var( 'layout_url', $_CONF['layout_url'] );
$login->set_var( 'lang_username', $LANG01[21] );
$login->set_var( 'lang_password', $LANG01[57] );
$login->set_var( 'lang_login', $LANG01[58] );
$login->set_var( 'lang_signup', $LANG01[59] );
$retval .= $login->parse( 'output', 'form' );
$retval .= COM_endBlock( COM_getBlockTemplate( 'user_block', 'footer' ));
}
return $retval;
}
/**
* Prints administration menu
*
* This will return the administration menu items that the user has
* sufficient rights to -- Admin Block on right side.
*
* @param string $help Help file to show
* @param string $title Menu Title
* @see function COM_userMenu
*
*/
function COM_adminMenu( $help = '', $title = '' )
{
global $_TABLES, $_USER, $_CONF, $LANG01, $_BLOCK_TEMPLATE, $LANG_PDF, $HTTP_SERVER_VARS;
$retval = '';
if( empty( $_USER['username'] ))
{
return $retval;
}
$plugin_options = PLG_getAdminOptions();
$nrows = count( $plugin_options );
if( SEC_isModerator() OR SEC_hasrights( 'story.edit,block.edit,topic.edit,link.edit,event.edit,poll.edit,user.edit,plugin.edit,user.mail', 'OR' ) OR ( $nrows > 0 ))
{
// what's our current URL?
$thisUrl = COM_getCurrentURL();
$adminmenu = new Template( $_CONF['path_layout'] );
if( isset( $_BLOCK_TEMPLATE['adminoption'] ))
{
$templates = explode( ',', $_BLOCK_TEMPLATE['adminoption'] );
$adminmenu->set_file( array( 'option' => $templates[0],
'current' => $templates[1] ));
}
else
{
$adminmenu->set_file( array( 'option' => 'adminoption.thtml',
'current' => 'adminoption_off.thtml' ));
}
$adminmenu->set_var( 'site_url', $_CONF['site_url'] );
$adminmenu->set_var( 'layout_url', $_CONF['layout_url'] );
$adminmenu->set_var( 'block_name', str_replace( '_', '-', 'admin_block' ));
if( empty( $title ))
{
$title = DB_getItem( $_TABLES['blocks'], 'title',
"name = 'admin_block'" );
}
$retval .= COM_startBlock( $title, $help,
COM_getBlockTemplate( 'admin_block', 'header' ));
$topicsql = '';
if( SEC_isModerator() || SEC_hasrights( 'story.edit' ))
{
$tresult = DB_query( "SELECT tid FROM {$_TABLES['topics']}"
. COM_getPermSQL() );
$trows = DB_numRows( $tresult );
if( $trows > 0 )
{
$tids = array();
for( $i = 0; $i < $trows; $i++ )
{
$T = DB_fetchArray( $tresult );
$tids[] = $T['tid'];
}
if( sizeof( $tids ) > 0 )
{
$topicsql = " (tid IN ('" . implode( "','", $tids ) . "'))";
}
}
}
if( SEC_isModerator() || (( $_CONF['usersubmission'] == 1 ) && SEC_hasRights( 'user.edit,user.delete' )))
{
$num = 0;
if( SEC_hasrights( 'story.edit' ))
{
if( empty( $topicsql ))
{
$num += DB_count( $_TABLES['storysubmission'] );
}
else
{
$sresult = DB_query( "SELECT COUNT(*) AS count FROM {$_TABLES['storysubmission']} WHERE" . $topicsql );
$S = DB_fetchArray( $sresult );
$num += $S['count'];
}
if( $_CONF['listdraftstories'] == 1 )
{
$sql = "SELECT COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (draft_flag = 1)";
if( !empty( $topicsql ))
{
$sql .= ' AND' . $topicsql;
}
$result = DB_query( $sql . COM_getPermSQL( 'AND', 0, 3 ));
$A = DB_fetchArray( $result );
$num += $A['count'];
}
}
if( SEC_hasrights( 'event.edit' ))
{
$num += DB_count( $_TABLES['eventsubmission'] );
}
if( SEC_hasrights( 'link.edit' ))
{
$num += DB_count( $_TABLES['linksubmission'] );
}
if( $_CONF['usersubmission'] == 1 )
{
if( SEC_hasrights( 'user.edit' ) && SEC_hasrights( 'user.delete' ))
{
$emptypwd = md5( '' );
$num += DB_count( $_TABLES['users'], 'passwd', $emptypwd );
}
}
// now handle submissions for plugins
$num = $num + PLG_getSubmissionCount();
$url = $_CONF['site_admin_url'] . '/moderation.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[10] );
$adminmenu->set_var( 'option_count', $num );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'story.edit' ))
{
$url = $_CONF['site_admin_url'] . '/story.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[11] );
if( empty( $topicsql ))
{
$numstories = DB_count( $_TABLES['stories'] );
}
else
{
$nresult = DB_query( "SELECT COUNT(*) AS count from {$_TABLES['stories']} WHERE" . $topicsql );
$N = DB_fetchArray( $nresult );
$numstories = $N['count'];
}
$adminmenu->set_var( 'option_count', $numstories );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'block.edit' ))
{
$url = $_CONF['site_admin_url'] . '/block.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[12] );
$adminmenu->set_var( 'option_count', DB_count( $_TABLES['blocks'] ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'topic.edit' ))
{
$url = $_CONF['site_admin_url'] . '/topic.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[13] );
$adminmenu->set_var( 'option_count', DB_count( $_TABLES['topics'] ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'link.edit' ))
{
$url = $_CONF['site_admin_url'] . '/link.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[14] );
$adminmenu->set_var( 'option_count', DB_count( $_TABLES['links'] ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'event.edit' ))
{
$url = $_CONF['site_admin_url'] . '/event.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[15] );
$adminmenu->set_var( 'option_count', DB_count( $_TABLES['events'] ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'poll.edit' ))
{
$url = $_CONF['site_admin_url'] . '/poll.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[16] );
$adminmenu->set_var( 'option_count', DB_count( $_TABLES['pollquestions'] ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'user.edit' ))
{
$url = $_CONF['site_admin_url'] . '/user.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[17] );
$adminmenu->set_var( 'option_count', ( DB_count( $_TABLES['users'] ) -1 ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'group.edit' ))
{
$thisUsersGroups = SEC_getUserGroups();
$grp_list = implode( ',', $thisUsersGroups );
$result = DB_query( "SELECT COUNT(*) AS count FROM {$_TABLES['groups']} WHERE grp_id IN ($grp_list)" );
$A = DB_fetchArray( $result );
$url = $_CONF['site_admin_url'] . '/group.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[96] );
$adminmenu->set_var( 'option_count', $A['count'] );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'user.mail' ))
{
$url = $_CONF['site_admin_url'] . '/mail.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[105] );
$adminmenu->set_var( 'option_count', 'N/A' );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if(( $_CONF['backend'] == 1 ) && SEC_inGroup( 'Root' ))
{
$url = $_CONF['site_admin_url'] . '/syndication.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[38] );
$count = DB_count( $_TABLES['syndication'] );
$adminmenu->set_var( 'option_count', $count );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( SEC_hasrights( 'plugin.edit' ))
{
$url = $_CONF['site_admin_url'] . '/plugins.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[77] );
$adminmenu->set_var( 'option_count', DB_count( $_TABLES['plugins'] ));
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
// This will show the admin options for all installed plugins (if any)
for( $i = 1; $i <= $nrows; $i++ )
{
$plg = current( $plugin_options );
$adminmenu->set_var( 'option_url', $plg->adminurl );
$adminmenu->set_var( 'option_label', $plg->adminlabel );
if( empty( $plg->numsubmissions ))
{
$adminmenu->set_var( 'option_count', 'N/A' );
}
else
{
$adminmenu->set_var( 'option_count', $plg->numsubmissions );
}
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $plg->adminurl ) ? 'current' : 'option', true );
next( $plugin_options );
}
if( $_CONF['allow_mysqldump'] == 1 AND SEC_inGroup( 'Root' ))
{
$url = $_CONF['site_admin_url'] . '/database.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG01[103] );
$adminmenu->set_var( 'option_count', 'N/A' );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
// Add PDF Generator Link if the feature is enabled
if(( $_CONF['pdf_enabled'] == 1 ) AND ( SEC_inGroup( 'Root' )))
{
$url = $_CONF['site_url'] . '/pdfgenerator.php';
$adminmenu->set_var( 'option_url', $url );
$adminmenu->set_var( 'option_label', $LANG_PDF[9] );
$adminmenu->set_var( 'option_count', 'N/A' );
$retval .= $adminmenu->parse( 'item',
( $thisUrl == $url ) ? 'current' : 'option' );
}
if( $_CONF['link_documentation'] == 1 )
{
$adminmenu->set_var( 'option_url', $_CONF['site_url'] . '/docs/' );
$adminmenu->set_var( 'option_label', $LANG01[113] );
$adminmenu->set_var( 'option_count', 'N/A' );
$retval .= $adminmenu->parse( 'item', 'option' );
}
if( SEC_inGroup( 'Root' ))
{
$adminmenu->set_var( 'option_url',
'http://www.geeklog.net/versionchecker.php?version=' . VERSION );
$adminmenu->set_var( 'option_label', $LANG01[107] );
$adminmenu->set_var( 'option_count', VERSION );
$retval .= $adminmenu->parse( 'item', 'option' );
}
$retval .= COM_endBlock( COM_getBlockTemplate( 'admin_block', 'footer' ));
}
return $retval;
}
/**
* Redirects user to a given URL
*
* This function COM_passes a meta tag to COM_refresh after a form is sent. This is
* necessary because for some reason Nutscrape and PHP4 don't play well with
* the header() function COM_100% of the time.
*
* @param string $url URL to send user to
*
*/
function COM_refresh( $url )
{
return "<html><head><meta http-equiv="refresh" content="0; URL=$url"></head></html>n";
}
/**
* This function displays the comment control bar
*
* Prints the control that allows the user to interact with Geeklog Comments
*
* @param string $sid ID of item in question
* @param string $title Title of item
* @param string $type Type of item (i.e. story, photo, etc)
* @param string $order Order that comments are displayed in
* @param string $mode Mode (nested, flat, etc.)
* @see COM_userComments
* @see COM_commentChildren
* @return string HTML Formated comment bar
*
*/
function COM_commentBar( $sid, $title, $type, $order, $mode )
{
global $_CONF, $_TABLES, $_USER, $LANG01, $_REQUEST, $HTTP_SERVER_VARS;
$page = array_pop( explode( '/', $HTTP_SERVER_VARS['PHP_SELF'] ));
$nrows = DB_count( $_TABLES['comments'], 'sid', $sid );
$commentbar = new Template( $_CONF['path_layout'] . 'comment' );
$commentbar->set_file( array( 'commentbar' => 'commentbar.thtml' ));
$commentbar->set_var( 'site_url', $_CONF['site_url'] );
$commentbar->set_var( 'layout_url', $_CONF['layout_url'] );
$commentbar->set_var( 'lang_comments', $LANG01[3] );
$commentbar->set_var( 'lang_refresh', $LANG01[39] );
$commentbar->set_var( 'lang_reply', $LANG01[25] );
$commentbar->set_var( 'lang_disclaimer', $LANG01[26] );
$commentbar->set_var( 'story_title', stripslashes( $title ));
$commentbar->set_var( 'num_comments', $nrows );
$commentbar->set_var( 'comment_type', $type );
if( $type == 'poll' )
{
$commentbar->set_var( 'story_link', $_CONF['site_url']
. "/pollbooth.php?scale=400&qid=$sid&aid=-1" );
}
else if( $type == 'article' )
{
$articleUrl = COM_buildUrl( $_CONF['site_url'] . '/article.php?story='
. $sid );
$commentbar->set_var( 'story_link', $articleUrl );
$commentbar->set_var( 'article_url', $articleUrl );
}
else
{
$commentbar->set_var( 'story_link', $_CONF['site_url']
. "/comment.php?type=$type&cid=$sid" );
}
if( $_USER['uid'] > 1 )
{
$username = $_USER['username'];
$fullname = DB_getItem( $_TABLES['users'], 'fullname',
"uid = '{$_USER['uid']}'" );
}
else
{
$result = DB_query( "SELECT username,fullname FROM {$_TABLES['users']} WHERE uid = 1" );
$N = DB_fetchArray( $result );
$username = $N['username'];
$fullname = $N['fullname'];
}
if( empty( $fullname ))
{
$fullname = $username;
}
$commentbar->set_var( 'user_name', $username );
$commentbar->set_var( 'user_fullname', $fullname );
if( !empty( $_USER['username'] ))
{
$commentbar->set_var( 'user_nullname', $username );
$commentbar->set_var( 'login_logout_url',
$_CONF['site_url'] . '/users.php?mode=logout' );
$commentbar->set_var( 'lang_login_logout', $LANG01[35] );
}
else
{
$commentbar->set_var( 'user_nullname', '' );
$commentbar->set_var( 'login_logout_url',
$_CONF['site_url'] . '/users.php?mode=new' );
$commentbar->set_var( 'lang_login_logout', $LANG01[61] );
}
if( $page == 'comment.php' )
{
$commentbar->set_var( 'parent_url',
$_CONF['site_url'] . '/comment.php' );
$hidden = '';
if( $_REQUEST['mode'] == 'view' )
{
$hidden .= '<input type="hidden" name="cid" value="' . $_REQUEST['cid'] . '">';
$hidden .= '<input type="hidden" name="pid" value="' . $_REQUEST['cid'] . '">';
}
else if( $_REQUEST['mode'] == 'display' )
{
$hidden .= '<input type="hidden" name="pid" value="' . $_REQUEST['pid'] . '">';
}
else /* This is likely a plugin (or a mistake) */
{
$hidden .= '<input type="hidden" name="cid" value="' . $sid . '">';
}
$commentbar->set_var( 'hidden_field', $hidden .
'<input type="hidden" name="mode" value="' . $_REQUEST['mode'] . '">' );
}
else if( $type == 'poll' )
{
$commentbar->set_var( 'parent_url',
$_CONF['site_url'] . '/pollbooth.php' );
$commentbar->set_var( 'hidden_field',
'<input type="hidden" name="scale" value="400">' .
'<input type="hidden" name="qid" value="' . $sid . '">' .
'<input type="hidden" name="aid" value="-1">' );
}
else
{
$commentbar->set_var( 'parent_url',
$_CONF['site_url'] . '/article.php' );
$commentbar->set_var( 'hidden_field',
'<input type="hidden" name="story" value="' . $sid . '">' );
}
// Order
$selector = '<select name="order">' . LB
. COM_optionList( $_TABLES['sortcodes'], 'code,name', $order )
. LB . '</select>';
$commentbar->set_var( 'order_selector', $selector);
// Mode
if( $page == 'comment.php' )
{
$selector = '<select name="format">';
}
else
{
$selector = '<select name="mode">';
}
$selector .= LB
. COM_optionList( $_TABLES['commentmodes'], 'mode,name', $mode )
. LB . '</select>';
$commentbar->set_var( 'mode_selector', $selector);
return $commentbar->finish( $commentbar->parse( 'output', 'commentbar' ));
}
/**
* This function prints &$comments (db results set of comments) in comment format
* -For previews, &$comments is assumed to be an associative array containing
* data for a single comment.
*
* @param array &$comments Database result set of comments to be printed
* @param string $mode 'flat', 'threaded', etc
* @param string $type Type of item (article, poll, etc.)
* @param string $order How to order the comments 'ASC' or 'DESC'
* @param boolean $delete_option if current user can delete comments
* @param boolean $preview Preview display (for edit) or not
* @return string HTML Formated Comment
*
*/
function COM_getComment( &$comments, $mode, $type, $order, $delete_option = false, $preview = false )
{
global $_CONF, $_TABLES, $_USER, $LANG01, $query;
$indent = 0; // begin with 0 indent
$level = array(); // used to track depth
$retval = ''; // initialize return value
$template = new Template( $_CONF['path_layout'] . 'comment' );
$template->set_file( array( 'comment' => 'comment.thtml',
'thread' => 'thread.thtml' ));
// generic template variables
$template->set_var( 'site_url', $_CONF['site_url'] );
$template->set_var( 'layout_url', $_CONF['layout_url'] );
$template->set_var( 'lang_replytothis', $LANG01[43] );
$template->set_var( 'lang_reply', $LANG01[25] );
$template->set_var( 'lang_authoredby', $LANG01[42] );
$template->set_var( 'lang_on', $LANG01[36] );
$template->set_var( 'order', $order );
// Make sure we have a default value for comment indentation
if( !isset( $_CONF['comment_indent'] ))
{
$_CONF['comment_indent'] = 25;
}
if( $preview )
{
$A = $comments;
$mode = 'flat';
}
else
{
$A = DB_fetchArray($comments);
}
if( empty( $A ) )
{
return '';
}
do
{
// determines indentation for current comment
if( $mode == 'threaded' || $mode == 'nested' )
{
$indent = ($A['indent'] - $A['pindent']) * $_CONF['comment_indent'];
}
// comment variables
$template->set_var( 'indent', $indent );
$template->set_var( 'author', $A['username'] );
$template->set_var( 'author_id', $A['uid'] );
if( $A['uid'] > 1 )
{
if( empty( $A['fullname'] ))
{
$template->set_var( 'author_fullname', $A['username'] );
$alttext = $A['username'];
}
else
{
$template->set_var( 'author_fullname', $A['fullname'] );
$alttext = $A['fullname'];
}
if( !empty( $A['photo'] ))
{
$template->set_var( 'author_photo', '<img src="'
. $_CONF['site_url']
. '/images/userphotos/' . $A['photo']
. '" alt="' . $alttext . '">' );
$template->set_var( 'camera_icon', '<a href="'
. $_CONF['site_url']
. '/users.php?mode=profile&uid=' . $A['uid']
. '"><img src="' . $_CONF['layout_url']
. '/images/smallcamera.gif" border="0" alt=""></a>' );
}
else
{
$template->set_var( 'author_photo', '' );
$template->set_var( 'camera_icon', '' );
}
$template->set_var( 'start_author_anchortag', '<a href="'
. $_CONF['site_url'] . '/users.php?mode=profile&uid='
. $A['uid'] . '">' );
$template->set_var( 'end_author_anchortag', '</a>' );
}
else
{
$template->set_var( 'author_fullname', $A['username'] );
$template->set_var( 'author_photo', '' );
$template->set_var( 'camera_icon', '' );
$template->set_var( 'start_author_anchortag', '' );
$template->set_var( 'end_author_anchortag', '' );
}
// hide reply link from anonymous users if they can't post replies
$hidefromanon = false;
if( empty( $_USER['username'] ) && (( $_CONF['loginrequired'] == 1 ) || ( $_CONF['commentsloginrequired'] == 1 )))
{
$hidefromanon = true;
}
// this will hide HTML that should not be viewed in preview mode
if( $preview || $hidefromanon )
{
$template->set_var( 'hide_if_preview', 'style="display:none"' );
}
else
{
$template->set_var( 'hide_if_preview', '' );
}
// for threaded mode, add a link to comment parent
if( $mode == 'threaded' && $A['pid'] != 0 && $indent == 0 )
{
$result = DB_query( "SELECT title,pid from {$_TABLES['comments']} where cid = '{$A['pid']}'" );
$P = DB_fetchArray( $result );
if ($P['pid'] != 0) {
$plink = $_CONF['site_url'] . '/comment.php?mode=display&sid='
. $A['sid'] . '&title=' . rawurlencode( $P['title'] )
. '&type=' . $type . '&order=' . $order . '&pid='
. $P['pid'];
} else {
$plink = $_CONF['site_url'] . '/comment.php?mode=view&sid='
. $A['sid'] . '&title=' . rawurlencode( $P['title'] )
. '&type=' . $type . '&order=' . $order . '&cid='
. $A['pid'] . '&format=threaded';
}
$template->set_var( 'parent_link', "| <a href="$plink">{$LANG01[44]}</a>");
}
else
{
$template->set_var( 'parent_link', '');
}
$template->set_var( 'date', strftime( $_CONF['date'], $A['nice_date'] ));
$template->set_var( 'sid', $A['sid'] );
$template->set_var( 'type', $A['type'] );
// If deletion is allowed, displays delete link
if( $delete_option )
{
$deloption = '| <a href="' . $_CONF['site_url']
. '/comment.php?mode=delete&cid='
. $A['cid'] . '&sid=' . $A['sid'] . '&type='
. $type . '">' . $LANG01[28] . '</a> ';
if( !empty( $A['ipaddress'] ))
{
if( empty( $_CONF['ip_lookup'] ))
{
$deloption .= '| ' . $A['ipaddress'] . ' ';
}
else
{
$iplookup = str_replace( '*', $A['ipaddress'],
$_CONF['ip_lookup'] );
$deloption .= '| <a href="' . $iplookup . '">'
. $A['ipaddress'] . '</a> ';
}
}
$template->set_var( 'delete_option', $deloption );
}
else if( !empty( $_USER['username'] ))
{
$reportthis = ' | <a href="' . $_CONF['site_url']
. '/comment.php?mode=report&cid=' . $A['cid']
. '&type=' . $type . '" title="' . $LANG01[110]
. '">' . $LANG01[109] . '</a> ';
$template->set_var( 'delete_option', $reportthis );
}
else
{
$template->set_var( 'delete_option', '' );
}
$A['title'] = stripslashes( $A['title'] );
$A['title'] = htmlspecialchars( $A['title'] );
$A['title'] = str_replace( '$', '$', $A['title'] );
// and finally: format the actual text of the comment
$A['comment'] = stripslashes( $A['comment'] );
if( preg_match( '/<.*>/', $A['comment'] ) == 0 )
{
$A['comment'] = nl2br( $A['comment'] );
}
// highlight search terms if specified
if( !empty( $query ))
{
$A['comment'] = COM_highlightQuery( $A['comment'], $query );
}
$A['comment'] = str_replace( '$', '$', $A['comment'] );
$A['comment'] = str_replace( '{', '{', $A['comment'] );
$A['comment'] = str_replace( '}', '}', $A['comment'] );
// Replace any plugin autolink tags
$A['comment'] = PLG_replaceTags( $A['comment'] );
$template->set_var( 'title', $A['title'] );
$template->set_var( 'comments', $A['comment'] );
// parse the templates
if( $mode == 'threaded' && $indent > 0 )
{
$template->set_var( 'pid', $A['pid'] );
$retval .= $template->parse( 'output', 'thread' );
}
else
{
$template->set_var( 'pid', $A['cid'] );
$retval .= $template->parse( 'output', 'comment' );
}
}
while( $A = DB_fetchArray( $comments ));
return $retval;
}
/**
* This function displays the comments in a high level format.
*
* Begins displaying user comments for an item
*
* @param string $sid ID for item to show comments for
* @param string $title Title of item
* @param string $type Type of item (article, poll, etc.)
* @param string $order How to order the comments 'ASC' or 'DESC'
* @param string $mode comment mode (nested, flat, etc.)
* @param int $pid id of parent comment
* @param int $page page number of comments to display
* @param boolean $cid true if $pid should be interpreted as a cid instead
* @param boolean $delete_option if current user can delete comments
* @see function COM_commentBar
* @see function COM_commentChildren
* @return string HTML Formated Comments
*
*/
function COM_userComments( $sid, $title, $type='article', $order='', $mode='', $pid = 0, $page = 1, $cid = false, $delete_option = false )
{
global $_CONF, $_TABLES, $_USER, $LANG01;
if( !empty( $_USER['uid'] ) )
{
$result = DB_query( "SELECT commentorder,commentmode,commentlimit FROM {$_TABLES['usercomment']} WHERE uid = '{$_USER['uid']}'" );
$U = DB_fetchArray( $result );
if( empty( $order ) )
{
$order = $U['commentorder'];
}
if( empty( $mode ) )
{
$mode = $U['commentmode'];
}
$limit = $U['commentlimit'];
}
if( empty( $order ))
{
$order = 'ASC';
}
if( empty( $mode ))
{
$mode = $_CONF['comment_mode'];
}
if( empty( $limit ))
{
$limit = $_CONF['comment_limit'];
}
if( !is_numeric($page) || $page < 1 )
{
$page = 1;
}
$start = $limit * ( $page - 1 );
$template = new Template( $_CONF['path_layout'] . 'comment' );
$template->set_file( array( 'commentarea' => 'startcomment.thtml' ));
$template->set_var( 'site_url', $_CONF['site_url'] );
$template->set_var( 'layout_url', $_CONF['layout_url'] );
$template->set_var( 'commentbar',
COM_commentBar( $sid, $title, $type, $order, $mode));
if( $mode == 'nested' or $mode == 'threaded' or $mode == 'flat' )
{
// build query
switch( $mode )
{
case 'flat':
if( $cid )
{
$count = 1;
$q = "SELECT c.*, u.username, u.fullname, u.photo, "
. "unix_timestamp(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['users']} as u "
. "WHERE c.uid = u.uid AND c.cid = $pid";
}
else
{
$count = DB_count( $_TABLES['comments'], 'sid', $sid );
$q = "SELECT c.*, u.username, u.fullname, u.photo, "
. "unix_timestamp(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['users']} as u "
. "WHERE c.uid = u.uid AND c.sid = '$sid' "
. "ORDER BY date $order LIMIT $start, $limit";
}
break;
case 'nested':
case 'threaded':
default:
if( $order == 'DESC' )
{
$cOrder = 'c.rht DESC';
}
else
{
$cOrder = 'c.lft ASC';
}
// We can simplify the query, and hence increase performance
// when pid = 0 (when fetching all the comments for a given sid)
if( $cid )
{
// count the total number of applicable comments
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2 "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid";
$result = DB_query( $q2 );
list( $count ) = DB_fetchArray( $result );
$q = "SELECT c.*, u.username, u.fullname, u.photo, c2.indent as pindent, "
. "unix_timestamp(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2, "
. "{$_TABLES['users']} as u "
. "WHERE c.sid = '$sid' AND (c.lft >= c2.lft AND c.lft <= c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid "
. "ORDER BY $cOrder LIMIT $start, $limit";
}
else
{
if( $pid == 0 )
{
// count the total number of applicable comments
$count = DB_count( $_TABLES['comments'], 'sid', $sid );
$q = "SELECT c.*, u.username, u.fullname, u.photo, 0 as pindent, "
. "unix_timestamp(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['users']} as u "
. "WHERE c.sid = '$sid' AND c.uid = u.uid "
. "ORDER BY $cOrder LIMIT $start, $limit";
}
else
{
// count the total number of applicable comments
$q2 = "SELECT COUNT(*) "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2 "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid";
$result = DB_query($q2);
list($count) = DB_fetchArray($result);
$q = "SELECT c.*, u.username, u.fullname, u.photo, c2.indent + 1 as pindent, "
. "unix_timestamp(c.date) AS nice_date "
. "FROM {$_TABLES['comments']} as c, {$_TABLES['comments']} as c2, "
. "{$_TABLES['users']} as u "
. "WHERE c.sid = '$sid' AND (c.lft > c2.lft AND c.lft < c2.rht) "
. "AND c2.cid = $pid AND c.uid = u.uid "
. "ORDER BY $cOrder LIMIT $start, $limit";
}
}
break;
}
$thecomments = '';
$result = DB_query( $q );
$thecomments .= COM_getComment( $result, $mode, $type, $order,
$delete_option );
// Pagination
$tot_pages = ceil( $count / $limit );
$pLink = $_CONF['site_url'] . "/article.php?story=$sid&type=$type&order=$order&mode=$mode";
$template->set_var( 'pagenav',
COM_printPageNavigation($pLink, $page, $tot_pages));
$template->set_var( 'comments', $thecomments );
$retval = $template->parse( 'output', 'commentarea' );
}
return $retval;
}
/**
* This censors inappropriate content
*
* This will replace 'bad words' with something more appropriate
*
* @param string $Message String to check
* @see function COM_checkHTML
* @return string Edited $Message
*
*/
function COM_checkWords( $Message )
{
global $_CONF;
$EditedMessage = $Message;
if( $_CONF['censormode'] != 0 )
{
if( is_array( $_CONF['censorlist'] ))
{
$Replacement = $_CONF['censorreplace'];
switch( $_CONF['censormode'])
{
case 1: # Exact match
$RegExPrefix = '(s*)';
$RegExSuffix = '(W*)';
break;
case 2: # Word beginning
$RegExPrefix = '(s*)';
$RegExSuffix = '(w*)';
break;
case 3: # Word fragment
$RegExPrefix = '(w*)';
$RegExSuffix = '(w*)';
break;
}
for( $i = 0; $i < count( $_CONF['censorlist']); $i++ )
{
$EditedMessage = eregi_replace( $RegExPrefix . $_CONF['censorlist'][$i] . $RegExSuffix, "1$Replacement2", $EditedMessage );
}
}
}
return $EditedMessage;
}
/**
* Takes some amount of text and replaces all javascript events on*= with in
*
* This script takes some amount of text and matches all javascript events, on*= (onBlur= onMouseClick=)
* and replaces them with in*=
* Essentially this will cause onBlur to become inBlur, onFocus to be inFocus
* These are not valid javascript events and the browser will ignore them.
* @param string $Message Text to filter
* @return string $Message with javascript filtered
* @see COM_checkWords
* @see COM_checkHTML
*
*/
function COM_killJS( $Message )
{
return( preg_replace( '/(s)+[oO][nN](w*) ?=/', '1in2=', $Message ));
}
/**
* Handles the part within a ...
section, i.e. escapes all
* special characters.
* This function checks html tags.
* removes them if not.
* @param string $permissions comma-separated list of rights which identify the current user as an "Admin"
$str = substr( $str, 0, $start_pos ) . $encoded
. substr( $str, $end_pos + 7 );
// special characters). However, the calling entity should
// function ...
$str = substr( $str, 0, $start_pos ) . $encoded;
// strip_tags() gets confused by HTML comments ...
if( isset( $_CONF['allowed_protocols'] ) && is_array( $_CONF['allowed_protocols'] ) && ( sizeof( $_CONF['allowed_protocols'] ) > 0 ))
* into their ASCII equivalents. Also handles the entities for $, {, and }.
* @param string $string The string to convert.
* @return string The converted string.
* (.000001th of a second) since the last full second.
* Checks to see if email address is valid.
* This function checks to see if an email address is in the correct from.
* resembles an email address specification conforming to RFC(2)822 ...
* @param string $name name, e.g. John Doe
* @param string $address email address only, e.g. john.doe@example.com
$formatted_name = '"' . $formatted_name . '"';
return $formatted_name . ' ';
* Send an email.
* All emails sent by Geeklog are sent through this function now.
function COM_mail( $to, $subject, $message, $from = '', $html = false, $priority = 0 )
$from = COM_formatEmailAddress( $_CONF['site_name'], $_CONF['site_mail']);
$headers['Message-Id'] = '
. '@' . $_CONF['mail_settings']['host'] . '>';
$headers['Content-Type'] = 'text/html; charset=' . $charset;
$headers['Content-Type'] = 'text/plain; charset=' . $charset;
$headers['X-Mailer'] = 'GeekLog ' . VERSION;
* Creates the olderstuff block for display.
* Actually updates the olderstuff record in the gl_blocks database.
$sql = "SELECT sid,tid,title,comments,UNIX_TIMESTAMP(date) AS day FROM {$_TABLES['stories']} WHERE (perm_anon = 2) AND (date
$result = DB_query( $sql );
$dateonly = '%d-%b'; // fallback: day - abbrev. month name