| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
require_once "phing/Task.php"; |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
class importStyle extends Task |
|---|
| 17 |
{ |
|---|
| 18 |
|
|---|
| 19 |
protected $style = null; |
|---|
| 20 |
|
|---|
| 21 |
function __construct() |
|---|
| 22 |
{ |
|---|
| 23 |
|
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
protected $returnProperty; |
|---|
| 27 |
|
|---|
| 28 |
/** |
|---|
| 29 |
* The root path to where the module is stored. |
|---|
| 30 |
*/ |
|---|
| 31 |
private $path = null; |
|---|
| 32 |
|
|---|
| 33 |
*/ |
|---|
| 34 |
protected $template = null; |
|---|
| 35 |
|
|---|
| 36 |
public function setPath($str) |
|---|
| 37 |
{ |
|---|
| 38 |
$this->path = $str; |
|---|
| 39 |
} |
|---|
| 40 |
public function setPackage($str) |
|---|
| 41 |
{ |
|---|
| 42 |
$this->package = $str; |
|---|
| 43 |
} |
|---|
| 44 |
public function setTemplate($str) |
|---|
| 45 |
{ |
|---|
| 46 |
$this->template = $str; |
|---|
| 47 |
} |
|---|
| 48 |
|
|---|
| 49 |
public function setReturnProperty($r) |
|---|
| 50 |
{ |
|---|
| 51 |
$this->returnProperty = $r; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
* The init method: Do init steps. |
|---|
| 57 |
*/ |
|---|
| 58 |
public function init() |
|---|
| 59 |
{ |
|---|
| 60 |
|
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
* The main entry point method. |
|---|
| 65 |
*/ |
|---|
| 66 |
public function main() |
|---|
| 67 |
{ |
|---|
| 68 |
|
|---|
| 69 |
$name = $this->template; |
|---|
| 70 |
$style_name = "template_{$name}"; |
|---|
| 71 |
$qb = new midgardQueryBuilder('midgard_style'); |
|---|
| 72 |
$qb->add_constraint('name', '=', $style_name); |
|---|
| 73 |
$qb->add_constraint('up', '=', 0); |
|---|
| 74 |
|
|---|
| 75 |
$styles = $qb->execute(); |
|---|
| 76 |
|
|---|
| 77 |
if (count($styles) == 0) |
|---|
| 78 |
{ |
|---|
| 79 |
|
|---|
| 80 |
$new_style = new midgard_style(); |
|---|
| 81 |
$new_style->up = 0; |
|---|
| 82 |
$new_style->name = $style_name; |
|---|
| 83 |
$stat = $new_style->create(); |
|---|
| 84 |
if (!$stat) |
|---|
| 85 |
{ |
|---|
| 86 |
PEAR::raiseError("Failed to create Midgard style \"{$style_name}\", check config directives in the Midgard conf.d file \"{$init_file}\". Error was " . mgd_errstr()); |
|---|
| 87 |
} |
|---|
| 88 |
$style = new midgard_style(); |
|---|
| 89 |
$style->get_by_id($new_style->id); |
|---|
| 90 |
} |
|---|
| 91 |
else |
|---|
| 92 |
{ |
|---|
| 93 |
echo "installing into existing style...\n"; |
|---|
| 94 |
$style = $styles[0]; |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
echo "Installing template: " . $style->name ; |
|---|
| 98 |
|
|---|
| 99 |
$files = dir($this->path . "/" . $style_name); |
|---|
| 100 |
$elements = array(); |
|---|
| 101 |
while (($file = $files->read()) !== false ) { |
|---|
| 102 |
if (substr($file,0, 1) == '.' || !is_file("$dir/$file") ) continue; |
|---|
| 103 |
$path = pathinfo($file); |
|---|
| 104 |
if ($path['extension'] == 'php') { |
|---|
| 105 |
|
|---|
| 106 |
$elements[] = str_replace('.php', '', $path['basename']); |
|---|
| 107 |
} else { |
|---|
| 108 |
echo "@todo: install static $file\n"; |
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
foreach ($elements as $element_name ) { |
|---|
| 113 |
$this->add_element_to_style($style, $element_name); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
if (!$this->clearCache()) |
|---|
| 117 |
{ |
|---|
| 118 |
echo "Remember that you have to clear the midgard pagecache to see effects!\n"; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
protected function clearCache() { |
|---|
| 125 |
if (function_exists('mgd_clear_cache')) { |
|---|
| 126 |
return mgd_clear_cache(); |
|---|
| 127 |
} |
|---|
| 128 |
return false; |
|---|
| 129 |
} |
|---|
| 130 |
|
|---|
| 131 |
} |
|---|
| 132 |
?> |
|---|