static function getNavigationMenu() {
$contactID = CRM_Core_Session::singleton()->get('userID');
if ($contactID) {
- // Set headers to encourage browsers to cache for a long time
- $year = 60*60*24*364;
- header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + $year));
- header('Content-Type: application/javascript');
- header("Cache-Control: max-age=$year, public");
-
+ CRM_Core_Page_AJAX::setJsHeaders();
print CRM_Core_Smarty::singleton()->fetchWith('CRM/common/navigation.js.tpl', array(
'navigation' => CRM_Core_BAO_Navigation::createNavigation($contactID),
));
// Reset navigation
CRM_Core_BAO_Navigation::resetNavigation();
// Clear js localization
- CRM_Core_Resources::singleton()->flushStrings()->rebuildDynamicResources();
+ CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode();
}
return TRUE;
CRM_Core_BAO_Setting::updateSettingsFromMetaData();
// Clear js caches
- CRM_Core_Resources::singleton()->flushStrings()->rebuildDynamicResources();
+ CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode();
CRM_Case_XMLRepository::singleton(TRUE);
// also rebuild triggers if requested explicitly
CRM_Utils_System::civiExit();
}
+ /**
+ * Set headers appropriate for a js file
+ */
+ static function setJsHeaders() {
+ // Encourage browsers to cache for a long time - 1 year
+ $year = 60*60*24*364;
+ header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + $year));
+ header('Content-Type: application/javascript');
+ header("Cache-Control: max-age=$year, public");
+ }
+
/**
* Send autocomplete results to the client. Input can be a simple or nested array.
* @param array $results - If nested array, also provide:
}
// Dynamic localization script
- $this->addScriptUrl($this->addLocalizationJs(), $jsWeight++, $region);
+ $this->addScriptUrl(CRM_Utils_System::url('civicrm/ajax/l10n-js/' . $config->lcMessages, array('r' => $this->getCacheCode())), $jsWeight++, $region);
// Add global settings
$settings = array('config' => array(
return $this;
}
- /**
- * Deletes and rebuilds dynamic resource files
- * @return CRM_Core_Resources
- */
- public function rebuildDynamicResources() {
- CRM_Utils_File::flushDynamicResources();
- $this->addLocalizationJs();
- return $this;
- }
-
/**
* Translate strings in a javascript file
*
$this->addString($stringsByFile[$file]);
}
- /**
- * Add dynamic l10n js
- *
- * @return string URL of JS file
- */
- private function addLocalizationJs() {
- $config = CRM_Core_Config::singleton();
- $fileName = 'l10n-' . $config->lcMessages . '.js';
- if (!is_file(CRM_Utils_File::dynamicResourcePath($fileName))) {
- CRM_Utils_File::addDynamicResource($fileName, $this->createLocalizationJs());
- }
- // Dynamic localization script
- return CRM_Utils_File::dynamicResourceUrl($fileName);
- }
-
/**
* Create dynamic script for localizing js widgets
*
* @return string javascript content
*/
- private function createLocalizationJs() {
+ static function outputLocalizationJS() {
+ CRM_Core_Page_AJAX::setJsHeaders();
$config = CRM_Core_Config::singleton();
$vars = array(
'moneyFormat' => json_encode(CRM_Utils_Money::format(1234.56)),
'otherSearch' => json_encode(ts('Enter search term...')),
'contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks(),
);
- return CRM_Core_Smarty::singleton()->fetchWith('CRM/common/localization.js.tpl', $vars);
+ print CRM_Core_Smarty::singleton()->fetchWith('CRM/common/localization.js.tpl', $vars);
+ CRM_Utils_System::civiExit();
}
/**
<page_callback>CRM_Core_Page_Angular</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
+ <item>
+ <path>civicrm/ajax/l10n-js</path>
+ <page_callback>CRM_Core_Resources::outputLocalizationJS</page_callback>
+ </item>
</menu>
}
// All cached content needs to be cleared because the civi codebase was just replaced
- CRM_Core_Resources::singleton()->flushStrings()->rebuildDynamicResources();
+ CRM_Core_Resources::singleton()->flushStrings()->resetCacheCode();
+ CRM_Core_Menu::store();
// This could be removed in later rev
if ($currentVer == '2.1.6') {
}
return TRUE;
}
-
- /**
- * Create a static file (e.g. css or js) in the dynamic resource directory
- * Note: if the file already exists it will be overwritten
- * @param string $fileName
- * @param string $contents
- */
- static function addDynamicResource($fileName, $contents) {
- // First ensure the directory exists
- $path = self::dynamicResourcePath();
- if (!is_dir($path)) {
- self::createDir($path);
- self::restrictBrowsing($path);
- }
- file_put_contents("$path/$fileName", $contents);
- }
-
- /**
- * Get the path of a dynamic resource file
- * With no fileName supplied, returns the path of the directory
- * @param string $fileName
- * @return string
- */
- static function dynamicResourcePath($fileName = NULL) {
- $config = CRM_Core_Config::singleton();
- // FIXME: Use self::baseFilePath once url issue has been resolved
- // Windows PHP accepts any mix of "/" or "\"; simpler if we only deal with one of those
- $imageUploadDir = str_replace('\\', '/', $config->imageUploadDir);
- $path = self::addTrailingSlash(str_replace('/persist/contribute', '', $imageUploadDir), '/') . 'dynamic';
- if ($fileName !== NULL) {
- $path .= "/$fileName";
- }
- return $path;
- }
-
- /**
- * Get the URL of a dynamic resource file
- * @param string $fileName
- * @return string
- */
- static function dynamicResourceUrl($fileName, $addCacheCode = TRUE) {
- $config = CRM_Core_Config::singleton();
- // FIXME: Need a better way of getting the url of the baseFilePath
- $url = self::addTrailingSlash(str_replace('/persist/contribute', '', $config->imageUploadURL), '/') . 'dynamic/' . $fileName;
- if ($addCacheCode) {
- return $url . '?r=' . CRM_Core_Resources::singleton()->getCacheCode();
- }
- return $url;
- }
-
- /**
- * Delete all files from the dynamic resource directory
- * Change the cache code to force browsers to reload new resources
- */
- static function flushDynamicResources() {
- $files = glob(self::dynamicResourcePath('*'));
- foreach ($files ? $files : array() as $file) {
- if (is_file($file)) {
- unlink($file);
- }
- }
- CRM_Core_Resources::singleton()->resetCacheCode();
- }
}