private function initialize() { $config = CRM_Core_Config::singleton(); if (isset($config->customTemplateDir) && $config->customTemplateDir) { $this->template_dir = array_merge(array($config->customTemplateDir), $config->templateDir); } else { $this->template_dir = $config->templateDir; } $this->compile_dir = CRM_Utils_File::addTrailingSlash(CRM_Utils_File::addTrailingSlash($config->templateCompileDir) . $this->getLocale()); CRM_Utils_File::createDir($this->compile_dir); CRM_Utils_File::restrictAccess($this->compile_dir); // check and ensure it is writable // else we sometime suppress errors quietly and this results // in blank emails etc if (!is_writable($this->compile_dir)) { echo "CiviCRM does not have permission to write temp files in {$this->compile_dir}, Exiting"; exit; } //Check for safe mode CRM-2207 if (ini_get('safe_mode')) { $this->use_sub_dirs = FALSE; } else { $this->use_sub_dirs = TRUE; } $customPluginsDir = NULL; if (isset($config->customPHPPathDir)) { $customPluginsDir = $config->customPHPPathDir . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR; if (!file_exists($customPluginsDir)) { $customPluginsDir = NULL; } } $smartyDir = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'packages' . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR; $pluginsDir = __DIR__ . DIRECTORY_SEPARATOR . 'Smarty' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR; if ($customPluginsDir) { $this->plugins_dir = array($customPluginsDir, $smartyDir . 'plugins', $pluginsDir); } else { $this->plugins_dir = array($smartyDir . 'plugins', $pluginsDir); } // add the session and the config here $session = CRM_Core_Session::singleton(); $this->assign_by_ref('config', $config); $this->assign_by_ref('session', $session); global $tsLocale; $this->assign('tsLocale', $tsLocale); // CRM-7163 hack: we don’t display langSwitch on upgrades anyway if (!CRM_Core_Config::isUpgradeMode()) { $this->assign('langSwitch', CRM_Core_I18n::languages(TRUE)); } $this->register_function('crmURL', array('CRM_Utils_System', 'crmURL')); $this->load_filter('pre', 'resetExtScope'); $this->assign('crmPermissions', new CRM_Core_Smarty_Permissions()); }
/** * Scan all api directories to discover entities * * @param \Civi\API\Result $result */ public function _run(Result $result) { $entities = array(); foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) { $dir = \CRM_Utils_File::addTrailingSlash($path) . 'Civi/Api4'; if (is_dir($dir)) { foreach (glob("{$dir}/*.php") as $file) { $matches = array(); preg_match('/(\\w*).php/', $file, $matches); $entities[$matches[1]] = $matches[1]; } } } $result->exchangeArray(array_values($entities)); }
public function _run(Result $result) { $includePaths = array_unique(explode(PATH_SEPARATOR, get_include_path())); $entityReflection = new \ReflectionClass('\\Civi\\Api4\\' . $this->getEntity()); // First search entity-specific actions (including those provided by extensions foreach ($includePaths as $path) { $dir = \CRM_Utils_File::addTrailingSlash($path) . 'Civi/API/V4/Entity/' . $this->getEntity(); $this->scanDir($dir); } // Scan all generic actions unless this entity does not extend generic entity if ($entityReflection->getParentClass()) { foreach ($includePaths as $path) { $dir = \CRM_Utils_File::addTrailingSlash($path) . 'Civi/API/V4/Action'; $this->scanDir($dir); } } else { foreach ($entityReflection->getMethods(\ReflectionMethod::IS_STATIC) as $method) { $this->loadAction($method->getName()); } } $result->exchangeArray(array_values($this->_actions)); }
public function __get($k) { if (!isset($this->map[$k])) { throw new \CRM_Core_Exception("Cannot read unrecognized property CRM_Core_Config::\${$k}."); } if (isset($this->cache[$k])) { return $this->cache[$k]; } $type = $this->map[$k][0]; $name = isset($this->map[$k][1]) ? $this->map[$k][1] : $k; switch ($type) { case 'setting': return $this->getSettings()->get($name); case 'setting-path': // Array(0 => $type, 1 => $setting, 2 => $actions). $value = $this->getSettings()->get($name); $value = Civi::paths()->getPath($value); if ($value) { $value = CRM_Utils_File::addTrailingSlash($value); if (isset($this->map[$k][2]) && in_array('mkdir', $this->map[$k][2])) { CRM_Utils_File::createDir($value); } if (isset($this->map[$k][2]) && in_array('restrict', $this->map[$k][2])) { CRM_Utils_File::restrictAccess($value); } } $this->cache[$k] = $value; return $value; case 'setting-url-abs': $value = $this->getSettings()->get($name); $this->cache[$k] = Civi::paths()->getUrl($value, 'absolute'); return $this->cache[$k]; case 'setting-url-rel': $value = $this->getSettings()->get($name); $this->cache[$k] = Civi::paths()->getUrl($value, 'relative'); return $this->cache[$k]; case 'runtime': return \Civi\Core\Container::getBootService('runtime')->{$name}; case 'boot-svc': $this->cache[$k] = \Civi\Core\Container::getBootService($name); return $this->cache[$k]; case 'local': $this->initLocals(); return $this->locals[$name]; case 'user-system': $userSystem = \Civi\Core\Container::getBootService('userSystem'); $this->cache[$k] = call_user_func(array($userSystem, $name)); return $this->cache[$k]; case 'service': return \Civi::service($name); case 'callback': // Array(0 => $type, 1 => $obj, 2 => $getter, 3 => $setter, 4 => $unsetter). if (!isset($this->map[$k][1], $this->map[$k][2])) { throw new \CRM_Core_Exception("Cannot find getter for property CRM_Core_Config::\${$k}"); } return \Civi\Core\Resolver::singleton()->call(array($this->map[$k][1], $this->map[$k][2]), array($k)); default: throw new \CRM_Core_Exception("Cannot read property CRM_Core_Config::\${$k} ({$type})"); } }
/** * initialize the config variables * * @return void * @access private */ private function _initVariables() { // initialize component registry early to avoid "race" // between CRM_Core_Config and CRM_Core_Component (they // are co-dependant) require_once 'CRM/Core/Component.php'; $this->componentRegistry = new CRM_Core_Component(); // retrieve serialised settings require_once "CRM/Core/BAO/Setting.php"; $variables = array(); CRM_Core_BAO_Setting::retrieve($variables); // if settings are not available, go down the full path if (empty($variables)) { // Step 1. get system variables with their hardcoded defaults $variables = get_object_vars($this); // Step 2. get default values (with settings file overrides if // available - handled in CRM_Core_Config_Defaults) require_once 'CRM/Core/Config/Defaults.php'; CRM_Core_Config_Defaults::setValues($variables); // add component specific settings $this->componentRegistry->addConfig($this); // serialise settings CRM_Core_BAO_Setting::add($variables); } $urlArray = array('userFrameworkResourceURL', 'imageUploadURL'); $dirArray = array('uploadDir', 'customFileUploadDir'); foreach ($variables as $key => $value) { if (in_array($key, $urlArray)) { $value = CRM_Utils_File::addTrailingSlash($value, '/'); } else { if (in_array($key, $dirArray)) { $value = CRM_Utils_File::addTrailingSlash($value); if (CRM_Utils_File::createDir($value, false) === false) { // seems like we could not create the directories // settings might have changed, lets suppress a message for now // so we can make some more progress and let the user fix their settings // for now we assign it to a know value // CRM-4949 $value = $this->templateCompileDir; } } else { if ($key == 'lcMessages') { // reset the templateCompileDir to locale-specific and make sure it exists $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($value); CRM_Utils_File::createDir($this->templateCompileDir); } } } $this->{$key} = $value; } if ($this->userFrameworkResourceURL) { // we need to do this here so all blocks also load from an ssl server if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') { CRM_Utils_System::mapConfigToSSL(); } $rrb = parse_url($this->userFrameworkResourceURL); // dont use absolute path if resources are stored on a different server // CRM-4642 $this->resourceBase = $this->userFrameworkResourceURL; if (isset($_SERVER['HTTP_HOST'])) { $this->resourceBase = $rrb['host'] == $_SERVER['HTTP_HOST'] ? $rrb['path'] : $this->userFrameworkResourceURL; } } if (!$this->customFileUploadDir) { $this->customFileUploadDir = $this->uploadDir; } if ($this->mapProvider) { $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->mapProvider; } }
function postProcess() { // redirect to admin page after saving $session =& CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin')); $params = $this->controller->exportValues($this->_name); //CRM-5679 foreach ($params as $name => &$val) { if ($val && in_array($name, array('newBaseURL', 'newBaseDir', 'newSiteName'))) { $val = CRM_Utils_File::addTrailingSlash($val); } } $from = array($this->_oldBaseURL, $this->_oldBaseDir); $to = array(trim($params['newBaseURL']), trim($params['newBaseDir'])); if ($this->_oldSiteName && $params['newSiteName']) { $from[] = $this->_oldSiteName; $to[] = $params['newSiteName']; } $newValues = str_replace($from, $to, $this->_defaults); parent::commonProcess($newValues); parent::rebuildMenu(); }
function testFormatMailchimpWebhookUrl() { $url = CIVICRM_UF_BASEURL; $url = CRM_Utils_File::addTrailingSlash($url); $site_key = CRM_CiviMailchimp_Utils::getSiteKey(); $expected_webhook_url = "{$url}civicrm/mailchimp/webhook?key={$site_key}"; $webhook_url = CRM_CiviMailchimp_Utils::formatMailchimpWebhookUrl(); $this->assertEquals($expected_webhook_url, $webhook_url); }
/** * Determine the location of the CiviCRM source tree. * * 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 we take the hard way. * * @return array * - url: string. ex: "http://example.com/sites/all/modules/civicrm" * - path: string. ex: "/var/www/sites/all/modules/civicrm" */ public function getCiviSourceStorage() { global $civicrm_root; $config = CRM_Core_Config::singleton(); // Don't use $config->userFrameworkBaseURL; it has garbage on it. // More generally, w shouldn't be using $config here. if (!defined('CIVICRM_UF_BASEURL')) { throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); } $baseURL = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/'); if (CRM_Utils_System::isSSL()) { $baseURL = str_replace('http://', 'https://', $baseURL); } if ($config->userFramework == 'Joomla') { $userFrameworkResourceURL = $baseURL . "components/com_civicrm/civicrm/"; } elseif ($config->userFramework == 'WordPress') { $userFrameworkResourceURL = CIVICRM_PLUGIN_URL . "civicrm/"; } elseif ($this->is_drupal) { // 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 $cmsPath = $config->userSystem->cmsRootPath(); $userFrameworkResourceURL = $baseURL . str_replace("{$cmsPath}/", '', str_replace('\\', '/', $civicrm_root)); $siteName = $config->userSystem->parseDrupalSiteName($civicrm_root); if ($siteName) { $civicrmDirName = trim(basename($civicrm_root)); $userFrameworkResourceURL = $baseURL . "sites/{$siteName}/modules/{$civicrmDirName}/"; } } else { $userFrameworkResourceURL = NULL; } return array('url' => CRM_Utils_File::addTrailingSlash($userFrameworkResourceURL), 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root)); }
/** * Download the Mailchimp export file to a temporary folder. */ static function retrieveMailchimpMemberExportFile($url, $list_id) { $config = CRM_Core_Config::singleton(); $timestamp = microtime(); $temp_dir = CRM_Utils_File::addTrailingSlash($config->uploadDir); $file_path = "{$temp_dir}mailchimp_export_{$list_id}_{$timestamp}.tmp"; $file = fopen($file_path, 'w'); if ($file === FALSE) { throw new CRM_CiviMailchimp_Exception("Unable to open the temporary Mailchimp Export file located at {$file_path}."); } $ch = curl_init($url); if ($ch === FALSE) { $err_number = curl_errno($ch); $err_string = curl_error($ch); throw new CRM_CiviMailchimp_Exception("cURL failed to initiate for the url {$url}. cURL error # {$err_number}: {$err_string}."); } curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_FILE, $file); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $data = curl_exec($ch); if ($data === FALSE) { $err_number = curl_errno($ch); $err_string = curl_error($ch); throw new CRM_CiviMailchimp_Exception("cURL failed to retrieve data from the url {$url}. cURL error # {$err_number}: {$err_string}."); } curl_close($ch); fclose($file); return $file_path; }
/** * Determine the location of the CiviCRM source tree. * * @return array * - url: string. ex: "http://example.com/sites/all/modules/civicrm" * - path: string. ex: "/var/www/sites/all/modules/civicrm" */ public function getCiviSourceStorage() { global $civicrm_root; // Don't use $config->userFrameworkBaseURL; it has garbage on it. // More generally, we shouldn't be using $config here. if (!defined('CIVICRM_UF_BASEURL')) { throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL'); } $cmsPath = $this->cmsRootPath(); // $config = CRM_Core_Config::singleton(); // overkill? // $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE); $cmsUrl = CIVICRM_UF_BASEURL; if (CRM_Utils_System::isSSL()) { $cmsUrl = str_replace('http://', 'https://', $cmsUrl); } $civiRelPath = CRM_Utils_File::relativize($civicrm_root, $cmsPath); $civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /'); return array('url' => CRM_Utils_File::addTrailingSlash($civiUrl, '/'), 'path' => CRM_Utils_File::addTrailingSlash($civicrm_root)); }
/** * Initialize the config variables. * * @return void */ private function _initVariables() { // retrieve serialised settings $variables = array(); CRM_Core_BAO_ConfigSetting::retrieve($variables); // if settings are not available, go down the full path if (empty($variables)) { // Step 1. get system variables with their hardcoded defaults $variables = get_object_vars($this); // Step 2. get default values (with settings file overrides if // available - handled in CRM_Core_Config_Defaults) CRM_Core_Config_Defaults::setValues($variables); // retrieve directory and url preferences also CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($variables); // add component specific settings $this->componentRegistry->addConfig($this); // serialise settings $settings = $variables; CRM_Core_BAO_ConfigSetting::add($settings); } $urlArray = array('userFrameworkResourceURL', 'imageUploadURL'); $dirArray = array('uploadDir', 'customFileUploadDir'); foreach ($variables as $key => $value) { if (in_array($key, $urlArray)) { $value = CRM_Utils_File::addTrailingSlash($value, '/'); } elseif (in_array($key, $dirArray)) { if ($value) { $value = CRM_Utils_File::addTrailingSlash($value); } if (empty($value) || CRM_Utils_File::createDir($value, FALSE) === FALSE) { // seems like we could not create the directories // settings might have changed, lets suppress a message for now // so we can make some more progress and let the user fix their settings // for now we assign it to a know value // CRM-4949 $value = $this->templateCompileDir; $url = CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1'); CRM_Core_Session::setStatus(ts('%1 has an incorrect directory path. Please go to the <a href="%2">path setting page</a> and correct it.', array(1 => $key, 2 => $url)), ts('Check Settings'), 'alert'); } } elseif ($key == 'lcMessages') { // reset the templateCompileDir to locale-specific and make sure it exists if (substr($this->templateCompileDir, -1 * strlen($value) - 1, -1) != $value) { $this->templateCompileDir .= CRM_Utils_File::addTrailingSlash($value); CRM_Utils_File::createDir($this->templateCompileDir); CRM_Utils_File::restrictAccess($this->templateCompileDir); } } $this->{$key} = $value; } if ($this->userFrameworkResourceURL) { // we need to do this here so all blocks also load from an ssl server if (CRM_Utils_System::isSSL()) { CRM_Utils_System::mapConfigToSSL(); } $rrb = parse_url($this->userFrameworkResourceURL); // don't use absolute path if resources are stored on a different server // CRM-4642 $this->resourceBase = $this->userFrameworkResourceURL; if (isset($_SERVER['HTTP_HOST']) && isset($rrb['host'])) { $this->resourceBase = $rrb['host'] == $_SERVER['HTTP_HOST'] ? $rrb['path'] : $this->userFrameworkResourceURL; } } if (!$this->customFileUploadDir) { $this->customFileUploadDir = $this->uploadDir; } if ($this->geoProvider) { $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->geoProvider; } elseif ($this->mapProvider) { $this->geocodeMethod = 'CRM_Utils_Geocode_' . $this->mapProvider; } require_once str_replace('_', DIRECTORY_SEPARATOR, $this->userFrameworkClass) . '.php'; $class = $this->userFrameworkClass; // redundant with _setUserFrameworkConfig $this->userSystem = new $class(); }
/** * Create the base file path from which all our internal directories are * offset. This is derived from the template compile directory set */ static function baseFilePath($templateCompileDir = NULL) { static $_path = NULL; if (!$_path) { if ($templateCompileDir == NULL) { $config = CRM_Core_Config::singleton(); $templateCompileDir = $config->templateCompileDir; } $path = dirname($templateCompileDir); //this fix is to avoid creation of upload dirs inside templates_c directory $checkPath = explode(DIRECTORY_SEPARATOR, $path); $cnt = count($checkPath) - 1; if ($checkPath[$cnt] == 'templates_c') { unset($checkPath[$cnt]); $path = implode(DIRECTORY_SEPARATOR, $checkPath); } $_path = CRM_Utils_File::addTrailingSlash($path); } return $_path; }
/** * @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; }
function postProcess() { if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) { $config = CRM_Core_Config::singleton(); // cleanup templates_c directory $config->cleanup(1, FALSE); // clear db caching CRM_Core_Config::clearDBCache(); parent::rebuildMenu(); CRM_Core_BAO_WordReplacement::rebuild(); CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success"); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1')); } // redirect to admin page after saving $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin')); $params = $this->controller->exportValues($this->_name); //CRM-5679 foreach ($params as $name => &$val) { if ($val && in_array($name, array('newBaseURL', 'newBaseDir', 'newSiteName'))) { $val = CRM_Utils_File::addTrailingSlash($val); } } $from = array($this->_oldBaseURL, $this->_oldBaseDir); $to = array(trim($params['newBaseURL']), trim($params['newBaseDir'])); if ($this->_oldSiteName && $params['newSiteName']) { $from[] = $this->_oldSiteName; $to[] = $params['newSiteName']; } $newValues = str_replace($from, $to, $this->_defaults); parent::commonProcess($newValues); parent::rebuildMenu(); }
/** * Function to set the default values * * @param array $defaults associated array of form elements * @param boolena $formMode this funtion is called to set default * values in an empty db, also called when setting component using GUI * this variable is set true for GUI * mode (eg: Global setting >> Components) * * @access public */ public function setValues(&$defaults, $formMode = false) { $config =& CRM_Core_Config::singleton(); $baseURL = $config->userFrameworkBaseURL; if ($config->templateCompileDir) { $path = dirname($config->templateCompileDir); //this fix is to avoid creation of upload dirs inside templates_c directory $checkPath = explode(DIRECTORY_SEPARATOR, $path); $cnt = count($checkPath) - 1; if ($checkPath[$cnt] == 'templates_c') { unset($checkPath[$cnt]); $path = implode(DIRECTORY_SEPARATOR, $checkPath); } $path = CRM_Utils_File::addTrailingSlash($path); } //set defaults if not set in db if (!isset($defaults['userFrameworkResourceURL'])) { $testIMG = "i/tracker.gif"; if ($config->userFramework == 'Joomla') { if (CRM_Utils_System::checkURL("{$baseURL}components/com_civicrm/civicrm/{$testIMG}")) { $defaults['userFrameworkResourceURL'] = $baseURL . "components/com_civicrm/civicrm/"; } } else { if ($config->userFramework == 'Standalone') { // potentially sane default for standalone; // could probably be smarter about this, but this // should work in many cases $defaults['userFrameworkResourceURL'] = str_replace('standalone/', '', $baseURL); } 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; $civicrmDirName = trim(basename($civicrm_root)); $defaults['userFrameworkResourceURL'] = $baseURL . "sites/all/modules/{$civicrmDirName}/"; 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); $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/"; } else { if ($config->userFramework == 'Standalone') { //for standalone no need of sites/defaults directory $defaults['imageUploadURL'] = $baseURL . "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); $defaults['uploadDir'] = $uploadDir; } if (!isset($defaults['customFileUploadDir']) && is_dir($config->templateCompileDir)) { $customDir = $path . "custom/"; CRM_Utils_File::createDir($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]); } foreach ($defaults['enableComponents'] as $key => $name) { $comp = $config->componentRegistry->get($name); if ($comp) { $co = $comp->getConfigObject(); $co->setDefaults($defaults); } } }
/** * Format the url as per language Negotiation. * * @param string $url * * @return string $url, formatted url. * @static */ function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) { if (empty($url)) { return $url; } //upto d6 only, already we have code in place for d7 $config = CRM_Core_Config::singleton(); if (function_exists('variable_get') && module_exists('locale')) { global $language; //get the mode. $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE); //url prefix / path. if (isset($language->prefix) && $language->prefix && in_array($mode, array(LANGUAGE_NEGOTIATION_PATH, LANGUAGE_NEGOTIATION_PATH_DEFAULT))) { if ($addLanguagePart) { $url .= $language->prefix . '/'; } if ($removeLanguagePart) { $url = str_replace("/{$language->prefix}/", '/', $url); } } if (isset($language->domain) && $language->domain && $mode == LANGUAGE_NEGOTIATION_DOMAIN) { if ($addLanguagePart) { $url = CRM_Utils_File::addTrailingSlash($language->domain, '/'); } if ($removeLanguagePart && defined('CIVICRM_UF_BASEURL')) { $url = str_replace('\\', '/', $url); $parseUrl = parse_url($url); //kinda hackish but not sure how to do it right //hope http_build_url() will help at some point. if (is_array($parseUrl) && !empty($parseUrl)) { $urlParts = explode('/', $url); $hostKey = array_search($parseUrl['host'], $urlParts); $ufUrlParts = parse_url(CIVICRM_UF_BASEURL); $urlParts[$hostKey] = $ufUrlParts['host']; $url = implode('/', $urlParts); } } } } return $url; }
/** * @param array $params * @param bool $setInConfig */ public static function retrieveDirectoryAndURLPreferences(&$params, $setInConfig = FALSE) { if (CRM_Core_Config::isUpgradeMode()) { $isJoomla = defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla' ? TRUE : FALSE; // hack to set the resource base url so that js/ css etc is loaded correctly if ($isJoomla) { $params['userFrameworkResourceURL'] = CRM_Utils_File::addTrailingSlash(CIVICRM_UF_BASEURL, '/') . str_replace('administrator', '', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', 'userFrameworkResourceURL', 'value', 'name')); } if (self::isUpgradeFromPreFourOneAlpha1()) { return; } } if ($setInConfig) { $config = CRM_Core_Config::singleton(); } $sql = "\nSELECT name, group_name, value\nFROM civicrm_setting\nWHERE ( group_name = %1\nOR group_name = %2 )\nAND domain_id = %3\n"; $sqlParams = array(1 => array(self::DIRECTORY_PREFERENCES_NAME, 'String'), 2 => array(self::URL_PREFERENCES_NAME, 'String'), 3 => array(CRM_Core_Config::domainID(), 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $sqlParams, TRUE, NULL, FALSE, TRUE, TRUE); if (is_a($dao, 'DB_Error')) { echo "Fatal DB error, exiting, seems like your schema does not have civicrm_setting table\n"; exit; } while ($dao->fetch()) { $value = self::getOverride($dao->group_name, $dao->name, NULL); if ($value === NULL && $dao->value) { $value = unserialize($dao->value); if ($dao->group_name == self::DIRECTORY_PREFERENCES_NAME) { $value = CRM_Utils_File::absoluteDirectory($value); } else { // CRM-7622: we need to remove the language part $value = CRM_Utils_System::absoluteURL($value, TRUE); } } // CRM-10931, If DB doesn't have any value, carry on with any default value thats already available if (!isset($value) && !empty($params[$dao->name])) { $value = $params[$dao->name]; } $params[$dao->name] = $value; if ($setInConfig) { $config->{$dao->name} = $value; } } }
/** * Helper for figuring out menu XML file location. * * @return mixed component's element as class instance * @access private * */ private function _getMenuXMLPath() { global $civicrm_root; $fullpath = $this->namespace . '_' . self::COMPONENT_XML_RESOURCES . '_' . self::COMPONENT_MENU_XML; return CRM_Utils_File::addTrailingSlash($civicrm_root . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $fullpath)); }
/** * Create the base file path from which all our internal directories are * offset. This is derived from the template compile directory set */ public static function baseFilePath() { static $_path = NULL; if (!$_path) { // Note: Don't rely on $config; that creates a dependency loop. if (!defined('CIVICRM_TEMPLATE_COMPILEDIR')) { throw new RuntimeException("Undefined constant: CIVICRM_TEMPLATE_COMPILEDIR"); } $templateCompileDir = CIVICRM_TEMPLATE_COMPILEDIR; $path = dirname($templateCompileDir); //this fix is to avoid creation of upload dirs inside templates_c directory $checkPath = explode(DIRECTORY_SEPARATOR, $path); $cnt = count($checkPath) - 1; if ($checkPath[$cnt] == 'templates_c') { unset($checkPath[$cnt]); $path = implode(DIRECTORY_SEPARATOR, $checkPath); } $_path = CRM_Utils_File::addTrailingSlash($path); } return $_path; }
/** * Format the url as per language Negotiation. * * @param string $url * * @return string $url, formatted url. * @static */ function languageNegotiationURL($url, $addLanguagePart = TRUE, $removeLanguagePart = FALSE) { if (empty($url)) { return $url; } //CRM-7803 -from d7 onward. $config = CRM_Core_Config::singleton(); if (function_exists('variable_get') && module_exists('locale') && function_exists('language_negotiation_get')) { global $language; //does user configuration allow language //support from the URL (Path prefix or domain) if (language_negotiation_get('language') == 'locale-url') { $urlType = variable_get('locale_language_negotiation_url_part'); //url prefix if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) { if (isset($language->prefix) && $language->prefix) { if ($addLanguagePart) { $url .= $language->prefix . '/'; } if ($removeLanguagePart) { $url = str_replace("/{$language->prefix}/", '/', $url); } } } //domain if ($urlType == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN) { if (isset($language->domain) && $language->domain) { if ($addLanguagePart) { $url = CRM_Utils_File::addTrailingSlash($language->domain, '/'); } if ($removeLanguagePart && defined('CIVICRM_UF_BASEURL')) { $url = str_replace('\\', '/', $url); $parseUrl = parse_url($url); //kinda hackish but not sure how to do it right //hope http_build_url() will help at some point. if (is_array($parseUrl) && !empty($parseUrl)) { $urlParts = explode('/', $url); $hostKey = array_search($parseUrl['host'], $urlParts); $ufUrlParts = parse_url(CIVICRM_UF_BASEURL); $urlParts[$hostKey] = $ufUrlParts['host']; $url = implode('/', $urlParts); } } } } } } return $url; }