Seagull PHP Cross Reference Content Management Systems

Source: /lib/SGL/Task/Init.php - 786 lines - 26965 bytes - Summary - Text - Print

Description: Basic init tasks: sets up paths, contstants, include_path, etc.

   1  <?php
   2  /* Reminder: always indent with 4 spaces (no tabs). */
   3  // +---------------------------------------------------------------------------+
   4  // | Copyright (c) 2010, Demian Turner                                         |
   5  // | All rights reserved.                                                      |
   6  // |                                                                           |
   7  // | Redistribution and use in source and binary forms, with or without        |
   8  // | modification, are permitted provided that the following conditions        |
   9  // | are met:                                                                  |
  10  // |                                                                           |
  11  // | o Redistributions of source code must retain the above copyright          |
  12  // |   notice, this list of conditions and the following disclaimer.           |
  13  // | o Redistributions in binary form must reproduce the above copyright       |
  14  // |   notice, this list of conditions and the following disclaimer in the     |
  15  // |   documentation and/or other materials provided with the distribution.    |
  16  // | o The names of the authors may not be used to endorse or promote          |
  17  // |   products derived from this software without specific prior written      |
  18  // |   permission.                                                             |
  19  // |                                                                           |
  20  // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       |
  21  // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         |
  22  // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR     |
  23  // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
  24  // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,     |
  25  // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT          |
  26  // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,     |
  27  // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY     |
  28  // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT       |
  29  // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE     |
  30  // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.      |
  31  // |                                                                           |
  32  // +---------------------------------------------------------------------------+
  33  // | Seagull 1.0                                                               |
  34  // +---------------------------------------------------------------------------+
  35  // | Init.php                                                                  |
  36  // +---------------------------------------------------------------------------+
  37  // | Author:   Demian Turner <demian@phpkitchen.com>                           |
  38  // +---------------------------------------------------------------------------+
  39  // $Id: Init.php,v 1.85 2005/06/22 00:40:44 demian Exp $
  40  
  41  /**
  42   * Basic init tasks: sets up paths, contstants, include_path, etc.
  43   *
  44   * @author  Demian Turner <demian@phpkitchen.com>
  45   */
  46  require_once dirname(__FILE__) . '/../Task.php';
  47  
  48  // if SGL_FrontController::init() called without index.php
  49  if (!isset($GLOBALS['varDir'])) {
  50      $GLOBALS['varDir']  = realpath(dirname(__FILE__) . '/../../../var');
  51      $GLOBALS['rootDir'] = realpath(dirname(__FILE__) . '/../../../');
  52  }
  53  
  54  /**
  55   * @package Task
  56   */
  57  class SGL_Task_SetupPaths extends SGL_Task
  58  {
  59      /**
  60       * Sets up the minimum paths required for framework execution.
  61       *
  62       * - SGL_SERVER_NAME must always be known in order to rewrite config file
  63       * - SGL_PATH is the filesystem root path
  64       * - pear include path is setup
  65       * - PEAR.php included for errors, etc
  66       *
  67       * @param array $data
  68       */
  69      public function run($conf = array())
  70      {
  71          define('SGL_SERVER_NAME', $this->hostnameToFilename());
  72          if (defined('SGL_PEAR_INSTALLED')) {
  73              define('SGL_PATH', '@PHP-DIR@/Seagull');
  74              define('SGL_LIB_PEAR_DIR', '@PHP-DIR@');
  75          } else {
  76              $path = $GLOBALS['varDir']  . '/INSTALL_COMPLETE.php';
  77              if (is_file($path)) {
  78                  $configFile = $GLOBALS['varDir']  . '/'
  79                      . SGL_Task_SetupPaths::hostnameToFilename() . '.conf.php';
  80                  require_once $configFile;
  81                  if (!empty($conf['path']['installRoot'])) {
  82                      define('SGL_PATH', $conf['path']['installRoot']);
  83                  }
  84              } else {
  85                  define('SGL_PATH', $GLOBALS['rootDir']);
  86              }
  87              define('SGL_LIB_PEAR_DIR', SGL_PATH . '/lib/pear');
  88              //  put sgl lib dir in include path
  89              $sglLibDir =  SGL_PATH . '/lib';
  90          }
  91  
  92          if (!defined('PATH_SEPARATOR')) { // defined in >= PHP 4.3.4
  93              define('PATH_SEPARATOR', (substr(PHP_OS, 0, 3) == 'WIN') ? ';' : ':');
  94          }
  95          $sglPath = '.' . PATH_SEPARATOR . SGL_LIB_PEAR_DIR . PATH_SEPARATOR . $sglLibDir .
  96              PATH_SEPARATOR . get_include_path();
  97          $allowed = @ini_set('include_path', $sglPath);
  98          if (!$allowed) {
  99              //  depends on PHP version being >= 4.3.0
 100              if (function_exists('set_include_path')) {
 101                  set_include_path($sglPath);
 102              } else {
 103                  die('You need at least PHP 4.3.0 if you want to run Seagull
 104                  with safe mode enabled.');
 105              }
 106          }
 107      }
 108  
 109      /**
 110       * Determines the name of the INI file, based on the host name.
 111       *
 112       * If PHP is being run interactively (CLI) where no $_SERVER vars
 113       * are available, a default 'localhost' is supplied.
 114       *
 115       * @return  string  the name of the host
 116       */
 117      function hostnameToFilename()
 118      {
 119          //  start with a default
 120          $hostName = 'localhost';
 121          if (!SGL::runningFromCLI()) {
 122  
 123              // Determine the host name
 124              if (!empty($_SERVER['SERVER_NAME'])) {
 125                  $hostName = $_SERVER['SERVER_NAME'];
 126  
 127              } elseif (!empty($_SERVER['HTTP_HOST'])) {
 128                  //  do some spoof checking here, like
 129                  //  if (gethostbyname($_SERVER['HTTP_HOST']) != $_SERVER['SERVER_ADDR'])
 130                  $hostName = $_SERVER['HTTP_HOST'];
 131              } else {
 132                  //  if neither of these variables are set
 133                  //  we're going to have a hard time setting up
 134                  die('Could not determine your server name');
 135              }
 136              // Determine if the port number needs to be added onto the end
 137              if (!empty($_SERVER['SERVER_PORT'])
 138                      && $_SERVER['SERVER_PORT'] != 80
 139                      && $_SERVER['SERVER_PORT'] != 443) {
 140                  $hostName .= '_' . $_SERVER['SERVER_PORT'];
 141              }
 142          }
 143          return $hostName;
 144      }
 145  }
 146  
 147  /**
 148   * @package Task
 149   */
 150  class SGL_Task_SetupConstantsStart extends SGL_Task
 151  {
 152      function run($conf = array())
 153      {
 154          // framework file structure
 155          if (defined('SGL_PEAR_INSTALLED')) {
 156              define('SGL_VAR_DIR',              '@DATA-DIR@/Seagull/var');
 157              define('SGL_ETC_DIR',              '@DATA-DIR@/Seagull/etc');
 158              define('SGL_APP_ROOT',             '@PHP-DIR@/Seagull');
 159          } else {
 160              define('SGL_VAR_DIR',               SGL_PATH . '/var');
 161              define('SGL_ETC_DIR',               SGL_PATH . '/etc');
 162              define('SGL_APP_ROOT',              SGL_PATH);
 163          }
 164          define('SGL_LOG_DIR',                   SGL_VAR_DIR . '/log');
 165          define('SGL_CACHE_DIR',                 SGL_VAR_DIR . '/cache');
 166          define('SGL_LIB_DIR',                   SGL_APP_ROOT . '/lib');
 167          define('SGL_ENT_DIR',                   SGL_CACHE_DIR . '/entities');
 168          define('SGL_DAT_DIR',                   SGL_APP_ROOT . '/lib/data');
 169          define('SGL_CORE_DIR',                  SGL_APP_ROOT . '/lib/SGL');
 170  
 171          //  error codes to use with SGL::raiseError()
 172          //  start at -100 in order not to conflict with PEAR::DB error codes
 173  
 174          /**
 175           * Wrong args to function.
 176           */
 177          define('SGL_ERROR_INVALIDARGS',         -101);
 178          /**
 179           * Something wrong with the config.
 180           */
 181          define('SGL_ERROR_INVALIDCONFIG',       -102);
 182          /**
 183           * No data available.
 184           */
 185          define('SGL_ERROR_NODATA',              -103);
 186          /**
 187           * No class exists.
 188           */
 189          define('SGL_ERROR_NOCLASS',             -104);
 190          /**
 191           * No method exists.
 192           */
 193          define('SGL_ERROR_NOMETHOD',            -105);
 194          /**
 195           * No rows were affected by query.
 196           */
 197          define('SGL_ERROR_NOAFFECTEDROWS',      -106);
 198          /**
 199           * Limit queries on unsuppored databases.
 200           */
 201          define('SGL_ERROR_NOTSUPPORTED'  ,      -107);
 202          /**
 203           * Invalid call.
 204           */
 205          define('SGL_ERROR_INVALIDCALL',         -108);
 206          /**
 207           * Authentication failure.
 208           */
 209          define('SGL_ERROR_INVALIDAUTH',         -109);
 210          /**
 211           * Failed to send email.
 212           */
 213          define('SGL_ERROR_EMAILFAILURE',        -110);
 214          /**
 215           * Failed to connect to DB.
 216           */
 217          define('SGL_ERROR_DBFAILURE',           -111);
 218          /**
 219           * A DB transaction failed.
 220           */
 221          define('SGL_ERROR_DBTRANSACTIONFAILURE',-112);
 222          /**
 223           * User not allow to access site.
 224           */
 225          define('SGL_ERROR_BANNEDUSER',          -113);
 226          /**
 227           * File not found.
 228           */
 229          define('SGL_ERROR_NOFILE',              -114);
 230          /**
 231           * Perms were invalid.
 232           */
 233          define('SGL_ERROR_INVALIDFILEPERMS',    -115);
 234          /**
 235           * Session was invalid.
 236           */
 237          define('SGL_ERROR_INVALIDSESSION',      -116);
 238          /**
 239           * Posted data was invalid.
 240           */
 241          define('SGL_ERROR_INVALIDPOST',         -117);
 242          /**
 243           * Translation invalid.
 244           */
 245          define('SGL_ERROR_INVALIDTRANSLATION',  -118);
 246          /**
 247           * Could not write to the file.
 248           */
 249          define('SGL_ERROR_FILEUNWRITABLE',      -119);
 250          /**
 251           * Method perms were invalid.
 252           */
 253          define('SGL_ERROR_INVALIDMETHODPERMS',  -120);
 254          /**
 255           * Authorisation is invalid.
 256           */
 257          define('SGL_ERROR_INVALIDAUTHORISATION',  -121);
 258          /**
 259           * Request was invalid.
 260           */
 261          define('SGL_ERROR_INVALIDREQUEST',      -122);
 262          /**
 263           * Type invalid.
 264           */
 265          define('SGL_ERROR_INVALIDTYPE',         -123);
 266          /**
 267           * Excessive recursion occured.
 268           */
 269          define('SGL_ERROR_RECURSION',           -124);
 270          /**
 271           * Resource could not be found.
 272           */
 273          define('SGL_ERROR_RESOURCENOTFOUND',    -404);
 274  
 275          //  message types to use with SGL:raiseMsg($msg, $translation, $msgType)
 276          define('SGL_MESSAGE_ERROR',             0);  // by default
 277          define('SGL_MESSAGE_INFO',              1);
 278          define('SGL_MESSAGE_WARNING',           2);
 279  
 280          //  automate sorting
 281          define('SGL_SORTBY_GRP',                1);
 282          define('SGL_SORTBY_USER',               2);
 283          define('SGL_SORTBY_ORG',                3);
 284  
 285          //  Seagull user roles
 286          define('SGL_ANY_ROLE',                  -2);
 287          define('SGL_UNASSIGNED',                -1);
 288          define('SGL_GUEST',                     0);
 289          define('SGL_ADMIN',                     1);
 290          define('SGL_MEMBER',                    2);
 291  
 292          define('SGL_STATUS_DELETED',            0);
 293          define('SGL_STATUS_FOR_APPROVAL',       1);
 294          define('SGL_STATUS_BEING_EDITED',       2);
 295          define('SGL_STATUS_APPROVED',           3);
 296          define('SGL_STATUS_PUBLISHED',          4);
 297          define('SGL_STATUS_ARCHIVED',           5);
 298  
 299          //  comment status types
 300          define('SGL_COMMENT_FOR_APPROVAL',      0);
 301          define('SGL_COMMENT_APPROVED',          1);
 302          define('SGL_COMMENT_AKISMET_PASSED',    2);
 303          define('SGL_COMMENT_AKISMET_FAILED',    3);
 304  
 305          //  define return types, k/v pairs, arrays, strings, etc
 306          define('SGL_RET_NAME_VALUE',            1);
 307          define('SGL_RET_ID_VALUE',              2);
 308          define('SGL_RET_ARRAY',                 3);
 309          define('SGL_RET_STRING',                4);
 310  
 311          //  define string element
 312          define('SGL_CHAR',                      1);
 313          define('SGL_WORD',                      2);
 314  
 315          //  define language id types
 316          define('SGL_LANG_ID_SGL',               1);
 317          define('SGL_LANG_ID_TRANS2',            2);
 318  
 319          //  various
 320          define('SGL_ANY_SECTION',               0);
 321          define('SGL_NEXT_ID',                   0);
 322          define('SGL_NOTICES_DISABLED',          0);
 323          define('SGL_NOTICES_ENABLED',           1);
 324  
 325          //  with logging, you can optionally show the file + line no. where
 326          //  SGL::logMessage was called from
 327          define('SGL_DEBUG_SHOW_LINE_NUMBERS',   false);
 328  
 329          //  to overcome overload problem
 330          define('DB_DATAOBJECT_NO_OVERLOAD',     true);
 331      }
 332  }
 333  
 334  /**
 335   * @package Task
 336   */
 337  class SGL_Task_SetupConstantsFinish extends SGL_Task
 338  {
 339      function run($conf = array())
 340      {
 341          //  include Log.php if logging enabled
 342          if (isset($conf['log']['enabled']) && $conf['log']['enabled']) {
 343              require_once 'Log.php';
 344  
 345          } else {
 346              //  define log levels to avoid notices, since Log.php not included
 347              define('PEAR_LOG_EMERG',    0);     /** System is unusable */
 348              define('PEAR_LOG_ALERT',    1);     /** Immediately action */
 349              define('PEAR_LOG_CRIT',     2);     /** Critical conditions */
 350              define('PEAR_LOG_ERR',      3);     /** Error conditions */
 351              define('PEAR_LOG_WARNING',  4);     /** Warning conditions */
 352              define('PEAR_LOG_NOTICE',   5);     /** Normal but significant */
 353              define('PEAR_LOG_INFO',     6);     /** Informational */
 354              define('PEAR_LOG_DEBUG',    7);     /** Debug-level messages */
 355          }
 356          // On install, $conf is empty let's load it
 357          if (empty($conf) && file_exists(SGL_ETC_DIR . '/customInstallDefaults.ini')) {
 358              $c = SGL_Config::singleton();
 359              $conf1 = $c->load(SGL_ETC_DIR . '/customInstallDefaults.ini');
 360              if (isset($conf1['path']['moduleDirOverride'])) {
 361                  $conf['path']['moduleDirOverride'] = $conf1['path']['moduleDirOverride'];
 362              }
 363          // On re-install or INSTALL_COMPLETE
 364          } elseif (count($conf)) {
 365              //  set constant to represent profiling mode so it can be used in Controller
 366              define('SGL_PROFILING_ENABLED', ($conf['debug']['profiling']) ? true : false);
 367              define('SGL_SEAGULL_VERSION', $conf['tuples']['version']);
 368  
 369              //  which degree of error severity before emailing admin
 370              define('SGL_EMAIL_ADMIN_THRESHOLD',
 371                  SGL_String::pseudoConstantToInt($conf['debug']['emailAdminThreshold']));
 372              define('SGL_BASE_URL', $conf['site']['baseUrl']);
 373  
 374              //  add additional search paths
 375              if (!empty($conf['path']['additionalIncludePath'])) {
 376                  $ok = ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR
 377                      . $conf['path']['additionalIncludePath']);
 378              }
 379          }
 380  
 381          if (isset($conf['path']['webRoot'])) {
 382              define('SGL_WEB_ROOT', $conf['path']['webRoot']);
 383          } elseif (defined('SGL_PEAR_INSTALLED')) {
 384              define('SGL_WEB_ROOT', '@WEB-DIR@/Seagull/www');
 385          } else {
 386              define('SGL_WEB_ROOT', SGL_PATH . '/www');
 387          }
 388  
 389          define('SGL_THEME_DIR', SGL_WEB_ROOT . '/themes');
 390          if (!empty($conf['path']['moduleDirOverride'])) {
 391              define('SGL_MOD_DIR', SGL_APP_ROOT . '/' . $conf['path']['moduleDirOverride']);
 392          } else {
 393              define('SGL_MOD_DIR', SGL_APP_ROOT . '/modules');
 394          }
 395          if (!empty($conf['path']['uploadDirOverride'])) {
 396              define('SGL_UPLOAD_DIR', SGL_PATH . $conf['path']['uploadDirOverride']);
 397          } else {
 398              define('SGL_UPLOAD_DIR', SGL_VAR_DIR . '/uploads');
 399          }
 400          if (!empty($conf['path']['tmpDirOverride'])) {
 401              define('SGL_TMP_DIR', $conf['path']['tmpDirOverride']);
 402          } else {
 403              define('SGL_TMP_DIR', SGL_VAR_DIR . '/tmp');
 404          }
 405      }
 406  }
 407  
 408  /**
 409   * @package Task
 410   */
 411  class SGL_Task_InitialiseDbDataObject extends SGL_Task
 412  {
 413      function run($conf = array())
 414      {
 415          $options = &PEAR::getStaticProperty('DB_DataObject', 'options');
 416          $options = array(
 417              'database'              => SGL_DB::getDsn(SGL_DSN_STRING),
 418              'schema_location'       => SGL_ENT_DIR,
 419              'class_location'        => SGL_ENT_DIR,
 420              'require_prefix'        => SGL_ENT_DIR . '/',
 421              'class_prefix'          => 'DataObjects_',
 422              'debug'                 => SGL_Config::get('debug.dataObject'),
 423              'production'            => 0,
 424              'ignore_sequence_keys'  => 'ALL',
 425              'generator_strip_schema'=> 1,
 426              'quote_identifiers'     => 1,
 427          );
 428      }
 429  }
 430  
 431  /**
 432   * @package Task
 433   */
 434  class SGL_Task_EnsurePlaceholderDbPrefixIsNull extends SGL_Task
 435  {
 436      function run($conf = array())
 437      {
 438          // for 0.6.x versions
 439          if (!empty($conf['db']['prefix'])
 440                  && $conf['db']['prefix'] == 'not implemented yet') {
 441              $config = SGL_Config::singleton();
 442              $config->set('db', array('prefix' => ''));
 443              $config->save();
 444          }
 445      }
 446  }
 447  
 448  /**
 449   * @package Task
 450   */
 451  class SGL_Task_SetGlobals extends SGL_Task
 452  {
 453      function run($conf = array())
 454      {
 455          $GLOBALS['_SGL']['BANNED_IPS'] =        array();
 456          $GLOBALS['_SGL']['ERRORS'] =            array();
 457          $GLOBALS['_SGL']['QUERY_COUNT'] =       0;
 458          $GLOBALS['_SGL']['ERROR_OVERRIDE'] =    false;
 459          $GLOBALS['_SGL']['CHARSET'] =           '';
 460      }
 461  }
 462  
 463  /**
 464   * @package Task
 465   */
 466  class SGL_Task_SetupPearErrorCallback extends SGL_Task
 467  {
 468      function run($conf = array())
 469      {
 470          //  set PEAR error handler
 471          #$old_error_handler = set_error_handler("myErrorHandler");
 472          PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array($this, 'pearErrorHandler'));
 473          if (!SGL_Config::get('debug.showBacktrace')) {
 474             $options = &PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
 475             $options = true;
 476          }
 477      }
 478  
 479      /**
 480       * A callback method that sets the default PEAR error behaviour.
 481       *
 482       * @access   public
 483       * @static
 484       * @param    object $oError the PEAR error object
 485       * @return   void
 486       */
 487      function pearErrorHandler($oError)
 488      {
 489          //  log message
 490          $message = $oError->getMessage();
 491          $debugInfo = $oError->getDebugInfo();
 492          SGL::logMessage('PEAR' . " :: $message : $debugInfo", PEAR_LOG_ERR);
 493  
 494          //  send error info to screen
 495          SGL_Error::push($oError);
 496          if (SGL_Config::get('debug.showBacktrace')) {
 497              echo '<pre>'; print_r($oError->getBacktrace()); print '</pre>';
 498          }
 499      }
 500  }
 501  
 502  /**
 503   * @package Task
 504   */
 505  class SGL_Task_SetupCustomErrorHandler extends SGL_Task
 506  {
 507      function run($conf = array())
 508      {
 509          if (version_compare(phpversion(), "5.3.0", '>=')) {
 510              return;
 511          }
 512          //  start custom PHP error handler
 513          if (isset( $conf['debug']['customErrorHandler'])
 514                  && $conf['debug']['customErrorHandler'] == true
 515                  && !defined('SGL_TEST_MODE')) {
 516              require_once SGL_CORE_DIR . '/ErrorHandler.php';
 517              $eh = new SGL_ErrorHandler();
 518              $eh->startHandler();
 519  
 520              //  clean start for logs
 521              error_log(' ');
 522              error_log('##########   New request: '.trim($_SERVER['PHP_SELF']).'   ##########');
 523          } else {
 524              // otherwise setup standard PHP error handling
 525              if (!empty($conf['debug']['production'])) {
 526                  ini_set('display_errors', false);
 527              }
 528              if (!empty($conf['log']['enabled']) && $conf['log']['enabled']) {
 529                  ini_set('log_errors', true);
 530              }
 531          }
 532      }
 533  }
 534  
 535  /**
 536   * Routine to discover the base url of the installation.
 537   *
 538   * Only gets invoked if user deletes URL in config, or if we're setting up.
 539   *
 540   * @package Task
 541   */
 542  class SGL_Task_SetBaseUrl extends SGL_Task
 543  {
 544      function run($conf = array())
 545      {
 546          if (!(isset($conf['site']['baseUrl']))) {
 547  
 548              //  defines SGL_BASE_URL constant
 549              require_once dirname(__FILE__)  . '/Install.php';
 550              SGL_Task_SetBaseUrlMinimal::run();
 551          }
 552      }
 553  }
 554  
 555  //          $userInfo = posix_getpwuid(fileowner($configFile));
 556  //          $fileOwnerName = $userInfo['name'];
 557  //          $allowedFileOwners = array('nobody', 'apache');
 558  //
 559  //          if (!in_array($fileOwnerName, $allowedFileOwners)) {
 560  //                die("<br />Your config file in the seagull/var directory has the wrong " .
 561  //                  "owner (currently set as: $fileOwnerName). " .
 562  //                    "Please set the correct file owner to this directory and it's contents, eg:<br/>" .
 563  //                    "<code>'chmod -R 777 seagull/var'</code>");
 564  //          }
 565  
 566  /**
 567   * @package Task
 568   */
 569  class SGL_Task_ModifyIniSettings extends SGL_Task
 570  {
 571      function run($conf = array())
 572      {
 573          // set php.ini directives
 574          @ini_set('session.auto_start',          0); //  sessions will fail fail if enabled
 575          @ini_set('allow_url_fopen',             0); //  this can be quite dangerous if enabled
 576          if (count($conf)) {
 577              @ini_set('error_log', SGL_PATH . '/' . $conf['log']['name']);
 578              if (!empty($conf['log']['ignoreRepeated'])) {
 579                  ini_set('ignore_repeated_errors', true);
 580                  ini_set('ignore_repeated_source', true);
 581              }
 582          }
 583      }
 584  }
 585  
 586  /**
 587   * @package Task
 588   */
 589  class SGL_Task_RegisterTrustedIPs extends SGL_Task
 590  {
 591      function run($conf = array())
 592      {
 593          //  only IPs defined here can access debug sessions and delete config files
 594          $GLOBALS['_SGL']['TRUSTED_IPS'] = array(
 595              '127.0.0.1',
 596          );
 597      }
 598  }
 599  
 600  /**
 601   * @package Task
 602   */
 603  class SGL_Task_LoadCustomConfig extends SGL_Task
 604  {
 605      function run($conf = array())
 606      {
 607          if (!empty($conf['path']['pathToCustomConfigFile'])) {
 608              if (is_file($conf['path']['pathToCustomConfigFile'])) {
 609                  require_once realpath($conf['path']['pathToCustomConfigFile']);
 610              }
 611          }
 612      }
 613  }
 614  
 615  /**
 616   * @package Task
 617   */
 618  class SGL_Task_InitialiseModules extends SGL_Task
 619  {
 620      function run($conf = array())
 621      {
 622          $c = SGL_Config::singleton();
 623          $conf = $c->getAll();
 624  
 625          //  skip if we're in installer
 626          if (defined('SGL_INSTALLED')) {
 627              $locator = SGL_ServiceLocator::singleton();
 628              $dbh = $locator->get('DB');
 629              if (!$dbh) {
 630                  $dbh =  SGL_DB::singleton();
 631                  $locator->register('DB', $dbh);
 632              }
 633              //  this task can be called when installing a new module
 634              if (!empty($conf['aModuleList'])) {
 635                  $oMod = new stdClass();
 636                  $oMod->name = $conf['aModuleList'][0];
 637                  $aRet[] = $oMod;
 638              } else {
 639                  $query = "
 640                      SELECT  name
 641                      FROM    {$conf['table']['module']}
 642                      ";
 643                  $aRet = $dbh->getAll($query);
 644              }
 645              if (is_array($aRet) && count($aRet)) {
 646                  foreach ($aRet as $oModule) {
 647                      $moduleInitFile = SGL_MOD_DIR . '/' . $oModule->name . '/init.php';
 648                      if (is_file($moduleInitFile)) {
 649                          require_once $moduleInitFile;
 650                      }
 651                  }
 652              }
 653          }
 654      }
 655  }
 656  
 657  /**
 658   * @package Task
 659   */
 660  class SGL_Task_EnsureFC extends SGL_Task
 661  {
 662      function run($conf = array())
 663      {
 664          //  load BC functions depending on PHP version detected
 665          if (version_compare(phpversion(), "5.3.0", '>=')) {
 666              date_default_timezone_set('UTC');
 667              error_reporting(E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR);
 668          }
 669      }
 670  }
 671  
 672      // +---------------------------------------+
 673      // | Abstract classes                      |
 674      // +---------------------------------------+
 675  
 676  /**
 677   * Abstract renderer strategy
 678   *
 679   * @abstract
 680   * @package SGL
 681   */
 682  class SGL_OutputRendererStrategy
 683  {
 684      /**
 685       * Prepare renderer options.
 686       *
 687       */
 688      function initEngine() {}
 689  
 690      /**
 691       * Abstract render method.
 692       *
 693       * @param SGL_View $view
 694       */
 695      function render($view) {}
 696  }
 697  
 698  /**
 699   * Container for output data and renderer strategy.
 700   *
 701   * @abstract
 702   * @package SGL
 703   */
 704  class SGL_View
 705  {
 706      /**
 707       * Output object.
 708       *
 709       * @var SGL_Output
 710       */
 711      var $data;
 712  
 713      /**
 714       * Reference to renderer strategy.
 715       *
 716       * @var SGL_OutputRendererStrategy
 717       */
 718      var $rendererStrategy;
 719  
 720      /**
 721       * Constructor.
 722       *
 723       * @param SGL_Output $data
 724       * @param SGL_OutputRendererStrategy $rendererStrategy
 725       * @return SGL_View
 726       */
 727      function SGL_View(&$data, $rendererStrategy)
 728      {
 729          $this->data = $data;
 730          $this->rendererStrategy = $rendererStrategy;
 731      }
 732  
 733      /**
 734       * Post processing tasks specific to view type.
 735       *
 736       * @abstract
 737       * @return boolean
 738       */
 739      function postProcess() {}
 740  
 741  
 742      /**
 743       * Delegates rendering strategy based on view.
 744       *
 745       * @return string   Rendered output data
 746       */
 747      function render()
 748      {
 749          return $this->rendererStrategy->render($this);
 750      }
 751  }
 752  
 753  /**
 754   * Wrapper for simple HTML views.
 755   *
 756   * @package SGL
 757   */
 758  class SGL_HtmlSimpleView extends SGL_View
 759  {
 760      /**
 761       * HTML renderer decorator
 762       *
 763       * @param SGL_Output $data
 764       * @return string   Rendered output data
 765       */
 766      function SGL_HtmlSimpleView(&$data, $templateEngine = null)
 767      {
 768          //  prepare renderer class
 769          if (!$templateEngine) {
 770              $templateEngine = SGL_Config::get('site.templateEngine');
 771          }
 772          $templateEngine = ucfirst($templateEngine);
 773          $rendererClass  = 'SGL_HtmlRenderer_' . $templateEngine . 'Strategy';
 774          $rendererFile   = $templateEngine.'Strategy.php';
 775  
 776          if (is_file(SGL_LIB_DIR . '/SGL/HtmlRenderer/' . $rendererFile)) {
 777              require_once SGL_LIB_DIR . '/SGL/HtmlRenderer/' . $rendererFile;
 778          } else {
 779              PEAR::raiseError('Could not find renderer', SGL_ERROR_NOFILE,
 780                  PEAR_ERROR_DIE);
 781          }
 782          parent::SGL_View($data, new $rendererClass);
 783      }
 784  }
 785  
 786  ?>

title

Description

title

Description

title

Description

title

title

Body