Example #1
0
 /**
  * @return array
  */
 public function readActiveConfig()
 {
     if (!defined('CIVICRM_SETTINGS_PATH') || CIVICRM_SETTINGS_PATH !== $this->settingsFile) {
         return array();
     }
     $paths = is_callable(array('Civi', 'paths')) ? \Civi::paths() : NULL;
     $data = array('CMS_DB_DSN' => CIVICRM_UF_DSN, 'CMS_VERSION' => \CRM_Core_Config::singleton()->userSystem->getVersion(), 'CIVI_DB_DSN' => CIVICRM_DSN, 'CIVI_SITE_KEY' => CIVICRM_SITE_KEY, 'CIVI_VERSION' => \CRM_Utils_System::version(), 'CIVI_SETTINGS' => CIVICRM_SETTINGS_PATH, 'CIVI_TEMPLATEC' => \CRM_Core_Config::singleton()->templateCompileDir, 'CIVI_UF' => \CRM_Core_Config::singleton()->userFramework, 'IS_INSTALLED' => '1', 'SITE_TYPE' => 'cv-auto', 'CMS_URL' => $paths ? \Civi::paths()->getUrl('[cms.root]/', 'absolute') : \CRM_Utils_System::languageNegotiationURL(\CRM_Utils_System::baseCMSURL(), FALSE, TRUE), 'CMS_ROOT' => $paths ? \Civi::paths()->getPath('[cms.root]/.') : \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), 'CIVI_CORE' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : $GLOBALS['civicrm_root'], 'CIVI_URL' => $paths ? \Civi::paths()->getUrl('[civicrm.root]/', 'absolute') : '', 'CIVI_FILES' => $paths ? \Civi::paths()->getPath('[civicrm.root]/.') : dirname(\CRM_Core_Config::singleton()->templateCompileDir));
     return $data;
 }
Example #2
0
 /**
  * Moved from CRM_Utils_System_Base
  */
 public function getDefaultFileStorage()
 {
     $config = CRM_Core_Config::singleton();
     $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
     $cmsPath = $this->cmsRootPath();
     $filesPath = CRM_Utils_File::baseFilePath();
     $filesRelPath = CRM_Utils_File::relativize($filesPath, $cmsPath);
     $filesURL = rtrim($cmsUrl, '/') . '/' . ltrim($filesRelPath, ' /');
     return array('url' => CRM_Utils_File::addTrailingSlash($filesURL, '/'), 'path' => CRM_Utils_File::addTrailingSlash($filesPath));
 }
Example #3
0
 public function __construct()
 {
     $this->register('civicrm.root', function () {
         return \CRM_Core_Config::singleton()->userSystem->getCiviSourceStorage();
     })->register('civicrm.files', function () {
         return \CRM_Core_Config::singleton()->userSystem->getDefaultFileStorage();
     })->register('cms', function () {
         return array('path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), 'url' => \CRM_Utils_System::baseCMSURL());
     })->register('cms.root', function () {
         return array('path' => \CRM_Core_Config::singleton()->userSystem->cmsRootPath(), 'url' => \CRM_Utils_System::languageNegotiationURL(\CRM_Utils_System::baseCMSURL(), FALSE, TRUE));
     });
 }
Example #4
0
 /**
  * Moved from CRM_Utils_System_Base
  */
 public function getDefaultFileStorage()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
     $filesURL = NULL;
     $filesPath = NULL;
     $upload_dir = wp_upload_dir();
     $settingsDir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR;
     $settingsURL = $upload_dir['baseurl'] . DIRECTORY_SEPARATOR . 'civicrm' . DIRECTORY_SEPARATOR;
     if (is_dir(WP_PLUGIN_DIR . '/files/civicrm/')) {
         //for legacy path
         $filesURL = WP_PLUGIN_URL . "/files/civicrm/";
     } elseif (is_dir($settingsDir)) {
         $filesURL = $settingsURL;
     } else {
         throw new CRM_Core_Exception("Failed to locate default file storage ({$config->userFramework})");
     }
     return array('url' => $filesURL, 'path' => CRM_Utils_File::baseFilePath());
 }
 /**
  * Return relative path.
  *
  * @todo make this a method of $config->userSystem (i.e. UF classes) rather than a static function
  *
  * @param string $absolutePath
  *   Absolute path.
  *
  * @return string
  *   Relative url of uploaded image
  */
 public static function getRelativePath($absolutePath)
 {
     $relativePath = NULL;
     $config = CRM_Core_Config::singleton();
     if ($config->userFramework == 'Joomla') {
         $userFrameworkBaseURL = trim(str_replace('/administrator/', '', $config->userFrameworkBaseURL));
         $customFileUploadDirectory = strstr(str_replace('\\', '/', $absolutePath), '/media');
         $relativePath = $userFrameworkBaseURL . $customFileUploadDirectory;
     } elseif ($config->userSystem->is_drupal == '1') {
         //ideally we would do a bigger re-factoring & move the getRelativePath onto the UF class
         $rootPath = $config->userSystem->cmsRootPath();
         $baseUrl = $config->userFrameworkBaseURL;
         //format url for language negotiation, CRM-7135
         $baseUrl = CRM_Utils_System::languageNegotiationURL($baseUrl, FALSE, TRUE);
         $relativePath = str_replace("{$rootPath}/", $baseUrl, str_replace('\\', '/', $absolutePath));
     } elseif ($config->userFramework == 'WordPress') {
         $userFrameworkBaseURL = trim(str_replace('/wp-admin/', '', $config->userFrameworkBaseURL));
         $customFileUploadDirectory = strstr(str_replace('\\', '/', $absolutePath), '/wp-content/');
         $relativePath = $userFrameworkBaseURL . $customFileUploadDirectory;
     }
     return $relativePath;
 }
