リビジョン | 183 (tree) |
---|---|
日時 | 2010-03-31 08:23:28 |
作者 | kmorimatsu |
1) Revised plugin option routines
2) <%skin%> - <%endskin%> as in-line skin implementation.
@@ -53,14 +53,8 @@ | ||
53 | 53 | // Initialize $cache. See instance() method. |
54 | 54 | if (is_object($mode) && !isset($cache)) $cache=$mode; |
55 | 55 | switch($mode){ |
56 | - case 'group': | |
57 | - return $cache->group($id); | |
58 | - case 'item': | |
59 | - return $cache->item($id); | |
60 | - case 'comment': | |
61 | - return $cache->comment($id); | |
62 | - case 'member': | |
63 | - return $cache->member($id); | |
56 | + case 'group': case 'subgroup': case 'item': case 'comment': case 'member': case 'guest': | |
57 | + return $cache->$mode($id); | |
64 | 58 | case 'global': |
65 | 59 | default: |
66 | 60 | return $cache; |
@@ -136,7 +130,7 @@ | ||
136 | 130 | } |
137 | 131 | private function option($mode,$id){ |
138 | 132 | if (!isset($this->objects[$mode])) { |
139 | - $this->objects[$mode]=new self($this->class,$mode,$this); | |
133 | + $this->objects[$mode]=new self($this->class,$mode,$id); | |
140 | 134 | } |
141 | 135 | return $this->objects[$mode]; |
142 | 136 | } |
@@ -143,6 +137,9 @@ | ||
143 | 137 | public function group($id){ |
144 | 138 | return $this->option('group',$id); |
145 | 139 | } |
140 | + public function subgroup($id){ | |
141 | + return $this->option('subgroup',$id); | |
142 | + } | |
146 | 143 | public function item($id){ |
147 | 144 | return $this->option('item',$id); |
148 | 145 | } |
@@ -152,11 +149,14 @@ | ||
152 | 149 | public function member($id){ |
153 | 150 | return $this->option('member',$id); |
154 | 151 | } |
152 | + public function guest($id){ | |
153 | + return $this->option('guest',$id); | |
154 | + } | |
155 | 155 | /* |
156 | 156 | * Option-creating and deleting methods follow. |
157 | 157 | */ |
158 | 158 | public function create($name,$desc=false,$type='text',$defvalue='',$extra='',$sequence=0){ |
159 | - $name=strtolower($name); | |
159 | + $name=$this->class.'_'.strtolower($name); | |
160 | 160 | if ($desc===false) $desc=$name; |
161 | 161 | // Update DB |
162 | 162 | $query='INSERT OR REPLACE INTO jeans_config_desc (<%key:row%>) VALUES (<%row%>);'; |
@@ -169,7 +169,7 @@ | ||
169 | 169 | if (!isset($this->values[$name])) $this->values[$name]=$defvalue; |
170 | 170 | } |
171 | 171 | public function delete($name){ |
172 | - $name=strtolower($name); | |
172 | + $name=$this->class.'_'.strtolower($name); | |
173 | 173 | $query='DELETE FROM jeans_config_desc WHERE name=<%name%> AND configtype=<%mode%> AND owner=<%class%>'; |
174 | 174 | $array=array('name'=>$name,'mode'=>$this->mode,'class'=>$this->class,'xmlname'=>$this->class.'_'.$name); |
175 | 175 | sql::register_shutdown_query($query,$array); |
@@ -177,9 +177,8 @@ | ||
177 | 177 | case 'global': |
178 | 178 | $query='DELETE FROM jeans_config WHERE name=<%name%> AND type=<%mode%> AND owner=<%class%>'; |
179 | 179 | break; |
180 | - case 'group': case 'item': case 'comment': case 'member': | |
181 | - $table=array('table'=>'jeans_'.$this->mode); | |
182 | - $query=sql::fill_query('UPDATE <%table%> SET xml=UpdatwXML(xml,<%xmlname%>,NULL)',$table); | |
180 | + default: | |
181 | + $query=sql::fill_query('UPDATE <%0%> SET xml=UpdatwXML(xml,<%xmlname%>,NULL)',$this->table_name()); | |
183 | 182 | break; |
184 | 183 | } |
185 | 184 | sql::register_shutdown_query($query,$array); |
@@ -223,11 +222,17 @@ | ||
223 | 222 | } |
224 | 223 | private function load(){ |
225 | 224 | if ($this->mode=='global') return $this->load_global(); |
226 | - $query=sql::fill_query('SELECT xml FROM <%0%> WHERE id=<%id%> LIMIT 1',$this->mode); | |
227 | - $row=sel::query($query,$this->id)->fetch(); | |
225 | + $query=sql::fill_query('SELECT xml FROM <%0%> WHERE id=<%id%> LIMIT 1',$this->table_name()); | |
226 | + $row=sql::query($query,array('id'=>$this->id))->fetch(); | |
228 | 227 | if ($row) { |
229 | - sql::convert_xml($row,'group',$this->class); | |
230 | - $this->values=array_merge($this->values,$row); | |
228 | + // Receive values from XML. | |
229 | + sql::convert_xml($row,$this->mode,$this->class); | |
230 | + // Remove prefix. | |
231 | + $values=array(); | |
232 | + $start=strlen($this->class)+1; | |
233 | + foreach ($row as $key=>$value) $values[substr($key,$start)]=$value; | |
234 | + // Set values. | |
235 | + $this->values=array_merge($this->values,$values); | |
231 | 236 | } |
232 | 237 | } |
233 | 238 | private function save(){ |
@@ -238,7 +243,7 @@ | ||
238 | 243 | $row[]=$class.'_'.$key; |
239 | 244 | $row[]=$value; |
240 | 245 | } |
241 | - $query=sql::fill_query('UPDATE <%0%> SET xml=UpdatwXML(xml,<%row%>) WHERE id=<%id%>',$this->mode); | |
246 | + $query=sql::fill_query('UPDATE <%0%> SET xml=UpdatwXML(xml,<%row%>) WHERE id=<%id%>',$this->table_name()); | |
242 | 247 | $array=array('id'=>$this->id,'row'=>$row); |
243 | 248 | sql::register_shutdown_query($query,$array); |
244 | 249 | } |
@@ -303,4 +308,18 @@ | ||
303 | 308 | if (isset($cache[$class][$type])) return $cache[$class][$type]; |
304 | 309 | else return false; |
305 | 310 | } |
311 | + private function table_name($mode=false){ | |
312 | + if (!$mode) $mode=$this->mode; | |
313 | + switch($mode){ | |
314 | + case 'member': case 'guest': | |
315 | + return 'jeans_member'; | |
316 | + case 'group': case 'subgroup': | |
317 | + return 'jeans_group'; | |
318 | + case 'item': case 'comment': | |
319 | + return 'jeans_'.$mode; | |
320 | + case 'grobal': | |
321 | + default: | |
322 | + return 'jeans_config'; | |
323 | + } | |
324 | + } | |
306 | 325 | } |
\ No newline at end of file |
@@ -59,7 +59,7 @@ | ||
59 | 59 | 'value'=>self::data('language'), |
60 | 60 | 'type'=>'select', |
61 | 61 | 'extra'=>'languagelist'); |
62 | - $res=sql::query('SELECT * FROM jeans_config_desc WHERE configtype="member" ORDER BY sequence ASC'); | |
62 | + $res=sql::query('SELECT * FROM jeans_config_desc WHERE configtype="member" ORDER BY owner,sequence ASC'); | |
63 | 63 | while ($row=$res->fetch()) { |
64 | 64 | // TODO: Remove properties that cannot be edited by non-admin member |
65 | 65 | $row['value']=self::data($row['name']); |
@@ -25,11 +25,28 @@ | ||
25 | 25 | $array=array('itemid'=>$itemid); |
26 | 26 | $row=sql::query($query,$array)->fetch(); |
27 | 27 | } |
28 | - $post=self::item_from_post(); | |
28 | + $post=self::item_from_post('item'); | |
29 | 29 | if (isset($post['time'])) $post['time']=gmdate('Y-m-d H:i:s', strtotime($post['time'])); |
30 | 30 | if ($post) $row=array_merge($row,$post); |
31 | 31 | view::show_using_array($data,array($row),$skin); |
32 | 32 | } |
33 | + static public function tag_edititemformextra(&$data,$skin){ | |
34 | + // TODO: here. | |
35 | + // TODO: get data from XML in table using $_GET['itemid'] | |
36 | + if (!empty($_GET['itemid'])) { | |
37 | + $org=sql::query('SELECT xml FROM jeans_item WHERE id=<%0%>',$_GET['itemid'])->fetch(); | |
38 | + if ($org) sql::convert_xml($org,'item'); | |
39 | + else $org=array(); | |
40 | + } | |
41 | + $res=sql::query('SELECT * FROM jeans_config_desc WHERE configtype="item" ORDER BY owner,sequence ASC'); | |
42 | + $rows=array(); | |
43 | + while($row=$res->fetch()){ | |
44 | + if (isset($data[$row['name']])) $row['value']=$data[$row['name']]; | |
45 | + elseif (isset($org[$row['name']])) $row['value']=$org[$row['name']]; | |
46 | + $rows[]=$row; | |
47 | + } | |
48 | + view::show_using_array($data,$rows,$skin); | |
49 | + } | |
33 | 50 | static public function tag_list(&$data,$skin,$limit=10){ |
34 | 51 | $gid=isset($_GET['gid'])?(int)$_GET['gid']:0; |
35 | 52 | $offset=isset($_GET['offset'])?(int)$_GET['offset']:0; |
@@ -40,19 +40,26 @@ | ||
40 | 40 | /* Main skin parse routine follows */ |
41 | 41 | static public function parse_skin($skin=false,$parent_skin=false,$data=false,$template=false) { |
42 | 42 | static $parsed=false; |
43 | - // Refresh current skin | |
44 | - // Note that $data also keeps information of used skin. | |
45 | - if ($skin) { | |
46 | - $skin=self::skin_path($skin,$parent_skin); | |
47 | - self::$current_skin=$skin; | |
48 | - } else $skin=self::$current_skin; | |
43 | + // Initialize $data and set template | |
49 | 44 | if ($data===false) $data=self::$globals; |
50 | - $data['skin']=$skin; | |
51 | 45 | if (is_array($template)) { |
52 | 46 | $data=array_merge($data,$template); |
53 | 47 | } else if ($template!==false) { |
54 | 48 | $data['template']=$template; |
55 | 49 | } |
50 | + // Refresh current skin | |
51 | + // Note that $data also keeps information of used skin. | |
52 | + if ($skin) { | |
53 | + if (isset($data['libs']['view']['lambda'][$skin]) && is_callable($data['libs']['view']['lambda'][$skin])) { | |
54 | + // <%skin%> tag implementation | |
55 | + $data['libs']['view']['lambda'][$skin]($data); | |
56 | + return; | |
57 | + } else { | |
58 | + $skin=self::skin_path($skin,$parent_skin); | |
59 | + self::$current_skin=$skin; | |
60 | + } | |
61 | + } else $skin=self::$current_skin; | |
62 | + $data['skin']=$skin; | |
56 | 63 | // init_skinfile_parse event. |
57 | 64 | $cached=false; |
58 | 65 | core::event('init_skinfile_parse',array('data'=>&$data,'skin'=>$skin,'cached'=>&$cached,'child'=>$parsed),'view'); |
@@ -190,7 +197,7 @@ | ||
190 | 197 | case 'else': |
191 | 198 | return "<?php $cr } else { ?>"; |
192 | 199 | case 'endif': |
193 | - return "<?php $cr } ?>"; | |
200 | + return "<?php $cr } /* endif */ ?>"; | |
194 | 201 | case 'select': |
195 | 202 | $switch=''; |
196 | 203 | foreach($argarray as $value) $switch.="[{$value}]"; |
@@ -202,7 +209,16 @@ | ||
202 | 209 | case 'caseelse': case 'case.else': |
203 | 210 | return "<?php $cr break;/**/ default: ?>"; |
204 | 211 | case 'endselect': |
205 | - return "<?php $cr } ?>"; | |
212 | + return "<?php $cr } /* endselect */ ?>"; | |
213 | + case 'skin': | |
214 | + // TODO: Following routine will be revised after shifting to PHP 5.3 | |
215 | + static $funcnum=0; | |
216 | + $funcnum++; | |
217 | + $funcname="lambda_{$funcnum}".preg_replace('/[^a-z0-9]/','_',self::$current_skin); | |
218 | + return "<?php $cr \$data['libs']['view']['lambda'][$argarray[0]]='$funcname'; ". | |
219 | + "if (!function_exists('$funcname')) { function $funcname(&\$data){ ?>"; | |
220 | + case 'endskin': | |
221 | + return "<?php $cr }; } /* endskin */ ?>"; | |
206 | 222 | default: |
207 | 223 | $method=self::compile_cb_method($matches[2]); |
208 | 224 | if ($method) return "$cr<?php $method($args); ?>"; |