Merge pull request #8193 from colemanw/scardinius-issue-CRM-16911
[civicrm-core.git] / CRM / Core / Smarty.php
index fb84a6c1a9d6f216366b350199e39a0e3a4b12a8..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
@@ -315,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';
+  }
+
 }