Example #6
0
 /**
  * Determine the default location for file storage.
  *
  * FIXME:
  *  1. This was pulled out from a bigger function. It should be split
  *     into even smaller pieces and marked abstract.
  *  2. This would be easier to compute by a calling a CMS API, but
  *     for whatever reason Civi gets it from config data.
  *
  * @return array
  *   - url: string. ex: "http://example.com/sites/foo.com/files/civicrm"
  *   - path: string. ex: "/var/www/sites/foo.com/files/civicrm"
  */
 public function getDefaultFileStorage()
 {
     global $civicrm_root;
     $config = CRM_Core_Config::singleton();
     $baseURL = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
     $filesURL = NULL;
     $filesPath = NULL;
     if ($config->userFramework == 'Joomla') {
         // gross hack
         // we need to remove the administrator/ from the end
         $tempURL = str_replace("/administrator/", "/", $baseURL);
         $filesURL = $tempURL . "media/civicrm/";
     } elseif ($this->is_drupal) {
         $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root);
         if ($siteName) {
             $filesURL = $baseURL . "sites/{$siteName}/files/civicrm/";
         } else {
             $filesURL = $baseURL . "sites/default/files/civicrm/";
         }
     } elseif ($config->userFramework == 'UnitTests') {
         $filesURL = $baseURL . "sites/default/files/civicrm/";
     } else {
         throw new CRM_Core_Exception("Failed to locate default file storage ({$config->userFramework})");
     }
     return array('url' => $filesURL, 'path' => CRM_Utils_File::baseFilePath());
 }
Example #7
0
 /**
  * @param string $userFramework
  *   One of 'Drupal', 'Joomla', etc.
  */
 private function _setUserFrameworkConfig($userFramework)
 {
     $this->userFrameworkClass = 'CRM_Utils_System_' . $userFramework;
     $this->userHookClass = 'CRM_Utils_Hook_' . $userFramework;
     $userPermissionClass = 'CRM_Core_Permission_' . $userFramework;
     $this->userPermissionClass = new $userPermissionClass();
     $class = $this->userFrameworkClass;
     // redundant with _initVariables
     $this->userSystem = new $class();
     if ($userFramework == 'Joomla') {
         $this->userFrameworkURLVar = 'task';
     }
     if (defined('CIVICRM_UF_BASEURL')) {
         $this->userFrameworkBaseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/');
         //format url for language negotiation, CRM-7803
         $this->userFrameworkBaseURL = CRM_Utils_System::languageNegotiationURL($this->userFrameworkBaseURL);
         if (CRM_Utils_System::isSSL()) {
             $this->userFrameworkBaseURL = str_replace('http://', 'https://', $this->userFrameworkBaseURL);
         }
     }
     if (defined('CIVICRM_UF_DSN')) {
         $this->userFrameworkDSN = CIVICRM_UF_DSN;
     }
     // this is dynamically figured out in the civicrm.settings.php file
     if (defined('CIVICRM_CLEANURL')) {
         $this->cleanURL = CIVICRM_CLEANURL;
     } else {
         $this->cleanURL = 0;
     }
     $this->userFrameworkVersion = $this->userSystem->getVersion();
     if ($userFramework == 'Joomla') {
         /** @var object|null $mainframe */
         global $mainframe;
         $dbprefix = $mainframe ? $mainframe->getCfg('dbprefix') : 'jos_';
         $this->userFrameworkUsersTableName = $dbprefix . 'users';
     } elseif ($userFramework == 'WordPress') {
         global $wpdb;
         $dbprefix = $wpdb ? $wpdb->prefix : '';
         $this->userFrameworkUsersTableName = $dbprefix . 'users';
     }
 }