fcktemplates.xml.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. // setting the character set to UTF-8
  3. header('Content-Type: text/xml; charset=utf-8');
  4. // name of the language file that needs to be included
  5. $language_file = 'document';
  6. // including the global dokeos file
  7. require_once('../../global.inc.php');
  8. // outputting the opening tag of the xml file
  9. echo '<?xml version="1.0" encoding="utf-8" ?>';
  10. // is this needed?
  11. $IMConfig['base_url'] = $_configuration['root_web'].'main/img/gallery/';
  12. // load a stylesheet
  13. $css = loadCSS(api_get_setting('stylesheets'));
  14. // load libreries js
  15. $js = '';
  16. if (api_get_setting('show_glossary_in_documents') != 'none') {
  17. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js"/>'.PHP_EOL;
  18. if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
  19. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"/>';
  20. } else {
  21. $js .= '<script language="javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"/>';
  22. }
  23. }
  24. // setting some paths
  25. $img_dir = api_get_path(REL_CODE_PATH).'img/';
  26. $default_course_dir = api_get_path(REL_CODE_PATH).'default_course_document/';
  27. // start the templates node
  28. echo '<Templates imagesBasePath="">';
  29. // load empty template
  30. load_empty_template();
  31. // load the templates that were defined by the platform admin
  32. load_platform_templates();
  33. // load the personal templates
  34. load_personal_templates(api_get_user_id());
  35. // end the templates node
  36. echo '</Templates>';
  37. exit;
  38. /**
  39. * load a given css style (default.css)
  40. *
  41. * @param string $css_name the folder name of the style
  42. * @return html code for adding a css style <style ...
  43. */
  44. function loadCSS($css_name)
  45. {
  46. $template_css = ' <style type="text/css">'.str_replace('../../img/',api_get_path(REL_CODE_PATH).'img/',file_get_contents(api_get_path(SYS_PATH).'main/css/'.$css_name.'/default.css')).'</style>';
  47. $template_css = str_replace('images/',api_get_path(REL_CODE_PATH).'css/'.$css_name.'/images/',$template_css);
  48. return $template_css;
  49. }
  50. /**
  51. * Transforms a language variable into XML-usable code
  52. *
  53. * @param unknown_type $var
  54. * @return unknown
  55. */
  56. function s($var)
  57. {
  58. $search = array('&','<','>');
  59. $replace = array ('&amp;','&amp;lt;','&amp;gt;');
  60. return str_replace($search, $replace, api_utf8_encode(get_lang($var, '')));
  61. }
  62. /**
  63. * Transforms some text into XML-usable code
  64. *
  65. * @param unknown_type $var
  66. * @return unknown
  67. */
  68. function s2($var)
  69. {
  70. $search = array('&','<','>');
  71. $replace = array ('&amp;','&amp;lt;','&amp;gt;');
  72. return str_replace($search, $replace, api_utf8_encode($var));
  73. }
  74. /**
  75. * Load the platform templates as defined by the platform administrator in "Platform administration > Dokeos configuration settings > templates"
  76. *
  77. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  78. * @version March 2009
  79. * @since Dokeos 1.8.6
  80. */
  81. function load_platform_templates() {
  82. // Database table definition
  83. $table_template = Database::get_main_table('system_template');
  84. global $css, $img_dir, $default_course_dir,$js;
  85. $sql = "SELECT title, image, comment, content FROM $table_template";
  86. $result = api_sql_query($sql, __FILE__, __LINE__);
  87. while ($row = Database::fetch_array($result)) {
  88. if (!empty($row['image'])) {
  89. $image = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/'.$row['image'];
  90. } else {
  91. $image = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/empty.gif';
  92. }
  93. $row['content'] = str_replace('{CSS}',$css.$js, $row['content']);
  94. $row['content'] = str_replace('{IMG_DIR}',$img_dir, $row['content']);
  95. $row['content'] = str_replace('{REL_PATH}', api_get_path(REL_PATH), $row['content']);
  96. $row['content'] = str_replace('{COURSE_DIR}',$default_course_dir, $row['content']);
  97. echo ' <Template title="'.s(get_lang($row['title']), '').'" image="'.$image.'">
  98. <Description>'.s(get_lang($row['comment']), '').'</Description>
  99. <Html>
  100. <![CDATA[
  101. '.$row['content'].'
  102. ]]>
  103. </Html>
  104. </Template>';
  105. }
  106. }
  107. /**
  108. * Load all the personal templates of the user when
  109. *
  110. * @param integer $user_id the id of the user
  111. * @return xml node
  112. *
  113. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  114. * @version March 2009
  115. * @since Dokeos 1.8.6 The code already existed but not in a function and a lot less performant.
  116. */
  117. function load_personal_templates($user_id=0) {
  118. global $_course;
  119. // the templates that the user has defined are only available inside the course itself
  120. if (empty($_course))
  121. {
  122. return false;
  123. }
  124. // For which user are we getting the templates?
  125. if ($user_id==0)
  126. {
  127. $user_id = api_get_user_id();
  128. }
  129. // Database table definition
  130. $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
  131. $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
  132. // The sql statement for getting all the user defined templates
  133. $sql = "SELECT template.id, template.title, template.description, template.image, template.ref_doc, document.path
  134. FROM ".$table_template." template, ".$table_document." document
  135. WHERE user_id='".Database::escape_string($user_id)."'
  136. AND course_code='".Database::escape_string(api_get_course_id())."'
  137. AND document.id = template.ref_doc";
  138. $result_template = api_sql_query($sql,__FILE__,__LINE__);
  139. while ($row = Database::fetch_array($result_template))
  140. {
  141. $row['content'] = file_get_contents(api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$row['path']);
  142. //$row['content'] = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document'.$row['path'];
  143. if (!empty($row['image']))
  144. {
  145. $image = api_get_path(WEB_CODE_PATH).'upload/template_thumbnails/'.$row['image'];
  146. } else {
  147. $image = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/noimage.gif';
  148. }
  149. echo ' <Template title="'.s2($row['title']).'" image="'.$image.'">
  150. <Description>'.s2($row['Description']).'</Description>
  151. <Html>
  152. <![CDATA[
  153. '.$row['content'].'
  154. ]]>
  155. </Html>
  156. </Template>';
  157. }
  158. }
  159. function load_empty_template()
  160. {
  161. global $css,$js;
  162. ?>
  163. <Template title="<?php echo s2('Empty'); ?>" image="<?php echo api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/empty.gif'; ?>">
  164. <Description></Description>
  165. <Html>
  166. <![CDATA[
  167. <html>
  168. <head>
  169. <?php echo $css ?>
  170. <?php echo $js ?>
  171. <body></body>
  172. </head>
  173. </html>
  174. ]]>
  175. </Html>
  176. </Template>
  177. <?php
  178. }
  179. ?>