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)
11 class NP_Container extends NucleusPlugin {
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' ); }
20 function getDescription() {
21 return "utility plugin to use container-tag-like description";
24 function supportsFeature($what) {
26 case 'SqlTablePrefix':
34 $this->parts = array();
38 function getParts($plugname, $partname='') {
39 if ($partname) return $this->parts[$plugname][$partname];
40 else return $this->parts[$plugname];
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;
49 function unsetParts($plugname, $partname='') {
50 if ($partname) unset( $this->parts[$plugname][$partname] );
51 else unset( $this->parts[$plugname] );
54 function doSkinVar($skinType, $mode='', $param='') {
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();
62 $manager->templates[$param] =& $this->getParts($param);
67 function event_PreSkinParse($data) {
68 global $skinid, $manager;
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);
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
87 /* retrieve container data */
88 $search = '/<%Container\(begin,([^)]+?)\)%>(.+?)<%Container\(end\)%>/s';
89 $data['contents'] = preg_replace_callback($search, array(&$this, '_cb_preskinparse'), $data['contents']);
92 function _cb_preinclude($m) {
95 if ($this->level > 3) return;
96 if ($inctype == 'includespecial') list($skinpart, $incname) = explode('|', $incname, 2);
98 if ( $inctype == 'includespecial' and ($buff = $this->skin->getContent($skinpart)) ) {
99 //do nothing ... include only, not parsed
103 $this->handler->parse_include($incname); //include only, not parsed.
104 $buff = ob_get_contents();
111 function _cb_preskinparse($m) {
113 $this->setParts($plugname, '', $this->_get_parts($m[2]) );
115 return ''; // clear strings
118 /* get template parts */
119 function _get_parts($buff) {
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);
124 $type = array_shift($data);
126 if ( empty($type) ) continue;
127 $parts[$type] = array_shift($data);