[geeklog-cvs] geeklog: updated lib-common.php

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Tue Jan 26 15:53:57 EST 2010


changeset 7650:4dc8e95d1943
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/4dc8e95d1943
user: stan <yankees26an at gmail.com>
date: Wed Aug 19 11:09:19 2009 -0400
description:
updated lib-common.php

diffstat:

 public_html/lib-common.php |  738 ++++++++++++++++++++++++++----------------------
 1 files changed, 396 insertions(+), 342 deletions(-)

diffs (truncated from 1515 to 300 lines):

diff -r 8c3760c8583d -r 4dc8e95d1943 public_html/lib-common.php
--- a/public_html/lib-common.php	Sun Aug 16 19:45:53 2009 -0400
+++ b/public_html/lib-common.php	Wed Aug 19 11:09:19 2009 -0400
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.5                                                               |
+// | Geeklog 1.6                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-common.php                                                            |
 // |                                                                           |
 // | Geeklog common library.                                                   |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2000-2008 by the following authors:                         |
+// | Copyright (C) 2000-2009 by the following authors:                         |
 // |                                                                           |
 // | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
 // |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
@@ -32,8 +32,6 @@
 // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
 // |                                                                           |
 // +---------------------------------------------------------------------------+
-//
-// $Id: lib-common.php,v 1.728 2008/09/21 08:37:09 dhaun Exp $
 
 // Prevent PHP from reporting uninitialized variables
 error_reporting( E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR );
@@ -55,38 +53,46 @@
 * Turn this on to get various debug messages from the code in this library
 * @global Boolean $_COM_VERBOSE
 */
