template.lib.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. // Load Smarty library
  3. require_once api_get_path(LIBRARY_PATH).'smarty/Smarty.class.php';
  4. //include api_get_path(LIBRARY_PATH)."raintpl/rain.tpl.class.php";
  5. //include api_get_path(LIBRARY_PATH)."dwoo/dwooAutoload.php";
  6. class Template extends Smarty {
  7. var $style = 'default'; //see the template folder
  8. function __construct($title = '') {
  9. $this->title = $title;
  10. /*
  11. *
  12. * Rain TPL
  13. raintpl::configure("base_url", null );
  14. raintpl::configure("tpl_dir", api_get_path(SYS_CODE_PATH).'template/' );
  15. raintpl::configure("cache_dir", api_get_path(SYS_ARCHIVE_PATH));
  16. $this->tpl = new RainTPL();
  17. */
  18. // Dwoo
  19. //$this->dwoo = new Dwoo(api_get_path(SYS_ARCHIVE_PATH), api_get_path(SYS_ARCHIVE_PATH));
  20. // Load a template file, this is reusable if you want to render multiple times the same template with different data
  21. //$tpl = new Dwoo_Template_File('path/to/index.tpl');
  22. // Create a data set, this data set can be reused to render multiple templates if it contains enough data to fill them all
  23. //$this->tpl = new Dwoo_Data();
  24. // Class Constructor.
  25. // These automatically get set with each new instance.
  26. $this->template_dir = api_get_path(SYS_CODE_PATH).'template/'; // '/web/www.example.com/guestbook/templates/';
  27. $this->compile_dir = api_get_path(SYS_ARCHIVE_PATH); // '/web/www.example.com/guestbook/templates_c/';
  28. $this->config_dir = api_get_path(SYS_ARCHIVE_PATH); // '/web/www.example.com/guestbook/configs/'; main/inc/conf/config?
  29. $this->cache_dir = api_get_path(SYS_ARCHIVE_PATH); // '/web/www.example.com/guestbook/cache/';
  30. $this->caching = true;
  31. $this->cache_lifetime = Smarty::CACHING_OFF; // no caching
  32. //$this->cache_lifetime = 120;
  33. $this->set_header_parameters();
  34. $this->set_footer_parameters();
  35. //$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
  36. $this->assign('style', $this->style);
  37. }
  38. function get_template($name) {
  39. return $this->style.'/'.$name;
  40. }
  41. public function set_header_parameters($help = null) {
  42. $nameTools = $this->title;
  43. global $_plugins, $lp_theme_css, $mycoursetheme, $user_theme, $platform_theme;
  44. global $httpHeadXtra, $htmlHeadXtra, $_course, $_user, $clarolineRepositoryWeb, $text_dir, $plugins, $_user,
  45. $rootAdminWeb, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
  46. global $menu_navigation;
  47. global $_configuration, $show_learn_path;
  48. $this->assign('system_charset', api_get_system_encoding());
  49. if (isset($httpHeadXtra) && $httpHeadXtra) {
  50. foreach ($httpHeadXtra as & $thisHttpHead) {
  51. header($thisHttpHead);
  52. }
  53. }
  54. // Get language iso-code for this page - ignore errors
  55. $this->assign('document_language', api_get_language_isocode());
  56. $course_title = $_course['name'];
  57. $title_list[] = api_get_setting('Institution');
  58. $title_list[] = api_get_setting('siteName');
  59. if (!empty($course_title)) {
  60. $title_list[] = $course_title;
  61. }
  62. if ($nameTools != '') {
  63. $title_list[] = $nameTools;
  64. }
  65. $title_string = '';
  66. for($i=0; $i<count($title_list);$i++) {
  67. $title_string .=$title_list[$i];
  68. if (isset($title_list[$i+1])) {
  69. $item = trim($title_list[$i+1]);
  70. if (!empty($item))
  71. $title_string .=' - ';
  72. }
  73. }
  74. $this->assign('title_string', $title_string);
  75. $platform_theme = api_get_setting('stylesheets');
  76. $my_style = api_get_visual_theme();
  77. $style = '';
  78. //Base CSS
  79. $style = '@import "'.api_get_path(WEB_CSS_PATH).'base.css";';
  80. //Default CSS
  81. $style .= '@import "'.api_get_path(WEB_CSS_PATH).$my_style.'/default.css";';
  82. //Course CSS
  83. $style .= '@import "'.api_get_path(WEB_CSS_PATH).$my_style.'/course.css";';
  84. if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
  85. $style .= 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } ';
  86. }
  87. $this->assign('css_style', $style);
  88. $style_print = '@import "'.api_get_path(WEB_CSS_PATH).$my_style.'/print.css";';
  89. $this->assign('css_style_print', $style_print);
  90. $js_files = array(
  91. 'jquery.min.js',
  92. 'chosen/chosen.jquery.min.js',
  93. 'thickbox.js',
  94. 'jquery.menu.js',
  95. 'dtree/dtree.js',
  96. 'email_links.lib.js.php',
  97. );
  98. if (api_get_setting('accessibility_font_resize') == 'true') {
  99. $js_files[] = 'fontresize.js';
  100. }
  101. if (api_get_setting('include_asciimathml_script') == 'true') {
  102. $js_files[] = 'asciimath/ASCIIMathML.js';
  103. }
  104. $js_file_to_string = '';
  105. foreach($js_files as $js_file) {
  106. $js_file_to_string .= api_get_js($js_file);
  107. }
  108. $css_files = array (
  109. api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css',
  110. api_get_path(WEB_LIBRARY_PATH).'javascript/chosen/chosen.css',
  111. api_get_path(WEB_LIBRARY_PATH).'javascript/dtree/dtree.css',
  112. );
  113. if ($show_learn_path) {
  114. $css_files[] = api_get_path(WEB_CSS_PATH).$my_style.'/learnpath.css';
  115. }
  116. $css_file_to_string = '';
  117. foreach($css_files as $css_file) {
  118. $css_file_to_string .= api_get_css($css_file);
  119. }
  120. $this->assign('css_file_to_string', $css_file_to_string);
  121. $this->assign('js_file_to_string', $js_file_to_string);
  122. $this->assign('text_direction', api_get_text_direction());
  123. //@todo add this
  124. /*<link rel="top" href="<?php echo api_get_path(WEB_PATH); ?>index.php" title="" />
  125. <link rel="courses" href="<?php echo api_get_path(WEB_CODE_PATH); ?>auth/courses.php" title="<?php echo api_htmlentities(get_lang('OtherCourses'), ENT_QUOTES); ?>" />
  126. <link rel="profil" href="<?php echo api_get_path(WEB_CODE_PATH); ?>auth/profile.php" title="<?php echo api_htmlentities(get_lang('ModifyProfile'), ENT_QUOTES); ?>" />
  127. <link href="http://www.chamilo.org/documentation.php" rel="Help" />
  128. <link href="http://www.chamilo.org/team.php" rel="Author" />
  129. <link href="http://www.chamilo.org" rel="Copyright" />
  130. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
  131. <meta name="Generator" content="<?php echo $_configuration['software_name'].' '.substr($_configuration['system_version'],0,1);?>" />
  132. */
  133. $this->assign('style_print', $style_print);
  134. $extra_headers = '';
  135. if (isset($htmlHeadXtra) && $htmlHeadXtra) {
  136. foreach ($htmlHeadXtra as & $this_html_head) {
  137. $extra_headers .= $this_html_head;
  138. }
  139. }
  140. $this->assign('extra_headers', $extra_headers);
  141. $favico = '<link rel="shortcut icon" href="'.api_get_path(WEB_PATH).'favicon.ico" type="image/x-icon" />';
  142. if (isset($_configuration['multiple_access_urls']) && $_configuration['multiple_access_urls']) {
  143. $access_url_id = api_get_current_access_url_id();
  144. if ($access_url_id != -1) {
  145. $url_info = api_get_access_url($access_url_id);
  146. $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
  147. $clean_url = replace_dangerous_char($url);
  148. $clean_url = str_replace('/', '-', $clean_url);
  149. $clean_url .= '/';
  150. $homep = api_get_path(REL_PATH).'home/'.$clean_url; //homep for Home Path
  151. //we create the new dir for the new sites
  152. if (is_file($homep.'favicon.ico')) {
  153. $favico = '<link rel="shortcut icon" href="'.$homep.'favicon.ico" type="image/x-icon" />';
  154. }
  155. }
  156. }
  157. $this->assign('favico', $favico);
  158. //old banner.inc.php
  159. require_once api_get_path(LIBRARY_PATH).'banner.lib.php';
  160. global $my_session_id;
  161. $session_id = api_get_session_id();
  162. $session_name = api_get_session_name($my_session_id);
  163. $help_content = '';
  164. if (!empty($help)) {
  165. $help = Security::remove_XSS($help);
  166. $help_content = '<li class="help">';
  167. $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').'">';
  168. $help_content .= '<img src="'.api_get_path(WEB_IMG_PATH).'help.large.png" alt="'.get_lang('Help').'" title="'.get_lang('Help').'" />';
  169. $help_content .= '</a></li>';
  170. }
  171. $this->assign('help_content', $help_content);
  172. $bug_notification_link = '';
  173. if (api_get_setting('show_link_bug_notification') == 'true') {
  174. $bug_notification_link = '<li class="report">
  175. <a href="http://support.chamilo.org/projects/chamilo-18/wiki/How_to_report_bugs" target="_blank">
  176. <img src="'.api_get_path(WEB_IMG_PATH).'bug.large.png" style="vertical-align: middle;" alt="'.get_lang('ReportABug').'" title="'.get_lang('ReportABug').'"/></a>
  177. </li>';
  178. }
  179. $this->assign('bug_notification_link', $bug_notification_link);
  180. if (isset($database_connection)) {
  181. // connect to the main database.
  182. // if single database, don't pefix table names with the main database name in SQL queries
  183. // (ex. SELECT * FROM table)
  184. // if multiple database, prefix table names with the course database name in SQL queries (or no prefix if the table is in
  185. // the main database)
  186. // (ex. SELECT * FROM table_from_main_db - SELECT * FROM courseDB.table_from_course_db)
  187. Database::select_db($_configuration['main_database'], $database_connection);
  188. }
  189. ob_start();
  190. show_header_1($language_file, $nameTools);
  191. $header1 = ob_get_contents();
  192. ob_clean();
  193. ob_start();
  194. show_header_2();
  195. $header2 = ob_get_contents();
  196. ob_clean();
  197. ob_start();
  198. $menu_navigation = show_header_3();
  199. $header3 = ob_get_contents();
  200. ob_clean();
  201. $header4 = show_header_4($interbreadcrumb, $language_file, $nameTools);
  202. $this->assign('header1', $header1);
  203. $this->assign('header2', $header2);
  204. $this->assign('header3', $header3);
  205. $this->assign('header4', $header4);
  206. header('Content-Type: text/html; charset='.api_get_system_encoding());
  207. header('X-Powered-By: '.$_configuration['software_name'].' '.substr($_configuration['system_version'],0,1));
  208. }
  209. function set_footer_parameters() {
  210. //Footer plugin
  211. global $_plugins, $_configuration;
  212. ob_start();
  213. api_plugin('footer');
  214. $plugin_footer = ob_get_contents();
  215. ob_clean();
  216. $this->assign('plugin_footer', $plugin_footer);
  217. $this->assign('show_administrator_data', api_get_setting('show_administrator_data'));
  218. $platform = get_lang('Platform').' <a href="'.$_configuration['software_url'].'" target="_blank">'.$_configuration['software_name'].' '.$_configuration['system_version'].'</a> &copy; '.date('Y');
  219. $this->assign('platform', $platform);
  220. $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')));
  221. $this->assign('administrator_data', $administrator_data);
  222. $stats = '';
  223. $this->assign('execution_stats', $stats);
  224. }
  225. }