Beispiel #1
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));
 }
 /**
  * Set the default values.
  * in an empty db, also called when setting component using GUI
  *
  * @param array $defaults
  *   Associated array of form elements.
  * @param bool $formMode
  *   this variable is set true for GUI
  *   mode (eg: Global setting >> Components)
  *
  */
 public static function setValues(&$defaults, $formMode = FALSE)
 {
     $config = CRM_Core_Config::singleton();
     $baseURL = $config->userFrameworkBaseURL;
     // CRM-6216: Drupal’s $baseURL might have a trailing LANGUAGE_NEGOTIATION_PATH,
     // which needs to be stripped before we start basing ResourceURL on it
     if ($config->userSystem->is_drupal) {
         global $language;
         if (isset($language->prefix) and $language->prefix) {
             if (substr($baseURL, -(strlen($language->prefix) + 1)) == $language->prefix . '/') {
                 $baseURL = substr($baseURL, 0, -(strlen($language->prefix) + 1));
             }
         }
     }
     $baseCMSURL = CRM_Utils_System::baseCMSURL();
     if ($config->templateCompileDir) {
         $path = CRM_Utils_File::baseFilePath($config->templateCompileDir);
     }
     if (!isset($defaults['enableSSL'])) {
         $defaults['enableSSL'] = 0;
     }
     //set defaults if not set in db
     if (!isset($defaults['userFrameworkResourceURL'])) {
         if ($config->userFramework == 'Joomla') {
             $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/";
         } elseif ($config->userFramework == 'WordPress') {
             $defaults['userFrameworkResourceURL'] = $baseURL . "wp-content/plugins/civicrm/civicrm/";
         } else {
             // Drupal setting
             // check and see if we are installed in sites/all (for D5 and above)
             // we dont use checkURL since drupal generates an error page and throws
             // the system for a loop on lobo's macosx box
             // or in modules
             global $civicrm_root;
             $cmsPath = $config->userSystem->cmsRootPath();
             $defaults['userFrameworkResourceURL'] = $baseURL . str_replace("{$cmsPath}/", '', str_replace('\\', '/', $civicrm_root));
             if (strpos($civicrm_root, DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'all' . DIRECTORY_SEPARATOR . 'modules') === FALSE) {
                 $startPos = strpos($civicrm_root, DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR);
                 $endPos = strpos($civicrm_root, DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR);
                 if ($startPos && $endPos) {
                     // if component is in sites/SITENAME/modules
                     $siteName = substr($civicrm_root, $startPos + 7, $endPos - $startPos - 7);
                     $civicrmDirName = trim(basename($civicrm_root));
                     $defaults['userFrameworkResourceURL'] = $baseURL . "sites/{$siteName}/modules/{$civicrmDirName}/";
                     if (!isset($defaults['imageUploadURL'])) {
                         $defaults['imageUploadURL'] = $baseURL . "sites/{$siteName}/files/civicrm/persist/contribute/";
                     }
                 }
             }
         }
     }
     if (!isset($defaults['imageUploadURL'])) {
         if ($config->userFramework == 'Joomla') {
             // gross hack
             // we need to remove the administrator/ from the end
             $tempURL = str_replace("/administrator/", "/", $baseURL);
             $defaults['imageUploadURL'] = $tempURL . "media/civicrm/persist/contribute/";
         } elseif ($config->userFramework == 'WordPress') {
             //for standalone no need of sites/defaults directory
             $defaults['imageUploadURL'] = $baseURL . "wp-content/plugins/files/civicrm/persist/contribute/";
         } else {
             $defaults['imageUploadURL'] = $baseURL . "sites/default/files/civicrm/persist/contribute/";
         }
     }
     if (!isset($defaults['imageUploadDir']) && is_dir($config->templateCompileDir)) {
         $imgDir = $path . "persist/contribute/";
         CRM_Utils_File::createDir($imgDir);
         $defaults['imageUploadDir'] = $imgDir;
     }
     if (!isset($defaults['uploadDir']) && is_dir($config->templateCompileDir)) {
         $uploadDir = $path . "upload/";
         CRM_Utils_File::createDir($uploadDir);
         CRM_Utils_File::restrictAccess($uploadDir);
         $defaults['uploadDir'] = $uploadDir;
     }
     if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) {
         $customDir = $path . "custom/";
         CRM_Utils_File::createDir($customDir);
         CRM_Utils_File::restrictAccess($customDir);
         $defaults['customFileUploadDir'] = $customDir;
     }
     // FIXME: hack to bypass the step for generating defaults for components,
     // while running upgrade, to avoid any serious non-recoverable error
     // which might hinder the upgrade process.
     $args = array();
     if (isset($_GET[$config->userFrameworkURLVar])) {
         $args = explode('/', $_GET[$config->userFrameworkURLVar]);
     }
     if (isset($defaults['enableComponents'])) {
         foreach ($defaults['enableComponents'] as $key => $name) {
             $comp = $config->componentRegistry->get($name);
             if ($comp) {
                 $co = $comp->getConfigObject();
                 $co->setDefaults($defaults);
             }
         }
     }
 }
