version fixes
[civicrm-core.git] / CRM / Core / Resources.php
index d12afab2d06dbc48d90a69ccd4b38fcc4a7bde40..f5f57cfd4c6195c2934672ead91cef2b89691366 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
   +--------------------------------------------------------------------+
-  | CiviCRM version 4.6                                                |
+  | CiviCRM version 4.7                                                |
   +--------------------------------------------------------------------+
   | Copyright CiviCRM LLC (c) 2004-2015                                |
   +--------------------------------------------------------------------+
@@ -195,13 +195,7 @@ class CRM_Core_Resources {
       $domain = ($translate === TRUE) ? $ext : $translate;
       $this->addString($this->strings->get($domain, $this->getPath($ext, $file), 'text/javascript'), $domain);
     }
-    // Look for non-minified version if we are in debug mode
-    if (CRM_Core_Config::singleton()->debug && strpos($file, '.min.js') !== FALSE) {
-      $nonMiniFile = str_replace('.min.js', '.js', $file);
-      if ($this->getPath($ext, $nonMiniFile)) {
-        $file = $nonMiniFile;
-      }
-    }
+    $this->resolveFileName($file, $ext);
     return $this->addScriptUrl($this->getUrl($ext, $file, TRUE), $weight, $region);
   }
 
@@ -416,6 +410,7 @@ class CRM_Core_Resources {
    * @return CRM_Core_Resources
    */
   public function addStyleFile($ext, $file, $weight = self::DEFAULT_WEIGHT, $region = self::DEFAULT_REGION) {
+    $this->resolveFileName($file, $ext);
     return $this->addStyleUrl($this->getUrl($ext, $file, TRUE), $weight, $region);
   }
 
@@ -587,14 +582,17 @@ class CRM_Core_Resources {
 
       // Add resources from coreResourceList
       $jsWeight = -9999;
-      foreach ($this->coreResourceList() as $file) {
-        if (substr($file, -2) == 'js') {
+      foreach ($this->coreResourceList($region) as $item) {
+        if (is_array($item)) {
+          $this->addSetting($item);
+        }
+        elseif (substr($item, -2) == 'js') {
           // Don't bother  looking for ts() calls in packages, there aren't any
-          $translate = (substr($file, 0, 3) == 'js/');
-          $this->addScriptFile('civicrm', $file, $jsWeight++, $region, $translate);
+          $translate = (substr($item, 0, 3) == 'js/');
+          $this->addScriptFile('civicrm', $item, $jsWeight++, $region, $translate);
         }
         else {
-          $this->addStyleFile('civicrm', $file, -100, $region);
+          $this->addStyleFile('civicrm', $item, -100, $region);
         }
       }
 
@@ -685,52 +683,53 @@ class CRM_Core_Resources {
   /**
    * List of core resources we add to every CiviCRM page.
    *
+   * Note: non-compressed versions of .min files will be used in debug mode
+   *
+   * @param string $region
    * @return array
    */
-  public function coreResourceList() {
+  public function coreResourceList($region) {
     $config = CRM_Core_Config::singleton();
-    // Use minified files for production, uncompressed in debug mode
-    // Note, $this->addScriptFile would automatically search for the non-minified file in debug mode but this is probably faster
-    $min = $config->debug ? '' : '.min';
 
     // Scripts needed by everyone, everywhere
     // FIXME: This is too long; list needs finer-grained segmentation
     $items = array(
       "bower_components/jquery/dist/jquery.min.js",
       "bower_components/jquery-ui/jquery-ui.min.js",
-      "bower_components/jquery-ui/themes/smoothness/jquery-ui$min.css",
+      "bower_components/jquery-ui/themes/smoothness/jquery-ui.min.css",
       "bower_components/lodash-compat/lodash.min.js",
-      "packages/jquery/plugins/jquery.mousewheel$min.js",
-      "bower_components/select2/select2$min.js",
-      "bower_components/select2/select2$min.css",
+      "packages/jquery/plugins/jquery.mousewheel.min.js",
+      "bower_components/select2/select2.min.js",
+      "bower_components/select2/select2.min.css",
       "packages/jquery/plugins/jquery.tableHeader.js",
-      "packages/jquery/plugins/jquery.form$min.js",
-      "packages/jquery/plugins/jquery.timeentry$min.js",
-      "packages/jquery/plugins/jquery.blockUI$min.js",
-      "bower_components/datatables/media/js/jquery.dataTables$min.js",
-      "bower_components/datatables/media/css/jquery.dataTables$min.css",
-      "bower_components/jquery-validation/dist/jquery.validate$min.js",
-      "packages/jquery/plugins/jquery.ui.datepicker.validation.pack.js",
+      "packages/jquery/plugins/jquery.form.min.js",
+      "packages/jquery/plugins/jquery.timeentry.min.js",
+      "packages/jquery/plugins/jquery.blockUI.min.js",
+      "bower_components/datatables/media/js/jquery.dataTables.min.js",
+      "bower_components/datatables/media/css/jquery.dataTables.min.css",
+      "bower_components/jquery-validation/dist/jquery.validate.min.js",
+      "packages/jquery/plugins/jquery.ui.datepicker.validation.min.js",
       "js/Common.js",
       "js/crm.ajax.js",
     );
     // add wysiwyg editor
-    $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id');
-    $editor = CRM_Utils_Array::value($editorID,
-      CRM_Core_OptionGroup::values('wysiwyg_editor', FALSE, FALSE, FALSE, NULL, 'name')
-    );
+    $editor = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id');
     $items[] = "js/wysiwyg/crm.wysiwyg.js";
     if ($editor == "CKEditor") {
       $items[] = "bower_components/ckeditor/ckeditor.js";
       $items[] = "js/wysiwyg/crm.ckeditor.js";
+      $ckConfig = CRM_Admin_Page_CKEditorConfig::getConfigUrl();
+      if ($ckConfig) {
+        $items[] = array('config' => array('CKEditorCustomConfig' => $ckConfig));
+      }
     }
 
     // These scripts are only needed by back-office users
     if (CRM_Core_Permission::check('access CiviCRM')) {
-      $items[] = "packages/jquery/plugins/jquery.menu$min.js";
+      $items[] = "packages/jquery/plugins/jquery.menu.min.js";
       $items[] = "css/navigation.css";
-      $items[] = "packages/jquery/plugins/jquery.jeditable$min.js";
-      $items[] = "packages/jquery/plugins/jquery.notify$min.js";
+      $items[] = "packages/jquery/plugins/jquery.jeditable.min.js";
+      $items[] = "packages/jquery/plugins/jquery.notify.min.js";
       $items[] = "js/jquery/jquery.crmeditable.js";
     }
 
@@ -758,8 +757,8 @@ class CRM_Core_Resources {
       }
     }
 
-    // CMS-specific resources
-    $config->userSystem->appendCoreResources($items);
+    // Allow hooks to modify this list
+    CRM_Utils_Hook::coreResourceList($items, $region);
 
     return $items;
   }
@@ -817,4 +816,19 @@ class CRM_Core_Resources {
     return $filters;
   }
 
+  /**
+   * In debug mode, look for a non-minified version of this file
+   *
+   * @param string $fileName
+   * @param string $extName
+   */
+  private function resolveFileName(&$fileName, $extName) {
+    if (CRM_Core_Config::singleton()->debug && strpos($fileName, '.min.') !== FALSE) {
+      $nonMiniFile = str_replace('.min.', '.', $fileName);
+      if ($this->getPath($extName, $nonMiniFile)) {
+        $fileName = $nonMiniFile;
+      }
+    }
+  }
+
 }