@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | /** |
93 | 93 | * @param string $key |
94 | 94 | * @param string $format |
95 | - * @return mixed |
|
95 | + * @return string |
|
96 | 96 | */ |
97 | 97 | public function getVar($key, $format = 's') |
98 | 98 | { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
160 | - * @return mixed|string |
|
160 | + * @return string |
|
161 | 161 | */ |
162 | 162 | public function generateTag() |
163 | 163 | { |
@@ -36,87 +36,87 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class SmartobjectAdsense extends SmartObject |
38 | 38 | { |
39 | - /** |
|
40 | - * SmartobjectAdsense constructor. |
|
41 | - */ |
|
42 | - public function __construct() |
|
43 | - { |
|
44 | - $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
45 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
46 | - $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
47 | - $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
48 | - $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
49 | - $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
50 | - $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
51 | - $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
52 | - $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
53 | - $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
54 | - $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
55 | - |
|
56 | - $this->setControl('format', array( |
|
57 | - 'handler' => 'adsense', |
|
58 | - 'method' => 'getFormats' |
|
59 | - )); |
|
60 | - |
|
61 | - $this->setControl('border_color', array( |
|
62 | - 'name' => 'text', |
|
63 | - 'size' => 6, |
|
64 | - 'maxlength' => 6 |
|
65 | - )); |
|
66 | - |
|
67 | - $this->setControl('background_color', array( |
|
68 | - 'name' => 'text', |
|
69 | - 'size' => 6, |
|
70 | - 'maxlength' => 6 |
|
71 | - )); |
|
72 | - |
|
73 | - $this->setControl('link_color', array( |
|
74 | - 'name' => 'text', |
|
75 | - 'size' => 6, |
|
76 | - 'maxlength' => 6 |
|
77 | - )); |
|
78 | - |
|
79 | - $this->setControl('url_color', array( |
|
80 | - 'name' => 'text', |
|
81 | - 'size' => 6, |
|
82 | - 'maxlength' => 6 |
|
83 | - )); |
|
84 | - |
|
85 | - $this->setControl('text_color', array( |
|
86 | - 'name' => 'text', |
|
87 | - 'size' => 6, |
|
88 | - 'maxlength' => 6 |
|
89 | - )); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $key |
|
94 | - * @param string $format |
|
95 | - * @return mixed |
|
96 | - */ |
|
97 | - public function getVar($key, $format = 's') |
|
98 | - { |
|
99 | - if ($format === 's' && in_array($key, array())) { |
|
100 | - // return call_user_func(array($this, $key)); |
|
101 | - return $this->{$key}(); |
|
102 | - } |
|
103 | - |
|
104 | - return parent::getVar($key, $format); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function render() |
|
111 | - { |
|
112 | - global $smartobjectAdsenseHandler; |
|
113 | - if ($this->getVar('style', 'n') != '') { |
|
114 | - $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
115 | - } else { |
|
116 | - $ret = '<div>'; |
|
117 | - } |
|
118 | - |
|
119 | - $ret .= '<script type="text/javascript"><!-- |
|
39 | + /** |
|
40 | + * SmartobjectAdsense constructor. |
|
41 | + */ |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + $this->quickInitVar('adsenseid', XOBJ_DTYPE_INT, true); |
|
45 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_ADSENSE_DESCRIPTION, _CO_SOBJECT_ADSENSE_DESCRIPTION_DSC); |
|
46 | + $this->quickInitVar('client_id', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_CLIENT_ID, _CO_SOBJECT_ADSENSE_CLIENT_ID_DSC); |
|
47 | + $this->quickInitVar('tag', XOBJ_DTYPE_TXTBOX, false, _CO_SOBJECT_ADSENSE_TAG, _CO_SOBJECT_ADSENSE_TAG_DSC); |
|
48 | + $this->quickInitVar('format', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_FORMAT, _CO_SOBJECT_ADSENSE_FORMAT_DSC); |
|
49 | + $this->quickInitVar('border_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BORDER_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
50 | + $this->quickInitVar('background_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_BACKGROUND_COLOR, _CO_SOBJECT_ADSENSE_BORDER_COLOR_DSC); |
|
51 | + $this->quickInitVar('link_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_LINK_COLOR, _CO_SOBJECT_ADSENSE_LINK_COLOR_DSC); |
|
52 | + $this->quickInitVar('url_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_URL_COLOR, _CO_SOBJECT_ADSENSE_URL_COLOR_DSC); |
|
53 | + $this->quickInitVar('text_color', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_ADSENSE_TEXT_COLOR, _CO_SOBJECT_ADSENSE_TEXT_COLOR_DSC); |
|
54 | + $this->quickInitVar('style', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_ADSENSE_STYLE, _CO_SOBJECT_ADSENSE_STYLE_DSC); |
|
55 | + |
|
56 | + $this->setControl('format', array( |
|
57 | + 'handler' => 'adsense', |
|
58 | + 'method' => 'getFormats' |
|
59 | + )); |
|
60 | + |
|
61 | + $this->setControl('border_color', array( |
|
62 | + 'name' => 'text', |
|
63 | + 'size' => 6, |
|
64 | + 'maxlength' => 6 |
|
65 | + )); |
|
66 | + |
|
67 | + $this->setControl('background_color', array( |
|
68 | + 'name' => 'text', |
|
69 | + 'size' => 6, |
|
70 | + 'maxlength' => 6 |
|
71 | + )); |
|
72 | + |
|
73 | + $this->setControl('link_color', array( |
|
74 | + 'name' => 'text', |
|
75 | + 'size' => 6, |
|
76 | + 'maxlength' => 6 |
|
77 | + )); |
|
78 | + |
|
79 | + $this->setControl('url_color', array( |
|
80 | + 'name' => 'text', |
|
81 | + 'size' => 6, |
|
82 | + 'maxlength' => 6 |
|
83 | + )); |
|
84 | + |
|
85 | + $this->setControl('text_color', array( |
|
86 | + 'name' => 'text', |
|
87 | + 'size' => 6, |
|
88 | + 'maxlength' => 6 |
|
89 | + )); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $key |
|
94 | + * @param string $format |
|
95 | + * @return mixed |
|
96 | + */ |
|
97 | + public function getVar($key, $format = 's') |
|
98 | + { |
|
99 | + if ($format === 's' && in_array($key, array())) { |
|
100 | + // return call_user_func(array($this, $key)); |
|
101 | + return $this->{$key}(); |
|
102 | + } |
|
103 | + |
|
104 | + return parent::getVar($key, $format); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function render() |
|
111 | + { |
|
112 | + global $smartobjectAdsenseHandler; |
|
113 | + if ($this->getVar('style', 'n') != '') { |
|
114 | + $ret = '<div style="' . $this->getVar('style', 'n') . '">'; |
|
115 | + } else { |
|
116 | + $ret = '<div>'; |
|
117 | + } |
|
118 | + |
|
119 | + $ret .= '<script type="text/javascript"><!-- |
|
120 | 120 | google_ad_client = "' . $this->getVar('client_id', 'n') . '"; |
121 | 121 | google_ad_width = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['width'] . '; |
122 | 122 | google_ad_height = ' . $smartobjectAdsenseHandler->adFormats[$this->getVar('format', 'n')]['height'] . '; |
@@ -134,66 +134,66 @@ discard block |
||
134 | 134 | </script> |
135 | 135 | </div>'; |
136 | 136 | |
137 | - return $ret; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function getXoopsCode() |
|
144 | - { |
|
145 | - $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
146 | - |
|
147 | - return $ret; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param $var |
|
152 | - * @return bool |
|
153 | - */ |
|
154 | - public function emptyString($var) |
|
155 | - { |
|
156 | - return (strlen($var) > 0); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @return mixed|string |
|
161 | - */ |
|
162 | - public function generateTag() |
|
163 | - { |
|
164 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
165 | - $title = xoops_substr($title, 0, 10, ''); |
|
166 | - // Transformation des ponctuations |
|
167 | - // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
|
168 | - $pattern = array('/%09/', '/%20/', '/%21/', '/%22/', '/%23/', '/%25/', '/%26/', '/%27/', '/%28/', '/%29/', '/%2C/', '/%2F/', '/%3A/', '/%3B/', '/%3C/', '/%3D/', '/%3E/', '/%3F/', '/%40/', '/%5B/', '/%5C/', '/%5D/', '/%5E/', '/%7B/', '/%7C/', '/%7D/', '/%7E/', "/\./"); |
|
169 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
170 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
171 | - |
|
172 | - // Transformation des caract�res accentu�s |
|
173 | - // ° è é ê ë ç à â ä î ï ù ü û ô ö |
|
174 | - $pattern = array('/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/'); |
|
175 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
176 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
177 | - |
|
178 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
179 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
180 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
181 | - |
|
182 | - $title = $title . time(); |
|
183 | - $title = md5($title); |
|
184 | - |
|
185 | - return $title; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public function getCloneLink() |
|
192 | - { |
|
193 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '" /></a>'; |
|
194 | - |
|
195 | - return $ret; |
|
196 | - } |
|
137 | + return $ret; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function getXoopsCode() |
|
144 | + { |
|
145 | + $ret = '[adsense]' . $this->getVar('tag', 'n') . '[/adsense]'; |
|
146 | + |
|
147 | + return $ret; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param $var |
|
152 | + * @return bool |
|
153 | + */ |
|
154 | + public function emptyString($var) |
|
155 | + { |
|
156 | + return (strlen($var) > 0); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @return mixed|string |
|
161 | + */ |
|
162 | + public function generateTag() |
|
163 | + { |
|
164 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
165 | + $title = xoops_substr($title, 0, 10, ''); |
|
166 | + // Transformation des ponctuations |
|
167 | + // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
|
168 | + $pattern = array('/%09/', '/%20/', '/%21/', '/%22/', '/%23/', '/%25/', '/%26/', '/%27/', '/%28/', '/%29/', '/%2C/', '/%2F/', '/%3A/', '/%3B/', '/%3C/', '/%3D/', '/%3E/', '/%3F/', '/%40/', '/%5B/', '/%5C/', '/%5D/', '/%5E/', '/%7B/', '/%7C/', '/%7D/', '/%7E/', "/\./"); |
|
169 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
170 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
171 | + |
|
172 | + // Transformation des caract�res accentu�s |
|
173 | + // ° è é ê ë ç à â ä î ï ù ü û ô ö |
|
174 | + $pattern = array('/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/'); |
|
175 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
176 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
177 | + |
|
178 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
179 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
180 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
181 | + |
|
182 | + $title = $title . time(); |
|
183 | + $title = md5($title); |
|
184 | + |
|
185 | + return $title; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public function getCloneLink() |
|
192 | + { |
|
193 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/adsense.php?op=clone&adsenseid=' . $this->getVar('adsenseid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" alt="' . _CO_SOBJECT_ADSENSE_CLONE . '" title="' . _CO_SOBJECT_ADSENSE_CLONE . '" /></a>'; |
|
194 | + |
|
195 | + return $ret; |
|
196 | + } |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -201,116 +201,116 @@ discard block |
||
201 | 201 | */ |
202 | 202 | class SmartobjectAdsenseHandler extends SmartPersistableObjectHandler |
203 | 203 | { |
204 | - public $adFormats; |
|
205 | - public $adFormatsList; |
|
206 | - public $objects = false; |
|
207 | - |
|
208 | - /** |
|
209 | - * SmartobjectAdsenseHandler constructor. |
|
210 | - * @param object|XoopsDatabase $db |
|
211 | - */ |
|
212 | - public function __construct($db) |
|
213 | - { |
|
214 | - parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
215 | - $this->adFormats = array(); |
|
216 | - $this->adFormatsList = array(); |
|
217 | - |
|
218 | - $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
219 | - $this->adFormats['728x90_as']['width'] = 728; |
|
220 | - $this->adFormats['728x90_as']['height'] = 90; |
|
221 | - $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
222 | - |
|
223 | - $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
224 | - $this->adFormats['468x60_as']['width'] = 468; |
|
225 | - $this->adFormats['468x60_as']['height'] = 60; |
|
226 | - $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
227 | - |
|
228 | - $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
229 | - $this->adFormats['234x60_as']['width'] = 234; |
|
230 | - $this->adFormats['234x60_as']['height'] = 60; |
|
231 | - $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
232 | - |
|
233 | - $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
234 | - $this->adFormats['120x600_as']['width'] = 120; |
|
235 | - $this->adFormats['120x600_as']['height'] = 600; |
|
236 | - $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
237 | - |
|
238 | - $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
239 | - $this->adFormats['160x600_as']['width'] = 160; |
|
240 | - $this->adFormats['160x600_as']['height'] = 600; |
|
241 | - $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
242 | - |
|
243 | - $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
244 | - $this->adFormats['120x240_as']['width'] = 120; |
|
245 | - $this->adFormats['120x240_as']['height'] = 240; |
|
246 | - $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
247 | - |
|
248 | - $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
249 | - $this->adFormats['336x280_as']['width'] = 136; |
|
250 | - $this->adFormats['336x280_as']['height'] = 280; |
|
251 | - $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
252 | - |
|
253 | - $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
254 | - $this->adFormats['300x250_as']['width'] = 300; |
|
255 | - $this->adFormats['300x250_as']['height'] = 250; |
|
256 | - $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
257 | - |
|
258 | - $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
259 | - $this->adFormats['250x250_as']['width'] = 250; |
|
260 | - $this->adFormats['250x250_as']['height'] = 250; |
|
261 | - $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
262 | - |
|
263 | - $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
264 | - $this->adFormats['200x200_as']['width'] = 200; |
|
265 | - $this->adFormats['200x200_as']['height'] = 200; |
|
266 | - $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
267 | - |
|
268 | - $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
269 | - $this->adFormats['180x150_as']['width'] = 180; |
|
270 | - $this->adFormats['180x150_as']['height'] = 150; |
|
271 | - $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
272 | - |
|
273 | - $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
274 | - $this->adFormats['125x125_as']['width'] = 125; |
|
275 | - $this->adFormats['125x125_as']['height'] = 125; |
|
276 | - $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * @return array |
|
281 | - */ |
|
282 | - public function getFormats() |
|
283 | - { |
|
284 | - return $this->adFormatsList; |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * @param $obj |
|
289 | - * @return bool |
|
290 | - */ |
|
291 | - public function beforeSave(&$obj) |
|
292 | - { |
|
293 | - if ($obj->getVar('tag') == '') { |
|
294 | - $obj->setVar('tag', $title = $obj->generateTag()); |
|
295 | - } |
|
296 | - |
|
297 | - return true; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * @return array|bool |
|
302 | - */ |
|
303 | - public function getAdsensesByTag() |
|
304 | - { |
|
305 | - if (!$this->objects) { |
|
306 | - $adsensesObj = $this->getObjects(null, true); |
|
307 | - $ret = array(); |
|
308 | - foreach ($adsensesObj as $adsenseObj) { |
|
309 | - $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
310 | - } |
|
311 | - $this->objects = $ret; |
|
312 | - } |
|
313 | - |
|
314 | - return $this->objects; |
|
315 | - } |
|
204 | + public $adFormats; |
|
205 | + public $adFormatsList; |
|
206 | + public $objects = false; |
|
207 | + |
|
208 | + /** |
|
209 | + * SmartobjectAdsenseHandler constructor. |
|
210 | + * @param object|XoopsDatabase $db |
|
211 | + */ |
|
212 | + public function __construct($db) |
|
213 | + { |
|
214 | + parent::__construct($db, 'adsense', 'adsenseid', 'description', '', 'smartobject'); |
|
215 | + $this->adFormats = array(); |
|
216 | + $this->adFormatsList = array(); |
|
217 | + |
|
218 | + $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
219 | + $this->adFormats['728x90_as']['width'] = 728; |
|
220 | + $this->adFormats['728x90_as']['height'] = 90; |
|
221 | + $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
222 | + |
|
223 | + $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
224 | + $this->adFormats['468x60_as']['width'] = 468; |
|
225 | + $this->adFormats['468x60_as']['height'] = 60; |
|
226 | + $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
227 | + |
|
228 | + $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
229 | + $this->adFormats['234x60_as']['width'] = 234; |
|
230 | + $this->adFormats['234x60_as']['height'] = 60; |
|
231 | + $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
232 | + |
|
233 | + $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
234 | + $this->adFormats['120x600_as']['width'] = 120; |
|
235 | + $this->adFormats['120x600_as']['height'] = 600; |
|
236 | + $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
237 | + |
|
238 | + $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
239 | + $this->adFormats['160x600_as']['width'] = 160; |
|
240 | + $this->adFormats['160x600_as']['height'] = 600; |
|
241 | + $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
242 | + |
|
243 | + $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
244 | + $this->adFormats['120x240_as']['width'] = 120; |
|
245 | + $this->adFormats['120x240_as']['height'] = 240; |
|
246 | + $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
247 | + |
|
248 | + $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
249 | + $this->adFormats['336x280_as']['width'] = 136; |
|
250 | + $this->adFormats['336x280_as']['height'] = 280; |
|
251 | + $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
252 | + |
|
253 | + $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
254 | + $this->adFormats['300x250_as']['width'] = 300; |
|
255 | + $this->adFormats['300x250_as']['height'] = 250; |
|
256 | + $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
257 | + |
|
258 | + $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
259 | + $this->adFormats['250x250_as']['width'] = 250; |
|
260 | + $this->adFormats['250x250_as']['height'] = 250; |
|
261 | + $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
262 | + |
|
263 | + $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
264 | + $this->adFormats['200x200_as']['width'] = 200; |
|
265 | + $this->adFormats['200x200_as']['height'] = 200; |
|
266 | + $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
267 | + |
|
268 | + $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
269 | + $this->adFormats['180x150_as']['width'] = 180; |
|
270 | + $this->adFormats['180x150_as']['height'] = 150; |
|
271 | + $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
272 | + |
|
273 | + $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
274 | + $this->adFormats['125x125_as']['width'] = 125; |
|
275 | + $this->adFormats['125x125_as']['height'] = 125; |
|
276 | + $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * @return array |
|
281 | + */ |
|
282 | + public function getFormats() |
|
283 | + { |
|
284 | + return $this->adFormatsList; |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * @param $obj |
|
289 | + * @return bool |
|
290 | + */ |
|
291 | + public function beforeSave(&$obj) |
|
292 | + { |
|
293 | + if ($obj->getVar('tag') == '') { |
|
294 | + $obj->setVar('tag', $title = $obj->generateTag()); |
|
295 | + } |
|
296 | + |
|
297 | + return true; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * @return array|bool |
|
302 | + */ |
|
303 | + public function getAdsensesByTag() |
|
304 | + { |
|
305 | + if (!$this->objects) { |
|
306 | + $adsensesObj = $this->getObjects(null, true); |
|
307 | + $ret = array(); |
|
308 | + foreach ($adsensesObj as $adsenseObj) { |
|
309 | + $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
310 | + } |
|
311 | + $this->objects = $ret; |
|
312 | + } |
|
313 | + |
|
314 | + return $this->objects; |
|
315 | + } |
|
316 | 316 | } |
@@ -147,7 +147,7 @@ |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * @return mixed|string |
|
150 | + * @return string |
|
151 | 151 | */ |
152 | 152 | public function generateTag() |
153 | 153 | { |
@@ -36,154 +36,154 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class SmartobjectCustomtag extends SmartObject |
38 | 38 | { |
39 | - public $content = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * SmartobjectCustomtag constructor. |
|
43 | - */ |
|
44 | - public function __construct() |
|
45 | - { |
|
46 | - $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
47 | - $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
48 | - $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
49 | - $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
50 | - $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
51 | - |
|
52 | - $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
53 | - $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
54 | - $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
55 | - $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
56 | - |
|
57 | - $this->setControl('content', array( |
|
58 | - 'name' => 'textarea', |
|
59 | - 'form_editor' => 'textarea', |
|
60 | - 'form_rows' => 25 |
|
61 | - )); |
|
62 | - $this->setControl('language', array( |
|
63 | - 'name' => 'language', |
|
64 | - 'all' => true |
|
65 | - )); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param string $key |
|
70 | - * @param string $format |
|
71 | - * @return mixed |
|
72 | - */ |
|
73 | - public function getVar($key, $format = 's') |
|
74 | - { |
|
75 | - if ($format === 's' && in_array($key, array())) { |
|
76 | - // return call_user_func(array($this, $key)); |
|
77 | - return $this->{$key}(); |
|
78 | - } |
|
79 | - |
|
80 | - return parent::getVar($key, $format); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return bool|mixed |
|
85 | - */ |
|
86 | - public function render() |
|
87 | - { |
|
88 | - if (!$this->content) { |
|
89 | - $ret = $this->getVar('content'); |
|
90 | - $this->content = $ret; |
|
91 | - } |
|
92 | - |
|
93 | - return $this->content; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return bool|mixed|string |
|
98 | - */ |
|
99 | - public function renderWithPhp() |
|
100 | - { |
|
101 | - if (!$this->content) { |
|
102 | - $ret = $this->getVar('content'); |
|
103 | - $this->content = $ret; |
|
104 | - } else { |
|
105 | - $ret = $this->content; |
|
106 | - } |
|
107 | - |
|
108 | - // check for PHP if we are not on admin side |
|
109 | - if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
110 | - $ret = str_replace('[php]', '', $ret); |
|
111 | - // we have PHP code, let's evaluate |
|
112 | - eval($ret); |
|
113 | - |
|
114 | - return ''; |
|
115 | - } |
|
116 | - |
|
117 | - return $this->content; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getXoopsCode() |
|
124 | - { |
|
125 | - $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
126 | - |
|
127 | - return $ret; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getCloneLink() |
|
134 | - { |
|
135 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" /></a>'; |
|
136 | - |
|
137 | - return $ret; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param $var |
|
142 | - * @return bool |
|
143 | - */ |
|
144 | - public function emptyString($var) |
|
145 | - { |
|
146 | - return (strlen($var) > 0); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return mixed|string |
|
151 | - */ |
|
152 | - public function generateTag() |
|
153 | - { |
|
154 | - $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
155 | - $title = xoops_substr($title, 0, 10, ''); |
|
156 | - // Transformation des ponctuations |
|
157 | - // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
|
158 | - $pattern = array('/%09/', '/%20/', '/%21/', '/%22/', '/%23/', '/%25/', '/%26/', '/%27/', '/%28/', '/%29/', '/%2C/', '/%2F/', '/%3A/', '/%3B/', '/%3C/', '/%3D/', '/%3E/', '/%3F/', '/%40/', '/%5B/', '/%5C/', '/%5D/', '/%5E/', '/%7B/', '/%7C/', '/%7D/', '/%7E/', "/\./"); |
|
159 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
160 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
161 | - |
|
162 | - // Transformation des caract�res accentu�s |
|
163 | - // ° è é ê ë ç à â ä î ï ù ü û ô ö |
|
164 | - $pattern = array('/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/'); |
|
165 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
166 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
167 | - |
|
168 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
169 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
170 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
171 | - |
|
172 | - $title = $title . time(); |
|
173 | - $title = md5($title); |
|
174 | - |
|
175 | - return $title; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return mixed |
|
180 | - */ |
|
181 | - public function getCustomtagName() |
|
182 | - { |
|
183 | - $ret = $this->getVar('name'); |
|
184 | - |
|
185 | - return $ret; |
|
186 | - } |
|
39 | + public $content = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * SmartobjectCustomtag constructor. |
|
43 | + */ |
|
44 | + public function __construct() |
|
45 | + { |
|
46 | + $this->quickInitVar('customtagid', XOBJ_DTYPE_INT, true); |
|
47 | + $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_NAME, _CO_SOBJECT_CUSTOMTAG_NAME_DSC); |
|
48 | + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA, false, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION, _CO_SOBJECT_CUSTOMTAG_DESCRIPTION_DSC); |
|
49 | + $this->quickInitVar('content', XOBJ_DTYPE_TXTAREA, true, _CO_SOBJECT_CUSTOMTAG_CONTENT, _CO_SOBJECT_CUSTOMTAG_CONTENT_DSC); |
|
50 | + $this->quickInitVar('language', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CUSTOMTAG_LANGUAGE, _CO_SOBJECT_CUSTOMTAG_LANGUAGE_DSC); |
|
51 | + |
|
52 | + $this->initNonPersistableVar('dohtml', XOBJ_DTYPE_INT, 'class', 'dohtml', '', true); |
|
53 | + $this->initNonPersistableVar('doimage', XOBJ_DTYPE_INT, 'class', 'doimage', '', true); |
|
54 | + $this->initNonPersistableVar('doxcode', XOBJ_DTYPE_INT, 'class', 'doxcode', '', true); |
|
55 | + $this->initNonPersistableVar('dosmiley', XOBJ_DTYPE_INT, 'class', 'dosmiley', '', true); |
|
56 | + |
|
57 | + $this->setControl('content', array( |
|
58 | + 'name' => 'textarea', |
|
59 | + 'form_editor' => 'textarea', |
|
60 | + 'form_rows' => 25 |
|
61 | + )); |
|
62 | + $this->setControl('language', array( |
|
63 | + 'name' => 'language', |
|
64 | + 'all' => true |
|
65 | + )); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param string $key |
|
70 | + * @param string $format |
|
71 | + * @return mixed |
|
72 | + */ |
|
73 | + public function getVar($key, $format = 's') |
|
74 | + { |
|
75 | + if ($format === 's' && in_array($key, array())) { |
|
76 | + // return call_user_func(array($this, $key)); |
|
77 | + return $this->{$key}(); |
|
78 | + } |
|
79 | + |
|
80 | + return parent::getVar($key, $format); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return bool|mixed |
|
85 | + */ |
|
86 | + public function render() |
|
87 | + { |
|
88 | + if (!$this->content) { |
|
89 | + $ret = $this->getVar('content'); |
|
90 | + $this->content = $ret; |
|
91 | + } |
|
92 | + |
|
93 | + return $this->content; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return bool|mixed|string |
|
98 | + */ |
|
99 | + public function renderWithPhp() |
|
100 | + { |
|
101 | + if (!$this->content) { |
|
102 | + $ret = $this->getVar('content'); |
|
103 | + $this->content = $ret; |
|
104 | + } else { |
|
105 | + $ret = $this->content; |
|
106 | + } |
|
107 | + |
|
108 | + // check for PHP if we are not on admin side |
|
109 | + if (!defined('XOOPS_CPFUNC_LOADED') && !(strpos($ret, '[php]') === false)) { |
|
110 | + $ret = str_replace('[php]', '', $ret); |
|
111 | + // we have PHP code, let's evaluate |
|
112 | + eval($ret); |
|
113 | + |
|
114 | + return ''; |
|
115 | + } |
|
116 | + |
|
117 | + return $this->content; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getXoopsCode() |
|
124 | + { |
|
125 | + $ret = '[customtag]' . $this->getVar('tag', 'n') . '[/customtag]'; |
|
126 | + |
|
127 | + return $ret; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getCloneLink() |
|
134 | + { |
|
135 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/customtag.php?op=clone&customtagid=' . $this->id() . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'editcopy.png" style="vertical-align: middle;" alt="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" title="' . _CO_SOBJECT_CUSTOMTAG_CLONE . '" /></a>'; |
|
136 | + |
|
137 | + return $ret; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param $var |
|
142 | + * @return bool |
|
143 | + */ |
|
144 | + public function emptyString($var) |
|
145 | + { |
|
146 | + return (strlen($var) > 0); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return mixed|string |
|
151 | + */ |
|
152 | + public function generateTag() |
|
153 | + { |
|
154 | + $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
|
155 | + $title = xoops_substr($title, 0, 10, ''); |
|
156 | + // Transformation des ponctuations |
|
157 | + // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
|
158 | + $pattern = array('/%09/', '/%20/', '/%21/', '/%22/', '/%23/', '/%25/', '/%26/', '/%27/', '/%28/', '/%29/', '/%2C/', '/%2F/', '/%3A/', '/%3B/', '/%3C/', '/%3D/', '/%3E/', '/%3F/', '/%40/', '/%5B/', '/%5C/', '/%5D/', '/%5E/', '/%7B/', '/%7C/', '/%7D/', '/%7E/', "/\./"); |
|
159 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
160 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
161 | + |
|
162 | + // Transformation des caract�res accentu�s |
|
163 | + // ° è é ê ë ç à â ä î ï ù ü û ô ö |
|
164 | + $pattern = array('/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/'); |
|
165 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
166 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
167 | + |
|
168 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
169 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
170 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
171 | + |
|
172 | + $title = $title . time(); |
|
173 | + $title = md5($title); |
|
174 | + |
|
175 | + return $title; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return mixed |
|
180 | + */ |
|
181 | + public function getCustomtagName() |
|
182 | + { |
|
183 | + $ret = $this->getVar('name'); |
|
184 | + |
|
185 | + return $ret; |
|
186 | + } |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -191,48 +191,48 @@ discard block |
||
191 | 191 | */ |
192 | 192 | class SmartobjectCustomtagHandler extends SmartPersistableObjectHandler |
193 | 193 | { |
194 | - public $objects = false; |
|
195 | - |
|
196 | - /** |
|
197 | - * SmartobjectCustomtagHandler constructor. |
|
198 | - * @param object|XoopsDatabase $db |
|
199 | - */ |
|
200 | - public function __construct($db) |
|
201 | - { |
|
202 | - parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
203 | - $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @return array|bool |
|
208 | - */ |
|
209 | - public function getCustomtagsByName() |
|
210 | - { |
|
211 | - if (!$this->objects) { |
|
212 | - global $xoopsConfig; |
|
213 | - |
|
214 | - $ret = array(); |
|
215 | - |
|
216 | - $criteria = new CriteriaCompo(); |
|
217 | - |
|
218 | - $criteria_language = new CriteriaCompo(); |
|
219 | - $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
220 | - $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
221 | - $criteria->add($criteria_language); |
|
222 | - |
|
223 | - $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
224 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
225 | - |
|
226 | - if ($granted_ids && count($granted_ids) > 0) { |
|
227 | - $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
228 | - $customtagsObj = $this->getObjects($criteria, true); |
|
229 | - foreach ($customtagsObj as $customtagObj) { |
|
230 | - $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
231 | - } |
|
232 | - } |
|
233 | - $this->objects = $ret; |
|
234 | - } |
|
235 | - |
|
236 | - return $this->objects; |
|
237 | - } |
|
194 | + public $objects = false; |
|
195 | + |
|
196 | + /** |
|
197 | + * SmartobjectCustomtagHandler constructor. |
|
198 | + * @param object|XoopsDatabase $db |
|
199 | + */ |
|
200 | + public function __construct($db) |
|
201 | + { |
|
202 | + parent::__construct($db, 'customtag', 'customtagid', 'name', 'description', 'smartobject'); |
|
203 | + $this->addPermission('view', _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW, _CO_SOBJECT_CUSTOMTAG_PERMISSION_VIEW_DSC); |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @return array|bool |
|
208 | + */ |
|
209 | + public function getCustomtagsByName() |
|
210 | + { |
|
211 | + if (!$this->objects) { |
|
212 | + global $xoopsConfig; |
|
213 | + |
|
214 | + $ret = array(); |
|
215 | + |
|
216 | + $criteria = new CriteriaCompo(); |
|
217 | + |
|
218 | + $criteria_language = new CriteriaCompo(); |
|
219 | + $criteria_language->add(new Criteria('language', $xoopsConfig['language'])); |
|
220 | + $criteria_language->add(new Criteria('language', 'all'), 'OR'); |
|
221 | + $criteria->add($criteria_language); |
|
222 | + |
|
223 | + $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
|
224 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
225 | + |
|
226 | + if ($granted_ids && count($granted_ids) > 0) { |
|
227 | + $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
|
228 | + $customtagsObj = $this->getObjects($criteria, true); |
|
229 | + foreach ($customtagsObj as $customtagObj) { |
|
230 | + $ret[$customtagObj->getVar('name')] = $customtagObj; |
|
231 | + } |
|
232 | + } |
|
233 | + $this->objects = $ret; |
|
234 | + } |
|
235 | + |
|
236 | + return $this->objects; |
|
237 | + } |
|
238 | 238 | } |
@@ -221,7 +221,7 @@ |
||
221 | 221 | $criteria->add($criteria_language); |
222 | 222 | |
223 | 223 | $smartobjectPermissionsHandler = new SmartObjectPermissionHandler($this); |
224 | - $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
224 | + $granted_ids = $smartobjectPermissionsHandler->getGrantedItems('view'); |
|
225 | 225 | |
226 | 226 | if ($granted_ids && count($granted_ids) > 0) { |
227 | 227 | $criteria->add(new Criteria('customtagid', '(' . implode(', ', $granted_ids) . ')', 'IN')); |
@@ -12,8 +12,8 @@ |
||
12 | 12 | class SmartFormUploadElement extends XoopsFormFile |
13 | 13 | { |
14 | 14 | /** |
15 | - * @param $object |
|
16 | - * @param $key |
|
15 | + * @param string $object |
|
16 | + * @param string $key |
|
17 | 17 | */ |
18 | 18 | public function SmartFormFileElement($object, $key) |
19 | 19 | { |
@@ -11,25 +11,25 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormUploadElement extends XoopsFormFile |
13 | 13 | { |
14 | - /** |
|
15 | - * @param $object |
|
16 | - * @param $key |
|
17 | - */ |
|
18 | - public function SmartFormFileElement($object, $key) |
|
19 | - { |
|
20 | - parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | - $this->setExtra(' size=50'); |
|
22 | - } |
|
14 | + /** |
|
15 | + * @param $object |
|
16 | + * @param $key |
|
17 | + */ |
|
18 | + public function SmartFormFileElement($object, $key) |
|
19 | + { |
|
20 | + parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | + $this->setExtra(' size=50'); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * prepare HTML for output |
|
26 | - * |
|
27 | - * @return string HTML |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "' /> |
|
24 | + /** |
|
25 | + * prepare HTML for output |
|
26 | + * |
|
27 | + * @return string HTML |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "' /> |
|
32 | 32 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . " /> |
33 | 33 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "' />"; |
34 | - } |
|
34 | + } |
|
35 | 35 | } |
@@ -306,8 +306,8 @@ |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * @param $form_name |
|
310 | - * @param $form_caption |
|
309 | + * @param string $form_name |
|
310 | + * @param string $form_caption |
|
311 | 311 | * @param bool $submit_button_caption |
312 | 312 | */ |
313 | 313 | public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
@@ -30,776 +30,776 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class SmartObjectForm extends XoopsThemeForm |
32 | 32 | { |
33 | - public $targetObject = null; |
|
34 | - public $form_fields = null; |
|
35 | - public $_cancel_js_action = false; |
|
36 | - public $_custom_button = false; |
|
37 | - public $_captcha = false; |
|
38 | - public $_form_name = false; |
|
39 | - public $_form_caption = false; |
|
40 | - public $_submit_button_caption = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectForm constructor. |
|
44 | - * @param string $target |
|
45 | - * @param string $form_name |
|
46 | - * @param string $form_caption |
|
47 | - * @param string $form_action |
|
48 | - * @param null $form_fields |
|
49 | - * @param bool $submit_button_caption |
|
50 | - * @param bool $cancel_js_action |
|
51 | - * @param bool $captcha |
|
52 | - */ |
|
53 | - public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false) |
|
54 | - { |
|
55 | - $this->targetObject =& $target; |
|
56 | - $this->form_fields = $form_fields; |
|
57 | - $this->_cancel_js_action = $cancel_js_action; |
|
58 | - $this->_captcha = $captcha; |
|
59 | - $this->_form_name = $form_name; |
|
60 | - $this->_form_caption = $form_caption; |
|
61 | - $this->_submit_button_caption = $submit_button_caption; |
|
62 | - |
|
63 | - if (!isset($form_action)) { |
|
64 | - $form_action = xoops_getenv('PHP_SELF'); |
|
65 | - } |
|
66 | - |
|
67 | - $this->XoopsForm($form_caption, $form_name, $form_action); |
|
68 | - $this->setExtra('enctype="multipart/form-data"'); |
|
69 | - |
|
70 | - $this->createElements(); |
|
71 | - |
|
72 | - if ($captcha) { |
|
73 | - $this->addCaptcha(); |
|
74 | - } |
|
75 | - |
|
76 | - $this->createPermissionControls(); |
|
77 | - |
|
78 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
79 | - } |
|
80 | - |
|
81 | - public function addCaptcha() |
|
82 | - { |
|
83 | - include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'); |
|
84 | - $this->addElement(new XoopsFormCaptcha(), true); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param $name |
|
89 | - * @param $caption |
|
90 | - * @param bool $onclick |
|
91 | - */ |
|
92 | - public function addCustomButton($name, $caption, $onclick = false) |
|
93 | - { |
|
94 | - $custom_button_array = array( |
|
95 | - 'name' => $name, |
|
96 | - 'caption' => $caption, |
|
97 | - 'onclick' => $onclick |
|
98 | - ); |
|
99 | - $this->_custom_button[] = $custom_button_array; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Add an element to the form |
|
104 | - * |
|
105 | - * @param object &$formElement reference to a {@link XoopsFormElement} |
|
106 | - * @param bool $key |
|
107 | - * @param bool $var |
|
108 | - * @param bool|string $required is this a "required" element? |
|
109 | - */ |
|
110 | - public function addElement(&$formElement, $key = false, $var = false, $required = 'notset') |
|
111 | - { |
|
112 | - if ($key) { |
|
113 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
114 | - $formElement->setExtra('disabled="disabled"'); |
|
115 | - $formElement->setName($key . '-readonly'); |
|
116 | - // Since this element is disable, we still want to pass it's value in the form |
|
117 | - $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
118 | - $this->addElement($hidden); |
|
119 | - } |
|
120 | - $formElement->setDescription($var['form_dsc']); |
|
121 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
122 | - $hidden = new XoopsFormHidden('changedField', false); |
|
123 | - $this->addElement($hidden); |
|
124 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
125 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
126 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
127 | - } else { |
|
128 | - if (isset($var['form_extra'])) { |
|
129 | - $formElement->setExtra($var['form_extra']); |
|
130 | - } |
|
131 | - } |
|
132 | - $controls = $this->targetObject->controls; |
|
133 | - if (isset($controls[$key]['js'])) { |
|
134 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
135 | - } |
|
136 | - parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
137 | - } else { |
|
138 | - parent::addElement($formElement, $required === 'notset' ? false : true); |
|
139 | - } |
|
140 | - unset($formElement); |
|
141 | - } |
|
142 | - |
|
143 | - public function createElements() |
|
144 | - { |
|
145 | - $controls = $this->targetObject->controls; |
|
146 | - $vars = $this->targetObject->vars; |
|
147 | - foreach ($vars as $key => $var) { |
|
148 | - |
|
149 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
150 | - // need to be displayed, then we only create an hidden field |
|
151 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
152 | - $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
153 | - $this->addElement($elementToAdd, $key, $var, false); |
|
154 | - unset($elementToAdd); |
|
155 | - // If not, the we need to create the proper form control for this fields |
|
156 | - } else { |
|
157 | - // If this field has a specific control, we will use it |
|
158 | - |
|
159 | - if ($key === 'parentid') { |
|
160 | - /** |
|
161 | - * Why this ? |
|
162 | - */ |
|
163 | - } |
|
164 | - if (isset($controls[$key])) { |
|
165 | - /* If the control has name, it's because it's an object already present in the script |
|
33 | + public $targetObject = null; |
|
34 | + public $form_fields = null; |
|
35 | + public $_cancel_js_action = false; |
|
36 | + public $_custom_button = false; |
|
37 | + public $_captcha = false; |
|
38 | + public $_form_name = false; |
|
39 | + public $_form_caption = false; |
|
40 | + public $_submit_button_caption = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectForm constructor. |
|
44 | + * @param string $target |
|
45 | + * @param string $form_name |
|
46 | + * @param string $form_caption |
|
47 | + * @param string $form_action |
|
48 | + * @param null $form_fields |
|
49 | + * @param bool $submit_button_caption |
|
50 | + * @param bool $cancel_js_action |
|
51 | + * @param bool $captcha |
|
52 | + */ |
|
53 | + public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false) |
|
54 | + { |
|
55 | + $this->targetObject =& $target; |
|
56 | + $this->form_fields = $form_fields; |
|
57 | + $this->_cancel_js_action = $cancel_js_action; |
|
58 | + $this->_captcha = $captcha; |
|
59 | + $this->_form_name = $form_name; |
|
60 | + $this->_form_caption = $form_caption; |
|
61 | + $this->_submit_button_caption = $submit_button_caption; |
|
62 | + |
|
63 | + if (!isset($form_action)) { |
|
64 | + $form_action = xoops_getenv('PHP_SELF'); |
|
65 | + } |
|
66 | + |
|
67 | + $this->XoopsForm($form_caption, $form_name, $form_action); |
|
68 | + $this->setExtra('enctype="multipart/form-data"'); |
|
69 | + |
|
70 | + $this->createElements(); |
|
71 | + |
|
72 | + if ($captcha) { |
|
73 | + $this->addCaptcha(); |
|
74 | + } |
|
75 | + |
|
76 | + $this->createPermissionControls(); |
|
77 | + |
|
78 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
79 | + } |
|
80 | + |
|
81 | + public function addCaptcha() |
|
82 | + { |
|
83 | + include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'); |
|
84 | + $this->addElement(new XoopsFormCaptcha(), true); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param $name |
|
89 | + * @param $caption |
|
90 | + * @param bool $onclick |
|
91 | + */ |
|
92 | + public function addCustomButton($name, $caption, $onclick = false) |
|
93 | + { |
|
94 | + $custom_button_array = array( |
|
95 | + 'name' => $name, |
|
96 | + 'caption' => $caption, |
|
97 | + 'onclick' => $onclick |
|
98 | + ); |
|
99 | + $this->_custom_button[] = $custom_button_array; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Add an element to the form |
|
104 | + * |
|
105 | + * @param object &$formElement reference to a {@link XoopsFormElement} |
|
106 | + * @param bool $key |
|
107 | + * @param bool $var |
|
108 | + * @param bool|string $required is this a "required" element? |
|
109 | + */ |
|
110 | + public function addElement(&$formElement, $key = false, $var = false, $required = 'notset') |
|
111 | + { |
|
112 | + if ($key) { |
|
113 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
114 | + $formElement->setExtra('disabled="disabled"'); |
|
115 | + $formElement->setName($key . '-readonly'); |
|
116 | + // Since this element is disable, we still want to pass it's value in the form |
|
117 | + $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
118 | + $this->addElement($hidden); |
|
119 | + } |
|
120 | + $formElement->setDescription($var['form_dsc']); |
|
121 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
122 | + $hidden = new XoopsFormHidden('changedField', false); |
|
123 | + $this->addElement($hidden); |
|
124 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
125 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
126 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
127 | + } else { |
|
128 | + if (isset($var['form_extra'])) { |
|
129 | + $formElement->setExtra($var['form_extra']); |
|
130 | + } |
|
131 | + } |
|
132 | + $controls = $this->targetObject->controls; |
|
133 | + if (isset($controls[$key]['js'])) { |
|
134 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
135 | + } |
|
136 | + parent::addElement($formElement, $required === 'notset' ? $var['required'] : $required); |
|
137 | + } else { |
|
138 | + parent::addElement($formElement, $required === 'notset' ? false : true); |
|
139 | + } |
|
140 | + unset($formElement); |
|
141 | + } |
|
142 | + |
|
143 | + public function createElements() |
|
144 | + { |
|
145 | + $controls = $this->targetObject->controls; |
|
146 | + $vars = $this->targetObject->vars; |
|
147 | + foreach ($vars as $key => $var) { |
|
148 | + |
|
149 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
150 | + // need to be displayed, then we only create an hidden field |
|
151 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
152 | + $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
153 | + $this->addElement($elementToAdd, $key, $var, false); |
|
154 | + unset($elementToAdd); |
|
155 | + // If not, the we need to create the proper form control for this fields |
|
156 | + } else { |
|
157 | + // If this field has a specific control, we will use it |
|
158 | + |
|
159 | + if ($key === 'parentid') { |
|
160 | + /** |
|
161 | + * Why this ? |
|
162 | + */ |
|
163 | + } |
|
164 | + if (isset($controls[$key])) { |
|
165 | + /* If the control has name, it's because it's an object already present in the script |
|
166 | 166 | * for example, "user" |
167 | 167 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
168 | 168 | */ |
169 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
170 | - $controls[$key]['name'] = 'select'; |
|
171 | - } |
|
172 | - |
|
173 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
174 | - |
|
175 | - // Adding on the form, the control for this field |
|
176 | - $this->addElement($form_select, $key, $var); |
|
177 | - unset($form_select); |
|
178 | - |
|
179 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
180 | - } else { |
|
181 | - switch ($var['data_type']) { |
|
182 | - |
|
183 | - case XOBJ_DTYPE_TXTBOX: |
|
184 | - |
|
185 | - $form_text = $this->getControl('text', $key); |
|
186 | - $this->addElement($form_text, $key, $var); |
|
187 | - unset($form_text); |
|
188 | - break; |
|
189 | - |
|
190 | - case XOBJ_DTYPE_INT: |
|
191 | - $this->targetObject->setControl($key, array( |
|
192 | - 'name' => 'text', |
|
193 | - 'size' => '5' |
|
194 | - )); |
|
195 | - $form_text = $this->getControl('text', $key); |
|
196 | - $this->addElement($form_text, $key, $var); |
|
197 | - unset($form_text); |
|
198 | - break; |
|
199 | - |
|
200 | - case XOBJ_DTYPE_FLOAT: |
|
201 | - $this->targetObject->setControl($key, array( |
|
202 | - 'name' => 'text', |
|
203 | - 'size' => '5' |
|
204 | - )); |
|
205 | - $form_text = $this->getControl('text', $key); |
|
206 | - $this->addElement($form_text, $key, $var); |
|
207 | - unset($form_text); |
|
208 | - break; |
|
209 | - |
|
210 | - case XOBJ_DTYPE_LTIME: |
|
211 | - $form_date_time = $this->getControl('date_time', $key); |
|
212 | - $this->addElement($form_date_time, $key, $var); |
|
213 | - unset($form_date_time); |
|
214 | - break; |
|
215 | - |
|
216 | - case XOBJ_DTYPE_STIME: |
|
217 | - $form_date_time = $this->getControl('date', $key); |
|
218 | - $this->addElement($form_date_time, $key, $var); |
|
219 | - unset($form_date_time); |
|
220 | - break; |
|
221 | - |
|
222 | - case XOBJ_DTYPE_TIME_ONLY: |
|
223 | - $form_time = $this->getControl('time', $key); |
|
224 | - $this->addElement($form_time, $key, $var); |
|
225 | - unset($form_time); |
|
226 | - break; |
|
227 | - |
|
228 | - case XOBJ_DTYPE_CURRENCY: |
|
229 | - $this->targetObject->setControl($key, array( |
|
230 | - 'name' => 'text', |
|
231 | - 'size' => '15' |
|
232 | - )); |
|
233 | - $form_currency = $this->getControl('text', $key); |
|
234 | - $this->addElement($form_currency, $key, $var); |
|
235 | - unset($form_currency); |
|
236 | - break; |
|
237 | - |
|
238 | - case XOBJ_DTYPE_URLLINK: |
|
239 | - $form_urllink = $this->getControl('urllink', $key); |
|
240 | - $this->addElement($form_urllink, $key, $var); |
|
241 | - unset($form_urllink); |
|
242 | - break; |
|
243 | - |
|
244 | - case XOBJ_DTYPE_FILE: |
|
245 | - $form_file = $this->getControl('richfile', $key); |
|
246 | - $this->addElement($form_file, $key, $var); |
|
247 | - unset($form_file); |
|
248 | - break; |
|
249 | - |
|
250 | - case XOBJ_DTYPE_TXTAREA: |
|
251 | - |
|
252 | - $form_text_area = $this->getTextArea($key, $var); |
|
253 | - $this->addElement($form_text_area, $key, $var); |
|
254 | - unset($form_text_area); |
|
255 | - break; |
|
256 | - |
|
257 | - case XOBJ_DTYPE_ARRAY: |
|
258 | - // TODO: To come... |
|
259 | - break; |
|
260 | - case XOBJ_DTYPE_SOURCE: |
|
261 | - // TODO: To come... |
|
262 | - break; |
|
263 | - case XOBJ_DTYPE_FORM_SECTION: |
|
264 | - $section_control = new SmartFormSection($key, $var['value']); |
|
265 | - $this->addElement($section_control, $key, $var); |
|
266 | - unset($section_control); |
|
267 | - break; |
|
268 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
269 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
270 | - $this->addElement($section_control, $key, $var); |
|
271 | - unset($section_control); |
|
272 | - break; |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - } |
|
277 | - // Add an hidden field to store the URL of the page before this form |
|
278 | - $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
279 | - } |
|
280 | - |
|
281 | - public function createPermissionControls() |
|
282 | - { |
|
283 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
284 | - |
|
285 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
286 | - |
|
287 | - if ($permissions) { |
|
288 | - $memberHandler = xoops_getHandler('member'); |
|
289 | - $group_list = $memberHandler->getGroupList(); |
|
290 | - asort($group_list); |
|
291 | - foreach ($permissions as $permission) { |
|
292 | - if ($this->targetObject->isNew()) { |
|
293 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
294 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
295 | - } |
|
296 | - } else { |
|
297 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
298 | - } |
|
299 | - $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
300 | - $groups_select->setDescription($permission['description']); |
|
301 | - $groups_select->addOptionArray($group_list); |
|
302 | - $this->addElement($groups_select); |
|
303 | - unset($groups_select); |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * @param $form_name |
|
310 | - * @param $form_caption |
|
311 | - * @param bool $submit_button_caption |
|
312 | - */ |
|
313 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
314 | - { |
|
315 | - $button_tray = new XoopsFormElementTray('', ''); |
|
316 | - $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
317 | - if (!$submit_button_caption) { |
|
318 | - if ($this->targetObject->isNew()) { |
|
319 | - $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
320 | - } else { |
|
321 | - $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
322 | - } |
|
323 | - } else { |
|
324 | - $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
325 | - } |
|
326 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
327 | - $button_tray->addElement($butt_create); |
|
328 | - |
|
329 | - //creating custom buttons |
|
330 | - if ($this->_custom_button) { |
|
331 | - foreach ($this->_custom_button as $custom_button) { |
|
332 | - $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
333 | - if ($custom_button['onclick']) { |
|
334 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
335 | - } |
|
336 | - $button_tray->addElement($butt_custom); |
|
337 | - unset($butt_custom); |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - // creating the "cancel" button |
|
342 | - $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
343 | - if ($this->_cancel_js_action) { |
|
344 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
345 | - } else { |
|
346 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
347 | - } |
|
348 | - $button_tray->addElement($butt_cancel); |
|
349 | - |
|
350 | - $this->addElement($button_tray); |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * @param $controlName |
|
355 | - * @param $key |
|
356 | - * @return XoopsFormLabel |
|
357 | - */ |
|
358 | - public function getControl($controlName, $key) |
|
359 | - { |
|
360 | - switch ($controlName) { |
|
361 | - case 'check': |
|
362 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'); |
|
363 | - $control = $this->targetObject->getControl($key); |
|
364 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
365 | - $controlObj->addOptionArray($control['options']); |
|
366 | - |
|
367 | - return $controlObj; |
|
368 | - break; |
|
369 | - |
|
370 | - case 'color': |
|
371 | - $control = $this->targetObject->getControl($key); |
|
372 | - $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
373 | - |
|
374 | - return $controlObj; |
|
375 | - break; |
|
376 | - |
|
377 | - case 'radio': |
|
378 | - $control = $this->targetObject->getControl($key); |
|
379 | - |
|
380 | - $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
381 | - $controlObj->addOptionArray($control['options']); |
|
382 | - |
|
383 | - return $controlObj; |
|
384 | - break; |
|
385 | - |
|
386 | - case 'label': |
|
387 | - return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
388 | - break; |
|
389 | - |
|
390 | - case 'textarea': |
|
391 | - return $this->getTextArea($key); |
|
392 | - |
|
393 | - case 'theme': |
|
394 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
395 | - |
|
396 | - case 'theme_multi': |
|
397 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
398 | - break; |
|
399 | - |
|
400 | - case 'timezone': |
|
401 | - return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
402 | - break; |
|
403 | - |
|
404 | - case 'group': |
|
405 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
406 | - break; |
|
407 | - |
|
408 | - case 'group_multi': |
|
409 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
410 | - break; |
|
411 | - |
|
412 | - /*case 'user': |
|
169 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
170 | + $controls[$key]['name'] = 'select'; |
|
171 | + } |
|
172 | + |
|
173 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
174 | + |
|
175 | + // Adding on the form, the control for this field |
|
176 | + $this->addElement($form_select, $key, $var); |
|
177 | + unset($form_select); |
|
178 | + |
|
179 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
180 | + } else { |
|
181 | + switch ($var['data_type']) { |
|
182 | + |
|
183 | + case XOBJ_DTYPE_TXTBOX: |
|
184 | + |
|
185 | + $form_text = $this->getControl('text', $key); |
|
186 | + $this->addElement($form_text, $key, $var); |
|
187 | + unset($form_text); |
|
188 | + break; |
|
189 | + |
|
190 | + case XOBJ_DTYPE_INT: |
|
191 | + $this->targetObject->setControl($key, array( |
|
192 | + 'name' => 'text', |
|
193 | + 'size' => '5' |
|
194 | + )); |
|
195 | + $form_text = $this->getControl('text', $key); |
|
196 | + $this->addElement($form_text, $key, $var); |
|
197 | + unset($form_text); |
|
198 | + break; |
|
199 | + |
|
200 | + case XOBJ_DTYPE_FLOAT: |
|
201 | + $this->targetObject->setControl($key, array( |
|
202 | + 'name' => 'text', |
|
203 | + 'size' => '5' |
|
204 | + )); |
|
205 | + $form_text = $this->getControl('text', $key); |
|
206 | + $this->addElement($form_text, $key, $var); |
|
207 | + unset($form_text); |
|
208 | + break; |
|
209 | + |
|
210 | + case XOBJ_DTYPE_LTIME: |
|
211 | + $form_date_time = $this->getControl('date_time', $key); |
|
212 | + $this->addElement($form_date_time, $key, $var); |
|
213 | + unset($form_date_time); |
|
214 | + break; |
|
215 | + |
|
216 | + case XOBJ_DTYPE_STIME: |
|
217 | + $form_date_time = $this->getControl('date', $key); |
|
218 | + $this->addElement($form_date_time, $key, $var); |
|
219 | + unset($form_date_time); |
|
220 | + break; |
|
221 | + |
|
222 | + case XOBJ_DTYPE_TIME_ONLY: |
|
223 | + $form_time = $this->getControl('time', $key); |
|
224 | + $this->addElement($form_time, $key, $var); |
|
225 | + unset($form_time); |
|
226 | + break; |
|
227 | + |
|
228 | + case XOBJ_DTYPE_CURRENCY: |
|
229 | + $this->targetObject->setControl($key, array( |
|
230 | + 'name' => 'text', |
|
231 | + 'size' => '15' |
|
232 | + )); |
|
233 | + $form_currency = $this->getControl('text', $key); |
|
234 | + $this->addElement($form_currency, $key, $var); |
|
235 | + unset($form_currency); |
|
236 | + break; |
|
237 | + |
|
238 | + case XOBJ_DTYPE_URLLINK: |
|
239 | + $form_urllink = $this->getControl('urllink', $key); |
|
240 | + $this->addElement($form_urllink, $key, $var); |
|
241 | + unset($form_urllink); |
|
242 | + break; |
|
243 | + |
|
244 | + case XOBJ_DTYPE_FILE: |
|
245 | + $form_file = $this->getControl('richfile', $key); |
|
246 | + $this->addElement($form_file, $key, $var); |
|
247 | + unset($form_file); |
|
248 | + break; |
|
249 | + |
|
250 | + case XOBJ_DTYPE_TXTAREA: |
|
251 | + |
|
252 | + $form_text_area = $this->getTextArea($key, $var); |
|
253 | + $this->addElement($form_text_area, $key, $var); |
|
254 | + unset($form_text_area); |
|
255 | + break; |
|
256 | + |
|
257 | + case XOBJ_DTYPE_ARRAY: |
|
258 | + // TODO: To come... |
|
259 | + break; |
|
260 | + case XOBJ_DTYPE_SOURCE: |
|
261 | + // TODO: To come... |
|
262 | + break; |
|
263 | + case XOBJ_DTYPE_FORM_SECTION: |
|
264 | + $section_control = new SmartFormSection($key, $var['value']); |
|
265 | + $this->addElement($section_control, $key, $var); |
|
266 | + unset($section_control); |
|
267 | + break; |
|
268 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
269 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
270 | + $this->addElement($section_control, $key, $var); |
|
271 | + unset($section_control); |
|
272 | + break; |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + } |
|
277 | + // Add an hidden field to store the URL of the page before this form |
|
278 | + $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
279 | + } |
|
280 | + |
|
281 | + public function createPermissionControls() |
|
282 | + { |
|
283 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
284 | + |
|
285 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
286 | + |
|
287 | + if ($permissions) { |
|
288 | + $memberHandler = xoops_getHandler('member'); |
|
289 | + $group_list = $memberHandler->getGroupList(); |
|
290 | + asort($group_list); |
|
291 | + foreach ($permissions as $permission) { |
|
292 | + if ($this->targetObject->isNew()) { |
|
293 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
294 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
295 | + } |
|
296 | + } else { |
|
297 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
298 | + } |
|
299 | + $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
300 | + $groups_select->setDescription($permission['description']); |
|
301 | + $groups_select->addOptionArray($group_list); |
|
302 | + $this->addElement($groups_select); |
|
303 | + unset($groups_select); |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * @param $form_name |
|
310 | + * @param $form_caption |
|
311 | + * @param bool $submit_button_caption |
|
312 | + */ |
|
313 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
314 | + { |
|
315 | + $button_tray = new XoopsFormElementTray('', ''); |
|
316 | + $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
317 | + if (!$submit_button_caption) { |
|
318 | + if ($this->targetObject->isNew()) { |
|
319 | + $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
320 | + } else { |
|
321 | + $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
322 | + } |
|
323 | + } else { |
|
324 | + $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
325 | + } |
|
326 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
327 | + $button_tray->addElement($butt_create); |
|
328 | + |
|
329 | + //creating custom buttons |
|
330 | + if ($this->_custom_button) { |
|
331 | + foreach ($this->_custom_button as $custom_button) { |
|
332 | + $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
333 | + if ($custom_button['onclick']) { |
|
334 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
335 | + } |
|
336 | + $button_tray->addElement($butt_custom); |
|
337 | + unset($butt_custom); |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + // creating the "cancel" button |
|
342 | + $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
343 | + if ($this->_cancel_js_action) { |
|
344 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
345 | + } else { |
|
346 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
347 | + } |
|
348 | + $button_tray->addElement($butt_cancel); |
|
349 | + |
|
350 | + $this->addElement($button_tray); |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * @param $controlName |
|
355 | + * @param $key |
|
356 | + * @return XoopsFormLabel |
|
357 | + */ |
|
358 | + public function getControl($controlName, $key) |
|
359 | + { |
|
360 | + switch ($controlName) { |
|
361 | + case 'check': |
|
362 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'); |
|
363 | + $control = $this->targetObject->getControl($key); |
|
364 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
365 | + $controlObj->addOptionArray($control['options']); |
|
366 | + |
|
367 | + return $controlObj; |
|
368 | + break; |
|
369 | + |
|
370 | + case 'color': |
|
371 | + $control = $this->targetObject->getControl($key); |
|
372 | + $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
373 | + |
|
374 | + return $controlObj; |
|
375 | + break; |
|
376 | + |
|
377 | + case 'radio': |
|
378 | + $control = $this->targetObject->getControl($key); |
|
379 | + |
|
380 | + $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
381 | + $controlObj->addOptionArray($control['options']); |
|
382 | + |
|
383 | + return $controlObj; |
|
384 | + break; |
|
385 | + |
|
386 | + case 'label': |
|
387 | + return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
388 | + break; |
|
389 | + |
|
390 | + case 'textarea': |
|
391 | + return $this->getTextArea($key); |
|
392 | + |
|
393 | + case 'theme': |
|
394 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
395 | + |
|
396 | + case 'theme_multi': |
|
397 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
398 | + break; |
|
399 | + |
|
400 | + case 'timezone': |
|
401 | + return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
402 | + break; |
|
403 | + |
|
404 | + case 'group': |
|
405 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
406 | + break; |
|
407 | + |
|
408 | + case 'group_multi': |
|
409 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
410 | + break; |
|
411 | + |
|
412 | + /*case 'user': |
|
413 | 413 | return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
414 | 414 | break;*/ |
415 | 415 | |
416 | - case 'user_multi': |
|
417 | - return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
418 | - break; |
|
419 | - |
|
420 | - case 'password': |
|
421 | - return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
422 | - break; |
|
423 | - |
|
424 | - case 'country': |
|
425 | - return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
426 | - break; |
|
427 | - |
|
428 | - case 'urllink': |
|
429 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'); |
|
430 | - |
|
431 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
432 | - break; |
|
433 | - |
|
434 | - case 'richfile': |
|
435 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'); |
|
436 | - |
|
437 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
438 | - break; |
|
439 | - case 'section': |
|
440 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'); |
|
441 | - |
|
442 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
443 | - break; |
|
444 | - |
|
445 | - default: |
|
446 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
447 | - if (!class_exists($classname)) { |
|
448 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
449 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'); |
|
450 | - } else { |
|
451 | - // perhaps this is a control created by the module |
|
452 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
453 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
454 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
455 | - $classFileName = strtolower($classname) . '.php'; |
|
456 | - |
|
457 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
458 | - include_once($moduleFormElementsPath . $classFileName); |
|
459 | - } else { |
|
460 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
461 | - |
|
462 | - return new XoopsFormLabel(); //Empty object |
|
463 | - } |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - return new $classname($this->targetObject, $key); |
|
468 | - break; |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @param $key |
|
474 | - * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
475 | - */ |
|
476 | - public function getTextArea($key) |
|
477 | - { |
|
478 | - $var = $this->targetObject->vars[$key]; |
|
479 | - |
|
480 | - // if no control has been created, let's create a default one |
|
481 | - if (!isset($this->targetObject->controls[$key])) { |
|
482 | - $control = array( |
|
483 | - 'name' => 'textarea', |
|
484 | - 'itemHandler' => false, |
|
485 | - 'method' => false, |
|
486 | - 'module' => false, |
|
487 | - 'form_editor' => 'default' |
|
488 | - ); |
|
489 | - } else { |
|
490 | - $control = $this->targetObject->controls[$key]; |
|
491 | - } |
|
492 | - $xoops22 = smart_isXoops22(); |
|
493 | - |
|
494 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
495 | - /** |
|
496 | - * If the editor is 'default', retreive the default editor of this module |
|
497 | - */ |
|
498 | - if ($form_editor === 'default') { |
|
499 | - global $xoopsModuleConfig; |
|
500 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
501 | - } |
|
502 | - |
|
503 | - $caption = $var['form_caption']; |
|
504 | - $name = $key; |
|
505 | - |
|
506 | - $value = $this->targetObject->getVar($key); |
|
507 | - |
|
508 | - $value = $this->targetObject->getValueFor($key, true); |
|
509 | - |
|
510 | - $editor_configs = array(); |
|
511 | - $editor_configs['name'] = $name; |
|
512 | - $editor_configs['value'] = $value; |
|
513 | - if ($form_editor !== 'textarea') { |
|
514 | - $editor_configs['rows'] = 35; |
|
515 | - $editor_configs['cols'] = 60; |
|
516 | - } |
|
517 | - |
|
518 | - if (isset($control['rows'])) { |
|
519 | - $editor_configs['rows'] = $control['rows']; |
|
520 | - } |
|
521 | - if (isset($control['cols'])) { |
|
522 | - $editor_configs['cols'] = $control['cols']; |
|
523 | - } |
|
524 | - |
|
525 | - $editor_configs['width'] = '100%'; |
|
526 | - $editor_configs['height'] = '400px'; |
|
527 | - |
|
528 | - $dhtml = true; |
|
529 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
530 | - |
|
531 | - if (file_exists($xoopseditorclass)) { |
|
532 | - include_once($xoopseditorclass); |
|
533 | - $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
534 | - } else { |
|
535 | - switch ($form_editor) { |
|
536 | - |
|
537 | - case 'tiny': |
|
538 | - if (!$xoops22) { |
|
539 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
540 | - include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'); |
|
541 | - $editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
542 | - } else { |
|
543 | - if ($dhtml) { |
|
544 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
545 | - } else { |
|
546 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
547 | - } |
|
548 | - } |
|
549 | - } else { |
|
550 | - $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
551 | - } |
|
552 | - break; |
|
553 | - |
|
554 | - case 'dhtmltextarea': |
|
555 | - case 'dhtmltext': |
|
556 | - $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
557 | - if ($var['form_dsc']) { |
|
558 | - $editor->setDescription($var['form_dsc']); |
|
559 | - } |
|
560 | - break; |
|
561 | - |
|
562 | - case 'fckeditor': |
|
563 | - if (!$xoops22) { |
|
564 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
565 | - include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'); |
|
566 | - $editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
567 | - } else { |
|
568 | - if ($dhtml) { |
|
569 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
570 | - } else { |
|
571 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
572 | - } |
|
573 | - } |
|
574 | - } else { |
|
575 | - $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
576 | - } |
|
577 | - break; |
|
578 | - |
|
579 | - case 'inbetween': |
|
580 | - if (!$xoops22) { |
|
581 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
582 | - include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'); |
|
583 | - $editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
584 | - } else { |
|
585 | - if ($dhtml) { |
|
586 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
587 | - } else { |
|
588 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
589 | - } |
|
590 | - } |
|
591 | - } else { |
|
592 | - $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
593 | - } |
|
594 | - break; |
|
595 | - |
|
596 | - case 'koivi': |
|
597 | - if (!$xoops22) { |
|
598 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
599 | - include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
600 | - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
601 | - } else { |
|
602 | - if ($dhtml) { |
|
603 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
604 | - } else { |
|
605 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
606 | - } |
|
607 | - } |
|
608 | - } else { |
|
609 | - $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
610 | - } |
|
611 | - break; |
|
612 | - |
|
613 | - case 'spaw': |
|
614 | - if (!$xoops22) { |
|
615 | - if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
616 | - include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'); |
|
617 | - $editor = new XoopsFormSpaw($caption, $name, $value); |
|
618 | - } |
|
619 | - } else { |
|
620 | - $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
621 | - } |
|
622 | - break; |
|
623 | - |
|
624 | - case 'htmlarea': |
|
625 | - if (!$xoops22) { |
|
626 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
627 | - include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
628 | - $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
629 | - } |
|
630 | - } else { |
|
631 | - $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
632 | - } |
|
633 | - break; |
|
634 | - |
|
635 | - default: |
|
636 | - case 'textarea': |
|
637 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
638 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
639 | - |
|
640 | - $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
641 | - if ($var['form_dsc']) { |
|
642 | - $editor->setDescription($var['form_dsc']); |
|
643 | - } |
|
644 | - break; |
|
645 | - |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - return $editor; |
|
650 | - } |
|
651 | - |
|
652 | - /** |
|
653 | - * @param $key |
|
654 | - * @param $var |
|
655 | - * @param bool $multiple |
|
656 | - * @return XoopsFormSelect |
|
657 | - */ |
|
658 | - public function getThemeSelect($key, $var, $multiple = false) |
|
659 | - { |
|
660 | - $size = $multiple ? 5 : 1; |
|
661 | - $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
662 | - |
|
663 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
664 | - $dirlist = array(); |
|
665 | - while (false !== ($file = readdir($handle))) { |
|
666 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') { |
|
667 | - $dirlist[$file] = $file; |
|
668 | - } |
|
669 | - } |
|
670 | - closedir($handle); |
|
671 | - if (!empty($dirlist)) { |
|
672 | - asort($dirlist); |
|
673 | - $theme_select->addOptionArray($dirlist); |
|
674 | - } |
|
675 | - |
|
676 | - return $theme_select; |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * @param $keyname |
|
681 | - * @return bool |
|
682 | - */ |
|
683 | - public function &getElementById($keyname) |
|
684 | - { |
|
685 | - foreach ($this->_elements as $eleObj) { |
|
686 | - if ($eleObj->getName() == $keyname) { |
|
687 | - $ret =& $eleObj; |
|
688 | - break; |
|
689 | - } |
|
690 | - } |
|
691 | - |
|
692 | - return isset($ret) ? $ret : false; |
|
693 | - } |
|
694 | - |
|
695 | - /** |
|
696 | - * create HTML to output the form as a theme-enabled table with validation. |
|
697 | - * |
|
698 | - * @return string |
|
699 | - */ |
|
700 | - public function render() |
|
701 | - { |
|
702 | - $required = $this->getRequired(); |
|
703 | - $ret = " |
|
416 | + case 'user_multi': |
|
417 | + return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
418 | + break; |
|
419 | + |
|
420 | + case 'password': |
|
421 | + return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
422 | + break; |
|
423 | + |
|
424 | + case 'country': |
|
425 | + return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
426 | + break; |
|
427 | + |
|
428 | + case 'urllink': |
|
429 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'); |
|
430 | + |
|
431 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
432 | + break; |
|
433 | + |
|
434 | + case 'richfile': |
|
435 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'); |
|
436 | + |
|
437 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
438 | + break; |
|
439 | + case 'section': |
|
440 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'); |
|
441 | + |
|
442 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
443 | + break; |
|
444 | + |
|
445 | + default: |
|
446 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
447 | + if (!class_exists($classname)) { |
|
448 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
449 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'); |
|
450 | + } else { |
|
451 | + // perhaps this is a control created by the module |
|
452 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
453 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
454 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
455 | + $classFileName = strtolower($classname) . '.php'; |
|
456 | + |
|
457 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
458 | + include_once($moduleFormElementsPath . $classFileName); |
|
459 | + } else { |
|
460 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
461 | + |
|
462 | + return new XoopsFormLabel(); //Empty object |
|
463 | + } |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + return new $classname($this->targetObject, $key); |
|
468 | + break; |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @param $key |
|
474 | + * @return XoopsFormDhtmlTextArea|XoopsFormEditor|XoopsFormFckeditor|XoopsFormTextArea|XoopsFormTinyTextArea |
|
475 | + */ |
|
476 | + public function getTextArea($key) |
|
477 | + { |
|
478 | + $var = $this->targetObject->vars[$key]; |
|
479 | + |
|
480 | + // if no control has been created, let's create a default one |
|
481 | + if (!isset($this->targetObject->controls[$key])) { |
|
482 | + $control = array( |
|
483 | + 'name' => 'textarea', |
|
484 | + 'itemHandler' => false, |
|
485 | + 'method' => false, |
|
486 | + 'module' => false, |
|
487 | + 'form_editor' => 'default' |
|
488 | + ); |
|
489 | + } else { |
|
490 | + $control = $this->targetObject->controls[$key]; |
|
491 | + } |
|
492 | + $xoops22 = smart_isXoops22(); |
|
493 | + |
|
494 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
495 | + /** |
|
496 | + * If the editor is 'default', retreive the default editor of this module |
|
497 | + */ |
|
498 | + if ($form_editor === 'default') { |
|
499 | + global $xoopsModuleConfig; |
|
500 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
501 | + } |
|
502 | + |
|
503 | + $caption = $var['form_caption']; |
|
504 | + $name = $key; |
|
505 | + |
|
506 | + $value = $this->targetObject->getVar($key); |
|
507 | + |
|
508 | + $value = $this->targetObject->getValueFor($key, true); |
|
509 | + |
|
510 | + $editor_configs = array(); |
|
511 | + $editor_configs['name'] = $name; |
|
512 | + $editor_configs['value'] = $value; |
|
513 | + if ($form_editor !== 'textarea') { |
|
514 | + $editor_configs['rows'] = 35; |
|
515 | + $editor_configs['cols'] = 60; |
|
516 | + } |
|
517 | + |
|
518 | + if (isset($control['rows'])) { |
|
519 | + $editor_configs['rows'] = $control['rows']; |
|
520 | + } |
|
521 | + if (isset($control['cols'])) { |
|
522 | + $editor_configs['cols'] = $control['cols']; |
|
523 | + } |
|
524 | + |
|
525 | + $editor_configs['width'] = '100%'; |
|
526 | + $editor_configs['height'] = '400px'; |
|
527 | + |
|
528 | + $dhtml = true; |
|
529 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
530 | + |
|
531 | + if (file_exists($xoopseditorclass)) { |
|
532 | + include_once($xoopseditorclass); |
|
533 | + $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
534 | + } else { |
|
535 | + switch ($form_editor) { |
|
536 | + |
|
537 | + case 'tiny': |
|
538 | + if (!$xoops22) { |
|
539 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
540 | + include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'); |
|
541 | + $editor = new XoopsFormTinyTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
542 | + } else { |
|
543 | + if ($dhtml) { |
|
544 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
545 | + } else { |
|
546 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
547 | + } |
|
548 | + } |
|
549 | + } else { |
|
550 | + $editor = new XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
551 | + } |
|
552 | + break; |
|
553 | + |
|
554 | + case 'dhtmltextarea': |
|
555 | + case 'dhtmltext': |
|
556 | + $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
557 | + if ($var['form_dsc']) { |
|
558 | + $editor->setDescription($var['form_dsc']); |
|
559 | + } |
|
560 | + break; |
|
561 | + |
|
562 | + case 'fckeditor': |
|
563 | + if (!$xoops22) { |
|
564 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php')) { |
|
565 | + include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/fckeditor/formfckeditor.php'); |
|
566 | + $editor = new XoopsFormFckeditor(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
567 | + } else { |
|
568 | + if ($dhtml) { |
|
569 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
570 | + } else { |
|
571 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
572 | + } |
|
573 | + } |
|
574 | + } else { |
|
575 | + $editor = new XoopsFormEditor($caption, 'fckeditor', $editor_configs); |
|
576 | + } |
|
577 | + break; |
|
578 | + |
|
579 | + case 'inbetween': |
|
580 | + if (!$xoops22) { |
|
581 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php')) { |
|
582 | + include_once(XOOPS_ROOT_PATH . '/class/xoopseditor/inbetween/forminbetweentextarea.php'); |
|
583 | + $editor = new XoopsFormInbetweenTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '300px'), true); |
|
584 | + } else { |
|
585 | + if ($dhtml) { |
|
586 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
587 | + } else { |
|
588 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
589 | + } |
|
590 | + } |
|
591 | + } else { |
|
592 | + $editor = new XoopsFormEditor($caption, 'inbetween', $editor_configs); |
|
593 | + } |
|
594 | + break; |
|
595 | + |
|
596 | + case 'koivi': |
|
597 | + if (!$xoops22) { |
|
598 | + if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
599 | + include_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
600 | + $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
601 | + } else { |
|
602 | + if ($dhtml) { |
|
603 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
604 | + } else { |
|
605 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
606 | + } |
|
607 | + } |
|
608 | + } else { |
|
609 | + $editor = new XoopsFormEditor($caption, 'koivi', $editor_configs); |
|
610 | + } |
|
611 | + break; |
|
612 | + |
|
613 | + case 'spaw': |
|
614 | + if (!$xoops22) { |
|
615 | + if (is_readable(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php')) { |
|
616 | + include_once(XOOPS_ROOT_PATH . '/class/spaw/formspaw.php'); |
|
617 | + $editor = new XoopsFormSpaw($caption, $name, $value); |
|
618 | + } |
|
619 | + } else { |
|
620 | + $editor = new XoopsFormEditor($caption, 'spaw', $editor_configs); |
|
621 | + } |
|
622 | + break; |
|
623 | + |
|
624 | + case 'htmlarea': |
|
625 | + if (!$xoops22) { |
|
626 | + if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
627 | + include_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
628 | + $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
629 | + } |
|
630 | + } else { |
|
631 | + $editor = new XoopsFormEditor($caption, 'htmlarea', $editor_configs); |
|
632 | + } |
|
633 | + break; |
|
634 | + |
|
635 | + default: |
|
636 | + case 'textarea': |
|
637 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
638 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
639 | + |
|
640 | + $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
641 | + if ($var['form_dsc']) { |
|
642 | + $editor->setDescription($var['form_dsc']); |
|
643 | + } |
|
644 | + break; |
|
645 | + |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + return $editor; |
|
650 | + } |
|
651 | + |
|
652 | + /** |
|
653 | + * @param $key |
|
654 | + * @param $var |
|
655 | + * @param bool $multiple |
|
656 | + * @return XoopsFormSelect |
|
657 | + */ |
|
658 | + public function getThemeSelect($key, $var, $multiple = false) |
|
659 | + { |
|
660 | + $size = $multiple ? 5 : 1; |
|
661 | + $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
662 | + |
|
663 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
664 | + $dirlist = array(); |
|
665 | + while (false !== ($file = readdir($handle))) { |
|
666 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) !== 'cvs') { |
|
667 | + $dirlist[$file] = $file; |
|
668 | + } |
|
669 | + } |
|
670 | + closedir($handle); |
|
671 | + if (!empty($dirlist)) { |
|
672 | + asort($dirlist); |
|
673 | + $theme_select->addOptionArray($dirlist); |
|
674 | + } |
|
675 | + |
|
676 | + return $theme_select; |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * @param $keyname |
|
681 | + * @return bool |
|
682 | + */ |
|
683 | + public function &getElementById($keyname) |
|
684 | + { |
|
685 | + foreach ($this->_elements as $eleObj) { |
|
686 | + if ($eleObj->getName() == $keyname) { |
|
687 | + $ret =& $eleObj; |
|
688 | + break; |
|
689 | + } |
|
690 | + } |
|
691 | + |
|
692 | + return isset($ret) ? $ret : false; |
|
693 | + } |
|
694 | + |
|
695 | + /** |
|
696 | + * create HTML to output the form as a theme-enabled table with validation. |
|
697 | + * |
|
698 | + * @return string |
|
699 | + */ |
|
700 | + public function render() |
|
701 | + { |
|
702 | + $required = $this->getRequired(); |
|
703 | + $ret = " |
|
704 | 704 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
705 | 705 | <table width='100%' class='outer' cellspacing='1'> |
706 | 706 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
707 | 707 | '; |
708 | - $hidden = ''; |
|
709 | - $class = 'even'; |
|
710 | - foreach ($this->getElements() as $ele) { |
|
711 | - if (!is_object($ele)) { |
|
712 | - $ret .= $ele; |
|
713 | - } elseif (!$ele->isHidden()) { |
|
714 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
715 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
716 | - if ($ele->getDescription() != '') { |
|
717 | - $ret .= '<br /><br /><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
718 | - } |
|
719 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
720 | - } else { |
|
721 | - $hidden .= $ele->render(); |
|
722 | - } |
|
723 | - } |
|
724 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
725 | - $ret .= $this->renderValidationJS(true); |
|
726 | - |
|
727 | - return $ret; |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * assign to smarty form template instead of displaying directly |
|
732 | - * |
|
733 | - * @param object &$tpl reference to a {@link Smarty} object |
|
734 | - * @param bool $smartyName |
|
735 | - * @see Smarty |
|
736 | - */ |
|
737 | - public function assign(&$tpl, $smartyName = false) |
|
738 | - { |
|
739 | - $i = 0; |
|
740 | - $elements = array(); |
|
741 | - foreach ($this->getElements() as $ele) { |
|
742 | - $n = ($ele->getName() != '') ? $ele->getName() : $i; |
|
743 | - $elements[$n]['name'] = $ele->getName(); |
|
744 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
745 | - $elements[$n]['body'] = $ele->render(); |
|
746 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
747 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
748 | - $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
749 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
750 | - if ($ele->getDescription() != '') { |
|
751 | - $elements[$n]['description'] = $ele->getDescription(); |
|
752 | - } |
|
753 | - ++$i; |
|
754 | - } |
|
755 | - $js = $this->renderValidationJS(); |
|
756 | - if (!$smartyName) { |
|
757 | - $smartyName = $this->getName(); |
|
758 | - } |
|
759 | - |
|
760 | - $tpl->assign($smartyName, array( |
|
761 | - 'title' => $this->getTitle(), |
|
762 | - 'name' => $this->getName(), |
|
763 | - 'action' => $this->getAction(), |
|
764 | - 'method' => $this->getMethod(), |
|
765 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
766 | - 'javascript' => $js, |
|
767 | - 'elements' => $elements |
|
768 | - )); |
|
769 | - } |
|
770 | - |
|
771 | - /** |
|
772 | - * @param bool $withtags |
|
773 | - * @return string |
|
774 | - */ |
|
775 | - public function renderValidationJS($withtags = true) |
|
776 | - { |
|
777 | - $js = ''; |
|
778 | - if ($withtags) { |
|
779 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
780 | - } |
|
781 | - $myts = MyTextSanitizer::getInstance(); |
|
782 | - $formname = $this->getName(); |
|
783 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
784 | - // First, output code to check required elements |
|
785 | - $elements =& $this->getRequired(); |
|
786 | - foreach ($elements as $elt) { |
|
787 | - $eltname = $elt->getName(); |
|
788 | - $eltcaption = trim($elt->getCaption()); |
|
789 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
790 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
791 | - if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
792 | - $js .= 'var myOption = -1;'; |
|
793 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
708 | + $hidden = ''; |
|
709 | + $class = 'even'; |
|
710 | + foreach ($this->getElements() as $ele) { |
|
711 | + if (!is_object($ele)) { |
|
712 | + $ret .= $ele; |
|
713 | + } elseif (!$ele->isHidden()) { |
|
714 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
715 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
716 | + if ($ele->getDescription() != '') { |
|
717 | + $ret .= '<br /><br /><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
718 | + } |
|
719 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
720 | + } else { |
|
721 | + $hidden .= $ele->render(); |
|
722 | + } |
|
723 | + } |
|
724 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
725 | + $ret .= $this->renderValidationJS(true); |
|
726 | + |
|
727 | + return $ret; |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * assign to smarty form template instead of displaying directly |
|
732 | + * |
|
733 | + * @param object &$tpl reference to a {@link Smarty} object |
|
734 | + * @param bool $smartyName |
|
735 | + * @see Smarty |
|
736 | + */ |
|
737 | + public function assign(&$tpl, $smartyName = false) |
|
738 | + { |
|
739 | + $i = 0; |
|
740 | + $elements = array(); |
|
741 | + foreach ($this->getElements() as $ele) { |
|
742 | + $n = ($ele->getName() != '') ? $ele->getName() : $i; |
|
743 | + $elements[$n]['name'] = $ele->getName(); |
|
744 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
745 | + $elements[$n]['body'] = $ele->render(); |
|
746 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
747 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
748 | + $elements[$n]['section_close'] = get_class($ele) === 'SmartFormSectionClose'; |
|
749 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
750 | + if ($ele->getDescription() != '') { |
|
751 | + $elements[$n]['description'] = $ele->getDescription(); |
|
752 | + } |
|
753 | + ++$i; |
|
754 | + } |
|
755 | + $js = $this->renderValidationJS(); |
|
756 | + if (!$smartyName) { |
|
757 | + $smartyName = $this->getName(); |
|
758 | + } |
|
759 | + |
|
760 | + $tpl->assign($smartyName, array( |
|
761 | + 'title' => $this->getTitle(), |
|
762 | + 'name' => $this->getName(), |
|
763 | + 'action' => $this->getAction(), |
|
764 | + 'method' => $this->getMethod(), |
|
765 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
766 | + 'javascript' => $js, |
|
767 | + 'elements' => $elements |
|
768 | + )); |
|
769 | + } |
|
770 | + |
|
771 | + /** |
|
772 | + * @param bool $withtags |
|
773 | + * @return string |
|
774 | + */ |
|
775 | + public function renderValidationJS($withtags = true) |
|
776 | + { |
|
777 | + $js = ''; |
|
778 | + if ($withtags) { |
|
779 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
780 | + } |
|
781 | + $myts = MyTextSanitizer::getInstance(); |
|
782 | + $formname = $this->getName(); |
|
783 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
784 | + // First, output code to check required elements |
|
785 | + $elements =& $this->getRequired(); |
|
786 | + foreach ($elements as $elt) { |
|
787 | + $eltname = $elt->getName(); |
|
788 | + $eltcaption = trim($elt->getCaption()); |
|
789 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
790 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
791 | + if (strtolower(get_class($elt)) === 'xoopsformradio') { |
|
792 | + $js .= 'var myOption = -1;'; |
|
793 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
794 | 794 | if (myform.{$eltname}[i].checked) { |
795 | 795 | myOption = i; i = -1; |
796 | 796 | } |
797 | 797 | } |
798 | 798 | if (myOption == -1) { |
799 | 799 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
800 | - } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
801 | - $js .= 'var hasSelections = false;'; |
|
802 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
800 | + } elseif (strtolower(get_class($elt)) === 'smartformselect_multielement') { |
|
801 | + $js .= 'var hasSelections = false;'; |
|
802 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
803 | 803 | if (myform['{$eltname}[]'].options[i].selected) { |
804 | 804 | hasSelections = true; |
805 | 805 | } |
@@ -807,11 +807,11 @@ discard block |
||
807 | 807 | } |
808 | 808 | if (hasSelections == false) { |
809 | 809 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
810 | - } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
811 | - $js .= 'var hasSelections = false;'; |
|
812 | - //sometimes, there is an implicit '[]', sometimes not |
|
813 | - if (strpos($eltname, '[') === false) { |
|
814 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
810 | + } elseif (strtolower(get_class($elt)) === 'xoopsformcheckbox' || strtolower(get_class($elt)) === 'smartformcheckelement') { |
|
811 | + $js .= 'var hasSelections = false;'; |
|
812 | + //sometimes, there is an implicit '[]', sometimes not |
|
813 | + if (strpos($eltname, '[') === false) { |
|
814 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
815 | 815 | if (myform['{$eltname}[]'][i].checked) { |
816 | 816 | hasSelections = true; |
817 | 817 | } |
@@ -819,8 +819,8 @@ discard block |
||
819 | 819 | } |
820 | 820 | if (hasSelections == false) { |
821 | 821 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
822 | - } else { |
|
823 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
822 | + } else { |
|
823 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
824 | 824 | if (myform['{$eltname}'][i].checked) { |
825 | 825 | hasSelections = true; |
826 | 826 | } |
@@ -828,25 +828,25 @@ discard block |
||
828 | 828 | } |
829 | 829 | if (hasSelections == false) { |
830 | 830 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
831 | - } |
|
832 | - } else { |
|
833 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
834 | - } |
|
835 | - } |
|
836 | - // Now, handle custom validation code |
|
837 | - $elements =& $this->getElements(true); |
|
838 | - foreach ($elements as $elt) { |
|
839 | - if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
840 | - if ($eltjs = $elt->renderValidationJS()) { |
|
841 | - $js .= $eltjs . "\n"; |
|
842 | - } |
|
843 | - } |
|
844 | - } |
|
845 | - $js .= "return true;\n}\n"; |
|
846 | - if ($withtags) { |
|
847 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
848 | - } |
|
849 | - |
|
850 | - return $js; |
|
851 | - } |
|
831 | + } |
|
832 | + } else { |
|
833 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
834 | + } |
|
835 | + } |
|
836 | + // Now, handle custom validation code |
|
837 | + $elements =& $this->getElements(true); |
|
838 | + foreach ($elements as $elt) { |
|
839 | + if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
|
840 | + if ($eltjs = $elt->renderValidationJS()) { |
|
841 | + $js .= $eltjs . "\n"; |
|
842 | + } |
|
843 | + } |
|
844 | + } |
|
845 | + $js .= "return true;\n}\n"; |
|
846 | + if ($withtags) { |
|
847 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
848 | + } |
|
849 | + |
|
850 | + return $js; |
|
851 | + } |
|
852 | 852 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __construct(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false) |
54 | 54 | { |
55 | - $this->targetObject =& $target; |
|
55 | + $this->targetObject = & $target; |
|
56 | 56 | $this->form_fields = $form_fields; |
57 | 57 | $this->_cancel_js_action = $cancel_js_action; |
58 | 58 | $this->_captcha = $captcha; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function addCustomButton($name, $caption, $onclick = false) |
93 | 93 | { |
94 | - $custom_button_array = array( |
|
94 | + $custom_button_array = array( |
|
95 | 95 | 'name' => $name, |
96 | 96 | 'caption' => $caption, |
97 | 97 | 'onclick' => $onclick |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | |
287 | 287 | if ($permissions) { |
288 | 288 | $memberHandler = xoops_getHandler('member'); |
289 | - $group_list = $memberHandler->getGroupList(); |
|
289 | + $group_list = $memberHandler->getGroupList(); |
|
290 | 290 | asort($group_list); |
291 | 291 | foreach ($permissions as $permission) { |
292 | 292 | if ($this->targetObject->isNew()) { |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | { |
685 | 685 | foreach ($this->_elements as $eleObj) { |
686 | 686 | if ($eleObj->getName() == $keyname) { |
687 | - $ret =& $eleObj; |
|
687 | + $ret = & $eleObj; |
|
688 | 688 | break; |
689 | 689 | } |
690 | 690 | } |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | $formname = $this->getName(); |
783 | 783 | $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
784 | 784 | // First, output code to check required elements |
785 | - $elements =& $this->getRequired(); |
|
785 | + $elements = & $this->getRequired(); |
|
786 | 786 | foreach ($elements as $elt) { |
787 | 787 | $eltname = $elt->getName(); |
788 | 788 | $eltcaption = trim($elt->getCaption()); |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | } |
835 | 835 | } |
836 | 836 | // Now, handle custom validation code |
837 | - $elements =& $this->getElements(true); |
|
837 | + $elements = & $this->getElements(true); |
|
838 | 838 | foreach ($elements as $elt) { |
839 | 839 | if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) !== 'xoopsformcheckbox') { |
840 | 840 | if ($eltjs = $elt->renderValidationJS()) { |
@@ -237,7 +237,7 @@ |
||
237 | 237 | * Creates a random number with a specified number of $digits |
238 | 238 | * |
239 | 239 | * @param int $digits number of digits |
240 | - * @return return int random number |
|
240 | + * @return string int random number |
|
241 | 241 | * @author xHelp Team |
242 | 242 | * |
243 | 243 | * @access public |
@@ -46,227 +46,227 @@ |
||
46 | 46 | */ |
47 | 47 | class SmartobjectMemberHandler extends XoopsMemberHandler |
48 | 48 | { |
49 | - /** |
|
50 | - * constructor |
|
51 | - * @param XoopsDatabase $db |
|
52 | - */ |
|
53 | - public function __construct(XoopsDatabase $db) |
|
54 | - { |
|
55 | - parent::__construct($db); |
|
56 | - $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
57 | - } |
|
49 | + /** |
|
50 | + * constructor |
|
51 | + * @param XoopsDatabase $db |
|
52 | + */ |
|
53 | + public function __construct(XoopsDatabase $db) |
|
54 | + { |
|
55 | + parent::__construct($db); |
|
56 | + $this->_uHandler = xoops_getModuleHandler('user', 'smartobject'); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param $userObj |
|
61 | - * @param bool $groups |
|
62 | - * @param bool $notifyUser |
|
63 | - * @param bool $password |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function addAndActivateUser(&$userObj, $groups = false, $notifyUser = true, &$password = false) |
|
67 | - { |
|
68 | - $email = $userObj->getVar('email'); |
|
69 | - if (!$userObj->getVar('email') || $email == '') { |
|
70 | - $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
59 | + /** |
|
60 | + * @param $userObj |
|
61 | + * @param bool $groups |
|
62 | + * @param bool $notifyUser |
|
63 | + * @param bool $password |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function addAndActivateUser(&$userObj, $groups = false, $notifyUser = true, &$password = false) |
|
67 | + { |
|
68 | + $email = $userObj->getVar('email'); |
|
69 | + if (!$userObj->getVar('email') || $email == '') { |
|
70 | + $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL); |
|
71 | 71 | |
72 | - return false; |
|
73 | - } |
|
72 | + return false; |
|
73 | + } |
|
74 | 74 | |
75 | - $password = $userObj->getVar('pass'); |
|
76 | - // randomly generating the password if not already set |
|
77 | - if ('' === $password) { |
|
78 | - $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
79 | - } |
|
80 | - $userObj->setVar('pass', md5($password)); |
|
75 | + $password = $userObj->getVar('pass'); |
|
76 | + // randomly generating the password if not already set |
|
77 | + if ('' === $password) { |
|
78 | + $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6); |
|
79 | + } |
|
80 | + $userObj->setVar('pass', md5($password)); |
|
81 | 81 | |
82 | - // if no username is set, let's generate one |
|
83 | - $unamecount = 20; |
|
84 | - $uname = $userObj->getVar('uname'); |
|
85 | - if (!$uname || $uname == '') { |
|
86 | - $usernames = $this->genUserNames($email, $unamecount); |
|
87 | - $newuser = false; |
|
88 | - $i = 0; |
|
89 | - while ($newuser == false) { |
|
90 | - $crit = new Criteria('uname', $usernames[$i]); |
|
91 | - $count = $this->getUserCount($crit); |
|
92 | - if ($count == 0) { |
|
93 | - $newuser = true; |
|
94 | - } else { |
|
95 | - //Move to next username |
|
96 | - ++$i; |
|
97 | - if ($i == $unamecount) { |
|
98 | - //Get next batch of usernames to try, reset counter |
|
99 | - $usernames = $this->genUserNames($email, $unamecount); |
|
100 | - $i = 0; |
|
101 | - } |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
82 | + // if no username is set, let's generate one |
|
83 | + $unamecount = 20; |
|
84 | + $uname = $userObj->getVar('uname'); |
|
85 | + if (!$uname || $uname == '') { |
|
86 | + $usernames = $this->genUserNames($email, $unamecount); |
|
87 | + $newuser = false; |
|
88 | + $i = 0; |
|
89 | + while ($newuser == false) { |
|
90 | + $crit = new Criteria('uname', $usernames[$i]); |
|
91 | + $count = $this->getUserCount($crit); |
|
92 | + if ($count == 0) { |
|
93 | + $newuser = true; |
|
94 | + } else { |
|
95 | + //Move to next username |
|
96 | + ++$i; |
|
97 | + if ($i == $unamecount) { |
|
98 | + //Get next batch of usernames to try, reset counter |
|
99 | + $usernames = $this->genUserNames($email, $unamecount); |
|
100 | + $i = 0; |
|
101 | + } |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - global $xoopsConfig; |
|
106 | + global $xoopsConfig; |
|
107 | 107 | |
108 | - $configHandler = xoops_getHandler('config'); |
|
109 | - $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
110 | - switch ($xoopsConfigUser['activation_type']) { |
|
111 | - case 0: |
|
112 | - $level = 0; |
|
113 | - $mailtemplate = 'smartmail_activate_user.tpl'; |
|
114 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
115 | - break; |
|
116 | - case 1: |
|
117 | - $level = 1; |
|
118 | - $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
119 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
120 | - break; |
|
121 | - case 2: |
|
122 | - default: |
|
123 | - $level = 0; |
|
124 | - $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
125 | - $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
126 | - } |
|
108 | + $configHandler = xoops_getHandler('config'); |
|
109 | + $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
|
110 | + switch ($xoopsConfigUser['activation_type']) { |
|
111 | + case 0: |
|
112 | + $level = 0; |
|
113 | + $mailtemplate = 'smartmail_activate_user.tpl'; |
|
114 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email); |
|
115 | + break; |
|
116 | + case 1: |
|
117 | + $level = 1; |
|
118 | + $mailtemplate = 'smartmail_auto_activate_user.tpl'; |
|
119 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email); |
|
120 | + break; |
|
121 | + case 2: |
|
122 | + default: |
|
123 | + $level = 0; |
|
124 | + $mailtemplate = 'smartmail_admin_activate_user.tpl'; |
|
125 | + $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email); |
|
126 | + } |
|
127 | 127 | |
128 | - $userObj->setVar('uname', $usernames[$i]); |
|
129 | - $userObj->setVar('user_avatar', 'blank.gif'); |
|
130 | - $userObj->setVar('user_regdate', time()); |
|
131 | - $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
132 | - $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
133 | - $userObj->setVar('actkey', $actkey); |
|
134 | - $userObj->setVar('email', $email); |
|
135 | - $userObj->setVar('notify_method', 2); |
|
136 | - $userObj->setVar('level', $userObj); |
|
128 | + $userObj->setVar('uname', $usernames[$i]); |
|
129 | + $userObj->setVar('user_avatar', 'blank.gif'); |
|
130 | + $userObj->setVar('user_regdate', time()); |
|
131 | + $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']); |
|
132 | + $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8); |
|
133 | + $userObj->setVar('actkey', $actkey); |
|
134 | + $userObj->setVar('email', $email); |
|
135 | + $userObj->setVar('notify_method', 2); |
|
136 | + $userObj->setVar('level', $userObj); |
|
137 | 137 | |
138 | - if ($this->insertUser($userObj)) { |
|
138 | + if ($this->insertUser($userObj)) { |
|
139 | 139 | |
140 | - // if $groups=false, Add the user to Registered Users group |
|
141 | - if (!$groups) { |
|
142 | - $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
143 | - } else { |
|
144 | - foreach ($groups as $groupid) { |
|
145 | - $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
146 | - } |
|
147 | - } |
|
148 | - } else { |
|
149 | - return false; |
|
150 | - } |
|
140 | + // if $groups=false, Add the user to Registered Users group |
|
141 | + if (!$groups) { |
|
142 | + $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid')); |
|
143 | + } else { |
|
144 | + foreach ($groups as $groupid) { |
|
145 | + $this->addUserToGroup($groupid, $userObj->getVar('uid')); |
|
146 | + } |
|
147 | + } |
|
148 | + } else { |
|
149 | + return false; |
|
150 | + } |
|
151 | 151 | |
152 | - if ($notifyUser) { |
|
153 | - // send some notifications |
|
154 | - $xoopsMailer =& getMailer(); |
|
155 | - $xoopsMailer->useMail(); |
|
156 | - $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
157 | - $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
158 | - $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
159 | - $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
160 | - $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
161 | - $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
162 | - $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
163 | - $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
164 | - $xoopsMailer->setToUsers($userObj); |
|
165 | - $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
166 | - $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
167 | - $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
152 | + if ($notifyUser) { |
|
153 | + // send some notifications |
|
154 | + $xoopsMailer =& getMailer(); |
|
155 | + $xoopsMailer->useMail(); |
|
156 | + $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
|
157 | + $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
|
158 | + $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password); |
|
159 | + $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']); |
|
160 | + $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']); |
|
161 | + $xoopsMailer->assign('SITEURL', XOOPS_URL . '/'); |
|
162 | + $xoopsMailer->assign('NAME', $userObj->getVar('name')); |
|
163 | + $xoopsMailer->assign('UNAME', $userObj->getVar('uname')); |
|
164 | + $xoopsMailer->setToUsers($userObj); |
|
165 | + $xoopsMailer->setFromEmail($xoopsConfig['adminmail']); |
|
166 | + $xoopsMailer->setFromName($xoopsConfig['sitename']); |
|
167 | + $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename'])); |
|
168 | 168 | |
169 | - if (!$xoopsMailer->send(true)) { |
|
170 | - /** |
|
171 | - * @todo trap error if email was not sent |
|
172 | - */ |
|
173 | - $xoopsMailer->getErrors(true); |
|
174 | - } |
|
175 | - } |
|
169 | + if (!$xoopsMailer->send(true)) { |
|
170 | + /** |
|
171 | + * @todo trap error if email was not sent |
|
172 | + */ |
|
173 | + $xoopsMailer->getErrors(true); |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - return true; |
|
178 | - } |
|
177 | + return true; |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Generates an array of usernames |
|
182 | - * |
|
183 | - * @param string $email email of user |
|
184 | - * @param int $count number of names to generate |
|
185 | - * @return array $names |
|
186 | - * @internal param string $name name of user |
|
187 | - * @author xHelp Team |
|
188 | - * |
|
189 | - * @access public |
|
190 | - */ |
|
191 | - public function genUserNames($email, $count = 20) |
|
192 | - { |
|
193 | - $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
180 | + /** |
|
181 | + * Generates an array of usernames |
|
182 | + * |
|
183 | + * @param string $email email of user |
|
184 | + * @param int $count number of names to generate |
|
185 | + * @return array $names |
|
186 | + * @internal param string $name name of user |
|
187 | + * @author xHelp Team |
|
188 | + * |
|
189 | + * @access public |
|
190 | + */ |
|
191 | + public function genUserNames($email, $count = 20) |
|
192 | + { |
|
193 | + $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username |
|
194 | 194 | |
195 | - $names = array(); |
|
196 | - $userid = explode('@', $email); |
|
195 | + $names = array(); |
|
196 | + $userid = explode('@', $email); |
|
197 | 197 | |
198 | - $basename = ''; |
|
199 | - $hasbasename = false; |
|
200 | - $emailname = $userid[0]; |
|
198 | + $basename = ''; |
|
199 | + $hasbasename = false; |
|
200 | + $emailname = $userid[0]; |
|
201 | 201 | |
202 | - $names[] = $emailname; |
|
202 | + $names[] = $emailname; |
|
203 | 203 | |
204 | - if (strlen($name) > 0) { |
|
205 | - $name = explode(' ', trim($name)); |
|
206 | - if (count($name) > 1) { |
|
207 | - $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
208 | - } else { |
|
209 | - $basename = strtolower($name[0]); |
|
210 | - } |
|
211 | - $basename = xoops_substr($basename, 0, 60, ''); |
|
212 | - //Prevent Duplication of Email Username and Name |
|
213 | - if (!in_array($basename, $names)) { |
|
214 | - $names[] = $basename; |
|
215 | - $hasbasename = true; |
|
216 | - } |
|
217 | - } |
|
204 | + if (strlen($name) > 0) { |
|
205 | + $name = explode(' ', trim($name)); |
|
206 | + if (count($name) > 1) { |
|
207 | + $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]); |
|
208 | + } else { |
|
209 | + $basename = strtolower($name[0]); |
|
210 | + } |
|
211 | + $basename = xoops_substr($basename, 0, 60, ''); |
|
212 | + //Prevent Duplication of Email Username and Name |
|
213 | + if (!in_array($basename, $names)) { |
|
214 | + $names[] = $basename; |
|
215 | + $hasbasename = true; |
|
216 | + } |
|
217 | + } |
|
218 | 218 | |
219 | - $i = count($names); |
|
220 | - $onbasename = 1; |
|
221 | - while ($i < $count) { |
|
222 | - $num = $this->genRandNumber(); |
|
223 | - if ($onbasename < 0 && $hasbasename) { |
|
224 | - $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
225 | - } else { |
|
226 | - $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
227 | - } |
|
228 | - $i = count($names); |
|
229 | - $onbasename = ~$onbasename; |
|
230 | - $num = ''; |
|
231 | - } |
|
219 | + $i = count($names); |
|
220 | + $onbasename = 1; |
|
221 | + while ($i < $count) { |
|
222 | + $num = $this->genRandNumber(); |
|
223 | + if ($onbasename < 0 && $hasbasename) { |
|
224 | + $names[] = xoops_substr($basename, 0, 58, '') . $num; |
|
225 | + } else { |
|
226 | + $names[] = xoops_substr($emailname, 0, 58, '') . $num; |
|
227 | + } |
|
228 | + $i = count($names); |
|
229 | + $onbasename = ~$onbasename; |
|
230 | + $num = ''; |
|
231 | + } |
|
232 | 232 | |
233 | - return $names; |
|
234 | - } |
|
233 | + return $names; |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Creates a random number with a specified number of $digits |
|
238 | - * |
|
239 | - * @param int $digits number of digits |
|
240 | - * @return return int random number |
|
241 | - * @author xHelp Team |
|
242 | - * |
|
243 | - * @access public |
|
244 | - */ |
|
245 | - public function genRandNumber($digits = 2) |
|
246 | - { |
|
247 | - $this->initRand(); |
|
248 | - $tmp = array(); |
|
236 | + /** |
|
237 | + * Creates a random number with a specified number of $digits |
|
238 | + * |
|
239 | + * @param int $digits number of digits |
|
240 | + * @return return int random number |
|
241 | + * @author xHelp Team |
|
242 | + * |
|
243 | + * @access public |
|
244 | + */ |
|
245 | + public function genRandNumber($digits = 2) |
|
246 | + { |
|
247 | + $this->initRand(); |
|
248 | + $tmp = array(); |
|
249 | 249 | |
250 | - for ($i = 0; $i < $digits; ++$i) { |
|
251 | - $tmp[$i] = (mt_rand() % 9); |
|
252 | - } |
|
250 | + for ($i = 0; $i < $digits; ++$i) { |
|
251 | + $tmp[$i] = (mt_rand() % 9); |
|
252 | + } |
|
253 | 253 | |
254 | - return implode('', $tmp); |
|
255 | - } |
|
254 | + return implode('', $tmp); |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Gives the random number generator a seed to start from |
|
259 | - * |
|
260 | - * @return void |
|
261 | - * |
|
262 | - * @access public |
|
263 | - */ |
|
264 | - public function initRand() |
|
265 | - { |
|
266 | - static $randCalled = false; |
|
267 | - if (!$randCalled) { |
|
268 | - mt_srand((double)microtime() * 1000000); |
|
269 | - $randCalled = true; |
|
270 | - } |
|
271 | - } |
|
257 | + /** |
|
258 | + * Gives the random number generator a seed to start from |
|
259 | + * |
|
260 | + * @return void |
|
261 | + * |
|
262 | + * @access public |
|
263 | + */ |
|
264 | + public function initRand() |
|
265 | + { |
|
266 | + static $randCalled = false; |
|
267 | + if (!$randCalled) { |
|
268 | + mt_srand((double)microtime() * 1000000); |
|
269 | + $randCalled = true; |
|
270 | + } |
|
271 | + } |
|
272 | 272 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | global $xoopsConfig; |
107 | 107 | |
108 | - $configHandler = xoops_getHandler('config'); |
|
108 | + $configHandler = xoops_getHandler('config'); |
|
109 | 109 | $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
110 | 110 | switch ($xoopsConfigUser['activation_type']) { |
111 | 111 | case 0: |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | if ($notifyUser) { |
153 | 153 | // send some notifications |
154 | - $xoopsMailer =& getMailer(); |
|
154 | + $xoopsMailer = & getMailer(); |
|
155 | 155 | $xoopsMailer->useMail(); |
156 | 156 | $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template'); |
157 | 157 | $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl'); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | { |
266 | 266 | static $randCalled = false; |
267 | 267 | if (!$randCalled) { |
268 | - mt_srand((double)microtime() * 1000000); |
|
268 | + mt_srand((double) microtime() * 1000000); |
|
269 | 269 | $randCalled = true; |
270 | 270 | } |
271 | 271 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | - * @param $field |
|
144 | + * @param string $field |
|
145 | 145 | * @return bool |
146 | 146 | */ |
147 | 147 | public function fieldExists($field) |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | /** |
624 | 624 | * Use to update a table |
625 | 625 | * |
626 | - * @param object $table {@link SmartDbTable} that will be updated |
|
626 | + * @param SmartDbTable $table {@link SmartDbTable} that will be updated |
|
627 | 627 | * |
628 | 628 | * @see SmartDbTable |
629 | 629 | * |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | /** |
726 | 726 | * @param $module |
727 | 727 | * @param $item |
728 | - * @return bool |
|
728 | + * @return false|null |
|
729 | 729 | */ |
730 | 730 | public function upgradeObjectItem($module, $item) |
731 | 731 | { |
@@ -1,32 +1,32 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Contains the classes for updating database tables |
|
4 | - * |
|
5 | - * @license GNU |
|
6 | - * @author marcan <[email protected]> |
|
7 | - * @link http://www.smartfactory.ca The SmartFactory |
|
8 | - * @package SmartObject |
|
9 | - */ |
|
3 | + * Contains the classes for updating database tables |
|
4 | + * |
|
5 | + * @license GNU |
|
6 | + * @author marcan <[email protected]> |
|
7 | + * @link http://www.smartfactory.ca The SmartFactory |
|
8 | + * @package SmartObject |
|
9 | + */ |
|
10 | 10 | /** |
11 | - * SmartDbTable class |
|
12 | - * |
|
13 | - * Information about an individual table |
|
14 | - * |
|
15 | - * @package SmartObject |
|
16 | - * @author marcan <[email protected]> |
|
17 | - * @link http://www.smartfactory.ca The SmartFactory |
|
18 | - */ |
|
11 | + * SmartDbTable class |
|
12 | + * |
|
13 | + * Information about an individual table |
|
14 | + * |
|
15 | + * @package SmartObject |
|
16 | + * @author marcan <[email protected]> |
|
17 | + * @link http://www.smartfactory.ca The SmartFactory |
|
18 | + */ |
|
19 | 19 | // defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
20 | 20 | if (!defined('SMARTOBJECT_ROOT_PATH')) { |
21 | - include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
21 | + include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
22 | 22 | } |
23 | 23 | /** |
24 | - * Include the language constants for the SmartObjectDBUpdater |
|
25 | - */ |
|
24 | + * Include the language constants for the SmartObjectDBUpdater |
|
25 | + */ |
|
26 | 26 | global $xoopsConfig; |
27 | 27 | $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php'; |
28 | 28 | if (!file_exists($common_file)) { |
29 | - $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
29 | + $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php'; |
|
30 | 30 | } |
31 | 31 | include($common_file); |
32 | 32 | |
@@ -35,500 +35,500 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class SmartDbTable |
37 | 37 | { |
38 | - /** |
|
39 | - * @var string $_name name of the table |
|
40 | - */ |
|
41 | - public $_name; |
|
42 | - /** |
|
43 | - * @var string $_structure structure of the table |
|
44 | - */ |
|
45 | - public $_structure; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var array $_data containing valued of each records to be added |
|
49 | - */ |
|
50 | - public $_data; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array $_alteredFields containing fields to be altered |
|
54 | - */ |
|
55 | - public $_alteredFields; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var array $_newFields containing new fields to be added |
|
59 | - */ |
|
60 | - public $_newFields; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var array $_droppedFields containing fields to be dropped |
|
64 | - */ |
|
65 | - public $_droppedFields; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var array $_flagForDrop flag table to drop it |
|
69 | - */ |
|
70 | - public $_flagForDrop = false; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var array $_updatedFields containing fields which values will be updated |
|
74 | - */ |
|
75 | - public $_updatedFields; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var array $_updatedFields containing fields which values will be updated |
|
79 | - */ //felix |
|
80 | - public $_updatedWhere; |
|
81 | - |
|
82 | - public $_existingFieldsArray = false; |
|
83 | - |
|
84 | - /** |
|
85 | - * Constructor |
|
86 | - * |
|
87 | - * @param string $name name of the table |
|
88 | - * |
|
89 | - */ |
|
90 | - public function __construct($name) |
|
91 | - { |
|
92 | - $this->_name = $name; |
|
93 | - $this->_data = array(); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Return the table name, prefixed with site table prefix |
|
98 | - * |
|
99 | - * @return string table name |
|
100 | - * |
|
101 | - */ |
|
102 | - public function name() |
|
103 | - { |
|
104 | - global $xoopsDB; |
|
105 | - |
|
106 | - return $xoopsDB->prefix($this->_name); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Checks if the table already exists in the database |
|
111 | - * |
|
112 | - * @return bool TRUE if it exists, FALSE if not |
|
113 | - * |
|
114 | - */ |
|
115 | - public function exists() |
|
116 | - { |
|
117 | - return smart_TableExists($this->_name); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return mixed |
|
122 | - */ |
|
123 | - public function getExistingFieldsArray() |
|
124 | - { |
|
125 | - global $xoopsDB; |
|
126 | - $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
127 | - while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
128 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
129 | - if ($existing_field['Null'] !== 'YES') { |
|
130 | - $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
131 | - } |
|
132 | - if ($existing_field['Extra']) { |
|
133 | - $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
134 | - } |
|
135 | - if (!($existing_field['Default'] === null) && ($existing_field['Default'] || $existing_field['Default'] == '' || $existing_field['Default'] == 0)) { |
|
136 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - return $fields; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param $field |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function fieldExists($field) |
|
148 | - { |
|
149 | - $existingFields = $this->getExistingFieldsArray(); |
|
150 | - |
|
151 | - return isset($existingFields[$field]); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Set the table structure |
|
156 | - * |
|
157 | - * Example: |
|
158 | - * |
|
159 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
160 | - * `date` int(11) NOT NULL default '0', |
|
161 | - * `status` int(1) NOT NULL default '-1', |
|
162 | - * `itemid` int(11) NOT NULL default '0', |
|
163 | - * `uid` int(11) NOT NULL default '0', |
|
164 | - * `price` float NOT NULL default '0', |
|
165 | - * `currency` varchar(100) NOT NULL default '', |
|
166 | - * PRIMARY KEY (`transactionid`)"); |
|
167 | - * |
|
168 | - * @param string $structure table structure |
|
169 | - * |
|
170 | - */ |
|
171 | - public function setStructure($structure) |
|
172 | - { |
|
173 | - $this->_structure = $structure; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Return the table structure |
|
178 | - * |
|
179 | - * @return string table structure |
|
180 | - * |
|
181 | - */ |
|
182 | - public function getStructure() |
|
183 | - { |
|
184 | - return sprintf($this->_structure, $this->name()); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Add values of a record to be added |
|
189 | - * |
|
190 | - * @param string $data values of a record |
|
191 | - * |
|
192 | - */ |
|
193 | - public function setData($data) |
|
194 | - { |
|
195 | - $this->_data[] = $data; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get the data array |
|
200 | - * |
|
201 | - * @return array containing the records values to be added |
|
202 | - * |
|
203 | - */ |
|
204 | - public function getData() |
|
205 | - { |
|
206 | - return $this->_data; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * Use to insert data in a table |
|
211 | - * |
|
212 | - * @return bool true if success, false if an error occured |
|
213 | - * |
|
214 | - */ |
|
215 | - public function addData() |
|
216 | - { |
|
217 | - global $xoopsDB; |
|
218 | - foreach ($this->getData() as $data) { |
|
219 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
220 | - $ret = $xoopsDB->query($query); |
|
221 | - if (!$ret) { |
|
222 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br />'; |
|
223 | - } else { |
|
224 | - echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br />'; |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - return $ret; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Add a field to be added |
|
233 | - * |
|
234 | - * @param string $name name of the field |
|
235 | - * @param string $properties properties of the field |
|
236 | - * @param bool $newname |
|
237 | - * @param bool $showerror |
|
238 | - */ |
|
239 | - public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
240 | - { |
|
241 | - $field['name'] = $name; |
|
242 | - $field['properties'] = $properties; |
|
243 | - $field['showerror'] = $showerror; |
|
244 | - $field['newname'] = $newname; |
|
245 | - $this->_alteredFields[] = $field; |
|
246 | - } |
|
247 | - /** |
|
248 | - * Invert values 0 to 1 and 1 to 0 |
|
249 | - * |
|
250 | - * @param string $name name of the field |
|
251 | - * @param $newValue |
|
252 | - * @param $oldValue |
|
253 | - * @internal param string $old old propertie |
|
254 | - * @internal param string $new new propertie |
|
255 | - */ //felix |
|
256 | - public function addUpdatedWhere($name, $newValue, $oldValue) |
|
257 | - { |
|
258 | - $field['name'] = $name; |
|
259 | - $field['value'] = $newValue; |
|
260 | - $field['where'] = $oldValue; |
|
261 | - $this->_updatedWhere[] = $field; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Add new field of a record to be added |
|
266 | - * |
|
267 | - * @param string $name name of the field |
|
268 | - * @param string $properties properties of the field |
|
269 | - * |
|
270 | - */ |
|
271 | - public function addNewField($name, $properties) |
|
272 | - { |
|
273 | - $field['name'] = $name; |
|
274 | - $field['properties'] = $properties; |
|
275 | - $this->_newFields[] = $field; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Get fields that need to be altered |
|
280 | - * |
|
281 | - * @return array fields that need to be altered |
|
282 | - * |
|
283 | - */ |
|
284 | - public function getAlteredFields() |
|
285 | - { |
|
286 | - return $this->_alteredFields; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Add field for which the value will be updated |
|
291 | - * |
|
292 | - * @param string $name name of the field |
|
293 | - * @param string $value value to be set |
|
294 | - * |
|
295 | - */ |
|
296 | - public function addUpdatedField($name, $value) |
|
297 | - { |
|
298 | - $field['name'] = $name; |
|
299 | - $field['value'] = $value; |
|
300 | - $this->_updatedFields[] = $field; |
|
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Get new fields to be added |
|
305 | - * |
|
306 | - * @return array fields to be added |
|
307 | - * |
|
308 | - */ |
|
309 | - public function getNewFields() |
|
310 | - { |
|
311 | - return $this->_newFields; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Get fields which values need to be updated |
|
316 | - * |
|
317 | - * @return array fields which values need to be updated |
|
318 | - * |
|
319 | - */ |
|
320 | - public function getUpdatedFields() |
|
321 | - { |
|
322 | - return $this->_updatedFields; |
|
323 | - } |
|
324 | - /** |
|
325 | - * Get fields which values need to be updated |
|
326 | - * |
|
327 | - * @return array fields which values need to be updated |
|
328 | - * |
|
329 | - */ //felix |
|
330 | - public function getUpdatedWhere() |
|
331 | - { |
|
332 | - return $this->_updatedWhere; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Add values of a record to be added |
|
337 | - * |
|
338 | - * @param string $name name of the field |
|
339 | - * |
|
340 | - */ |
|
341 | - public function addDroppedField($name) |
|
342 | - { |
|
343 | - $this->_droppedFields[] = $name; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get fields that need to be dropped |
|
348 | - * |
|
349 | - * @return array fields that need to be dropped |
|
350 | - * |
|
351 | - */ |
|
352 | - public function getDroppedFields() |
|
353 | - { |
|
354 | - return $this->_droppedFields; |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Set the flag to drop the table |
|
359 | - * |
|
360 | - */ |
|
361 | - public function setFlagForDrop() |
|
362 | - { |
|
363 | - $this->_flagForDrop = true; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Use to create a table |
|
368 | - * |
|
369 | - * @return bool true if success, false if an error occured |
|
370 | - * |
|
371 | - */ |
|
372 | - public function createTable() |
|
373 | - { |
|
374 | - global $xoopsDB; |
|
375 | - $query = $this->getStructure(); |
|
376 | - $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
377 | - //xoops_debug($query); |
|
378 | - $ret = $xoopsDB->query($query); |
|
379 | - if (!$ret) { |
|
380 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
381 | - } else { |
|
382 | - echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br />'; |
|
383 | - } |
|
384 | - |
|
385 | - return $ret; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Use to drop a table |
|
390 | - * |
|
391 | - * @return bool true if success, false if an error occured |
|
392 | - * |
|
393 | - */ |
|
394 | - public function dropTable() |
|
395 | - { |
|
396 | - global $xoopsDB; |
|
397 | - $query = sprintf('DROP TABLE %s', $this->name()); |
|
398 | - $ret = $xoopsDB->query($query); |
|
399 | - if (!$ret) { |
|
400 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
401 | - |
|
402 | - return false; |
|
403 | - } else { |
|
404 | - echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br />'; |
|
405 | - |
|
406 | - return true; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Use to alter a table |
|
412 | - * |
|
413 | - * @return bool true if success, false if an error occured |
|
414 | - * |
|
415 | - */ |
|
416 | - public function alterTable() |
|
417 | - { |
|
418 | - global $xoopsDB; |
|
419 | - $ret = true; |
|
420 | - |
|
421 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
422 | - if (!$alteredField['newname']) { |
|
423 | - $alteredField['newname'] = $alteredField['name']; |
|
424 | - } |
|
425 | - |
|
426 | - $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
427 | - $ret = $ret && $xoopsDB->query($query); |
|
428 | - if ($alteredField['showerror']) { |
|
429 | - if (!$ret) { |
|
430 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
431 | - } else { |
|
432 | - echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br />'; |
|
433 | - } |
|
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - return $ret; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Use to add new fileds in the table |
|
442 | - * |
|
443 | - * @return bool true if success, false if an error occured |
|
444 | - * |
|
445 | - */ |
|
446 | - public function addNewFields() |
|
447 | - { |
|
448 | - global $xoopsDB; |
|
449 | - $ret = true; |
|
450 | - foreach ($this->getNewFields() as $newField) { |
|
451 | - $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
452 | - //echo $query; |
|
453 | - $ret = $ret && $xoopsDB->query($query); |
|
454 | - if (!$ret) { |
|
455 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br />'; |
|
456 | - } else { |
|
457 | - echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br />'; |
|
458 | - } |
|
459 | - } |
|
460 | - |
|
461 | - return $ret; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Use to update fields values |
|
466 | - * |
|
467 | - * @return bool true if success, false if an error occured |
|
468 | - * |
|
469 | - */ |
|
470 | - public function updateFieldsValues() |
|
471 | - { |
|
472 | - global $xoopsDB; |
|
473 | - $ret = true; |
|
474 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
475 | - $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
476 | - $ret = $ret && $xoopsDB->query($query); |
|
477 | - if (!$ret) { |
|
478 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
479 | - } else { |
|
480 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br />'; |
|
481 | - } |
|
482 | - } |
|
483 | - |
|
484 | - return $ret; |
|
485 | - } |
|
486 | - /** |
|
487 | - * Use to update fields values |
|
488 | - * |
|
489 | - * @return bool true if success, false if an error occured |
|
490 | - * |
|
491 | - */ //felix |
|
492 | - public function updateWhereValues() |
|
493 | - { |
|
494 | - global $xoopsDB; |
|
495 | - $ret = true; |
|
496 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
497 | - $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
498 | - //echo $query."<br>"; |
|
499 | - $ret = $ret && $xoopsDB->query($query); |
|
500 | - if (!$ret) { |
|
501 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
502 | - } else { |
|
503 | - echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br />'; |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - return $ret; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * Use to drop fields |
|
512 | - * |
|
513 | - * @return bool true if success, false if an error occured |
|
514 | - * |
|
515 | - */ |
|
516 | - public function dropFields() |
|
517 | - { |
|
518 | - global $xoopsDB; |
|
519 | - $ret = true; |
|
520 | - foreach ($this->getDroppedFields() as $droppedField) { |
|
521 | - $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
522 | - $ret = $ret && $xoopsDB->query($query); |
|
523 | - if (!$ret) { |
|
524 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
525 | - } else { |
|
526 | - echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br />'; |
|
527 | - } |
|
528 | - } |
|
529 | - |
|
530 | - return $ret; |
|
531 | - } |
|
38 | + /** |
|
39 | + * @var string $_name name of the table |
|
40 | + */ |
|
41 | + public $_name; |
|
42 | + /** |
|
43 | + * @var string $_structure structure of the table |
|
44 | + */ |
|
45 | + public $_structure; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var array $_data containing valued of each records to be added |
|
49 | + */ |
|
50 | + public $_data; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array $_alteredFields containing fields to be altered |
|
54 | + */ |
|
55 | + public $_alteredFields; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var array $_newFields containing new fields to be added |
|
59 | + */ |
|
60 | + public $_newFields; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var array $_droppedFields containing fields to be dropped |
|
64 | + */ |
|
65 | + public $_droppedFields; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var array $_flagForDrop flag table to drop it |
|
69 | + */ |
|
70 | + public $_flagForDrop = false; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var array $_updatedFields containing fields which values will be updated |
|
74 | + */ |
|
75 | + public $_updatedFields; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var array $_updatedFields containing fields which values will be updated |
|
79 | + */ //felix |
|
80 | + public $_updatedWhere; |
|
81 | + |
|
82 | + public $_existingFieldsArray = false; |
|
83 | + |
|
84 | + /** |
|
85 | + * Constructor |
|
86 | + * |
|
87 | + * @param string $name name of the table |
|
88 | + * |
|
89 | + */ |
|
90 | + public function __construct($name) |
|
91 | + { |
|
92 | + $this->_name = $name; |
|
93 | + $this->_data = array(); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Return the table name, prefixed with site table prefix |
|
98 | + * |
|
99 | + * @return string table name |
|
100 | + * |
|
101 | + */ |
|
102 | + public function name() |
|
103 | + { |
|
104 | + global $xoopsDB; |
|
105 | + |
|
106 | + return $xoopsDB->prefix($this->_name); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Checks if the table already exists in the database |
|
111 | + * |
|
112 | + * @return bool TRUE if it exists, FALSE if not |
|
113 | + * |
|
114 | + */ |
|
115 | + public function exists() |
|
116 | + { |
|
117 | + return smart_TableExists($this->_name); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return mixed |
|
122 | + */ |
|
123 | + public function getExistingFieldsArray() |
|
124 | + { |
|
125 | + global $xoopsDB; |
|
126 | + $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name()); |
|
127 | + while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
128 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
129 | + if ($existing_field['Null'] !== 'YES') { |
|
130 | + $fields[$existing_field['Field']] .= ' NOT NULL'; |
|
131 | + } |
|
132 | + if ($existing_field['Extra']) { |
|
133 | + $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra']; |
|
134 | + } |
|
135 | + if (!($existing_field['Default'] === null) && ($existing_field['Default'] || $existing_field['Default'] == '' || $existing_field['Default'] == 0)) { |
|
136 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + return $fields; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param $field |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function fieldExists($field) |
|
148 | + { |
|
149 | + $existingFields = $this->getExistingFieldsArray(); |
|
150 | + |
|
151 | + return isset($existingFields[$field]); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Set the table structure |
|
156 | + * |
|
157 | + * Example: |
|
158 | + * |
|
159 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
160 | + * `date` int(11) NOT NULL default '0', |
|
161 | + * `status` int(1) NOT NULL default '-1', |
|
162 | + * `itemid` int(11) NOT NULL default '0', |
|
163 | + * `uid` int(11) NOT NULL default '0', |
|
164 | + * `price` float NOT NULL default '0', |
|
165 | + * `currency` varchar(100) NOT NULL default '', |
|
166 | + * PRIMARY KEY (`transactionid`)"); |
|
167 | + * |
|
168 | + * @param string $structure table structure |
|
169 | + * |
|
170 | + */ |
|
171 | + public function setStructure($structure) |
|
172 | + { |
|
173 | + $this->_structure = $structure; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Return the table structure |
|
178 | + * |
|
179 | + * @return string table structure |
|
180 | + * |
|
181 | + */ |
|
182 | + public function getStructure() |
|
183 | + { |
|
184 | + return sprintf($this->_structure, $this->name()); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Add values of a record to be added |
|
189 | + * |
|
190 | + * @param string $data values of a record |
|
191 | + * |
|
192 | + */ |
|
193 | + public function setData($data) |
|
194 | + { |
|
195 | + $this->_data[] = $data; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get the data array |
|
200 | + * |
|
201 | + * @return array containing the records values to be added |
|
202 | + * |
|
203 | + */ |
|
204 | + public function getData() |
|
205 | + { |
|
206 | + return $this->_data; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * Use to insert data in a table |
|
211 | + * |
|
212 | + * @return bool true if success, false if an error occured |
|
213 | + * |
|
214 | + */ |
|
215 | + public function addData() |
|
216 | + { |
|
217 | + global $xoopsDB; |
|
218 | + foreach ($this->getData() as $data) { |
|
219 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
220 | + $ret = $xoopsDB->query($query); |
|
221 | + if (!$ret) { |
|
222 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br />'; |
|
223 | + } else { |
|
224 | + echo ' ' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br />'; |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + return $ret; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Add a field to be added |
|
233 | + * |
|
234 | + * @param string $name name of the field |
|
235 | + * @param string $properties properties of the field |
|
236 | + * @param bool $newname |
|
237 | + * @param bool $showerror |
|
238 | + */ |
|
239 | + public function addAlteredField($name, $properties, $newname = false, $showerror = true) |
|
240 | + { |
|
241 | + $field['name'] = $name; |
|
242 | + $field['properties'] = $properties; |
|
243 | + $field['showerror'] = $showerror; |
|
244 | + $field['newname'] = $newname; |
|
245 | + $this->_alteredFields[] = $field; |
|
246 | + } |
|
247 | + /** |
|
248 | + * Invert values 0 to 1 and 1 to 0 |
|
249 | + * |
|
250 | + * @param string $name name of the field |
|
251 | + * @param $newValue |
|
252 | + * @param $oldValue |
|
253 | + * @internal param string $old old propertie |
|
254 | + * @internal param string $new new propertie |
|
255 | + */ //felix |
|
256 | + public function addUpdatedWhere($name, $newValue, $oldValue) |
|
257 | + { |
|
258 | + $field['name'] = $name; |
|
259 | + $field['value'] = $newValue; |
|
260 | + $field['where'] = $oldValue; |
|
261 | + $this->_updatedWhere[] = $field; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Add new field of a record to be added |
|
266 | + * |
|
267 | + * @param string $name name of the field |
|
268 | + * @param string $properties properties of the field |
|
269 | + * |
|
270 | + */ |
|
271 | + public function addNewField($name, $properties) |
|
272 | + { |
|
273 | + $field['name'] = $name; |
|
274 | + $field['properties'] = $properties; |
|
275 | + $this->_newFields[] = $field; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Get fields that need to be altered |
|
280 | + * |
|
281 | + * @return array fields that need to be altered |
|
282 | + * |
|
283 | + */ |
|
284 | + public function getAlteredFields() |
|
285 | + { |
|
286 | + return $this->_alteredFields; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Add field for which the value will be updated |
|
291 | + * |
|
292 | + * @param string $name name of the field |
|
293 | + * @param string $value value to be set |
|
294 | + * |
|
295 | + */ |
|
296 | + public function addUpdatedField($name, $value) |
|
297 | + { |
|
298 | + $field['name'] = $name; |
|
299 | + $field['value'] = $value; |
|
300 | + $this->_updatedFields[] = $field; |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Get new fields to be added |
|
305 | + * |
|
306 | + * @return array fields to be added |
|
307 | + * |
|
308 | + */ |
|
309 | + public function getNewFields() |
|
310 | + { |
|
311 | + return $this->_newFields; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Get fields which values need to be updated |
|
316 | + * |
|
317 | + * @return array fields which values need to be updated |
|
318 | + * |
|
319 | + */ |
|
320 | + public function getUpdatedFields() |
|
321 | + { |
|
322 | + return $this->_updatedFields; |
|
323 | + } |
|
324 | + /** |
|
325 | + * Get fields which values need to be updated |
|
326 | + * |
|
327 | + * @return array fields which values need to be updated |
|
328 | + * |
|
329 | + */ //felix |
|
330 | + public function getUpdatedWhere() |
|
331 | + { |
|
332 | + return $this->_updatedWhere; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Add values of a record to be added |
|
337 | + * |
|
338 | + * @param string $name name of the field |
|
339 | + * |
|
340 | + */ |
|
341 | + public function addDroppedField($name) |
|
342 | + { |
|
343 | + $this->_droppedFields[] = $name; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get fields that need to be dropped |
|
348 | + * |
|
349 | + * @return array fields that need to be dropped |
|
350 | + * |
|
351 | + */ |
|
352 | + public function getDroppedFields() |
|
353 | + { |
|
354 | + return $this->_droppedFields; |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Set the flag to drop the table |
|
359 | + * |
|
360 | + */ |
|
361 | + public function setFlagForDrop() |
|
362 | + { |
|
363 | + $this->_flagForDrop = true; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Use to create a table |
|
368 | + * |
|
369 | + * @return bool true if success, false if an error occured |
|
370 | + * |
|
371 | + */ |
|
372 | + public function createTable() |
|
373 | + { |
|
374 | + global $xoopsDB; |
|
375 | + $query = $this->getStructure(); |
|
376 | + $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
377 | + //xoops_debug($query); |
|
378 | + $ret = $xoopsDB->query($query); |
|
379 | + if (!$ret) { |
|
380 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
381 | + } else { |
|
382 | + echo ' ' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br />'; |
|
383 | + } |
|
384 | + |
|
385 | + return $ret; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Use to drop a table |
|
390 | + * |
|
391 | + * @return bool true if success, false if an error occured |
|
392 | + * |
|
393 | + */ |
|
394 | + public function dropTable() |
|
395 | + { |
|
396 | + global $xoopsDB; |
|
397 | + $query = sprintf('DROP TABLE %s', $this->name()); |
|
398 | + $ret = $xoopsDB->query($query); |
|
399 | + if (!$ret) { |
|
400 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
401 | + |
|
402 | + return false; |
|
403 | + } else { |
|
404 | + echo ' ' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br />'; |
|
405 | + |
|
406 | + return true; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Use to alter a table |
|
412 | + * |
|
413 | + * @return bool true if success, false if an error occured |
|
414 | + * |
|
415 | + */ |
|
416 | + public function alterTable() |
|
417 | + { |
|
418 | + global $xoopsDB; |
|
419 | + $ret = true; |
|
420 | + |
|
421 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
422 | + if (!$alteredField['newname']) { |
|
423 | + $alteredField['newname'] = $alteredField['name']; |
|
424 | + } |
|
425 | + |
|
426 | + $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
427 | + $ret = $ret && $xoopsDB->query($query); |
|
428 | + if ($alteredField['showerror']) { |
|
429 | + if (!$ret) { |
|
430 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
431 | + } else { |
|
432 | + echo ' ' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br />'; |
|
433 | + } |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + return $ret; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Use to add new fileds in the table |
|
442 | + * |
|
443 | + * @return bool true if success, false if an error occured |
|
444 | + * |
|
445 | + */ |
|
446 | + public function addNewFields() |
|
447 | + { |
|
448 | + global $xoopsDB; |
|
449 | + $ret = true; |
|
450 | + foreach ($this->getNewFields() as $newField) { |
|
451 | + $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']); |
|
452 | + //echo $query; |
|
453 | + $ret = $ret && $xoopsDB->query($query); |
|
454 | + if (!$ret) { |
|
455 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br />'; |
|
456 | + } else { |
|
457 | + echo ' ' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br />'; |
|
458 | + } |
|
459 | + } |
|
460 | + |
|
461 | + return $ret; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Use to update fields values |
|
466 | + * |
|
467 | + * @return bool true if success, false if an error occured |
|
468 | + * |
|
469 | + */ |
|
470 | + public function updateFieldsValues() |
|
471 | + { |
|
472 | + global $xoopsDB; |
|
473 | + $ret = true; |
|
474 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
475 | + $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']); |
|
476 | + $ret = $ret && $xoopsDB->query($query); |
|
477 | + if (!$ret) { |
|
478 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
479 | + } else { |
|
480 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br />'; |
|
481 | + } |
|
482 | + } |
|
483 | + |
|
484 | + return $ret; |
|
485 | + } |
|
486 | + /** |
|
487 | + * Use to update fields values |
|
488 | + * |
|
489 | + * @return bool true if success, false if an error occured |
|
490 | + * |
|
491 | + */ //felix |
|
492 | + public function updateWhereValues() |
|
493 | + { |
|
494 | + global $xoopsDB; |
|
495 | + $ret = true; |
|
496 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
497 | + $query = sprintf('UPDATE %s SET %s = %s WHERE %s %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
498 | + //echo $query."<br>"; |
|
499 | + $ret = $ret && $xoopsDB->query($query); |
|
500 | + if (!$ret) { |
|
501 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
502 | + } else { |
|
503 | + echo ' ' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br />'; |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + return $ret; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * Use to drop fields |
|
512 | + * |
|
513 | + * @return bool true if success, false if an error occured |
|
514 | + * |
|
515 | + */ |
|
516 | + public function dropFields() |
|
517 | + { |
|
518 | + global $xoopsDB; |
|
519 | + $ret = true; |
|
520 | + foreach ($this->getDroppedFields() as $droppedField) { |
|
521 | + $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField); |
|
522 | + $ret = $ret && $xoopsDB->query($query); |
|
523 | + if (!$ret) { |
|
524 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br />'; |
|
525 | + } else { |
|
526 | + echo ' ' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br />'; |
|
527 | + } |
|
528 | + } |
|
529 | + |
|
530 | + return $ret; |
|
531 | + } |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | /** |
@@ -542,328 +542,328 @@ discard block |
||
542 | 542 | */ |
543 | 543 | class SmartobjectDbupdater |
544 | 544 | { |
545 | - public $_dbTypesArray; |
|
546 | - |
|
547 | - /** |
|
548 | - * SmartobjectDbupdater constructor. |
|
549 | - */ |
|
550 | - public function __construct() |
|
551 | - { |
|
552 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
553 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
554 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
555 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
556 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
557 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
558 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
559 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
560 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
561 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
562 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
563 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
564 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
565 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
566 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
567 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
568 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
569 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Use to execute a general query |
|
574 | - * |
|
575 | - * @param string $query query that will be executed |
|
576 | - * @param string $goodmsg message displayed on success |
|
577 | - * @param string $badmsg message displayed on error |
|
578 | - * |
|
579 | - * @return bool true if success, false if an error occured |
|
580 | - * |
|
581 | - */ |
|
582 | - public function runQuery($query, $goodmsg, $badmsg) |
|
583 | - { |
|
584 | - global $xoopsDB; |
|
585 | - $ret = $xoopsDB->query($query); |
|
586 | - if (!$ret) { |
|
587 | - echo " $badmsg<br />"; |
|
588 | - |
|
589 | - return false; |
|
590 | - } else { |
|
591 | - echo " $goodmsg<br />"; |
|
592 | - |
|
593 | - return true; |
|
594 | - } |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Use to rename a table |
|
599 | - * |
|
600 | - * @param string $from name of the table to rename |
|
601 | - * @param string $to new name of the renamed table |
|
602 | - * |
|
603 | - * @return bool true if success, false if an error occured |
|
604 | - */ |
|
605 | - public function renameTable($from, $to) |
|
606 | - { |
|
607 | - global $xoopsDB; |
|
608 | - $from = $xoopsDB->prefix($from); |
|
609 | - $to = $xoopsDB->prefix($to); |
|
610 | - $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
611 | - $ret = $xoopsDB->query($query); |
|
612 | - if (!$ret) { |
|
613 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br />'; |
|
614 | - |
|
615 | - return false; |
|
616 | - } else { |
|
617 | - echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br />'; |
|
618 | - |
|
619 | - return true; |
|
620 | - } |
|
621 | - } |
|
622 | - |
|
623 | - /** |
|
624 | - * Use to update a table |
|
625 | - * |
|
626 | - * @param object $table {@link SmartDbTable} that will be updated |
|
627 | - * |
|
628 | - * @see SmartDbTable |
|
629 | - * |
|
630 | - * @return bool true if success, false if an error occured |
|
631 | - */ |
|
632 | - public function updateTable($table) |
|
633 | - { |
|
634 | - global $xoopsDB; |
|
635 | - $ret = true; |
|
636 | - // If table has a structure, create the table |
|
637 | - if ($table->getStructure()) { |
|
638 | - $ret = $table->createTable() && $ret; |
|
639 | - } |
|
640 | - // If table is flag for drop, drop it |
|
641 | - if ($table->_flagForDrop) { |
|
642 | - $ret = $table->dropTable() && $ret; |
|
643 | - } |
|
644 | - // If table has data, insert it |
|
645 | - if ($table->getData()) { |
|
646 | - $ret = $table->addData() && $ret; |
|
647 | - } |
|
648 | - // If table has new fields to be added, add them |
|
649 | - if ($table->getNewFields()) { |
|
650 | - $ret = $table->addNewFields() && $ret; |
|
651 | - } |
|
652 | - // If table has altered field, alter the table |
|
653 | - if ($table->getAlteredFields()) { |
|
654 | - $ret = $table->alterTable() && $ret; |
|
655 | - } |
|
656 | - // If table has updated field values, update the table |
|
657 | - if ($table->getUpdatedFields()) { |
|
658 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
659 | - } |
|
660 | - // If table has dropped field, alter the table |
|
661 | - if ($table->getDroppedFields()) { |
|
662 | - $ret = $table->dropFields($table) && $ret; |
|
663 | - } |
|
664 | - //felix |
|
665 | - // If table has updated field values, update the table |
|
666 | - if ($table->getUpdatedWhere()) { |
|
667 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
668 | - } |
|
669 | - |
|
670 | - return $ret; |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * @param $module |
|
675 | - * @param $item |
|
676 | - */ |
|
677 | - public function automaticUpgrade($module, $item) |
|
678 | - { |
|
679 | - if (is_array($item)) { |
|
680 | - foreach ($item as $v) { |
|
681 | - $this->upgradeObjectItem($module, $v); |
|
682 | - } |
|
683 | - } else { |
|
684 | - $this->upgradeObjectItem($module, $item); |
|
685 | - } |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * @param $var |
|
690 | - * @return string |
|
691 | - */ |
|
692 | - public function getFieldTypeFromVar($var) |
|
693 | - { |
|
694 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
695 | - |
|
696 | - return $ret; |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * @param $var |
|
701 | - * @param bool $key |
|
702 | - * @return string |
|
703 | - */ |
|
704 | - public function getFieldDefaultFromVar($var, $key = false) |
|
705 | - { |
|
706 | - if ($var['value']) { |
|
707 | - return $var['value']; |
|
708 | - } else { |
|
709 | - if (in_array($var['data_type'], array( |
|
710 | - XOBJ_DTYPE_INT, |
|
711 | - XOBJ_DTYPE_STIME, |
|
712 | - XOBJ_DTYPE_MTIME, |
|
713 | - XOBJ_DTYPE_LTIME, |
|
714 | - XOBJ_DTYPE_TIME_ONLY, |
|
715 | - XOBJ_DTYPE_URLLINK, |
|
716 | - XOBJ_DTYPE_FILE |
|
717 | - ))) { |
|
718 | - return '0'; |
|
719 | - } else { |
|
720 | - return ''; |
|
721 | - } |
|
722 | - } |
|
723 | - } |
|
724 | - |
|
725 | - /** |
|
726 | - * @param $module |
|
727 | - * @param $item |
|
728 | - * @return bool |
|
729 | - */ |
|
730 | - public function upgradeObjectItem($module, $item) |
|
731 | - { |
|
732 | - $moduleHandler = xoops_getModuleHandler($item, $module); |
|
733 | - if (!$moduleHandler) { |
|
734 | - return false; |
|
735 | - } |
|
736 | - |
|
737 | - $table = new SmartDbTable($module . '_' . $item); |
|
738 | - $object = $moduleHandler->create(); |
|
739 | - $objectVars = $object->getVars(); |
|
740 | - |
|
741 | - if (!$table->exists()) { |
|
742 | - // table was never created, let's do it |
|
743 | - $structure = ''; |
|
744 | - foreach ($objectVars as $key => $var) { |
|
745 | - if ($var['persistent']) { |
|
746 | - $type = $this->getFieldTypeFromVar($var); |
|
747 | - if ($key == $moduleHandler->keyName) { |
|
748 | - $extra = 'auto_increment'; |
|
749 | - } else { |
|
750 | - $default = $this->getFieldDefaultFromVar($var); |
|
751 | - $extra = "default '$default' |
|
545 | + public $_dbTypesArray; |
|
546 | + |
|
547 | + /** |
|
548 | + * SmartobjectDbupdater constructor. |
|
549 | + */ |
|
550 | + public function __construct() |
|
551 | + { |
|
552 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
553 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
554 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
555 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
556 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
557 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
558 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
559 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
560 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
561 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
562 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
563 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
564 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
565 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
566 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
567 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
568 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
569 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Use to execute a general query |
|
574 | + * |
|
575 | + * @param string $query query that will be executed |
|
576 | + * @param string $goodmsg message displayed on success |
|
577 | + * @param string $badmsg message displayed on error |
|
578 | + * |
|
579 | + * @return bool true if success, false if an error occured |
|
580 | + * |
|
581 | + */ |
|
582 | + public function runQuery($query, $goodmsg, $badmsg) |
|
583 | + { |
|
584 | + global $xoopsDB; |
|
585 | + $ret = $xoopsDB->query($query); |
|
586 | + if (!$ret) { |
|
587 | + echo " $badmsg<br />"; |
|
588 | + |
|
589 | + return false; |
|
590 | + } else { |
|
591 | + echo " $goodmsg<br />"; |
|
592 | + |
|
593 | + return true; |
|
594 | + } |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Use to rename a table |
|
599 | + * |
|
600 | + * @param string $from name of the table to rename |
|
601 | + * @param string $to new name of the renamed table |
|
602 | + * |
|
603 | + * @return bool true if success, false if an error occured |
|
604 | + */ |
|
605 | + public function renameTable($from, $to) |
|
606 | + { |
|
607 | + global $xoopsDB; |
|
608 | + $from = $xoopsDB->prefix($from); |
|
609 | + $to = $xoopsDB->prefix($to); |
|
610 | + $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to); |
|
611 | + $ret = $xoopsDB->query($query); |
|
612 | + if (!$ret) { |
|
613 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br />'; |
|
614 | + |
|
615 | + return false; |
|
616 | + } else { |
|
617 | + echo ' ' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br />'; |
|
618 | + |
|
619 | + return true; |
|
620 | + } |
|
621 | + } |
|
622 | + |
|
623 | + /** |
|
624 | + * Use to update a table |
|
625 | + * |
|
626 | + * @param object $table {@link SmartDbTable} that will be updated |
|
627 | + * |
|
628 | + * @see SmartDbTable |
|
629 | + * |
|
630 | + * @return bool true if success, false if an error occured |
|
631 | + */ |
|
632 | + public function updateTable($table) |
|
633 | + { |
|
634 | + global $xoopsDB; |
|
635 | + $ret = true; |
|
636 | + // If table has a structure, create the table |
|
637 | + if ($table->getStructure()) { |
|
638 | + $ret = $table->createTable() && $ret; |
|
639 | + } |
|
640 | + // If table is flag for drop, drop it |
|
641 | + if ($table->_flagForDrop) { |
|
642 | + $ret = $table->dropTable() && $ret; |
|
643 | + } |
|
644 | + // If table has data, insert it |
|
645 | + if ($table->getData()) { |
|
646 | + $ret = $table->addData() && $ret; |
|
647 | + } |
|
648 | + // If table has new fields to be added, add them |
|
649 | + if ($table->getNewFields()) { |
|
650 | + $ret = $table->addNewFields() && $ret; |
|
651 | + } |
|
652 | + // If table has altered field, alter the table |
|
653 | + if ($table->getAlteredFields()) { |
|
654 | + $ret = $table->alterTable() && $ret; |
|
655 | + } |
|
656 | + // If table has updated field values, update the table |
|
657 | + if ($table->getUpdatedFields()) { |
|
658 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
659 | + } |
|
660 | + // If table has dropped field, alter the table |
|
661 | + if ($table->getDroppedFields()) { |
|
662 | + $ret = $table->dropFields($table) && $ret; |
|
663 | + } |
|
664 | + //felix |
|
665 | + // If table has updated field values, update the table |
|
666 | + if ($table->getUpdatedWhere()) { |
|
667 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
668 | + } |
|
669 | + |
|
670 | + return $ret; |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * @param $module |
|
675 | + * @param $item |
|
676 | + */ |
|
677 | + public function automaticUpgrade($module, $item) |
|
678 | + { |
|
679 | + if (is_array($item)) { |
|
680 | + foreach ($item as $v) { |
|
681 | + $this->upgradeObjectItem($module, $v); |
|
682 | + } |
|
683 | + } else { |
|
684 | + $this->upgradeObjectItem($module, $item); |
|
685 | + } |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * @param $var |
|
690 | + * @return string |
|
691 | + */ |
|
692 | + public function getFieldTypeFromVar($var) |
|
693 | + { |
|
694 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
695 | + |
|
696 | + return $ret; |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * @param $var |
|
701 | + * @param bool $key |
|
702 | + * @return string |
|
703 | + */ |
|
704 | + public function getFieldDefaultFromVar($var, $key = false) |
|
705 | + { |
|
706 | + if ($var['value']) { |
|
707 | + return $var['value']; |
|
708 | + } else { |
|
709 | + if (in_array($var['data_type'], array( |
|
710 | + XOBJ_DTYPE_INT, |
|
711 | + XOBJ_DTYPE_STIME, |
|
712 | + XOBJ_DTYPE_MTIME, |
|
713 | + XOBJ_DTYPE_LTIME, |
|
714 | + XOBJ_DTYPE_TIME_ONLY, |
|
715 | + XOBJ_DTYPE_URLLINK, |
|
716 | + XOBJ_DTYPE_FILE |
|
717 | + ))) { |
|
718 | + return '0'; |
|
719 | + } else { |
|
720 | + return ''; |
|
721 | + } |
|
722 | + } |
|
723 | + } |
|
724 | + |
|
725 | + /** |
|
726 | + * @param $module |
|
727 | + * @param $item |
|
728 | + * @return bool |
|
729 | + */ |
|
730 | + public function upgradeObjectItem($module, $item) |
|
731 | + { |
|
732 | + $moduleHandler = xoops_getModuleHandler($item, $module); |
|
733 | + if (!$moduleHandler) { |
|
734 | + return false; |
|
735 | + } |
|
736 | + |
|
737 | + $table = new SmartDbTable($module . '_' . $item); |
|
738 | + $object = $moduleHandler->create(); |
|
739 | + $objectVars = $object->getVars(); |
|
740 | + |
|
741 | + if (!$table->exists()) { |
|
742 | + // table was never created, let's do it |
|
743 | + $structure = ''; |
|
744 | + foreach ($objectVars as $key => $var) { |
|
745 | + if ($var['persistent']) { |
|
746 | + $type = $this->getFieldTypeFromVar($var); |
|
747 | + if ($key == $moduleHandler->keyName) { |
|
748 | + $extra = 'auto_increment'; |
|
749 | + } else { |
|
750 | + $default = $this->getFieldDefaultFromVar($var); |
|
751 | + $extra = "default '$default' |
|
752 | 752 | "; |
753 | - } |
|
754 | - $structure .= "`$key` $type not null $extra, |
|
753 | + } |
|
754 | + $structure .= "`$key` $type not null $extra, |
|
755 | 755 | "; |
756 | - } |
|
757 | - } |
|
758 | - $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
756 | + } |
|
757 | + } |
|
758 | + $structure .= 'PRIMARY KEY (`' . $moduleHandler->keyName . '`) |
|
759 | 759 | '; |
760 | - $table->setStructure($structure); |
|
761 | - if (!$this->updateTable($table)) { |
|
762 | - /** |
|
763 | - * @todo trap the errors |
|
764 | - */ |
|
765 | - } |
|
766 | - } else { |
|
767 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
768 | - foreach ($objectVars as $key => $var) { |
|
769 | - if ($var['persistent']) { |
|
770 | - if (!isset($existingFieldsArray[$key])) { |
|
771 | - // the fiels does not exist, let's create it |
|
772 | - $type = $this->getFieldTypeFromVar($var); |
|
773 | - $default = $this->getFieldDefaultFromVar($var); |
|
774 | - $table->addNewField($key, "$type not null default '$default'"); |
|
775 | - } else { |
|
776 | - // if field already exists, let's check if the definition is correct |
|
777 | - $definition = strtolower($existingFieldsArray[$key]); |
|
778 | - $type = $this->getFieldTypeFromVar($var); |
|
779 | - if ($key == $moduleHandler->keyName) { |
|
780 | - $extra = 'auto_increment'; |
|
781 | - } else { |
|
782 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
783 | - $extra = "default '$default'"; |
|
784 | - } |
|
785 | - $actual_definition = "$type not null $extra"; |
|
786 | - if ($definition != $actual_definition) { |
|
787 | - $table->addAlteredField($key, $actual_definition); |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - // check to see if there are some unused fields left in the table |
|
794 | - foreach ($existingFieldsArray as $key => $v) { |
|
795 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
796 | - $table->addDroppedField($key); |
|
797 | - } |
|
798 | - } |
|
799 | - |
|
800 | - if (!$this->updateTable($table)) { |
|
801 | - /** |
|
802 | - * @todo trap the errors |
|
803 | - */ |
|
804 | - } |
|
805 | - } |
|
806 | - } |
|
807 | - |
|
808 | - /** |
|
809 | - * @param $module |
|
810 | - * @return bool |
|
811 | - */ |
|
812 | - public function moduleUpgrade(&$module) |
|
813 | - { |
|
814 | - $dirname = $module->getVar('dirname'); |
|
815 | - |
|
816 | - ob_start(); |
|
817 | - |
|
818 | - $table = new SmartDbTable($dirname . '_meta'); |
|
819 | - if (!$table->exists()) { |
|
820 | - $table->setStructure(" |
|
760 | + $table->setStructure($structure); |
|
761 | + if (!$this->updateTable($table)) { |
|
762 | + /** |
|
763 | + * @todo trap the errors |
|
764 | + */ |
|
765 | + } |
|
766 | + } else { |
|
767 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
768 | + foreach ($objectVars as $key => $var) { |
|
769 | + if ($var['persistent']) { |
|
770 | + if (!isset($existingFieldsArray[$key])) { |
|
771 | + // the fiels does not exist, let's create it |
|
772 | + $type = $this->getFieldTypeFromVar($var); |
|
773 | + $default = $this->getFieldDefaultFromVar($var); |
|
774 | + $table->addNewField($key, "$type not null default '$default'"); |
|
775 | + } else { |
|
776 | + // if field already exists, let's check if the definition is correct |
|
777 | + $definition = strtolower($existingFieldsArray[$key]); |
|
778 | + $type = $this->getFieldTypeFromVar($var); |
|
779 | + if ($key == $moduleHandler->keyName) { |
|
780 | + $extra = 'auto_increment'; |
|
781 | + } else { |
|
782 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
783 | + $extra = "default '$default'"; |
|
784 | + } |
|
785 | + $actual_definition = "$type not null $extra"; |
|
786 | + if ($definition != $actual_definition) { |
|
787 | + $table->addAlteredField($key, $actual_definition); |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + // check to see if there are some unused fields left in the table |
|
794 | + foreach ($existingFieldsArray as $key => $v) { |
|
795 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
796 | + $table->addDroppedField($key); |
|
797 | + } |
|
798 | + } |
|
799 | + |
|
800 | + if (!$this->updateTable($table)) { |
|
801 | + /** |
|
802 | + * @todo trap the errors |
|
803 | + */ |
|
804 | + } |
|
805 | + } |
|
806 | + } |
|
807 | + |
|
808 | + /** |
|
809 | + * @param $module |
|
810 | + * @return bool |
|
811 | + */ |
|
812 | + public function moduleUpgrade(&$module) |
|
813 | + { |
|
814 | + $dirname = $module->getVar('dirname'); |
|
815 | + |
|
816 | + ob_start(); |
|
817 | + |
|
818 | + $table = new SmartDbTable($dirname . '_meta'); |
|
819 | + if (!$table->exists()) { |
|
820 | + $table->setStructure(" |
|
821 | 821 | `metakey` varchar(50) NOT NULL default '', |
822 | 822 | `metavalue` varchar(255) NOT NULL default '', |
823 | 823 | PRIMARY KEY (`metakey`)"); |
824 | - $table->setData("'version',0"); |
|
825 | - if (!$this->updateTable($table)) { |
|
826 | - /** |
|
827 | - * @todo trap the errors |
|
828 | - */ |
|
829 | - } |
|
830 | - } |
|
831 | - |
|
832 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
833 | - if (!$dbVersion) { |
|
834 | - $dbVersion = 0; |
|
835 | - } |
|
836 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
837 | - echo 'Database version: ' . $dbVersion . '<br />'; |
|
838 | - echo 'New database version: ' . $newDbVersion . '<br />'; |
|
839 | - |
|
840 | - if ($newDbVersion > $dbVersion) { |
|
841 | - for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
842 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
843 | - if (function_exists($upgrade_function)) { |
|
844 | - $upgrade_function(); |
|
845 | - } |
|
846 | - } |
|
847 | - } |
|
848 | - |
|
849 | - echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br />'; |
|
850 | - |
|
851 | - // if there is a function to execute for this DB version, let's do it |
|
852 | - //$function_ |
|
853 | - |
|
854 | - $module_info = smart_getModuleInfo($dirname); |
|
855 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
856 | - |
|
857 | - echo '</code>'; |
|
858 | - |
|
859 | - $feedback = ob_get_clean(); |
|
860 | - if (method_exists($module, 'setMessage')) { |
|
861 | - $module->setMessage($feedback); |
|
862 | - } else { |
|
863 | - echo $feedback; |
|
864 | - } |
|
865 | - smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
866 | - |
|
867 | - return true; |
|
868 | - } |
|
824 | + $table->setData("'version',0"); |
|
825 | + if (!$this->updateTable($table)) { |
|
826 | + /** |
|
827 | + * @todo trap the errors |
|
828 | + */ |
|
829 | + } |
|
830 | + } |
|
831 | + |
|
832 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
833 | + if (!$dbVersion) { |
|
834 | + $dbVersion = 0; |
|
835 | + } |
|
836 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0; |
|
837 | + echo 'Database version: ' . $dbVersion . '<br />'; |
|
838 | + echo 'New database version: ' . $newDbVersion . '<br />'; |
|
839 | + |
|
840 | + if ($newDbVersion > $dbVersion) { |
|
841 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) { |
|
842 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
843 | + if (function_exists($upgrade_function)) { |
|
844 | + $upgrade_function(); |
|
845 | + } |
|
846 | + } |
|
847 | + } |
|
848 | + |
|
849 | + echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br />'; |
|
850 | + |
|
851 | + // if there is a function to execute for this DB version, let's do it |
|
852 | + //$function_ |
|
853 | + |
|
854 | + $module_info = smart_getModuleInfo($dirname); |
|
855 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
856 | + |
|
857 | + echo '</code>'; |
|
858 | + |
|
859 | + $feedback = ob_get_clean(); |
|
860 | + if (method_exists($module, 'setMessage')) { |
|
861 | + $module->setMessage($feedback); |
|
862 | + } else { |
|
863 | + echo $feedback; |
|
864 | + } |
|
865 | + smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current |
|
866 | + |
|
867 | + return true; |
|
868 | + } |
|
869 | 869 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | /** |
198 | 198 | * @param $val |
199 | 199 | * @param $separator |
200 | - * @param $trimFunction |
|
200 | + * @param false|string $trimFunction |
|
201 | 201 | * @return mixed|string |
202 | 202 | */ |
203 | 203 | public function valToCsvHelper($val, $separator, $trimFunction) |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
251 | - * @param $content |
|
251 | + * @param string $content |
|
252 | 252 | */ |
253 | 253 | public function saveExportFile($content) |
254 | 254 | { |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Contains the classes for easily exporting data |
|
4 | - * |
|
5 | - * @license GNU |
|
6 | - * @author marcan <[email protected]> |
|
7 | - * @link http://www.smartfactory.ca The SmartFactory |
|
8 | - * @package SmartObject |
|
9 | - */ |
|
3 | + * Contains the classes for easily exporting data |
|
4 | + * |
|
5 | + * @license GNU |
|
6 | + * @author marcan <[email protected]> |
|
7 | + * @link http://www.smartfactory.ca The SmartFactory |
|
8 | + * @package SmartObject |
|
9 | + */ |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * SmartObjectExport class |
@@ -19,110 +19,110 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class SmartObjectExport |
21 | 21 | { |
22 | - public $handler; |
|
23 | - public $criteria; |
|
24 | - public $fields; |
|
25 | - public $format; |
|
26 | - public $filename; |
|
27 | - public $filepath; |
|
28 | - public $options; |
|
29 | - public $outputMethods = false; |
|
30 | - public $notDisplayFields; |
|
22 | + public $handler; |
|
23 | + public $criteria; |
|
24 | + public $fields; |
|
25 | + public $format; |
|
26 | + public $filename; |
|
27 | + public $filepath; |
|
28 | + public $options; |
|
29 | + public $outputMethods = false; |
|
30 | + public $notDisplayFields; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param object $objectHandler SmartObjectHandler handling the data we want to export |
|
36 | - * @param object $criteria containing the criteria of the query fetching the objects to be exported |
|
37 | - * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
38 | - * @param bool|string $filename name of the file to be created |
|
39 | - * @param bool|string $filepath path where the file will be saved |
|
40 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
41 | - * @param array|bool $options options of the format to be exported in |
|
42 | - */ |
|
43 | - public function __construct($objectHandler, $criteria = null, $fields = false, $filename = false, $filepath = false, $format = 'csv', $options = false) |
|
44 | - { |
|
45 | - $this->handler = $objectHandler; |
|
46 | - $this->criteria = $criteria; |
|
47 | - $this->fields = $fields; |
|
48 | - $this->filename = $filename; |
|
49 | - $this->format = $format; |
|
50 | - $this->options = $options; |
|
51 | - $this->notDisplayFields = false; |
|
52 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param object $objectHandler SmartObjectHandler handling the data we want to export |
|
36 | + * @param object $criteria containing the criteria of the query fetching the objects to be exported |
|
37 | + * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
38 | + * @param bool|string $filename name of the file to be created |
|
39 | + * @param bool|string $filepath path where the file will be saved |
|
40 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
41 | + * @param array|bool $options options of the format to be exported in |
|
42 | + */ |
|
43 | + public function __construct($objectHandler, $criteria = null, $fields = false, $filename = false, $filepath = false, $format = 'csv', $options = false) |
|
44 | + { |
|
45 | + $this->handler = $objectHandler; |
|
46 | + $this->criteria = $criteria; |
|
47 | + $this->fields = $fields; |
|
48 | + $this->filename = $filename; |
|
49 | + $this->format = $format; |
|
50 | + $this->options = $options; |
|
51 | + $this->notDisplayFields = false; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Renders the export |
|
56 | - * @param $filename |
|
57 | - */ |
|
58 | - public function render($filename) |
|
59 | - { |
|
60 | - $this->filename = $filename; |
|
54 | + /** |
|
55 | + * Renders the export |
|
56 | + * @param $filename |
|
57 | + */ |
|
58 | + public function render($filename) |
|
59 | + { |
|
60 | + $this->filename = $filename; |
|
61 | 61 | |
62 | - $objects = $this->handler->getObjects($this->criteria); |
|
63 | - $rows = array(); |
|
64 | - $columnsHeaders = array(); |
|
65 | - $firstObject = true; |
|
66 | - foreach ($objects as $object) { |
|
67 | - $row = array(); |
|
68 | - foreach ($object->vars as $key => $var) { |
|
69 | - if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
70 | - if ($this->outputMethods && isset($this->outputMethods[$key]) && method_exists($object, $this->outputMethods[$key])) { |
|
71 | - $method = $this->outputMethods[$key]; |
|
72 | - $row[$key] = $object->$method(); |
|
73 | - } else { |
|
74 | - $row[$key] = $object->getVar($key); |
|
75 | - } |
|
76 | - if ($firstObject) { |
|
77 | - // then set the columnsHeaders array as well |
|
78 | - $columnsHeaders[$key] = $var['form_caption']; |
|
79 | - } |
|
80 | - } |
|
81 | - } |
|
82 | - $firstObject = false; |
|
83 | - $rows[] = $row; |
|
84 | - unset($row); |
|
85 | - } |
|
86 | - $data = array(); |
|
87 | - $data['rows'] = $rows; |
|
88 | - $data['columnsHeaders'] = $columnsHeaders; |
|
89 | - $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
90 | - $smartExportRenderer->execute(); |
|
91 | - } |
|
62 | + $objects = $this->handler->getObjects($this->criteria); |
|
63 | + $rows = array(); |
|
64 | + $columnsHeaders = array(); |
|
65 | + $firstObject = true; |
|
66 | + foreach ($objects as $object) { |
|
67 | + $row = array(); |
|
68 | + foreach ($object->vars as $key => $var) { |
|
69 | + if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
70 | + if ($this->outputMethods && isset($this->outputMethods[$key]) && method_exists($object, $this->outputMethods[$key])) { |
|
71 | + $method = $this->outputMethods[$key]; |
|
72 | + $row[$key] = $object->$method(); |
|
73 | + } else { |
|
74 | + $row[$key] = $object->getVar($key); |
|
75 | + } |
|
76 | + if ($firstObject) { |
|
77 | + // then set the columnsHeaders array as well |
|
78 | + $columnsHeaders[$key] = $var['form_caption']; |
|
79 | + } |
|
80 | + } |
|
81 | + } |
|
82 | + $firstObject = false; |
|
83 | + $rows[] = $row; |
|
84 | + unset($row); |
|
85 | + } |
|
86 | + $data = array(); |
|
87 | + $data['rows'] = $rows; |
|
88 | + $data['columnsHeaders'] = $columnsHeaders; |
|
89 | + $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
90 | + $smartExportRenderer->execute(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Set an array contaning the alternate methods to use instead of the default getVar() |
|
95 | - * |
|
96 | - * $outputMethods array example: 'uid' => 'getUserName'... |
|
97 | - * @param $outputMethods |
|
98 | - */ |
|
99 | - public function setOuptutMethods($outputMethods) |
|
100 | - { |
|
101 | - $this->outputMethods = $outputMethods; |
|
102 | - } |
|
93 | + /** |
|
94 | + * Set an array contaning the alternate methods to use instead of the default getVar() |
|
95 | + * |
|
96 | + * $outputMethods array example: 'uid' => 'getUserName'... |
|
97 | + * @param $outputMethods |
|
98 | + */ |
|
99 | + public function setOuptutMethods($outputMethods) |
|
100 | + { |
|
101 | + $this->outputMethods = $outputMethods; |
|
102 | + } |
|
103 | 103 | |
104 | - /* |
|
104 | + /* |
|
105 | 105 | * Set an array of fields that we don't want in export |
106 | 106 | */ |
107 | - /** |
|
108 | - * @param $fields |
|
109 | - */ |
|
110 | - public function setNotDisplayFields($fields) |
|
111 | - { |
|
112 | - if (!$this->notDisplayFields) { |
|
113 | - if (is_array($fields)) { |
|
114 | - $this->notDisplayFields = $fields; |
|
115 | - } else { |
|
116 | - $this->notDisplayFields = array($fields); |
|
117 | - } |
|
118 | - } else { |
|
119 | - if (is_array($fields)) { |
|
120 | - $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
121 | - } else { |
|
122 | - $this->notDisplayFields[] = $fields; |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
107 | + /** |
|
108 | + * @param $fields |
|
109 | + */ |
|
110 | + public function setNotDisplayFields($fields) |
|
111 | + { |
|
112 | + if (!$this->notDisplayFields) { |
|
113 | + if (is_array($fields)) { |
|
114 | + $this->notDisplayFields = $fields; |
|
115 | + } else { |
|
116 | + $this->notDisplayFields = array($fields); |
|
117 | + } |
|
118 | + } else { |
|
119 | + if (is_array($fields)) { |
|
120 | + $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
121 | + } else { |
|
122 | + $this->notDisplayFields[] = $fields; |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -136,181 +136,181 @@ discard block |
||
136 | 136 | */ |
137 | 137 | class SmartExportRenderer |
138 | 138 | { |
139 | - public $data; |
|
140 | - public $format; |
|
141 | - public $filename; |
|
142 | - public $filepath; |
|
143 | - public $options; |
|
139 | + public $data; |
|
140 | + public $format; |
|
141 | + public $filename; |
|
142 | + public $filepath; |
|
143 | + public $options; |
|
144 | 144 | |
145 | - /** |
|
146 | - * Constructor |
|
147 | - * |
|
148 | - * @param array $data contains the data to be exported |
|
149 | - * @param bool|string $filename name of the file in which the exported data will be saved |
|
150 | - * @param bool|string $filepath path where the file will be saved |
|
151 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
152 | - * @param array $options options of the format to be exported in |
|
153 | - */ |
|
154 | - public function __construct($data, $filename = false, $filepath = false, $format = 'csv', $options = array('separator' => ';')) |
|
155 | - { |
|
156 | - $this->data = $data; |
|
157 | - $this->format = $format; |
|
158 | - $this->filename = $filename; |
|
159 | - $this->filepath = $filepath; |
|
160 | - $this->options = $options; |
|
161 | - } |
|
145 | + /** |
|
146 | + * Constructor |
|
147 | + * |
|
148 | + * @param array $data contains the data to be exported |
|
149 | + * @param bool|string $filename name of the file in which the exported data will be saved |
|
150 | + * @param bool|string $filepath path where the file will be saved |
|
151 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
152 | + * @param array $options options of the format to be exported in |
|
153 | + */ |
|
154 | + public function __construct($data, $filename = false, $filepath = false, $format = 'csv', $options = array('separator' => ';')) |
|
155 | + { |
|
156 | + $this->data = $data; |
|
157 | + $this->format = $format; |
|
158 | + $this->filename = $filename; |
|
159 | + $this->filepath = $filepath; |
|
160 | + $this->options = $options; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * @param $dataArray |
|
165 | - * @param $separator |
|
166 | - * @param string $trim |
|
167 | - * @param bool $removeEmptyLines |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
171 | - { |
|
172 | - if (!is_array($dataArray) || empty($dataArray)) { |
|
173 | - return ''; |
|
174 | - } |
|
175 | - switch ($trim) { |
|
176 | - case 'none': |
|
177 | - $trimFunction = false; |
|
178 | - break; |
|
179 | - case 'left': |
|
180 | - $trimFunction = 'ltrim'; |
|
181 | - break; |
|
182 | - case 'right': |
|
183 | - $trimFunction = 'rtrim'; |
|
184 | - break; |
|
185 | - default: //'both': |
|
186 | - $trimFunction = 'trim'; |
|
187 | - break; |
|
188 | - } |
|
189 | - $ret = array(); |
|
190 | - foreach ($dataArray as $key => $field) { |
|
191 | - $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
192 | - } |
|
163 | + /** |
|
164 | + * @param $dataArray |
|
165 | + * @param $separator |
|
166 | + * @param string $trim |
|
167 | + * @param bool $removeEmptyLines |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
171 | + { |
|
172 | + if (!is_array($dataArray) || empty($dataArray)) { |
|
173 | + return ''; |
|
174 | + } |
|
175 | + switch ($trim) { |
|
176 | + case 'none': |
|
177 | + $trimFunction = false; |
|
178 | + break; |
|
179 | + case 'left': |
|
180 | + $trimFunction = 'ltrim'; |
|
181 | + break; |
|
182 | + case 'right': |
|
183 | + $trimFunction = 'rtrim'; |
|
184 | + break; |
|
185 | + default: //'both': |
|
186 | + $trimFunction = 'trim'; |
|
187 | + break; |
|
188 | + } |
|
189 | + $ret = array(); |
|
190 | + foreach ($dataArray as $key => $field) { |
|
191 | + $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
192 | + } |
|
193 | 193 | |
194 | - return implode($separator, $ret); |
|
195 | - } |
|
194 | + return implode($separator, $ret); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @param $val |
|
199 | - * @param $separator |
|
200 | - * @param $trimFunction |
|
201 | - * @return mixed|string |
|
202 | - */ |
|
203 | - public function valToCsvHelper($val, $separator, $trimFunction) |
|
204 | - { |
|
205 | - if ($trimFunction) { |
|
206 | - $val = $trimFunction ($val); |
|
207 | - } |
|
208 | - //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
209 | - $needQuote = false; |
|
210 | - do { |
|
211 | - if (strpos($val, '"') !== false) { |
|
212 | - $val = str_replace('"', '""', $val); |
|
213 | - $needQuote = true; |
|
214 | - break; |
|
215 | - } |
|
216 | - if (strpos($val, $separator) !== false) { |
|
217 | - $needQuote = true; |
|
218 | - break; |
|
219 | - } |
|
220 | - if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac |
|
221 | - $needQuote = true; |
|
222 | - break; |
|
223 | - } |
|
224 | - } while (false); |
|
225 | - if ($needQuote) { |
|
226 | - $val = '"' . $val . '"'; |
|
227 | - } |
|
197 | + /** |
|
198 | + * @param $val |
|
199 | + * @param $separator |
|
200 | + * @param $trimFunction |
|
201 | + * @return mixed|string |
|
202 | + */ |
|
203 | + public function valToCsvHelper($val, $separator, $trimFunction) |
|
204 | + { |
|
205 | + if ($trimFunction) { |
|
206 | + $val = $trimFunction ($val); |
|
207 | + } |
|
208 | + //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
209 | + $needQuote = false; |
|
210 | + do { |
|
211 | + if (strpos($val, '"') !== false) { |
|
212 | + $val = str_replace('"', '""', $val); |
|
213 | + $needQuote = true; |
|
214 | + break; |
|
215 | + } |
|
216 | + if (strpos($val, $separator) !== false) { |
|
217 | + $needQuote = true; |
|
218 | + break; |
|
219 | + } |
|
220 | + if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac |
|
221 | + $needQuote = true; |
|
222 | + break; |
|
223 | + } |
|
224 | + } while (false); |
|
225 | + if ($needQuote) { |
|
226 | + $val = '"' . $val . '"'; |
|
227 | + } |
|
228 | 228 | |
229 | - return $val; |
|
230 | - } |
|
229 | + return $val; |
|
230 | + } |
|
231 | 231 | |
232 | - public function execute() |
|
233 | - { |
|
234 | - $exportFileData = ''; |
|
232 | + public function execute() |
|
233 | + { |
|
234 | + $exportFileData = ''; |
|
235 | 235 | |
236 | - switch ($this->format) { |
|
237 | - case 'csv': |
|
238 | - $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
239 | - $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
240 | - $exportFileData .= $firstRow . "\r\n"; |
|
236 | + switch ($this->format) { |
|
237 | + case 'csv': |
|
238 | + $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
239 | + $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
240 | + $exportFileData .= $firstRow . "\r\n"; |
|
241 | 241 | |
242 | - foreach ($this->data['rows'] as $cols) { |
|
243 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
244 | - } |
|
245 | - break; |
|
246 | - } |
|
247 | - $this->saveExportFile($exportFileData); |
|
248 | - } |
|
242 | + foreach ($this->data['rows'] as $cols) { |
|
243 | + $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
244 | + } |
|
245 | + break; |
|
246 | + } |
|
247 | + $this->saveExportFile($exportFileData); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * @param $content |
|
252 | - */ |
|
253 | - public function saveExportFile($content) |
|
254 | - { |
|
255 | - switch ($this->format) { |
|
256 | - case 'csv': |
|
257 | - $this->saveCsv($content); |
|
258 | - break; |
|
259 | - } |
|
260 | - } |
|
250 | + /** |
|
251 | + * @param $content |
|
252 | + */ |
|
253 | + public function saveExportFile($content) |
|
254 | + { |
|
255 | + switch ($this->format) { |
|
256 | + case 'csv': |
|
257 | + $this->saveCsv($content); |
|
258 | + break; |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * @param $content |
|
264 | - */ |
|
265 | - public function saveCsv($content) |
|
266 | - { |
|
267 | - if (!$this->filepath) { |
|
268 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
269 | - } |
|
270 | - if (!$this->filename) { |
|
271 | - $this->filename .= time(); |
|
272 | - $this->filename .= '.csv'; |
|
273 | - } |
|
262 | + /** |
|
263 | + * @param $content |
|
264 | + */ |
|
265 | + public function saveCsv($content) |
|
266 | + { |
|
267 | + if (!$this->filepath) { |
|
268 | + $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
269 | + } |
|
270 | + if (!$this->filename) { |
|
271 | + $this->filename .= time(); |
|
272 | + $this->filename .= '.csv'; |
|
273 | + } |
|
274 | 274 | |
275 | - $fullFileName = $this->filepath . $this->filename; |
|
275 | + $fullFileName = $this->filepath . $this->filename; |
|
276 | 276 | |
277 | - if (!$handle = fopen($fullFileName, 'a+')) { |
|
278 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
279 | - } elseif (fwrite($handle, $content) === false) { |
|
280 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
281 | - } else { |
|
282 | - $mimeType = 'text/csv'; |
|
283 | - $file = strrev($this->filename); |
|
284 | - $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
285 | - if ($temp_name == '') { |
|
286 | - $file_name = $this->filename; |
|
287 | - } else { |
|
288 | - $file_name = $temp_name; |
|
289 | - } |
|
290 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
277 | + if (!$handle = fopen($fullFileName, 'a+')) { |
|
278 | + trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
279 | + } elseif (fwrite($handle, $content) === false) { |
|
280 | + trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
281 | + } else { |
|
282 | + $mimeType = 'text/csv'; |
|
283 | + $file = strrev($this->filename); |
|
284 | + $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
285 | + if ($temp_name == '') { |
|
286 | + $file_name = $this->filename; |
|
287 | + } else { |
|
288 | + $file_name = $temp_name; |
|
289 | + } |
|
290 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
291 | 291 | |
292 | - if (ini_get('zlib.output_compression')) { |
|
293 | - ini_set('zlib.output_compression', 'Off'); |
|
294 | - } |
|
292 | + if (ini_get('zlib.output_compression')) { |
|
293 | + ini_set('zlib.output_compression', 'Off'); |
|
294 | + } |
|
295 | 295 | |
296 | - header('Pragma: public'); |
|
297 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
298 | - header('Cache-Control: private', false); |
|
299 | - header('Content-Transfer-Encoding: binary'); |
|
300 | - if (isset($mimeType)) { |
|
301 | - header('Content-Type: ' . $mimeType); |
|
302 | - } |
|
296 | + header('Pragma: public'); |
|
297 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
298 | + header('Cache-Control: private', false); |
|
299 | + header('Content-Transfer-Encoding: binary'); |
|
300 | + if (isset($mimeType)) { |
|
301 | + header('Content-Type: ' . $mimeType); |
|
302 | + } |
|
303 | 303 | |
304 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
304 | + header('Content-Disposition: attachment; filename=' . $file_name); |
|
305 | 305 | |
306 | - if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
307 | - $fp = fopen($fullFileName, 'r'); |
|
308 | - } else { |
|
309 | - $fp = fopen($fullFileName, 'rb'); |
|
310 | - } |
|
311 | - fpassthru($fp); |
|
312 | - exit(); |
|
313 | - } |
|
314 | - fclose($handle); |
|
315 | - } |
|
306 | + if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
307 | + $fp = fopen($fullFileName, 'r'); |
|
308 | + } else { |
|
309 | + $fp = fopen($fullFileName, 'rb'); |
|
310 | + } |
|
311 | + fpassthru($fp); |
|
312 | + exit(); |
|
313 | + } |
|
314 | + fclose($handle); |
|
315 | + } |
|
316 | 316 | } |
@@ -203,7 +203,7 @@ |
||
203 | 203 | public function valToCsvHelper($val, $separator, $trimFunction) |
204 | 204 | { |
205 | 205 | if ($trimFunction) { |
206 | - $val = $trimFunction ($val); |
|
206 | + $val = $trimFunction($val); |
|
207 | 207 | } |
208 | 208 | //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
209 | 209 | $needQuote = false; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | /** |
168 | - * @param $keywords |
|
168 | + * @param string|boolean $keywords |
|
169 | 169 | */ |
170 | 170 | public function setKeywords($keywords) |
171 | 171 | { |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
176 | - * @param $categoryPath |
|
176 | + * @param boolean $categoryPath |
|
177 | 177 | */ |
178 | 178 | public function setCategoryPath($categoryPath) |
179 | 179 | { |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * @param $description |
|
185 | + * @param boolean $description |
|
186 | 186 | */ |
187 | 187 | public function setDescription($description) |
188 | 188 | { |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * @param $text |
|
246 | - * @param $minChar |
|
245 | + * @param string $text |
|
246 | + * @param integer $minChar |
|
247 | 247 | * @return array |
248 | 248 | */ |
249 | 249 | public function findMetaKeywords($text, $minChar) |
@@ -18,276 +18,276 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class SmartMetaGen |
20 | 20 | { |
21 | - public $_myts; |
|
22 | - |
|
23 | - public $_title; |
|
24 | - public $_original_title; |
|
25 | - public $_keywords; |
|
26 | - public $_meta_description; |
|
27 | - public $_categoryPath; |
|
28 | - public $_description; |
|
29 | - public $_minChar = 4; |
|
30 | - |
|
31 | - /** |
|
32 | - * SmartMetaGen constructor. |
|
33 | - * @param $title |
|
34 | - * @param bool $keywords |
|
35 | - * @param bool $description |
|
36 | - * @param bool $categoryPath |
|
37 | - */ |
|
38 | - public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
39 | - { |
|
40 | - $this->_myts = MyTextSanitizer::getInstance(); |
|
41 | - $this->setCategoryPath($categoryPath); |
|
42 | - $this->setTitle($title); |
|
43 | - $this->setDescription($description); |
|
44 | - |
|
45 | - if (!$keywords) { |
|
46 | - $keywords = $this->createMetaKeywords(); |
|
47 | - } |
|
48 | - |
|
49 | - /* $myts = MyTextSanitizer::getInstance(); |
|
21 | + public $_myts; |
|
22 | + |
|
23 | + public $_title; |
|
24 | + public $_original_title; |
|
25 | + public $_keywords; |
|
26 | + public $_meta_description; |
|
27 | + public $_categoryPath; |
|
28 | + public $_description; |
|
29 | + public $_minChar = 4; |
|
30 | + |
|
31 | + /** |
|
32 | + * SmartMetaGen constructor. |
|
33 | + * @param $title |
|
34 | + * @param bool $keywords |
|
35 | + * @param bool $description |
|
36 | + * @param bool $categoryPath |
|
37 | + */ |
|
38 | + public function __construct($title, $keywords = false, $description = false, $categoryPath = false) |
|
39 | + { |
|
40 | + $this->_myts = MyTextSanitizer::getInstance(); |
|
41 | + $this->setCategoryPath($categoryPath); |
|
42 | + $this->setTitle($title); |
|
43 | + $this->setDescription($description); |
|
44 | + |
|
45 | + if (!$keywords) { |
|
46 | + $keywords = $this->createMetaKeywords(); |
|
47 | + } |
|
48 | + |
|
49 | + /* $myts = MyTextSanitizer::getInstance(); |
|
50 | 50 | if (method_exists($myts, 'formatForML')) { |
51 | 51 | $keywords = $myts->formatForML($keywords); |
52 | 52 | $description = $myts->formatForML($description); |
53 | 53 | } |
54 | 54 | */ |
55 | - $this->setKeywords($keywords); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Return true if the string is length > 0 |
|
60 | - * |
|
61 | - * @credit psylove |
|
62 | - * |
|
63 | - * @var string $string Chaine de caract�re |
|
64 | - * @return boolean |
|
65 | - */ |
|
66 | - public function emptyString($var) |
|
67 | - { |
|
68 | - return (strlen($var) > 0); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Create a title for the short_url field of an article |
|
73 | - * |
|
74 | - * @credit psylove |
|
75 | - * |
|
76 | - * @var string $title title of the article |
|
77 | - * @param bool|string $withExt |
|
78 | - * @return string sort_url for the article |
|
79 | - */ |
|
80 | - public function generateSeoTitle($title = '', $withExt = true) |
|
81 | - { |
|
82 | - // Transformation de la chaine en minuscule |
|
83 | - // Codage de la chaine afin d'�viter les erreurs 500 en cas de caract�res impr�vus |
|
84 | - $title = rawurlencode(strtolower($title)); |
|
85 | - |
|
86 | - // Transformation des ponctuations |
|
87 | - // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
|
88 | - $pattern = array('/%09/', '/%20/', '/%21/', '/%22/', '/%23/', '/%25/', '/%26/', '/%27/', '/%28/', '/%29/', '/%2C/', '/%2F/', '/%3A/', '/%3B/', '/%3C/', '/%3D/', '/%3E/', '/%3F/', '/%40/', '/%5B/', '/%5C/', '/%5D/', '/%5E/', '/%7B/', '/%7C/', '/%7D/', '/%7E/', "/\./"); |
|
89 | - $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
90 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
91 | - |
|
92 | - // Transformation des caract�res accentu�s |
|
93 | - // ° è é ê ë ç à â ä î ï ù ü û ô ö |
|
94 | - $pattern = array('/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/'); |
|
95 | - $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
96 | - $title = preg_replace($pattern, $rep_pat, $title); |
|
97 | - |
|
98 | - $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
99 | - $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
100 | - $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
101 | - |
|
102 | - if (count($title) > 0) { |
|
103 | - if ($withExt) { |
|
104 | - $title .= '.html'; |
|
105 | - } |
|
106 | - |
|
107 | - return $title; |
|
108 | - } else { |
|
109 | - return ''; |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param $document |
|
115 | - * @return mixed |
|
116 | - */ |
|
117 | - public function html2text($document) |
|
118 | - { |
|
119 | - return smart_html2text($document); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param $title |
|
124 | - */ |
|
125 | - public function setTitle($title) |
|
126 | - { |
|
127 | - global $xoopsModule, $xoopsModuleConfig; |
|
128 | - $this->_title = $this->html2text($title); |
|
129 | - $this->_title = $this->purifyText($this->_title); |
|
130 | - $this->_original_title = $this->_title; |
|
131 | - |
|
132 | - $moduleName = $xoopsModule->getVar('name'); |
|
133 | - |
|
134 | - $titleTag = array(); |
|
135 | - |
|
136 | - $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
137 | - |
|
138 | - if ($moduleName && $show_mod_name_breadcrumb) { |
|
139 | - $titleTag['module'] = $moduleName; |
|
140 | - } |
|
141 | - |
|
142 | - if (isset($this->_title) && ($this->_title != '') && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
143 | - $titleTag['title'] = $this->_title; |
|
144 | - } |
|
145 | - |
|
146 | - if (isset($this->_categoryPath) && ($this->_categoryPath != '')) { |
|
147 | - $titleTag['category'] = $this->_categoryPath; |
|
148 | - } |
|
149 | - |
|
150 | - $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
151 | - |
|
152 | - if (isset($titleTag['category']) && $titleTag['category'] != '') { |
|
153 | - if ($ret != '') { |
|
154 | - $ret .= ' - '; |
|
155 | - } |
|
156 | - $ret .= $titleTag['category']; |
|
157 | - } |
|
158 | - if (isset($titleTag['module']) && $titleTag['module'] !== '') { |
|
159 | - if ($ret != '') { |
|
160 | - $ret .= ' - '; |
|
161 | - } |
|
162 | - $ret .= $titleTag['module']; |
|
163 | - } |
|
164 | - $this->_title = $ret; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param $keywords |
|
169 | - */ |
|
170 | - public function setKeywords($keywords) |
|
171 | - { |
|
172 | - $this->_keywords = $keywords; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param $categoryPath |
|
177 | - */ |
|
178 | - public function setCategoryPath($categoryPath) |
|
179 | - { |
|
180 | - $categoryPath = $this->html2text($categoryPath); |
|
181 | - $this->_categoryPath = $categoryPath; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @param $description |
|
186 | - */ |
|
187 | - public function setDescription($description) |
|
188 | - { |
|
189 | - if (!$description) { |
|
190 | - global $xoopsModuleConfig; |
|
191 | - if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
192 | - $description = $xoopsModuleConfig['module_meta_description']; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - $description = $this->html2text($description); |
|
197 | - $description = $this->purifyText($description); |
|
198 | - |
|
199 | - $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
200 | - $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
201 | - $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
202 | - $description = stripslashes($description); |
|
203 | - |
|
204 | - $this->_description = $description; |
|
205 | - $this->_meta_description = $this->createMetaDescription(); |
|
206 | - } |
|
207 | - |
|
208 | - public function createTitleTag() |
|
209 | - { |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param $text |
|
214 | - * @param bool $keyword |
|
215 | - * @return mixed|string |
|
216 | - */ |
|
217 | - public function purifyText($text, $keyword = false) |
|
218 | - { |
|
219 | - return smart_purifyText($text, $keyword); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @param int $maxWords |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public function createMetaDescription($maxWords = 100) |
|
227 | - { |
|
228 | - $words = array(); |
|
229 | - $words = explode(' ', $this->_description); |
|
230 | - |
|
231 | - // Only keep $maxWords words |
|
232 | - $newWords = array(); |
|
233 | - $i = 0; |
|
234 | - |
|
235 | - while ($i < $maxWords - 1 && $i < count($words)) { |
|
236 | - $newWords[] = $words[$i]; |
|
237 | - ++$i; |
|
238 | - } |
|
239 | - $ret = implode(' ', $newWords); |
|
240 | - |
|
241 | - return $ret; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * @param $text |
|
246 | - * @param $minChar |
|
247 | - * @return array |
|
248 | - */ |
|
249 | - public function findMetaKeywords($text, $minChar) |
|
250 | - { |
|
251 | - $keywords = array(); |
|
252 | - |
|
253 | - $text = $this->purifyText($text); |
|
254 | - $text = $this->html2text($text); |
|
255 | - |
|
256 | - $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
257 | - $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
258 | - $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
259 | - $text = stripslashes($text); |
|
260 | - $text = |
|
261 | - |
|
262 | - $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
263 | - |
|
264 | - foreach ($originalKeywords as $originalKeyword) { |
|
265 | - $secondRoundKeywords = explode("'", $originalKeyword); |
|
266 | - foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
267 | - if (strlen($secondRoundKeyword) >= $minChar) { |
|
268 | - if (!in_array($secondRoundKeyword, $keywords)) { |
|
269 | - $keywords[] = trim($secondRoundKeyword); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - return $keywords; |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @return string |
|
280 | - */ |
|
281 | - public function createMetaKeywords() |
|
282 | - { |
|
283 | - global $xoopsModuleConfig; |
|
284 | - $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
285 | - if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] != '') { |
|
286 | - $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
287 | - $keywords = array_merge($keywords, $moduleKeywords); |
|
288 | - } |
|
289 | - |
|
290 | - /* Commenting this out as it may cause problem on XOOPS ML websites |
|
55 | + $this->setKeywords($keywords); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Return true if the string is length > 0 |
|
60 | + * |
|
61 | + * @credit psylove |
|
62 | + * |
|
63 | + * @var string $string Chaine de caract�re |
|
64 | + * @return boolean |
|
65 | + */ |
|
66 | + public function emptyString($var) |
|
67 | + { |
|
68 | + return (strlen($var) > 0); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Create a title for the short_url field of an article |
|
73 | + * |
|
74 | + * @credit psylove |
|
75 | + * |
|
76 | + * @var string $title title of the article |
|
77 | + * @param bool|string $withExt |
|
78 | + * @return string sort_url for the article |
|
79 | + */ |
|
80 | + public function generateSeoTitle($title = '', $withExt = true) |
|
81 | + { |
|
82 | + // Transformation de la chaine en minuscule |
|
83 | + // Codage de la chaine afin d'�viter les erreurs 500 en cas de caract�res impr�vus |
|
84 | + $title = rawurlencode(strtolower($title)); |
|
85 | + |
|
86 | + // Transformation des ponctuations |
|
87 | + // Tab Space ! " # % & ' ( ) , / : ; < = > ? @ [ \ ] ^ { | } ~ . |
|
88 | + $pattern = array('/%09/', '/%20/', '/%21/', '/%22/', '/%23/', '/%25/', '/%26/', '/%27/', '/%28/', '/%29/', '/%2C/', '/%2F/', '/%3A/', '/%3B/', '/%3C/', '/%3D/', '/%3E/', '/%3F/', '/%40/', '/%5B/', '/%5C/', '/%5D/', '/%5E/', '/%7B/', '/%7C/', '/%7D/', '/%7E/', "/\./"); |
|
89 | + $rep_pat = array('-', '-', '-', '-', '-', '-100', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-at-', '-', '-', '-', '-', '-', '-', '-', '-', '-'); |
|
90 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
91 | + |
|
92 | + // Transformation des caract�res accentu�s |
|
93 | + // ° è é ê ë ç à â ä î ï ù ü û ô ö |
|
94 | + $pattern = array('/%B0/', '/%E8/', '/%E9/', '/%EA/', '/%EB/', '/%E7/', '/%E0/', '/%E2/', '/%E4/', '/%EE/', '/%EF/', '/%F9/', '/%FC/', '/%FB/', '/%F4/', '/%F6/'); |
|
95 | + $rep_pat = array('-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o'); |
|
96 | + $title = preg_replace($pattern, $rep_pat, $title); |
|
97 | + |
|
98 | + $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
|
99 | + $tableau = array_filter($tableau, array($this, 'emptyString')); // Supprime les chaines vides du tableau |
|
100 | + $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
|
101 | + |
|
102 | + if (count($title) > 0) { |
|
103 | + if ($withExt) { |
|
104 | + $title .= '.html'; |
|
105 | + } |
|
106 | + |
|
107 | + return $title; |
|
108 | + } else { |
|
109 | + return ''; |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param $document |
|
115 | + * @return mixed |
|
116 | + */ |
|
117 | + public function html2text($document) |
|
118 | + { |
|
119 | + return smart_html2text($document); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param $title |
|
124 | + */ |
|
125 | + public function setTitle($title) |
|
126 | + { |
|
127 | + global $xoopsModule, $xoopsModuleConfig; |
|
128 | + $this->_title = $this->html2text($title); |
|
129 | + $this->_title = $this->purifyText($this->_title); |
|
130 | + $this->_original_title = $this->_title; |
|
131 | + |
|
132 | + $moduleName = $xoopsModule->getVar('name'); |
|
133 | + |
|
134 | + $titleTag = array(); |
|
135 | + |
|
136 | + $show_mod_name_breadcrumb = isset($xoopsModuleConfig['show_mod_name_breadcrumb']) ? $xoopsModuleConfig['show_mod_name_breadcrumb'] : true; |
|
137 | + |
|
138 | + if ($moduleName && $show_mod_name_breadcrumb) { |
|
139 | + $titleTag['module'] = $moduleName; |
|
140 | + } |
|
141 | + |
|
142 | + if (isset($this->_title) && ($this->_title != '') && (strtoupper($this->_title) != strtoupper($moduleName))) { |
|
143 | + $titleTag['title'] = $this->_title; |
|
144 | + } |
|
145 | + |
|
146 | + if (isset($this->_categoryPath) && ($this->_categoryPath != '')) { |
|
147 | + $titleTag['category'] = $this->_categoryPath; |
|
148 | + } |
|
149 | + |
|
150 | + $ret = isset($titleTag['title']) ? $titleTag['title'] : ''; |
|
151 | + |
|
152 | + if (isset($titleTag['category']) && $titleTag['category'] != '') { |
|
153 | + if ($ret != '') { |
|
154 | + $ret .= ' - '; |
|
155 | + } |
|
156 | + $ret .= $titleTag['category']; |
|
157 | + } |
|
158 | + if (isset($titleTag['module']) && $titleTag['module'] !== '') { |
|
159 | + if ($ret != '') { |
|
160 | + $ret .= ' - '; |
|
161 | + } |
|
162 | + $ret .= $titleTag['module']; |
|
163 | + } |
|
164 | + $this->_title = $ret; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param $keywords |
|
169 | + */ |
|
170 | + public function setKeywords($keywords) |
|
171 | + { |
|
172 | + $this->_keywords = $keywords; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @param $categoryPath |
|
177 | + */ |
|
178 | + public function setCategoryPath($categoryPath) |
|
179 | + { |
|
180 | + $categoryPath = $this->html2text($categoryPath); |
|
181 | + $this->_categoryPath = $categoryPath; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @param $description |
|
186 | + */ |
|
187 | + public function setDescription($description) |
|
188 | + { |
|
189 | + if (!$description) { |
|
190 | + global $xoopsModuleConfig; |
|
191 | + if (isset($xoopsModuleConfig['module_meta_description'])) { |
|
192 | + $description = $xoopsModuleConfig['module_meta_description']; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + $description = $this->html2text($description); |
|
197 | + $description = $this->purifyText($description); |
|
198 | + |
|
199 | + $description = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $description); |
|
200 | + $description = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $description); |
|
201 | + $description = preg_replace('/[ ]* [ ]*/', ' ', $description); |
|
202 | + $description = stripslashes($description); |
|
203 | + |
|
204 | + $this->_description = $description; |
|
205 | + $this->_meta_description = $this->createMetaDescription(); |
|
206 | + } |
|
207 | + |
|
208 | + public function createTitleTag() |
|
209 | + { |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param $text |
|
214 | + * @param bool $keyword |
|
215 | + * @return mixed|string |
|
216 | + */ |
|
217 | + public function purifyText($text, $keyword = false) |
|
218 | + { |
|
219 | + return smart_purifyText($text, $keyword); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @param int $maxWords |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public function createMetaDescription($maxWords = 100) |
|
227 | + { |
|
228 | + $words = array(); |
|
229 | + $words = explode(' ', $this->_description); |
|
230 | + |
|
231 | + // Only keep $maxWords words |
|
232 | + $newWords = array(); |
|
233 | + $i = 0; |
|
234 | + |
|
235 | + while ($i < $maxWords - 1 && $i < count($words)) { |
|
236 | + $newWords[] = $words[$i]; |
|
237 | + ++$i; |
|
238 | + } |
|
239 | + $ret = implode(' ', $newWords); |
|
240 | + |
|
241 | + return $ret; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * @param $text |
|
246 | + * @param $minChar |
|
247 | + * @return array |
|
248 | + */ |
|
249 | + public function findMetaKeywords($text, $minChar) |
|
250 | + { |
|
251 | + $keywords = array(); |
|
252 | + |
|
253 | + $text = $this->purifyText($text); |
|
254 | + $text = $this->html2text($text); |
|
255 | + |
|
256 | + $text = preg_replace("/([^\r\n])\r\n([^\r\n])/", "\\1 \\2", $text); |
|
257 | + $text = preg_replace("/[\r\n]*\r\n[\r\n]*/", "\r\n\r\n", $text); |
|
258 | + $text = preg_replace('/[ ]* [ ]*/', ' ', $text); |
|
259 | + $text = stripslashes($text); |
|
260 | + $text = |
|
261 | + |
|
262 | + $originalKeywords = preg_split('/[^a-zA-Z\'"-]+/', $text, -1, PREG_SPLIT_NO_EMPTY); |
|
263 | + |
|
264 | + foreach ($originalKeywords as $originalKeyword) { |
|
265 | + $secondRoundKeywords = explode("'", $originalKeyword); |
|
266 | + foreach ($secondRoundKeywords as $secondRoundKeyword) { |
|
267 | + if (strlen($secondRoundKeyword) >= $minChar) { |
|
268 | + if (!in_array($secondRoundKeyword, $keywords)) { |
|
269 | + $keywords[] = trim($secondRoundKeyword); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + return $keywords; |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @return string |
|
280 | + */ |
|
281 | + public function createMetaKeywords() |
|
282 | + { |
|
283 | + global $xoopsModuleConfig; |
|
284 | + $keywords = $this->findMetaKeywords($this->_original_title . ' ' . $this->_description, $this->_minChar); |
|
285 | + if (isset($xoopsModuleConfig) && isset($xoopsModuleConfig['moduleMetaKeywords']) && $xoopsModuleConfig['moduleMetaKeywords'] != '') { |
|
286 | + $moduleKeywords = explode(',', $xoopsModuleConfig['moduleMetaKeywords']); |
|
287 | + $keywords = array_merge($keywords, $moduleKeywords); |
|
288 | + } |
|
289 | + |
|
290 | + /* Commenting this out as it may cause problem on XOOPS ML websites |
|
291 | 291 | $return_keywords = array(); |
292 | 292 | |
293 | 293 | // Cleaning for duplicate keywords |
@@ -297,43 +297,43 @@ discard block |
||
297 | 297 | } |
298 | 298 | }*/ |
299 | 299 | |
300 | - // Only take the first 90 keywords |
|
301 | - $newKeywords = array(); |
|
302 | - $i = 0; |
|
303 | - while ($i < 90 - 1 && isset($keywords[$i])) { |
|
304 | - $newKeywords[] = $keywords[$i]; |
|
305 | - ++$i; |
|
306 | - } |
|
307 | - $ret = implode(', ', $newKeywords); |
|
308 | - |
|
309 | - return $ret; |
|
310 | - } |
|
311 | - |
|
312 | - public function autoBuildMeta_keywords() |
|
313 | - { |
|
314 | - } |
|
315 | - |
|
316 | - public function buildAutoMetaTags() |
|
317 | - { |
|
318 | - global $xoopsModule, $xoopsModuleConfig; |
|
319 | - |
|
320 | - $this->_keywords = $this->createMetaKeywords(); |
|
321 | - $this->_meta_description = $this->createMetaDescription(); |
|
322 | - $this->_title = $this->createTitleTag(); |
|
323 | - } |
|
324 | - |
|
325 | - public function createMetaTags() |
|
326 | - { |
|
327 | - global $xoopsTpl, $xoTheme; |
|
328 | - |
|
329 | - if (is_object($xoTheme)) { |
|
330 | - $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
331 | - $xoTheme->addMeta('meta', 'description', $this->_description); |
|
332 | - $xoTheme->addMeta('meta', 'title', $this->_title); |
|
333 | - } else { |
|
334 | - $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
335 | - $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
336 | - } |
|
337 | - $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
338 | - } |
|
300 | + // Only take the first 90 keywords |
|
301 | + $newKeywords = array(); |
|
302 | + $i = 0; |
|
303 | + while ($i < 90 - 1 && isset($keywords[$i])) { |
|
304 | + $newKeywords[] = $keywords[$i]; |
|
305 | + ++$i; |
|
306 | + } |
|
307 | + $ret = implode(', ', $newKeywords); |
|
308 | + |
|
309 | + return $ret; |
|
310 | + } |
|
311 | + |
|
312 | + public function autoBuildMeta_keywords() |
|
313 | + { |
|
314 | + } |
|
315 | + |
|
316 | + public function buildAutoMetaTags() |
|
317 | + { |
|
318 | + global $xoopsModule, $xoopsModuleConfig; |
|
319 | + |
|
320 | + $this->_keywords = $this->createMetaKeywords(); |
|
321 | + $this->_meta_description = $this->createMetaDescription(); |
|
322 | + $this->_title = $this->createTitleTag(); |
|
323 | + } |
|
324 | + |
|
325 | + public function createMetaTags() |
|
326 | + { |
|
327 | + global $xoopsTpl, $xoTheme; |
|
328 | + |
|
329 | + if (is_object($xoTheme)) { |
|
330 | + $xoTheme->addMeta('meta', 'keywords', $this->_keywords); |
|
331 | + $xoTheme->addMeta('meta', 'description', $this->_description); |
|
332 | + $xoTheme->addMeta('meta', 'title', $this->_title); |
|
333 | + } else { |
|
334 | + $xoopsTpl->assign('xoops_meta_keywords', $this->_keywords); |
|
335 | + $xoopsTpl->assign('xoops_meta_description', $this->_description); |
|
336 | + } |
|
337 | + $xoopsTpl->assign('xoops_pagetitle', $this->_title); |
|
338 | + } |
|
339 | 339 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | - * @param $key |
|
167 | + * @param string $key |
|
168 | 168 | * @param $data_type |
169 | 169 | * @param bool $itemName |
170 | 170 | * @param string $form_caption |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
193 | 193 | * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
194 | 194 | * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
195 | - * @param mixed $value default value of this variable |
|
195 | + * @param string|false $value default value of this variable |
|
196 | 196 | */ |
197 | 197 | public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null) |
198 | 198 | { |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
204 | - * @param $varname |
|
204 | + * @param string $varname |
|
205 | 205 | * @param bool $displayOnForm |
206 | 206 | * @param string $default |
207 | 207 | */ |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | /** |
458 | 458 | * add an error |
459 | 459 | * |
460 | - * @param $err_str |
|
460 | + * @param string $err_str |
|
461 | 461 | * @param bool $prefix |
462 | 462 | * @internal param string $value error to add |
463 | 463 | * @access public |
@@ -719,8 +719,8 @@ discard block |
||
719 | 719 | |
720 | 720 | /** |
721 | 721 | * @param $key |
722 | - * @param $info |
|
723 | - * @param $value |
|
722 | + * @param string $info |
|
723 | + * @param boolean $value |
|
724 | 724 | */ |
725 | 725 | public function setVarInfo($key, $info, $value) |
726 | 726 | { |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | } |
729 | 729 | |
730 | 730 | /** |
731 | - * @param $key |
|
731 | + * @param string $key |
|
732 | 732 | * @param bool $editor |
733 | 733 | * @return string |
734 | 734 | */ |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | * @access public |
906 | 906 | * @param string $key key of the object's variable to be returned |
907 | 907 | * @param string $format format to use for the output |
908 | - * @return mixed formatted value of the variable |
|
908 | + * @return string formatted value of the variable |
|
909 | 909 | */ |
910 | 910 | public function getVar($key, $format = 's') |
911 | 911 | { |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | /** |
1211 | - * @param $key |
|
1211 | + * @param string $key |
|
1212 | 1212 | */ |
1213 | 1213 | public function hideFieldFromForm($key) |
1214 | 1214 | { |
@@ -17,31 +17,31 @@ discard block |
||
17 | 17 | include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
18 | 18 | |
19 | 19 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
20 | - define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
20 | + define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
21 | 21 | } |
22 | 22 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
23 | - define('XOBJ_DTYPE_CURRENCY', 200); |
|
23 | + define('XOBJ_DTYPE_CURRENCY', 200); |
|
24 | 24 | } |
25 | 25 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
26 | - define('XOBJ_DTYPE_FLOAT', 201); |
|
26 | + define('XOBJ_DTYPE_FLOAT', 201); |
|
27 | 27 | } |
28 | 28 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
29 | - define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
29 | + define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
30 | 30 | } |
31 | 31 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
32 | - define('XOBJ_DTYPE_URLLINK', 203); |
|
32 | + define('XOBJ_DTYPE_URLLINK', 203); |
|
33 | 33 | } |
34 | 34 | if (!defined('XOBJ_DTYPE_FILE')) { |
35 | - define('XOBJ_DTYPE_FILE', 204); |
|
35 | + define('XOBJ_DTYPE_FILE', 204); |
|
36 | 36 | } |
37 | 37 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
38 | - define('XOBJ_DTYPE_IMAGE', 205); |
|
38 | + define('XOBJ_DTYPE_IMAGE', 205); |
|
39 | 39 | } |
40 | 40 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
41 | - define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
41 | + define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
42 | 42 | } |
43 | 43 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
44 | - define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
44 | + define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -55,1354 +55,1354 @@ discard block |
||
55 | 55 | */ |
56 | 56 | class SmartObject extends XoopsObject |
57 | 57 | { |
58 | - public $_image_path; |
|
59 | - public $_image_url; |
|
60 | - |
|
61 | - public $seoEnabled = false; |
|
62 | - public $titleField; |
|
63 | - public $summaryField = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Reference to the handler managing this object |
|
67 | - * |
|
68 | - * @var object reference to {@link SmartPersistableObjectHandler} |
|
69 | - */ |
|
70 | - public $handler; |
|
71 | - |
|
72 | - /** |
|
73 | - * References to control objects, managing the form fields of this object |
|
74 | - */ |
|
75 | - public $controls = array(); |
|
76 | - |
|
77 | - /** |
|
78 | - * SmartObject constructor. |
|
79 | - * @param $handler |
|
80 | - */ |
|
81 | - public function __construct($handler) |
|
82 | - { |
|
83 | - $this->handler = $handler; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Checks if the user has a specific access on this object |
|
88 | - * |
|
89 | - * @param $perm_name |
|
90 | - * @return bool: TRUE if user has access, false if not |
|
91 | - * @internal param string $gperm_name name of the permission to test |
|
92 | - */ |
|
93 | - public function accessGranted($perm_name) |
|
94 | - { |
|
95 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
96 | - |
|
97 | - return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @param $section_name |
|
102 | - * @param bool $value |
|
103 | - * @param bool $hide |
|
104 | - */ |
|
105 | - public function addFormSection($section_name, $value = false, $hide = false) |
|
106 | - { |
|
107 | - $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
108 | - $this->vars[$section_name]['hide'] = $hide; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @param $section_name |
|
113 | - */ |
|
114 | - public function closeSection($section_name) |
|
115 | - { |
|
116 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * |
|
121 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
122 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
123 | - * @param mixed $value default value of this variable |
|
124 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
125 | - * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
126 | - * @param string $options does this data have any select options? |
|
127 | - * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
128 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
129 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
130 | - * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
131 | - * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
132 | - * @param bool $displayOnForm |
|
133 | - */ |
|
134 | - public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false, $persistent = true, $displayOnForm = true) |
|
135 | - { |
|
136 | - //url_ is reserved for files. |
|
137 | - if (0 === strpos($key, 'url_')) { |
|
138 | - trigger_error("Cannot use variable starting with 'url_'."); |
|
139 | - } |
|
140 | - parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
141 | - if ($this->handler && (!$form_caption || $form_caption == '')) { |
|
142 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
143 | - if (defined($dyn_form_caption)) { |
|
144 | - $form_caption = constant($dyn_form_caption); |
|
145 | - } |
|
146 | - } |
|
147 | - if ($this->handler && (!$form_dsc || $form_dsc == '')) { |
|
148 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
149 | - if (defined($dyn_form_dsc)) { |
|
150 | - $form_dsc = constant($dyn_form_dsc); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - $this->vars[$key] = array_merge($this->vars[$key], array( |
|
155 | - 'multilingual' => $multilingual, |
|
156 | - 'form_caption' => $form_caption, |
|
157 | - 'form_dsc' => $form_dsc, |
|
158 | - 'sortby' => $sortby, |
|
159 | - 'persistent' => $persistent, |
|
160 | - 'displayOnForm' => $displayOnForm, |
|
161 | - 'displayOnSingleView' => true, |
|
162 | - 'readonly' => false |
|
163 | - )); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param $key |
|
168 | - * @param $data_type |
|
169 | - * @param bool $itemName |
|
170 | - * @param string $form_caption |
|
171 | - * @param bool $sortby |
|
172 | - * @param string $value |
|
173 | - * @param bool $displayOnForm |
|
174 | - * @param bool $required |
|
175 | - */ |
|
176 | - public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false) |
|
177 | - { |
|
178 | - $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
179 | - $this->vars[$key]['itemName'] = $itemName; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Quickly initiate a var |
|
184 | - * |
|
185 | - * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
186 | - * |
|
187 | - * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
188 | - * - all other vars are NULL or '' depending of the parameter |
|
189 | - * |
|
190 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
191 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
192 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
193 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
194 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
195 | - * @param mixed $value default value of this variable |
|
196 | - */ |
|
197 | - public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null) |
|
198 | - { |
|
199 | - $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
200 | - $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param $varname |
|
205 | - * @param bool $displayOnForm |
|
206 | - * @param string $default |
|
207 | - */ |
|
208 | - public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
209 | - { |
|
210 | - switch ($varname) { |
|
211 | - case 'dohtml': |
|
212 | - $value = $default !== 'notdefined' ? $default : true; |
|
213 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
214 | - $this->setControl($varname, 'yesno'); |
|
215 | - break; |
|
216 | - |
|
217 | - case 'dobr': |
|
218 | - $value = ($default === 'notdefined') ? true : $default; |
|
219 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
220 | - $this->setControl($varname, 'yesno'); |
|
221 | - break; |
|
222 | - |
|
223 | - case 'doimage': |
|
224 | - $value = $default !== 'notdefined' ? $default : true; |
|
225 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
226 | - $this->setControl($varname, 'yesno'); |
|
227 | - break; |
|
228 | - |
|
229 | - case 'dosmiley': |
|
230 | - $value = $default !== 'notdefined' ? $default : true; |
|
231 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
232 | - $this->setControl($varname, 'yesno'); |
|
233 | - break; |
|
234 | - |
|
235 | - case 'doxcode': |
|
236 | - $value = $default !== 'notdefined' ? $default : true; |
|
237 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
238 | - $this->setControl($varname, 'yesno'); |
|
239 | - break; |
|
240 | - |
|
241 | - case 'meta_keywords': |
|
242 | - $value = $default !== 'notdefined' ? $default : ''; |
|
243 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
244 | - $this->setControl('meta_keywords', array( |
|
245 | - 'name' => 'textarea', |
|
246 | - 'form_editor' => 'textarea' |
|
247 | - )); |
|
248 | - break; |
|
249 | - |
|
250 | - case 'meta_description': |
|
251 | - $value = $default !== 'notdefined' ? $default : ''; |
|
252 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
253 | - $this->setControl('meta_description', array( |
|
254 | - 'name' => 'textarea', |
|
255 | - 'form_editor' => 'textarea' |
|
256 | - )); |
|
257 | - break; |
|
258 | - |
|
259 | - case 'short_url': |
|
260 | - $value = $default !== 'notdefined' ? $default : ''; |
|
261 | - $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
262 | - break; |
|
263 | - |
|
264 | - case 'hierarchy_path': |
|
265 | - $value = $default !== 'notdefined' ? $default : ''; |
|
266 | - $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
267 | - break; |
|
268 | - |
|
269 | - case 'counter': |
|
270 | - $value = $default !== 'notdefined' ? $default : 0; |
|
271 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
272 | - break; |
|
273 | - |
|
274 | - case 'weight': |
|
275 | - $value = $default !== 'notdefined' ? $default : 0; |
|
276 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
277 | - break; |
|
278 | - case 'custom_css': |
|
279 | - $value = $default !== 'notdefined' ? $default : ''; |
|
280 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
281 | - $this->setControl('custom_css', array( |
|
282 | - 'name' => 'textarea', |
|
283 | - 'form_editor' => 'textarea' |
|
284 | - )); |
|
285 | - break; |
|
286 | - } |
|
287 | - $this->hideFieldFromSingleView($varname); |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Set control information for an instance variable |
|
292 | - * |
|
293 | - * The $options parameter can be a string or an array. Using a string |
|
294 | - * is the quickest way: |
|
295 | - * |
|
296 | - * $this->setControl('date', 'date_time'); |
|
297 | - * |
|
298 | - * This will create a date and time selectbox for the 'date' var on the |
|
299 | - * form to edit or create this item. |
|
300 | - * |
|
301 | - * Here are the currently supported controls: |
|
302 | - * |
|
303 | - * - color |
|
304 | - * - country |
|
305 | - * - date_time |
|
306 | - * - date |
|
307 | ||
308 | - * - group |
|
309 | - * - group_multi |
|
310 | - * - image |
|
311 | - * - imageupload |
|
312 | - * - label |
|
313 | - * - language |
|
314 | - * - parentcategory |
|
315 | - * - password |
|
316 | - * - select_multi |
|
317 | - * - select |
|
318 | - * - text |
|
319 | - * - textarea |
|
320 | - * - theme |
|
321 | - * - theme_multi |
|
322 | - * - timezone |
|
323 | - * - user |
|
324 | - * - user_multi |
|
325 | - * - yesno |
|
326 | - * |
|
327 | - * Now, using an array as $options, you can customize what information to |
|
328 | - * use in the control. For example, if one needs to display a select box for |
|
329 | - * the user to choose the status of an item. We only need to tell SmartObject |
|
330 | - * what method to execute within what handler to retreive the options of the |
|
331 | - * selectbox. |
|
332 | - * |
|
333 | - * $this->setControl('status', array('name' => false, |
|
334 | - * 'itemHandler' => 'item', |
|
335 | - * 'method' => 'getStatus', |
|
336 | - * 'module' => 'smartshop')); |
|
337 | - * |
|
338 | - * In this example, the array elements are the following: |
|
339 | - * - name: false, as we don't need to set a special control here. |
|
340 | - * we will use the default control related to the object type (defined in initVar) |
|
341 | - * - itemHandler: name of the object for which we will use the handler |
|
342 | - * - method: name of the method of this handler that we will execute |
|
343 | - * - module: name of the module from wich the handler is |
|
344 | - * |
|
345 | - * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
346 | - * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
347 | - * |
|
348 | - * Another example of the use of $options as an array is for TextArea: |
|
349 | - * |
|
350 | - * $this->setControl('body', array('name' => 'textarea', |
|
351 | - * 'form_editor' => 'default')); |
|
352 | - * |
|
353 | - * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
354 | - * the 'default' editor, providing it is defined in the module |
|
355 | - * preferences: $xoopsModuleConfig['default_editor'] |
|
356 | - * |
|
357 | - * Of course, you can force the use of a specific editor: |
|
358 | - * |
|
359 | - * $this->setControl('body', array('name' => 'textarea', |
|
360 | - * 'form_editor' => 'koivi')); |
|
361 | - * |
|
362 | - * Here is a list of supported editor: |
|
363 | - * - tiny: TinyEditor |
|
364 | - * - dhtmltextarea: XOOPS DHTML Area |
|
365 | - * - fckeditor: FCKEditor |
|
366 | - * - inbetween: InBetween |
|
367 | - * - koivi: Koivi |
|
368 | - * - spaw: Spaw WYSIWYG Editor |
|
369 | - * - htmlarea: HTMLArea |
|
370 | - * - textarea: basic textarea with no options |
|
371 | - * |
|
372 | - * @param string $var name of the variable for which we want to set a control |
|
373 | - * @param array $options |
|
374 | - */ |
|
375 | - public function setControl($var, $options = array()) |
|
376 | - { |
|
377 | - if (isset($this->controls[$var])) { |
|
378 | - unset($this->controls[$var]); |
|
379 | - } |
|
380 | - if (is_string($options)) { |
|
381 | - $options = array('name' => $options); |
|
382 | - } |
|
383 | - $this->controls[$var] = $options; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Get control information for an instance variable |
|
388 | - * |
|
389 | - * @param string $var |
|
390 | - * @return bool|mixed |
|
391 | - */ |
|
392 | - public function getControl($var) |
|
393 | - { |
|
394 | - return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Create the form for this object |
|
399 | - * |
|
400 | - * @param $form_caption |
|
401 | - * @param $form_name |
|
402 | - * @param bool $form_action |
|
403 | - * @param string $submit_button_caption |
|
404 | - * @param bool $cancel_js_action |
|
405 | - * @param bool $captcha |
|
406 | - * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
407 | - * object for this object |
|
408 | - * @see SmartObjectForm::SmartObjectForm() |
|
409 | - */ |
|
410 | - public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false) |
|
411 | - { |
|
412 | - include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
413 | - $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
414 | - |
|
415 | - return $form; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * @return array |
|
420 | - */ |
|
421 | - public function toArray() |
|
422 | - { |
|
423 | - $ret = array(); |
|
424 | - $vars =& $this->getVars(); |
|
425 | - foreach ($vars as $key => $var) { |
|
426 | - $value = $this->getVar($key); |
|
427 | - $ret[$key] = $value; |
|
428 | - } |
|
429 | - if ($this->handler->identifierName != '') { |
|
430 | - $controller = new SmartObjectController($this->handler); |
|
431 | - /** |
|
432 | - * Addition of some automatic value |
|
433 | - */ |
|
434 | - $ret['itemLink'] = $controller->getItemLink($this); |
|
435 | - $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
436 | - $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
437 | - $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
438 | - $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
439 | - } |
|
440 | - |
|
441 | - // Hightlighting searched words |
|
442 | - include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'); |
|
443 | - $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
444 | - |
|
445 | - if ($highlight && isset($_GET['keywords'])) { |
|
446 | - $myts = MyTextSanitizer::getInstance(); |
|
447 | - $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
448 | - $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
449 | - foreach ($this->handler->highlightFields as $field) { |
|
450 | - $ret[$field] = $h->highlight($ret[$field]); |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - return $ret; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * add an error |
|
459 | - * |
|
460 | - * @param $err_str |
|
461 | - * @param bool $prefix |
|
462 | - * @internal param string $value error to add |
|
463 | - * @access public |
|
464 | - */ |
|
465 | - public function setErrors($err_str, $prefix = false) |
|
466 | - { |
|
467 | - if (is_array($err_str)) { |
|
468 | - foreach ($err_str as $str) { |
|
469 | - $this->setErrors($str, $prefix); |
|
470 | - } |
|
471 | - } else { |
|
472 | - if ($prefix) { |
|
473 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
474 | - } |
|
475 | - parent::setErrors($err_str); |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @param $field |
|
481 | - * @param bool $required |
|
482 | - */ |
|
483 | - public function setFieldAsRequired($field, $required = true) |
|
484 | - { |
|
485 | - if (is_array($field)) { |
|
486 | - foreach ($field as $v) { |
|
487 | - $this->doSetFieldAsRequired($v, $required); |
|
488 | - } |
|
489 | - } else { |
|
490 | - $this->doSetFieldAsRequired($field, $required); |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @param $field |
|
496 | - */ |
|
497 | - public function setFieldForSorting($field) |
|
498 | - { |
|
499 | - if (is_array($field)) { |
|
500 | - foreach ($field as $v) { |
|
501 | - $this->doSetFieldForSorting($v); |
|
502 | - } |
|
503 | - } else { |
|
504 | - $this->doSetFieldForSorting($field); |
|
505 | - } |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * @return bool |
|
510 | - */ |
|
511 | - public function hasError() |
|
512 | - { |
|
513 | - return count($this->_errors) > 0; |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * @param $url |
|
518 | - * @param $path |
|
519 | - */ |
|
520 | - public function setImageDir($url, $path) |
|
521 | - { |
|
522 | - $this->_image_url = $url; |
|
523 | - $this->_image_path = $path; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Retreive the group that have been granted access to a specific permission for this object |
|
528 | - * |
|
529 | - * @param $group_perm |
|
530 | - * @return string $group_perm name of the permission |
|
531 | - */ |
|
532 | - public function getGroupPerm($group_perm) |
|
533 | - { |
|
534 | - if (!$this->handler->getPermissions()) { |
|
535 | - $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
536 | - |
|
537 | - return false; |
|
538 | - } |
|
539 | - |
|
540 | - $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
541 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
542 | - |
|
543 | - if (count($ret) == 0) { |
|
544 | - return false; |
|
545 | - } else { |
|
546 | - return $ret; |
|
547 | - } |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * @param bool $path |
|
552 | - * @return mixed |
|
553 | - */ |
|
554 | - public function getImageDir($path = false) |
|
555 | - { |
|
556 | - if ($path) { |
|
557 | - return $this->_image_path; |
|
558 | - } else { |
|
559 | - return $this->_image_url; |
|
560 | - } |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * @param bool $path |
|
565 | - * @return mixed |
|
566 | - */ |
|
567 | - public function getUploadDir($path = false) |
|
568 | - { |
|
569 | - if ($path) { |
|
570 | - return $this->_image_path; |
|
571 | - } else { |
|
572 | - return $this->_image_url; |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * @param string $key |
|
578 | - * @param string $info |
|
579 | - * @return array |
|
580 | - */ |
|
581 | - public function getVarInfo($key = '', $info = '') |
|
582 | - { |
|
583 | - if (isset($this->vars[$key][$info])) { |
|
584 | - return $this->vars[$key][$info]; |
|
585 | - } elseif ($info == '' && isset($this->vars[$key])) { |
|
586 | - return $this->vars[$key]; |
|
587 | - } else { |
|
588 | - return $this->vars; |
|
589 | - } |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Get the id of the object |
|
594 | - * |
|
595 | - * @return int id of this object |
|
596 | - */ |
|
597 | - public function id() |
|
598 | - { |
|
599 | - return $this->getVar($this->handler->keyName, 'e'); |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Return the value of the title field of this object |
|
604 | - * |
|
605 | - * @param string $format |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function title($format = 's') |
|
609 | - { |
|
610 | - return $this->getVar($this->handler->identifierName, $format); |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Return the value of the title field of this object |
|
615 | - * |
|
616 | - * @return string |
|
617 | - */ |
|
618 | - public function summary() |
|
619 | - { |
|
620 | - if ($this->handler->summaryName) { |
|
621 | - return $this->getVar($this->handler->summaryName); |
|
622 | - } else { |
|
623 | - return false; |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Retreive the object admin side link, displayijng a SingleView page |
|
629 | - * |
|
630 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
631 | - * @return string user side link to the object |
|
632 | - */ |
|
633 | - public function getAdminViewItemLink($onlyUrl = false) |
|
634 | - { |
|
635 | - $controller = new SmartObjectController($this->handler); |
|
636 | - |
|
637 | - return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * Retreive the object user side link |
|
642 | - * |
|
643 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
644 | - * @return string user side link to the object |
|
645 | - */ |
|
646 | - public function getItemLink($onlyUrl = false) |
|
647 | - { |
|
648 | - $controller = new SmartObjectController($this->handler); |
|
649 | - |
|
650 | - return $controller->getItemLink($this, $onlyUrl); |
|
651 | - } |
|
652 | - |
|
653 | - /** |
|
654 | - * @param bool $onlyUrl |
|
655 | - * @param bool $withimage |
|
656 | - * @param bool $userSide |
|
657 | - * @return string |
|
658 | - */ |
|
659 | - public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
660 | - { |
|
661 | - $controller = new SmartObjectController($this->handler); |
|
662 | - |
|
663 | - return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * @param bool $onlyUrl |
|
668 | - * @param bool $withimage |
|
669 | - * @param bool $userSide |
|
670 | - * @return string |
|
671 | - */ |
|
672 | - public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
673 | - { |
|
674 | - $controller = new SmartObjectController($this->handler); |
|
675 | - |
|
676 | - return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * @return string |
|
681 | - */ |
|
682 | - public function getPrintAndMailLink() |
|
683 | - { |
|
684 | - $controller = new SmartObjectController($this->handler); |
|
685 | - |
|
686 | - return $controller->getPrintAndMailLink($this); |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * @param $sortsel |
|
691 | - * @return array|bool |
|
692 | - */ |
|
693 | - public function getFieldsForSorting($sortsel) |
|
694 | - { |
|
695 | - $ret = array(); |
|
696 | - |
|
697 | - foreach ($this->vars as $key => $field_info) { |
|
698 | - if ($field_info['sortby']) { |
|
699 | - $ret[$key]['caption'] = $field_info['form_caption']; |
|
700 | - $ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : ''; |
|
701 | - } |
|
702 | - } |
|
703 | - |
|
704 | - if (count($ret) > 0) { |
|
705 | - return $ret; |
|
706 | - } else { |
|
707 | - return false; |
|
708 | - } |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * @param $key |
|
713 | - * @param $newType |
|
714 | - */ |
|
715 | - public function setType($key, $newType) |
|
716 | - { |
|
717 | - $this->vars[$key]['data_type'] = $newType; |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * @param $key |
|
722 | - * @param $info |
|
723 | - * @param $value |
|
724 | - */ |
|
725 | - public function setVarInfo($key, $info, $value) |
|
726 | - { |
|
727 | - $this->vars[$key][$info] = $value; |
|
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * @param $key |
|
732 | - * @param bool $editor |
|
733 | - * @return string |
|
734 | - */ |
|
735 | - public function getValueFor($key, $editor = true) |
|
736 | - { |
|
737 | - global $xoopsModuleConfig; |
|
738 | - |
|
739 | - $ret = $this->getVar($key, 'n'); |
|
740 | - $myts = MyTextSanitizer::getInstance(); |
|
741 | - |
|
742 | - $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
743 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
744 | - |
|
745 | - $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
746 | - $smiley = true; |
|
747 | - $xcode = true; |
|
748 | - $image = true; |
|
749 | - $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
750 | - $formatML = true; |
|
751 | - |
|
752 | - if ($form_editor === 'default') { |
|
753 | - global $xoopsModuleConfig; |
|
754 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
755 | - } |
|
756 | - |
|
757 | - if ($editor) { |
|
758 | - if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
759 | - $br = false; |
|
760 | - $formatML = !$editor; |
|
761 | - } else { |
|
762 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - if (method_exists($myts, 'formatForML')) { |
|
767 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
768 | - } else { |
|
769 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
770 | - } |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * clean values of all variables of the object for storage. |
|
775 | - * also add slashes whereever needed |
|
776 | - * |
|
777 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
778 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
779 | - * as a string separated by | |
|
780 | - * |
|
781 | - * @return bool true if successful |
|
782 | - * @access public |
|
783 | - */ |
|
784 | - public function cleanVars() |
|
785 | - { |
|
786 | - $ts = MyTextSanitizer::getInstance(); |
|
787 | - $existing_errors = $this->getErrors(); |
|
788 | - $this->_errors = array(); |
|
789 | - foreach ($this->vars as $k => $v) { |
|
790 | - $cleanv = $v['value']; |
|
791 | - if (!$v['changed']) { |
|
792 | - } else { |
|
793 | - $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
794 | - switch ($v['data_type']) { |
|
795 | - case XOBJ_DTYPE_TXTBOX: |
|
796 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
797 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
798 | - continue; |
|
799 | - } |
|
800 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
801 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
802 | - continue; |
|
803 | - } |
|
804 | - if (!$v['not_gpc']) { |
|
805 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
806 | - } else { |
|
807 | - $cleanv = $ts->censorString($cleanv); |
|
808 | - } |
|
809 | - break; |
|
810 | - case XOBJ_DTYPE_TXTAREA: |
|
811 | - if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
812 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
813 | - continue; |
|
814 | - } |
|
815 | - if (!$v['not_gpc']) { |
|
816 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
817 | - } else { |
|
818 | - $cleanv = $ts->censorString($cleanv); |
|
819 | - } |
|
820 | - break; |
|
821 | - case XOBJ_DTYPE_SOURCE: |
|
822 | - if (!$v['not_gpc']) { |
|
823 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
824 | - } else { |
|
825 | - $cleanv = $cleanv; |
|
826 | - } |
|
827 | - break; |
|
828 | - case XOBJ_DTYPE_INT: |
|
829 | - case XOBJ_DTYPE_TIME_ONLY: |
|
830 | - $cleanv = (int)$cleanv; |
|
831 | - break; |
|
832 | - |
|
833 | - case XOBJ_DTYPE_CURRENCY: |
|
834 | - $cleanv = smart_currency($cleanv); |
|
835 | - break; |
|
836 | - |
|
837 | - case XOBJ_DTYPE_FLOAT: |
|
838 | - $cleanv = smart_float($cleanv); |
|
839 | - break; |
|
840 | - |
|
841 | - case XOBJ_DTYPE_EMAIL: |
|
842 | - if ($v['required'] && $cleanv == '') { |
|
843 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
844 | - continue; |
|
845 | - } |
|
846 | - if ($cleanv != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
847 | - $this->setErrors('Invalid Email'); |
|
848 | - continue; |
|
849 | - } |
|
850 | - if (!$v['not_gpc']) { |
|
851 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
852 | - } |
|
853 | - break; |
|
854 | - case XOBJ_DTYPE_URL: |
|
855 | - if ($v['required'] && $cleanv == '') { |
|
856 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
857 | - continue; |
|
858 | - } |
|
859 | - if ($cleanv != '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
860 | - $cleanv = 'http://' . $cleanv; |
|
861 | - } |
|
862 | - if (!$v['not_gpc']) { |
|
863 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
864 | - } |
|
865 | - break; |
|
866 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
867 | - $cleanv = implode('|', $cleanv); |
|
868 | - break; |
|
869 | - case XOBJ_DTYPE_ARRAY: |
|
870 | - $cleanv = serialize($cleanv); |
|
871 | - break; |
|
872 | - case XOBJ_DTYPE_STIME: |
|
873 | - case XOBJ_DTYPE_MTIME: |
|
874 | - case XOBJ_DTYPE_LTIME: |
|
875 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
876 | - if (!($cleanv > 0)) { |
|
877 | - $cleanv = strtotime($cleanv); |
|
878 | - } |
|
879 | - break; |
|
880 | - default: |
|
881 | - break; |
|
882 | - } |
|
883 | - } |
|
884 | - $this->cleanVars[$k] =& $cleanv; |
|
885 | - unset($cleanv); |
|
886 | - } |
|
887 | - if (count($this->_errors) > 0) { |
|
888 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
889 | - |
|
890 | - return false; |
|
891 | - } |
|
892 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
893 | - $this->unsetDirty(); |
|
894 | - |
|
895 | - return true; |
|
896 | - } |
|
897 | - |
|
898 | - /** |
|
899 | - * returns a specific variable for the object in a proper format |
|
900 | - * |
|
901 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
902 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
903 | - * as a string separated by | |
|
904 | - * |
|
905 | - * @access public |
|
906 | - * @param string $key key of the object's variable to be returned |
|
907 | - * @param string $format format to use for the output |
|
908 | - * @return mixed formatted value of the variable |
|
909 | - */ |
|
910 | - public function getVar($key, $format = 's') |
|
911 | - { |
|
912 | - global $myts; |
|
913 | - |
|
914 | - $ret = $this->vars[$key]['value']; |
|
915 | - |
|
916 | - switch ($this->vars[$key]['data_type']) { |
|
917 | - |
|
918 | - case XOBJ_DTYPE_TXTBOX: |
|
919 | - switch (strtolower($format)) { |
|
920 | - case 's': |
|
921 | - case 'show': |
|
922 | - // ML Hack by marcan |
|
923 | - $ts = MyTextSanitizer::getInstance(); |
|
924 | - $ret = $ts->htmlSpecialChars($ret); |
|
925 | - |
|
926 | - if (method_exists($myts, 'formatForML')) { |
|
927 | - return $ts->formatForML($ret); |
|
928 | - } else { |
|
929 | - return $ret; |
|
930 | - } |
|
931 | - break 1; |
|
932 | - // End of ML Hack by marcan |
|
933 | - |
|
934 | - case 'clean': |
|
935 | - $ts = MyTextSanitizer::getInstance(); |
|
936 | - |
|
937 | - $ret = smart_html2text($ret); |
|
938 | - $ret = smart_purifyText($ret); |
|
939 | - |
|
940 | - if (method_exists($myts, 'formatForML')) { |
|
941 | - return $ts->formatForML($ret); |
|
942 | - } else { |
|
943 | - return $ret; |
|
944 | - } |
|
945 | - break 1; |
|
946 | - // End of ML Hack by marcan |
|
947 | - |
|
948 | - case 'e': |
|
949 | - case 'edit': |
|
950 | - $ts = MyTextSanitizer::getInstance(); |
|
951 | - |
|
952 | - return $ts->htmlSpecialChars($ret); |
|
953 | - break 1; |
|
954 | - case 'p': |
|
955 | - case 'preview': |
|
956 | - case 'f': |
|
957 | - case 'formpreview': |
|
958 | - $ts = MyTextSanitizer::getInstance(); |
|
959 | - |
|
960 | - return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
961 | - break 1; |
|
962 | - case 'n': |
|
963 | - case 'none': |
|
964 | - default: |
|
965 | - break 1; |
|
966 | - } |
|
967 | - break; |
|
968 | - case XOBJ_DTYPE_LTIME: |
|
969 | - switch (strtolower($format)) { |
|
970 | - case 's': |
|
971 | - case 'show': |
|
972 | - case 'p': |
|
973 | - case 'preview': |
|
974 | - case 'f': |
|
975 | - case 'formpreview': |
|
976 | - $ret = formatTimestamp($ret, _DATESTRING); |
|
977 | - |
|
978 | - return $ret; |
|
979 | - break 1; |
|
980 | - case 'n': |
|
981 | - case 'none': |
|
982 | - case 'e': |
|
983 | - case 'edit': |
|
984 | - break 1; |
|
985 | - default: |
|
986 | - break 1; |
|
987 | - } |
|
988 | - break; |
|
989 | - case XOBJ_DTYPE_STIME: |
|
990 | - switch (strtolower($format)) { |
|
991 | - case 's': |
|
992 | - case 'show': |
|
993 | - case 'p': |
|
994 | - case 'preview': |
|
995 | - case 'f': |
|
996 | - case 'formpreview': |
|
997 | - $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
998 | - |
|
999 | - return $ret; |
|
1000 | - break 1; |
|
1001 | - case 'n': |
|
1002 | - case 'none': |
|
1003 | - case 'e': |
|
1004 | - case 'edit': |
|
1005 | - break 1; |
|
1006 | - default: |
|
1007 | - break 1; |
|
1008 | - } |
|
1009 | - break; |
|
1010 | - case XOBJ_DTYPE_TIME_ONLY: |
|
1011 | - switch (strtolower($format)) { |
|
1012 | - case 's': |
|
1013 | - case 'show': |
|
1014 | - case 'p': |
|
1015 | - case 'preview': |
|
1016 | - case 'f': |
|
1017 | - case 'formpreview': |
|
1018 | - $ret = formatTimestamp($ret, 'G:i'); |
|
1019 | - |
|
1020 | - return $ret; |
|
1021 | - break 1; |
|
1022 | - case 'n': |
|
1023 | - case 'none': |
|
1024 | - case 'e': |
|
1025 | - case 'edit': |
|
1026 | - break 1; |
|
1027 | - default: |
|
1028 | - break 1; |
|
1029 | - } |
|
1030 | - break; |
|
1031 | - |
|
1032 | - case XOBJ_DTYPE_CURRENCY: |
|
1033 | - $decimal_section_original = strstr($ret, '.'); |
|
1034 | - $decimal_section = $decimal_section_original; |
|
1035 | - if ($decimal_section) { |
|
1036 | - if (strlen($decimal_section) == 1) { |
|
1037 | - $decimal_section = '.00'; |
|
1038 | - } elseif (strlen($decimal_section) == 2) { |
|
1039 | - $decimal_section = $decimal_section . '0'; |
|
1040 | - } |
|
1041 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1042 | - } else { |
|
1043 | - $ret = $ret . '.00'; |
|
1044 | - } |
|
1045 | - break; |
|
1046 | - |
|
1047 | - case XOBJ_DTYPE_TXTAREA: |
|
1048 | - switch (strtolower($format)) { |
|
1049 | - case 's': |
|
1050 | - case 'show': |
|
1051 | - $ts = MyTextSanitizer::getInstance(); |
|
1052 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1053 | - |
|
1054 | - $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1055 | - |
|
1056 | - $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1057 | - $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1058 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Hack by marcan <INBOX> for SCSPRO |
|
1062 | - * Setting mastop as the main editor |
|
1063 | - */ |
|
1064 | - if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1065 | - $br = false; |
|
1066 | - } |
|
1067 | - /** |
|
1068 | - * Hack by marcan <INBOX> for SCSPRO |
|
1069 | - * Setting mastop as the main editor |
|
1070 | - */ |
|
1071 | - |
|
1072 | - return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1073 | - break 1; |
|
1074 | - case 'e': |
|
1075 | - case 'edit': |
|
1076 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1077 | - break 1; |
|
1078 | - case 'p': |
|
1079 | - case 'preview': |
|
1080 | - $ts = MyTextSanitizer::getInstance(); |
|
1081 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1082 | - $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1083 | - $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1084 | - $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1085 | - $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1086 | - |
|
1087 | - return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1088 | - break 1; |
|
1089 | - case 'f': |
|
1090 | - case 'formpreview': |
|
1091 | - $ts = MyTextSanitizer::getInstance(); |
|
1092 | - |
|
1093 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1094 | - break 1; |
|
1095 | - case 'n': |
|
1096 | - case 'none': |
|
1097 | - default: |
|
1098 | - break 1; |
|
1099 | - } |
|
1100 | - break; |
|
1101 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1102 | - $ret =& explode('|', $ret); |
|
1103 | - break; |
|
1104 | - case XOBJ_DTYPE_ARRAY: |
|
1105 | - $ret =& unserialize($ret); |
|
1106 | - break; |
|
1107 | - case XOBJ_DTYPE_SOURCE: |
|
1108 | - switch (strtolower($format)) { |
|
1109 | - case 's': |
|
1110 | - case 'show': |
|
1111 | - break 1; |
|
1112 | - case 'e': |
|
1113 | - case 'edit': |
|
1114 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1115 | - break 1; |
|
1116 | - case 'p': |
|
1117 | - case 'preview': |
|
1118 | - $ts = MyTextSanitizer::getInstance(); |
|
1119 | - |
|
1120 | - return $ts->stripSlashesGPC($ret); |
|
1121 | - break 1; |
|
1122 | - case 'f': |
|
1123 | - case 'formpreview': |
|
1124 | - $ts = MyTextSanitizer::getInstance(); |
|
1125 | - |
|
1126 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1127 | - break 1; |
|
1128 | - case 'n': |
|
1129 | - case 'none': |
|
1130 | - default: |
|
1131 | - break 1; |
|
1132 | - } |
|
1133 | - break; |
|
1134 | - default: |
|
1135 | - if ($this->vars[$key]['options'] != '' && $ret != '') { |
|
1136 | - switch (strtolower($format)) { |
|
1137 | - case 's': |
|
1138 | - case 'show': |
|
1139 | - $selected = explode('|', $ret); |
|
1140 | - $options = explode('|', $this->vars[$key]['options']); |
|
1141 | - $i = 1; |
|
1142 | - $ret = array(); |
|
1143 | - foreach ($options as $op) { |
|
1144 | - if (in_array($i, $selected)) { |
|
1145 | - $ret[] = $op; |
|
1146 | - } |
|
1147 | - ++$i; |
|
1148 | - } |
|
1149 | - |
|
1150 | - return implode(', ', $ret); |
|
1151 | - case 'e': |
|
1152 | - case 'edit': |
|
1153 | - $ret = explode('|', $ret); |
|
1154 | - break 1; |
|
1155 | - default: |
|
1156 | - break 1; |
|
1157 | - } |
|
1158 | - } |
|
1159 | - break; |
|
1160 | - } |
|
1161 | - |
|
1162 | - return $ret; |
|
1163 | - } |
|
1164 | - |
|
1165 | - /** |
|
1166 | - * @param $key |
|
1167 | - */ |
|
1168 | - public function doMakeFieldreadOnly($key) |
|
1169 | - { |
|
1170 | - if (isset($this->vars[$key])) { |
|
1171 | - $this->vars[$key]['readonly'] = true; |
|
1172 | - $this->vars[$key]['displayOnForm'] = true; |
|
1173 | - } |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * @param $key |
|
1178 | - */ |
|
1179 | - public function makeFieldReadOnly($key) |
|
1180 | - { |
|
1181 | - if (is_array($key)) { |
|
1182 | - foreach ($key as $v) { |
|
1183 | - $this->doMakeFieldreadOnly($v); |
|
1184 | - } |
|
1185 | - } else { |
|
1186 | - $this->doMakeFieldreadOnly($key); |
|
1187 | - } |
|
1188 | - } |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * @param $key |
|
1192 | - */ |
|
1193 | - public function doHideFieldFromForm($key) |
|
1194 | - { |
|
1195 | - if (isset($this->vars[$key])) { |
|
1196 | - $this->vars[$key]['displayOnForm'] = false; |
|
1197 | - } |
|
1198 | - } |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * @param $key |
|
1202 | - */ |
|
1203 | - public function doHideFieldFromSingleView($key) |
|
1204 | - { |
|
1205 | - if (isset($this->vars[$key])) { |
|
1206 | - $this->vars[$key]['displayOnSingleView'] = false; |
|
1207 | - } |
|
1208 | - } |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * @param $key |
|
1212 | - */ |
|
1213 | - public function hideFieldFromForm($key) |
|
1214 | - { |
|
1215 | - if (is_array($key)) { |
|
1216 | - foreach ($key as $v) { |
|
1217 | - $this->doHideFieldFromForm($v); |
|
1218 | - } |
|
1219 | - } else { |
|
1220 | - $this->doHideFieldFromForm($key); |
|
1221 | - } |
|
1222 | - } |
|
1223 | - |
|
1224 | - /** |
|
1225 | - * @param $key |
|
1226 | - */ |
|
1227 | - public function hideFieldFromSingleView($key) |
|
1228 | - { |
|
1229 | - if (is_array($key)) { |
|
1230 | - foreach ($key as $v) { |
|
1231 | - $this->doHideFieldFromSingleView($v); |
|
1232 | - } |
|
1233 | - } else { |
|
1234 | - $this->doHideFieldFromSingleView($key); |
|
1235 | - } |
|
1236 | - } |
|
1237 | - |
|
1238 | - /** |
|
1239 | - * @param $key |
|
1240 | - */ |
|
1241 | - public function doShowFieldOnForm($key) |
|
1242 | - { |
|
1243 | - if (isset($this->vars[$key])) { |
|
1244 | - $this->vars[$key]['displayOnForm'] = true; |
|
1245 | - } |
|
1246 | - } |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1250 | - * |
|
1251 | - * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1252 | - * @param bool $userSide for futur use, to do something different on the user side |
|
1253 | - * @param array $actions |
|
1254 | - * @param bool $headerAsRow |
|
1255 | - * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1256 | - */ |
|
1257 | - public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true) |
|
1258 | - { |
|
1259 | - include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
1260 | - $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
1261 | - // add all fields mark as displayOnSingleView except the keyid |
|
1262 | - foreach ($this->vars as $key => $var) { |
|
1263 | - if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1264 | - $is_header = ($key == $this->handler->identifierName); |
|
1265 | - $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
1266 | - } |
|
1267 | - } |
|
1268 | - |
|
1269 | - if ($fetchOnly) { |
|
1270 | - $ret = $singleview->render($fetchOnly); |
|
1271 | - |
|
1272 | - return $ret; |
|
1273 | - } else { |
|
1274 | - $singleview->render($fetchOnly); |
|
1275 | - } |
|
1276 | - } |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * @param $key |
|
1280 | - */ |
|
1281 | - public function doDisplayFieldOnSingleView($key) |
|
1282 | - { |
|
1283 | - if (isset($this->vars[$key])) { |
|
1284 | - $this->vars[$key]['displayOnSingleView'] = true; |
|
1285 | - } |
|
1286 | - } |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * @param $field |
|
1290 | - * @param bool $required |
|
1291 | - */ |
|
1292 | - public function doSetFieldAsRequired($field, $required = true) |
|
1293 | - { |
|
1294 | - $this->setVarInfo($field, 'required', $required); |
|
1295 | - } |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * @param $field |
|
1299 | - */ |
|
1300 | - public function doSetFieldForSorting($field) |
|
1301 | - { |
|
1302 | - $this->setVarInfo($field, 'sortby', true); |
|
1303 | - } |
|
1304 | - |
|
1305 | - /** |
|
1306 | - * @param $key |
|
1307 | - */ |
|
1308 | - public function showFieldOnForm($key) |
|
1309 | - { |
|
1310 | - if (is_array($key)) { |
|
1311 | - foreach ($key as $v) { |
|
1312 | - $this->doShowFieldOnForm($v); |
|
1313 | - } |
|
1314 | - } else { |
|
1315 | - $this->doShowFieldOnForm($key); |
|
1316 | - } |
|
1317 | - } |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * @param $key |
|
1321 | - */ |
|
1322 | - public function displayFieldOnSingleView($key) |
|
1323 | - { |
|
1324 | - if (is_array($key)) { |
|
1325 | - foreach ($key as $v) { |
|
1326 | - $this->doDisplayFieldOnSingleView($v); |
|
1327 | - } |
|
1328 | - } else { |
|
1329 | - $this->doDisplayFieldOnSingleView($key); |
|
1330 | - } |
|
1331 | - } |
|
1332 | - |
|
1333 | - /** |
|
1334 | - * @param $key |
|
1335 | - */ |
|
1336 | - public function doSetAdvancedFormFields($key) |
|
1337 | - { |
|
1338 | - if (isset($this->vars[$key])) { |
|
1339 | - $this->vars[$key]['advancedform'] = true; |
|
1340 | - } |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * @param $key |
|
1345 | - */ |
|
1346 | - public function setAdvancedFormFields($key) |
|
1347 | - { |
|
1348 | - if (is_array($key)) { |
|
1349 | - foreach ($key as $v) { |
|
1350 | - $this->doSetAdvancedFormFields($v); |
|
1351 | - } |
|
1352 | - } else { |
|
1353 | - $this->doSetAdvancedFormFields($key); |
|
1354 | - } |
|
1355 | - } |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * @param $key |
|
1359 | - * @return mixed |
|
1360 | - */ |
|
1361 | - public function getUrlLinkObj($key) |
|
1362 | - { |
|
1363 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1364 | - $urllinkid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1365 | - if ($urllinkid != 0) { |
|
1366 | - return $smartobjectLinkurlHandler->get($urllinkid); |
|
1367 | - } else { |
|
1368 | - return $smartobjectLinkurlHandler->create(); |
|
1369 | - } |
|
1370 | - } |
|
1371 | - |
|
1372 | - /** |
|
1373 | - * @param $urlLinkObj |
|
1374 | - * @return mixed |
|
1375 | - */ |
|
1376 | - public function &storeUrlLinkObj($urlLinkObj) |
|
1377 | - { |
|
1378 | - $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1379 | - |
|
1380 | - return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1381 | - } |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * @param $key |
|
1385 | - * @return mixed |
|
1386 | - */ |
|
1387 | - public function getFileObj($key) |
|
1388 | - { |
|
1389 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1390 | - $fileid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1391 | - if ($fileid != 0) { |
|
1392 | - return $smartobjectFileHandler->get($fileid); |
|
1393 | - } else { |
|
1394 | - return $smartobjectFileHandler->create(); |
|
1395 | - } |
|
1396 | - } |
|
1397 | - |
|
1398 | - /** |
|
1399 | - * @param $fileObj |
|
1400 | - * @return mixed |
|
1401 | - */ |
|
1402 | - public function &storeFileObj($fileObj) |
|
1403 | - { |
|
1404 | - $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1405 | - |
|
1406 | - return $smartobjectFileHandler->insert($fileObj); |
|
1407 | - } |
|
58 | + public $_image_path; |
|
59 | + public $_image_url; |
|
60 | + |
|
61 | + public $seoEnabled = false; |
|
62 | + public $titleField; |
|
63 | + public $summaryField = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Reference to the handler managing this object |
|
67 | + * |
|
68 | + * @var object reference to {@link SmartPersistableObjectHandler} |
|
69 | + */ |
|
70 | + public $handler; |
|
71 | + |
|
72 | + /** |
|
73 | + * References to control objects, managing the form fields of this object |
|
74 | + */ |
|
75 | + public $controls = array(); |
|
76 | + |
|
77 | + /** |
|
78 | + * SmartObject constructor. |
|
79 | + * @param $handler |
|
80 | + */ |
|
81 | + public function __construct($handler) |
|
82 | + { |
|
83 | + $this->handler = $handler; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Checks if the user has a specific access on this object |
|
88 | + * |
|
89 | + * @param $perm_name |
|
90 | + * @return bool: TRUE if user has access, false if not |
|
91 | + * @internal param string $gperm_name name of the permission to test |
|
92 | + */ |
|
93 | + public function accessGranted($perm_name) |
|
94 | + { |
|
95 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
96 | + |
|
97 | + return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @param $section_name |
|
102 | + * @param bool $value |
|
103 | + * @param bool $hide |
|
104 | + */ |
|
105 | + public function addFormSection($section_name, $value = false, $hide = false) |
|
106 | + { |
|
107 | + $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
108 | + $this->vars[$section_name]['hide'] = $hide; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @param $section_name |
|
113 | + */ |
|
114 | + public function closeSection($section_name) |
|
115 | + { |
|
116 | + $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * |
|
121 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
122 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
123 | + * @param mixed $value default value of this variable |
|
124 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
125 | + * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
126 | + * @param string $options does this data have any select options? |
|
127 | + * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
128 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
129 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
130 | + * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
131 | + * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
132 | + * @param bool $displayOnForm |
|
133 | + */ |
|
134 | + public function initVar($key, $data_type, $value = null, $required = false, $maxlength = null, $options = '', $multilingual = false, $form_caption = '', $form_dsc = '', $sortby = false, $persistent = true, $displayOnForm = true) |
|
135 | + { |
|
136 | + //url_ is reserved for files. |
|
137 | + if (0 === strpos($key, 'url_')) { |
|
138 | + trigger_error("Cannot use variable starting with 'url_'."); |
|
139 | + } |
|
140 | + parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
141 | + if ($this->handler && (!$form_caption || $form_caption == '')) { |
|
142 | + $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
143 | + if (defined($dyn_form_caption)) { |
|
144 | + $form_caption = constant($dyn_form_caption); |
|
145 | + } |
|
146 | + } |
|
147 | + if ($this->handler && (!$form_dsc || $form_dsc == '')) { |
|
148 | + $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
149 | + if (defined($dyn_form_dsc)) { |
|
150 | + $form_dsc = constant($dyn_form_dsc); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + $this->vars[$key] = array_merge($this->vars[$key], array( |
|
155 | + 'multilingual' => $multilingual, |
|
156 | + 'form_caption' => $form_caption, |
|
157 | + 'form_dsc' => $form_dsc, |
|
158 | + 'sortby' => $sortby, |
|
159 | + 'persistent' => $persistent, |
|
160 | + 'displayOnForm' => $displayOnForm, |
|
161 | + 'displayOnSingleView' => true, |
|
162 | + 'readonly' => false |
|
163 | + )); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param $key |
|
168 | + * @param $data_type |
|
169 | + * @param bool $itemName |
|
170 | + * @param string $form_caption |
|
171 | + * @param bool $sortby |
|
172 | + * @param string $value |
|
173 | + * @param bool $displayOnForm |
|
174 | + * @param bool $required |
|
175 | + */ |
|
176 | + public function initNonPersistableVar($key, $data_type, $itemName = false, $form_caption = '', $sortby = false, $value = '', $displayOnForm = false, $required = false) |
|
177 | + { |
|
178 | + $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
179 | + $this->vars[$key]['itemName'] = $itemName; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Quickly initiate a var |
|
184 | + * |
|
185 | + * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
186 | + * |
|
187 | + * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
188 | + * - all other vars are NULL or '' depending of the parameter |
|
189 | + * |
|
190 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
191 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
192 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
193 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
194 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
195 | + * @param mixed $value default value of this variable |
|
196 | + */ |
|
197 | + public function quickInitVar($key, $data_type, $required = false, $form_caption = '', $form_dsc = '', $value = null) |
|
198 | + { |
|
199 | + $maxlength = $data_type === 'XOBJ_DTYPE_TXTBOX' ? 255 : null; |
|
200 | + $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param $varname |
|
205 | + * @param bool $displayOnForm |
|
206 | + * @param string $default |
|
207 | + */ |
|
208 | + public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
209 | + { |
|
210 | + switch ($varname) { |
|
211 | + case 'dohtml': |
|
212 | + $value = $default !== 'notdefined' ? $default : true; |
|
213 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
214 | + $this->setControl($varname, 'yesno'); |
|
215 | + break; |
|
216 | + |
|
217 | + case 'dobr': |
|
218 | + $value = ($default === 'notdefined') ? true : $default; |
|
219 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
220 | + $this->setControl($varname, 'yesno'); |
|
221 | + break; |
|
222 | + |
|
223 | + case 'doimage': |
|
224 | + $value = $default !== 'notdefined' ? $default : true; |
|
225 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
226 | + $this->setControl($varname, 'yesno'); |
|
227 | + break; |
|
228 | + |
|
229 | + case 'dosmiley': |
|
230 | + $value = $default !== 'notdefined' ? $default : true; |
|
231 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
232 | + $this->setControl($varname, 'yesno'); |
|
233 | + break; |
|
234 | + |
|
235 | + case 'doxcode': |
|
236 | + $value = $default !== 'notdefined' ? $default : true; |
|
237 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
238 | + $this->setControl($varname, 'yesno'); |
|
239 | + break; |
|
240 | + |
|
241 | + case 'meta_keywords': |
|
242 | + $value = $default !== 'notdefined' ? $default : ''; |
|
243 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
244 | + $this->setControl('meta_keywords', array( |
|
245 | + 'name' => 'textarea', |
|
246 | + 'form_editor' => 'textarea' |
|
247 | + )); |
|
248 | + break; |
|
249 | + |
|
250 | + case 'meta_description': |
|
251 | + $value = $default !== 'notdefined' ? $default : ''; |
|
252 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
253 | + $this->setControl('meta_description', array( |
|
254 | + 'name' => 'textarea', |
|
255 | + 'form_editor' => 'textarea' |
|
256 | + )); |
|
257 | + break; |
|
258 | + |
|
259 | + case 'short_url': |
|
260 | + $value = $default !== 'notdefined' ? $default : ''; |
|
261 | + $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
262 | + break; |
|
263 | + |
|
264 | + case 'hierarchy_path': |
|
265 | + $value = $default !== 'notdefined' ? $default : ''; |
|
266 | + $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
267 | + break; |
|
268 | + |
|
269 | + case 'counter': |
|
270 | + $value = $default !== 'notdefined' ? $default : 0; |
|
271 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
272 | + break; |
|
273 | + |
|
274 | + case 'weight': |
|
275 | + $value = $default !== 'notdefined' ? $default : 0; |
|
276 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
277 | + break; |
|
278 | + case 'custom_css': |
|
279 | + $value = $default !== 'notdefined' ? $default : ''; |
|
280 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
281 | + $this->setControl('custom_css', array( |
|
282 | + 'name' => 'textarea', |
|
283 | + 'form_editor' => 'textarea' |
|
284 | + )); |
|
285 | + break; |
|
286 | + } |
|
287 | + $this->hideFieldFromSingleView($varname); |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Set control information for an instance variable |
|
292 | + * |
|
293 | + * The $options parameter can be a string or an array. Using a string |
|
294 | + * is the quickest way: |
|
295 | + * |
|
296 | + * $this->setControl('date', 'date_time'); |
|
297 | + * |
|
298 | + * This will create a date and time selectbox for the 'date' var on the |
|
299 | + * form to edit or create this item. |
|
300 | + * |
|
301 | + * Here are the currently supported controls: |
|
302 | + * |
|
303 | + * - color |
|
304 | + * - country |
|
305 | + * - date_time |
|
306 | + * - date |
|
307 | ||
308 | + * - group |
|
309 | + * - group_multi |
|
310 | + * - image |
|
311 | + * - imageupload |
|
312 | + * - label |
|
313 | + * - language |
|
314 | + * - parentcategory |
|
315 | + * - password |
|
316 | + * - select_multi |
|
317 | + * - select |
|
318 | + * - text |
|
319 | + * - textarea |
|
320 | + * - theme |
|
321 | + * - theme_multi |
|
322 | + * - timezone |
|
323 | + * - user |
|
324 | + * - user_multi |
|
325 | + * - yesno |
|
326 | + * |
|
327 | + * Now, using an array as $options, you can customize what information to |
|
328 | + * use in the control. For example, if one needs to display a select box for |
|
329 | + * the user to choose the status of an item. We only need to tell SmartObject |
|
330 | + * what method to execute within what handler to retreive the options of the |
|
331 | + * selectbox. |
|
332 | + * |
|
333 | + * $this->setControl('status', array('name' => false, |
|
334 | + * 'itemHandler' => 'item', |
|
335 | + * 'method' => 'getStatus', |
|
336 | + * 'module' => 'smartshop')); |
|
337 | + * |
|
338 | + * In this example, the array elements are the following: |
|
339 | + * - name: false, as we don't need to set a special control here. |
|
340 | + * we will use the default control related to the object type (defined in initVar) |
|
341 | + * - itemHandler: name of the object for which we will use the handler |
|
342 | + * - method: name of the method of this handler that we will execute |
|
343 | + * - module: name of the module from wich the handler is |
|
344 | + * |
|
345 | + * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
346 | + * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
347 | + * |
|
348 | + * Another example of the use of $options as an array is for TextArea: |
|
349 | + * |
|
350 | + * $this->setControl('body', array('name' => 'textarea', |
|
351 | + * 'form_editor' => 'default')); |
|
352 | + * |
|
353 | + * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
354 | + * the 'default' editor, providing it is defined in the module |
|
355 | + * preferences: $xoopsModuleConfig['default_editor'] |
|
356 | + * |
|
357 | + * Of course, you can force the use of a specific editor: |
|
358 | + * |
|
359 | + * $this->setControl('body', array('name' => 'textarea', |
|
360 | + * 'form_editor' => 'koivi')); |
|
361 | + * |
|
362 | + * Here is a list of supported editor: |
|
363 | + * - tiny: TinyEditor |
|
364 | + * - dhtmltextarea: XOOPS DHTML Area |
|
365 | + * - fckeditor: FCKEditor |
|
366 | + * - inbetween: InBetween |
|
367 | + * - koivi: Koivi |
|
368 | + * - spaw: Spaw WYSIWYG Editor |
|
369 | + * - htmlarea: HTMLArea |
|
370 | + * - textarea: basic textarea with no options |
|
371 | + * |
|
372 | + * @param string $var name of the variable for which we want to set a control |
|
373 | + * @param array $options |
|
374 | + */ |
|
375 | + public function setControl($var, $options = array()) |
|
376 | + { |
|
377 | + if (isset($this->controls[$var])) { |
|
378 | + unset($this->controls[$var]); |
|
379 | + } |
|
380 | + if (is_string($options)) { |
|
381 | + $options = array('name' => $options); |
|
382 | + } |
|
383 | + $this->controls[$var] = $options; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Get control information for an instance variable |
|
388 | + * |
|
389 | + * @param string $var |
|
390 | + * @return bool|mixed |
|
391 | + */ |
|
392 | + public function getControl($var) |
|
393 | + { |
|
394 | + return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Create the form for this object |
|
399 | + * |
|
400 | + * @param $form_caption |
|
401 | + * @param $form_name |
|
402 | + * @param bool $form_action |
|
403 | + * @param string $submit_button_caption |
|
404 | + * @param bool $cancel_js_action |
|
405 | + * @param bool $captcha |
|
406 | + * @return a <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
407 | + * object for this object |
|
408 | + * @see SmartObjectForm::SmartObjectForm() |
|
409 | + */ |
|
410 | + public function getForm($form_caption, $form_name, $form_action = false, $submit_button_caption = _CO_SOBJECT_SUBMIT, $cancel_js_action = false, $captcha = false) |
|
411 | + { |
|
412 | + include_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
|
413 | + $form = new SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
414 | + |
|
415 | + return $form; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * @return array |
|
420 | + */ |
|
421 | + public function toArray() |
|
422 | + { |
|
423 | + $ret = array(); |
|
424 | + $vars =& $this->getVars(); |
|
425 | + foreach ($vars as $key => $var) { |
|
426 | + $value = $this->getVar($key); |
|
427 | + $ret[$key] = $value; |
|
428 | + } |
|
429 | + if ($this->handler->identifierName != '') { |
|
430 | + $controller = new SmartObjectController($this->handler); |
|
431 | + /** |
|
432 | + * Addition of some automatic value |
|
433 | + */ |
|
434 | + $ret['itemLink'] = $controller->getItemLink($this); |
|
435 | + $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
436 | + $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
437 | + $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
438 | + $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
439 | + } |
|
440 | + |
|
441 | + // Hightlighting searched words |
|
442 | + include_once(SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'); |
|
443 | + $highlight = smart_getConfig('module_search_highlighter', false, true); |
|
444 | + |
|
445 | + if ($highlight && isset($_GET['keywords'])) { |
|
446 | + $myts = MyTextSanitizer::getInstance(); |
|
447 | + $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
448 | + $h = new SmartHighlighter($keywords, true, 'smart_highlighter'); |
|
449 | + foreach ($this->handler->highlightFields as $field) { |
|
450 | + $ret[$field] = $h->highlight($ret[$field]); |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + return $ret; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * add an error |
|
459 | + * |
|
460 | + * @param $err_str |
|
461 | + * @param bool $prefix |
|
462 | + * @internal param string $value error to add |
|
463 | + * @access public |
|
464 | + */ |
|
465 | + public function setErrors($err_str, $prefix = false) |
|
466 | + { |
|
467 | + if (is_array($err_str)) { |
|
468 | + foreach ($err_str as $str) { |
|
469 | + $this->setErrors($str, $prefix); |
|
470 | + } |
|
471 | + } else { |
|
472 | + if ($prefix) { |
|
473 | + $err_str = '[' . $prefix . '] ' . $err_str; |
|
474 | + } |
|
475 | + parent::setErrors($err_str); |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @param $field |
|
481 | + * @param bool $required |
|
482 | + */ |
|
483 | + public function setFieldAsRequired($field, $required = true) |
|
484 | + { |
|
485 | + if (is_array($field)) { |
|
486 | + foreach ($field as $v) { |
|
487 | + $this->doSetFieldAsRequired($v, $required); |
|
488 | + } |
|
489 | + } else { |
|
490 | + $this->doSetFieldAsRequired($field, $required); |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @param $field |
|
496 | + */ |
|
497 | + public function setFieldForSorting($field) |
|
498 | + { |
|
499 | + if (is_array($field)) { |
|
500 | + foreach ($field as $v) { |
|
501 | + $this->doSetFieldForSorting($v); |
|
502 | + } |
|
503 | + } else { |
|
504 | + $this->doSetFieldForSorting($field); |
|
505 | + } |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * @return bool |
|
510 | + */ |
|
511 | + public function hasError() |
|
512 | + { |
|
513 | + return count($this->_errors) > 0; |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * @param $url |
|
518 | + * @param $path |
|
519 | + */ |
|
520 | + public function setImageDir($url, $path) |
|
521 | + { |
|
522 | + $this->_image_url = $url; |
|
523 | + $this->_image_path = $path; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Retreive the group that have been granted access to a specific permission for this object |
|
528 | + * |
|
529 | + * @param $group_perm |
|
530 | + * @return string $group_perm name of the permission |
|
531 | + */ |
|
532 | + public function getGroupPerm($group_perm) |
|
533 | + { |
|
534 | + if (!$this->handler->getPermissions()) { |
|
535 | + $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
536 | + |
|
537 | + return false; |
|
538 | + } |
|
539 | + |
|
540 | + $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
|
541 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
542 | + |
|
543 | + if (count($ret) == 0) { |
|
544 | + return false; |
|
545 | + } else { |
|
546 | + return $ret; |
|
547 | + } |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * @param bool $path |
|
552 | + * @return mixed |
|
553 | + */ |
|
554 | + public function getImageDir($path = false) |
|
555 | + { |
|
556 | + if ($path) { |
|
557 | + return $this->_image_path; |
|
558 | + } else { |
|
559 | + return $this->_image_url; |
|
560 | + } |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * @param bool $path |
|
565 | + * @return mixed |
|
566 | + */ |
|
567 | + public function getUploadDir($path = false) |
|
568 | + { |
|
569 | + if ($path) { |
|
570 | + return $this->_image_path; |
|
571 | + } else { |
|
572 | + return $this->_image_url; |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * @param string $key |
|
578 | + * @param string $info |
|
579 | + * @return array |
|
580 | + */ |
|
581 | + public function getVarInfo($key = '', $info = '') |
|
582 | + { |
|
583 | + if (isset($this->vars[$key][$info])) { |
|
584 | + return $this->vars[$key][$info]; |
|
585 | + } elseif ($info == '' && isset($this->vars[$key])) { |
|
586 | + return $this->vars[$key]; |
|
587 | + } else { |
|
588 | + return $this->vars; |
|
589 | + } |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Get the id of the object |
|
594 | + * |
|
595 | + * @return int id of this object |
|
596 | + */ |
|
597 | + public function id() |
|
598 | + { |
|
599 | + return $this->getVar($this->handler->keyName, 'e'); |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Return the value of the title field of this object |
|
604 | + * |
|
605 | + * @param string $format |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function title($format = 's') |
|
609 | + { |
|
610 | + return $this->getVar($this->handler->identifierName, $format); |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Return the value of the title field of this object |
|
615 | + * |
|
616 | + * @return string |
|
617 | + */ |
|
618 | + public function summary() |
|
619 | + { |
|
620 | + if ($this->handler->summaryName) { |
|
621 | + return $this->getVar($this->handler->summaryName); |
|
622 | + } else { |
|
623 | + return false; |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Retreive the object admin side link, displayijng a SingleView page |
|
629 | + * |
|
630 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
631 | + * @return string user side link to the object |
|
632 | + */ |
|
633 | + public function getAdminViewItemLink($onlyUrl = false) |
|
634 | + { |
|
635 | + $controller = new SmartObjectController($this->handler); |
|
636 | + |
|
637 | + return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * Retreive the object user side link |
|
642 | + * |
|
643 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
644 | + * @return string user side link to the object |
|
645 | + */ |
|
646 | + public function getItemLink($onlyUrl = false) |
|
647 | + { |
|
648 | + $controller = new SmartObjectController($this->handler); |
|
649 | + |
|
650 | + return $controller->getItemLink($this, $onlyUrl); |
|
651 | + } |
|
652 | + |
|
653 | + /** |
|
654 | + * @param bool $onlyUrl |
|
655 | + * @param bool $withimage |
|
656 | + * @param bool $userSide |
|
657 | + * @return string |
|
658 | + */ |
|
659 | + public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
660 | + { |
|
661 | + $controller = new SmartObjectController($this->handler); |
|
662 | + |
|
663 | + return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * @param bool $onlyUrl |
|
668 | + * @param bool $withimage |
|
669 | + * @param bool $userSide |
|
670 | + * @return string |
|
671 | + */ |
|
672 | + public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
673 | + { |
|
674 | + $controller = new SmartObjectController($this->handler); |
|
675 | + |
|
676 | + return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * @return string |
|
681 | + */ |
|
682 | + public function getPrintAndMailLink() |
|
683 | + { |
|
684 | + $controller = new SmartObjectController($this->handler); |
|
685 | + |
|
686 | + return $controller->getPrintAndMailLink($this); |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * @param $sortsel |
|
691 | + * @return array|bool |
|
692 | + */ |
|
693 | + public function getFieldsForSorting($sortsel) |
|
694 | + { |
|
695 | + $ret = array(); |
|
696 | + |
|
697 | + foreach ($this->vars as $key => $field_info) { |
|
698 | + if ($field_info['sortby']) { |
|
699 | + $ret[$key]['caption'] = $field_info['form_caption']; |
|
700 | + $ret[$key]['selected'] = $key == $sortsel ? "selected='selected'" : ''; |
|
701 | + } |
|
702 | + } |
|
703 | + |
|
704 | + if (count($ret) > 0) { |
|
705 | + return $ret; |
|
706 | + } else { |
|
707 | + return false; |
|
708 | + } |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * @param $key |
|
713 | + * @param $newType |
|
714 | + */ |
|
715 | + public function setType($key, $newType) |
|
716 | + { |
|
717 | + $this->vars[$key]['data_type'] = $newType; |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * @param $key |
|
722 | + * @param $info |
|
723 | + * @param $value |
|
724 | + */ |
|
725 | + public function setVarInfo($key, $info, $value) |
|
726 | + { |
|
727 | + $this->vars[$key][$info] = $value; |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * @param $key |
|
732 | + * @param bool $editor |
|
733 | + * @return string |
|
734 | + */ |
|
735 | + public function getValueFor($key, $editor = true) |
|
736 | + { |
|
737 | + global $xoopsModuleConfig; |
|
738 | + |
|
739 | + $ret = $this->getVar($key, 'n'); |
|
740 | + $myts = MyTextSanitizer::getInstance(); |
|
741 | + |
|
742 | + $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
743 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
744 | + |
|
745 | + $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
746 | + $smiley = true; |
|
747 | + $xcode = true; |
|
748 | + $image = true; |
|
749 | + $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
750 | + $formatML = true; |
|
751 | + |
|
752 | + if ($form_editor === 'default') { |
|
753 | + global $xoopsModuleConfig; |
|
754 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
755 | + } |
|
756 | + |
|
757 | + if ($editor) { |
|
758 | + if (defined('XOOPS_EDITOR_IS_HTML') && !in_array($form_editor, array('formtextarea', 'textarea', 'dhtmltextarea'))) { |
|
759 | + $br = false; |
|
760 | + $formatML = !$editor; |
|
761 | + } else { |
|
762 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + if (method_exists($myts, 'formatForML')) { |
|
767 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
768 | + } else { |
|
769 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
770 | + } |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * clean values of all variables of the object for storage. |
|
775 | + * also add slashes whereever needed |
|
776 | + * |
|
777 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
778 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
779 | + * as a string separated by | |
|
780 | + * |
|
781 | + * @return bool true if successful |
|
782 | + * @access public |
|
783 | + */ |
|
784 | + public function cleanVars() |
|
785 | + { |
|
786 | + $ts = MyTextSanitizer::getInstance(); |
|
787 | + $existing_errors = $this->getErrors(); |
|
788 | + $this->_errors = array(); |
|
789 | + foreach ($this->vars as $k => $v) { |
|
790 | + $cleanv = $v['value']; |
|
791 | + if (!$v['changed']) { |
|
792 | + } else { |
|
793 | + $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
794 | + switch ($v['data_type']) { |
|
795 | + case XOBJ_DTYPE_TXTBOX: |
|
796 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
797 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
798 | + continue; |
|
799 | + } |
|
800 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
801 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
802 | + continue; |
|
803 | + } |
|
804 | + if (!$v['not_gpc']) { |
|
805 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
806 | + } else { |
|
807 | + $cleanv = $ts->censorString($cleanv); |
|
808 | + } |
|
809 | + break; |
|
810 | + case XOBJ_DTYPE_TXTAREA: |
|
811 | + if ($v['required'] && $cleanv != '0' && $cleanv == '') { |
|
812 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
813 | + continue; |
|
814 | + } |
|
815 | + if (!$v['not_gpc']) { |
|
816 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
817 | + } else { |
|
818 | + $cleanv = $ts->censorString($cleanv); |
|
819 | + } |
|
820 | + break; |
|
821 | + case XOBJ_DTYPE_SOURCE: |
|
822 | + if (!$v['not_gpc']) { |
|
823 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
824 | + } else { |
|
825 | + $cleanv = $cleanv; |
|
826 | + } |
|
827 | + break; |
|
828 | + case XOBJ_DTYPE_INT: |
|
829 | + case XOBJ_DTYPE_TIME_ONLY: |
|
830 | + $cleanv = (int)$cleanv; |
|
831 | + break; |
|
832 | + |
|
833 | + case XOBJ_DTYPE_CURRENCY: |
|
834 | + $cleanv = smart_currency($cleanv); |
|
835 | + break; |
|
836 | + |
|
837 | + case XOBJ_DTYPE_FLOAT: |
|
838 | + $cleanv = smart_float($cleanv); |
|
839 | + break; |
|
840 | + |
|
841 | + case XOBJ_DTYPE_EMAIL: |
|
842 | + if ($v['required'] && $cleanv == '') { |
|
843 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
844 | + continue; |
|
845 | + } |
|
846 | + if ($cleanv != '' && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
847 | + $this->setErrors('Invalid Email'); |
|
848 | + continue; |
|
849 | + } |
|
850 | + if (!$v['not_gpc']) { |
|
851 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
852 | + } |
|
853 | + break; |
|
854 | + case XOBJ_DTYPE_URL: |
|
855 | + if ($v['required'] && $cleanv == '') { |
|
856 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
857 | + continue; |
|
858 | + } |
|
859 | + if ($cleanv != '' && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
860 | + $cleanv = 'http://' . $cleanv; |
|
861 | + } |
|
862 | + if (!$v['not_gpc']) { |
|
863 | + $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
864 | + } |
|
865 | + break; |
|
866 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
867 | + $cleanv = implode('|', $cleanv); |
|
868 | + break; |
|
869 | + case XOBJ_DTYPE_ARRAY: |
|
870 | + $cleanv = serialize($cleanv); |
|
871 | + break; |
|
872 | + case XOBJ_DTYPE_STIME: |
|
873 | + case XOBJ_DTYPE_MTIME: |
|
874 | + case XOBJ_DTYPE_LTIME: |
|
875 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
876 | + if (!($cleanv > 0)) { |
|
877 | + $cleanv = strtotime($cleanv); |
|
878 | + } |
|
879 | + break; |
|
880 | + default: |
|
881 | + break; |
|
882 | + } |
|
883 | + } |
|
884 | + $this->cleanVars[$k] =& $cleanv; |
|
885 | + unset($cleanv); |
|
886 | + } |
|
887 | + if (count($this->_errors) > 0) { |
|
888 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
889 | + |
|
890 | + return false; |
|
891 | + } |
|
892 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
893 | + $this->unsetDirty(); |
|
894 | + |
|
895 | + return true; |
|
896 | + } |
|
897 | + |
|
898 | + /** |
|
899 | + * returns a specific variable for the object in a proper format |
|
900 | + * |
|
901 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
902 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
903 | + * as a string separated by | |
|
904 | + * |
|
905 | + * @access public |
|
906 | + * @param string $key key of the object's variable to be returned |
|
907 | + * @param string $format format to use for the output |
|
908 | + * @return mixed formatted value of the variable |
|
909 | + */ |
|
910 | + public function getVar($key, $format = 's') |
|
911 | + { |
|
912 | + global $myts; |
|
913 | + |
|
914 | + $ret = $this->vars[$key]['value']; |
|
915 | + |
|
916 | + switch ($this->vars[$key]['data_type']) { |
|
917 | + |
|
918 | + case XOBJ_DTYPE_TXTBOX: |
|
919 | + switch (strtolower($format)) { |
|
920 | + case 's': |
|
921 | + case 'show': |
|
922 | + // ML Hack by marcan |
|
923 | + $ts = MyTextSanitizer::getInstance(); |
|
924 | + $ret = $ts->htmlSpecialChars($ret); |
|
925 | + |
|
926 | + if (method_exists($myts, 'formatForML')) { |
|
927 | + return $ts->formatForML($ret); |
|
928 | + } else { |
|
929 | + return $ret; |
|
930 | + } |
|
931 | + break 1; |
|
932 | + // End of ML Hack by marcan |
|
933 | + |
|
934 | + case 'clean': |
|
935 | + $ts = MyTextSanitizer::getInstance(); |
|
936 | + |
|
937 | + $ret = smart_html2text($ret); |
|
938 | + $ret = smart_purifyText($ret); |
|
939 | + |
|
940 | + if (method_exists($myts, 'formatForML')) { |
|
941 | + return $ts->formatForML($ret); |
|
942 | + } else { |
|
943 | + return $ret; |
|
944 | + } |
|
945 | + break 1; |
|
946 | + // End of ML Hack by marcan |
|
947 | + |
|
948 | + case 'e': |
|
949 | + case 'edit': |
|
950 | + $ts = MyTextSanitizer::getInstance(); |
|
951 | + |
|
952 | + return $ts->htmlSpecialChars($ret); |
|
953 | + break 1; |
|
954 | + case 'p': |
|
955 | + case 'preview': |
|
956 | + case 'f': |
|
957 | + case 'formpreview': |
|
958 | + $ts = MyTextSanitizer::getInstance(); |
|
959 | + |
|
960 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
961 | + break 1; |
|
962 | + case 'n': |
|
963 | + case 'none': |
|
964 | + default: |
|
965 | + break 1; |
|
966 | + } |
|
967 | + break; |
|
968 | + case XOBJ_DTYPE_LTIME: |
|
969 | + switch (strtolower($format)) { |
|
970 | + case 's': |
|
971 | + case 'show': |
|
972 | + case 'p': |
|
973 | + case 'preview': |
|
974 | + case 'f': |
|
975 | + case 'formpreview': |
|
976 | + $ret = formatTimestamp($ret, _DATESTRING); |
|
977 | + |
|
978 | + return $ret; |
|
979 | + break 1; |
|
980 | + case 'n': |
|
981 | + case 'none': |
|
982 | + case 'e': |
|
983 | + case 'edit': |
|
984 | + break 1; |
|
985 | + default: |
|
986 | + break 1; |
|
987 | + } |
|
988 | + break; |
|
989 | + case XOBJ_DTYPE_STIME: |
|
990 | + switch (strtolower($format)) { |
|
991 | + case 's': |
|
992 | + case 'show': |
|
993 | + case 'p': |
|
994 | + case 'preview': |
|
995 | + case 'f': |
|
996 | + case 'formpreview': |
|
997 | + $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
998 | + |
|
999 | + return $ret; |
|
1000 | + break 1; |
|
1001 | + case 'n': |
|
1002 | + case 'none': |
|
1003 | + case 'e': |
|
1004 | + case 'edit': |
|
1005 | + break 1; |
|
1006 | + default: |
|
1007 | + break 1; |
|
1008 | + } |
|
1009 | + break; |
|
1010 | + case XOBJ_DTYPE_TIME_ONLY: |
|
1011 | + switch (strtolower($format)) { |
|
1012 | + case 's': |
|
1013 | + case 'show': |
|
1014 | + case 'p': |
|
1015 | + case 'preview': |
|
1016 | + case 'f': |
|
1017 | + case 'formpreview': |
|
1018 | + $ret = formatTimestamp($ret, 'G:i'); |
|
1019 | + |
|
1020 | + return $ret; |
|
1021 | + break 1; |
|
1022 | + case 'n': |
|
1023 | + case 'none': |
|
1024 | + case 'e': |
|
1025 | + case 'edit': |
|
1026 | + break 1; |
|
1027 | + default: |
|
1028 | + break 1; |
|
1029 | + } |
|
1030 | + break; |
|
1031 | + |
|
1032 | + case XOBJ_DTYPE_CURRENCY: |
|
1033 | + $decimal_section_original = strstr($ret, '.'); |
|
1034 | + $decimal_section = $decimal_section_original; |
|
1035 | + if ($decimal_section) { |
|
1036 | + if (strlen($decimal_section) == 1) { |
|
1037 | + $decimal_section = '.00'; |
|
1038 | + } elseif (strlen($decimal_section) == 2) { |
|
1039 | + $decimal_section = $decimal_section . '0'; |
|
1040 | + } |
|
1041 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1042 | + } else { |
|
1043 | + $ret = $ret . '.00'; |
|
1044 | + } |
|
1045 | + break; |
|
1046 | + |
|
1047 | + case XOBJ_DTYPE_TXTAREA: |
|
1048 | + switch (strtolower($format)) { |
|
1049 | + case 's': |
|
1050 | + case 'show': |
|
1051 | + $ts = MyTextSanitizer::getInstance(); |
|
1052 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1053 | + |
|
1054 | + $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1055 | + |
|
1056 | + $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1057 | + $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1058 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Hack by marcan <INBOX> for SCSPRO |
|
1062 | + * Setting mastop as the main editor |
|
1063 | + */ |
|
1064 | + if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1065 | + $br = false; |
|
1066 | + } |
|
1067 | + /** |
|
1068 | + * Hack by marcan <INBOX> for SCSPRO |
|
1069 | + * Setting mastop as the main editor |
|
1070 | + */ |
|
1071 | + |
|
1072 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1073 | + break 1; |
|
1074 | + case 'e': |
|
1075 | + case 'edit': |
|
1076 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1077 | + break 1; |
|
1078 | + case 'p': |
|
1079 | + case 'preview': |
|
1080 | + $ts = MyTextSanitizer::getInstance(); |
|
1081 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1082 | + $xcode = (!isset($this->vars['doxcode']['value']) || $this->vars['doxcode']['value'] == 1) ? 1 : 0; |
|
1083 | + $smiley = (!isset($this->vars['dosmiley']['value']) || $this->vars['dosmiley']['value'] == 1) ? 1 : 0; |
|
1084 | + $image = (!isset($this->vars['doimage']['value']) || $this->vars['doimage']['value'] == 1) ? 1 : 0; |
|
1085 | + $br = (!isset($this->vars['dobr']['value']) || $this->vars['dobr']['value'] == 1) ? 1 : 0; |
|
1086 | + |
|
1087 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1088 | + break 1; |
|
1089 | + case 'f': |
|
1090 | + case 'formpreview': |
|
1091 | + $ts = MyTextSanitizer::getInstance(); |
|
1092 | + |
|
1093 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1094 | + break 1; |
|
1095 | + case 'n': |
|
1096 | + case 'none': |
|
1097 | + default: |
|
1098 | + break 1; |
|
1099 | + } |
|
1100 | + break; |
|
1101 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1102 | + $ret =& explode('|', $ret); |
|
1103 | + break; |
|
1104 | + case XOBJ_DTYPE_ARRAY: |
|
1105 | + $ret =& unserialize($ret); |
|
1106 | + break; |
|
1107 | + case XOBJ_DTYPE_SOURCE: |
|
1108 | + switch (strtolower($format)) { |
|
1109 | + case 's': |
|
1110 | + case 'show': |
|
1111 | + break 1; |
|
1112 | + case 'e': |
|
1113 | + case 'edit': |
|
1114 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1115 | + break 1; |
|
1116 | + case 'p': |
|
1117 | + case 'preview': |
|
1118 | + $ts = MyTextSanitizer::getInstance(); |
|
1119 | + |
|
1120 | + return $ts->stripSlashesGPC($ret); |
|
1121 | + break 1; |
|
1122 | + case 'f': |
|
1123 | + case 'formpreview': |
|
1124 | + $ts = MyTextSanitizer::getInstance(); |
|
1125 | + |
|
1126 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1127 | + break 1; |
|
1128 | + case 'n': |
|
1129 | + case 'none': |
|
1130 | + default: |
|
1131 | + break 1; |
|
1132 | + } |
|
1133 | + break; |
|
1134 | + default: |
|
1135 | + if ($this->vars[$key]['options'] != '' && $ret != '') { |
|
1136 | + switch (strtolower($format)) { |
|
1137 | + case 's': |
|
1138 | + case 'show': |
|
1139 | + $selected = explode('|', $ret); |
|
1140 | + $options = explode('|', $this->vars[$key]['options']); |
|
1141 | + $i = 1; |
|
1142 | + $ret = array(); |
|
1143 | + foreach ($options as $op) { |
|
1144 | + if (in_array($i, $selected)) { |
|
1145 | + $ret[] = $op; |
|
1146 | + } |
|
1147 | + ++$i; |
|
1148 | + } |
|
1149 | + |
|
1150 | + return implode(', ', $ret); |
|
1151 | + case 'e': |
|
1152 | + case 'edit': |
|
1153 | + $ret = explode('|', $ret); |
|
1154 | + break 1; |
|
1155 | + default: |
|
1156 | + break 1; |
|
1157 | + } |
|
1158 | + } |
|
1159 | + break; |
|
1160 | + } |
|
1161 | + |
|
1162 | + return $ret; |
|
1163 | + } |
|
1164 | + |
|
1165 | + /** |
|
1166 | + * @param $key |
|
1167 | + */ |
|
1168 | + public function doMakeFieldreadOnly($key) |
|
1169 | + { |
|
1170 | + if (isset($this->vars[$key])) { |
|
1171 | + $this->vars[$key]['readonly'] = true; |
|
1172 | + $this->vars[$key]['displayOnForm'] = true; |
|
1173 | + } |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * @param $key |
|
1178 | + */ |
|
1179 | + public function makeFieldReadOnly($key) |
|
1180 | + { |
|
1181 | + if (is_array($key)) { |
|
1182 | + foreach ($key as $v) { |
|
1183 | + $this->doMakeFieldreadOnly($v); |
|
1184 | + } |
|
1185 | + } else { |
|
1186 | + $this->doMakeFieldreadOnly($key); |
|
1187 | + } |
|
1188 | + } |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * @param $key |
|
1192 | + */ |
|
1193 | + public function doHideFieldFromForm($key) |
|
1194 | + { |
|
1195 | + if (isset($this->vars[$key])) { |
|
1196 | + $this->vars[$key]['displayOnForm'] = false; |
|
1197 | + } |
|
1198 | + } |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * @param $key |
|
1202 | + */ |
|
1203 | + public function doHideFieldFromSingleView($key) |
|
1204 | + { |
|
1205 | + if (isset($this->vars[$key])) { |
|
1206 | + $this->vars[$key]['displayOnSingleView'] = false; |
|
1207 | + } |
|
1208 | + } |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * @param $key |
|
1212 | + */ |
|
1213 | + public function hideFieldFromForm($key) |
|
1214 | + { |
|
1215 | + if (is_array($key)) { |
|
1216 | + foreach ($key as $v) { |
|
1217 | + $this->doHideFieldFromForm($v); |
|
1218 | + } |
|
1219 | + } else { |
|
1220 | + $this->doHideFieldFromForm($key); |
|
1221 | + } |
|
1222 | + } |
|
1223 | + |
|
1224 | + /** |
|
1225 | + * @param $key |
|
1226 | + */ |
|
1227 | + public function hideFieldFromSingleView($key) |
|
1228 | + { |
|
1229 | + if (is_array($key)) { |
|
1230 | + foreach ($key as $v) { |
|
1231 | + $this->doHideFieldFromSingleView($v); |
|
1232 | + } |
|
1233 | + } else { |
|
1234 | + $this->doHideFieldFromSingleView($key); |
|
1235 | + } |
|
1236 | + } |
|
1237 | + |
|
1238 | + /** |
|
1239 | + * @param $key |
|
1240 | + */ |
|
1241 | + public function doShowFieldOnForm($key) |
|
1242 | + { |
|
1243 | + if (isset($this->vars[$key])) { |
|
1244 | + $this->vars[$key]['displayOnForm'] = true; |
|
1245 | + } |
|
1246 | + } |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1250 | + * |
|
1251 | + * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1252 | + * @param bool $userSide for futur use, to do something different on the user side |
|
1253 | + * @param array $actions |
|
1254 | + * @param bool $headerAsRow |
|
1255 | + * @return content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1256 | + */ |
|
1257 | + public function displaySingleObject($fetchOnly = false, $userSide = false, $actions = array(), $headerAsRow = true) |
|
1258 | + { |
|
1259 | + include_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
|
1260 | + $singleview = new SmartObjectSingleView($this, $userSide, $actions, $headerAsRow); |
|
1261 | + // add all fields mark as displayOnSingleView except the keyid |
|
1262 | + foreach ($this->vars as $key => $var) { |
|
1263 | + if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1264 | + $is_header = ($key == $this->handler->identifierName); |
|
1265 | + $singleview->addRow(new SmartObjectRow($key, false, $is_header)); |
|
1266 | + } |
|
1267 | + } |
|
1268 | + |
|
1269 | + if ($fetchOnly) { |
|
1270 | + $ret = $singleview->render($fetchOnly); |
|
1271 | + |
|
1272 | + return $ret; |
|
1273 | + } else { |
|
1274 | + $singleview->render($fetchOnly); |
|
1275 | + } |
|
1276 | + } |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * @param $key |
|
1280 | + */ |
|
1281 | + public function doDisplayFieldOnSingleView($key) |
|
1282 | + { |
|
1283 | + if (isset($this->vars[$key])) { |
|
1284 | + $this->vars[$key]['displayOnSingleView'] = true; |
|
1285 | + } |
|
1286 | + } |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * @param $field |
|
1290 | + * @param bool $required |
|
1291 | + */ |
|
1292 | + public function doSetFieldAsRequired($field, $required = true) |
|
1293 | + { |
|
1294 | + $this->setVarInfo($field, 'required', $required); |
|
1295 | + } |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * @param $field |
|
1299 | + */ |
|
1300 | + public function doSetFieldForSorting($field) |
|
1301 | + { |
|
1302 | + $this->setVarInfo($field, 'sortby', true); |
|
1303 | + } |
|
1304 | + |
|
1305 | + /** |
|
1306 | + * @param $key |
|
1307 | + */ |
|
1308 | + public function showFieldOnForm($key) |
|
1309 | + { |
|
1310 | + if (is_array($key)) { |
|
1311 | + foreach ($key as $v) { |
|
1312 | + $this->doShowFieldOnForm($v); |
|
1313 | + } |
|
1314 | + } else { |
|
1315 | + $this->doShowFieldOnForm($key); |
|
1316 | + } |
|
1317 | + } |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * @param $key |
|
1321 | + */ |
|
1322 | + public function displayFieldOnSingleView($key) |
|
1323 | + { |
|
1324 | + if (is_array($key)) { |
|
1325 | + foreach ($key as $v) { |
|
1326 | + $this->doDisplayFieldOnSingleView($v); |
|
1327 | + } |
|
1328 | + } else { |
|
1329 | + $this->doDisplayFieldOnSingleView($key); |
|
1330 | + } |
|
1331 | + } |
|
1332 | + |
|
1333 | + /** |
|
1334 | + * @param $key |
|
1335 | + */ |
|
1336 | + public function doSetAdvancedFormFields($key) |
|
1337 | + { |
|
1338 | + if (isset($this->vars[$key])) { |
|
1339 | + $this->vars[$key]['advancedform'] = true; |
|
1340 | + } |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * @param $key |
|
1345 | + */ |
|
1346 | + public function setAdvancedFormFields($key) |
|
1347 | + { |
|
1348 | + if (is_array($key)) { |
|
1349 | + foreach ($key as $v) { |
|
1350 | + $this->doSetAdvancedFormFields($v); |
|
1351 | + } |
|
1352 | + } else { |
|
1353 | + $this->doSetAdvancedFormFields($key); |
|
1354 | + } |
|
1355 | + } |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * @param $key |
|
1359 | + * @return mixed |
|
1360 | + */ |
|
1361 | + public function getUrlLinkObj($key) |
|
1362 | + { |
|
1363 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1364 | + $urllinkid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1365 | + if ($urllinkid != 0) { |
|
1366 | + return $smartobjectLinkurlHandler->get($urllinkid); |
|
1367 | + } else { |
|
1368 | + return $smartobjectLinkurlHandler->create(); |
|
1369 | + } |
|
1370 | + } |
|
1371 | + |
|
1372 | + /** |
|
1373 | + * @param $urlLinkObj |
|
1374 | + * @return mixed |
|
1375 | + */ |
|
1376 | + public function &storeUrlLinkObj($urlLinkObj) |
|
1377 | + { |
|
1378 | + $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
|
1379 | + |
|
1380 | + return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1381 | + } |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * @param $key |
|
1385 | + * @return mixed |
|
1386 | + */ |
|
1387 | + public function getFileObj($key) |
|
1388 | + { |
|
1389 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1390 | + $fileid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1391 | + if ($fileid != 0) { |
|
1392 | + return $smartobjectFileHandler->get($fileid); |
|
1393 | + } else { |
|
1394 | + return $smartobjectFileHandler->create(); |
|
1395 | + } |
|
1396 | + } |
|
1397 | + |
|
1398 | + /** |
|
1399 | + * @param $fileObj |
|
1400 | + * @return mixed |
|
1401 | + */ |
|
1402 | + public function &storeFileObj($fileObj) |
|
1403 | + { |
|
1404 | + $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
|
1405 | + |
|
1406 | + return $smartobjectFileHandler->insert($fileObj); |
|
1407 | + } |
|
1408 | 1408 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | public function toArray() |
422 | 422 | { |
423 | 423 | $ret = array(); |
424 | - $vars =& $this->getVars(); |
|
424 | + $vars = & $this->getVars(); |
|
425 | 425 | foreach ($vars as $key => $var) { |
426 | 426 | $value = $this->getVar($key); |
427 | 427 | $ret[$key] = $value; |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | } |
539 | 539 | |
540 | 540 | $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler); |
541 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
541 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
542 | 542 | |
543 | 543 | if (count($ret) == 0) { |
544 | 544 | return false; |
@@ -797,8 +797,8 @@ discard block |
||
797 | 797 | $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
798 | 798 | continue; |
799 | 799 | } |
800 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
801 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
800 | + if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) { |
|
801 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength'])); |
|
802 | 802 | continue; |
803 | 803 | } |
804 | 804 | if (!$v['not_gpc']) { |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | break; |
828 | 828 | case XOBJ_DTYPE_INT: |
829 | 829 | case XOBJ_DTYPE_TIME_ONLY: |
830 | - $cleanv = (int)$cleanv; |
|
830 | + $cleanv = (int) $cleanv; |
|
831 | 831 | break; |
832 | 832 | |
833 | 833 | case XOBJ_DTYPE_CURRENCY: |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | $cleanv = 'http://' . $cleanv; |
861 | 861 | } |
862 | 862 | if (!$v['not_gpc']) { |
863 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
863 | + $cleanv = & $ts->stripSlashesGPC($cleanv); |
|
864 | 864 | } |
865 | 865 | break; |
866 | 866 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | case XOBJ_DTYPE_STIME: |
873 | 873 | case XOBJ_DTYPE_MTIME: |
874 | 874 | case XOBJ_DTYPE_LTIME: |
875 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
875 | + $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv); |
|
876 | 876 | if (!($cleanv > 0)) { |
877 | 877 | $cleanv = strtotime($cleanv); |
878 | 878 | } |
@@ -881,7 +881,7 @@ discard block |
||
881 | 881 | break; |
882 | 882 | } |
883 | 883 | } |
884 | - $this->cleanVars[$k] =& $cleanv; |
|
884 | + $this->cleanVars[$k] = & $cleanv; |
|
885 | 885 | unset($cleanv); |
886 | 886 | } |
887 | 887 | if (count($this->_errors) > 0) { |
@@ -1099,10 +1099,10 @@ discard block |
||
1099 | 1099 | } |
1100 | 1100 | break; |
1101 | 1101 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
1102 | - $ret =& explode('|', $ret); |
|
1102 | + $ret = & explode('|', $ret); |
|
1103 | 1103 | break; |
1104 | 1104 | case XOBJ_DTYPE_ARRAY: |
1105 | - $ret =& unserialize($ret); |
|
1105 | + $ret = & unserialize($ret); |
|
1106 | 1106 | break; |
1107 | 1107 | case XOBJ_DTYPE_SOURCE: |
1108 | 1108 | switch (strtolower($format)) { |
@@ -1361,7 +1361,7 @@ discard block |
||
1361 | 1361 | public function getUrlLinkObj($key) |
1362 | 1362 | { |
1363 | 1363 | $smartobjectLinkurlHandler = xoops_getModuleHandler('urllink', 'smartobject'); |
1364 | - $urllinkid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1364 | + $urllinkid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1365 | 1365 | if ($urllinkid != 0) { |
1366 | 1366 | return $smartobjectLinkurlHandler->get($urllinkid); |
1367 | 1367 | } else { |
@@ -1387,7 +1387,7 @@ discard block |
||
1387 | 1387 | public function getFileObj($key) |
1388 | 1388 | { |
1389 | 1389 | $smartobjectFileHandler = xoops_getModuleHandler('file', 'smartobject'); |
1390 | - $fileid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1390 | + $fileid = $this->getVar($key) != null ? $this->getVar($key) : 0; |
|
1391 | 1391 | if ($fileid != 0) { |
1392 | 1392 | return $smartobjectFileHandler->get($fileid); |
1393 | 1393 | } else { |