PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/drupal/sites/all/modules/civicrm/CRM/Core/Smarty.php

https://github.com/michaelmcandrew/ste
PHP | 205 lines | 103 code | 31 blank | 71 comment | 25 complexity | cef100a8974251c6994e9a6c82dab647 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.4 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2011 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  10. | CiviCRM is free software; you can copy, modify, and distribute it |
  11. | under the terms of the GNU Affero General Public License |
  12. | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
  13. | |
  14. | CiviCRM is distributed in the hope that it will be useful, but |
  15. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  17. | See the GNU Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU Affero General Public |
  20. | License and the CiviCRM Licensing Exception along |
  21. | with this program; if not, contact CiviCRM LLC |
  22. | at info[AT]civicrm[DOT]org. If you have questions about the |
  23. | GNU Affero General Public License or the licensing of CiviCRM, |
  24. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  25. +--------------------------------------------------------------------+
  26. */
  27. /**
  28. *
  29. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2011
  31. * $Id$
  32. *
  33. */
  34. require_once 'CRM/Utils/Recent.php';
  35. /**
  36. * Fix for bug CRM-392. Not sure if this is the best fix or it will impact
  37. * other similar PEAR packages. doubt it
  38. */
  39. if ( ! class_exists( 'Smarty' ) ) {
  40. require_once 'Smarty/Smarty.class.php';
  41. }
  42. /**
  43. *
  44. */
  45. class CRM_Core_Smarty extends Smarty {
  46. const
  47. PRINT_PAGE = 1,
  48. PRINT_SNIPPET = 2,
  49. PRINT_PDF = 3,
  50. PRINT_NOFORM = 4;
  51. /**
  52. * We only need one instance of this object. So we use the singleton
  53. * pattern and cache the instance in this variable
  54. *
  55. * @var object
  56. * @static
  57. */
  58. static private $_singleton = null;
  59. /**
  60. * class constructor
  61. *
  62. * @return CRM_Core_Smarty
  63. * @access private
  64. */
  65. function __construct( ) {
  66. parent::__construct( );
  67. $config = CRM_Core_Config::singleton( );
  68. if ( isset( $config->customTemplateDir ) && $config->customTemplateDir ) {
  69. $this->template_dir = array_merge( array( $config->customTemplateDir ),
  70. $config->templateDir );
  71. } else {
  72. $this->template_dir = $config->templateDir;
  73. }
  74. $this->compile_dir = $config->templateCompileDir;
  75. //Check for safe mode CRM-2207
  76. if ( ini_get('safe_mode') ) {
  77. $this->use_sub_dirs = false;
  78. } else {
  79. $this->use_sub_dirs = true;
  80. }
  81. $customPluginsDir = null;
  82. if ( isset( $config->customPHPPathDir ) ) {
  83. $customPluginsDir =
  84. $config->customPHPPathDir . DIRECTORY_SEPARATOR .
  85. 'CRM' . DIRECTORY_SEPARATOR .
  86. 'Core' . DIRECTORY_SEPARATOR .
  87. 'Smarty' . DIRECTORY_SEPARATOR .
  88. 'plugins' . DIRECTORY_SEPARATOR ;
  89. if ( ! file_exists( $customPluginsDir ) ) {
  90. $customPluginsDir = null;
  91. }
  92. }
  93. if ( $customPluginsDir ) {
  94. $this->plugins_dir = array ( $customPluginsDir, $config->smartyDir . 'plugins', $config->pluginsDir );
  95. } else {
  96. $this->plugins_dir = array ( $config->smartyDir . 'plugins', $config->pluginsDir );
  97. }
  98. // add the session and the config here
  99. $session = CRM_Core_Session::singleton();
  100. $this->assign_by_ref( 'config' , $config );
  101. $this->assign_by_ref( 'session' , $session );
  102. // check default editor and assign to template, store it in session to reduce db calls
  103. $defaultWysiwygEditor = $session->get( 'defaultWysiwygEditor');
  104. if ( !$defaultWysiwygEditor && !CRM_Core_Config::isUpgradeMode() ) {
  105. require_once 'CRM/Core/BAO/Preferences.php';
  106. $defaultWysiwygEditor = CRM_Core_BAO_Preferences::value( 'editor_id' );
  107. $session->set( 'defaultWysiwygEditor', $defaultWysiwygEditor );
  108. }
  109. $this->assign( 'defaultWysiwygEditor', $defaultWysiwygEditor );
  110. global $tsLocale;
  111. $this->assign('tsLocale', $tsLocale);
  112. // CRM-7163 hack: we don’t display langSwitch on upgrades anyway
  113. if ( CRM_Utils_Array::value( $config->userFrameworkURLVar, $_REQUEST ) != 'civicrm/upgrade' ) {
  114. $this->assign('langSwitch', CRM_Core_I18n::languages(true));
  115. }
  116. //check if logged in use has access CiviCRM permission and build menu
  117. require_once 'CRM/Core/Permission.php';
  118. $buildNavigation = CRM_Core_Permission::check( 'access CiviCRM' );
  119. $this->assign('buildNavigation', $buildNavigation );
  120. if ( !CRM_Core_Config::isUpgradeMode() && $buildNavigation ) {
  121. require_once 'CRM/Core/BAO/Navigation.php';
  122. $contactID = $session->get('userID');
  123. if ( $contactID ) {
  124. $navigation =& CRM_Core_BAO_Navigation::createNavigation( $contactID );
  125. $this->assign('navigation', $navigation );
  126. }
  127. }
  128. $this->register_function ( 'crmURL' , array( 'CRM_Utils_System', 'crmURL' ) );
  129. }
  130. /**
  131. * Static instance provider.
  132. *
  133. * Method providing static instance of SmartTemplate, as
  134. * in Singleton pattern.
  135. */
  136. static function &singleton( ) {
  137. if ( ! isset( self::$_singleton ) ) {
  138. $config = CRM_Core_Config::singleton( );
  139. self::$_singleton = new CRM_Core_Smarty( $config->templateDir, $config->templateCompileDir );
  140. }
  141. return self::$_singleton;
  142. }
  143. /**
  144. * executes & returns or displays the template results
  145. *
  146. * @param string $resource_name
  147. * @param string $cache_id
  148. * @param string $compile_id
  149. * @param boolean $display
  150. */
  151. function fetch($resource_name, $cache_id = null, $compile_id = null, $display = false)
  152. {
  153. require_once 'CRM/Core/Menu.php';
  154. return parent::fetch( $resource_name, $cache_id, $compile_id, $display );
  155. }
  156. function appendValue( $name, $value ) {
  157. $currentValue = $this->get_template_vars( $name );
  158. if ( ! $currentValue ) {
  159. $this->assign( $name, $value );
  160. } else {
  161. if ( strpos( $currentValue, $value ) === false ) {
  162. $this->assign( $name, $currentValue . $value );
  163. }
  164. }
  165. }
  166. function clearTemplateVars( ) {
  167. foreach ( array_keys( $this->_tpl_vars ) as $key ) {
  168. if ( $key == 'config' || $key == 'session' ) {
  169. continue;
  170. }
  171. unset( $this->_tpl_vars[$key] );
  172. }
  173. }
  174. }