Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 /**
  * AJAX callback to fetch examples.
  */
 public static function getExampleFile()
 {
     if (!empty($_GET['entity']) && strpos($_GET['entity'], '.') === FALSE) {
         $examples = array();
         foreach (scandir(\Civi::paths()->getPath("[civicrm.root]/api/v3/examples/{$_GET['entity']}")) as $item) {
             $item = str_replace('.php', '', $item);
             if ($item && strpos($item, '.') === FALSE) {
                 $examples[] = array('key' => $item, 'value' => $item);
             }
         }
         CRM_Utils_JSON::output($examples);
     }
     if (!empty($_GET['file']) && strpos($_GET['file'], '.') === FALSE) {
         $fileName = \Civi::paths()->getPath("[civicrm.root]/api/v3/examples/{$_GET['file']}.php");
         if (file_exists($fileName)) {
             echo file_get_contents($fileName);
         } else {
             echo "Not found.";
         }
         CRM_Utils_System::civiExit();
     }
     CRM_Utils_System::permissionDenied();
 }
Ejemplo n.º 3
0
 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})");
     }
 }
Ejemplo n.º 4
0
 /**
  * Determine whether the value contains a valid reference to a directory.
  *
  * Paths stored in the setting system may be absolute -- or may be
  * relative to the default data directory.
  *
  * @param string $path
  * @return bool
  */
 public static function settingPath($path)
 {
     return is_dir(Civi::paths()->getPath($path));
 }
Ejemplo n.º 5
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->localVersion = CRM_Utils_System::version();
     $this->localMajorVersion = $this->getMajorVersion($this->localVersion);
     $this->cacheFile = Civi::paths()->getPath(self::CACHEFILE_NAME);
 }
Ejemplo n.º 6
0
 /**
  * Construct a resource manager.
  *
  * @param CRM_Extension_Mapper $extMapper
  *   Map extension names to their base path or URLs.
  * @param CRM_Utils_Cache_Interface $cache
  *   JS-localization cache.
  * @param string|null $cacheCodeKey Random code to append to resource URLs; changing the code forces clients to reload resources
  */
 public function __construct($extMapper, $cache, $cacheCodeKey = NULL)
 {
     $this->extMapper = $extMapper;
     $this->strings = new CRM_Core_Resources_Strings($cache);
     $this->cacheCodeKey = $cacheCodeKey;
     if ($cacheCodeKey !== NULL) {
         $this->cacheCode = Civi::settings()->get($cacheCodeKey);
     }
     if (!$this->cacheCode) {
         $this->resetCacheCode();
     }
     $this->ajaxPopupsEnabled = (bool) Civi::settings()->get('ajaxPopupsEnabled');
     $this->paths = Civi::paths();
 }
Ejemplo n.º 7
0
 /**
  * Include custom PHP and template paths
  */
 public function includeCustomPath()
 {
     $customProprtyName = array('customPHPPathDir', 'customTemplateDir');
     foreach ($customProprtyName as $property) {
         $value = $this->getSettings()->get($property);
         if (!empty($value)) {
             $customPath = Civi::paths()->getPath($value);
             set_include_path($customPath . PATH_SEPARATOR . get_include_path());
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * @param bool $checkIfFileExists
  *   If false, this fn will return fileName even if it doesn't exist
  *
  * @return null|string
  */
 public static function getConfigFile($checkIfFileExists = TRUE)
 {
     $fileName = Civi::paths()->getPath(self::CONFIG_FILENAME);
     return !$checkIfFileExists || is_file($fileName) ? $fileName : NULL;
 }