Zikula_Core
[ class tree: Zikula_Core ] [ index: Zikula_Core ] [ all elements ]

Source for file pnAPI.php

Documentation is available at pnAPI.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2001, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: pnAPI.php 24457 2008-07-10 07:08:27Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Core
  10.  * @subpackage pnAPI
  11. */
  12.  
  13.  
  14. /**
  15.  * Defines
  16.  */
  17.  
  18. /**
  19.  * Yes/no integer
  20.  */
  21. define('PNYES'1);
  22. define('PNNO'0);
  23.  
  24. /**
  25.  * State of modules
  26.  */
  27. define('PNMODULE_STATE_UNINITIALISED'1);
  28. define('PNMODULE_STATE_INACTIVE'2);
  29. define('PNMODULE_STATE_ACTIVE'3);
  30. define('PNMODULE_STATE_MISSING'4);
  31. define('PNMODULE_STATE_UPGRADED'5);
  32. define('PNMODULE_STATE_INVALID'-1);
  33.  
  34. /**
  35.  * Module dependency states
  36.  */
  37. define('PNMODULE_DEPENDENCY_REQUIRED'1);
  38. define('PNMODULE_DEPENDENCY_RECOMMENDED'2);
  39. define('PNMODULE_DEPENDENCY_CONFLICTS'3);
  40.  
  41. /**
  42.  * 'All' and 'unregistered' for user and group permissions
  43.  */
  44. define('PNPERMS_ALL''-1');
  45. define('PNPERMS_UNREGISTERED''0');
  46.  
  47. /**
  48.  * Core version informations - should be upgraded on each release for
  49.  * better control on config settings
  50.  */
  51. define('PN_VERSION_NUM''1.0.1');
  52. define('PN_VERSION_ID''Zikula');
  53. define('PN_VERSION_SUB''adam_baum');
  54.  
  55. /**
  56.  * Fake module for config vars
  57.  */
  58. define('PN_CONFIG_MODULE''/PNConfig');
  59.  
  60. /**
  61.  * Core initialisation stages
  62.  */
  63. define('PN_CORE_NONE'0);
  64. define('PN_CORE_CONFIG'1);
  65. define('PN_CORE_ADODB'2);
  66. define('PN_CORE_DB'4);
  67. define('PN_CORE_OBJECTLAYER'8);
  68. define('PN_CORE_TABLES'16);
  69. define('PN_CORE_SESSIONS'32);
  70. define('PN_CORE_LANGS'64);
  71. define('PN_CORE_MODS'128);
  72. define('PN_CORE_TOOLS'256);
  73. define('PN_CORE_AJAX'512);
  74. define('PN_CORE_DECODEURLS'1024);
  75. define('PN_CORE_THEME'2048);
  76. define('PN_CORE_ALL',  4095);
  77.  
  78.  
  79. /**
  80.  * Functions
  81.  */
  82.  
  83. /**
  84.  * get a configuration variable
  85.  *
  86.  * @param name the name of the variable
  87.  * @param default the default value to return if the requested param is not set
  88.  * @return mixed value of the variable, or false on failure
  89.  */
  90. function pnConfigGetVar($name$default=null)
  91. {
  92.     if (!isset($name)) {
  93.         return null;
  94.     }
  95.  
  96.     if (isset($GLOBALS['PNConfig']['System'][$name])) {
  97.         $mod_var $GLOBALS['PNConfig']['System'][$name];
  98.     else {
  99.         $mod_var pnModGetVar(PN_CONFIG_MODULE$name);
  100.         // cache
  101.         $GLOBALS['PNConfig']['System'][$name$mod_var;
  102.     }
  103.  
  104.     if (isset($mod_var)) {
  105.         return $mod_var;
  106.     }
  107.  
  108.     return $default;
  109. }
  110.  
  111. /**
  112.  * set a configuration variable
  113.  *
  114.  * @param name the name of the variable
  115.  * @param value the value of the variable
  116.  * @return bool true on success, false on failure
  117.  */
  118. function pnConfigSetVar($name$value='')
  119. {
  120.     $name = isset($name? (string)$name '';
  121.  
  122.     // The database parameter are not allowed to change
  123.     if (empty($name|| $name == 'dbtype' || $name == 'dbhost' || $name == 'dbuname' || $name == 'dbpass' ||
  124.         $name == 'dbname' || $name == 'system' || $name == 'prefix' || $name == 'encoded'{
  125.         return false;
  126.     }
  127.  
  128.     // set the variable
  129.     if (pnModSetVar(PN_CONFIG_MODULE$name$value))  {
  130.         // Update my vars
  131.         $GLOBALS['PNConfig']['System'][$name$value;
  132.         return true;
  133.     }
  134.  
  135.     return false;
  136. }
  137.  
  138. /**
  139.  * delete a configuration variable
  140.  *
  141.  * @param name the name of the variable
  142.  * @returns mixed value of deleted config var or false on failure
  143.  */
  144. function pnConfigDelVar($name)
  145. {
  146.     if (!isset($name)) {
  147.         return false;
  148.     }
  149.  
  150.     // The database parameter are not allowed to be deleted
  151.     if (empty($name|| $name == 'dbtype' || $name == 'dbhost' || $name == 'dbuname' || $name == 'dbpass' ||
  152.         $name == 'dbname' || $name == 'system' || $name == 'prefix' || $name == 'encoded'{
  153.         return false;
  154.     }
  155.  
  156.     // set the variable
  157.     pnModDelVar(PN_CONFIG_MODULE$name);
  158.  
  159.     // Update my vars
  160.     $val false;
  161.     if (isset($GLOBALS['PNConfig']['System'][$name])) {
  162.         $val $GLOBALS['PNConfig']['System'][$name];
  163.         unset($GLOBALS['PNConfig']['System'][$name]);
  164.     }
  165.  
  166.     // success
  167.     return $val;
  168. }
  169.  
  170. /**
  171.  * Initialise Zikula
  172.  * <br />
  173.  * Carries out a number of initialisation tasks to get Zikula up and
  174.  * running.
  175.  *
  176.  * @returns bool true initialisation successful false otherwise
  177.  */
  178. function pnInit($stages PN_CORE_ALL)
  179. {
  180.     static $globalscleansed false;
  181.  
  182.     // force register_globals = off
  183.     if ($globalscleansed == false && ini_get('register_globals')) {
  184.         foreach ($GLOBALS as $s_variable_name => $m_variable_value{
  185.             if (!in_array($s_variable_namearray('GLOBALS''argv''argc''_FILES''_COOKIE''_POST''_GET''_SERVER''_ENV''_SESSION''_REQUEST''s_variable_name''m_variable_value''_PNSession'))) {
  186.                 unset($GLOBALS[$s_variable_name]);
  187.             }
  188.         }
  189.         unset($GLOBALS['s_variable_name']);
  190.         unset($GLOBALS['m_variable_value']);
  191.         $globalscleansed true;
  192.     }
  193.  
  194.     // Neither Smarty nor Zikula itself works with magic_quotes_runtime (not to be confused with magic_quotes_gpc!)
  195.     if (get_magic_quotes_runtime())
  196.       die("Sorry, but Zikula does not support PHP magic_quotes_runtime - please disable this feature in your php.ini file.");
  197.  
  198.     if (!is_numeric($stages)) {
  199.         $stages PN_CORE_ALL;
  200.     }
  201.  
  202.     // initialise environment
  203.     if ($stages PN_CORE_CONFIG{
  204.         $GLOBALS['PNConfig'array();
  205.         $GLOBALS['PNRuntime'array();
  206.         // add some useful runtime vars
  207.         $GLOBALS['PNRuntime']['magic_quotes_runtime'get_magic_quotes_runtime();
  208.     }
  209.  
  210.     // store the load stages in a global so other API's can check whats loaded
  211.     $GLOBALS['loadstages'$stages;
  212.  
  213.     // Hack for some weird PHP systems that should have the
  214.     // LC_* constants defined, but don't
  215.     if (!defined('LC_TIME')) {
  216.         define('LC_TIME''LC_TIME');
  217.     }
  218.  
  219.     // quick hack until we remove this define
  220.     if (!defined('WHERE_IS_PERSO')) {
  221.         define('WHERE_IS_PERSO''');
  222.     }
  223.  
  224.     // we need this loaded before anything else to access the
  225.     // faster require/include_once functions
  226.     class_exists('Loader'|| require 'includes/pnobjlib/Loader.class.php';
  227.  
  228.     // load our core files
  229.     Loader::requireOnce('includes/pnobjlib/DataUtil.class.php');
  230.     Loader::requireOnce('includes/pnUser.php');
  231.     Loader::requireOnce('includes/pnMod.php');
  232.     Loader::loadClass('SessionUtil');
  233.     Loader::requireOnce('includes/pnSecurity.php');
  234.     Loader::requireOnce('includes/pnLang.php');
  235.     Loader::loadClass('PageUtil');
  236.     Loader::requireOnce('includes/pnRender.class.php');
  237.     // the next include independent from the rest of the pnobjlib
  238.     Loader::loadClass('StringUtil');
  239.  
  240.     if ($stages PN_CORE_THEME{
  241.         Loader::requireOnce('includes/pnBlocks.php');
  242.         Loader::loadClass('ThemeUtil');
  243.         // include old pnTheme.php for backwards compatibility
  244.         // To Do: Decide when to remove this
  245.         Loader::requireOnce('includes/pnTheme.php');
  246.         Loader::requireOnce('includes/pnTheme.class.php');
  247.     }
  248.  
  249.     // Initialise and load configuration
  250.     if ($stages PN_CORE_CONFIG{
  251.         Loader::requireOnce('config/config.php');
  252.         if (defined('_PNINSTALLVER')) {
  253.             $GLOBALS['PNConfig']['System']['PN_CONFIG_USE_OBJECT_ATTRIBUTION'false;
  254.             $GLOBALS['PNConfig']['System']['PN_CONFIG_USE_OBJECT_LOGGING'false;
  255.             $GLOBALS['PNConfig']['System']['PN_CONFIG_USE_OBJECT_META'false;
  256.         }
  257.     }
  258.  
  259.     // Initialize the (ugly) additional header array
  260.     $GLOBALS['additional_header'array();
  261.  
  262.     /**
  263.      * schemas - holds all component/instance schemas
  264.      * Should wrap this in a static one day, but the information
  265.      * isn't critical so we'll do it later
  266.      */
  267.      $GLOBALS['schemas'array();
  268.  
  269.     // Check that Zikula is installed before continuing
  270.     if (pnConfigGetVar('installed'== && !defined('_PNINSTALLVER')) {
  271.         header('HTTP/1.1 503 Service Unavailable');
  272.         if (file_exists('config/templates/notinstalled.htm')) {
  273.             Loader::requireOnce('config/templates/notinstalled.htm');
  274.         else {
  275.             Loader::requireOnce('includes/templates/notinstalled.htm');
  276.         }
  277.         pnShutDown();
  278.     }
  279.  
  280.     if ($stages PN_CORE_ADODB{
  281.         // load ADODB
  282.         pnADODBInit();
  283.     }
  284.  
  285.     if ($stages PN_CORE_OBJECTLAYER{
  286.         Loader::requireOnce('includes/pnobjlib/pnobjlib_globals.inc');
  287.         Loader::loadClass('LogUtil');
  288.         Loader::requireOnce('includes/pnobjlib/debug.php');
  289.         Loader::loadClass('DBConnectionStack');
  290.         Loader::loadClass('ObjectUtil');
  291.         Loader::loadClass('DBUtil');
  292.         Loader::loadClass('RandomUtil');
  293.         Loader::loadClass('DateUtil');
  294.         Loader::loadClass('PNObject');
  295.         Loader::loadClass('PNObjectArray');
  296.         Loader::loadClass('FormUtil');
  297.         Loader::loadClass('SecurityUtil');
  298.         Loader::loadClass('CookieUtil');
  299.         Loader::loadClass('WorkflowUtil');
  300.     }
  301.  
  302.     if ($stages PN_CORE_DB{
  303.         // Connect to database
  304.         if (!pnDBInit()) {
  305.             if (!defined('_PNINSTALLVER')) {
  306.                 header('HTTP/1.1 503 Service Unavailable');
  307.                 if (file_exists('config/templates/dbconnectionerror.htm')) {
  308.                     Loader::requireOnce('config/templates/dbconnectionerror.htm');
  309.                 else {
  310.                     Loader::requireOnce('includes/templates/dbconnectionerror.htm');
  311.                 }
  312.                 pnShutDown();
  313.             else {
  314.                 return false;
  315.             }
  316.         }
  317.     }
  318.  
  319.     if ($stages PN_CORE_TABLES{
  320.         // Initialise and load pntables
  321.         pnDBSetTables();
  322.         // ensure that the base modules info is available
  323.         pnModDBInfoLoad('Modules''Modules');
  324.         pnModDBInfoLoad('Theme''Theme');
  325.         pnModDBInfoLoad('Profile''Profile');
  326.         pnModDBInfoLoad('Users''Users');
  327.         pnModDBInfoLoad('Groups''Groups');
  328.         pnModDBInfoLoad('Permissions''Permissions');
  329.         // load core module vars
  330.         pnModInitCoreVars();
  331.         // if we've got this far an error handler can come into play
  332.         // (except in the installer)
  333.         if (!defined('_PNINSTALLVER')) {
  334.             set_error_handler('pnErrorHandler');
  335.         }
  336.     }
  337.  
  338.     if ($stages PN_CORE_SESSIONS{
  339.         // Other includes
  340.         // ensure that the sesssions table info is available
  341.         pnModDBInfoLoad('Users''Users');
  342.         $anonymoussessions pnConfigGetVar('anonymoussessions');
  343.         if ($anonymoussessions=='1' || !empty($_COOKIE[SessionUtil::getCookieName()])) {
  344.             // we need to create a session for guests as configured or
  345.             // a cookie exists which means we have been here before
  346.             // Start session
  347.             SessionUtil::requireSession();
  348.  
  349.             // Auto-login via HTTP(S) REMOTE_USER property
  350.             if (pnConfigGetVar('session_http_login'&& !pnUserLoggedIn()) {
  351.                 pnUserLogInHTTP();
  352.             }
  353.         }
  354.     }
  355.  
  356.     if ($stages PN_CORE_LANGS{
  357.         Loader::loadClass('LanguageUtil');
  358.         // Load our language files
  359.         pnLangLoad();
  360.     }
  361.  
  362.     if ($stages PN_CORE_MODS{
  363.         // Set up multisites
  364.         if (!defined('WHERE_IS_PERSO'))
  365.             define('WHERE_IS_PERSO''');
  366.  
  367.         // Set compression on if desired
  368.         if (pnConfigGetVar('UseCompression'== 1{
  369.             ob_start("ob_gzhandler");
  370.         }
  371.  
  372.         // Legacy includes
  373.         if (pnConfigGetVar('loadlegacy'== '1'{
  374.             Loader::requireOnce('includes/legacy/legacy.php');
  375.             Loader::requireOnce('includes/legacy/queryutil.php');
  376.             Loader::requireOnce('includes/legacy/xhtml.php');
  377.             Loader::requireOnce('includes/legacy/oldfuncs.php');
  378.         }
  379.  
  380.         // New pnAnticracker code needs to be after pnMod as it's now a module - markwest
  381.         // Cross-Site Scripting attack defense - Sent by larsneo
  382.         // some syntax checking against injected javascript
  383.         if (pnModAvailable('SecurityCenter'&& pnConfigGetVar('enableanticracker'== && pnModAPILoad('SecurityCenter''user')) {
  384.             pnModAPIFunc('SecurityCenter''user''secureinput');
  385.         }
  386.     }
  387.  
  388.     if ($stages PN_CORE_TOOLS{
  389.         Loader::requireOnce('includes/pnHTML.php');
  390.         // Banner system
  391.         // TODO - move to banners module
  392.         if (pnModAvailable('Banners')) {
  393.             Loader::requireOnce('includes/pnBanners.php');
  394.         }
  395.  
  396.         // Call Stats module counter code if installed
  397.         if (pnModAvailable('Stats'&& pnModAPILoad('Stats''user')) {
  398.             pnModAPIFunc('Stats''user''collect');
  399.         }
  400.         // Call Referers module counter code if installed
  401.         if (pnModAvailable('Referers'&& pnModAPILoad('Referers''user')) {
  402.             pnModAPIFunc('Referers''user''collect');
  403.         }
  404.     }
  405.  
  406.     if ($stages PN_CORE_AJAX{
  407.         Loader::loadClass('AjaxUtil');
  408.     }
  409.  
  410.     if ($stages PN_CORE_DECODEURLS{
  411.         pnQueryStringDecode();
  412.     }
  413.  
  414.     if ($stages PN_CORE_THEME{
  415.         // register default page vars
  416.         PageUtil::registerVar('title');
  417.         PageUtil::registerVar('description'falsepnConfigGetVar('slogan'));
  418.         PageUtil::registerVar('keywords'true);
  419.         PageUtil::registerVar('stylesheet'true);
  420.         PageUtil::registerVar('javascript'true);
  421.         PageUtil::registerVar('body'true);
  422.         PageUtil::registerVar('rawtext'true);
  423.         PageUtil::registerVar('footer'true);
  424.         // Load the theme
  425.         ThemeUtil::load(pnUserGetTheme(true));
  426.     }
  427.  
  428.     // check the users status, if not 1 then log him out
  429.     if (pnUserLoggedIn()) {
  430.         $userstatus pnUserGetVar('activated');
  431.         if ($userstatus<>1{
  432.             pnUserLogOut();
  433.             SessionUtil::requireSession();
  434.             SessionUtil::setVar('confirmtou'0);
  435.             LogUtil::registerStatus(_LOGOUTFORCED);
  436.             pnRedirect(pnModURL('Users''user''loginscreen'));
  437.             pnShutDown();
  438.         }
  439.     }
  440.  
  441.     // remove log files being too old
  442.  
  443.     return true;
  444. }
  445.  
  446. /**
  447.  * Initialise DB connection
  448.  * @return bool true if successful, false otherwise
  449.  */
  450. function pnDBInit()
  451. {
  452.     return DBConnectionStack::init ();
  453. }
  454.  
  455. /**
  456.  * get a list of database connections
  457.  *
  458.  * @author Eric Barr
  459.  * @copyright Copyright (c) 2003 Envolution; Eric Barr. All rights reserved.
  460.  * @author Roger Raymond
  461.  * @param bool $pass_by_reference default = false
  462.  * @param string $fetchmode set ADODB fetchmode ADODB_FETCH_NUM, ADODB_FETCH_ASSOC, ADODB_FETCH_DEFAULT, ADODB_FETCH_BOTH
  463.  * @return array array of database connections
  464.  */
  465. function pnDBGetConn($pass_by_reference false$fetchmode ADODB_FETCH_NUM)
  466. {
  467.     $ret DBConnectionStack::getConnection ($fetchmode);
  468.  
  469.     // If $pass_by_reference is true, return a reference to the dbconn object
  470.     if ($pass_by_reference == true{
  471.         return $ret;
  472.     }
  473.  
  474.     $dbconn array($ret);
  475.     return $dbconn;
  476. }
  477.  
  478. /**
  479.  * get a list of database tables
  480.  *
  481.  * @author Eric Barr
  482.  * @copyright Copyright (c) 2003 Envolution; Eric Barr. All rights reserved.
  483.  * @author Roger Raymond
  484.  * @return array array of database tables
  485.  */
  486. function pnDBGetTables()
  487. {
  488.     return $GLOBALS['pntables'];
  489. }
  490.  
  491. /*
  492.  * get a list of dbms specific table options
  493.  *
  494.  * For use by ADODB's data dictionary
  495.  * Additional database specific settings can be defined here
  496.  * See ADODB's data dictionary docs for full details
  497.  *
  498.  * @author Mark West
  499.  * @since v1.93
  500.  * @param $tablename (optional) if tablename and there is a set of options configured
  501.  * for this table via pntable.php then this  we're returning these options, the default options are returned otherwise
  502.  */
  503. function pnDBGetTableOptions($tablename='')
  504. {
  505.     if($tablename!=''){
  506.         $pntables pnDBGetTables();
  507.         if(isset($pntables[$tablename.'_def'])){
  508.             return $pntables[$tablename.'_def'];
  509.         }
  510.     }
  511.     static $tableoptions;
  512.  
  513.     if (!isset($tableoptions)) {
  514.         // for mysql we need to get the the version to act on
  515.         // and the table type (myisam/innodb)
  516.         $serverinfo DBUtil::serverInfo();
  517.         $dbtype DBConnectionStack::getConnectionDBType();
  518.  
  519.         switch ($dbtype{
  520.             case 'mysql':
  521.                 $type pnConfigGetVar('tabletype');
  522.                 if (!isset($type|| empty($type)) $type 'MyISAM';
  523.                 if (substr($serverinfo['version']03== '3.2'{
  524.                     $tableoptions array('mysql' => 'type = ' $type);
  525.                 else {
  526.                     $tableoptions array('mysql' => 'engine = ' $type);
  527.                 }
  528.                 break;
  529.             default:
  530.                 $tableoptions array();
  531.         }
  532.     }
  533.  
  534.     return $tableoptions;
  535. }
  536.  
  537. /**
  538.  * Set Database Table Listing
  539.  *
  540.  * @desc        Creates the database table listing if it hasn't been created yet
  541.  *               and merges new table listings into the master list.
  542.  * @author Eric Barr
  543.  * @copyright Copyright (c) 2003 Envolution; Eric Barr. All rights reserved.
  544.  * @access      public
  545.  * @param       array $newtables 
  546.  * @return      void 
  547.  */
  548. function pnDBSetTables()
  549. {
  550.     // Create a static var to hold the database table listing
  551.     static $pntables;
  552.  
  553.     // If the table listing doesn't exist create it with the input array
  554.     $pntable array();
  555.     if (!is_array($pntables)) {
  556.         // if a multisite has its own pntables.
  557.         if (defined('WHERE_IS_PERSO'&& file_exists(WHERE_IS_PERSO 'pntables.php')) {
  558.             require_once WHERE_IS_PERSO 'pntables.php';
  559.         elseif (file_exists('pntables')) {
  560.             Loader::requireOnce('pntables.php');
  561.         }
  562.     }
  563.  
  564.     // Set the pntables in the global listing for pnDBGetTables to have access to
  565.     $GLOBALS['pntables'$pntable;
  566.     return;
  567. }
  568.  
  569. /**
  570.  * get table prefix
  571.  *
  572.  * get's the database prefix for the current site
  573.  *
  574.  * In a non multisite scenario this will be the 'prefix' config var
  575.  * from config/config.php. For a multisite configuration the multistes
  576.  * module will manage the prefixes for a given table
  577.  *
  578.  * The table name parameter is the table name to get the prefix for
  579.  * minus the prefix and seperating _
  580.  * e.g. pnDBGetPrefix returns pn_modules for pnDBGetPrefix('modules');
  581.  *
  582.  * @param table - table name
  583.  * @author Mark West
  584.  * @since 1.103
  585.  */
  586. function pnDBGetTablePrefix($table)
  587. {
  588.     if (!isset($table)) {
  589.         return false;
  590.     }
  591.  
  592.     if (!defined('_PNINSTALLVER'&& pnModAvailable('Multisites'&& pnModAPILoad('Multisites''user')) {
  593.         $prefix pnModAPIFunc('Multisites''user''getprefix'array('table' => $table));
  594.     else {
  595.         $prefix pnConfigGetVar('prefix');
  596.     }
  597.  
  598.     return $prefix;
  599.  
  600. }
  601.  
  602. /**
  603.  * clean user input
  604.  *
  605.  * Gets a global variable, cleaning it up to try to ensure that
  606.  * hack attacks don't work
  607.  *
  608.  * @deprecated
  609.  * @see FormUtil::getPassedValues
  610.  * @param var name of variable to get
  611.  * @param  ...
  612.  *
  613.  * @return mixed prepared variable if only one variable passed
  614.  *  in, otherwise an array of prepared variables
  615.  */
  616. {
  617.     LogUtil::log('Function pnVarCleanFromInput() is deprecated. Please use FormUtil::getPassedValue() instead.''STRICT');
  618.  
  619.     $vars func_get_args();
  620.     $resarray array();
  621.     foreach ($vars as $var{
  622.         $resarray[FormUtil::getPassedValue($var);
  623.     }
  624.  
  625.     if (func_num_args(== 1{
  626.         return $resarray[0];
  627.     }
  628.  
  629.     return $resarray;
  630. }
  631.  
  632. /**
  633.  * strip slashes
  634.  *
  635.  * stripslashes on multidimensional arrays.
  636.  * Used in conjunction with pnVarCleanFromInput
  637.  *
  638.  * @access private
  639.  * @param any variables or arrays to be stripslashed
  640.  */
  641. function pnStripslashes (&$value)
  642. {
  643.     if (empty($value))
  644.         return;
  645.  
  646.     if (!is_array($value)) {
  647.         $value stripslashes($value);
  648.     else {
  649.         array_walk($value'pnStripslashes');
  650.     }
  651. }
  652.  
  653. /**
  654.  * ready user output
  655.  *
  656.  * Gets a variable, cleaning it up such that the text is
  657.  * shown exactly as expected
  658.  *
  659.  * @deprecated
  660.  * @see DataUtil::formatForDisplay
  661.  * @param var variable to prepare
  662.  * @param  ...
  663.  * @return mixed prepared variable if only one variable passed
  664.  *  in, otherwise an array of prepared variables
  665.  */
  666. function pnVarPrepForDisplay ()
  667. {
  668.     LogUtil::log('Function pnVarPrepForDisplay() is deprecated. Please use DataUtil::formatForDisplay() instead.''STRICT');
  669.  
  670.     $resarray array();
  671.     $ourvars func_get_args();
  672.     foreach ($ourvars as $ourvar{
  673.         $resarray[DataUtil::formatForDisplay($ourvar);
  674.     }
  675.     // Return vars
  676.     if (func_num_args(== 1{
  677.         return $resarray[0];
  678.     else {
  679.         return $resarray;
  680.     }
  681. }
  682.  
  683. /**
  684.  * ready HTML output
  685.  *
  686.  * Gets a variable, cleaning it up such that the text is
  687.  * shown exactly as expected, except for allowed HTML tags which
  688.  * are allowed through
  689.  * @author Xaraya development team
  690.  *
  691.  * @deprecated
  692.  * @see DataUtil::formatForDisplayHTML
  693.  * @param var variable to prepare
  694.  * @param ... 
  695.  * @return string/array prepared variable if only one variable passed
  696.  *  in, otherwise an array of prepared variables
  697.  */
  698. function pnVarPrepHTMLDisplay ()
  699. {
  700.     LogUtil::log('Function pnVarPrepHTMLDisplay() is deprecated. Please use DataUtil::formatForDisplayHTML() instead.''STRICT');
  701.  
  702.     $resarray array();
  703.     $ourvars func_get_args();
  704.     foreach ($ourvars as $ourvar{
  705.         $resarray[DataUtil::formatForDisplayHTML ($ourvar);
  706.     }
  707.  
  708.     // Return vars
  709.     if (func_num_args(== 1{
  710.         return $resarray[0];
  711.     }
  712.  
  713.     return $resarray;
  714. }
  715.  
  716. /**
  717.  * ready database output
  718.  *
  719.  * Gets a variable, cleaning it up such that the text is
  720.  * stored in a database exactly as expected
  721.  *
  722.  * @deprecated
  723.  * @see DataUtil::formatForStore()
  724.  * @param var variable to prepare
  725.  * @param  ...
  726.  * @return mixed prepared variable if only one variable passed
  727.  *  in, otherwise an array of prepared variables
  728.  */
  729. function pnVarPrepForStore ()
  730. {
  731.     LogUtil::log('Function pnVarPrepForStore() is deprecated. Please use DataUtil::formatForStore() instead.''STRICT');
  732.  
  733.     $resarray array();
  734.     $ourvars func_get_args();
  735.     foreach ($ourvars as $ourvar{
  736.         $resarray[DataUtil::formatForStore ($ourvar);
  737.     }
  738.  
  739.     // Return vars
  740.     if (func_num_args(== 1{
  741.         return $resarray[0];
  742.     }
  743.  
  744.     return $resarray;
  745. }
  746.  
  747. /**
  748.  * ready operating system output
  749.  *
  750.  * Gets a variable, cleaning it up such that any attempts
  751.  * to access files outside of the scope of the Zikula
  752.  * system is not allowed.
  753.  *
  754.  * @deprecated
  755.  * @see DataUtil::formatForOS()
  756.  * @param var variable to prepare
  757.  * @param  ...
  758.  * @return mixed prepared variable if only one variable passed
  759.  *  in, otherwise an array of prepared variables
  760.  ***/
  761. function pnVarPrepForOS ()
  762. {
  763.     LogUtil::log('Function pnVarPrepForOS() is deprecated. Please use DataUtil::formatForOS() instead.''STRICT');
  764.  
  765.     $resarray array();
  766.  
  767.     $ourvars func_get_args();
  768.     foreach ($ourvars as $ourvar{
  769.         $resarray[DataUtil::formatForOS ($ourvar);
  770.     }
  771.  
  772.     // Return vars
  773.     if (func_num_args(== 1{
  774.         return $resarray[0];
  775.     }
  776.  
  777.     return $resarray;
  778. }
  779.  
  780. /**
  781.  * remove censored words
  782.  */
  783. function pnVarCensor()
  784. {
  785.     LogUtil::log('using deprecated function pnVarCensor in ' DataUtil::formatForDisplay(pnModGetName()) ', please activate the MultiHook for this module instead');
  786.  
  787.     $resarray array();
  788.     $ourvars func_get_args();
  789.     foreach ($ourvars as $ourvar{
  790.         $resarray[DataUtil::censor ($ourvar);
  791.     }
  792.  
  793.     // Return vars
  794.     if (func_num_args(== 1{
  795.         return $resarray[0];
  796.     }
  797.  
  798.     return $resarray;
  799. }
  800.  
  801. /**
  802.  * validate a zikula variable
  803.  *
  804.  * @access public
  805.  * @author Damien Bonvillain
  806.  * @author Gregor J. Rothfuss
  807.  * @author J�rg Napp
  808.  * @since 1.23 - 2002/02/01
  809.  * @param $var   the variable to validate
  810.  * @param $type  the type of the validation to perform (email, url etc.)
  811.  * @param $args  optional array with validation-specific settings (never used...)
  812.  * @return bool true if the validation was successful, false otherwise
  813.  */
  814. function pnVarValidate($var$type$args 0)
  815. {
  816.     if (!isset($var|| !isset($type)) {
  817.         return false;
  818.     }
  819.  
  820.     // typecasting (might be useless in this function)
  821.     $var = (string)$var;
  822.     $type = (string)$type;
  823.  
  824.     static $maxlength array('modvar' => 64,
  825.                               'func'   => 512,
  826.                               'api'    => 187,
  827.                               'theme'  => 200,
  828.                               'uname'  => 25,
  829.                               'config' => 64);
  830.  
  831.     static $minlength array('mod'    => 1,
  832.                               'modvar' => 1,
  833.                               'uname'  => 1,
  834.                               'config' => 1);
  835.  
  836.     // commented out some regexps until some useful and working ones are found
  837.     static $regexp    array// 'mod'    => '/^[^\\\/\?\*\"\'\>\<\:\|]*$/',
  838.                                // 'func'   => '/[^0-9a-zA-Z_]/',
  839.                                // 'api'    => '/[^0-9a-zA-Z_]/',
  840.                                // 'theme'  => '/^[^\\\/\?\*\"\'\>\<\:\|]*$/',
  841.                               'email'  => '/^(?:[^\s\000-\037\177\(\)<>@,;:\\"\[\]]\.?)+@(?:[^\s\000-\037\177\(\)<>@,;:\\\"\[\]]\.?)+\.[a-z]{2,6}$/Ui',
  842.                               'url'    => '/^([!#\$\046-\073=\077-\132_\141-\172~]|(?:%[a-f0-9]{2}))+$/i');
  843.  
  844.  
  845.     // special cases
  846.     if ($type == 'mod' && $var == '/PNConfig'{
  847.         return true;
  848.     }
  849.  
  850.     if ($type == 'config' && ($var == 'dbtype'||
  851.                              ($var == 'dbhost'||
  852.                              ($var == 'dbuname'||
  853.                              ($var == 'dbpass'||
  854.                              ($var == 'dbname'||
  855.                              ($var == 'system'||
  856.                              ($var == 'prefix'||
  857.                              ($var == 'encoded')) {
  858.         // The database parameter are not allowed to change
  859.         return false;
  860.     }
  861.  
  862.     if ($type == 'email' || $type == 'url'{
  863.         // CSRF protection for email and url
  864.         $var str_replace(array('\r''\n''%0d''%0a')''$var);
  865.  
  866.         if (pnConfigGetVar('idnnames'== 1{
  867.             // transfer between the encoded (Punycode) notation and the decoded (8bit) notation.
  868.             Loader::requireOnce('includes/classes/idna/idna_convert.class.php');
  869.             $IDN new idna_convert();
  870.             $var $IDN->encode(DataUtil::convertToUTF8($var));
  871.         }
  872.         // all characters must be 7 bit ascii
  873.         $length strlen($var);
  874.         $idx 0;
  875.         while ($length--{
  876.             $c $var[$idx++];
  877.             if (ord($c127{
  878.                 return false;
  879.             }
  880.         }
  881.     }
  882.  
  883.     if ($type == 'url'{
  884.         // check for url
  885.         $url_array @parse_url($var);
  886.         if (!empty($url_array&& empty($url_array['scheme'])) {
  887.             return false;
  888.         }
  889.     }
  890.  
  891.     if ($type == 'uname'{
  892.         // check for invalid characters
  893.         if strstr($varchr(160)) || strstr($varchr(173)) ) {
  894.             return false;
  895.         }
  896.     }
  897.  
  898.     // variable passed special checks. We now to generic checkings.
  899.  
  900.     // check for maximal length
  901.     if (isset($maxlength[$type]&& strlen($var$maxlength[$type]{
  902.         return false;
  903.     }
  904.  
  905.     // check for minimal length
  906.     if (isset($minlength[$type]&& strlen($var$minlength[$type]{
  907.         return false;
  908.     }
  909.  
  910.     // check for regular expression
  911.     if (isset($regexp[$type]&& !preg_match($regexp[$type]$var)) {
  912.         return false;
  913.     }
  914.  
  915.     // all tests for illegal entries failed, so we assume the var is ok ;-)
  916.     return true;
  917. }
  918.  
  919. /**
  920.  * get status message from previous operation
  921.  *
  922.  * Obtains any status message, and also destroys
  923.  * it from the session to prevent duplication
  924.  *
  925.  *
  926.  * @deprecated
  927.  * @see Logutil.class.php
  928.  * @return string the status message
  929.  */
  930. function pnGetStatusMsg()
  931. {
  932.     $msgStatus SessionUtil::getVar('_PNStatusMsg');
  933.     SessionUtil::delVar('_PNStatusMsg');
  934.     $msgError SessionUtil::getVar('_PNErrorMsg');
  935.     SessionUtil::delVar('_PNErrorMsg');
  936.     // Error message overrides status message
  937.     if (!empty($msgError)) {
  938.         $msgStatus $msgError;
  939.     }
  940.  
  941.     return $msgStatus;
  942. }
  943.  
  944. /**
  945.  * get base URI for Zikula
  946.  *
  947.  * @author Martin Andersen
  948.  * @return string base URI for Zikula
  949.  */
  950. function pnGetBaseURI()
  951. {
  952.     static $path;
  953.  
  954.     if (!isset($path)) {
  955.         $path dirname(pnServerGetVar('PHP_SELF'));
  956.         $path str_replace('\\''/'$path);
  957.         if ($path == '/'$path '';
  958.         // remove our entry point if found
  959.         $entrypoint pnConfigGetVar('entrypoint');
  960.         if (empty($entrypoint)) {
  961.             $entrypoint 'index.php';
  962.         }
  963.         $strip stristr($path'/'.$entrypoint);
  964.         $path str_replace($strip''$path);
  965.     }
  966.  
  967.     return $path;
  968. }
  969.  
  970. /**
  971.  * get base URL for Zikula
  972.  *
  973.  * @return string base URL for Zikula
  974.  */
  975. function pnGetBaseURL()
  976. {
  977.     $server pnServerGetVar('HTTP_HOST');
  978.  
  979.     // IIS sets HTTPS=off
  980.     $https pnServerGetVar('HTTPS''off');
  981.     if ($https != 'off'{
  982.         $proto 'https://';
  983.     else {
  984.         $proto 'http://';
  985.     }
  986.  
  987.     $path pnGetBaseURI();
  988.  
  989.     return "$proto$server$path/";
  990. }
  991.  
  992. /**
  993.  * Carry out a redirect
  994.  *
  995.  * @param string $redirecturl URL to redirect to
  996.  * @param array $addtionalheaders array of header strings to send with redirect
  997.  * @returns bool true if redirect successful, false otherwise
  998.  */
  999. function pnRedirect($redirecturl$additionalheaders array())
  1000. {
  1001.     // very basic input validation against HTTP response splitting
  1002.     $redirecturl str_replace(array('\r''\n''%0d''%0a')''$redirecturl);
  1003.  
  1004.     // check if the headers have already been sent
  1005.     if (headers_sent()) {
  1006.         return false;
  1007.     }
  1008.  
  1009.     // Always close session before redirect
  1010.  
  1011.     // add any additional headers supplied
  1012.     if (!empty($additionalheaders)) {
  1013.         foreach ($additionalheaders as $additionalheader{
  1014.             header($additionalheader);
  1015.         }
  1016.     }
  1017.  
  1018.     if (preg_match('!^(?:http|https|ftp|ftps):\/\/!'$redirecturl)) {
  1019.         // Absolute URL - simple redirect
  1020.     elseif (substr($redirecturl01== '/'{
  1021.         // Root-relative links
  1022.         $redirecturl 'http'.(pnServerGetVar('HTTPS')=='on' 's' '').'://'.pnServerGetVar('HTTP_HOST').$redirecturl;
  1023.     else {
  1024.         // Relative URL
  1025.         // Removing leading slashes from redirect url
  1026.         $redirecturl preg_replace('!^/*!'''$redirecturl);
  1027.         // Get base URL and append it to our redirect url
  1028.         $baseurl pnGetBaseURL();
  1029.         $redirecturl $baseurl.$redirecturl;
  1030.     }
  1031.     header("Location: $redirecturl");
  1032.     return true;
  1033. }
  1034.  
  1035. /**
  1036.  * check to see if this is a local referral
  1037.  *
  1038.  * @param bool strict - strict checking ensures that a referer must be set as well as local
  1039.  * @return bool true if locally referred, false if not
  1040.  */
  1041. function pnLocalReferer($strict false)
  1042. {
  1043.     $server pnServerGetVar('HTTP_HOST');
  1044.     $referer pnServerGetVar('HTTP_REFERER');
  1045.  
  1046.     // an empty referer returns true unless strict checking is enabled
  1047.     if (!$strict && empty($referer)) {
  1048.         return true;
  1049.     }
  1050.     // check the http referer
  1051.     if (preg_match("!^https?://$server/!"$referer)) {
  1052.         return true;
  1053.     }
  1054.  
  1055.     return false;
  1056. }
  1057.  
  1058. // Hack - we need this for themes, but will get rid of it soon
  1059. if (!function_exists('GetUserTime')) {
  1060.   /**
  1061.     * get a Time String in the right format
  1062.     *
  1063.     *
  1064.     * @param time - prefix string
  1065.     * @return mixed string if successfull, false if not
  1066.     */
  1067.     function GetUserTime($time)
  1068.     {
  1069.         if (empty($time)) {
  1070.             return;
  1071.         }
  1072.  
  1073.         if (pnUserLoggedIn()) {
  1074.             $time += (pnUserGetVar(pnUserDynamicAlias('timezone_offset')) pnConfigGetVar('timezone_server')) 3600;
  1075.         else {
  1076.             $time += (pnConfigGetVar('timezone_offset'pnConfigGetVar('timezone_server')) 3600;
  1077.         }
  1078.  
  1079.         return($time);
  1080.     }
  1081. }
  1082.  
  1083. /**
  1084.  * send an email
  1085.  *
  1086.  * e-mail messages should now be send with a pnModAPIFunc call to the mailer module
  1087.  *
  1088.  * @deprecated
  1089.  * @param to - recipient of the email
  1090.  * @param subject - title of the email
  1091.  * @param message - body of the email
  1092.  * @param headers - extra headers for the email
  1093.  * @param html - message is html formatted
  1094.  * @param debug - if 1, echo mail content
  1095.  * @return bool true if the email was sent, false if not
  1096.  */
  1097. function pnMail($to$subject$message=''$headers ''$html 0$debug 0)
  1098. {
  1099.     if (empty($to|| !isset($subject)) {
  1100.         return false;
  1101.     }
  1102.  
  1103.     // set initial return value until we know we have a valid return
  1104.     $return false;
  1105.  
  1106.     // check if the mailer module is availble and if so call the API
  1107.     if ((pnModAvailable('Mailer')) && (pnModAPILoad('Mailer''user'))) {
  1108.         $return pnModAPIFunc('Mailer''user''sendmessage'array('toaddress' => $to,
  1109.                                                                       'subject' => $subject,
  1110.                                                                       'headers' => $headers,
  1111.                                                                       'body' => $message,
  1112.                                                                       'headers' => $headers,
  1113.                                                                       'html' => $html));
  1114.     }
  1115.  
  1116.     return $return;
  1117. }
  1118.  
  1119. /**
  1120.  * Function that compares the current php version on the
  1121.  * system with the target one
  1122.  *
  1123.  * Deprecate function reverting to php detecion function
  1124.  *
  1125.  * @deprecated
  1126.  */
  1127. function pnPhpVersionCheck($vercheck='')
  1128. {
  1129.     $minver str_replace("."""$vercheck);
  1130.     $curver str_replace("."""phpversion());
  1131.  
  1132.     if ($curver >= $minver{
  1133.         return true;
  1134.     else {
  1135.         return false;
  1136.     }
  1137. }
  1138.  
  1139. /**
  1140.  * initialise ADODB
  1141.  *
  1142.  * @return void 
  1143.  */
  1144. function pnADODBInit()
  1145. {
  1146.     // ADODB configuration
  1147.     global $ADODB_CACHE_DIR;
  1148.     $ADODB_CACHE_DIR realpath($GLOBALS['PNConfig']['System']['temp''/adodb');
  1149.     if (!defined('ADODB_DIR')) {
  1150.         define('ADODB_DIR'getcwd().'/includes/classes/adodb');
  1151.     }
  1152.     Loader::requireOnce('includes/classes/adodb/adodb.inc.php');
  1153.  
  1154.     // ADODB Error handle
  1155.     if ($GLOBALS['PNConfig']['Debug']['sql_adodb']{
  1156.         Loader::requireOnce('includes/classes/adodb/adodb-errorhandler.inc.php');
  1157.     }
  1158.  
  1159.     // decode encoded new DB parameters
  1160.     $ak array_keys($GLOBALS['PNConfig']['DBInfo']);
  1161.     foreach ($ak as $key{
  1162.         if ($GLOBALS['PNConfig']['DBInfo'][$key]['encoded']{
  1163.             $GLOBALS['PNConfig']['DBInfo'][$key]['dbuname'base64_decode($GLOBALS['PNConfig']['DBInfo'][$key]['dbuname']);
  1164.             $GLOBALS['PNConfig']['DBInfo'][$key]['dbpass'base64_decode($GLOBALS['PNConfig']['DBInfo'][$key]['dbpass']);
  1165.             $GLOBALS['PNConfig']['DBInfo'][$key]['encoded'0;
  1166.         }
  1167.     }
  1168.  
  1169.     // debugger if required
  1170.     if ($GLOBALS['PNConfig']['Debug']['debug']{
  1171.         Loader::requireOnce('includes/classes/lensdebug/lensdebug.class.php');
  1172.         $GLOBALS['PNRuntime']['dbg'new LensDebug();
  1173.         $GLOBALS['PNRuntime']['debug_sqlcalls'0;
  1174.     }
  1175.  
  1176.     // initialise time to render
  1177.     if ($GLOBALS['PNConfig']['Debug']['pagerendertime']{
  1178.         $mtime explode(' 'microtime());
  1179.         $GLOBALS['PNRuntime']['dbg_starttime'$mtime[1$mtime[0];
  1180.     }
  1181. }
  1182.  
  1183. /**
  1184.  * Gets a server variable
  1185.  *
  1186.  * Returns the value of $name from $_SERVER array.
  1187.  * Accepted values for $name are exactly the ones described by the
  1188.  * {@link http://www.php.net/manual/en/reserved.variables.html#reserved.variables.server PHP manual}.
  1189.  * If the server variable doesn't exist void is returned.
  1190.  *
  1191.  * @author Marco Canini <marco@xaraya.com>, Michel Dalle
  1192.  * @access public
  1193.  * @param name string the name of the variable
  1194.  * @param default the default value to return if the requested param is not set
  1195.  * @return mixed value of the variable
  1196.  */
  1197. function pnServerGetVar($name$default=null)
  1198. {
  1199.     // Check the relevant superglobals
  1200.     if (!empty($name&& isset($_SERVER[$name])) {
  1201.         return $_SERVER[$name];
  1202.     }
  1203.     return $default// nothing found -> return default
  1204. }
  1205.  
  1206. /**
  1207.  * Gets the host name
  1208.  *
  1209.  * Returns the server host name fetched from HTTP headers when possible.
  1210.  * The host name is in the canonical form (host + : + port) when the port is different than 80.
  1211.  *
  1212.  * @author Marco Canini <marco@xaraya.com>
  1213.  * @access public
  1214.  * @return string HTTP host name
  1215.  */
  1216. function pnGetHost()
  1217. {
  1218.     $server pnServerGetVar('HTTP_HOST');
  1219.     if (empty($server)) {
  1220.         // HTTP_HOST is reliable only for HTTP 1.1
  1221.         $server pnServerGetVar('SERVER_NAME');
  1222.         $port pnServerGetVar('SERVER_PORT');
  1223.         if ($port != '80'$server .= ":$port";
  1224.     }
  1225.     return $server;
  1226. }
  1227.  
  1228. /**
  1229.  * Get current URI (and optionally add/replace some parameters)
  1230.  *
  1231.  * @access public
  1232.  * @param args array additional parameters to be added to/replaced in the URI (e.g. theme, ...)
  1233.  * @return string current URI
  1234.  */
  1235. function pnGetCurrentURI($args array())
  1236. {
  1237.     // get current URI
  1238.     $request pnServerGetVar('REQUEST_URI');
  1239.  
  1240.     if (empty($request)) {
  1241.         // adapted patch from Chris van de Steeg for IIS
  1242.         // TODO: please test this :)
  1243.         $scriptname pnServerGetVar('SCRIPT_NAME');
  1244.         $pathinfo pnServerGetVar('PATH_INFO');
  1245.         if ($pathinfo == $scriptname{
  1246.             $pathinfo '';
  1247.         }
  1248.         if (!empty($scriptname)) {
  1249.             $request $scriptname $pathinfo;
  1250.             $querystring pnServerGetVar('QUERY_STRING');
  1251.             if (!empty($querystring)) $request .= '?'.$querystring;
  1252.         else {
  1253.             $request '/';
  1254.         }
  1255.     }
  1256.  
  1257.     // add optional parameters
  1258.     if (count($args0{
  1259.         if (strpos($request,'?'=== false$request .= '?';
  1260.         else $request .= '&';
  1261.  
  1262.         foreach ($args as $k=>$v{
  1263.             if (is_array($v)) {
  1264.                 foreach($v as $l=>$w{
  1265.                 // TODO: replace in-line here too ?
  1266.                     if (!empty($w)) $request .= $k "[$l]=$w&";
  1267.                 }
  1268.             else {
  1269.                 // if this parameter is already in the query string...
  1270.                 if (preg_match("/(&|\?)($k=[^&]*)/",$request,$matches)) {
  1271.                     $find $matches[2];
  1272.                     // ... replace it in-line if it's not empty
  1273.                     if (!empty($v)) {
  1274.                         $request preg_replace("/(&|\?)$find/","$1$k=$v",$request);
  1275.  
  1276.                     // ... or remove it otherwise
  1277.                     elseif ($matches[1== '?'{
  1278.                         $request preg_replace("/\?$find(&|)/",'?',$request);
  1279.                     else {
  1280.                         $request preg_replace("/&$find/",'',$request);
  1281.                     }
  1282.                 elseif (!empty($v)) {
  1283.                     $request .= "$k=$v&";
  1284.                 }
  1285.             }
  1286.         }
  1287.  
  1288.         $request substr($request0-1);
  1289.     }
  1290.  
  1291.     return $request;
  1292. }
  1293.  
  1294.  
  1295. /**
  1296. * Gets the current protocol
  1297. *
  1298. * Returns the HTTP protocol used by current connection, it could be 'http' or 'https'.
  1299. *
  1300. @author Marco Canini <marco@xaraya.com>
  1301. @access public
  1302. @return string current HTTP protocol
  1303. */
  1304. {
  1305.     if (preg_match('/^http:/'pnGetCurrentURI())) {
  1306.         return 'http';
  1307.     }
  1308.     $HTTPS pnServerGetVar('HTTPS');
  1309.     // IIS seems to set HTTPS = off for some reason
  1310.     return (!empty($HTTPS&& $HTTPS != 'off''https' 'http';
  1311. }
  1312.  
  1313. /**
  1314. * Get current URL
  1315. *
  1316. @access public
  1317. @param args array additional parameters to be added to/replaced in the URL (e.g. theme, ...)
  1318. @return string current URL
  1319. @todo cfr. BaseURI() for other possible ways, or try PHP_SELF
  1320. */
  1321. function pnGetCurrentURL()
  1322. {
  1323.     $server   pnGetHost();
  1324.     $protocol pnServerGetProtocol();
  1325.     $baseurl  "$protocol://$server";
  1326.     $request  pnGetCurrentURI();
  1327.  
  1328.     if (empty($request)) {
  1329.         // adapted patch from Chris van de Steeg for IIS
  1330.         // TODO: please test this :)
  1331.         $scriptname pnServerGetVar('SCRIPT_NAME');
  1332.         $pathinfo   pnServerGetVar('PATH_INFO');
  1333.         if ($pathinfo == $scriptname{
  1334.             $pathinfo '';
  1335.         }
  1336.         if (!empty($scriptname)) {
  1337.             $request $scriptname $pathinfo;
  1338.             $querystring pnServerGetVar('QUERY_STRING');
  1339.             if (!empty($querystring)) $request .= '?'.$querystring;
  1340.         else {
  1341.             $request '/';
  1342.         }
  1343.     }
  1344.  
  1345.     return $baseurl $request;
  1346. }
  1347.  
  1348. /**
  1349.  * Decode the path string into a set of variable/value pairs
  1350.  * available via pnVarCleanFromInput or the object libary
  1351.  *
  1352.  * This API works in conjunction with the new short urls
  1353.  * system to extract a path based variable set into the Get, Post
  1354.  * and request superglobals.
  1355.  * A sample path is /modname/function/var1:value1
  1356.  *
  1357.  * @author Martin Andersen
  1358.  * @author Mark West
  1359.  * @access private
  1360. */
  1361. function pnQueryStringDecode()
  1362. {
  1363.     // get our base parameters to work out if we need to decode the url
  1364.     $module FormUtil::getPassedValue('module'null'GETPOST');
  1365.     $func   FormUtil::getPassedValue('func'null'GETPOST');
  1366.     $type   FormUtil::getPassedValue('type'null'GETPOST');
  1367.  
  1368.     // check if we need to decode the url
  1369.     if (!defined('_PNINSTALLVER'&& pnConfigGetVar('shorturls'&& pnConfigGetVar('shorturlstype'== &&
  1370.         (empty($module&& empty($type&& empty($func))) {
  1371.  
  1372.         // define our site entry points
  1373.         $customentrypoint pnConfigGetVar('entrypoint');
  1374.         $root empty($customentrypoint'index.php' $customentrypoint;
  1375.         $tobestripped array("/$root"'/admin.php''/user.php''/modules.php''/backend.php''/print.php'
  1376.                               '/error.php''/banners.php'pnGetBaseURI());
  1377.  
  1378.         // get base path to work out our current url
  1379.         $parsedURL parse_url(pnGetCurrentURI());
  1380.  
  1381.         // strip any unwanted content from the provided URL
  1382.         $path str_replace($tobestripped''$parsedURL['path']);
  1383.  
  1384.         // split the path into a set of argument strings
  1385.         $args explode('/'rtrim($path'/'));
  1386.  
  1387.         // ensure that each argument is properly decoded
  1388.         foreach ($args as $k => $v{
  1389.             $args[$kurldecode($v);
  1390.         }
  1391.  
  1392.         // the module is the first argument string
  1393.         if (isset($args[1]&& !empty($args[1])) {
  1394.             // first try the first argument as a module
  1395.             $modinfo pnModGetInfo(pnModGetIDFromName($args[1]));
  1396.             // if that fails it's a theme
  1397.             if (!$modinfo{
  1398.                 $themeinfo ThemeUtil::getInfo(ThemeUtil::getIDFromName($args[1]));
  1399.                 if ($themeinfo{
  1400.                     pnQueryStringSetVar('theme'$themeinfo['name']);
  1401.                     // now shift the vars and continue as before
  1402.                     array_shift($args);
  1403.                     $modinfo pnModGetInfo(pnModGetIDFromName($args[1]));
  1404.                 else {
  1405.                     // even though it's not really a module let the standard module code handle the problem
  1406.                     $modinfo['name'$args[1];
  1407.                     $modinfo['type'0;
  1408.                 }
  1409.             }
  1410.             if ($modinfo['type'== 1{
  1411.                 pnQueryStringSetVar('name'$modinfo['name']);
  1412.                 isset($args[2]pnQueryStringSetVar('req'$args[2]null;
  1413.                 $modname FormUtil::getPassedValue('name'null'GETPOST');
  1414.             else {
  1415.                 pnQueryStringSetVar('module'$modinfo['name']);
  1416.                 // the function name is the second argument string
  1417.                 isset($args[2]pnQueryStringSetVar('func'$args[2]null;
  1418.                 $modname FormUtil::getPassedValue('module'null'GETPOST');
  1419.             }
  1420.         }
  1421.  
  1422.         // check if there is a custom url handler for this module
  1423.         // if not decode the url using the default handler
  1424.         if (isset($modinfo&& $modinfo['type'!= && !pnModAPIFunc($modname'user''decodeurl'array('vars' => $args))) {
  1425.             // any remaining arguments are specific to the module
  1426.             $argscount count($args);
  1427.             for ($i 3$i $argscount$i $i 2{
  1428.                 if (isset($args[$i])) pnQueryStringSetVar($args[$i]urldecode($args[$i+1]));
  1429.             }
  1430.         }
  1431.     }
  1432. }
  1433.  
  1434. /**
  1435.  * add a variable/value pair into the query string
  1436.  * (really the _GET superglobal
  1437.  * This API also adds the variable to the _REQUEST superglobal for consistentcy
  1438.  *
  1439.  * @author Mark West
  1440.  * @return bool true if successful, false otherwise
  1441. */
  1442. function pnQueryStringSetVar($name$value)
  1443. {
  1444.     if (!isset($name)) {
  1445.         return;
  1446.     }
  1447.  
  1448.     // add the variable into the get superglobal
  1449.     $_REQUEST[$name$_GET[$name$value;
  1450.     return true;
  1451. }
  1452.  
  1453. /**
  1454.  *
  1455.  */
  1456. function pnErrorHandler($errno$errstr$errfile$errline$errcontext)
  1457. {
  1458.     // check for an @ suppression or E_STRICT errors (we're not php 5 only yet!)
  1459.     if ($errno == 2048 || error_reporting(== {
  1460.         return;
  1461.     }
  1462.  
  1463.     static $errorlog$errorlogtype$errordisplay$pntemp;
  1464.     if (!isset($errorlogtype)) {
  1465.         $errorlog     pnConfigGetVar('errorlog');
  1466.         $errorlogtype pnConfigGetVar('errorlogtype');
  1467.         $errordisplay pnConfigGetVar('errordisplay');
  1468.         $pntemp       DataUtil::formatForOS(pnConfigGetVar('temp'));
  1469.     }
  1470.  
  1471.     // What do we want to log?
  1472.     // 1 - Log real errors only.  2 - Log everything
  1473.     if ($errorlog == || ($errorlog == &&
  1474.         ($errno != E_WARNING || $errno != E_NOTICE || $errno != E_USER_WARNING || $errno != E_USER_NOTICE))) {
  1475.         // log the error
  1476.         $msg "Zikula Error: $errstr";
  1477.         if (SecurityUtil::checkPermission'::''::'ACCESS_ADMIN)) {
  1478.             $request pnGetCurrentURI();
  1479.             $msg .= " in $errfile on line $errline for page $request";
  1480.         }
  1481.         switch ($errorlogtype{
  1482.             // log to the system log (default php handling....)
  1483.             case 0:
  1484.                 error_log($msg);
  1485.                 break;
  1486.             // e-mail the error
  1487.             case 1:
  1488.                 pnModLangLoad('Errors''user');
  1489.                 $toaddress pnConfigGetVar('errormailto');
  1490.                 $body pnModFunc('Errors''user''system',
  1491.                         array('type' => $errno'message' => $errstr'file' => $errfile'line' => $errline));
  1492.                 pnModAPIFunc('Mailer''user''sendmessage',
  1493.                        array('toaddress' => $toaddress'toname' => $toaddress,
  1494.                              'subject' => _ERRORS_SYSTEMERROR'body' => $body));
  1495.                 break;
  1496.             // log a module specific log (based on top level module)
  1497.             case 2:
  1498.                 $modname DataUtil::formatForOS(pnModGetName());
  1499.                 error_log($msg."\r\n"3$pntemp '/error_logs/' $modname '.log');
  1500.                 break;
  1501.             // log to global error log
  1502.             case 3:
  1503.                 error_log($msg."\r\n"3$pntemp '/error_logs/error.log');
  1504.                 break;
  1505.         }
  1506.     }
  1507.  
  1508.     // should we display the error to the user
  1509.     if ($errordisplay == 0{
  1510.         return;
  1511.     }
  1512.  
  1513.     // check if we want to flag up warnings and notices
  1514.     if ($errordisplay == &&
  1515.         ($errno == E_WARNING || $errno == E_NOTICE || $errno == E_USER_WARNING || $errno == E_USER_NOTICE)) {
  1516.         return;
  1517.     }
  1518.  
  1519.     // clear the output buffer
  1520.     while (ob_get_level()) {
  1521.         ob_end_clean();
  1522.     }
  1523.  
  1524.     // display the new output and halt the script
  1525.     Loader::includeOnce('header.php');
  1526.     echo pnModFunc('Errors''user''system',
  1527.                    array('type' => $errno'message' => $errstr'file' => $errfile'line' => $errline));
  1528.     Loader::includeOnce('footer.php');
  1529.     pnShutDown();
  1530. }
  1531.  
  1532.  
  1533. /**
  1534.  * Gracefully shut down the framework (traps all exit and die calls)
  1535.  *
  1536.  * @author drak
  1537.  * @param $exit_param params to pass to the exit function
  1538.  * @return none - function halts execution
  1539.  *
  1540.  */
  1541. function pnShutDown($exit_param='')
  1542. {
  1543.     // we must deliberately cause the session to close down because if we
  1544.     // rely on PHP to do so after an exit is called, the framework gets shutdown
  1545.     // by PHP and no longer functions correctly.
  1546.  
  1547.     // do the exit
  1548.     if (empty($exit_param)) {
  1549.         exit;
  1550.     }else{
  1551.         exit($exit_param);
  1552.     }
  1553. }

Documentation generated on Fri, 18 Jul 2008 21:52:42 +0200 by phpDocumentor 1.4.1