Beispiel #3
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());
 }
Beispiel #4
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());
 }
 /**
  * Initializes the entire application.
  * Reads constants defined in civicrm.settings.php and
  * stores them in config properties.
  *
  * @param bool $loadFromDB
  */
 private function _initialize($loadFromDB = TRUE)
 {
     // following variables should be set in CiviCRM settings and
     // as crucial ones, are defined upon initialisation
     // instead of in CRM_Core_Config_Defaults
     if (defined('CIVICRM_DSN')) {
         $this->dsn = CIVICRM_DSN;
     } elseif ($loadFromDB) {
         // bypass when calling from gencode
         echo 'You need to define CIVICRM_DSN in civicrm.settings.php';
         exit;
     }
     if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
         $this->templateCompileDir = CRM_Utils_File::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR);
         // also make sure we create the config directory within this directory
         // the below statement will create both the templates directory and the config and log directory
         $this->configAndLogDir = CRM_Utils_File::baseFilePath($this->templateCompileDir) . 'ConfigAndLog' . DIRECTORY_SEPARATOR;
         CRM_Utils_File::createDir($this->configAndLogDir);
         CRM_Utils_File::restrictAccess($this->configAndLogDir);
         // we're automatically prefixing compiled templates directories with country/language code
         global $tsLocale;
         if (!empty($tsLocale)) {
             $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($tsLocale);
         } elseif (!empty($this->lcMessages)) {
             $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($this->lcMessages);
         }
         CRM_Utils_File::createDir($this->templateCompileDir);
         CRM_Utils_File::restrictAccess($this->templateCompileDir);
     } elseif ($loadFromDB) {
         echo 'You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php';
         exit;
     }
     $this->_initDAO();
     if (defined('CIVICRM_UF')) {
         $this->userFramework = CIVICRM_UF;
         $this->_setUserFrameworkConfig($this->userFramework);
     } else {
         echo 'You need to define CIVICRM_UF in civicrm.settings.php';
         exit;
     }
     // also initialize the logger
     self::$_log = Log::singleton('display');
     // initialize component registry early to avoid "race"
     // between CRM_Core_Config and CRM_Core_Component (they
     // are co-dependant)
     $this->componentRegistry = new CRM_Core_Component();
 }
Beispiel #6
0
 /**
  * @param bool $loadFromDB
  */
 public function initialize($loadFromDB = TRUE)
 {
     if (!defined('CIVICRM_DSN') && $loadFromDB) {
         $this->fatal('You need to define CIVICRM_DSN in civicrm.settings.php');
     }
     $this->dsn = defined('CIVICRM_DSN') ? CIVICRM_DSN : NULL;
     if (!defined('CIVICRM_TEMPLATE_COMPILEDIR') && $loadFromDB) {
         $this->fatal('You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php');
     }
     if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
         $this->configAndLogDir = CRM_Utils_File::baseFilePath() . 'ConfigAndLog' . DIRECTORY_SEPARATOR;
         CRM_Utils_File::createDir($this->configAndLogDir);
         CRM_Utils_File::restrictAccess($this->configAndLogDir);
         $this->templateCompileDir = defined('CIVICRM_TEMPLATE_COMPILEDIR') ? CRM_Utils_File::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR) : NULL;
         CRM_Utils_File::createDir($this->templateCompileDir);
         CRM_Utils_File::restrictAccess($this->templateCompileDir);
     }
     if (!defined('CIVICRM_UF')) {
         $this->fatal('You need to define CIVICRM_UF in civicrm.settings.php');
     }
     $this->userFramework = CIVICRM_UF;
     $this->userFrameworkClass = 'CRM_Utils_System_' . CIVICRM_UF;
     $this->userHookClass = 'CRM_Utils_Hook_' . CIVICRM_UF;
     if (CIVICRM_UF == 'Joomla') {
         $this->userFrameworkURLVar = 'task';
     }
     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->templateDir = array(dirname(dirname(dirname(__DIR__))) . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
     $this->initialized = 1;
 }
 /**
  * Get ConfigManager export / import location on disk.
  *
  * @return string
  */
 function getDirectory()
 {
     return \CRM_Utils_File::baseFilePath() . 'ConfigAndLog/configmgr' . DIRECTORY_SEPARATOR;
 }
function _configexport_get_directory()
{
    return CRM_Utils_File::baseFilePath() . 'ConfigAndLog/configmgr' . DIRECTORY_SEPARATOR;
}