template.lib.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // Load Smarty library
  4. require_once api_get_path(LIBRARY_PATH).'smarty/Smarty.class.php';
  5. class Template extends Smarty {
  6. var $style = 'default'; //see the template folder
  7. var $show_header;
  8. var $show_footer;
  9. function __construct($title = '', $show_header = true, $show_footer = true) {
  10. $this->title = $title;
  11. //Smarty 3 configuration
  12. $this->setPluginsDir(api_get_path(LIBRARY_PATH).'smarty/plugins');
  13. $this->setCacheDir(api_get_path(SYS_ARCHIVE_PATH));
  14. $this->setCompileDir(api_get_path(SYS_ARCHIVE_PATH));
  15. $this->setTemplateDir(api_get_path(SYS_CODE_PATH).'template/');
  16. $this->setConfigDir(api_get_path(SYS_ARCHIVE_PATH));
  17. //Caching settings
  18. $this->caching = true;
  19. //$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
  20. $this->cache_lifetime = Smarty::CACHING_OFF; // no caching
  21. //$this->cache_lifetime = 120;
  22. //By default we show the header and footer
  23. $this->set_footer($show_footer);
  24. $this->set_header($show_header);
  25. $this->set_system_parameters();
  26. $this->set_user_parameters();
  27. //Creating a Smarty modifier - Now we can call the get_lang from a template!!! Just use {"MyString"|get_lang}
  28. $this->registerPlugin("modifier","get_lang", "get_lang");
  29. $this->registerPlugin("modifier","get_path", "api_get_path");
  30. $this->registerPlugin("modifier","get_setting", "api_get_setting");
  31. //To load a smarty plugin
  32. //$this->loadPlugin('smarty_function_get_lang');
  33. //$this->testInstall();
  34. $this->set_header_parameters();
  35. $this->set_footer_parameters();
  36. $this->assign('style', $this->style);
  37. }
  38. /**
  39. * Shortcut to display a 1 col layout
  40. * */
  41. function display_one_col_template() {
  42. $tpl = $this->get_template('layout/layout_1_col.tpl');
  43. $this->display($tpl);
  44. }
  45. /**
  46. * Shortcut to display a 2 col layout
  47. * */
  48. function display_two_col_template() {
  49. $tpl = $this->get_template('layout/layout_2_col.tpl');
  50. $this->display($tpl);
  51. }
  52. /**
  53. * Displays an empty template
  54. */
  55. function display_blank_template() {
  56. $tpl = $this->get_template('layout/blank.tpl');
  57. $this->display($tpl);
  58. }
  59. /**
  60. * Displays an empty template
  61. */
  62. function display_no_layout_template() {
  63. $tpl = $this->get_template('layout/no_layout.tpl');
  64. $this->display($tpl);
  65. }
  66. /**
  67. * Sets the footer visibility
  68. * @param bool true if we show the footer
  69. */
  70. function set_footer($status) {
  71. $this->show_footer = $status;
  72. $this->assign('show_footer', $status);
  73. }
  74. /**
  75. * Sets the header visibility
  76. *
  77. */
  78. function set_header($status) {
  79. $this->show_header = $status;
  80. $this->assign('show_header', $status);
  81. }
  82. function get_template($name) {
  83. return $this->style.'/'.$name;
  84. }
  85. private function set_user_parameters() {
  86. $user_info = array();
  87. $user_info['logged'] = 0;
  88. if (api_get_user_id() && !api_is_anonymous()) {
  89. $user_info = api_get_user_info();
  90. $user_info['logged'] = 1;
  91. $user_info['messages_count'] = MessageManager::get_new_messages();
  92. }
  93. $this->assign('_u', $user_info);
  94. }
  95. private function set_system_parameters() {
  96. global $_configuration;
  97. //Setting app paths
  98. $_p = array('web' => api_get_path(WEB_PATH),
  99. 'web_course' => api_get_path(WEB_COURSE_PATH),
  100. 'web_main' => api_get_path(WEB_CODE_PATH),
  101. 'web_ajax' => api_get_path(WEB_AJAX_PATH),
  102. );
  103. $this->assign('_p', $_p);
  104. //Here we can add system parameters that can be use in any template
  105. $_s = array(
  106. 'software_name' => $_configuration['software_name'],
  107. 'system_version' => $_configuration['system_version'],
  108. 'site_name' => api_get_setting('siteName'),
  109. 'institution' => api_get_setting('Institution'),
  110. );
  111. $this->assign('_s', $_s);
  112. }
  113. private function set_header_parameters($help = null) {
  114. $nameTools = $this->title;
  115. global $_plugins, $lp_theme_css, $mycoursetheme, $user_theme, $platform_theme;
  116. global $httpHeadXtra, $htmlHeadXtra, $_course, $_user, $text_dir, $plugins, $_user,
  117. $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  118. global $menu_navigation;
  119. global $_configuration, $show_learn_path;
  120. $this->assign('system_charset', api_get_system_encoding());
  121. if (isset($httpHeadXtra) && $httpHeadXtra) {
  122. foreach ($httpHeadXtra as & $thisHttpHead) {
  123. header($thisHttpHead);
  124. }
  125. }
  126. // Get language iso-code for this page - ignore errors
  127. $this->assign('document_language', api_get_language_isocode());
  128. $course_title = $_course['name'];
  129. $title_list[] = api_get_setting('Institution');
  130. $title_list[] = api_get_setting('siteName');
  131. if (!empty($course_title)) {
  132. $title_list[] = $course_title;
  133. }
  134. if ($nameTools != '') {
  135. $title_list[] = $nameTools;
  136. }
  137. $title_string = '';
  138. for($i=0; $i<count($title_list);$i++) {
  139. $title_string .=$title_list[$i];
  140. if (isset($title_list[$i+1])) {
  141. $item = trim($title_list[$i+1]);
  142. if (!empty($item))
  143. $title_string .=' - ';
  144. }
  145. }
  146. $this->assign('title_string', $title_string);
  147. $platform_theme = api_get_setting('stylesheets');
  148. $my_style = api_get_visual_theme();
  149. $style = '';
  150. //Base CSS
  151. $style = '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
  152. //Default CSS
  153. $style .= '@import "'.api_get_path(WEB_CSS_PATH).$my_style.'/default.css";';
  154. //Course CSS
  155. $style .= '@import "'.api_get_path(WEB_CSS_PATH).$my_style.'/course.css";';
  156. if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
  157. $style .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } ';
  158. }
  159. $this->assign('css_style', $style);
  160. $style_print = '@import "'.api_get_path(WEB_CSS_PATH).$my_style.'/print.css";';
  161. $this->assign('css_style_print', $style_print);
  162. $js_files = array(
  163. 'jquery.min.js',
  164. 'chosen/chosen.jquery.min.js',
  165. 'thickbox.js',
  166. 'jquery.menu.js',
  167. 'dtree/dtree.js',
  168. 'email_links.lib.js.php',
  169. 'bootstrap/bootstrap-dropdown.js'
  170. );
  171. if (api_get_setting('accessibility_font_resize') == 'true') {
  172. $js_files[] = 'fontresize.js';
  173. }
  174. if (api_get_setting('include_asciimathml_script') == 'true') {
  175. $js_files[] = 'asciimath/ASCIIMathML.js';
  176. }
  177. $js_file_to_string = '';
  178. foreach($js_files as $js_file) {
  179. $js_file_to_string .= api_get_js($js_file);
  180. }
  181. $css_files = array (
  182. api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css',
  183. api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css',
  184. api_get_path(WEB_LIBRARY_PATH).'javascript/dtree/dtree.css',
  185. );
  186. if ($show_learn_path) {
  187. $css_files[] = api_get_path(WEB_CSS_PATH).$my_style.'/learnpath.css';
  188. }
  189. $css_file_to_string = '';
  190. foreach($css_files as $css_file) {
  191. $css_file_to_string .= api_get_css($css_file);
  192. }
  193. $this->assign('css_file_to_string', $css_file_to_string);
  194. $this->assign('js_file_to_string', $js_file_to_string);
  195. $this->assign('text_direction', api_get_text_direction());
  196. $this->assign('style_print', $style_print);
  197. $extra_headers = '';
  198. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  199. foreach ($htmlHeadXtra as & $this_html_head) {
  200. $extra_headers .= $this_html_head;
  201. }
  202. }
  203. $this->assign('extra_headers', $extra_headers);
  204. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  205. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  206. $access_url_id = api_get_current_access_url_id();
  207. if ($access_url_id != -1) {
  208. $url_info = api_get_access_url($access_url_id);
  209. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  210. $clean_url = replace_dangerous_char($url);
  211. $clean_url = str_replace('/', '-', $clean_url);
  212. $clean_url .= '/';
  213. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  214. //we create the new dir for the new sites
  215. if (is_file($homep.'favicon.ico')) {
  216. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  217. }
  218. }
  219. }
  220. $this->assign('favico', $favico);
  221. //old banner.inc.php
  222. require_once api_get_path(LIBRARY_PATH).'banner.lib.php';
  223. global $my_session_id;
  224. $session_id = api_get_session_id();
  225. $session_name = api_get_session_name($my_session_id);
  226. $help_content = '';
  227. if (api_get_setting('enable_help_link') == 'true') {
  228. if (!empty($help)) {
  229. $help = Security::remove_XSS($help);
  230. $help_content = '<li class="help">';
  231. $help_content .= '<a href="'.api_get_path(WEB_CODE_PATH).'help/help.php?open='.$help.'&height=400&width=600" class="thickbox" title="'.get_lang('Help').'">';
  232. $help_content .= '<img src="'.api_get_path(WEB_IMG_PATH).'help.large.png" alt="'.get_lang('Help').'" title="'.get_lang('Help').'" />';
  233. $help_content .= '</a></li>';
  234. }
  235. }
  236. $this->assign('help_content', $help_content);
  237. $bug_notification_link = '';
  238. if (api_get_setting('show_link_bug_notification') == 'true') {
  239. $bug_notification_link = '<li class="report">
  240. <a href="http://support.chamilo.org/projects/chamilo-18/wiki/How_to_report_bugs" target="_blank">
  241. <img src="'.api_get_path(WEB_IMG_PATH).'bug.large.png" style="vertical-align: middle;" alt="'.get_lang('ReportABug').'" title="'.get_lang('ReportABug').'"/></a>
  242. </li>';
  243. }
  244. $this->assign('bug_notification_link', $bug_notification_link);
  245. if (isset($database_connection)) {
  246. // connect to the main database.
  247. Database::select_db($_configuration['main_database'], $database_connection);
  248. }
  249. ob_start();
  250. show_header_1($language_file, $nameTools);
  251. $header1 = ob_get_contents();
  252. ob_clean();
  253. ob_start();
  254. show_header_2();
  255. $header2 = ob_get_contents();
  256. ob_clean();
  257. ob_start();
  258. $menu_navigation = show_header_3();
  259. $header3 = ob_get_contents();
  260. ob_clean();
  261. $header4 = show_header_4($interbreadcrumb, $language_file, $nameTools);
  262. $this->assign('header1', $header1);
  263. $this->assign('header2', $header2);
  264. $this->assign('header3', $header3);
  265. $this->assign('header4', $header4);
  266. if (!api_is_platform_admin()) {
  267. $extra_header = trim(api_get_setting('header_extra_content'));
  268. if (!empty($extra_header)) {
  269. $this->assign('header_extra_content', $extra_header);
  270. }
  271. }
  272. if ($this->show_header == 1) {
  273. header('Content-Type: text/html; charset='.api_get_system_encoding());
  274. header('X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'],0,1));
  275. }
  276. }
  277. private function set_footer_parameters() {
  278. //Footer plugin
  279. global $_plugins, $_configuration;
  280. ob_start();
  281. api_plugin('footer');
  282. $plugin_footer = ob_get_contents();
  283. ob_clean();
  284. $this->assign('plugin_footer', $plugin_footer);
  285. $this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  286. //$platform = get_lang('Platform').' <a href="'.$_configuration['software_url'].'" target="_blank">'.$_configuration['software_name'].' '.$_configuration['system_version'].'</a> &copy; '.date('Y');
  287. //$this->assign('platform_name', $platform);
  288. if (!api_is_platform_admin()) {
  289. $extra_footer = trim(api_get_setting('footer_extra_content'));
  290. if (!empty($extra_footer)) {
  291. $this->assign('footer_extra_content', $extra_footer);
  292. }
  293. }
  294. $administrator_data = get_lang('Manager'). ' : '. Display::encrypted_mailto_link(api_get_setting('emailAdministrator'), api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')));
  295. $this->assign('administrator_name', $administrator_data);
  296. $stats = '';
  297. $this->assign('execution_stats', $stats);
  298. }
  299. }