OSDN Git Service

ナイショコメントにOpenIdが使えるか模索中
[nucleus-jp/nucleus-plugins.git] / trunk / NP_Container / NP_Container.php
1 <?php
2 /*
3         This program is free software; you can redistribute it and/or
4         modify it under the terms of the GNU General Public License
5         as published by the Free Software Foundation; either version 2
6         of the License, or (at your option) any later version.
7         (see nucleus/documentation/index.html#license for more info)
8 */
9
10
11 class NP_Container extends NucleusPlugin {
12
13         function getName() { return 'Container'; }
14         function getAuthor()  { return 'yu + NKJG'; }
15         function getURL() { return 'http://nucleus.datoka.jp/'; }
16         function getVersion() { return '0.4'; }
17         function getMinNucleusVersion() { return 330; }
18         function getEventList() { return array( 'PreSkinParse' ); }
19
20         function getDescription() { 
21                 return "utility plugin to use container-tag-like description";
22         }
23
24         function supportsFeature($what) {
25                 switch($what){
26                         case 'SqlTablePrefix':
27                                 return 1;
28                         default:
29                                 return 0;
30                 }
31         }
32
33         function init() {
34                 $this->parts = array();
35                 $this->level = 0;
36         }
37
38         function getParts($plugname, $partname='') {
39                 if ($partname) return $this->parts[$plugname][$partname];
40                 else return $this->parts[$plugname];
41         }
42
43         function setParts($plugname, $partname='', $data) {
44                 if ($partname) $this->parts[$plugname][$partname] = $data;
45                 else if ($this->parts[$plugname]) $this->parts[$plugname] = array_merge($this->parts[$plugname], $data);
46                 else $this->parts[$plugname] = $data;
47         }
48
49         function unsetParts($plugname, $partname='') {
50                 if ($partname) unset( $this->parts[$plugname][$partname] );
51                 else unset( $this->parts[$plugname] );
52         }
53
54         function doSkinVar($skinType, $mode='', $param='') { 
55                 global $manager;
56                 
57                 switch (strtolower($mode)) {
58                 case 'totemplate': //merge the codes of NP_ContainerToTemplate (NKJG http://niku.suku.name/)
59                         if (!is_array($manager->templates)) {
60                                 $manager->templates = array();
61                         }
62                         $manager->templates[$param] =& $this->getParts($param);
63                         break;
64                 }
65         }
66
67         function event_PreSkinParse($data) { 
68                 global $skinid, $manager;
69                 
70                 // get and keep handler object to parse container parts
71                 $this->skin = new SKIN($skinid);
72                 if (!$this->skin->isValid) return;
73                 $this->handler = new ACTIONS($data['type']);
74                 $this->handler->setSkin($skin);
75                 $this->parser  = new PARSER($this->skin->getAllowedActionsForType($data['type']), $this->handler);
76                 $this->parser->setProperty('IncludeMode',$this->skin->getIncludeMode());
77                 $this->parser->setProperty('IncludePrefix',$this->skin->getIncludePrefix());
78                 $this->handler->setParser($this->parser);
79                 
80                 /* pre-include */
81                 $inctype = 'parsedinclude';
82                 if ($manager->pluginInstalled('NP_includespecial')) $inctype .= '|includespecial';
83                 $search = '/<%('. $inctype .')\(([^)]+?)\)%>/s';
84                 $data['contents'] = preg_replace_callback($search, array(&$this, '_cb_preinclude'), $data['contents']); //nest1
85                 $data['contents'] = preg_replace_callback($search, array(&$this, '_cb_preinclude'), $data['contents']); //nest2
86                 
87                 /* retrieve container data */
88                 $search = '/<%Container\(begin,([^)]+?)\)%>(.+?)<%Container\(end\)%>/s';
89                 $data['contents'] = preg_replace_callback($search, array(&$this, '_cb_preskinparse'), $data['contents']);
90         }
91
92         function _cb_preinclude($m) {
93                 $inctype = $m[1];
94                 $incname = $m[2];
95                 if ($this->level > 3) return;
96                 if ($inctype == 'includespecial') list($skinpart, $incname) = explode('|', $incname, 2);
97                 
98                 if ( $inctype == 'includespecial' and ($buff = $this->skin->getContent($skinpart)) ) {
99                         //do nothing ... include only, not parsed
100                 }
101                 else if ($incname) {
102                         ob_start();
103                         $this->handler->parse_include($incname); //include only, not parsed.
104                         $buff = ob_get_contents();
105                         ob_end_clean();
106                 }
107                 
108                 return $buff;
109         }
110
111         function _cb_preskinparse($m) {
112                 $plugname = $m[1];
113                 $this->setParts($plugname, '', $this->_get_parts($m[2]) );
114                 
115                 return ''; // clear strings
116         }
117
118         /* get template parts */
119         function _get_parts($buff) {
120                 $parts = array();
121                 $data = preg_split("{<!--\s*PART\s+name=\"([0-9a-zA-Z_-]+)\"[^>]*-->|<!--\s*/PART[^>]*-->}", $buff, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
122 //              $data = preg_split("{<!--PART name=\"([0-9a-zA-Z_-]+)\"-->|<!--/PART-->}", $buff, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
123                 while ($data) {
124                         $type = array_shift($data);
125                         $type = trim($type);
126                         if ( empty($type) ) continue;
127                         $parts[$type] = array_shift($data);
128                 }
129                 return $parts;
130         }
131
132 }
133
134 ?>