PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/functions/smarty2/tlsmarty.inc.php

https://github.com/franciscom/testlink-code-playground
PHP | 306 lines | 177 code | 51 blank | 78 comment | 10 complexity | 42f168c23e5ade3a93af496118042080 MD5 | raw file
  1. <?php
  2. /**
  3. * TestLink Open Source Project - http://testlink.sourceforge.net/
  4. * This script is distributed under the GNU General Public License 2 or later.
  5. *
  6. * TLSmarty class is TestLink wraper for GUI templates processing.
  7. * The class is loaded via common.php to all pages.
  8. *
  9. * @package TestLink
  10. * @author Martin Havlat
  11. * @copyright 2005-2009, TestLink community
  12. * @version CVS: $Id: tlsmarty.inc.php,v 1.1 2010/11/12 21:24:48 franciscom Exp $
  13. * @link http://www.teamst.org/index.php
  14. * @link http://www.smarty.net/
  15. *
  16. * @internal Revisions:
  17. * 20101112 - franciscom - Version that works with Smarty version present on TestLink 1.9
  18. * 20101030 - franciscom - BUGID 3948: Every image link contain a double /
  19. * 20101026 - Julian - BUGID 3930 - Localized dateformat for datepicker
  20. * 20101017 - franciscom - added new image -> import
  21. * reorder of image definition to remove duplicates and use only tlImages
  22. * 20100901 - franciscom - added new image
  23. * 20100621 - eloff - added guard_header_smarty() function
  24. * 20100121 - franciscom - added show_help_icon to remove error on event viewer
  25. * 20090304 - franciscom - removed some MAGIC NUMBERS
  26. * 20081027 - havlatm - moved to include Smarty library
  27. * 20080424 - havlatm - added $tlCfg
  28. */
  29. define('SMARTY_DIR', TL_ABS_PATH . 'third_party'. DIRECTORY_SEPARATOR . 'smarty'.
  30. DIRECTORY_SEPARATOR . 'libs' . DIRECTORY_SEPARATOR);
  31. define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR);
  32. /** include parent extrenal component */
  33. require_once( SMARTY_DIR . 'Smarty.class.php');
  34. /** in this way you can switch ext js version in easy way,
  35. To use a different version of Sencha (Old EXT-JS) that provided with TL */
  36. if( !defined('TL_EXTJS_RELATIVE_PATH') )
  37. {
  38. define('TL_EXTJS_RELATIVE_PATH','third_party/ext-js' );
  39. }
  40. /** @TODO martin: refactore + describe
  41. * The next two functions was moved here from common.php */
  42. function translate_tc_status($status_code)
  43. {
  44. $resultsCfg = config_get('results');
  45. $verbose = lang_get('test_status_not_run');
  46. if( $status_code != '')
  47. {
  48. $suffix = $resultsCfg['code_status'][$status_code];
  49. $verbose = lang_get('test_status_' . $suffix);
  50. }
  51. return $verbose;
  52. }
  53. /**
  54. * function is registered in tlSmarty class
  55. * @uses function translate_tc_status
  56. * @todo should be moved to tlSmarty class
  57. */
  58. function translate_tc_status_smarty($params, &$smarty)
  59. {
  60. $the_ret = translate_tc_status($params['s']);
  61. if( isset($params['var']) )
  62. {
  63. $smarty->assign($params['var'], $the_ret);
  64. }
  65. else
  66. {
  67. return $the_ret;
  68. }
  69. }
  70. /**
  71. * Should be used to prevent certain templates to only get included once per page load.
  72. * For example javascript includes, such as ext-js.
  73. *
  74. * Usage (in template):
  75. * <code>
  76. * {if guard_header_smarty(__FILE__)}
  77. * template code
  78. * <script src="big-library.js type="text/javascript"></script>
  79. * {/if}
  80. * </code>
  81. */
  82. function guard_header_smarty($file)
  83. {
  84. static $guarded = array();
  85. $status_ok = false;
  86. if (!isset($guarded[$file]))
  87. {
  88. $guarded[$file] = true;
  89. $status_ok = true;
  90. }
  91. return $status_ok;
  92. }
  93. /**
  94. * TestLink wrapper for external Smarty class
  95. * @package TestLink
  96. */
  97. class TLSmarty extends Smarty
  98. {
  99. function TLSmarty()
  100. {
  101. global $tlCfg;
  102. global $g_locales_html_select_date_field_order;
  103. global $g_locales_date_format;
  104. global $g_locales_timestamp_format;
  105. parent::__construct();
  106. $this->template_dir = TL_ABS_PATH . 'gui/templates/';
  107. $this->compile_dir = TL_TEMP_PATH;
  108. $this->config_dir = TL_ABS_PATH . 'gui/templates/';
  109. $testproject_coloring = $tlCfg->gui->testproject_coloring;
  110. $testprojectColor = $tlCfg->gui->background_color ; //TL_BACKGROUND_DEFAULT;
  111. if (isset($_SESSION['testprojectColor']))
  112. {
  113. $testprojectColor = $_SESSION['testprojectColor'];
  114. if ($testprojectColor == "")
  115. {
  116. $testprojectColor = $tlCfg->gui->background_color;
  117. }
  118. }
  119. $this->assign('testprojectColor', $testprojectColor);
  120. $my_locale = isset($_SESSION['locale']) ? $_SESSION['locale'] : TL_DEFAULT_LOCALE;
  121. $basehref = isset($_SESSION['basehref']) ? $_SESSION['basehref'] : TL_BASE_HREF;
  122. if ($tlCfg->smarty_debug)
  123. {
  124. $this->debugging = true;
  125. tLog("Smarty debug window = ON");
  126. }
  127. // -------------------------------------------------------------------------------------
  128. // Must be initialized to avoid log on TestLink Event Viewer due to undefined variable.
  129. // This means that optional/missing parameters on include can not be used.
  130. //
  131. // Good refactoring must be done in future, to create group of this variable
  132. // with clear names that must be a hint for developers, to understand where this
  133. // variables are used.
  134. // inc_head.tpl
  135. $this->assign('SP_html_help_file',null);
  136. $this->assign('menuUrl',null);
  137. $this->assign('args',null);
  138. $this->assign('additionalArgs',null);
  139. $this->assign('pageTitle',null);
  140. $this->assign('css_only',null);
  141. $this->assign('body_onload',null);
  142. // inc_attachments.tpl
  143. $this->assign('attach_tableStyles',"font-size:12px");
  144. $this->assign('attach_tableClassName',"simple");
  145. $this->assign('attach_inheritStyle',0);
  146. $this->assign('attach_show_upload_btn',1);
  147. $this->assign('attach_show_title',1);
  148. $this->assign('attach_downloadOnly',false);
  149. // inc_help.tpl
  150. $this->assign('inc_help_alt',null);
  151. $this->assign('inc_help_title',null);
  152. $this->assign('inc_help_style',null);
  153. $this->assign('show_help_icon',true);
  154. $this->assign('tplan_name',null);
  155. $this->assign('name',null);
  156. // -----------------------------------------------------------------------------
  157. $this->assign('basehref', $basehref);
  158. $this->assign('css', $basehref . TL_TESTLINK_CSS);
  159. $this->assign('locale', $my_locale);
  160. // -----------------------------------------------------------------------------
  161. // load configuration
  162. $this->assign('session',isset($_SESSION) ? $_SESSION : null);
  163. $this->assign('tlCfg',$tlCfg);
  164. $this->assign('gsmarty_gui',$tlCfg->gui);
  165. $this->assign('gsmarty_spec_cfg',config_get('spec_cfg'));
  166. $this->assign('gsmarty_attachments',config_get('attachments'));
  167. $this->assign('gsmarty_bugInterfaceOn',config_get('bugInterfaceOn'));
  168. $this->assign('pageCharset',$tlCfg->charset);
  169. $this->assign('tlVersion',TL_VERSION);
  170. $this->assign('testproject_coloring',null);
  171. // -----------------------------------------------------------------------------
  172. // define a select structure for {html_options ...}
  173. $this->assign('gsmarty_option_yes_no', array(0 => lang_get('No'), 1 => lang_get('Yes')));
  174. $this->assign('gsmarty_option_priority', array(HIGH => lang_get('high_priority'),
  175. MEDIUM => lang_get('medium_priority'),
  176. LOW => lang_get('low_priority')));
  177. $this->assign('gsmarty_option_importance', array(HIGH => lang_get('high_importance'),
  178. MEDIUM => lang_get('medium_importance'),
  179. LOW => lang_get('low_importance')));
  180. // this allows unclosed <head> tag to add more information and link; see inc_head.tpl
  181. $this->assign('openHead', 'no');
  182. // there are some variables which should not be assigned for template but must be initialized
  183. // inc_head.tpl
  184. $this->assign('jsValidate', null);
  185. $this->assign('jsTree', null);
  186. $this->assign('editorType', null);
  187. // user feedback variables (used in inc_update.tpl)
  188. $this->assign('user_feedback', null);
  189. $this->assign('feedback_type', ''); // Possibile values: soft
  190. $this->assign('action', 'updated'); //todo: simplify (remove) - use user_feedback
  191. $this->assign('sqlResult', null); //todo: simplify (remove) - use user_feedback
  192. $this->assign('refresh', 'no');
  193. $this->assign('result', null);
  194. $this->assign('optLocale',config_get('locales'));
  195. $this->assign('gsmarty_href_keywordsView',
  196. ' "lib/keywords/keywordsView.php" ' . ' target="mainframe" class="bold" ' .
  197. ' title="' . lang_get('menu_manage_keywords') . '"');
  198. $this->assign('gsmarty_html_select_date_field_order',
  199. $g_locales_html_select_date_field_order[$my_locale]);
  200. $this->assign('gsmarty_date_format',$g_locales_date_format[$my_locale]);
  201. // add smarty variable to be able to set localized date format on datepicker
  202. $this->assign('gsmarty_datepicker_format',
  203. str_replace('%','',$g_locales_date_format[$my_locale]));
  204. $this->assign('gsmarty_timestamp_format',$g_locales_timestamp_format[$my_locale]);
  205. // -----------------------------------------------------------------------------
  206. // Images
  207. $tlImages = array('api_info' => TL_THEME_IMG_DIR . "brick.png",
  208. 'checked' => TL_THEME_IMG_DIR . "apply_f2_16.png",
  209. 'delete' => TL_THEME_IMG_DIR . "trash.png",
  210. 'delete_disabled' => TL_THEME_IMG_DIR . "trash_greyed.png",
  211. 'direct_link' => TL_THEME_IMG_DIR . "world_link.png",
  212. 'edit' => TL_THEME_IMG_DIR . "icon_edit.png",
  213. 'export' => TL_THEME_IMG_DIR . "export.png",
  214. 'export_import' => TL_THEME_IMG_DIR . "export_import.png",
  215. 'import' => TL_THEME_IMG_DIR . "door_in.png",
  216. 'info' => TL_THEME_IMG_DIR . "question.gif",
  217. 'insert_step' => TL_THEME_IMG_DIR . "insert_step.png",
  218. 'reorder' => TL_THEME_IMG_DIR . "arrow_switch.png",
  219. 'sort' => TL_THEME_IMG_DIR . "sort_hint.png",
  220. 'bullet' => TL_THEME_IMG_DIR . "slide_gripper.gif");
  221. $msg = lang_get('show_hide_api_info');
  222. $tlImages['toggle_api_info'] = "<img class=\"clickable\" title=\"{$msg}\" alt=\"{$msg}\" " .
  223. " onclick=\"showHideByClass('span','api_info');event.stopPropagation();\" " .
  224. " src=\"{$tlImages['api_info']}\" align=\"left\" />";
  225. $msg = lang_get('show_hide_direct_link');
  226. $tlImages['toggle_direct_link'] = "<img class=\"clickable\" title=\"{$msg}\" alt=\"{$msg}\" " .
  227. " onclick=\"showHideByClass('div','direct_link');event.stopPropagation();\" " .
  228. " src=\"{$tlImages['direct_link']}\" align=\"left\" />";
  229. // Some useful values for Sort Table Engine
  230. $tlImages['sort_hint'] = '';
  231. switch (TL_SORT_TABLE_ENGINE)
  232. {
  233. case 'kryogenix.org':
  234. $sort_table_by_column = lang_get('sort_table_by_column');
  235. $tlImages['sort_hint'] = "<img title=\"{$sort_table_by_column}\" " .
  236. " alt=\"{$sort_table_by_column}\" " .
  237. " src=\"{$tlImages['sort']}\" align=\"left\" />";
  238. $this->assign("noSortableColumnClass","sorttable_nosort");
  239. break;
  240. default:
  241. $this->assign("noSortableColumnClass",'');
  242. break;
  243. }
  244. // Do not move!!!
  245. $this->assign("tlImages",$tlImages);
  246. // Register functions
  247. $this->register_function("lang_get", "lang_get_smarty");
  248. $this->register_function("localize_date", "localize_date_smarty");
  249. $this->register_function("localize_timestamp", "localize_timestamp_smarty");
  250. $this->register_function("localize_tc_status","translate_tc_status_smarty");
  251. $this->register_modifier("basename","basename");
  252. $this->register_modifier("dirname","dirname");
  253. } // end of function TLSmarty()
  254. } // end of class TLSmarty
  255. ?>