[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/horde/Horde/ -> Registry.php (source)

   1  <?php
   2  
   3  /** Do not start a session. */
   4  define('HORDE_SESSION_NONE', 1);
   5  
   6  /** Do not write changes to session. */
   7  define('HORDE_SESSION_READONLY', 2);
   8  
   9  /**
  10   * The Registry:: class provides a set of methods for communication
  11   * between Horde applications and keeping track of application
  12   * configuration information.
  13   *
  14   * $Horde: framework/Horde/Horde/Registry.php,v 1.249 2005/02/14 18:00:59 jan Exp $
  15   *
  16   * Copyright 1999-2005 Chuck Hagenbuch <chuck@horde.org>
  17   * Copyright 1999-2005 Jon Parise <jon@horde.org>
  18   * Copyright 1999-2005 Anil Madhavapeddy <anil@recoil.org>
  19   *
  20   * See the enclosed file COPYING for license information (LGPL). If you
  21   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  22   *
  23   * @author  Chuck Hagenbuch <chuck@horde.org>
  24   * @author  Jon Parise <jon@horde.org>
  25   * @author  Anil Madhavapeddy <anil@recoil.org>
  26   * @since   Horde 1.3
  27   * @package Horde_Framework
  28   */
  29  class Registry {
  30  
  31      /**
  32       * Hash storing all of the known services and callbacks.
  33       *
  34       * @var array $_apiCache
  35       */
  36      var $_apiCache = array();
  37  
  38      /**
  39       * Hash storing all known data types.
  40       *
  41       * @var array $_typeCache
  42       */
  43      var $_typeCache = array();
  44  
  45      /**
  46       * Hash storing all of the registered interfaces that applications
  47       * provide.
  48       *
  49       * @var array $_interfaces
  50       */
  51      var $_interfaces = array();
  52  
  53      /**
  54       * Hash storing information on each registry-aware application.
  55       *
  56       * @var array $applications
  57       */
  58      var $applications = array();
  59  
  60      /**
  61       * Stack of in-use applications.
  62       *
  63       * @var array $_appStack
  64       */
  65      var $_appStack = array();
  66  
  67      /**
  68       * Quick pointer to the current application.
  69       *
  70       * @var $_currentApp
  71       */
  72      var $_currentApp = null;
  73  
  74      /**
  75       * Cache of $prefs objects
  76       *
  77       * @var array $_prefsCache
  78       */
  79      var $_prefsCache = array();
  80  
  81      /**
  82       * Cache of application configurations.
  83       *
  84       * @var array $_confCache
  85       */
  86      var $_confCache = array();
  87  
  88      /**
  89       * Returns a reference to the global Registry object, only
  90       * creating it if it doesn't already exist.
  91       *
  92       * This method must be invoked as: $registry = &Registry::singleton()
  93       *
  94       * @param optional integer $session_flags  Any session flags.
  95       *
  96       * @return object Registry  The Horde Registry instance.
  97       */
  98      function &singleton($session_flags = 0)
  99      {
 100          static $registry;
 101  
 102          if (!isset($registry)) {
 103              $registry = new Registry($session_flags);
 104          }
 105  
 106          return $registry;
 107      }
 108  
 109      /**
 110       * Create a new registry instance. Should never be called except
 111       * by &Registry::singleton().
 112       *
 113       * @param optional integer $session_flags  Any session flags.
 114       *
 115       * @access private
 116       */
 117      function Registry($session_flags = 0)
 118      {
 119          /* Import and global Horde's configuration values. */
 120          $this->importConfig('horde');
 121  
 122          /* Start a session. */
 123          if ($session_flags & HORDE_SESSION_NONE) {
 124              /* Never start a session if the session flags include
 125                 HORDE_SESSION_NONE. */
 126              $_SESSION = array();
 127          } else {
 128              Horde::setupSessionHandler();
 129              @session_start();
 130              if ($session_flags & HORDE_SESSION_READONLY) {
 131                  /* Close the session immediately so no changes can be
 132                     made but values are still available. */
 133                  @session_write_close();
 134              }
 135          }
 136  
 137          /* Read the registry configuration file. */
 138          require_once HORDE_BASE . '/config/registry.php';
 139  
 140          /* Initialize the localization routines and variables. */
 141  #        NLS::setLang();
 142  #        NLS::setTextdomain('horde', HORDE_BASE . '/locale', NLS::getCharset());
 143  #        String::setDefaultCharset(NLS::getCharset());
 144  
 145          /* Stop system if Horde is inactive. */
 146          if ($this->applications['horde']['status'] == 'inactive') {
 147              Horde::fatal(_("This system is currently deactivated."), __FILE__, __LINE__);
 148          }
 149  
 150          /* Scan for all APIs provided by each app, and set other
 151           * common defaults like templates and graphics. */
 152          $appList = array_keys($this->applications);
 153          foreach ($appList as $appName) {
 154              $app = &$this->applications[$appName];
 155              if (($app['status'] == 'heading') ||
 156                  ($app['status'] == 'inactive') ||
 157                  ($app['status'] == 'admin' && !Auth::isAdmin())) {
 158                  continue;
 159              }
 160              if (isset($app['provides'])) {
 161                  if (is_array($app['provides'])) {
 162                      foreach ($app['provides'] as $interface) {
 163                          $this->_interfaces[$interface] = $appName;
 164                      }
 165                  } else {
 166                      $this->_interfaces[$app['provides']] = $appName;
 167                  }
 168              }
 169              if (!isset($app['templates']) && isset($app['fileroot'])) {
 170                  $app['templates'] = $app['fileroot'] . '/templates';
 171              }
 172              if (!isset($app['jsuri']) && isset($app['webroot'])) {
 173                  $app['jsuri'] = $app['webroot'] . '/js';
 174              }
 175              if (!isset($app['jsfs']) && isset($app['fileroot'])) {
 176                  $app['jsfs'] = $app['fileroot'] . '/js';
 177              }
 178              if (!isset($app['themesuri']) && isset($app['webroot'])) {
 179                  $app['themesuri'] = $app['webroot'] . '/themes';
 180              }
 181              if (!isset($app['themesfs']) && isset($app['fileroot'])) {
 182                  $app['themesfs'] = $app['fileroot'] . '/themes';
 183              }
 184          }
 185  
 186  #        /* Create the global Perms object. */
 187  #        $GLOBALS['perms'] = &Perms::singleton();
 188  
 189  #        /* Attach javascript notification listener. */
 190  #        $notification = &Notification::singleton();
 191  #        $notification->attach('javascript');
 192  
 193          /* Register access key logger for translators. */
 194          if (@$GLOBALS['conf']['log_accesskeys']) {
 195              register_shutdown_function(create_function('', 'Horde::getAccessKey(null, null, true);'));
 196          }
 197      }
 198  
 199      /**
 200       * Return a list of the installed and registered applications.
 201       *
 202       * @since Horde 2.2
 203       *
 204       * @access public
 205       *
 206       * @param array   $filter      (optional) An array of the statuses that
 207       *                             should be returned. Defaults to non-hidden.
 208       * @param boolean $assoc       (optional) Associative array with app names
 209       *                             as keys.
 210       * @param integer $permission  (optional) The permission level to check
 211       *                             for in the list. Defaults to PERMS_SHOW.
 212       *
 213       * @return array  List of apps registered with Horde. If no
 214       *                applications are defined returns an empty array.
 215       */
 216      function listApps($filter = null, $assoc = false, $permission = PERMS_SHOW)
 217      {
 218          $apps = array();
 219          if (is_null($filter)) {
 220              $filter = array('notoolbar', 'active');
 221          }
 222  
 223          foreach ($this->applications as $app => $params) {
 224              if (in_array($params['status'], $filter) &&
 225                  (defined('AUTH_HANDLER') || $this->hasPermission($app, $permission))) {
 226                  $assoc ? $apps[$app] = $app : $apps[] = $app;
 227              }
 228          }
 229  
 230          return $apps;
 231      }
 232  
 233      /**
 234       * Returns all available registry APIs.
 235       *
 236       * @access public
 237       *
 238       * @return array  The API list.
 239       */
 240      function listAPIs()
 241      {
 242          $apis = array();
 243  
 244          foreach (array_keys($this->_interfaces) as $interface) {
 245              @list($api, ) = explode('/', $interface);
 246              $apis[] = $api;
 247          }
 248  
 249          return array_unique($apis);
 250      }
 251  
 252      /**
 253       * Returns all of the available registry methods, or alternately
 254       * only those for a specified API.
 255       *
 256       * @access public
 257       *
 258       * @param optional string $api  Defines the API for which the methods
 259       *                              shall be returned.
 260       *
 261       * @return array  The method list.
 262       */
 263      function listMethods($api = null)
 264      {
 265          $methods = array();
 266  
 267          $this->_fillAPICache();
 268  
 269          foreach (array_keys($this->applications) as $app) {
 270              if (isset($this->applications[$app]['provides'])) {
 271                  $provides = $this->applications[$app]['provides'];
 272                  if (!is_array($provides)) {
 273                      $provides = array($provides);
 274                  }
 275              } else {
 276                  $provides = array();
 277              }
 278  
 279              foreach ($provides as $method) {
 280                  if (strpos($method, '/') !== false) {
 281                      if (is_null($api) ||
 282                          (substr($method, 0, strlen($api)) == $api)) {
 283                          $methods[] = $method;
 284                      }
 285                  } elseif (is_null($api) || ($method == $api)) {
 286                      if (isset($this->_apiCache[$app])) {
 287                          foreach (array_keys($this->_apiCache[$app]) as $service) {
 288                              $methods[] = $method . '/' . $service;
 289                          }
 290                      }
 291                  }
 292              }
 293          }
 294  
 295          return array_unique($methods);
 296      }
 297  
 298      /**
 299       * Returns all of the available registry data types.
 300       *
 301       * @access public
 302       *
 303       * @return array  The data type list.
 304       */
 305      function listTypes()
 306      {
 307          $this->_fillAPICache();
 308          return $this->_typeCache;
 309      }
 310  
 311      /**
 312       * Returns a method's signature.
 313       *
 314       * @access public
 315       *
 316       * @param string $method  The full name of the method to check for.
 317       *
 318       * @return array  A two dimensional array. The first element contains an
 319       *                array with the parameter names, the second one the return
 320       *                type.
 321       */
 322      function getSignature($method)
 323      {
 324          if (!($app = $this->hasMethod($method))) {
 325              return;
 326          }
 327  
 328          $this->_fillAPICache();
 329  
 330          @list(, $function) = explode('/', $method);
 331          if (isset($this->_apiCache[$app][$function]['type']) &&
 332              isset($this->_apiCache[$app][$function]['args'])) {
 333              return array($this->_apiCache[$app][$function]['args'], $this->_apiCache[$app][$function]['type']);
 334          }
 335      }
 336  
 337      /**
 338       * Determine if an interface is implemented by an active
 339       * application.
 340       *
 341       * @access public
 342       *
 343       * @param string $interface  The interface to check for.
 344       *
 345       * @return mixed  The application implementing $interface if we have it,
 346       *                false if the interface is not implemented.
 347       */
 348      function hasInterface($interface)
 349      {
 350          return !empty($this->_interfaces[$interface]) ?
 351              $this->_interfaces[$interface] :
 352              false;
 353      }
 354  
 355      /**
 356       * Determine if a method has been registered with the registry.
 357       *
 358       * @access public
 359       *
 360       * @param string  $method      The full name of the method to check for.
 361       * @param string  $app         (optional) Only check this application.
 362       *
 363       * @return mixed  The application implementing $method if we have it,
 364       *                false if the method doesn't exist.
 365       */
 366      function hasMethod($method, $app = null)
 367      {
 368          if (is_null($app)) {
 369              @list($interface, $call) = explode('/', $method);
 370              if (!empty($this->_interfaces[$method])) {
 371                  $app = $this->_interfaces[$method];
 372              } elseif (!empty($this->_interfaces[$interface])) {
 373                  $app = $this->_interfaces[$interface];
 374              } else {
 375                  return false;
 376              }
 377          } else {
 378              $call = $method;
 379          }
 380  
 381          $this->_fillAPICache();
 382  
 383          return !empty($this->_apiCache[$app][$call]) ? $app : false;
 384      }
 385  
 386      /**
 387       * Return the hook corresponding to the default package that
 388       * provides the functionality requested by the $method
 389       * parameter. $method is a string consisting of
 390       * "packagetype/methodname".
 391       *
 392       * @access public
 393       *
 394       * @param string $method        The method to call.
 395       * @param optional array $args  Arguments to the method.
 396       *
 397       * @return  TODO
 398       *          Returns PEAR_Error on error.
 399       */
 400      function call($method, $args = array())
 401      {
 402          @list($interface, $call) = explode('/', $method);
 403  
 404          if (!empty($this->_interfaces[$method])) {
 405              $app = $this->_interfaces[$method];
 406          } elseif (!empty($this->_interfaces[$interface])) {
 407              $app = $this->_interfaces[$interface];
 408          } else {
 409              return PEAR::raiseError('The method "' . $method . '" is not defined in the Horde Registry.');
 410          }
 411  
 412          return $this->callByPackage($app, $call, $args);
 413      }
 414  
 415      /**
 416       * Output the hook corresponding to the specific package named.
 417       *
 418       * @access public
 419       *
 420       * @param string $app           The application being called.
 421       * @param string $call          The method to call.
 422       * @param optional array $args  Arguments to the method.
 423       *
 424       * @return  TODO
 425       *          Returns PEAR_Error on error.
 426       */
 427      function callByPackage($app, $call, $args = array())
 428      {
 429          /* Note: calling hasMethod() makes sure that we've cached
 430           * $app's services and included the API file, so we don't try
 431           * to do it again explicitly in this method. */
 432          if (!$this->hasMethod($call, $app)) {
 433              return PEAR::raiseError(sprintf('The method "%s" is not defined in the API for %s.', $call, $app));
 434          }
 435  
 436          /* Make sure that the function actually exists. */
 437          $function = '_' . $app . '_' . $call;
 438          if (!function_exists($function)) {
 439              return PEAR::raiseError('The function implementing ' . $call . ' (' . $function . ') is not defined in ' . $app . '\'s API.');
 440          }
 441  
 442          $checkPerms = isset($this->_apiCache[$app][$call]['checkperms']) ?
 443                        $this->_apiCache[$app][$call]['checkperms'] : true;
 444  
 445          /* Switch application contexts now, if necessary, before
 446           * including any files which might do it for us. Return an
 447           * error immediately if pushApp() fails. */
 448          $pushed = $this->pushApp($app, $checkPerms);
 449          if (is_a($pushed, 'PEAR_Error')) {
 450              return $pushed;
 451          }
 452  
 453          $res = call_user_func_array($function, $args);
 454  
 455          /* If we changed application context in the course of this
 456           * call, undo that change now. */
 457          if ($pushed === true) {
 458              $this->popApp();
 459          }
 460  
 461          return $res;
 462      }
 463  
 464      /**
 465       * Return the hook corresponding to the default package that
 466       * provides the functionality requested by the $method
 467       * parameter. $method is a string consisting of
 468       * "packagetype/methodname".
 469       *
 470       * @access public
 471       *
 472       * @param string $method         The method to link to.
 473       * @param optional array $args   Arguments to the method.
 474       * @param optional mixed $extra  Extra, non-standard arguments to the
 475       *                               method.
 476       *
 477       * @return  TODO
 478       *          Returns PEAR_Error on error.
 479       */
 480      function link($method, $args = array(), $extra = '')
 481      {
 482          @list($interface, $call) = explode('/', $method);
 483  
 484          if (!empty($this->_interfaces[$method])) {
 485              $app = $this->_interfaces[$method];
 486          } elseif (!empty($this->_interfaces[$interface])) {
 487              $app = $this->_interfaces[$interface];
 488          } else {
 489              return PEAR::raiseError('The method "' . $method . '" is not defined in the Horde Registry.');
 490          }
 491  
 492          return $this->linkByPackage($app, $call, $args, $extra);
 493      }
 494  
 495      /**
 496       * Output the hook corresponding to the specific package named.
 497       *
 498       * @access public
 499       *
 500       * @param string $app            The application being called.
 501       * @param string $call           The method to link to.
 502       * @param optional array $args   Arguments to the method.
 503       * @param optional mixed $extra  Extra, non-standard arguments to the
 504       *                               method.
 505       *
 506       * @return  TODO
 507       *          Returns PEAR_Error on error.
 508       */
 509      function linkByPackage($app, $call, $args = array(), $extra = '')
 510      {
 511          /* Note: calling hasMethod makes sure that we've cached $app's
 512           * services and included the API file, so we don't try to do
 513           * it it again explicitly in this method. */
 514          if (!$this->hasMethod($call, $app)) {
 515              return PEAR::raiseError('The method "' . $call . '" is not defined in ' . $app . '\'s API.');
 516          }
 517  
 518          /* Make sure the link is defined. */
 519          if (empty($this->_apiCache[$app][$call]['link'])) {
 520              return PEAR::raiseError('The link ' . $call . ' is not defined in ' . $app . '\'s API.');
 521          }
 522  
 523          /* Initial link value. */
 524          $link = $this->_apiCache[$app][$call]['link'];
 525  
 526          /* Fill in html-encoded arguments. */
 527          foreach ($args as $key => $val) {
 528              $link = str_replace('%' . $key . '%', htmlentities($val), $link);
 529          }
 530          if (isset($this->applications[$app]['webroot'])) {
 531              $link = str_replace('%application%', $this->get('webroot', $app), $link);
 532          }
 533  
 534          /* Replace htmlencoded arguments that haven't been specified with
 535             an empty string (this is where the default would be substituted
 536             in a stricter registry implementation). */
 537          $link = preg_replace('|%.+%|U', '', $link);
 538  
 539          /* Fill in urlencoded arguments. */
 540          foreach ($args as $key => $val) {
 541              $link = str_replace('|' . String::lower($key) . '|', urlencode($val), $link);
 542          }
 543  
 544          /* Append any extra, non-standard arguments. */
 545          if (is_array($extra)) {
 546              $extra_args = '';
 547              foreach ($extra as $key => $val) {
 548                  $extra_args .- '&' . urlencode($key) . '=' . urlencode($val);
 549              }
 550          } else {
 551              $extra_args = $extra;
 552          }
 553          $link = str_replace('|extra|', $extra_args, $link);
 554  
 555          /* Replace html-encoded arguments that haven't been specified with
 556             an empty string (this is where the default would be substituted
 557             in a stricter registry implementation). */
 558          $link = preg_replace('|\|.+\||U', '', $link);
 559  
 560          return $link;
 561      }
 562  
 563      /**
 564       * Replace any %application% strings with the filesystem path to
 565       * the application.
 566       *
 567       * @access public
 568       *
 569       * @param string $path          The application string.
 570       * @param optional string $app  The application being called.
 571       *
 572       * @return  TODO
 573       *          Returns PEAR_Error on error.
 574       */
 575      function applicationFilePath($path, $app = null)
 576      {
 577          if (is_null($app)) {
 578              $app = $this->_currentApp;
 579          }
 580  
 581          if (!isset($this->applications[$app])) {
 582              return PEAR::raiseError(sprintf(_("'%s' is not configured in the Horde Registry."), $app));
 583          }
 584  
 585          return str_replace('%application%', $this->applications[$app]['fileroot'], $path);
 586      }
 587  
 588      /**
 589       * Replace any %application% strings with the web path to the
 590       * application.
 591       *
 592       * @access public
 593       *
 594       * @param string $path          The application string.
 595       * @param optional string $app  The application being called.
 596       *
 597       * @return  TODO
 598       *          Returns PEAR_Error on error.
 599       */
 600      function applicationWebPath($path, $app = null)
 601      {
 602          if (!isset($app)) {
 603              $app = $this->_currentApp;
 604          }
 605  
 606          return str_replace('%application%', $this->applications[$app]['webroot'], $path);
 607      }
 608  
 609      /**
 610       * Set the current application, adding it to the top of the Horde
 611       * application stack. If this is the first application to be
 612       * pushed, retrieve session information as well.
 613       *
 614       * pushApp() also reads the application's configuration file and
 615       * sets up its global $conf hash.
 616       *
 617       * @access public
 618       *
 619       * @param string  $app         The name of the application to push.
 620       * @param boolean $checkPerms  (optional) Make sure that the current user
 621       *                             has permissions to the application being
 622       *                             loaded. Defaults to true. Should ONLY
 623       *                             be disabled by system scripts (cron jobs,
 624       *                             etc.) and scripts that handle login.
 625       *
 626       * @return boolean  Whether or not the _appStack was modified.
 627       *                  Return PEAR_Error on error.
 628       */
 629      function pushApp($app, $checkPerms = true)
 630      {
 631          if ($app == $this->_currentApp) {
 632              return false;
 633          }
 634  
 635          /* Bail out if application is not present or inactive. */
 636          if (!isset($this->applications[$app]) ||
 637              $this->applications[$app]['status'] == 'inactive' ||
 638              ($this->applications[$app]['status'] == 'admin' && !Auth::isAdmin())) {
 639              Horde::fatal($app . ' is not activated', __FILE__, __LINE__);
 640          }
 641  
 642          /* If permissions checking is requested, return an error if
 643           * the current user does not have read perms to the
 644           * application being loaded. We allow access:
 645           *
 646           *  - To all admins.
 647           *  - To all authenticated users if no permission is set on $app.
 648           *  - To anyone who is allowed by an explicit ACL on $app. */
 649          if ($checkPerms && !$this->hasPermission($app)) {
 650              Horde::logMessage(sprintf('User %s does not have READ permission for %s', Auth::getAuth(), $app), __FILE__, __LINE__, PEAR_LOG_DEBUG);
 651              return PEAR::raiseError(sprintf(_("User %s is not authorised for %s."), Auth::getAuth(), $this->applications[$app]['name']), 'permission_denied');
 652          }
 653  
 654          /* Import this application's configuration values. */
 655          $success = $this->importConfig($app);
 656          if (is_a($success, 'PEAR_Error')) {
 657              return $success;
 658          }
 659  
 660          /* Load preferences after the configuration has been loaded to
 661           * make sure the prefs file has all the information it needs. */
 662          $this->loadPrefs($app);
 663  
 664          /* Reset the language in case there is a different one
 665           * selected in the preferences. */
 666          $language = '';
 667          if (isset($this->_prefsCache[$app]) &&
 668              isset($this->_prefsCache[$app]->_prefs['language'])) {
 669              $language = $this->_prefsCache[$app]->getValue('language');
 670          }
 671          NLS::setLang($language);
 672          NLS::setTextdomain($app, $this->applications[$app]['fileroot'] . '/locale', NLS::getCharset());
 673          String::setDefaultCharset(NLS::getCharset());
 674  
 675          /* Once we know everything succeeded and is in a consistent
 676           * state again, push the new application onto the stack. */
 677          array_push($this->_appStack, $app);
 678          $this->_currentApp = $app;
 679  
 680          return true;
 681      }
 682  
 683      /**
 684       * Remove the current app from the application stack, setting the
 685       * current app to whichever app was current before this one took
 686       * over.
 687       *
 688       * @access public
 689       *
 690       * @return string  The name of the application that was popped.
 691       */
 692      function popApp()
 693      {
 694          /* Pop the current application off of the stack. */
 695          $previous = array_pop($this->_appStack);
 696  
 697          /* Import the new active application's configuration values
 698           * and set the gettext domain and the preferred language. */
 699          $this->_currentApp = count($this->_appStack) ? end($this->_appStack) : null;
 700          if ($this->_currentApp) {
 701              $this->importConfig($this->_currentApp);
 702              $this->loadPrefs($this->_currentApp);
 703              #$language = $GLOBALS['prefs']->getValue('language');
 704              #if (isset($language)) {
 705              #    NLS::setLang($language);
 706              #}
 707              NLS::setTextdomain($this->_currentApp, $this->applications[$this->_currentApp]['fileroot'] . '/locale', NLS::getCharset());
 708              String::setDefaultCharset(NLS::getCharset());
 709          }
 710  
 711          return $previous;
 712      }
 713  
 714      /**
 715       * Return the current application - the app at the top of the
 716       * application stack.
 717       *
 718       * @access public
 719       *
 720       * @return string  The current application.
 721       */
 722      function getApp()
 723      {
 724          return $this->_currentApp;
 725      }
 726  
 727      /**
 728       * Check permissions on an application.
 729       *
 730       * @access public
 731       *
 732       * @return boolean  Whether or not access is allowed.
 733       */
 734      function hasPermission($app, $permission = PERMS_READ)
 735      {
 736          return true;
 737          #return Auth::isAdmin() || ($GLOBALS['perms']->exists($app) ?
 738          #                           $GLOBALS['perms']->hasPermission($app, Auth::getAuth(), $permission) :
 739          #                           (bool)Auth::getAuth());
 740      }
 741  
 742      /**
 743       * Reads the configuration values for the given application and
 744       * imports them into the global $conf variable.
 745       *
 746       * @access public
 747       *
 748       * @param string $app  The name of the application.
 749       *
 750       * @return boolean  True on success, PEAR_Error on error.
 751       */
 752      function importConfig($app)
 753      {
 754          /* Don't make config files global $registry themselves. */
 755          global $registry;
 756  
 757          /* Cache config values so that we don't re-read files on every
 758           * popApp() call. */
 759          if (!isset($this->_confCache[$app])) {
 760              if (!isset($this->_confCache['horde'])) {
 761                  $conf = array();
 762                  ob_start();
 763                  $success = include HORDE_BASE . '/config/conf.php';
 764                  $errors = ob_get_contents();
 765                  ob_end_clean();
 766                  if (!empty($errors)) {
 767                      return PEAR::raiseError(sprintf('Failed to import Horde configuration: %s', strip_tags($errors)));
 768                  }
 769                  if (!$success) {
 770                      return PEAR::raiseError('Failed to import Horde configuration.');
 771                  }
 772  
 773                  /* Initial Horde-wide settings. */
 774  
 775                  /* Set the error reporting level in accordance with
 776                   * the config settings. */
 777                  error_reporting($conf['debug_level']);
 778  
 779                  /* Set the maximum execution time in accordance with
 780                   * the config settings. */
 781                  @set_time_limit($conf['max_exec_time']);
 782  
 783                  /* Set the umask according to config settings. */
 784                  if (isset($conf['umask'])) {
 785                      umask($conf['umask']);
 786                  }
 787              } else {
 788                  $conf = $this->_confCache['horde'];
 789              }
 790  
 791              if ($app !== 'horde') {
 792                  $success = @include $this->applications[$app]['fileroot'] . '/config/conf.php';
 793                  if (!$success) {
 794                      return PEAR::raiseError('Failed to import application configuration for ' . $app);
 795                  }
 796              }
 797  
 798              $this->_confCache[$app] = &$conf;
 799          }
 800  
 801          $GLOBALS['conf'] = &$this->_confCache[$app];
 802          return true;
 803      }
 804  
 805      /**
 806       * Loads the preferences for the current user for the current
 807       * application and imports them into the global $prefs variable.
 808       *
 809       * @access public
 810       *
 811       * @param string $app  The name of the application.
 812       */
 813      function loadPrefs($app = null)
 814      {
 815          return array();
 816          
 817          static $prefs_default = false;
 818  
 819          require_once 'Horde/Prefs.php';
 820  
 821          if ($app === null) {
 822              $app = $this->_currentApp;
 823          }
 824  
 825          /* If there is no logged in user, return an empty Prefs::
 826           * object with just default preferences. */
 827  #        if (!Auth::getAuth()) {
 828  #            $prefs = &Prefs::factory('none', $app, '', '', null, false);
 829  #            $prefs->retrieve();
 830  #            $this->_prefsCache[$app] = &$prefs;
 831  #            $GLOBALS['prefs'] = &$this->_prefsCache[$app];
 832  #            $prefs_default = true;
 833  #            return;
 834  #        }
 835  
 836          /* Cache prefs objects so that we don't re-load them on every
 837           * popApp() call. */
 838  #        if (!isset($this->_prefsCache[$app]) ||
 839  #            !empty($prefs_default)) {
 840  #            $prefs = &Prefs::factory($GLOBALS['conf']['prefs']['driver'], $app,
 841  #                                     Auth::getAuth(), Auth::getCredential('password'));
 842  #            $prefs->retrieve();
 843  #            $this->_prefsCache[$app] = &$prefs;
 844  #       }
 845  
 846          $GLOBALS['prefs'] = &$this->_prefsCache[$app];
 847      }
 848  
 849      /**
 850       * Unload preferences from an application or (if no application is
 851       * specified) from ALL applications. Useful when a user has logged
 852       * out but you need to continue on the same page, etc.
 853       *
 854       * After unloading, if there is an application on the app stack to
 855       * load preferences from, then we reload a fresh set.
 856       *
 857       * @access public
 858       *
 859       * @param string $app  (optional) The application to unload prefrences for.
 860       *                     If null, ALL preferences are reset.
 861       */
 862      function unloadPrefs($app = null)
 863      {
 864          if ($app === null) {
 865              $this->_prefsCache = array();
 866          } elseif (isset($this->_prefsCache[$app])) {
 867              unset($this->_prefsCache[$app]);
 868          } else {
 869              return;
 870          }
 871  
 872          if ($this->_currentApp) {
 873              $this->loadPrefs();
 874          }
 875      }
 876  
 877      /**
 878       * Return the requested configuration parameter for the specified
 879       * application. If no application is specified, the value of
 880       * $this->_currentApp (the current application) is used. However,
 881       * if the parameter is not present for that application, the
 882       * Horde-wide value is used instead. If that is not present, we
 883       * return null.
 884       *
 885       * @access public
 886       *
 887       * @param string $parameter     The configuration value to retrieve.
 888       * @param optional string $app  The application to get the value for.
 889       *
 890       * @return string  The requested parameter, or null if it is not set.
 891       */
 892      function get($parameter, $app = null)
 893      {
 894          if (is_null($app)) {
 895              $app = $this->_currentApp;
 896          }
 897  
 898          if (isset($this->applications[$app][$parameter])) {
 899              $pval = $this->applications[$app][$parameter];
 900          } else {
 901              if ($parameter == 'icon') {
 902                  $pval = $this->_getIcon($app);
 903              } else {
 904                  $pval = isset($this->applications['horde'][$parameter]) ? $this->applications['horde'][$parameter] : null;
 905              }
 906          }
 907  
 908          if ($parameter == 'name') {
 909              return _($pval);
 910          } else {
 911              return $pval;
 912          }
 913      }
 914  
 915      /**
 916       * Function to work out an application's graphics URI, taking into
 917       * account any themes directories that may be set up.
 918       *
 919       * @access public
 920       *
 921       * @param optional string $app  The application for which to get the
 922       *                              image directory. If blank will default
 923       *                              to current application.
 924       *
 925       * @return string  The image directory uri path.
 926       */
 927      function getImageDir($app = null)
 928      {
 929          if (empty($app)) {
 930              $app = $this->_currentApp;
 931          }
 932  
 933          static $img_dir = array();
 934          if (isset($img_dir[$app])) {
 935              return $img_dir[$app];
 936          }
 937  
 938          /* This is the default location for the graphics. */
 939          $img_dir[$app] = $this->get('themesuri', $app) . '/graphics';
 940  
 941          /* Figure out if this is going to be overridden by any theme
 942           * settings. */
 943          if (isset($GLOBALS['prefs']) && ($theme = $GLOBALS['prefs']->getValue('theme')) &&
 944              (@include $this->get('themesfs', 'horde') . '/' . $theme . '/info.php') &&
 945              isset($theme_icons) &&
 946              in_array($app, $theme_icons)) {
 947              $img_dir[$app] = $this->get('themesuri', $app) . '/' . $theme . '/graphics';
 948          }
 949  
 950          return $img_dir[$app];
 951      }
 952  
 953      /**
 954       * Returns the path to an application's icon, respecting whether the
 955       * current theme has its own icons.
 956       *
 957       * @access private
 958       *
 959       * @param string $app  The application for which to get the icon.
 960       */
 961      function _getIcon($app)
 962      {
 963          return $this->getImageDir($app) . '/' . $app . '.png';
 964      }
 965  
 966      /**
 967       * Query the initial page for an application - the webroot, if
 968       * there is no initial_page set, and the initial_page, if it is
 969       * set.
 970       *
 971       * @access public
 972       *
 973       * @param optional string $app  The name of the application.
 974       *
 975       * @return string  URL pointing to the inital page of the application.
 976       *                 Returns PEAR_Error on error.
 977       */
 978      function getInitialPage($app = null)
 979      {
 980          if (is_null($app)) {
 981              $app = $this->_currentApp;
 982          }
 983  
 984          if (!isset($this->applications[$app])) {
 985              return PEAR::raiseError(sprintf(_("'%s' is not configured in the Horde Registry."), $app));
 986          }
 987          return $this->applications[$app]['webroot'] . '/' . (isset($this->applications[$app]['initial_page']) ? $this->applications[$app]['initial_page'] : '');
 988      }
 989  
 990      /**
 991       * Fills the registry's API cache with the available services.
 992       *
 993       * @access private
 994       */
 995      function _fillAPICache()
 996      {
 997          if (!empty($this->_apiCache)) {
 998              return;
 999          }
1000  
1001          $status = array('active', 'notoolbar', 'hidden');
1002  #        if (Auth::isAdmin()) {
1003  #            $status[] = 'admin';
1004  #        }
1005          $apps = $this->listApps($status);
1006          foreach ($apps as $app) {
1007              $_services = $_types = null;
1008              $api = $this->get('fileroot', $app) . '/lib/api.php';
1009              if (is_readable($api)) {
1010                  include_once $api;
1011              }
1012              if (!isset($_services)) {
1013                  $this->_apiCache[$app] = array();
1014              } else {
1015                  $this->_apiCache[$app] = $_services;
1016              }
1017              if (isset($_types)) {
1018                  foreach ($_types as $type => $params) {
1019                      /* Prefix non-Horde types with the application
1020                       * name. */
1021                      $prefix = $app == 'horde' ? '' : "$app}_";
1022                      $this->_typeCache[$prefix . $type] = $params;
1023                  }
1024              }
1025          }
1026      }
1027  
1028  }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7