root/trunk/midcom/build/importStyle.php

Revision 14773, 3.3 kB (checked in by rambo, 8 months ago)

scripted whitespace normalization, see r14772

Line 
1 <?php
2
3
4 /**
5  * Created on 10/09/2006
6  * @author tarjei huse
7  * @package midcom.admin.aegir
8  * @copyright The Midgard Project, http://www.midgard-project.org
9  * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
10  *
11  */
12 require_once "phing/Task.php";
13 /**
14  * This class importes a style
15  */
16 class importStyle extends Task
17 {
18
19     protected $style = null; // package name
20
21     function __construct()
22     {
23
24     }
25
26     protected $returnProperty; // name of property to set to return value
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     /** Sets property name to set with return value of function or expression.*/
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         // nothing to do here
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             // Create missing style template
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         //print_r($elements); exit;
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 ?>
Note: See TracBrowser for help on using the browser.