Merge pull request #8193 from colemanw/scardinius-issue-CRM-16911
[civicrm-core.git] / CRM / Core / Smarty.php
index 9022db85a546f22e84b5584c20fdda80fdbcec80..40b2a91e85985c8cf06de3cfd7bb1b206ce38f3c 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  * $Id$
  *
  */
@@ -97,7 +97,9 @@ class CRM_Core_Smarty extends Smarty {
     else {
       $this->template_dir = $config->templateDir;
     }
-    $this->compile_dir = $config->templateCompileDir;
+    $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
@@ -128,11 +130,14 @@ class CRM_Core_Smarty extends Smarty {
       }
     }
 
+    $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, $config->smartyDir . 'plugins', $config->pluginsDir);
+      $this->plugins_dir = array($customPluginsDir, $smartyDir . 'plugins', $pluginsDir);
     }
     else {
-      $this->plugins_dir = array($config->smartyDir . 'plugins', $config->pluginsDir);
+      $this->plugins_dir = array($smartyDir . 'plugins', $pluginsDir);
     }
 
     // add the session and the config here
@@ -312,4 +317,18 @@ class CRM_Core_Smarty extends Smarty {
     return $this;
   }
 
+  private function getLocale() {
+    global $tsLocale;
+    if (!empty($tsLocale)) {
+      return $tsLocale;
+    }
+
+    $config = CRM_Core_Config::singleton();
+    if (!empty($config->lcMessages)) {
+      return $config->lcMessages;
+    }
+
+    return 'en_US';
+  }
+
 }