CRM-15525 change require to require_once
[civicrm-core.git] / CRM / Utils / System / Joomla.php
index e7d8a4765bdc4a431ad6704c4e4ce4b39b1a7ad6..07ba3ed32dbf33f06f69e8ac01149d2fed3141af 100644 (file)
@@ -41,6 +41,12 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
    *
    */
   function __construct() {
+    /**
+     * deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
+     * functions and leave the codebase oblivious to the type of CMS
+     * @deprecated
+     * @var bool
+     */
     $this->is_drupal = FALSE;
   }
 
@@ -105,7 +111,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
     $ufName = CRM_Utils_Type::escape($ufName, 'String');
 
     $values = array();
-    $user = &JUser::getInstance($ufID);
+    $user = JUser::getInstance($ufID);
 
     $values['email'] = $ufName;
     $user->bind($values);
@@ -534,9 +540,9 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
 
         //include additional files required by Joomla 3.2.1+
         if ( version_compare(JVERSION, '3.2.1', 'ge') ) {
-          require $joomlaBase . '/libraries/cms/application/helper.php';
-          require $joomlaBase . '/libraries/cms/application/cms.php';
-          require $joomlaBase . '/libraries/cms/application/administrator.php';
+          require_once $joomlaBase . '/libraries/cms/application/helper.php';
+          require_once $joomlaBase . '/libraries/cms/application/cms.php';
+          require_once $joomlaBase . '/libraries/cms/application/administrator.php';
         }
       }
 
@@ -764,6 +770,11 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
     $loginURL = $config->userFrameworkBaseURL;
     $loginURL = str_replace('administrator/', '', $loginURL);
     $loginURL .= 'index.php?option=com_users&view=login';
+
+    //CRM-14872 append destination
+    if ( !empty($destination) ) {
+      $loginURL .= '&return='.urlencode(base64_encode($destination));
+    }
     return $loginURL;
   }
 
@@ -771,7 +782,35 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
    * @param $form
    */
   public function getLoginDestination(&$form) {
-    return;
+    $args = NULL;
+
+    $id = $form->get('id');
+    if ($id) {
+      $args .= "&id=$id";
+    }
+    else {
+      $gid = $form->get('gid');
+      if ($gid) {
+        $args .= "&gid=$gid";
+      }
+      else {
+        // Setup Personal Campaign Page link uses pageId
+        $pageId = $form->get('pageId');
+        if ($pageId) {
+          $component = $form->get('component');
+          $args .= "&pageId=$pageId&component=$component&action=add";
+        }
+      }
+    }
+
+    $destination = NULL;
+    if ($args) {
+      // append destination so user is returned to form they came from after login
+      $args = 'reset=1'.$args;
+      $destination = CRM_Utils_System::url(CRM_Utils_System::currentPath(), $args, TRUE, NULL, TRUE, TRUE);
+    }
+
+    return $destination;
   }
 
   /**
@@ -826,5 +865,22 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
       return TRUE;
     }
   }
+
+  /**
+   * output code from error function
+   * @param string $content
+   */
+  function outputError($content) {
+    if (class_exists('JErrorPage')) {
+      $error = new Exception($content);
+      JErrorPage::render($error);
+    }
+    else if (class_exists('JError')) {
+      JError::raiseError('CiviCRM-001', $content);
+    }
+    else {
+      parent::outputError($content);
+    }
+  }
 }