root/releases/0.9rc2/utils/exporttemplates.php

Revision 758, 1.6 kB (checked in by sven, 2 years ago)

set svn property eol-style native on some files without it

  • Property svn:eol-style set to native
Line 
1 <?php
2 /***
3  *** exporttemplates.php -- exports the in-db templates to files
4  ***
5  *** Define $CFG->templatedir and then execute
6  ***
7  ***   php4 -c /etc/php4/apache/php.ini utils/exporttemplates.php
8  ***
9  ***/
10 $starttime = microtime();
11
12 require_once(dirname(dirname(__FILE__)). '/includes.php');
13
14 // setup destination directory
15 if (empty($CFG->templatesroot)) {
16     cli_die('$CFG->templatesroot is not defined');
17 }
18 if (!is_dir($CFG->templatesroot)) {
19     if (!mkdir($CFG->templatesroot, 0755)) {
20         cli_die("Cannot create $CFG->templatesroot");
21     }
22 }
23
24 $templates = get_records('templates');
25 foreach ($templates as $template) {
26     $dirname = strtolower($template->name);
27     $dirname = clean_param($dirname, PARAM_ALPHANUM);
28     print "$dirname\n";
29     if (!is_dir($CFG->templatesroot."/$dirname")) {
30         if (!mkdir($CFG->templatesroot."/$dirname", 0755)) {
31             cli_die("Cannot create $CFG->templatesroot/$dirname");
32         }
33     }
34     $elements = get_records('template_elements', 'template_id', $template->ident);
35     foreach ($elements as $element) {
36         $filename = strtolower($element->name);
37         $filename = clean_param($filename, PARAM_ALPHANUM);
38         if (!($fh = fopen($CFG->templatesroot."/$dirname/$filename", 'a'))) {
39             cli_die("Cannot open $CFG->templatesroot/$dirname/$filename");
40         }
41         if (!fwrite($fh, $element->content)) {
42             cli_die("Cannot write to $CFG->templatesroot/$dirname/$filename");
43         };
44         if (!fclose($fh)) {
45             cli_die("Cannot write to $CFG->templatesroot/$dirname/$filename");
46         }
47     }
48
49 }
50
51 ?>
Note: See TracBrowser for help on using the browser.