template.lib.php 10 KB

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