Caravel CMS PHP Cross Reference Content Management Systems

Source: /core/App.php - 814 lines - 26116 bytes - Summary - Text - Print

   1  <?php
   2  /***************************************************************************
   3   *                                                                          
   4   * App.php - Mennonite.net pluggable template site application 
   5   *  base class and includes
   6   *                                                                          
   7   ***************************************************************************
   8   *                                                                          
   9   * Provides base class which all mennonite.net template site applications
  10   *  must extend.  Also includes class files for all template site apps.                                              
  11   *                                                                          
  12   ***************************************************************************
  13   * $Id: App.php,v 1.26 2007/08/27 17:40:08 reuvenmh Exp $                                                                         
  14   ***************************************************************************/
  15  
  16  require_once (T_CODE_BASE . 'LDAP/mnLDAPAccess.php');
  17  require_once(T_WIDGET_BASE . 'Widget.php');
  18  require_once(T_WIDGET_BASE . 'FormWidget/FormWidget.php');
  19  
  20  /**
  21  * base template site application class
  22  *
  23  * Don't instantiate an App object - it's meant to be extended by 
  24  * each application class.
  25  *
  26  * @author   Carl J Meyer <carljm@goshen.edu>
  27  */
  28  class App extends mnLDAPAccess
  29      {
  30      /*
  31      * hash array of all application parameters
  32      *
  33      * basically just settingsVars, siteVars and httpVars merged
  34      * httpVars overwrite settingsVars, which overwrite siteVars
  35      *
  36      * @var  array
  37      * @access   private
  38      */
  39      var $params;
  40      
  41      /**
  42      * hash array of params from REQUEST (GET and POST)
  43      *
  44      * @var  array
  45      * @access   private
  46      */
  47      var $httpVars = array();
  48      
  49      /**
  50      * hash array of params saved in content block with saveSettings()
  51      *
  52      * @var  array
  53      * @access   private
  54      */
  55      var $settingsVars = array();
  56      
  57      /**
  58      * hash array of params that are site wide and stored in ldap (e.g., postUpload)
  59      *
  60      * @var  array
  61      * @access   private
  62      */
  63      var $siteVars = array();
  64  
  65      /**
  66      * hash array of params that will be appended to any linkToSelf
  67      *
  68      * @var array
  69      * @access   public
  70      **/
  71      var $linkVars = array();
  72      
  73      /**
  74      * current section object
  75      *
  76      * @var object
  77      * @access private
  78      */
  79      var $section;
  80      
  81      /**
  82      * auth object for this session
  83      *
  84      * @var  object
  85      * @access   private
  86      */
  87      var $auth;
  88      
  89      /**
  90      * section path array (so we can link to ourself)
  91      *
  92      * @var  array
  93      * @access   private
  94      */
  95      var $sectionPathArray;
  96      
  97      /**
  98      * base path to application HTML, dbrc files
  99      *
 100      * @var  string
 101      * @access   private
 102      */
 103      var $appPath;
 104      
 105      /**
 106      * name of content block which called this instantiation of the app
 107      *
 108      * @var  string
 109      * @access   private
 110      */
 111      var $blockID;
 112      
 113      /**
 114      * ldapDN of content block
 115      *
 116      * @var  string
 117      * @access   private
 118      */
 119      var $ldapDN;
 120      
 121      /**
 122      * whether this block is currently under edit
 123      *
 124      * @var  boolean
 125      * @access   private
 126      */
 127      var $edit;
 128  
 129      /**
 130      * whether we are publishing
 131      *
 132      * @var    boolean
 133      * @access    private
 134      */
 135      var $publish;
 136      
 137      /**
 138      * pixel width of column in which block is located
 139      *
 140      * @var  integer
 141      * @access   private
 142      */
 143      var $colWidth;
 144      
 145      /**
 146      * true if this block is allowed or configable, based on the current user's permissions
 147      *
 148      * @var    boolean
 149      * @access    private
 150      */
 151      var $allowed;
 152      
 153      /**
 154      * mnTemplateApp initializer -- all child classes should call this
 155      *
 156      * @param    mixed   mnLDAP object, ldap server URI, or null 
 157      * @param    string  name of content block calling this instance of the app
 158      * @param    object  ldapDN of calling content block
 159      * @param    object  request section object
 160      * @param    array   (optional) hash array of params from POST and GET
 161      * @param    array   (optional) hash array of contentblock-level saved params
 162      * @param    array   (optional) hash array of application parameters
 163      * @param    array   (optional) hash array of site-defined configuration params
 164      * @param    array   (optional) sectionPath array
 165      * @param    string  (optional) base directory of app files
 166      * @param    boolean (optional) in edit mode?
 167      * @param    integer (optional) pixel width of column
 168      * @access   public
 169      * @return   mixed   true on success, mnError on failure
 170      */
 171      function init($appID, $blockID, $ldapDN, $pageDN, &$section, $httpVars = array(), $settingsVars = array(), $siteVars = array(), $sectionPathArray = array(), $appBase = '', $edit = 0, $colWidth = 400)
 172          {
 173          $this->ldap =& cv_getLDAP();
 174  
 175          $this->appID = $appID;
 176          $this->blockID = $blockID;
 177          $this->pageDN = $pageDN;
 178          $this->ldapDN = $ldapDN;
 179          if (!$this->ldapDN)
 180              $this->ldapDN = DN::pageUrlToDn(T_SITE_ID . '/' . join('/', $sectionPathArray));
 181          $this->initPrivs();
 182          $this->appBase = $appBase;
 183          $this->edit = $edit;
 184          $this->section =& $section;
 185          $this->auth =& $section->auth;
 186          $this->userVars =& $_SESSION['userVars'];
 187          if(is_array($settingsVars))
 188              $this->settingsVars = $settingsVars;
 189          else
 190              {
 191              $res = $this->getSettingsVars();
 192              if(mnError::isError($res))
 193                  { return new mnError('App::init(): getSettingsVars failed: ' . $res->getMessage(), __FILE__, __LINE__); }
 194              $this->settingsVars = $res;    
 195              }
 196          $this->colWidth = T_SINGLE_BLOCK ? T_SECTION_WIDTH : $colWidth;
 197          $this->sectionPathArray = $sectionPathArray;
 198  
 199          $this->httpVars = $httpVars;
 200          $res = $this->getSiteVars();
 201          if(mnError::isError($res))
 202              { return new mnError('App::init(): getSiteVars failed: ' . $res->getMessage(), __FILE__, __LINE__); }
 203          $this->siteVars = $res;    
 204  
 205          $this->params = $httpVars + $this->settingsVars + $siteVars;
 206          
 207          // raise onInit event when app is initialized
 208          if ($this->allowed)
 209              $this->onInit();
 210  
 211          // raise onSave event if we have permission and a button named 'cv_submit' was pressed
 212          if ( isset($this->httpVars['cv_submit']) and $this->httpVars['cv_submit'] != "")
 213              $this->onSave($this->httpVars['cv_submit']);
 214  
 215          return true;
 216          }
 217  
 218      function getTime($t = null)
 219          {
 220          $time = explode(" ", isset($t) ? $t : microtime());
 221          $time = ((float)$time[0] + (float)$time[1]);
 222          return $time;
 223          }
 224      
 225      /**
 226      * get site-level settings from LDAP
 227      * pjh may 29 (carl forgot)
 228      * preconditions:
 229      *   $this->ldap, $this->ldapDN
 230      * postconditions:
 231      *   return val
 232      *
 233      * @access   private
 234      * @return   mixed   array of appParams from LDAP, or mnError on failure
 235      */
 236      function getSiteVars()
 237          {
 238          
 239          $params = array();
 240          
 241          $info = $this->ldap->search
 242              (
 243              '(objectclass=*)',
 244              array('mnAppParam', 'mnAppParam2'),
 245              T_SITE_DN,
 246              LDAP_SCOPE_BASE
 247              );
 248  
 249          if(mnError::isError($info))
 250              { return new mnError('App::getSiteVars() unable to read application info: ' . $info->message, __FILE__, __LINE__); }
 251          
 252          if(is_array($info))
 253              {
 254              $block = $info[0];
 255              if(!isset($block['mnappparam'])) { return array(); }
 256              if(isset($block['mnappparam']) && is_array($block['mnappparam']))
 257                  {
 258                  unset($block['mnappparam']['count']);
 259                  $params = $block['mnappparam'];
 260                  }
 261  
 262              if(isset($block['mnappparam2']) && is_array($block['mnappparam2']))
 263                  {
 264                  unset($block['mnappparam2']['count']);
 265                  $params = array_merge($params, $block['mnappparam2']);
 266                  }
 267  
 268              }
 269          
 270          $ret = Utility::processParams($params);
 271          return $ret;
 272          }
 273  
 274  
 275      /**
 276      * get block-level settings from LDAP
 277      *
 278      * preconditions:
 279      *   $this->ldap, $this->ldapDN
 280      * postconditions:
 281      *   return val
 282      *
 283      * @access   private
 284      * @return   mixed   array of appParams from LDAP, or mnError on failure
 285      */
 286      function getSettingsVars($ldapDN = "NONE")
 287          {
 288          if ($ldapDN == "NONE")
 289              $ldapDN = $this->ldapDN;
 290          $params = array();
 291          
 292          $info = $this->ldap->search
 293              (
 294              '(objectclass=' . C_LDAP_BLOCK_OBJECT . ')',
 295              array('mnAppParam', 'mnAppParam2'),
 296              $ldapDN,
 297              LDAP_SCOPE_BASE
 298              );
 299  
 300          if(mnError::isError($info))
 301              { return new mnError('Block::getSettingsVars() unable to read application info: ' . $info->message, __FILE__, __LINE__); }
 302          
 303          if(is_array($info))
 304              {
 305              $block = $info[0];
 306              if(isset($block['mnappparam']))
 307                  {
 308                  if (is_array($block['mnappparam']))
 309                      {
 310                      unset($block['mnappparam']['count']);
 311                      $params = $block['mnappparam'];
 312                      }
 313                  }
 314              if (isset($block['mnappparam2']))
 315                  {
 316                  if (is_array($block['mnappparam']))
 317                      {
 318                      unset($block['mnappparam2']['count']);
 319                      $params = array_merge($params, $block['mnappparam2']);
 320                      }
 321                  }
 322              }
 323          $ret = Utility::processParams($params);
 324          return $ret;
 325          }
 326      
 327      /**
 328      * returns link to current section with params included
 329      *
 330      * constructs link back to self with all key-val pairs in $params
 331      * hash array included in the GET portion of the URL string, with the keys
 332      * properly wrapped in a multilayered array so template site can pull out
 333      * the params destined for each content block (see paramName).
 334      *
 335      * @see  paramName
 336      * @param    array   hash array of parameters to pass through link
 337      * @param    boolean whether to load up only this block
 338      * @param    boolean whether to provide a popup() call for use in javascripts
 339      * @param    boolean whether to force a link to the secure server
 340      * @return   string  link URL
 341      * @access   private
 342      */
 343      function linkToSelf($params = array(), $single = false, $popup = false, $secure = T_SECURE)
 344          {
 345          $globalParams = array();
 346          if(T_SECURE && !@$GLOBALS['CV_PUBLISHING']) $globalParams['aC'] = T_ADMIN_CODE;
 347          if(T_SINGLE_BLOCK) $single = true;
 348          if($single) $globalParams['_single'] = $this->blockID;
 349  
 350          if (T_SECURE && !@$GLOBALS['CV_PUBLISHING'])
 351              {
 352              $link = T_SECURE_BASE_LINK . T_PRE_PATH .'/';
 353              }
 354          else
 355              $link = T_BASE_LINK . T_PRE_PATH .'/';
 356  
 357          $link .= implode('/', $this->sectionPathArray);
 358          #$link = T_BASE_LINK . (T_SECURE ? '/' : T_PRE_PATH) . implode('/', $this->sectionPathArray);
 359          $link = rtrim($link, '/'); 
 360          $link .= '?';
 361          if($secure && !@$GLOBALS['CV_PUBLISHING'])
 362              $link .= '&amp;id=' . urlencode(T_SITE_ID);
 363          if($this->edit)
 364              $link .= '&amp;' . $this->paramName('edit') . '=1';
 365          foreach($globalParams as $key => $val)
 366              {
 367              $key = htmlentities(urlencode($key));
 368              $val = htmlentities(urlencode($val));
 369              $link .= "&amp;$key=$val";
 370              }
 371              
 372          $params += $this->linkVars;
 373          foreach ($params as $key => $val)
 374              {
 375              if(is_array($val))
 376                  {
 377                  $key = urlencode($this->paramName($key . '[]'));
 378                  foreach($val as $item)
 379                      {
 380                      $item = urlencode($item);
 381                      $link .= "&amp;$key=$val";
 382                      }
 383                  }
 384              else
 385                  {
 386                  $key = urlencode($this->paramName($key));
 387                  $val = urlencode($val);
 388                  $link .= "&amp;$key=$val"; 
 389                  }
 390              }
 391          if(!$single) 
 392              $link .= '#' . strtr($this->blockID, ' ', '_') . '_a';
 393          if($popup && is_array($popup))
 394              $link = "popup('" . $link . "','" . $popup[0] . "', " . $popup[1] . ", " . $popup[2] . "); return false;";
 395          return $link;
 396          }
 397      
 398  	function httpRequestUrl($app = '')
 399          {
 400          if ($app == '')
 401              $app = $this->appID;
 402          return T_WEB_TOOLS . '/ajax.php?app=' . $app;
 403          }
 404          
 405  	function link_to_feed($title = '') {
 406          if (!$title && isset($this->section->blocks[$this->blockID]))
 407              $title = $this->section->blocks[$this->blockID]->getTitle();
 408          return Utility::link_to_feed($title, $this->sectionPathArray, array('_single' => $this->blockID));
 409      }
 410      
 411  	function link_to_ajax() {
 412          return str_replace('&amp;', '&', Utility::link($this->sectionPathArray, array('_single' => $this->blockID)));
 413      }
 414  
 415      /**
 416      * encloses parameter name in multilayered array format for template site
 417      *
 418      * except now (in order to allow apps to do javascript stuff with their
 419      * form inputs, since javascript doesn't like hard brackets in input names) 
 420      * we actually do a hack with double underscores instead of using hard
 421      * brackets - this means we have to reverse the hack in HTTPRequest.php and
 422      * package things properly in an array
 423      *
 424      * @param    string  basic parameter name (ie 'key')
 425      * @return   string  array-enclosed name (ie 'block[<blockID>][key]')
 426      * @access   private
 427      */
 428      function paramName($name)
 429          {
 430          $name = 'block__' . $this->blockID . '__' . $name;
 431          return $name;
 432          }
 433          
 434      /**
 435      * saves array of site-level params to LDAP
 436      *
 437      * preconditions:
 438      *   $this->ldapDN, $this->ldap, parameter
 439      * postconditions:
 440      *   hash array of params ($params) is saved to LDAP in mnAppParam
 441      *   attributes as key:val, existing parameters overwritten
 442      *
 443      * @param    array   hash array of parameters
 444      * @access   private
 445      * @return   true on success, mnError on error
 446      */
 447      function saveSiteSettings($settings)
 448          {
 449  
 450          $attrs['mnappparam'] = Utility::packageParams($settings);
 451          
 452          $res = $this->ldap->replace(T_SITE_DN, $attrs);
 453          if(mnError::isError($res))
 454              { return new mnError('App::saveSiteSettings(): ' . $res->getMessage(), __FILE__, __LINE__); }
 455          
 456          $this->siteVars = array();
 457          foreach($settings as $k => $v)
 458              {
 459              $this->siteVars[$k] = $v;
 460              }
 461  
 462          $this->params = $this->httpVars + $this->settingsVars + $this->siteVars;
 463          
 464          return true;
 465          }
 466  
 467  
 468      /**
 469      * saves array of content block-level params to LDAP
 470      *
 471      * preconditions:
 472      *   $this->ldapDN, $this->ldap, parameter
 473      * postconditions:
 474      *   hash array of params ($params) is saved to LDAP in mnAppParam
 475      *   attributes as key:val, existing parameters overwritten
 476      *
 477      * @param    array   hash array of parameters
 478      * @access   private
 479      * @return   true on success, mnError on error
 480      */
 481      function saveSettings($settings, $ldapDN = 'NONE')
 482          {
 483          if ($ldapDN == 'NONE')
 484              $ldapDN = $this->ldapDN;
 485  
 486          // the following is left in for its historical humor --reuvenmh
 487          //if ($ssize > 31000)
 488          //    {
 489          //    print "Awfully bad: but your folder is much too large for us to handle.<br>";
 490          //    die;
 491          //    }
 492  
 493          $attrs = array();
 494          $attrs['mnappparam'] = Utility::packageParams($settings);
 495          $res = $this->ldap->replace($ldapDN, $attrs);
 496          if(mnError::isError($res))
 497              { return new mnError('App::saveSettings(): ' . $res->getMessage(), __FILE__, __LINE__); }
 498          $this->settingsVars = array();
 499          foreach($settings as $k => $v)
 500              {
 501              $this->settingsVars[$k] = $v;
 502              }
 503          if ($ldapDN == $this->ldapDN)
 504              $this->params = $this->httpVars + $this->settingsVars + $this->siteVars;
 505          
 506          return true;
 507          }
 508  
 509       function getHelp($topics = array())
 510          {
 511          $app = str_replace('tmp', '', $this->blockID);
 512          $link = Utility::link('/Helper/'. $app);
 513          if (count($topics))
 514              {
 515              $string = implode('__', $topics);
 516              $link .= "#$string";
 517              }
 518                                      
 519          return "<a href=\"#\" onClick=\"popup('$link', 'Helper $app', 400, 500);\">?</a>";
 520          }
 521       
 522       function getPullDownArray()
 523          {
 524          return false;
 525          }
 526  
 527      /**
 528      * placeholder for onInit event (called when app is loaded)
 529      *
 530      * should be overloaded by inheriting app class to handle as an event
 531      **/
 532      function onInit()
 533          {
 534          return;
 535          }
 536  
 537      /**
 538      * placeholder for function to get header content for this app
 539      *
 540      * is called after app initialization and after data is saved, but before app content is retrieved
 541      *
 542      * may be overloaded by child application class
 543      **/
 544      function getHeader()
 545          {
 546          return '';
 547          }
 548  
 549      //This is a interface method that can be implemented by applications to return their keywords.
 550      function getKeywords()
 551          {
 552          return array();
 553          }
 554          
 555      /**
 556      * placeholder for function to get (non-config-screen) HTML content from this application
 557      *
 558      * should be overloaded by child application class
 559      *
 560      * @param    integer permissions level of user accessing block
 561      * @access   public
 562      */
 563      function getContent()
 564          {
 565          $class = get_class($this);
 566          return "Error: application $class does not define getContent method.";
 567          }
 568          
 569      /**
 570      * placeholder for onSave event (called when user has pressed a button named cv_submit)
 571      *
 572      * should be overloaded by inheriting app class to handle as an event
 573      *
 574      * @param    string  $submit title of the cv_submit button that was pressed
 575      */
 576      function onSave($submit)
 577          {
 578          return;
 579          }
 580      
 581      /**
 582      * default dispatcher method
 583      *
 584      * first saves if needed, then calls getContent or getConfig depending on
 585      * whether we're in edit mode or not
 586      *
 587      * override this method in an inheriting app class to dispatch differently
 588      */
 589      function dispatch()
 590          {
 591          if (isset($this->httpVars['cv_widget']))
 592              {
 593              $widget = $this->httpVars['cv_widget'];
 594              $widgetFile = T_WIDGET_BASE . '/' . $widget . '.php'; 
 595              include_once($widgetFile);
 596              return eval("return $widget::getContent();");
 597              }
 598          
 599          // this override exist specifically for the folderviewer, it does not create a block
 600          // before it is initially edited thus $this->can('config') will never return true
 601          // thus we check for layout privs on the page instead
 602          $override = false;
 603          if($this->blockID == 'tmpFolderViewer' && Security::can($this->ldapDN, 'layout'))
 604            $override = true;
 605          if($this->blockID == 'tmpBlockSettings' && Security::can($this->ldapDN, 'layout'))
 606            $override = true;
 607          if($this->blockID == 'tmpPageHelp' && Security::can($this->ldapDN, 'layout'))
 608            $override = true;  
 609            
 610          if ($this->can('config') || $override)
 611              {
 612              if ( isset($this->httpVars['cv_submit']) )
 613                  {
 614                  // close window if necessary
 615                  $submit = str_replace('&amp;', '&', $this->httpVars['cv_submit']);
 616                  if (T_SINGLE_BLOCK and ($submit == 'Save & Preview' or $submit == 'Save & Close'))
 617                      return Utility::getCloseRefreshJavascript();
 618                  else if(T_SINGLE_BLOCK and ($submit == 'Save & Return'))
 619                      return Utility::getCloseRefreshJavascript('' , true, false);    
 620                  }
 621                  
 622              // return configuration/editing screen if we're in that mode
 623              if ($this->edit)
 624                  {
 625                  if (method_exists($this, 'getConfig'))
 626                      return $this->getConfig();
 627                  else
 628                      return $this->getContent();
 629                  }
 630              }
 631          // return normal view if user isn't logged in or we're in preview mode
 632          return $this->getContent();
 633          }
 634  
 635      /**
 636      * returns the minimum width (in pixels) allowed for editing an app in place
 637      *
 638      * App::getMinWidth returns the default width, which may be overridden in
 639      * individual apps by redefining this method, if more space is needed
 640      *
 641      * a return value of 0 will force editing in a single-block new window
 642      */        
 643      function getMinWidth()
 644          {
 645          $app =& $GLOBALS['apps'][$this->appID];
 646          return ($app['minimum_width'] === "") ? 200 : $app['minimum_width'];
 647          }
 648          
 649      function bindAsUserAdmin()
 650          {
 651          $this->binddn = $this->ldap->binddn;
 652          $this->bindpw = $this->ldap->bindpw;
 653          $res = $this->ldap->bind(T_LDAP_ROOT_UID, T_LDAP_ROOT_PASSWD);
 654          if(mnError::isError($res))
 655              { return new mnError('Accounts::bindAsUserAdmin(): Unable to bind: ' . $res->getMessage(), __FILE__, __LINE__); }
 656          return 1;
 657          }
 658          
 659      function rebindAsLoginUser()
 660          {
 661          if ($this->super)
 662              return 1;
 663          $res = $this->ldap->bind($this->binddn, $this->bindpw);
 664          if(mnError::isError($res))
 665              { return new mnError('Accounts::rebindAsLoginUser(): Unable to bind: ' . $res->getMessage(), __FILE__, __LINE__); }
 666          return 1;
 667          }
 668          
 669      function dbwrapper(&$class, $function, $params = array())
 670          {
 671          if (!is_array($params))
 672              return 0;
 673          if (!isset($this->errorMessages) || !is_array($this->errorMessages))
 674              $this->errorMessages = array();
 675  
 676          foreach($params as $key => $value)
 677            {
 678            //$t = implode(",", $params);
 679            if(is_array($value))
 680              {
 681              $key = "arrayb".$key;
 682              ${$key} = $value;
 683              $t .= "\$".$key." ,";            
 684              }
 685            else
 686              $t .= $value.",";
 687            }
 688            
 689          $t=substr($t, 0, strlen($t) - 1);  
 690          
 691          if (!method_exists($class, $function))
 692              { 
 693              $error = "$class::$function() does not exist.";
 694              array_push($this->errorMessages, $error);
 695              return 0;
 696              }
 697          eval("\$res = is_object(\$class);");
 698          if (!$res)
 699              {
 700              $error = "this->$class doesn't exist.  Uninitialized?";
 701              array_push($this->errorMessages, $error);
 702              }
 703          $string = "\$res = @\$class->$function($t);";
 704          //print "string: $string<br>";
 705          eval($string);
 706          if (mnError::isError($res))
 707              {
 708              $error[0] = $res->getMessage();
 709              $error[1] = debug_backtrace();
 710  
 711              // zero args since we don't need them
 712              foreach($error[1] as $key => $value)
 713                {
 714                $error[1][$key]['args'] = array();
 715                }
 716  
 717              array_push($this->errorMessages, $error);
 718              return 0;
 719              }
 720              
 721          return $res;
 722          }
 723  
 724      function getDir($appID)
 725          {
 726          if (!isset($GLOBALS['apps'][$appID]))
 727              return false;
 728          $app =& $GLOBALS['apps'][$appID];
 729           
 730          if (isset($app['dir']))
 731              return T_APP_BASE . $app['dir'] . '/';
 732          else
 733              return T_APP_BASE . $appID . '/';
 734          }
 735  
 736      function getFile($appID)
 737          {
 738          if (!isset($GLOBALS['apps'][$appID]))
 739              return false;
 740          $app =& $GLOBALS['apps'][$appID];
 741          
 742          if (isset($app['file']))
 743              $file = $app['file'];
 744          else
 745              $file = $appID . '.php';
 746              
 747          return App::getDir($appID) . $file;
 748          }
 749          
 750      function getClass($appID)
 751          {
 752          if (!isset($GLOBALS['apps'][$appID]))
 753              return false;
 754          $app =& $GLOBALS['apps'][$appID];
 755          return isset($app['class']) ? $app['class'] : $appID;
 756          } 
 757  
 758      /*
 759      *    getAllHeaders
 760      *
 761      *    Returns all headers needed for the app, including both the ones from $GLOBALS['apps'][APP_NAME]['include']
 762      *    and anything returned by the $app->getHeader() function.
 763      *
 764      *    Called from Section::getContent() [and Display::get() for single-block mode]
 765      */
 766  	function getAllHeaders($appID = '')
 767          {
 768          if ($appID)
 769              $called_statically = true;
 770          else
 771              {
 772              $called_statically = false;
 773              $appID = $this->appID;
 774              }
 775          $h = '';
 776          if (isset($GLOBALS['apps'][$appID]['include']))
 777              {
 778              foreach ($GLOBALS['apps'][$appID]['include'] as $file => $edit)
 779                  {
 780                  if ($edit != 'edit')
 781                      $file = $edit;
 782                  if ($edit != 'edit' || ($edit == 'edit' and $this->edit))
 783                      {
 784                      // prepend the app dir, unless the filename starts with a slash
 785                      if ($file[0] != '/')
 786                          $file = App::getDir($appID) . $file;
 787                      if (isset($GLOBALS['included'][$file]))
 788                          continue;
 789                      $GLOBALS['included'][$file] = '';
 790                      
 791                      // handle javascripts and css stylesheets
 792                      if (ereg('\.js$', $file))
 793                          $h .= '<script language="Javascript" type="text/javascript" src="' . $file . '"></script>';
 794                      else if (ereg('\.css$', $file))
 795                          $h .= '<link rel="Stylesheet" type="text/css" href="' . $file . '">';
 796                      }
 797                  }
 798              }
 799          // add any headers from $this->getHeader()
 800          if ($called_statically)
 801              $h .= call_user_func(array(App::getClass($appID), 'getHeader'));
 802          else
 803              $h .= $this->getHeader();
 804              
 805          return $h;
 806          }
 807  
 808  	function addHeader($s)
 809          {
 810          $GLOBALS['CV_HEADERS'] .= $s;
 811          }
 812          
 813      } // end App class
 814       

title

Description

title

Description

title

Description

title

title

Body