CRM-13737 drupal integration - Use basename fn to extract last dir in the url as...
[civicrm-core.git] / CRM / Utils / System / Joomla.php
index 518d85f439c79ab9abbd660a86ad82323017fdf6..0f635aacb86ab2cfec02b7be38bcd9085d6023a7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -471,7 +471,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
     jimport('joomla.application.component.helper');
     jimport('joomla.database.table');
 
-    $JUserTable = &JTable::getInstance('User', 'JTable');
+    $JUserTable = JTable::getInstance('User', 'JTable');
 
     $db = $JUserTable->getDbo();
     $query = $db->getQuery(TRUE);
@@ -526,7 +526,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
   function setUserSession($data) {
     list($userID, $ufID) = $data;
     $user = new JUser( $ufID );
-    $session = &JFactory::getSession();
+    $session = JFactory::getSession();
     $session->set('user', $user);
 
     parent::setUserSession($data);
@@ -564,7 +564,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
   function getUFLocale() {
     if (defined('_JEXEC')) {
       $conf = JFactory::getConfig();
-      $locale = $conf->getValue('config.language');
+      $locale = $conf->get('language');
       return str_replace('-', '_', $locale);
     }
     return NULL;
@@ -587,7 +587,7 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
    * @param $loadUser boolean load cms user?
    * @param $throwError throw error on failure?
    */
-  function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $loadDefines = TRUE) {
+  function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL, $loadDefines = TRUE) {
     // Setup the base path related constant.
     $joomlaBase = dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))))));
 
@@ -601,12 +601,28 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
     }
 
     // Get the framework.
+    if (file_exists($joomlaBase . '/libraries/import.legacy.php')) {
+      require $joomlaBase . '/libraries/import.legacy.php';
+    }
     require $joomlaBase . '/libraries/import.php';
     require $joomlaBase . '/libraries/joomla/event/dispatcher.php';
-    require $joomlaBase . '/libraries/joomla/environment/uri.php';
-    require $joomlaBase . '/libraries/joomla/application/component/helper.php';
     require $joomlaBase . '/configuration.php';
 
+    // Files may be in different places depending on Joomla version
+    if ( !defined('JVERSION') ) {
+      require $joomlaBase . '/libraries/cms/version/version.php';
+      $jversion = new JVersion;
+      define('JVERSION', $jversion->getShortVersion());
+    }
+
+    if( version_compare(JVERSION, '3.0', 'lt') ) {
+      require $joomlaBase . '/libraries/joomla/environment/uri.php';
+      require $joomlaBase . '/libraries/joomla/application/component/helper.php';
+    }
+    else {
+      require $joomlaBase . '/libraries/joomla/uri/uri.php';
+    }
+
     jimport('joomla.application.cli');
 
     return TRUE;
@@ -670,9 +686,31 @@ class CRM_Utils_System_Joomla extends CRM_Utils_System_Base {
     $loginURL .= 'index.php?option=com_users&view=login';
     return $loginURL;
   }
-  
+
   public function getLoginDestination(&$form) {
     return;
   }
+
+  /**
+   * Return default Site Settings
+   * @return array array
+   * - $url, (Joomla - non admin url)
+   * - $siteName,
+   * - $siteRoot
+   */
+  function getDefaultSiteSettings($dir){
+    $config = CRM_Core_Config::singleton();
+    $url = preg_replace(
+      '|/administrator|',
+      '',
+      $config->userFrameworkBaseURL
+    );
+    $siteRoot = preg_replace(
+      '|/media/civicrm/.*$|',
+      '',
+      $config->imageUploadDir
+    );
+    return array($url, NULL, $siteRoot);
+  }
 }