-
 $_COM_VERBOSE = false;
 
 /**
-  * Here, we shall establish an error handler. This will mean that whenever a
-  * php level error is encountered, our own code handles it. This will hopefuly
-  * go someway towards preventing nasties like path exposures from ever being
-  * possible. That is, unless someone has overridden our error handler with one
-  * with a path exposure issue...
-  *
-  * Must make sure that the function hasn't been disabled before calling it.
-  *
-  */
-if( function_exists('set_error_handler') )
-{
-    if( PHP_VERSION >= 5 )
-    {
+* Prevent getting any surprise values. But we should really stop
+* using $_REQUEST altogether.
+*/
+$_REQUEST = array_merge($_GET, $_POST);
+
+/**
+* Here, we shall establish an error handler. This will mean that whenever a
+* php level error is encountered, our own code handles it. This will hopefuly
+* go someway towards preventing nasties like path exposures from ever being
+* possible. That is, unless someone has overridden our error handler with one
+* with a path exposure issue...
+*
+* Must make sure that the function hasn't been disabled before calling it.
+*
+*/
+if (function_exists('set_error_handler')) {
+    if (PHP_VERSION >= 5) {
         /* Tell the error handler to use the default error reporting options.
-         * you may like to change this to use it in more/less cases, if so,
+         * You may like to change this to use it in more/less cases, if so,
          * just use the syntax used in the call to error_reporting() above.
          */
-        $defaultErrorHandler = set_error_handler('COM_handleError', error_reporting());
+        $defaultErrorHandler = set_error_handler('COM_handleError',
+                                                 error_reporting());
     } else {
         $defaultErrorHandler = set_error_handler('COM_handleError');
     }
 }
 
-/*
+/**
 * Configuration Include:
 * You do NOT need to modify anything here any more!
 */
-require_once 'siteconfig.php' ;
+require_once 'siteconfig.php';
+
+/**
+* Configuration class
+*/
 require_once $_CONF['path_system'] . 'classes/config.class.php';
 
 $config =& config::get_instance();
@@ -139,39 +145,18 @@
 * 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' );
+if (! $_CONF['have_pear']) {
+    $curPHPIncludePath = get_include_path();
+    if (empty($curPHPIncludePath)) {
+        $curPHPIncludePath = $_CONF['path_pear'];
+    } else {
+        $curPHPIncludePath = $_CONF['path_pear'] . PATH_SEPARATOR
+                           . $curPHPIncludePath;
+    }
+
+    if (set_include_path($curPHPIncludePath) === false) {
+        COM_errorLog('set_include_path failed - there may be problems using the PEAR classes.', 1);
+    }
 }
 
 
@@ -188,8 +173,6 @@
 * 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' );
@@ -197,7 +180,7 @@
 
 /**
 * 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
+* licensed under the LGPL.  See that file for details.
 *
 */
 
@@ -239,8 +222,9 @@
 * 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.
+* The lib-custom.php as shipped will never contain required code,
+* so it's safe to always use your own copy.
+* This should hold all custom hacks to make upgrading easier.
 *
 */
 
@@ -276,9 +260,6 @@
 require_once( $_CONF['path_system'] . 'lib-mbyte.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.
 
 $usetheme = '';
 if( isset( $_POST['usetheme'] ))
@@ -327,10 +308,20 @@
     require_once $_CONF['path_layout'] . 'functions.php';
 }
 
-// ensure XHTML constant is defined to avoid problems elsewhere
-
+/**
+* ensure XHTML constant is defined to avoid problems elsewhere
+*/
 if (!defined('XHTML')) {
-    define('XHTML', '');
+    switch ($_CONF['doctype']) {
+    case 'xhtml10transitional':
+    case 'xhtml10strict':
+        define('XHTML', ' /');
+        break;
+
+    default:
+        define('XHTML', '');
+        break;
+    }
 }
 
 // themes can now specify the default image type
@@ -368,13 +359,13 @@
 // Handle Who's Online block
 if (COM_isAnonUser() && isset($_SERVER['REMOTE_ADDR'])) {
     // The following code handles anonymous users so they show up properly
-    DB_query( "DELETE FROM {$_TABLES['sessions']} WHERE remote_ip = '{$_SERVER['REMOTE_ADDR']}' AND uid = 1" );
+    DB_delete($_TABLES['sessions'], array('remote_ip', 'uid'),
+                                    array($_SERVER['REMOTE_ADDR'], 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();
 
@@ -445,7 +436,7 @@
 {
     $topic = '';
 }
-     
+
 
 // +---------------------------------------------------------------------------+
 // | HTML WIDGETS                                                              |
@@ -544,7 +535,7 @@
 * Returns a list of all the directory names in $_CONF['path_themes'], i.e.
 * a list of all the theme names.
 *
-* @param    bool    $all    if true, return all themes even if users aren't allowed to change their default themes
+* @param    boolean $all    if true, return all themes even if users aren't allowed to change their default themes
 * @return   array           All installed themes
 *
 */
@@ -556,8 +547,6 @@
 
     $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 )
@@ -566,6 +555,8 @@
     }
     else
     {
+        $fd = opendir( $_CONF['path_themes'] );
+
         while(( $dir = @readdir( $fd )) == TRUE )
         {
             if( is_dir( $_CONF['path_themes'] . $dir) && $dir <> '.' && $dir <> '..' && $dir <> 'CVS' && substr( $dir, 0 , 1 ) <> '.' )
@@ -584,7 +575,7 @@
 * 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
 *
 */
@@ -812,21 +803,23 @@
 * and the footer.  You use them like a sandwich.  Thus the following code will
 * display a Geeklog page with both right and left blocks displayed.
 *
-* -------------------------------------------------------------------------------------
+* <code>
 * <?php
-* require_once('lib-common.php');
-* $display .= COM_siteHeader(); //Change to COM_siteHeader('none') to not display left blocks
+* require_once 'lib-common.php';
+* // Change to COM_siteHeader('none') to not display left blocks
+* $display .= COM_siteHeader();
 * $display .= "Here is your html for display";
-* $display .= COM_siteFooter(true);  // Change to COM_siteFooter() to not display right blocks
+* // Change to COM_siteFooter() to not display right blocks
+* $display .= COM_siteFooter(true);
 * echo $display;
 * ? >
-* ---------------------------------------------------------------------------------------
+* </code>
 *
 * Note that the default for the header is to display the left blocks and the
 * default of the footer is to not display the right blocks.
 *
 * This sandwich produces code like this (greatly simplified)
-*
+* <code>
 * // COM_siteHeader
 * <table><tr><td colspan="3">Header</td></tr>
 * <tr><td>Left Blocks</td><td>



More information about the geeklog-cvs mailing list