XOOPS Cube Legacy base repository
Revision | 17dc88c5bfbd3aab0a8168b0d24e36c4d20c7b73 (tree) |
---|---|
Time | 2013-04-12 16:36:06 |
Author | kilica <kilica.hikawa@gmai...> |
Commiter | kilica |
Add lecat block
@@ -0,0 +1,158 @@ | ||
1 | +<?php | |
2 | +/** | |
3 | + * @file | |
4 | + * @package lecat | |
5 | + * @version $Id$ | |
6 | +**/ | |
7 | + | |
8 | +if(!defined('XOOPS_ROOT_PATH')) | |
9 | +{ | |
10 | + exit(); | |
11 | +} | |
12 | + | |
13 | +/** | |
14 | + * Lecat_ListBlock | |
15 | +**/ | |
16 | +class Lecat_ListBlock extends Legacy_BlockProcedure | |
17 | +{ | |
18 | + /** | |
19 | + * @var Lecat_CatHandler | |
20 | + * | |
21 | + * @private | |
22 | + **/ | |
23 | + var $_mHandler = null; | |
24 | + | |
25 | + /** | |
26 | + * @var Lecat_CatObject | |
27 | + * | |
28 | + * @private | |
29 | + **/ | |
30 | + var $_mObject = null; | |
31 | + | |
32 | + /** | |
33 | + * @var string[] | |
34 | + * | |
35 | + * @private | |
36 | + **/ | |
37 | + var $_mOptions = array(); | |
38 | + | |
39 | + /** | |
40 | + * prepare | |
41 | + * | |
42 | + * @param void | |
43 | + * | |
44 | + * @return bool | |
45 | + * | |
46 | + * @public | |
47 | + **/ | |
48 | + public function prepare() | |
49 | + { | |
50 | + return parent::prepare() && $this->_parseOptions() && $this->_setupObject(); | |
51 | + } | |
52 | + | |
53 | + /** | |
54 | + * _parseOptions | |
55 | + * | |
56 | + * @param void | |
57 | + * | |
58 | + * @return bool | |
59 | + * | |
60 | + * @private | |
61 | + **/ | |
62 | + protected function _parseOptions() | |
63 | + { | |
64 | + $opts = explode('|',$this->_mBlock->get('options')); | |
65 | + $this->_mOptions = array( | |
66 | + 'parent_id' => (intval($opts[0])>0 ? intval($opts[0]) : 0), | |
67 | + ); | |
68 | + return true; | |
69 | + } | |
70 | + | |
71 | + /** | |
72 | + * getBlockOption | |
73 | + * | |
74 | + * @param string $key | |
75 | + * | |
76 | + * @return string | |
77 | + * | |
78 | + * @public | |
79 | + **/ | |
80 | + public function getBlockOption($key) | |
81 | + { | |
82 | + return isset($this->_mOptions[$key]) ? $this->_mOptions[$key] : null; | |
83 | + } | |
84 | + | |
85 | + /** | |
86 | + * getOptionForm | |
87 | + * | |
88 | + * @param void | |
89 | + * | |
90 | + * @return string | |
91 | + * | |
92 | + * @public | |
93 | + **/ | |
94 | + public function getOptionForm() | |
95 | + { | |
96 | + if(!$this->prepare()) | |
97 | + { | |
98 | + return null; | |
99 | + } | |
100 | + $form = '<label for="'. $this->_mBlock->get('dirname') .'block_parent_id">'._AD_LECAT_LANG_PARENT_ID.'</label> : | |
101 | + <input type="text" size="5" name="options[0]" id="'. $this->_mBlock->get('dirname') .'block_parent_id" value="'.$this->getBlockOption('parent_id').'" />'; | |
102 | + return $form; | |
103 | + } | |
104 | + | |
105 | + /** | |
106 | + * _setupObject | |
107 | + * | |
108 | + * @param void | |
109 | + * | |
110 | + * @return bool | |
111 | + * | |
112 | + * @private | |
113 | + **/ | |
114 | + protected function _setupObject() | |
115 | + { | |
116 | + $categoryIds = null; | |
117 | + | |
118 | + //get block options | |
119 | + $parentId = $this->getBlockOption('parent_id'); | |
120 | + | |
121 | + //get module asset for handlers | |
122 | + $asset = null; | |
123 | + XCube_DelegateUtils::call( | |
124 | + 'Module.lecat.Global.Event.GetAssetManager', | |
125 | + new XCube_Ref($asset), | |
126 | + $this->_mBlock->get('dirname') | |
127 | + ); | |
128 | + | |
129 | + $this->_mHandler =& $asset->getObject('handler','cat'); | |
130 | + $this->_mObject = $this->_mHandler->getTree($parentId); | |
131 | + | |
132 | + return true; | |
133 | + } | |
134 | + | |
135 | + /** | |
136 | + * execute | |
137 | + * | |
138 | + * @param void | |
139 | + * | |
140 | + * @return void | |
141 | + * | |
142 | + * @public | |
143 | + **/ | |
144 | + function execute() | |
145 | + { | |
146 | + $root = XCube_Root::getSingleton(); | |
147 | + | |
148 | + $render = $this->getRenderTarget(); | |
149 | + $render->setTemplateName($this->_mBlock->get('template')); | |
150 | + $render->setAttribute('block', $this->_mObject); | |
151 | + $render->setAttribute('dirname', $this->_mBlock->get('dirname')); | |
152 | + $render->setAttribute('parentId', $this->getBlockOption('parent_id')); | |
153 | + $renderSystem =& $root->getRenderSystem($this->getRenderSystemName()); | |
154 | + $renderSystem->renderBlock($render); | |
155 | + } | |
156 | +} | |
157 | + | |
158 | +?> |
@@ -0,0 +1,3 @@ | ||
1 | +<div class="lecat"> | |
2 | + <{legacy_tree tree=$block dirname=$dirname}> | |
3 | +</div> |
@@ -0,0 +1,45 @@ | ||
1 | +<?php | |
2 | + | |
3 | +/* | |
4 | + * Smarty plugin | |
5 | + * ------------------------------------------------------------- | |
6 | + * Type: function | |
7 | + * Name: legacy_image | |
8 | + * Version: 1.0 | |
9 | + * Date: Jun 29, 2011 | |
10 | + * Author: HIKAWA Kilica | |
11 | + * Purpose: show image html tag | |
12 | + * Input: string dirname(*): target module's dirname | |
13 | + * string dataname(*): target table's name | |
14 | + * int data_id(*): target table's primary key | |
15 | + * int num: target image number | |
16 | + * int size: thumbnail number | |
17 | + * Examples: {legacy_image dirname=score dataname=page datsa_id=$object->get('page_id')} | |
18 | + * ------------------------------------------------------------- | |
19 | + */ | |
20 | +function smarty_function_legacy_image($params, &$smarty) | |
21 | +{ | |
22 | + if(!defined(LEGACY_IMAGE_DUMMY_EXT)) define('LEGACY_IMAGE_DUMMY_EXT', 'gif'); | |
23 | + | |
24 | + $dirname = $params['dirname']; | |
25 | + $dataname = $params['dataname']; | |
26 | + $dataId = $params['data_id']; | |
27 | + $num = isset($params['num']) ? $params['num'] : 1; | |
28 | + $size = isset($params['size']) ? $params['size'] : 0; | |
29 | + $returnUri = isset($params['returnUri']) ? true : false; | |
30 | + | |
31 | + $imageObjs = array(); | |
32 | + XCube_DelegateUtils::call('Legacy_Image.GetImageObjects', new XCube_Ref($imageObjs), $dirname, $dataname, $dataId, $num); | |
33 | + | |
34 | + //display dummy image | |
35 | + if(! $imageObj=array_shift($imageObjs)){ | |
36 | + $imageObj = null; | |
37 | + XCube_DelegateUtils::call('Legacy_Image.CreateImageObject', new XCube_Ref($imageObj)); | |
38 | + $imageObj->set('dirname', $dirname); | |
39 | + $imageObj->set('dataname', $dataname); | |
40 | + } | |
41 | + | |
42 | + echo $returnUri ? $imageObj->getFileUrl($size) : $imageObj->makeImageTag($size); | |
43 | +} | |
44 | + | |
45 | +?> |