| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
$starttime = microtime(); |
|---|
| 11 |
|
|---|
| 12 |
require_once(dirname(dirname(__FILE__)). '/includes.php'); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 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 |
?> |
|---|