123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- <?php
- header('Content-Type: text/xml; charset=utf-8');
- $language_file = 'document';
- require_once '../../global.inc.php';
- echo '<?xml version="1.0" encoding="utf-8" ?>';
- $css = loadCSS(api_get_setting('stylesheets'));
- $img_dir = api_get_path(REL_CODE_PATH).'img/';
- $default_course_dir = api_get_path(REL_CODE_PATH).'default_course_document/';
- $is_allowed_to_edit = api_is_allowed_to_edit(false,true);
- echo '<Templates imagesBasePath="">';
- load_empty_template();
- if($is_allowed_to_edit){
-
- load_platform_templates();
- }
- else{
-
- load_student_templates();
- }
- load_personal_templates(api_get_user_id());
- echo '</Templates>';
- exit;
- function loadCSS($css_name) {
- $template_css = file_get_contents(api_get_path(SYS_PATH).'main/css/'.$css_name.'/default.css');
- $template_css = str_replace('../../img/', api_get_path(REL_CODE_PATH).'img/', $template_css);
- $template_css = str_replace('images/', api_get_path(REL_CODE_PATH).'css/'.$css_name.'/images/', $template_css);
-
- $template_css .= "\n".'body { background: #fff; } /* Resetting the background. */'."\n";
-
- $regex1 = array(
- '/\/\*(.+?)\*\//sm' => '',
- '/\r\n/m' => "\n",
- '/\r/m' => "\n"
- );
- $template_css = preg_replace(array_keys($regex1), $regex1, $template_css);
- $template_css = preg_replace('/behavior[^;\{\}]*;/ism', '', $template_css);
- $template_css_array = explode('}', $template_css);
- if (!empty($template_css_array)) {
- $deleters = array(
- '/.*\#.*\{[^\}]*\}/sm',
- '/.*\..*\{[^\}]*\}/sm',
-
- '/.*input.*\{[^\}]*\}/ism',
- '/.*textarea.*\{[^\}]*\}/ism',
- '/.*select.*\{[^\}]*\}/ism',
- '/.*form.*\{[^\}]*\}/ism',
- '/.*button.*\{[^\}]*\}/ism'
- );
- foreach ($template_css_array as $key => & $css_definition) {
- if (trim($css_definition) == '') {
- unset($template_css_array[$key]);
- continue;
- }
- $css_definition = trim($css_definition.'}');
- foreach ($deleters as & $deleter) {
- if (preg_match($deleter, $css_definition)) {
- unset($template_css_array[$key]);
- }
- }
- }
- $template_css = implode("\n\n", $template_css_array);
- }
- $regex2 = array(
- '/[ \t]*\n/m' => "\n",
- '/\n{3,}/m' => "\n\n"
- );
- $template_css = preg_replace(array_keys($regex2), $regex2, $template_css);
- if (trim($template_css) == '') {
- return '';
- }
- return "\n".'<style type="text/css">'."\n".$template_css."\n".'</style>'."\n";
- }
- function s($var) {
- static $search = array('&', '<', '>');
- static $replace = array('&',' &lt;', '&gt;');
- return str_replace($search, $replace, api_utf8_encode(get_lang($var, '')));
- }
- function s2($var) {
- static $search = array('&', '<', '>');
- static $replace = array('&', '&lt;', '&gt;');
- return str_replace($search, $replace, api_utf8_encode($var));
- }
- function load_platform_templates() {
- global $css, $img_dir, $default_course_dir, $js;
- $table_template = Database::get_main_table('system_template');
- $sql = "SELECT title, image, comment, content FROM $table_template";
- $result = Database::query($sql);
- $search = array('{CSS}', '{IMG_DIR}', '{REL_PATH}', '{COURSE_DIR}');
- $replace = array($css.$js, $img_dir, api_get_path(REL_PATH), $default_course_dir);
- $template_thumb = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/';
- while ($row = Database::fetch_array($result)) {
- $image = empty($row['image']) ? $template_thumb.'empty.gif' : $template_thumb.$row['image'];
- $row['content'] = str_replace($search, $replace, $row['content']);
- echo '
- <Template title="'.s($row['title']).'" image="'.$image.'">
- <Description>'.s($row['comment']).'</Description>
- <Html>
- <![CDATA[
- '.$row['content'].'
- ]]>
- </Html>
- </Template>';
- }
- }
- function load_personal_templates($user_id = 0) {
- global $_course;
-
- if (empty($_course)) {
- return false;
- }
-
- if ($user_id == 0) {
- $user_id = api_get_user_id();
- }
- $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
- $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
-
- $sql = "SELECT template.id, template.title, template.description, template.image, template.ref_doc, document.path
- FROM ".$table_template." template, ".$table_document." document
- WHERE user_id='".Database::escape_string($user_id)."'
- AND course_code='".Database::escape_string(api_get_course_id())."'
- AND document.id = template.ref_doc";
- $result_template = Database::query($sql);
- while ($row = Database::fetch_array($result_template)) {
- $row['content'] = file_get_contents(api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'.$row['path']);
-
- if (!empty($row['image'])) {
- $image = api_get_path(WEB_PATH).'courses/'.$_course['path'].'/upload/template_thumbnails/'.$row['image'];
- } else {
- $image = api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/noimage.gif';
- }
- echo '
- <Template title="'.s2($row['title']).'" image="'.$image.'">
- <Description>'.s2($row['Description']).'</Description>
- <Html>
- <![CDATA[
- '.$row['content'].'
- ]]>
- </Html>
- </Template>';
- }
- }
- function load_empty_template() {
- global $css, $js;
- ?>
- <Template title="<?php echo s2('Empty'); ?>" image="<?php echo api_get_path(WEB_PATH).'home/default_platform_document/template_thumb/empty.gif'; ?>">
- <Description></Description>
- <Html>
- <![CDATA[
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
- <?php echo $css; ?>
- <?php echo $js; ?>
- </head>
- <body dir="<?php echo api_get_text_direction(); ?>">
- </body>
- </html>
- ]]>
- </Html>
- </Template>
- <?php
- }
- function load_student_templates() {
- $fckeditor_template_path='/main/inc/lib/fckeditor/editor/dialog/fck_template/images/';
- ?>
- <Template title="Image and Title" image="<?php echo api_get_path(WEB_PATH).$fckeditor_template_path.'template1.gif';?>">
- <Description>One main image with a title and text that surround the image.</Description>
- <Html>
- <![CDATA[
- <img style="MARGIN-RIGHT: 10px" height="100" alt="" width="100" align="left"/>
- <h3>Type the title here</h3>
- Type the text here
- ]]>
- </Html>
- </Template>
- <Template title="Strange Template" image="<?php echo api_get_path(WEB_PATH).$fckeditor_template_path.'template2.gif';?>">
- <Description>A template that defines two colums, each one with a title, and some text.</Description>
- <Html>
- <![CDATA[
- <table cellspacing="0" cellpadding="0" width="100%" border="0">
- <tbody>
- <tr>
- <td width="50%">
- <h3>Title 1</h3>
- </td>
- <td> </td>
- <td width="50%">
- <h3>Title 2</h3>
- </td>
- </tr>
- <tr>
- <td>Text 1</td>
- <td> </td>
- <td>Text 2</td>
- </tr>
- </tbody>
- </table>
- More text goes here.
- ]]>
- </Html>
- </Template>
- <Template title="Text and Table" image="<?php echo api_get_path(WEB_PATH).$fckeditor_template_path.'template3.gif';?>">
- <Description>A title with some text and a table.</Description>
- <Html>
- <![CDATA[
- <table align="left" width="80%" border="0" cellspacing="0" cellpadding="0"><tr><td>
- <h3>Title goes here</h3>
- <p>
- <table style="FLOAT: right" cellspacing="0" cellpadding="0" width="150" border="1">
- <tbody>
- <tr>
- <td align="center" colspan="3"><strong>Table title</strong></td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- <td> </td>
- </tr>
- </tbody>
- </table>
- Type the text here</p>
- </td></tr></table>
- ]]>
- </Html>
- </Template>
- <?php
- }
|