customTemplateDir) && $config->customTemplateDir) { $this->template_dir = array_merge(array($config->customTemplateDir), $config->templateDir ); } else { $this->template_dir = $config->templateDir; } $this->compile_dir = $config->templateCompileDir; // 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; } } if ($customPluginsDir) { $this->plugins_dir = array($customPluginsDir, $config->smartyDir . 'plugins', $config->pluginsDir); } else { $this->plugins_dir = array($config->smartyDir . 'plugins', $config->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); // check default editor and assign to template $defaultWysiwygEditor = $session->get('defaultWysiwygEditor'); if (!$defaultWysiwygEditor && !CRM_Core_Config::isUpgradeMode()) { $defaultWysiwygEditor = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id' ); // For logged-in users, store it in session to reduce db calls if ($session->get('userID')) { $session->set('defaultWysiwygEditor', $defaultWysiwygEditor); } } $this->assign('defaultWysiwygEditor', $defaultWysiwygEditor); 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')); } /** * Static instance provider. * * Method providing static instance of SmartTemplate, as * in Singleton pattern. */ static function &singleton() { if (!isset(self::$_singleton)) { self::$_singleton = new CRM_Core_Smarty( ); self::$_singleton->initialize( ); self::registerStringResource(); } return self::$_singleton; } /** * executes & returns or displays the template results * * @param string $resource_name * @param string $cache_id * @param string $compile_id * @param boolean $display */ function fetch($resource_name, $cache_id = NULL, $compile_id = NULL, $display = FALSE) { return parent::fetch($resource_name, $cache_id, $compile_id, $display); } function appendValue($name, $value) { $currentValue = $this->get_template_vars($name); if (!$currentValue) { $this->assign($name, $value); } else { if (strpos($currentValue, $value) === FALSE) { $this->assign($name, $currentValue . $value); } } } function clearTemplateVars() { foreach (array_keys($this->_tpl_vars) as $key) { if ($key == 'config' || $key == 'session') { continue; } unset($this->_tpl_vars[$key]); } } static function registerStringResource() { require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); } function addTemplateDir($path) { if ( is_array( $this->template_dir ) ) { array_unshift( $this->template_dir, $path ); } else { $this->template_dir = array( $path, $this->template_dir ); } } }