INFRA-132 - Change "else if" to "elseif"
[civicrm-core.git] / CRM / Core / Invoke.php
index 4c25c0f885a14ab036f37efad462fc9a9dabd674..67f1adc801677c227713ac983a05420534349f0c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 class CRM_Core_Invoke {
 
   /**
-   * This is the main function that is called on every click action and based on the argument
-   * respective functions are called
+   * This is the main front-controller that integrates with the CMS. Any
+   * page-request that is sent to the CMS and intended for CiviCRM should
+   * be processed by invoke().
    *
-   * @param $args array this array contains the arguments of the url
-   * @return string, HTML
+   * @param array $args
+   *   The parts of the URL which identify the intended CiviCRM page
+   *   (e.g. array('civicrm', 'event', 'register')).
+   * @return string
+   *   HTML. For non-HTML content, invoke() may call print() and exit().
    *
    * @static
-   * @access public
    */
-  static function invoke($args) {
+  public static function invoke($args) {
     try {
       return self::_invoke($args);
     }
-
     catch (Exception $e) {
-      return CRM_Core_Error::handleUnhandledException($e);
+      CRM_Core_Error::handleUnhandledException($e);
     }
   }
 
   /**
-   * @param $args
+   * This is the same as invoke(), but it does *not* include exception
+   * handling.
+   *
+   * @param array $args
+   *   The parts of the URL which identify the intended CiviCRM page
+   *   (e.g. array('civicrm', 'event', 'register')).
+   * @return string
+   *   HTML. For non-HTML content, invoke() may call print() and exit().
    */
-  protected static function _invoke($args) {
+  public static function _invoke($args) {
     if ($args[0] !== 'civicrm') {
       return;
     }
 
     if (!defined('CIVICRM_SYMFONY_PATH')) {
-      try {
-        // Traditional Civi invocation path
-        self::hackMenuRebuild($args); // may exit
-        self::init($args);
-        self::hackStandalone($args);
-        $item = self::getItem($args);
-        return self::runItem($item);
-      }
-      catch (CRM_Core_EXCEPTION $e) {
-        $params = $e->getErrorData();
-        $message = $e->getMessage();
-        if (isset($params['legacy_status_bounce'])) {
-          //@todo remove this- see comments on
-          //https://github.com/eileenmcnaughton/civicrm-core/commit/ae686b09e2c987091612bb25ba0a58e520a203e7
-          CRM_Core_Error::statusBounce($params['message']);
-        }
-        else {
-          $session = CRM_Core_Session::singleton();
-          $session->setStatus(
-            $message,
-            CRM_Utils_Array::value('message_title', $params),
-            CRM_Utils_Array::value('message_type', $params, 'error')
-          );
-
-          // @todo remove this code - legacy redirect path is an interim measure for moving redirects out of BAO
-          // to somewhere slightly more acceptable. they should not be part of the exception class & should
-          // be managed @ the form level - if you find a form that is triggering this piece of code
-          // you should log a ticket for it to be removed with details about the form you were on.
-          if(!empty($params['legacy_redirect_path'])) {
-            if(CRM_Utils_System::isDevelopment()) {
-              // here we could set a message telling devs to log it per above
-            }
-            CRM_Utils_System::redirect($params['legacy_redirect_path'], $params['legacy_redirect_query']);
-          }
-        }
-      }
-      catch (Exception $e) {
-        // Recall: CRM_Core_Config is initialized before calling CRM_Core_Invoke
-        $config = CRM_Core_Config::singleton();
-        return CRM_Core_Error::handleUnhandledException($e);
-        /*
-        if ($config->backtrace) {
-          return CRM_Core_Error::formatHtmlException($e);
-        } else {
-         // TODO
-        }*/
-      }
-    } else {
+      // Traditional Civi invocation path
+      self::hackMenuRebuild($args); // may exit
+      self::init($args);
+      self::hackStandalone($args);
+      $item = self::getItem($args);
+      return self::runItem($item);
+    }
+    else {
       // Symfony-based invocation path
       require_once CIVICRM_SYMFONY_PATH . '/app/bootstrap.php.cache';
       require_once CIVICRM_SYMFONY_PATH . '/app/AppKernel.php';
@@ -123,7 +92,8 @@ class CRM_Core_Invoke {
       if (preg_match(':^text/html:', $response->headers->get('Content-Type'))) {
         // let the CMS handle the trappings
         return $response->getContent();
-      } else {
+      }
+      else {
         $response->send();
         exit();
       }
@@ -132,7 +102,8 @@ class CRM_Core_Invoke {
   /**
    * Hackish support /civicrm/menu/rebuild
    *
-   * @param array $args list of path parts
+   * @param array $args
+   *   List of path parts.
    * @void
    */
   static public function hackMenuRebuild($args) {
@@ -152,7 +123,8 @@ class CRM_Core_Invoke {
   /**
    * Perform general setup
    *
-   * @param array $args list of path parts
+   * @param array $args
+   *   List of path parts.
    * @void
    */
   static public function init($args) {
@@ -171,7 +143,8 @@ class CRM_Core_Invoke {
   /**
    * Hackish support for /standalone/*
    *
-   * @param array $args list of path parts
+   * @param array $args
+   *   List of path parts.
    * @void
    */
   static public function hackStandalone($args) {
@@ -190,14 +163,16 @@ class CRM_Core_Invoke {
   /**
    * Determine which menu $item corresponds to $args
    *
-   * @param array $args list of path parts
+   * @param array $args
+   *   List of path parts.
    * @return array; see CRM_Core_Menu
    */
   static public function getItem($args) {
     if (is_array($args)) {
       // get the menu items
       $path = implode('/', $args);
-    } else {
+    }
+    else {
       $path = $args;
     }
     $item = CRM_Core_Menu::get($path);
@@ -215,7 +190,8 @@ class CRM_Core_Invoke {
   /**
    * Given a menu item, call the appropriate controller and return the response
    *
-   * @param array $item see CRM_Core_Menu
+   * @param array $item
+   *   See CRM_Core_Menu.
    * @return string, HTML
    */
   static public function runItem($item) {
@@ -349,9 +325,8 @@ class CRM_Core_Invoke {
    * @param $contact_sub_type
    *
    * @static
-   * @access public
    */
-  static function form($action, $contact_type, $contact_sub_type) {
+  public static function form($action, $contact_type, $contact_sub_type) {
     CRM_Utils_System::setUserContext(array('civicrm/contact/search/basic', 'civicrm/contact/view'));
     $wrapper = new CRM_Utils_Wrapper();
 
@@ -367,15 +342,21 @@ class CRM_Core_Invoke {
   /**
    * Show the message about CiviCRM versions
    *
-   * @param obj: $template (reference)
+   * @param CRM_Core_Smarty $template
    */
-  static function versionCheck($template) {
+  public static function versionCheck($template) {
     if (CRM_Core_Config::isUpgradeMode()) {
       return;
     }
-    $versionCheck = CRM_Utils_VersionCheck::singleton();
-    $newerVersion = $versionCheck->newerVersion();
+    $newerVersion = $securityUpdate = NULL;
+    if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, 1) & 1) {
+      $newerVersion = CRM_Utils_VersionCheck::singleton()->isNewerVersionAvailable();
+    }
+    if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityUpdateAlert', NULL, 3) & 1) {
+      $securityUpdate = CRM_Utils_VersionCheck::singleton()->isSecurityUpdateAvailable();
+    }
     $template->assign('newer_civicrm_version', $newerVersion);
+    $template->assign('security_update', $securityUpdate);
   }
 
   /**
@@ -384,7 +365,7 @@ class CRM_Core_Invoke {
    *
    * @throws Exception
    */
-  static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
+  public static function rebuildMenuAndCaches($triggerRebuild = FALSE, $sessionReset = FALSE) {
     $config = CRM_Core_Config::singleton();
     $config->clearModuleList();