fcktemplates.xml.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <?php
  2. /**
  3. * Chamilo LMS
  4. *
  5. * For a full list of contributors, see "credits.txt".
  6. * The full license can be read in "license.txt".
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * See the GNU General Public License for more details.
  14. */
  15. // Setting the encoding to UTF-8.
  16. header('Content-Type: text/xml; charset=utf-8');
  17. // Name of the language file that needs to be included.
  18. $language_file = 'document';
  19. // Including the global initialization file.
  20. require_once '../../global.inc.php';
  21. // Outputting the opening tag of the xml file.
  22. echo '<?xml version="1.0" encoding="utf-8" ?>';
  23. // Load a stylesheet.
  24. $css = loadCSS(api_get_setting('stylesheets'));
  25. // Load libraries js.
  26. /* This libraries will be loaded in the showinframes.php file
  27. $js = '';
  28. if (api_get_setting('show_glossary_in_documents') != 'none') {
  29. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js"/>'.PHP_EOL;
  30. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  31. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"/>';
  32. } else {
  33. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"/>'.PHP_EOL;
  34. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"/>';
  35. }
  36. }
  37. */
  38. // Setting some paths.
  39. $img_dir = api_get_path(REL_CODE_PATH).'img/';
  40. $default_course_dir = api_get_path(REL_CODE_PATH).'default_course_document/';
  41. // Setting templates for teachers or for students
  42. $is_allowed_to_edit = api_is_allowed_to_edit(false,true);
  43. // Start the templates node.
  44. echo '<Templates imagesBasePath="">';
  45. // Load empty template.
  46. load_empty_template();
  47. if($is_allowed_to_edit){
  48. // Load the templates that were defined by the platform admin.
  49. load_platform_templates();
  50. }
  51. else{
  52. // Load student templates.
  53. load_student_templates();
  54. }
  55. // Load the personal templates.
  56. load_personal_templates(api_get_user_id());
  57. // End the templates node.
  58. echo '</Templates>';
  59. exit;
  60. /**
  61. * Loads a given css style (default.css).
  62. *
  63. * @param string $css_name the folder name of the style
  64. * @return html code for adding a css style <style ...
  65. */
  66. function loadCSS($css_name) {
  67. $template_css = file_get_contents(api_get_path(SYS_PATH).'main/css/'.$css_name.'/default.css');
  68. $template_css = str_replace('../../img/', api_get_path(REL_CODE_PATH).'img/', $template_css);
  69. $template_css = str_replace('images/', api_get_path(REL_CODE_PATH).'css/'.$css_name.'/images/', $template_css);
  70. // Reseting the body's background color to be in white, see Task #1885 and http://www.chamilo.org/en/node/713
  71. $template_css .= "\n".'body { background: #fff; } /* Resetting the background. */'."\n";
  72. // Removing system-specific styles and cleaning, see task #1282.
  73. $regex1 = array(
  74. '/\/\*(.+?)\*\//sm' => '', // Removing comments.
  75. '/\r\n/m' => "\n", // New lines in Unix style.
  76. '/\r/m' => "\n" // New lines in Unix style.
  77. );
  78. $template_css = preg_replace(array_keys($regex1), $regex1, $template_css);
  79. $template_css = preg_replace('/behavior[^;\{\}]*;/ism', '', $template_css); // Removing behavior-definition, it is IE-specific.
  80. $template_css_array = explode('}', $template_css);
  81. if (!empty($template_css_array)) {
  82. $deleters = array(
  83. '/.*\#.*\{[^\}]*\}/sm', // Removing css definitions bound to system secific elements (identified by id).
  84. '/.*\..*\{[^\}]*\}/sm', // Removing css definitions bound to classes, we assume them as system secific.
  85. // Removing css definitions bound to intractive types of elements that teachers most probably don't need.
  86. '/.*input.*\{[^\}]*\}/ism',
  87. '/.*textarea.*\{[^\}]*\}/ism',
  88. '/.*select.*\{[^\}]*\}/ism',
  89. '/.*form.*\{[^\}]*\}/ism',
  90. '/.*button.*\{[^\}]*\}/ism'
  91. );
  92. foreach ($template_css_array as $key => & $css_definition) {
  93. if (trim($css_definition) == '') {
  94. unset($template_css_array[$key]);
  95. continue;
  96. }
  97. $css_definition = trim($css_definition.'}');
  98. foreach ($deleters as & $deleter) {
  99. if (preg_match($deleter, $css_definition)) {
  100. unset($template_css_array[$key]);
  101. }
  102. }
  103. }
  104. $template_css = implode("\n\n", $template_css_array);
  105. }
  106. $regex2 = array(
  107. '/[ \t]*\n/m' => "\n", // Removing trailing whitespace.
  108. '/\n{3,}/m' => "\n\n" // Removing extra empty lines.
  109. );
  110. $template_css = preg_replace(array_keys($regex2), $regex2, $template_css);
  111. if (trim($template_css) == '') {
  112. return '';
  113. }
  114. return "\n".'<style type="text/css">'."\n".$template_css."\n".'</style>'."\n";
  115. }
  116. /**
  117. * Transforms a language variable into XML-usable code
  118. *
  119. * @param unknown_type $var
  120. * @return unknown
  121. */
  122. function s($var) {
  123. static $search = array('&', '<', '>');
  124. static $replace = array('&amp;',' &amp;lt;', '&amp;gt;');
  125. return str_replace($search, $replace, api_utf8_encode(get_lang($var, '')));
  126. }
  127. /**
  128. * Transforms some text into XML-usable code
  129. *
  130. * @param unknown_type $var
  131. * @return unknown
  132. */
  133. function s2($var) {
  134. static $search = array('&', '<', '>');
  135. static $replace = array('&amp;', '&amp;lt;', '&amp;gt;');
  136. return str_replace($search, $replace, api_utf8_encode($var));
  137. }
  138. /**
  139. * Loads the platform templates as defined by the platform administrator in
  140. * "Administration > Configuration settings > Templates"
  141. *
  142. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  143. * @version March 2009
  144. * @since Dokeos 1.8.6
  145. */
  146. function load_platform_templates() {
  147. global $css, $img_dir, $default_course_dir, $js;
  148. $table_template = Database::get_main_table('system_template');
  149. $sql = "SELECT title, image, comment, content FROM $table_template";
  150. $result = Database::query($sql);
  151. $search = array('{CSS}', '{IMG_DIR}', '{REL_PATH}', '{COURSE_DIR}');
  152. $replace = array($css.$js, $img_dir, api_get_path(REL_PATH), $default_course_dir);
  153. $template_thumb = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/';
  154. while ($row = Database::fetch_array($result)) {
  155. $image = empty($row['image']) ? $template_thumb.'empty.gif' : $template_thumb.$row['image'];
  156. $row['content'] = str_replace($search, $replace, $row['content']);
  157. echo '
  158. <Template title="'.s($row['title']).'" image="'.$image.'">
  159. <Description>'.s($row['comment']).'</Description>
  160. <Html>
  161. <![CDATA[
  162. '.$row['content'].'
  163. ]]>
  164. </Html>
  165. </Template>';
  166. }
  167. }
  168. /**
  169. * Loads all the personal templates of the user when
  170. *
  171. * @param integer $user_id the id of the user
  172. * @return xml node
  173. *
  174. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  175. * @version March 2009
  176. * @since Dokeos 1.8.6 The code already existed but not in a function and a lot less performant.
  177. */
  178. function load_personal_templates($user_id = 0) {
  179. global $_course;
  180. // the templates that the user has defined are only available inside the course itself
  181. if (empty($_course)) {
  182. return false;
  183. }
  184. // For which user are we getting the templates?
  185. if ($user_id == 0) {
  186. $user_id = api_get_user_id();
  187. }
  188. $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
  189. $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
  190. // The sql statement for getting all the user defined templates
  191. $sql = "SELECT template.id, template.title, template.description, template.image, template.ref_doc, document.path
  192. FROM ".$table_template." template, ".$table_document." document
  193. WHERE user_id='".Database::escape_string($user_id)."'
  194. AND course_code='".Database::escape_string(api_get_course_id())."'
  195. AND document.id = template.ref_doc";
  196. $result_template = Database::query($sql);
  197. while ($row = Database::fetch_array($result_template)) {
  198. $row['content'] = file_get_contents(api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$row['path']);
  199. //$row['content'] = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$row['path'];
  200. if (!empty($row['image'])) {
  201. $image = api_get_path(WEB_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/'.$row['image'];
  202. } else {
  203. $image = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/noimage.gif';
  204. }
  205. echo '
  206. <Template title="'.s2($row['title']).'" image="'.$image.'">
  207. <Description>'.s2($row['Description']).'</Description>
  208. <Html>
  209. <![CDATA[
  210. '.$row['content'].'
  211. ]]>
  212. </Html>
  213. </Template>';
  214. }
  215. }
  216. function load_empty_template() {
  217. global $css, $js;
  218. ?>
  219. <Template title="<?php echo s2('Empty'); ?>" image="<?php echo api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/empty.gif'; ?>">
  220. <Description></Description>
  221. <Html>
  222. <![CDATA[
  223. <html>
  224. <head>
  225. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
  226. <?php echo $css; ?>
  227. <?php echo $js; ?>
  228. </head>
  229. <body dir="<?php echo api_get_text_direction(); ?>">
  230. </body>
  231. </html>
  232. ]]>
  233. </Html>
  234. </Template>
  235. <?php
  236. }
  237. /**
  238. * Loads the student templates
  239. */
  240. function load_student_templates() {
  241. $fckeditor_template_path='/main/inc/lib/fckeditor/editor/dialog/fck_template/images/';
  242. ?>
  243. <Template title="Image and Title" image="<?php echo api_get_path(WEB_PATH).$fckeditor_template_path.'template1.gif';?>">
  244. <Description>One main image with a title and text that surround the image.</Description>
  245. <Html>
  246. <![CDATA[
  247. <img style="MARGIN-RIGHT: 10px" height="100" alt="" width="100" align="left"/>
  248. <h3>Type the title here</h3>
  249. Type the text here
  250. ]]>
  251. </Html>
  252. </Template>
  253. <Template title="Strange Template" image="<?php echo api_get_path(WEB_PATH).$fckeditor_template_path.'template2.gif';?>">
  254. <Description>A template that defines two colums, each one with a title, and some text.</Description>
  255. <Html>
  256. <![CDATA[
  257. <table cellspacing="0" cellpadding="0" width="100%" border="0">
  258. <tbody>
  259. <tr>
  260. <td width="50%">
  261. <h3>Title 1</h3>
  262. </td>
  263. <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td>
  264. <td width="50%">
  265. <h3>Title 2</h3>
  266. </td>
  267. </tr>
  268. <tr>
  269. <td>Text 1</td>
  270. <td>&nbsp;</td>
  271. <td>Text 2</td>
  272. </tr>
  273. </tbody>
  274. </table>
  275. More text goes here.
  276. ]]>
  277. </Html>
  278. </Template>
  279. <Template title="Text and Table" image="<?php echo api_get_path(WEB_PATH).$fckeditor_template_path.'template3.gif';?>">
  280. <Description>A title with some text and a table.</Description>
  281. <Html>
  282. <![CDATA[
  283. <table align="left" width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td>
  284. <h3>Title goes here</h3>
  285. <p>
  286. <table style="FLOAT: right" cellspacing="0" cellpadding="0" width="150" border="1">
  287. <tbody>
  288. <tr>
  289. <td align="center" colspan="3"><strong>Table title</strong></td>
  290. </tr>
  291. <tr>
  292. <td>&nbsp;</td>
  293. <td>&nbsp;</td>
  294. <td>&nbsp;</td>
  295. </tr>
  296. <tr>
  297. <td>&nbsp;</td>
  298. <td>&nbsp;</td>
  299. <td>&nbsp;</td>
  300. </tr>
  301. <tr>
  302. <td>&nbsp;</td>
  303. <td>&nbsp;</td>
  304. <td>&nbsp;</td>
  305. </tr>
  306. <tr>
  307. <td>&nbsp;</td>
  308. <td>&nbsp;</td>
  309. <td>&nbsp;</td>
  310. </tr>
  311. </tbody>
  312. </table>
  313. Type the text here</p>
  314. </td></tr></table>
  315. ]]>
  316. </Html>
  317. </Template>
  318. <?php
  319. }