[ Index ]

PHP Cross Reference of phpwcms V1.4.3 _r380 (23.11.09)

title

Body

[close]

/include/inc_lib/ -> default.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2009 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_INCLUDE_CHECK')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  
  31  @ini_set( 'arg_separator.output' , '&amp;' );
  32  
  33  // i18n charsets that might be accessible - in general used in MySQL
  34  // but a few more as listed here http://www.w3.org/International/O-charset-list.html
  35  $phpwcms['charsets'] = array(
  36      'iso-2022-kr',
  37      'iso-2022-jp',
  38      'iso-8859-1',
  39      'iso-8859-2',
  40      'iso-8859-3',
  41      'iso-8859-4',
  42      'iso-8859-5',
  43      'iso-8859-6',
  44      'iso-8859-7',
  45      'iso-8859-8',
  46      'iso-8859-8-i',
  47      'iso-8859-9',
  48      'iso-8859-10',
  49      'iso-8859-11',
  50      'iso-8859-12',
  51      'iso-8859-13',
  52      'iso-8859-14',
  53      'iso-8859-15',
  54      'iso-10646-ucs-2',
  55      'windows-874',
  56      'windows-1250',
  57      'windows-1251',
  58      'windows-1252',
  59      'windows-1253',
  60      'windows-1254',
  61      'windows-1255',
  62      'windows-1256',
  63      'windows-1257',
  64      'windows-1258',
  65      'koi8-r',
  66      'big5',
  67      'gb2312',
  68      'us-ascii',
  69      'utf-16',
  70      'utf-8',
  71      'utf-7',
  72      'x-user-defined',
  73      'euc-cn',
  74      'euc-jp',
  75      'euc-kr',
  76      'euc-tw',
  77      'ks_c_5601-1987',
  78      'tis-620',
  79      'shift_jis'
  80  );
  81  
  82  define ('PHPWCMS_CHARSET',     empty($phpwcms["charset"]) ? 'utf-8' : strtolower($phpwcms["charset"]));
  83  
  84  /* seems to be problematic at the moment - so always use text/html
  85  if (!empty($phpwcms['header_XML']) && $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.1' && isset($_SERVER['HTTP_ACCEPT']) && preg_match('|application/xhtml\+xml(?!\s*;\s*q=0)|', $_SERVER['HTTP_ACCEPT'])) {
  86      header('Content-Type: application/xhtml+xml; charset='.PHPWCMS_CHARSET);
  87      header('Vary: Negotiate, Accept');
  88      $_use_content_type = 'application/xhtml+xml';
  89  }
  90  */
  91  if(defined('CUSTOM_CONTENT_TYPE')) {
  92  
  93      header(CUSTOM_CONTENT_TYPE);
  94      
  95  } else {
  96  
  97      header('Content-Type: text/html; charset='.PHPWCMS_CHARSET);
  98      //    header('Vary: Negotiate, Accept');
  99      $_use_content_type = 'text/html';
 100  
 101  }
 102  
 103  
 104  // define the real path of the phpwcms installation
 105  // important to script that must know the real path to files or something else
 106  
 107  $phpwcms['DOC_ROOT'] = rtrim( str_replace("\\", '/', $phpwcms['DOC_ROOT']), '/' );
 108  if( empty($phpwcms["root"]) ) {
 109      $phpwcms["root"]             = '';
 110      $phpwcms["host_root"]         = '';
 111  } else {
 112      $phpwcms["root"]             = trim( $phpwcms["root"], '/' );
 113      $phpwcms["host_root"]         = '/'.$phpwcms["root"];
 114      $phpwcms['DOC_ROOT']        .=     '/' . $phpwcms["root"];
 115      $phpwcms["root"]            .=     '/';
 116  }
 117  
 118  define ("PHPWCMS_ROOT",             $phpwcms['DOC_ROOT']);
 119  define ('PHPWCMS_FILES',             $phpwcms["file_path"] . '/');
 120  define ('PHPWCMS_BASEPATH',            '/' . $phpwcms["root"]);
 121  define ('On',                        true);
 122  define ('Off',                        false);
 123  define ('PHPWCMS_USER_KEY',            md5(getRemoteIP().$phpwcms['DOC_ROOT'].$phpwcms["db_pass"]));
 124  define ('PHPWCMS_REWRITE_EXT',        'phtml');
 125  
 126  $phpwcms['browser_detect']        =    phpwcms_getUserAgent();
 127  define('BROWSER_NAME',                $phpwcms['browser_detect']['agent']);
 128  define('BROWSER_NUMBER',            $phpwcms['browser_detect']['version']);
 129  define('BROWSER_OS',                $phpwcms['browser_detect']['platform']);
 130  
 131  $phpwcms["file_path"]            =     '/'.$phpwcms["file_path"].'/' ;  // "/phpwcms_filestorage/"
 132  
 133  define ('TEMPLATE_PATH',             $phpwcms["templates"].'/');
 134  $phpwcms["templates"]            =     '/'.$phpwcms["templates"].'/' ;  // "/phpwcms_template/"
 135  $phpwcms["content_path"]         =     $phpwcms["content_path"].'/'  ;  // "content/"
 136  define ('CONTENT_PATH',                $phpwcms["content_path"]);
 137  $phpwcms["cimage_path"]          =     $phpwcms["cimage_path"].'/'   ;  // "images/"
 138  $phpwcms["ftp_path"]             =     '/'.$phpwcms["ftp_path"].'/'  ;  // "/phpwcms_ftp/"
 139  
 140  define ('PHPWCMS_TEMPLATE',         PHPWCMS_ROOT.$phpwcms["templates"]);
 141  define ('PHPWCMS_URL',                 $phpwcms["site"].$phpwcms["root"]);
 142  
 143  $phpwcms['parse_url']            =    parse_url(PHPWCMS_URL);
 144  define ('PHPWCMS_HOST',                $phpwcms['parse_url']['host'].$phpwcms["host_root"]);
 145  define ('PHPWCMS_IMAGES',             $phpwcms["content_path"].$phpwcms["cimage_path"]);
 146  define ('PHPWCMS_TEMP',             PHPWCMS_ROOT.'/'.$phpwcms["content_path"].'tmp/');
 147  define ('PHPWCMS_CONTENT',            PHPWCMS_ROOT.'/'.$phpwcms["content_path"]);
 148  define ('PHPWCMS_THUMB',            PHPWCMS_CONTENT.$phpwcms["cimage_path"]);
 149  define ('PHPWCMS_RSS',                 PHPWCMS_CONTENT.'rss');
 150  define ('LF',                         "\n");     //global new line Feed
 151  define ('FEUSER_REGKEY',            empty($phpwcms['feuser_regkey']) ? 'FEUSER' : $phpwcms['feuser_regkey']);
 152  
 153  define ('MB_SAFE',                    function_exists('mb_substr') ? true : false); //mbstring safe - better to do a check here
 154  
 155  $phpwcms['modules']                 = array();
 156  $phpwcms['modules_fe_render']     = array();
 157  $phpwcms['modules_fe_init']         = array();
 158  
 159  // check which function should be used to create thumbnail images
 160  // and if ImageMagick check if enabled or 1 or located at give path
 161  if($phpwcms["imagick_path"]) {
 162      $phpwcms["imagick_path"] = $phpwcms["imagick_path"].'/';
 163      $phpwcms["imagick_path"] = str_replace("\\", '/', $phpwcms["imagick_path"]);
 164      $phpwcms["imagick_path"] = str_replace('//', '/', $phpwcms["imagick_path"]);
 165  }
 166  define ("IMAGICK_PATH",    $phpwcms["imagick_path"]);
 167  define ("IMAGICK_ON", intval($phpwcms["imagick"]));
 168  define ("GD2_ON", intval($phpwcms["use_gd2"]));
 169  
 170  if(empty($phpwcms['SMTP_MAILER'])) {
 171      $phpwcms['SMTP_MAILER'] = 'mail';
 172  }
 173  if(empty($phpwcms['SMTP_FROM_EMAIL'])) {
 174      $phpwcms['SMTP_FROM_EMAIL'] = $phpwcms["admin_email"];
 175  }
 176  
 177  $phpwcms['default_lang'] = strtolower($phpwcms['default_lang']);
 178  $phpwcms['DOCTYPE_LANG'] = empty($phpwcms['DOCTYPE_LANG']) ? $phpwcms['default_lang'] : strtolower(trim($phpwcms['DOCTYPE_LANG']));
 179  
 180  if(empty($phpwcms['mode_XHTML'])) {
 181      
 182      $phpwcms['mode_XHTML'] = 0;
 183  
 184      define('PHPWCMS_DOCTYPE', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'.LF.'<html{DOCTYPE_LANG}>'.LF.'<head>'.LF);
 185      define('SCRIPT_CDATA_START', '  <!-- ');
 186      define('SCRIPT_CDATA_END'  , '  //-->');
 187      define('HTML_TAG_CLOSE'  , '>');
 188      define('XHTML_MODE', false);
 189      define('PHPWCMS_DOCTYPE_LANG', ' lang="{DOCTYPE_LANG}"');
 190      
 191  } elseif($phpwcms['mode_XHTML'] == 2) {
 192  
 193      define('PHPWCMS_DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.LF.'<html xmlns="http://www.w3.org/1999/xhtml"{DOCTYPE_LANG}>'.LF.'<head>'.LF);
 194      define('SCRIPT_CDATA_START', '  /* <![CDATA[ */');
 195      define('SCRIPT_CDATA_END'  , '  /* ]]> */');
 196      define('HTML_TAG_CLOSE'  , ' />');
 197      define('XHTML_MODE', true);
 198      define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"');
 199      
 200  } else {
 201      
 202      $phpwcms['mode_XHTML'] = 1;
 203  
 204      define('PHPWCMS_DOCTYPE', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'.LF.'<html xmlns="http://www.w3.org/1999/xhtml"{DOCTYPE_LANG}>'.LF.'<head>'.LF);
 205      define('SCRIPT_CDATA_START', '  <!-- ');
 206      define('SCRIPT_CDATA_END'  , '  //-->');
 207      define('HTML_TAG_CLOSE'  , ' />');
 208      define('XHTML_MODE', true);
 209      define('PHPWCMS_DOCTYPE_LANG', ' xml:lang="{DOCTYPE_LANG}" lang="{DOCTYPE_LANG}"');
 210  
 211  }
 212  
 213  $phpwcms["release"]            = '1.4.3';
 214  $phpwcms["release_date"]    = '2009/11/23';
 215  $phpwcms["revision"]        = '380';
 216  
 217  
 218  // load permissions class
 219  require (PHPWCMS_ROOT.'/include/inc_lib/permissions.class.php');
 220  // init permissions
 221  $_PERMIT = new Permissions();
 222  
 223  
 224  
 225  // -------------------------------------------------------------
 226  
 227  function removeSessionName($str='') {
 228      // is used to remove all &hashID=...
 229      // not useful when when storing in cache
 230      // because it stores unneccessary session IDs too
 231      $sessName = session_name();
 232      if($sessName) {
 233          $str = preg_replace('/[&|\?]{0,1}'.$sessName.'=[a-zA-Z0-9]{1,}/', '', $str);
 234      }
 235      return $str;
 236  }
 237  
 238  
 239  function buildGlobalGET($return = '') {
 240      // build internal array containing all GET values
 241      // and remove session from this array
 242      $GLOBALS['_getVar'] = array();
 243      
 244      $_queryVal        = empty($_SERVER['QUERY_STRING']) ? array() : explode('&', $_SERVER['QUERY_STRING']);
 245      $_queryCount    = count($_queryVal);
 246      $_getCount        = is_array($_GET) ? count($_GET) : 0;
 247      
 248      if($_getCount && $_getCount >= $_queryCount) {
 249          $GLOBALS['_getVar'] = $_GET;
 250      } elseif($_queryCount) {
 251          foreach($_queryVal as $value) {
 252              $key = explode('=', $value);
 253              $val = empty($key[1]) ? '' : $key[1];
 254              $key = $key[0];
 255              $GLOBALS['_getVar'][$key] = $val;
 256          }
 257      }
 258      
 259      unset(    $_GET[session_name()], 
 260              $GLOBALS['_getVar'][session_name()], 
 261              $GLOBALS['_getVar']['']
 262            );
 263            
 264      if( get_magic_quotes_gpc() ) {
 265          foreach($GLOBALS['_getVar'] as $key => $value) {
 266              $GLOBALS['_getVar'][$key] = stripslashes($value);
 267          }
 268      }
 269      
 270      if($return == 'getQuery') {
 271          return returnGlobalGET_QueryString('htmlentities');
 272      }
 273  }
 274  
 275  // build phpwcms specific relative url
 276  function rel_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') {
 277      
 278      return 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind);
 279  
 280  }
 281  // build phpwcms specific absolute url
 282  function abs_url($add=array(), $remove=array(), $id_alias='', $format='htmlentities', $glue='&', $bind='=') {
 283      
 284      return PHPWCMS_URL . 'index.php' . returnGlobalGET_QueryString($format, $add, $remove, $id_alias, $glue, $bind);
 285  
 286  }
 287  
 288  // build a URL query string based on current values
 289  function returnGlobalGET_QueryString($format='', $add=array(), $remove=array(), $id_alias='', $glue='&', $bind='=') {
 290  
 291      $queryString    = array();
 292      $_getVarTemp    = $GLOBALS['_getVar'];
 293      
 294      // replace first value with $id_alias
 295      if($id_alias !== '') {
 296  
 297          $id_alias        = explode($bind, $id_alias, 2);
 298          $id_alias[0]    = trim($id_alias[0]);
 299  
 300          if($id_alias[0] !== '') {
 301              $id_alias[1] = isset($id_alias[1]) ? trim($id_alias[1]) : '';
 302              array_shift($_getVarTemp);
 303              $_getVarTemp = array($id_alias[0] => $id_alias[1]) + $_getVarTemp;
 304          }
 305      }
 306  
 307      foreach($remove as $value) {
 308          unset($_getVarTemp[$value]);
 309      }
 310  
 311      $pairs = count($add) ? array_merge($_getVarTemp, $add) : $_getVarTemp;
 312  
 313      switch($format) {
 314      
 315          case 'htmlentities':    $glue    = html_entities($glue);
 316                                  $funct    = 'getQueryString_htmlentities';
 317                                  break;
 318                                  
 319          case 'urlencode':        $funct    = 'getQueryString_urlencode';
 320                                  break;
 321                                  
 322          case 'rawurlencode':    $funct    = 'getQueryString_rawurlencode';
 323                                  break;
 324                                  
 325          default:                $funct    = 'getQueryString_default';
 326  
 327      }
 328      
 329      foreach($pairs as $key => $value) {
 330      
 331          $queryString[] = $funct($key, $value, $bind);
 332  
 333      }
 334  
 335      return count($queryString) ? '?'.implode($glue, $queryString) : '';
 336  }
 337  
 338  function getQueryString_htmlentities($key='', $value='', $bind='=') {
 339      if($value !== '') {
 340          return html_entities(urlencode($key).$bind.str_replace('%2C', ',', urlencode($value)));
 341      }
 342      return html_entities(urlencode($key));
 343  }
 344  
 345  function getQueryString_urlencode($key='', $value='', $bind='=') {
 346      if($value !== '') {
 347          return urlencode($key).$bind.urlencode($value);
 348      }
 349      return urlencode($key);
 350  }
 351  
 352  function getQueryString_rawurlencode($key='', $value='', $bind='=') {
 353      if($value !== '') {
 354          return rawurlencode($key).$bind.rawurlencode($value);
 355      }
 356      return rawurlencode($key);
 357  }
 358  
 359  function getQueryString_default($key='', $value='', $bind='=') {
 360      if($value !== '') {
 361          return $key.$bind.$value;
 362      }
 363      return $key;
 364  }
 365  
 366  
 367  
 368  function cleanupPOSTandGET() {
 369      // remove possible unsecure PHP replacement tags in GET and POST vars
 370      if(isset($_POST) && count($_POST)) {
 371          foreach($_POST as $key => $value) {
 372              if(!is_array($_POST[$key])) {
 373                  $_POST[$key] = remove_unsecure_rptags($value);
 374              }        
 375          }
 376      }
 377      if(isset($_GET) && count($_GET)) {
 378          foreach($_GET as $key => $value) {
 379              $_GET[$key] = remove_unsecure_rptags($value);
 380          }
 381      }
 382  }
 383  
 384  function remove_unsecure_rptags($check) {
 385      // this is for security reasons
 386      // where you can use input fields for
 387      // code injection
 388      
 389      //remove special replacement tags
 390      $check = preg_replace('/\{PHP:(.*?)\}/i', '$1', $check);
 391      $check = preg_replace('/\{PHPVAR:(.*?)\}/si', '$1', $check);
 392      $check = preg_replace('/\[PHP\](.*?)\[\/PHP\]/si', '$1', $check);
 393      $check = preg_replace('/\{URL:(.*?)\}/i', '$1', $check);
 394      $check = str_replace('[PHP]', '[ PHP ]', $check);
 395      $check = str_replace('[/PHP]', '[ /PHP ]', $check);
 396      $check = str_replace('{PHP:', '{ PHP :', $check);
 397      $check = str_replace('{PHPVAR:', '{ PHPVAR :', $check);
 398      $check = str_replace('{URL:', '{ URL :', $check);
 399      return $check;
 400  }
 401  
 402  function headerRedirect($target='', $type=0) {
 403      if(isset($_SESSION)) {
 404          session_write_close();
 405      }
 406      switch($type) {
 407          case 307:    header('HTTP/1.1 307 Temporary Redirect');        break;
 408          case 401:    header('HTTP/1.1 401 Authorization Required');     break;
 409          case 404:    header('HTTP/1.1 404 Not Found');                break;
 410          case 503:    header('HTTP/1.1 503 Service Unavailable');     break;
 411          case 301:    header('HTTP/1.1 301 Moved Permanently');        break;
 412      }
 413      if($target !== '') {
 414          header('Location: '.$target);
 415          exit();
 416      }
 417  }
 418  
 419  function _initSession() {
 420      if(!session_id()) session_start();
 421      if(empty($_SESSION['phpwcmsSessionInit']) && function_exists("session_regenerate_id")) {
 422          session_regenerate_id();
 423          $_SESSION['phpwcmsSessionInit'] = true;
 424      }
 425      return session_id();
 426  }
 427  
 428  function getRemoteIP() {
 429      if(defined('REMOTE_IP')) {
 430          return REMOTE_IP;
 431      }
 432      $IP = 'unknown';
 433      if (!empty($_SERVER['HTTP_CLIENT_IP']) && strcasecmp($_SERVER['HTTP_CLIENT_IP'], 'unknown')) {
 434          $IP = $_SERVER['HTTP_CLIENT_IP'];
 435      } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_FOR'], 'unknown')) {
 436          $IP = $_SERVER['HTTP_X_FORWARDED_FOR'];
 437      } elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
 438          $IP = $_SERVER['REMOTE_ADDR'];
 439      }
 440      define('REMOTE_IP', $IP);
 441      return $IP;
 442  }
 443  
 444  /************************************************************************/
 445  /* Openads 2.0                                                          */
 446  /* ===========                                                          */
 447  /*                                                                      */
 448  /* Copyright (c) 2000-2007 by the Openads developers                    */
 449  /* For more information visit: http://www.openads.org                   */
 450  /*                                                                      */
 451  /* This program is free software. You can redistribute it and/or modify */
 452  /* it under the terms of the GNU General Public License as published by */
 453  /* the Free Software Foundation; either version 2 of the License.       */
 454  /************************************************************************/
 455  
 456  function phpwcms_getUserAgent($USER_AGENT='') {
 457      
 458      if(isset($GLOBALS['phpwcms']['USER_AGENT'])) {
 459          return $GLOBALS['phpwcms']['USER_AGENT'];
 460      }
 461      
 462      $USER_AGENT = empty($USER_AGENT) && isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : $USER_AGENT;
 463  
 464      if(empty($USER_AGENT)) {
 465          $GLOBALS['phpwcms']['USER_AGENT'] = array(
 466              'agent' => 'Other',
 467              'version' => 0,
 468              'platform' => 'Other'
 469          );
 470          return $GLOBALS['phpwcms']['USER_AGENT'];
 471      }
 472  
 473      if(preg_match('#MSIE ([0-9].[0-9]{1,2})(.*Opera ([0-9].[0-9]{1,2}))?#', $USER_AGENT, $log_version)) {
 474          if(isset($log_version[3])) {
 475              $ver = $log_version[3];
 476              $agent = 'Opera';
 477          } else {
 478              $ver = $log_version[1];
 479              $agent = 'IE';
 480          }
 481      } elseif (preg_match('#Opera[/ ]([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) {
 482          $ver = $log_version[1];
 483          $agent = 'Opera';
 484      } elseif (strstr($USER_AGENT, 'Safari') && preg_match('#Safari/([0-9]{1,3})#', $USER_AGENT, $log_version)) {
 485          $ver = $log_version[1];
 486          $agent = 'Safari';
 487      } elseif (strstr($USER_AGENT, 'Konqueror') && preg_match('#Konqueror/([0-9])#', $USER_AGENT, $log_version)) {
 488          $ver = $log_version[1];
 489          $agent = 'Konqueror';
 490      } elseif (preg_match('#Mozilla/([0-9].[0-9]{1,2})#', $USER_AGENT, $log_version)) {
 491          $ver = $log_version[1];
 492          $agent = 'Mozilla';
 493      } else {
 494          $ver = 0;
 495          $agent = 'Other';
 496      }
 497      
 498      if (strstr($USER_AGENT, 'Win')) {
 499          $platform = 'Win';
 500      } elseif (strstr($USER_AGENT, 'Mac')) {
 501          $platform = 'Mac';
 502      } elseif (strstr($USER_AGENT, 'Linux')) {
 503          $platform = 'Linux';
 504      } elseif (strstr($USER_AGENT, 'Unix')) {
 505          $platform = 'Unix';
 506      } else {
 507          $platform = 'Other';
 508      }
 509      
 510      $GLOBALS['phpwcms']['USER_AGENT'] = array(
 511          'agent' => $agent,
 512          'version' => $ver,
 513          'platform' => $platform
 514      );
 515      
 516      return $GLOBALS['phpwcms']['USER_AGENT'];
 517  }
 518  
 519  /**
 520   * Return current UNIX timestamp
 521   * Wrapper function that might be enhanced for regional time and so on
 522   **/
 523  function now($format=NULL) {
 524      return is_string($format) ? date($format) : time();
 525  }
 526  
 527  /**
 528   * Log to db
 529   *
 530   * Default log types: DEBUG|INFO|ERROR|INFO or use specific module name
 531   */
 532  function log_message($type='UNDEFINED', $message='', $userid=0) {
 533  
 534      $log = array(
 535              'log_created'        => date('Y-m-d H:i:s', now()),
 536              'log_type'            => 'UNDEFINED',
 537              'log_ip'            => getRemoteIP(),
 538              'log_user_agent'    => '',
 539              'log_user_id'        => 0,
 540              'log_user_name'        => '',
 541              'log_referrer_id'    => 0,
 542              'log_referrer_url'    => '',
 543              'log_data1'            => '',
 544              'log_data2'            => '',
 545              'log_data3'            => '',
 546              'log_msg'            => ''
 547          );
 548  
 549      if(is_array($type)) {
 550          $user = array_intersect( $log, $type );
 551      } else {
 552          $user = array(
 553              'log_type'            => trim($type),
 554              'log_user_id'        => intval($userid),
 555              'log_msg'            => trim($message)
 556              );
 557      }
 558      
 559      $log = array_merge( $log, $user );
 560      
 561      $log['log_type'] = strtoupper($log['log_type']);
 562      
 563      if($log['log_user_agent'] == '') {
 564          $log['log_user_agent'] = empty($_SERVER['HTTP_USER_AGENT']) ? implode( ', ', phpwcms_getUserAgent() ) : $_SERVER['HTTP_USER_AGENT'];
 565      }
 566      if(empty($log['log_referrer_url']) && isset($_SERVER['HTTP_REFERER'])) {
 567          $log['log_referrer_url'] = $_SERVER['HTTP_REFERER'];
 568      }
 569      
 570      _dbInsert( 'phpwcms_log', $log, 'DELAYED' );
 571  
 572  }
 573  
 574  
 575  function init_frontend_edit() {
 576      // define VISIBLE_MODE
 577      // 0 = frontend (all) mode
 578      // 1 = article user mode
 579      // 2 = admin user mode
 580      if(empty($_SESSION["wcs_user_id"])) {
 581          define('VISIBLE_MODE', 0);
 582      } else {
 583          define('VISIBLE_MODE', $_SESSION['wcs_user_admin'] === 1 ? 2 : 1);
 584      }
 585      define ('FE_EDIT_LINK', VISIBLE_MODE == 0 || empty($GLOBALS['phpwcms']['frontend_edit']) ? false : true);
 586  }
 587  
 588  /**
 589   * Wrapper for htmlentities() to handle charset better inside of phpwcms
 590   **/
 591  function html_entities($string='', $quote_mode=ENT_QUOTES, $charset=PHPWCMS_CHARSET) {
 592      return @htmlentities($string, $quote_mode, $charset);
 593  }
 594  
 595  function getMicrotime() {
 596      list($usec, $sec) = explode(' ', microtime());
 597      return ((float)$usec + (float)$sec);
 598  }
 599  
 600  function getMicrotimeDiff($start=0) {
 601      return (getMicrotime() - $start);
 602  }
 603  
 604  /**
 605   * Return login.php
 606   */
 607  function get_login_file() {
 608      if(defined('PHPWCMS_LOGIN_PHP')) {
 609          return PHPWCMS_LOGIN_PHP;
 610      }
 611      global $phpwcms;
 612      $login = empty($GLOBALS['phpwcms']['login.php']) ? 'login.php' : $GLOBALS['phpwcms']['login.php'];
 613      if(is_file(PHPWCMS_ROOT.'/'.$login)) {
 614          define('PHPWCMS_LOGIN_PHP', $login);
 615          return PHPWCMS_LOGIN_PHP;
 616      }
 617      if(is_file(PHPWCMS_ROOT.'/login.php')) {
 618          define('PHPWCMS_LOGIN_PHP', 'login.php');
 619          return PHPWCMS_LOGIN_PHP;
 620      }
 621      die('Login.php cannot be found. We stop here!');
 622  }
 623  
 624  ?>


Generated: Wed Dec 30 05:55:15 2009 Cross-referenced by PHPXref 0.7