@@ -13,253 +13,253 @@ |
||
13 | 13 | */ |
14 | 14 | class XoopsCaptcha |
15 | 15 | { |
16 | - public $active = true; |
|
17 | - public $mode = 'text'; // potential values: image, text |
|
18 | - public $config = []; |
|
19 | - |
|
20 | - public $message = []; // Logging error messages |
|
21 | - |
|
22 | - /** |
|
23 | - * XoopsCaptcha constructor. |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - // Loading default preferences |
|
28 | - $this->config = @include __DIR__ . '/config.php'; |
|
29 | - |
|
30 | - $this->setMode($this->config['mode']); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return XoopsCaptcha |
|
35 | - */ |
|
36 | - public static function getInstance() |
|
37 | - { |
|
38 | - static $instance; |
|
39 | - if (null === $instance) { |
|
40 | - $instance = new static(); |
|
41 | - } |
|
42 | - |
|
43 | - return $instance; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * @param $name |
|
48 | - * @param $val |
|
49 | - * @return bool |
|
50 | - */ |
|
51 | - public function setConfig($name, $val) |
|
52 | - { |
|
53 | - if ($name === 'mode') { |
|
54 | - $this->setMode($val); |
|
55 | - } elseif (isset($this->$name)) { |
|
56 | - $this->$name = $val; |
|
57 | - } else { |
|
58 | - $this->config[$name] = $val; |
|
59 | - } |
|
60 | - |
|
61 | - return true; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Set CAPTCHA mode |
|
66 | - * |
|
67 | - * For future possible modes, right now force to use text or image |
|
68 | - * |
|
69 | - * @param string $mode if no mode is set, just verify current mode |
|
70 | - */ |
|
71 | - public function setMode($mode = null) |
|
72 | - { |
|
73 | - if (!empty($mode) && in_array($mode, ['text', 'image'])) { |
|
74 | - $this->mode = $mode; |
|
75 | - |
|
76 | - if ($this->mode !== 'image') { |
|
77 | - return; |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - // Disable image mode |
|
82 | - if (!extension_loaded('gd')) { |
|
83 | - $this->mode = 'text'; |
|
84 | - } else { |
|
85 | - $required_functions = [ |
|
86 | - 'imagecreatetruecolor', |
|
87 | - 'imagecolorallocate', |
|
88 | - 'imagefilledrectangle', |
|
89 | - 'imagejpeg', |
|
90 | - 'imagedestroy', |
|
91 | - 'imageftbbox' |
|
92 | - ]; |
|
93 | - foreach ($required_functions as $func) { |
|
94 | - if (!function_exists($func)) { |
|
95 | - $this->mode = 'text'; |
|
96 | - break; |
|
97 | - } |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Initializing the CAPTCHA class |
|
104 | - * @param string $name |
|
105 | - * @param null $skipmember |
|
106 | - * @param null $num_chars |
|
107 | - * @param null $fontsize_min |
|
108 | - * @param null $fontsize_max |
|
109 | - * @param null $background_type |
|
110 | - * @param null $background_num |
|
111 | - */ |
|
112 | - public function init( |
|
113 | - $name = 'xoopscaptcha', |
|
114 | - $skipmember = null, |
|
115 | - $num_chars = null, |
|
116 | - $fontsize_min = null, |
|
117 | - $fontsize_max = null, |
|
118 | - $background_type = null, |
|
119 | - $background_num = null |
|
120 | - ) { |
|
121 | - // Loading RUN-TIME settings |
|
122 | - foreach (array_keys($this->config) as $key) { |
|
123 | - if (isset(${$key}) && ${$key} !== null) { |
|
124 | - $this->config[$key] = ${$key}; |
|
125 | - } |
|
126 | - } |
|
127 | - $this->config['name'] = $name; |
|
128 | - |
|
129 | - // Skip CAPTCHA for member if set |
|
130 | - if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
131 | - $this->active = false; |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Verify user submission |
|
137 | - * @param null $skipMember |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function verify($skipMember = null) |
|
141 | - { |
|
142 | - $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
143 | - $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
144 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
145 | - |
|
146 | - $is_valid = false; |
|
147 | - |
|
148 | - // Skip CAPTCHA for member if set |
|
149 | - if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
150 | - $is_valid = true; |
|
151 | - // Kill too many attempts |
|
152 | - } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
153 | - $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
154 | - |
|
155 | - // Verify the code |
|
156 | - } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
157 | - $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
158 | - $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
159 | - } |
|
160 | - |
|
161 | - if (!empty($maxAttempts)) { |
|
162 | - if (!$is_valid) { |
|
163 | - // Increase the attempt records on failure |
|
164 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
165 | - // Log the error message |
|
166 | - $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
167 | - } else { |
|
168 | - |
|
169 | - // reset attempt records on success |
|
170 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
171 | - } |
|
172 | - } |
|
173 | - $this->destroyGarbage(true); |
|
174 | - |
|
175 | - return $is_valid; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @return mixed|string |
|
180 | - */ |
|
181 | - public function getCaption() |
|
182 | - { |
|
183 | - return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function getMessage() |
|
190 | - { |
|
191 | - return implode('<br>', $this->message); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Destory historical stuff |
|
196 | - * @param bool $clearSession |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function destroyGarbage($clearSession = false) |
|
200 | - { |
|
201 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
202 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
203 | - $captchaHandler = new $class(); |
|
204 | - if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
205 | - $captchaHandler->loadConfig($this->config); |
|
206 | - $captchaHandler->destroyGarbage(); |
|
207 | - } |
|
208 | - |
|
209 | - if ($clearSession) { |
|
210 | - $_SESSION['XoopsCaptcha_name'] = null; |
|
211 | - $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
212 | - $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
213 | - $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
214 | - } |
|
215 | - |
|
216 | - return true; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return mixed|string |
|
221 | - */ |
|
222 | - public function render() |
|
223 | - { |
|
224 | - $form = ''; |
|
225 | - |
|
226 | - if (!$this->active || empty($this->config['name'])) { |
|
227 | - return $form; |
|
228 | - } |
|
229 | - |
|
230 | - $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
231 | - $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
232 | - $maxAttempts = $this->config['maxattempt']; |
|
233 | - $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
234 | - /* |
|
16 | + public $active = true; |
|
17 | + public $mode = 'text'; // potential values: image, text |
|
18 | + public $config = []; |
|
19 | + |
|
20 | + public $message = []; // Logging error messages |
|
21 | + |
|
22 | + /** |
|
23 | + * XoopsCaptcha constructor. |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + // Loading default preferences |
|
28 | + $this->config = @include __DIR__ . '/config.php'; |
|
29 | + |
|
30 | + $this->setMode($this->config['mode']); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return XoopsCaptcha |
|
35 | + */ |
|
36 | + public static function getInstance() |
|
37 | + { |
|
38 | + static $instance; |
|
39 | + if (null === $instance) { |
|
40 | + $instance = new static(); |
|
41 | + } |
|
42 | + |
|
43 | + return $instance; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * @param $name |
|
48 | + * @param $val |
|
49 | + * @return bool |
|
50 | + */ |
|
51 | + public function setConfig($name, $val) |
|
52 | + { |
|
53 | + if ($name === 'mode') { |
|
54 | + $this->setMode($val); |
|
55 | + } elseif (isset($this->$name)) { |
|
56 | + $this->$name = $val; |
|
57 | + } else { |
|
58 | + $this->config[$name] = $val; |
|
59 | + } |
|
60 | + |
|
61 | + return true; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Set CAPTCHA mode |
|
66 | + * |
|
67 | + * For future possible modes, right now force to use text or image |
|
68 | + * |
|
69 | + * @param string $mode if no mode is set, just verify current mode |
|
70 | + */ |
|
71 | + public function setMode($mode = null) |
|
72 | + { |
|
73 | + if (!empty($mode) && in_array($mode, ['text', 'image'])) { |
|
74 | + $this->mode = $mode; |
|
75 | + |
|
76 | + if ($this->mode !== 'image') { |
|
77 | + return; |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + // Disable image mode |
|
82 | + if (!extension_loaded('gd')) { |
|
83 | + $this->mode = 'text'; |
|
84 | + } else { |
|
85 | + $required_functions = [ |
|
86 | + 'imagecreatetruecolor', |
|
87 | + 'imagecolorallocate', |
|
88 | + 'imagefilledrectangle', |
|
89 | + 'imagejpeg', |
|
90 | + 'imagedestroy', |
|
91 | + 'imageftbbox' |
|
92 | + ]; |
|
93 | + foreach ($required_functions as $func) { |
|
94 | + if (!function_exists($func)) { |
|
95 | + $this->mode = 'text'; |
|
96 | + break; |
|
97 | + } |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Initializing the CAPTCHA class |
|
104 | + * @param string $name |
|
105 | + * @param null $skipmember |
|
106 | + * @param null $num_chars |
|
107 | + * @param null $fontsize_min |
|
108 | + * @param null $fontsize_max |
|
109 | + * @param null $background_type |
|
110 | + * @param null $background_num |
|
111 | + */ |
|
112 | + public function init( |
|
113 | + $name = 'xoopscaptcha', |
|
114 | + $skipmember = null, |
|
115 | + $num_chars = null, |
|
116 | + $fontsize_min = null, |
|
117 | + $fontsize_max = null, |
|
118 | + $background_type = null, |
|
119 | + $background_num = null |
|
120 | + ) { |
|
121 | + // Loading RUN-TIME settings |
|
122 | + foreach (array_keys($this->config) as $key) { |
|
123 | + if (isset(${$key}) && ${$key} !== null) { |
|
124 | + $this->config[$key] = ${$key}; |
|
125 | + } |
|
126 | + } |
|
127 | + $this->config['name'] = $name; |
|
128 | + |
|
129 | + // Skip CAPTCHA for member if set |
|
130 | + if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
131 | + $this->active = false; |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Verify user submission |
|
137 | + * @param null $skipMember |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function verify($skipMember = null) |
|
141 | + { |
|
142 | + $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
143 | + $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
144 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
145 | + |
|
146 | + $is_valid = false; |
|
147 | + |
|
148 | + // Skip CAPTCHA for member if set |
|
149 | + if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
150 | + $is_valid = true; |
|
151 | + // Kill too many attempts |
|
152 | + } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
153 | + $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
154 | + |
|
155 | + // Verify the code |
|
156 | + } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
157 | + $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
158 | + $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
159 | + } |
|
160 | + |
|
161 | + if (!empty($maxAttempts)) { |
|
162 | + if (!$is_valid) { |
|
163 | + // Increase the attempt records on failure |
|
164 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
165 | + // Log the error message |
|
166 | + $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
167 | + } else { |
|
168 | + |
|
169 | + // reset attempt records on success |
|
170 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
171 | + } |
|
172 | + } |
|
173 | + $this->destroyGarbage(true); |
|
174 | + |
|
175 | + return $is_valid; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @return mixed|string |
|
180 | + */ |
|
181 | + public function getCaption() |
|
182 | + { |
|
183 | + return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function getMessage() |
|
190 | + { |
|
191 | + return implode('<br>', $this->message); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Destory historical stuff |
|
196 | + * @param bool $clearSession |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function destroyGarbage($clearSession = false) |
|
200 | + { |
|
201 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
202 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
203 | + $captchaHandler = new $class(); |
|
204 | + if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
205 | + $captchaHandler->loadConfig($this->config); |
|
206 | + $captchaHandler->destroyGarbage(); |
|
207 | + } |
|
208 | + |
|
209 | + if ($clearSession) { |
|
210 | + $_SESSION['XoopsCaptcha_name'] = null; |
|
211 | + $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
212 | + $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
213 | + $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
214 | + } |
|
215 | + |
|
216 | + return true; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return mixed|string |
|
221 | + */ |
|
222 | + public function render() |
|
223 | + { |
|
224 | + $form = ''; |
|
225 | + |
|
226 | + if (!$this->active || empty($this->config['name'])) { |
|
227 | + return $form; |
|
228 | + } |
|
229 | + |
|
230 | + $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
231 | + $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
232 | + $maxAttempts = $this->config['maxattempt']; |
|
233 | + $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
234 | + /* |
|
235 | 235 | if (!empty($maxAttempts)) { |
236 | 236 | $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts; |
237 | 237 | } |
238 | 238 | */ |
239 | 239 | |
240 | - // Fail on too many attempts |
|
241 | - if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
242 | - $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
243 | - // Load the form element |
|
244 | - } else { |
|
245 | - $form = $this->loadForm(); |
|
246 | - } |
|
247 | - |
|
248 | - return $form; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return mixed |
|
253 | - */ |
|
254 | - public function loadForm() |
|
255 | - { |
|
256 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
257 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
258 | - $captchaHandler = new $class(); |
|
259 | - $captchaHandler->loadConfig($this->config); |
|
260 | - |
|
261 | - $form = $captchaHandler->render(); |
|
262 | - |
|
263 | - return $form; |
|
264 | - } |
|
240 | + // Fail on too many attempts |
|
241 | + if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
242 | + $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
243 | + // Load the form element |
|
244 | + } else { |
|
245 | + $form = $this->loadForm(); |
|
246 | + } |
|
247 | + |
|
248 | + return $form; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return mixed |
|
253 | + */ |
|
254 | + public function loadForm() |
|
255 | + { |
|
256 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
257 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
258 | + $captchaHandler = new $class(); |
|
259 | + $captchaHandler->loadConfig($this->config); |
|
260 | + |
|
261 | + $form = $captchaHandler->render(); |
|
262 | + |
|
263 | + return $form; |
|
264 | + } |
|
265 | 265 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | class XoopsCaptcha |
15 | 15 | { |
16 | 16 | public $active = true; |
17 | - public $mode = 'text'; // potential values: image, text |
|
17 | + public $mode = 'text'; // potential values: image, text |
|
18 | 18 | public $config = []; |
19 | 19 | |
20 | 20 | public $message = []; // Logging error messages |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct() |
26 | 26 | { |
27 | 27 | // Loading default preferences |
28 | - $this->config = @include __DIR__ . '/config.php'; |
|
28 | + $this->config = @include __DIR__.'/config.php'; |
|
29 | 29 | |
30 | 30 | $this->setMode($this->config['mode']); |
31 | 31 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | { |
142 | 142 | $sessionName = @$_SESSION['XoopsCaptcha_name']; |
143 | 143 | $skipMember = ($skipMember === null) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
144 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
144 | + $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']); |
|
145 | 145 | |
146 | 146 | $is_valid = false; |
147 | 147 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
150 | 150 | $is_valid = true; |
151 | 151 | // Kill too many attempts |
152 | - } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
152 | + } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_'.$sessionName] > $maxAttempts) { |
|
153 | 153 | $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
154 | 154 | |
155 | 155 | // Verify the code |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | if (!empty($maxAttempts)) { |
162 | 162 | if (!$is_valid) { |
163 | 163 | // Increase the attempt records on failure |
164 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
164 | + $_SESSION['XoopsCaptcha_attempt_'.$sessionName]++; |
|
165 | 165 | // Log the error message |
166 | 166 | $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
167 | 167 | } else { |
168 | 168 | |
169 | 169 | // reset attempt records on success |
170 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
170 | + $_SESSION['XoopsCaptcha_attempt_'.$sessionName] = null; |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | $this->destroyGarbage(true); |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | */ |
199 | 199 | public function destroyGarbage($clearSession = false) |
200 | 200 | { |
201 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
202 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
201 | + require_once __DIR__.'/'.$this->mode.'.php'; |
|
202 | + $class = 'XoopsCaptcha'.ucfirst($this->mode); |
|
203 | 203 | $captchaHandler = new $class(); |
204 | 204 | if (method_exists($captchaHandler, 'destroyGarbage')) { |
205 | 205 | $captchaHandler->loadConfig($this->config); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | |
240 | 240 | // Fail on too many attempts |
241 | - if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
241 | + if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_'.$this->config['name']] > $maxAttempts) { |
|
242 | 242 | $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
243 | 243 | // Load the form element |
244 | 244 | } else { |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function loadForm() |
255 | 255 | { |
256 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
257 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
256 | + require_once __DIR__.'/'.$this->mode.'.php'; |
|
257 | + $class = 'XoopsCaptcha'.ucfirst($this->mode); |
|
258 | 258 | $captchaHandler = new $class(); |
259 | 259 | $captchaHandler->loadConfig($this->config); |
260 | 260 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
10 | 10 | |
11 | 11 | if (!defined('SMARTOBJECT_URL')) { |
12 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
12 | + require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
13 | 13 | } |
14 | 14 | require_once SMARTOBJECT_ROOT_PATH . 'class/rating.php'; |
15 | 15 | require_once SMARTOBJECT_ROOT_PATH . 'include/functions.php'; |
@@ -23,52 +23,52 @@ discard block |
||
23 | 23 | $smartobjectPluginHandler = new SmartPluginHandler(); |
24 | 24 | $pluginObj = $smartobjectPluginHandler->getPlugin($module_dirname); |
25 | 25 | if ($pluginObj) { |
26 | - $rating_item = $pluginObj->getItem(); |
|
27 | - if ($rating_item) { |
|
28 | - $rating_itemid = $pluginObj->getItemIdForItem($rating_item); |
|
29 | - $stats = $smartobjectRatingHandler->getRatingAverageByItemId($rating_itemid, $module_dirname, $rating_item); |
|
30 | - $xoopsTpl->assign('smartobject_rating_stats_total', $stats['sum']); |
|
31 | - $xoopsTpl->assign('smartobject_rating_stats_average', $stats['average']); |
|
32 | - $xoopsTpl->assign('smartobject_rating_item', $rating_item); |
|
33 | - if (is_object($xoopsUser)) { |
|
34 | - $ratingObj = $smartobjectRatingHandler->already_rated($rating_item, $rating_itemid, $module_dirname, $xoopsUser->getVar('uid')); |
|
35 | - $xoopsTpl->assign('smartobject_user_can_rate', true); |
|
36 | - } |
|
37 | - if (isset($ratingObj) && is_object($ratingObj)) { |
|
38 | - $xoopsTpl->assign('smartobject_user_rate', $ratingObj->getVar('rate')); |
|
39 | - $xoopsTpl->assign('smartobject_rated', true); |
|
40 | - } else { |
|
41 | - $xoopsTpl->assign('smartobject_rating_dirname', $module_dirname); |
|
42 | - $xoopsTpl->assign('smartobject_rating_itemid', $rating_itemid); |
|
43 | - $urls = smart_getCurrentUrls(); |
|
44 | - $xoopsTpl->assign('smartobject_rating_current_page', $urls['full']); |
|
45 | - if (isset($xoTheme) && is_object($xoTheme)) { |
|
46 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css'); |
|
47 | - } else { |
|
48 | - //probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme |
|
49 | - //$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>"); |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
26 | + $rating_item = $pluginObj->getItem(); |
|
27 | + if ($rating_item) { |
|
28 | + $rating_itemid = $pluginObj->getItemIdForItem($rating_item); |
|
29 | + $stats = $smartobjectRatingHandler->getRatingAverageByItemId($rating_itemid, $module_dirname, $rating_item); |
|
30 | + $xoopsTpl->assign('smartobject_rating_stats_total', $stats['sum']); |
|
31 | + $xoopsTpl->assign('smartobject_rating_stats_average', $stats['average']); |
|
32 | + $xoopsTpl->assign('smartobject_rating_item', $rating_item); |
|
33 | + if (is_object($xoopsUser)) { |
|
34 | + $ratingObj = $smartobjectRatingHandler->already_rated($rating_item, $rating_itemid, $module_dirname, $xoopsUser->getVar('uid')); |
|
35 | + $xoopsTpl->assign('smartobject_user_can_rate', true); |
|
36 | + } |
|
37 | + if (isset($ratingObj) && is_object($ratingObj)) { |
|
38 | + $xoopsTpl->assign('smartobject_user_rate', $ratingObj->getVar('rate')); |
|
39 | + $xoopsTpl->assign('smartobject_rated', true); |
|
40 | + } else { |
|
41 | + $xoopsTpl->assign('smartobject_rating_dirname', $module_dirname); |
|
42 | + $xoopsTpl->assign('smartobject_rating_itemid', $rating_itemid); |
|
43 | + $urls = smart_getCurrentUrls(); |
|
44 | + $xoopsTpl->assign('smartobject_rating_current_page', $urls['full']); |
|
45 | + if (isset($xoTheme) && is_object($xoTheme)) { |
|
46 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css'); |
|
47 | + } else { |
|
48 | + //probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme |
|
49 | + //$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>"); |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | if (isset($_POST['smartobject_rating_submit'])) { |
56 | - // The rating form has just been posted. Let's save the info |
|
57 | - $ratingObj = $smartobjectRatingHandler->create(); |
|
58 | - $ratingObj->setVar('dirname', $module_dirname); |
|
59 | - $ratingObj->setVar('item', $rating_item); |
|
60 | - $ratingObj->setVar('itemid', $rating_itemid); |
|
61 | - $ratingObj->setVar('uid', $xoopsUser->getVar('uid')); |
|
62 | - $ratingObj->setVar('date', time()); |
|
63 | - $ratingObj->setVar('rate', $_POST['smartobject_rating_value']); |
|
64 | - if (!$smartobjectRatingHandler->insert($ratingObj)) { |
|
65 | - if ($xoopsDB->errno() == 1062) { |
|
66 | - $message = _SOBJECT_RATING_DUPLICATE_ENTRY; |
|
67 | - } else { |
|
68 | - $message = _SOBJECT_RATING_ERROR; |
|
69 | - } |
|
70 | - } else { |
|
71 | - $message = _SOBJECT_RATING_SUCCESS; |
|
72 | - } |
|
73 | - redirect_header('', 3, $message); |
|
56 | + // The rating form has just been posted. Let's save the info |
|
57 | + $ratingObj = $smartobjectRatingHandler->create(); |
|
58 | + $ratingObj->setVar('dirname', $module_dirname); |
|
59 | + $ratingObj->setVar('item', $rating_item); |
|
60 | + $ratingObj->setVar('itemid', $rating_itemid); |
|
61 | + $ratingObj->setVar('uid', $xoopsUser->getVar('uid')); |
|
62 | + $ratingObj->setVar('date', time()); |
|
63 | + $ratingObj->setVar('rate', $_POST['smartobject_rating_value']); |
|
64 | + if (!$smartobjectRatingHandler->insert($ratingObj)) { |
|
65 | + if ($xoopsDB->errno() == 1062) { |
|
66 | + $message = _SOBJECT_RATING_DUPLICATE_ENTRY; |
|
67 | + } else { |
|
68 | + $message = _SOBJECT_RATING_ERROR; |
|
69 | + } |
|
70 | + } else { |
|
71 | + $message = _SOBJECT_RATING_SUCCESS; |
|
72 | + } |
|
73 | + redirect_header('', 3, $message); |
|
74 | 74 | } |
@@ -9,10 +9,10 @@ discard block |
||
9 | 9 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
10 | 10 | |
11 | 11 | if (!defined('SMARTOBJECT_URL')) { |
12 | - require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
12 | + require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
13 | 13 | } |
14 | -require_once SMARTOBJECT_ROOT_PATH . 'class/rating.php'; |
|
15 | -require_once SMARTOBJECT_ROOT_PATH . 'include/functions.php'; |
|
14 | +require_once SMARTOBJECT_ROOT_PATH.'class/rating.php'; |
|
15 | +require_once SMARTOBJECT_ROOT_PATH.'include/functions.php'; |
|
16 | 16 | |
17 | 17 | smart_loadLanguageFile('smartobject', 'rating'); |
18 | 18 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $urls = smart_getCurrentUrls(); |
44 | 44 | $xoopsTpl->assign('smartobject_rating_current_page', $urls['full']); |
45 | 45 | if (isset($xoTheme) && is_object($xoTheme)) { |
46 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'assets/css/module.css'); |
|
46 | + $xoTheme->addStylesheet(SMARTOBJECT_URL.'assets/css/module.css'); |
|
47 | 47 | } else { |
48 | 48 | //probleme d'inclusion de css apres le flashplayer. Style plac� dans css du theme |
49 | 49 | //$xoopsTpl->assign('smartobject_css',"<link rel='stylesheet' type='text/css' href='".XOOPS_URL."/modules/smartobject/assets/css/module.css'>"); |
@@ -10,66 +10,66 @@ |
||
10 | 10 | |
11 | 11 | class SmartAddTo |
12 | 12 | { |
13 | - public $_layout; |
|
14 | - public $_method; |
|
13 | + public $_layout; |
|
14 | + public $_method; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor of SmartAddTo |
|
18 | - * |
|
19 | - * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
20 | - * @param int $method 0=directpage, 1=popup |
|
21 | - */ |
|
22 | - public function __construct($layout = 0, $method = 1) |
|
23 | - { |
|
24 | - $layout = (int)$layout; |
|
25 | - if ($layout < 0 || $layout > 3) { |
|
26 | - $layout = 0; |
|
27 | - } |
|
28 | - $this->_layout = $layout; |
|
16 | + /** |
|
17 | + * Constructor of SmartAddTo |
|
18 | + * |
|
19 | + * @param int $layout 0=Horizontal 1 row, 1=Horizontal 2 rows, 2=Vertical with icons, 3=Vertical no icons |
|
20 | + * @param int $method 0=directpage, 1=popup |
|
21 | + */ |
|
22 | + public function __construct($layout = 0, $method = 1) |
|
23 | + { |
|
24 | + $layout = (int)$layout; |
|
25 | + if ($layout < 0 || $layout > 3) { |
|
26 | + $layout = 0; |
|
27 | + } |
|
28 | + $this->_layout = $layout; |
|
29 | 29 | |
30 | - $method = (int)$method; |
|
31 | - if ($method < 0 || $method > 1) { |
|
32 | - $method = 1; |
|
33 | - } |
|
34 | - $this->_method = $method; |
|
35 | - } |
|
30 | + $method = (int)$method; |
|
31 | + if ($method < 0 || $method > 1) { |
|
32 | + $method = 1; |
|
33 | + } |
|
34 | + $this->_method = $method; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param bool $fetchOnly |
|
39 | - * @return mixed|string|void |
|
40 | - */ |
|
41 | - public function render($fetchOnly = false) |
|
42 | - { |
|
43 | - global $xoTheme, $xoopsTpl; |
|
37 | + /** |
|
38 | + * @param bool $fetchOnly |
|
39 | + * @return mixed|string|void |
|
40 | + */ |
|
41 | + public function render($fetchOnly = false) |
|
42 | + { |
|
43 | + global $xoTheme, $xoopsTpl; |
|
44 | 44 | |
45 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
45 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
46 | 46 | |
47 | - $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
48 | - $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
47 | + $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
|
48 | + $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
|
49 | 49 | |
50 | - $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
50 | + $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
51 | 51 | |
52 | - if ($fetchOnly) { |
|
53 | - return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
54 | - } else { |
|
55 | - $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
56 | - } |
|
57 | - } |
|
52 | + if ($fetchOnly) { |
|
53 | + return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
|
54 | + } else { |
|
55 | + $xoopsTpl->display('db:smartobject_addto.tpl'); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function renderForBlock() |
|
63 | - { |
|
64 | - global $xoTheme; |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function renderForBlock() |
|
63 | + { |
|
64 | + global $xoTheme; |
|
65 | 65 | |
66 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
66 | + $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
67 | 67 | |
68 | - $block = []; |
|
69 | - $block['smartobject_addto_method'] = $this->_method; |
|
70 | - $block['smartobject_addto_layout'] = $this->_layout; |
|
71 | - $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
68 | + $block = []; |
|
69 | + $block['smartobject_addto_method'] = $this->_method; |
|
70 | + $block['smartobject_addto_layout'] = $this->_layout; |
|
71 | + $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
72 | 72 | |
73 | - return $block; |
|
74 | - } |
|
73 | + return $block; |
|
74 | + } |
|
75 | 75 | } |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public function __construct($layout = 0, $method = 1) |
23 | 23 | { |
24 | - $layout = (int)$layout; |
|
24 | + $layout = (int) $layout; |
|
25 | 25 | if ($layout < 0 || $layout > 3) { |
26 | 26 | $layout = 0; |
27 | 27 | } |
28 | 28 | $this->_layout = $layout; |
29 | 29 | |
30 | - $method = (int)$method; |
|
30 | + $method = (int) $method; |
|
31 | 31 | if ($method < 0 || $method > 1) { |
32 | 32 | $method = 1; |
33 | 33 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | { |
43 | 43 | global $xoTheme, $xoopsTpl; |
44 | 44 | |
45 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
45 | + $xoTheme->addStylesheet(SMARTOBJECT_URL.'include/addto/addto.css'); |
|
46 | 46 | |
47 | 47 | $xoopsTpl->assign('smartobject_addto_method', $this->_method); |
48 | 48 | $xoopsTpl->assign('smartobject_addto_layout', $this->_layout); |
49 | 49 | |
50 | - $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL . 'include/addto/'); |
|
50 | + $xoopsTpl->assign('smartobject_addto_url', SMARTOBJECT_URL.'include/addto/'); |
|
51 | 51 | |
52 | 52 | if ($fetchOnly) { |
53 | 53 | return $xoopsTpl->fetch('db:smartobject_addto.tpl'); |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | { |
64 | 64 | global $xoTheme; |
65 | 65 | |
66 | - $xoTheme->addStylesheet(SMARTOBJECT_URL . 'include/addto/addto.css'); |
|
66 | + $xoTheme->addStylesheet(SMARTOBJECT_URL.'include/addto/addto.css'); |
|
67 | 67 | |
68 | 68 | $block = []; |
69 | 69 | $block['smartobject_addto_method'] = $this->_method; |
70 | 70 | $block['smartobject_addto_layout'] = $this->_layout; |
71 | - $block['smartobject_addto_url'] = SMARTOBJECT_URL . 'include/addto/'; |
|
71 | + $block['smartobject_addto_url'] = SMARTOBJECT_URL.'include/addto/'; |
|
72 | 72 | |
73 | 73 | return $block; |
74 | 74 | } |
@@ -11,45 +11,45 @@ |
||
11 | 11 | |
12 | 12 | class SmartTip |
13 | 13 | { |
14 | - public $id; |
|
15 | - public $caption; |
|
16 | - public $message; |
|
17 | - public $visible; |
|
18 | - public $_tpl; |
|
14 | + public $id; |
|
15 | + public $caption; |
|
16 | + public $message; |
|
17 | + public $visible; |
|
18 | + public $_tpl; |
|
19 | 19 | |
20 | - /** |
|
21 | - * SmartTip constructor. |
|
22 | - * @param $id |
|
23 | - * @param $caption |
|
24 | - * @param $message |
|
25 | - * @param bool $visible |
|
26 | - */ |
|
27 | - public function __construct($id, $caption, $message, $visible = false) |
|
28 | - { |
|
29 | - $this->id = $id; |
|
30 | - $this->caption = $caption; |
|
31 | - $this->message = $message; |
|
32 | - $this->visible = $visible; |
|
33 | - $this->_tpl = new XoopsTpl(); |
|
34 | - } |
|
20 | + /** |
|
21 | + * SmartTip constructor. |
|
22 | + * @param $id |
|
23 | + * @param $caption |
|
24 | + * @param $message |
|
25 | + * @param bool $visible |
|
26 | + */ |
|
27 | + public function __construct($id, $caption, $message, $visible = false) |
|
28 | + { |
|
29 | + $this->id = $id; |
|
30 | + $this->caption = $caption; |
|
31 | + $this->message = $message; |
|
32 | + $this->visible = $visible; |
|
33 | + $this->_tpl = new XoopsTpl(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param bool $outputNow |
|
38 | - * @return mixed|string|void |
|
39 | - */ |
|
40 | - public function render($outputNow = true) |
|
41 | - { |
|
42 | - $aTip = [ |
|
43 | - 'id' => $this->id, |
|
44 | - 'caption' => $this->caption, |
|
45 | - 'message' => $this->message, |
|
46 | - 'visible' => $this->visible ? 'block' : 'none' |
|
47 | - ]; |
|
48 | - $this->_tpl->assign('tip', $aTip); |
|
49 | - if ($outputNow) { |
|
50 | - $this->_tpl->display('db:smartobject_tip.tpl'); |
|
51 | - } else { |
|
52 | - return $this->_tpl->fetch('db:smartobject_tip.tpl'); |
|
53 | - } |
|
54 | - } |
|
36 | + /** |
|
37 | + * @param bool $outputNow |
|
38 | + * @return mixed|string|void |
|
39 | + */ |
|
40 | + public function render($outputNow = true) |
|
41 | + { |
|
42 | + $aTip = [ |
|
43 | + 'id' => $this->id, |
|
44 | + 'caption' => $this->caption, |
|
45 | + 'message' => $this->message, |
|
46 | + 'visible' => $this->visible ? 'block' : 'none' |
|
47 | + ]; |
|
48 | + $this->_tpl->assign('tip', $aTip); |
|
49 | + if ($outputNow) { |
|
50 | + $this->_tpl->display('db:smartobject_tip.tpl'); |
|
51 | + } else { |
|
52 | + return $this->_tpl->fetch('db:smartobject_tip.tpl'); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | } |
@@ -19,96 +19,96 @@ |
||
19 | 19 | */ |
20 | 20 | class SmartHighlighter |
21 | 21 | { |
22 | - /** |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - public $preg_keywords = ''; |
|
26 | - /** |
|
27 | - * @access private |
|
28 | - */ |
|
29 | - public $keywords = ''; |
|
30 | - /** |
|
31 | - * @access private |
|
32 | - */ |
|
33 | - public $singlewords = false; |
|
34 | - /** |
|
35 | - * @access private |
|
36 | - */ |
|
37 | - public $replace_callback = null; |
|
22 | + /** |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + public $preg_keywords = ''; |
|
26 | + /** |
|
27 | + * @access private |
|
28 | + */ |
|
29 | + public $keywords = ''; |
|
30 | + /** |
|
31 | + * @access private |
|
32 | + */ |
|
33 | + public $singlewords = false; |
|
34 | + /** |
|
35 | + * @access private |
|
36 | + */ |
|
37 | + public $replace_callback = null; |
|
38 | 38 | |
39 | - public $content; |
|
39 | + public $content; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Main constructor |
|
43 | - * |
|
44 | - * This is the main constructor of keyhighlighter class. <br> |
|
45 | - * It's the only public method of the class. |
|
46 | - * @param string $keywords the keywords you want to highlight |
|
47 | - * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | - * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | - * <code> |
|
50 | - * <?php |
|
51 | - * require ('keyhighlighter.class.php'); |
|
52 | - * |
|
53 | - * function my_highlighter ($matches) { |
|
54 | - * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | - * } |
|
56 | - * |
|
57 | - * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | - * readfile ('http://www.w3c.org/'); |
|
59 | - * ?> |
|
60 | - * </code> |
|
61 | - */ |
|
62 | - // public function __construct () |
|
63 | - public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | - { |
|
65 | - $this->keywords = $keywords; |
|
66 | - $this->singlewords = $singlewords; |
|
67 | - $this->replace_callback = $replace_callback; |
|
68 | - } |
|
41 | + /** |
|
42 | + * Main constructor |
|
43 | + * |
|
44 | + * This is the main constructor of keyhighlighter class. <br> |
|
45 | + * It's the only public method of the class. |
|
46 | + * @param string $keywords the keywords you want to highlight |
|
47 | + * @param boolean $singlewords specify if it has to highlight also the single words. |
|
48 | + * @param callback $replace_callback a custom callback for keyword highlight. |
|
49 | + * <code> |
|
50 | + * <?php |
|
51 | + * require ('keyhighlighter.class.php'); |
|
52 | + * |
|
53 | + * function my_highlighter ($matches) { |
|
54 | + * return '<span style="font-weight: bolder; color: #FF0000;">' . $matches[0] . '</span>'; |
|
55 | + * } |
|
56 | + * |
|
57 | + * new keyhighlighter ('W3C', false, 'my_highlighter'); |
|
58 | + * readfile ('http://www.w3c.org/'); |
|
59 | + * ?> |
|
60 | + * </code> |
|
61 | + */ |
|
62 | + // public function __construct () |
|
63 | + public function __construct($keywords, $singlewords = false, $replace_callback = null) |
|
64 | + { |
|
65 | + $this->keywords = $keywords; |
|
66 | + $this->singlewords = $singlewords; |
|
67 | + $this->replace_callback = $replace_callback; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @access private |
|
72 | - * @param $replace_matches |
|
73 | - * @return mixed |
|
74 | - */ |
|
75 | - public function replace($replace_matches) |
|
76 | - { |
|
77 | - $patterns = []; |
|
78 | - if ($this->singlewords) { |
|
79 | - $keywords = explode(' ', $this->preg_keywords); |
|
80 | - foreach ($keywords as $keyword) { |
|
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | - } |
|
83 | - } else { |
|
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | - } |
|
70 | + /** |
|
71 | + * @access private |
|
72 | + * @param $replace_matches |
|
73 | + * @return mixed |
|
74 | + */ |
|
75 | + public function replace($replace_matches) |
|
76 | + { |
|
77 | + $patterns = []; |
|
78 | + if ($this->singlewords) { |
|
79 | + $keywords = explode(' ', $this->preg_keywords); |
|
80 | + foreach ($keywords as $keyword) { |
|
81 | + $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
82 | + } |
|
83 | + } else { |
|
84 | + $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
85 | + } |
|
86 | 86 | |
87 | - $result = $replace_matches[0]; |
|
87 | + $result = $replace_matches[0]; |
|
88 | 88 | |
89 | - foreach ($patterns as $pattern) { |
|
90 | - if (null !== $this->replace_callback) { |
|
91 | - $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | - } else { |
|
93 | - $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | - } |
|
95 | - } |
|
89 | + foreach ($patterns as $pattern) { |
|
90 | + if (null !== $this->replace_callback) { |
|
91 | + $result = preg_replace_callback($pattern, $this->replace_callback, $result); |
|
92 | + } else { |
|
93 | + $result = preg_replace($pattern, '<span class="highlightedkey">\\0</span>', $result); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - return $result; |
|
98 | - } |
|
97 | + return $result; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @access private |
|
102 | - * @param $buffer |
|
103 | - * @return mixed|string |
|
104 | - */ |
|
105 | - public function highlight($buffer) |
|
106 | - { |
|
107 | - $buffer = '>' . $buffer . '<'; |
|
108 | - $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
110 | - $buffer = substr($buffer, 1, -1); |
|
100 | + /** |
|
101 | + * @access private |
|
102 | + * @param $buffer |
|
103 | + * @return mixed|string |
|
104 | + */ |
|
105 | + public function highlight($buffer) |
|
106 | + { |
|
107 | + $buffer = '>' . $buffer . '<'; |
|
108 | + $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
110 | + $buffer = substr($buffer, 1, -1); |
|
111 | 111 | |
112 | - return $buffer; |
|
113 | - } |
|
112 | + return $buffer; |
|
113 | + } |
|
114 | 114 | } |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | if ($this->singlewords) { |
79 | 79 | $keywords = explode(' ', $this->preg_keywords); |
80 | 80 | foreach ($keywords as $keyword) { |
81 | - $patterns[] = '/(?' . '>' . $keyword . '+)/si'; |
|
81 | + $patterns[] = '/(?'.'>'.$keyword.'+)/si'; |
|
82 | 82 | } |
83 | 83 | } else { |
84 | - $patterns[] = '/(?' . '>' . $this->preg_keywords . '+)/si'; |
|
84 | + $patterns[] = '/(?'.'>'.$this->preg_keywords.'+)/si'; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | $result = $replace_matches[0]; |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function highlight($buffer) |
106 | 106 | { |
107 | - $buffer = '>' . $buffer . '<'; |
|
107 | + $buffer = '>'.$buffer.'<'; |
|
108 | 108 | $this->preg_keywords = preg_replace('/[^\w ]/si', '', $this->keywords); |
109 | - $buffer = preg_replace_callback("/(\>(((?" . ">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
109 | + $buffer = preg_replace_callback("/(\>(((?".">[^><]+)|(?R))*)\<)/is", [&$this, 'replace'], $buffer); |
|
110 | 110 | $buffer = substr($buffer, 1, -1); |
111 | 111 | |
112 | 112 | return $buffer; |
@@ -37,125 +37,125 @@ discard block |
||
37 | 37 | */ |
38 | 38 | class SmartobjectRating extends SmartObject |
39 | 39 | { |
40 | - public $_modulePlugin = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * SmartobjectRating constructor. |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | - $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | - $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | - $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | - $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | - $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | - $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | - |
|
55 | - $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | - |
|
57 | - $this->setControl('dirname', [ |
|
58 | - 'handler' => 'rating', |
|
59 | - 'method' => 'getModuleList', |
|
60 | - 'onSelect' => 'submit' |
|
61 | - ]); |
|
62 | - |
|
63 | - $this->setControl('item', [ |
|
64 | - 'object' => &$this, |
|
65 | - 'method' => 'getItemList' |
|
66 | - ]); |
|
67 | - |
|
68 | - $this->setControl('uid', 'user'); |
|
69 | - |
|
70 | - $this->setControl('rate', [ |
|
71 | - 'handler' => 'rating', |
|
72 | - 'method' => 'getRateList' |
|
73 | - ]); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @param string $key |
|
78 | - * @param string $format |
|
79 | - * @return mixed |
|
80 | - */ |
|
81 | - public function getVar($key, $format = 's') |
|
82 | - { |
|
83 | - if ($format === 's' && in_array($key, ['name', 'dirname'])) { |
|
84 | - // return call_user_func(array($this, $key)); |
|
85 | - return $this->{$key}(); |
|
86 | - } |
|
87 | - |
|
88 | - return parent::getVar($key, $format); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function name() |
|
95 | - { |
|
96 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
97 | - |
|
98 | - return $ret; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - public function dirname() |
|
105 | - { |
|
106 | - global $smartobjectRatingHandler; |
|
107 | - $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | - |
|
109 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @return mixed |
|
114 | - */ |
|
115 | - public function getItemList() |
|
116 | - { |
|
117 | - $plugin = $this->getModulePlugin(); |
|
118 | - |
|
119 | - return $plugin->getItemList(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function getItemValue() |
|
126 | - { |
|
127 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | - $plugin = $this->getModulePlugin(); |
|
129 | - $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | - if (!$pluginItemInfo) { |
|
131 | - return ''; |
|
132 | - } |
|
133 | - $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | - |
|
136 | - return $ret; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return mixed |
|
141 | - */ |
|
142 | - public function getRateValue() |
|
143 | - { |
|
144 | - return $this->getVar('rate'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function getModulePlugin() |
|
151 | - { |
|
152 | - if (!$this->_modulePlugin) { |
|
153 | - global $smartobjectRatingHandler; |
|
154 | - $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | - } |
|
156 | - |
|
157 | - return $this->_modulePlugin; |
|
158 | - } |
|
40 | + public $_modulePlugin = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * SmartobjectRating constructor. |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
48 | + $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
|
49 | + $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
|
50 | + $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
|
51 | + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_UID); |
|
52 | + $this->quickInitVar('date', XOBJ_DTYPE_LTIME, true, _CO_SOBJECT_RATING_DATE); |
|
53 | + $this->quickInitVar('rate', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_RATE); |
|
54 | + |
|
55 | + $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
|
56 | + |
|
57 | + $this->setControl('dirname', [ |
|
58 | + 'handler' => 'rating', |
|
59 | + 'method' => 'getModuleList', |
|
60 | + 'onSelect' => 'submit' |
|
61 | + ]); |
|
62 | + |
|
63 | + $this->setControl('item', [ |
|
64 | + 'object' => &$this, |
|
65 | + 'method' => 'getItemList' |
|
66 | + ]); |
|
67 | + |
|
68 | + $this->setControl('uid', 'user'); |
|
69 | + |
|
70 | + $this->setControl('rate', [ |
|
71 | + 'handler' => 'rating', |
|
72 | + 'method' => 'getRateList' |
|
73 | + ]); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @param string $key |
|
78 | + * @param string $format |
|
79 | + * @return mixed |
|
80 | + */ |
|
81 | + public function getVar($key, $format = 's') |
|
82 | + { |
|
83 | + if ($format === 's' && in_array($key, ['name', 'dirname'])) { |
|
84 | + // return call_user_func(array($this, $key)); |
|
85 | + return $this->{$key}(); |
|
86 | + } |
|
87 | + |
|
88 | + return parent::getVar($key, $format); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function name() |
|
95 | + { |
|
96 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, []); |
|
97 | + |
|
98 | + return $ret; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + public function dirname() |
|
105 | + { |
|
106 | + global $smartobjectRatingHandler; |
|
107 | + $moduleArray = $smartobjectRatingHandler->getModuleList(); |
|
108 | + |
|
109 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @return mixed |
|
114 | + */ |
|
115 | + public function getItemList() |
|
116 | + { |
|
117 | + $plugin = $this->getModulePlugin(); |
|
118 | + |
|
119 | + return $plugin->getItemList(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function getItemValue() |
|
126 | + { |
|
127 | + $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
128 | + $plugin = $this->getModulePlugin(); |
|
129 | + $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
|
130 | + if (!$pluginItemInfo) { |
|
131 | + return ''; |
|
132 | + } |
|
133 | + $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
|
134 | + $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
135 | + |
|
136 | + return $ret; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | + public function getRateValue() |
|
143 | + { |
|
144 | + return $this->getVar('rate'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function getModulePlugin() |
|
151 | + { |
|
152 | + if (!$this->_modulePlugin) { |
|
153 | + global $smartobjectRatingHandler; |
|
154 | + $this->_modulePlugin = $smartobjectRatingHandler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
|
155 | + } |
|
156 | + |
|
157 | + return $this->_modulePlugin; |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,93 +163,93 @@ discard block |
||
163 | 163 | */ |
164 | 164 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler |
165 | 165 | { |
166 | - public $_rateOptions = []; |
|
167 | - public $_moduleList = false; |
|
168 | - public $pluginsObject; |
|
169 | - |
|
170 | - /** |
|
171 | - * SmartobjectRatingHandler constructor. |
|
172 | - * @param XoopsDatabase $db |
|
173 | - */ |
|
174 | - public function __construct(XoopsDatabase $db) |
|
175 | - { |
|
176 | - parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
177 | - $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
178 | - |
|
179 | - $this->_rateOptions[1] = 1; |
|
180 | - $this->_rateOptions[2] = 2; |
|
181 | - $this->_rateOptions[3] = 3; |
|
182 | - $this->_rateOptions[4] = 4; |
|
183 | - $this->_rateOptions[5] = 5; |
|
184 | - |
|
185 | - $this->pluginsObject = new SmartPluginHandler(); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function getModuleList() |
|
192 | - { |
|
193 | - if (!$this->_moduleList) { |
|
194 | - $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | - $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | - foreach ($moduleArray as $k => $v) { |
|
197 | - $this->_moduleList[$k] = $v; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - return $this->_moduleList; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function getRateList() |
|
208 | - { |
|
209 | - return $this->_rateOptions; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param $itemid |
|
214 | - * @param $dirname |
|
215 | - * @param $item |
|
216 | - * @return int |
|
217 | - */ |
|
218 | - public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | - { |
|
220 | - $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | - $result = $this->db->query($sql); |
|
222 | - if (!$result) { |
|
223 | - return 0; |
|
224 | - } |
|
225 | - list($average, $sum) = $this->db->fetchRow($result); |
|
226 | - $ret['average'] = isset($average) ? $average : 0; |
|
227 | - $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | - |
|
229 | - return $ret; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $item |
|
234 | - * @param $itemid |
|
235 | - * @param $dirname |
|
236 | - * @param $uid |
|
237 | - * @return bool |
|
238 | - */ |
|
239 | - public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | - { |
|
241 | - $criteria = new CriteriaCompo(); |
|
242 | - $criteria->add(new Criteria('item', $item)); |
|
243 | - $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | - $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | - $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | - |
|
247 | - $ret = $this->getObjects($criteria); |
|
248 | - |
|
249 | - if (!$ret) { |
|
250 | - return false; |
|
251 | - } else { |
|
252 | - return $ret[0]; |
|
253 | - } |
|
254 | - } |
|
166 | + public $_rateOptions = []; |
|
167 | + public $_moduleList = false; |
|
168 | + public $pluginsObject; |
|
169 | + |
|
170 | + /** |
|
171 | + * SmartobjectRatingHandler constructor. |
|
172 | + * @param XoopsDatabase $db |
|
173 | + */ |
|
174 | + public function __construct(XoopsDatabase $db) |
|
175 | + { |
|
176 | + parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
177 | + $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
178 | + |
|
179 | + $this->_rateOptions[1] = 1; |
|
180 | + $this->_rateOptions[2] = 2; |
|
181 | + $this->_rateOptions[3] = 3; |
|
182 | + $this->_rateOptions[4] = 4; |
|
183 | + $this->_rateOptions[5] = 5; |
|
184 | + |
|
185 | + $this->pluginsObject = new SmartPluginHandler(); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function getModuleList() |
|
192 | + { |
|
193 | + if (!$this->_moduleList) { |
|
194 | + $moduleArray = $this->pluginsObject->getPluginsArray(); |
|
195 | + $this->_moduleList[0] = _CO_SOBJECT_MAKE_SELECTION; |
|
196 | + foreach ($moduleArray as $k => $v) { |
|
197 | + $this->_moduleList[$k] = $v; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + return $this->_moduleList; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function getRateList() |
|
208 | + { |
|
209 | + return $this->_rateOptions; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param $itemid |
|
214 | + * @param $dirname |
|
215 | + * @param $item |
|
216 | + * @return int |
|
217 | + */ |
|
218 | + public function getRatingAverageByItemId($itemid, $dirname, $item) |
|
219 | + { |
|
220 | + $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | + $result = $this->db->query($sql); |
|
222 | + if (!$result) { |
|
223 | + return 0; |
|
224 | + } |
|
225 | + list($average, $sum) = $this->db->fetchRow($result); |
|
226 | + $ret['average'] = isset($average) ? $average : 0; |
|
227 | + $ret['sum'] = isset($sum) ? $sum : 0; |
|
228 | + |
|
229 | + return $ret; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $item |
|
234 | + * @param $itemid |
|
235 | + * @param $dirname |
|
236 | + * @param $uid |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | + public function already_rated($item, $itemid, $dirname, $uid) |
|
240 | + { |
|
241 | + $criteria = new CriteriaCompo(); |
|
242 | + $criteria->add(new Criteria('item', $item)); |
|
243 | + $criteria->add(new Criteria('itemid', $itemid)); |
|
244 | + $criteria->add(new Criteria('dirname', $dirname)); |
|
245 | + $criteria->add(new Criteria('user.uid', $uid)); |
|
246 | + |
|
247 | + $ret = $this->getObjects($criteria); |
|
248 | + |
|
249 | + if (!$ret) { |
|
250 | + return false; |
|
251 | + } else { |
|
252 | + return $ret[0]; |
|
253 | + } |
|
254 | + } |
|
255 | 255 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | |
30 | 30 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
31 | 31 | |
32 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
33 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartplugins.php'; |
|
32 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
33 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartplugins.php'; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Class SmartobjectRating |
@@ -124,14 +124,14 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function getItemValue() |
126 | 126 | { |
127 | - $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
|
127 | + $moduleUrl = XOOPS_URL.'/modules/'.$this->getVar('dirname', 'n').'/'; |
|
128 | 128 | $plugin = $this->getModulePlugin(); |
129 | 129 | $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
130 | 130 | if (!$pluginItemInfo) { |
131 | 131 | return ''; |
132 | 132 | } |
133 | 133 | $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
134 | - $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
|
134 | + $ret = '<a href="'.$moduleUrl.$itemPath.'">'.$pluginItemInfo['caption'].'</a>'; |
|
135 | 135 | |
136 | 136 | return $ret; |
137 | 137 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | public function __construct(XoopsDatabase $db) |
175 | 175 | { |
176 | 176 | parent::__construct($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
177 | - $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
|
177 | + $this->generalSQL = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname.' INNER JOIN '.$this->db->prefix('users').' AS user ON '.$this->_itemname.'.uid=user.uid'; |
|
178 | 178 | |
179 | 179 | $this->_rateOptions[1] = 1; |
180 | 180 | $this->_rateOptions[2] = 2; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function getRatingAverageByItemId($itemid, $dirname, $item) |
219 | 219 | { |
220 | - $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM ' . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
220 | + $sql = 'SELECT AVG(rate), COUNT(ratingid) FROM '.$this->table." WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
|
221 | 221 | $result = $this->db->query($sql); |
222 | 222 | if (!$result) { |
223 | 223 | return 0; |
@@ -11,36 +11,36 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormUserElement extends XoopsFormSelect |
13 | 13 | { |
14 | - public $multiple = false; |
|
14 | + public $multiple = false; |
|
15 | 15 | |
16 | - /** |
|
17 | - * SmartFormUserElement constructor. |
|
18 | - * @param string $object |
|
19 | - * @param string $key |
|
20 | - */ |
|
21 | - public function __construct($object, $key) |
|
22 | - { |
|
23 | - $var = $object->vars[$key]; |
|
24 | - $size = isset($var['size']) ? $var['size'] : ($this->multiple ? 5 : 1); |
|
16 | + /** |
|
17 | + * SmartFormUserElement constructor. |
|
18 | + * @param string $object |
|
19 | + * @param string $key |
|
20 | + */ |
|
21 | + public function __construct($object, $key) |
|
22 | + { |
|
23 | + $var = $object->vars[$key]; |
|
24 | + $size = isset($var['size']) ? $var['size'] : ($this->multiple ? 5 : 1); |
|
25 | 25 | |
26 | - parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e'), $size, $this->multiple); |
|
26 | + parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e'), $size, $this->multiple); |
|
27 | 27 | |
28 | - // Adding the options inside this SelectBox |
|
29 | - // If the custom method is not from a module, than it's from the core |
|
30 | - $control = $object->getControl($key); |
|
28 | + // Adding the options inside this SelectBox |
|
29 | + // If the custom method is not from a module, than it's from the core |
|
30 | + $control = $object->getControl($key); |
|
31 | 31 | |
32 | - global $xoopsDB; |
|
33 | - $ret = []; |
|
34 | - $limit = $start = 0; |
|
35 | - $sql = 'SELECT uid, uname FROM ' . $xoopsDB->prefix('users'); |
|
36 | - $sql .= ' ORDER BY uname ASC'; |
|
32 | + global $xoopsDB; |
|
33 | + $ret = []; |
|
34 | + $limit = $start = 0; |
|
35 | + $sql = 'SELECT uid, uname FROM ' . $xoopsDB->prefix('users'); |
|
36 | + $sql .= ' ORDER BY uname ASC'; |
|
37 | 37 | |
38 | - $result = $xoopsDB->query($sql); |
|
39 | - if ($result) { |
|
40 | - while ($myrow = $xoopsDB->fetchArray($result)) { |
|
41 | - $uArray[$myrow['uid']] = $myrow['uname']; |
|
42 | - } |
|
43 | - } |
|
44 | - $this->addOptionArray($uArray); |
|
45 | - } |
|
38 | + $result = $xoopsDB->query($sql); |
|
39 | + if ($result) { |
|
40 | + while ($myrow = $xoopsDB->fetchArray($result)) { |
|
41 | + $uArray[$myrow['uid']] = $myrow['uname']; |
|
42 | + } |
|
43 | + } |
|
44 | + $this->addOptionArray($uArray); |
|
45 | + } |
|
46 | 46 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | global $xoopsDB; |
33 | 33 | $ret = []; |
34 | 34 | $limit = $start = 0; |
35 | - $sql = 'SELECT uid, uname FROM ' . $xoopsDB->prefix('users'); |
|
35 | + $sql = 'SELECT uid, uname FROM '.$xoopsDB->prefix('users'); |
|
36 | 36 | $sql .= ' ORDER BY uname ASC'; |
37 | 37 | |
38 | 38 | $result = $xoopsDB->query($sql); |
@@ -18,123 +18,123 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class SmartobjectCategory extends SmartSeoObject |
20 | 20 | { |
21 | - public $_categoryPath; |
|
22 | - |
|
23 | - /** |
|
24 | - * SmartobjectCategory constructor. |
|
25 | - */ |
|
26 | - public function __construct() |
|
27 | - { |
|
28 | - $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
29 | - $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
30 | - $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
31 | - $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
32 | - $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
33 | - |
|
34 | - $this->initCommonVar('doxcode'); |
|
35 | - |
|
36 | - $this->setControl('image', ['name' => 'image']); |
|
37 | - $this->setControl('parentid', ['name' => 'parentcategory']); |
|
38 | - $this->setControl('description', [ |
|
39 | - 'name' => 'textarea', |
|
40 | - 'itemHandler' => false, |
|
41 | - 'method' => false, |
|
42 | - 'module' => false, |
|
43 | - 'form_editor' => 'default' |
|
44 | - ]); |
|
45 | - |
|
46 | - // call parent constructor to get SEO fields initiated |
|
47 | - parent::__construct(); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * returns a specific variable for the object in a proper format |
|
52 | - * |
|
53 | - * @access public |
|
54 | - * @param string $key key of the object's variable to be returned |
|
55 | - * @param string $format format to use for the output |
|
56 | - * @return mixed formatted value of the variable |
|
57 | - */ |
|
58 | - public function getVar($key, $format = 's') |
|
59 | - { |
|
60 | - if ($format === 's' && in_array($key, ['description', 'image'])) { |
|
61 | - // return call_user_func(array($this, $key)); |
|
62 | - return $this->{$key}(); |
|
63 | - } |
|
64 | - |
|
65 | - return parent::getVar($key, $format); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function description() |
|
72 | - { |
|
73 | - return $this->getValueFor('description', false); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return bool|mixed |
|
78 | - */ |
|
79 | - public function image() |
|
80 | - { |
|
81 | - $ret = $this->getVar('image', 'e'); |
|
82 | - if ($ret == '-1') { |
|
83 | - return false; |
|
84 | - } else { |
|
85 | - return $ret; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function toArray() |
|
93 | - { |
|
94 | - $this->setVar('doxcode', true); |
|
95 | - global $myts; |
|
96 | - $objectArray = parent::toArray(); |
|
97 | - if ($objectArray['image']) { |
|
98 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
99 | - } |
|
100 | - |
|
101 | - return $objectArray; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Create the complete path of a category |
|
106 | - * |
|
107 | - * @todo this could be improved as it uses multiple queries |
|
108 | - * @param bool $withAllLink make all name clickable |
|
109 | - * @param bool $currentCategory |
|
110 | - * @return string complete path (breadcrumb) |
|
111 | - */ |
|
112 | - public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
113 | - { |
|
114 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
115 | - $controller = new SmartObjectController($this->handler); |
|
116 | - |
|
117 | - if (!$this->_categoryPath) { |
|
118 | - if ($withAllLink && !$currentCategory) { |
|
119 | - $ret = $controller->getItemLink($this); |
|
120 | - } else { |
|
121 | - $currentCategory = false; |
|
122 | - $ret = $this->getVar('name'); |
|
123 | - } |
|
124 | - $parentid = $this->getVar('parentid'); |
|
125 | - if ($parentid != 0) { |
|
126 | - $parentObj = $this->handler->get($parentid); |
|
127 | - if ($parentObj->isNew()) { |
|
128 | - exit; |
|
129 | - } |
|
130 | - $parentid = $parentObj->getVar('parentid'); |
|
131 | - $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
132 | - } |
|
133 | - $this->_categoryPath = $ret; |
|
134 | - } |
|
135 | - |
|
136 | - return $this->_categoryPath; |
|
137 | - } |
|
21 | + public $_categoryPath; |
|
22 | + |
|
23 | + /** |
|
24 | + * SmartobjectCategory constructor. |
|
25 | + */ |
|
26 | + public function __construct() |
|
27 | + { |
|
28 | + $this->initVar('categoryid', XOBJ_DTYPE_INT, '', true); |
|
29 | + $this->initVar('parentid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_CATEGORY_PARENTID, _CO_SOBJECT_CATEGORY_PARENTID_DSC); |
|
30 | + $this->initVar('name', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_NAME, _CO_SOBJECT_CATEGORY_NAME_DSC); |
|
31 | + $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false, null, '', false, _CO_SOBJECT_CATEGORY_DESCRIPTION, _CO_SOBJECT_CATEGORY_DESCRIPTION_DSC); |
|
32 | + $this->initVar('image', XOBJ_DTYPE_TXTBOX, '', false, null, '', false, _CO_SOBJECT_CATEGORY_IMAGE, _CO_SOBJECT_CATEGORY_IMAGE_DSC); |
|
33 | + |
|
34 | + $this->initCommonVar('doxcode'); |
|
35 | + |
|
36 | + $this->setControl('image', ['name' => 'image']); |
|
37 | + $this->setControl('parentid', ['name' => 'parentcategory']); |
|
38 | + $this->setControl('description', [ |
|
39 | + 'name' => 'textarea', |
|
40 | + 'itemHandler' => false, |
|
41 | + 'method' => false, |
|
42 | + 'module' => false, |
|
43 | + 'form_editor' => 'default' |
|
44 | + ]); |
|
45 | + |
|
46 | + // call parent constructor to get SEO fields initiated |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * returns a specific variable for the object in a proper format |
|
52 | + * |
|
53 | + * @access public |
|
54 | + * @param string $key key of the object's variable to be returned |
|
55 | + * @param string $format format to use for the output |
|
56 | + * @return mixed formatted value of the variable |
|
57 | + */ |
|
58 | + public function getVar($key, $format = 's') |
|
59 | + { |
|
60 | + if ($format === 's' && in_array($key, ['description', 'image'])) { |
|
61 | + // return call_user_func(array($this, $key)); |
|
62 | + return $this->{$key}(); |
|
63 | + } |
|
64 | + |
|
65 | + return parent::getVar($key, $format); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function description() |
|
72 | + { |
|
73 | + return $this->getValueFor('description', false); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return bool|mixed |
|
78 | + */ |
|
79 | + public function image() |
|
80 | + { |
|
81 | + $ret = $this->getVar('image', 'e'); |
|
82 | + if ($ret == '-1') { |
|
83 | + return false; |
|
84 | + } else { |
|
85 | + return $ret; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function toArray() |
|
93 | + { |
|
94 | + $this->setVar('doxcode', true); |
|
95 | + global $myts; |
|
96 | + $objectArray = parent::toArray(); |
|
97 | + if ($objectArray['image']) { |
|
98 | + $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
99 | + } |
|
100 | + |
|
101 | + return $objectArray; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Create the complete path of a category |
|
106 | + * |
|
107 | + * @todo this could be improved as it uses multiple queries |
|
108 | + * @param bool $withAllLink make all name clickable |
|
109 | + * @param bool $currentCategory |
|
110 | + * @return string complete path (breadcrumb) |
|
111 | + */ |
|
112 | + public function getCategoryPath($withAllLink = true, $currentCategory = false) |
|
113 | + { |
|
114 | + require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
115 | + $controller = new SmartObjectController($this->handler); |
|
116 | + |
|
117 | + if (!$this->_categoryPath) { |
|
118 | + if ($withAllLink && !$currentCategory) { |
|
119 | + $ret = $controller->getItemLink($this); |
|
120 | + } else { |
|
121 | + $currentCategory = false; |
|
122 | + $ret = $this->getVar('name'); |
|
123 | + } |
|
124 | + $parentid = $this->getVar('parentid'); |
|
125 | + if ($parentid != 0) { |
|
126 | + $parentObj = $this->handler->get($parentid); |
|
127 | + if ($parentObj->isNew()) { |
|
128 | + exit; |
|
129 | + } |
|
130 | + $parentid = $parentObj->getVar('parentid'); |
|
131 | + $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
132 | + } |
|
133 | + $this->_categoryPath = $ret; |
|
134 | + } |
|
135 | + |
|
136 | + return $this->_categoryPath; |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,91 +142,91 @@ discard block |
||
142 | 142 | */ |
143 | 143 | class SmartobjectCategoryHandler extends SmartPersistableObjectHandler |
144 | 144 | { |
145 | - public $allCategoriesObj = false; |
|
146 | - public $_allCategoriesId = false; |
|
147 | - |
|
148 | - /** |
|
149 | - * SmartobjectCategoryHandler constructor. |
|
150 | - * @param XoopsDatabase $db |
|
151 | - * @param $modulename |
|
152 | - */ |
|
153 | - public function __construct(XoopsDatabase $db, $modulename) |
|
154 | - { |
|
155 | - parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param int $parentid |
|
160 | - * @param bool $perm_name |
|
161 | - * @param string $sort |
|
162 | - * @param string $order |
|
163 | - * @return array|bool |
|
164 | - */ |
|
165 | - public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC') |
|
166 | - { |
|
167 | - if (!$this->allCategoriesObj) { |
|
168 | - $criteria = new CriteriaCompo(); |
|
169 | - $criteria->setSort($sort); |
|
170 | - $criteria->setOrder($order); |
|
171 | - global $xoopsUser; |
|
172 | - $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin(); |
|
173 | - |
|
174 | - if ($perm_name && !$userIsAdmin) { |
|
175 | - if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) { |
|
176 | - return false; |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - $this->allCategoriesObj = $this->getObjects($criteria, 'parentid'); |
|
181 | - } |
|
182 | - |
|
183 | - $ret = []; |
|
184 | - if (isset($this->allCategoriesObj[$parentid])) { |
|
185 | - foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) { |
|
186 | - $ret[$categoryid]['self'] = $categoryObj->toArray(); |
|
187 | - if (isset($this->allCategoriesObj[$categoryid])) { |
|
188 | - $ret[$categoryid]['sub'] = $this->getAllCategoriesArray($categoryid); |
|
189 | - $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $ret; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $parentid |
|
199 | - * @param bool $asString |
|
200 | - * @return array|string |
|
201 | - */ |
|
202 | - public function getParentIds($parentid, $asString = true) |
|
203 | - { |
|
204 | - if (!$this->allCategoriesId) { |
|
205 | - $ret = []; |
|
206 | - $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
207 | - |
|
208 | - $result = $this->db->query($sql); |
|
209 | - |
|
210 | - if (!$result) { |
|
211 | - return $ret; |
|
212 | - } |
|
213 | - |
|
214 | - while ($myrow = $this->db->fetchArray($result)) { |
|
215 | - $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $retArray = [$parentid]; |
|
220 | - while ($parentid != 0) { |
|
221 | - $parentid = $this->allCategoriesId[$parentid]; |
|
222 | - if ($parentid != 0) { |
|
223 | - $retArray[] = $parentid; |
|
224 | - } |
|
225 | - } |
|
226 | - if ($asString) { |
|
227 | - return implode(', ', $retArray); |
|
228 | - } else { |
|
229 | - return $retArray; |
|
230 | - } |
|
231 | - } |
|
145 | + public $allCategoriesObj = false; |
|
146 | + public $_allCategoriesId = false; |
|
147 | + |
|
148 | + /** |
|
149 | + * SmartobjectCategoryHandler constructor. |
|
150 | + * @param XoopsDatabase $db |
|
151 | + * @param $modulename |
|
152 | + */ |
|
153 | + public function __construct(XoopsDatabase $db, $modulename) |
|
154 | + { |
|
155 | + parent::__construct($db, 'category', 'categoryid', 'name', 'description', $modulename); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param int $parentid |
|
160 | + * @param bool $perm_name |
|
161 | + * @param string $sort |
|
162 | + * @param string $order |
|
163 | + * @return array|bool |
|
164 | + */ |
|
165 | + public function getAllCategoriesArray($parentid = 0, $perm_name = false, $sort = 'parentid', $order = 'ASC') |
|
166 | + { |
|
167 | + if (!$this->allCategoriesObj) { |
|
168 | + $criteria = new CriteriaCompo(); |
|
169 | + $criteria->setSort($sort); |
|
170 | + $criteria->setOrder($order); |
|
171 | + global $xoopsUser; |
|
172 | + $userIsAdmin = is_object($xoopsUser) && $xoopsUser->isAdmin(); |
|
173 | + |
|
174 | + if ($perm_name && !$userIsAdmin) { |
|
175 | + if (!$this->setGrantedObjectsCriteria($criteria, $perm_name)) { |
|
176 | + return false; |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + $this->allCategoriesObj = $this->getObjects($criteria, 'parentid'); |
|
181 | + } |
|
182 | + |
|
183 | + $ret = []; |
|
184 | + if (isset($this->allCategoriesObj[$parentid])) { |
|
185 | + foreach ($this->allCategoriesObj[$parentid] as $categoryid => $categoryObj) { |
|
186 | + $ret[$categoryid]['self'] = $categoryObj->toArray(); |
|
187 | + if (isset($this->allCategoriesObj[$categoryid])) { |
|
188 | + $ret[$categoryid]['sub'] = $this->getAllCategoriesArray($categoryid); |
|
189 | + $ret[$categoryid]['subcatscount'] = count($ret[$categoryid]['sub']); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $ret; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $parentid |
|
199 | + * @param bool $asString |
|
200 | + * @return array|string |
|
201 | + */ |
|
202 | + public function getParentIds($parentid, $asString = true) |
|
203 | + { |
|
204 | + if (!$this->allCategoriesId) { |
|
205 | + $ret = []; |
|
206 | + $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
207 | + |
|
208 | + $result = $this->db->query($sql); |
|
209 | + |
|
210 | + if (!$result) { |
|
211 | + return $ret; |
|
212 | + } |
|
213 | + |
|
214 | + while ($myrow = $this->db->fetchArray($result)) { |
|
215 | + $this->allCategoriesId[$myrow['categoryid']] = $myrow['parentid']; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $retArray = [$parentid]; |
|
220 | + while ($parentid != 0) { |
|
221 | + $parentid = $this->allCategoriesId[$parentid]; |
|
222 | + if ($parentid != 0) { |
|
223 | + $retArray[] = $parentid; |
|
224 | + } |
|
225 | + } |
|
226 | + if ($asString) { |
|
227 | + return implode(', ', $retArray); |
|
228 | + } else { |
|
229 | + return $retArray; |
|
230 | + } |
|
231 | + } |
|
232 | 232 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
14 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartseoobject.php'; |
|
14 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartseoobject.php'; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * Class SmartobjectCategory |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | global $myts; |
96 | 96 | $objectArray = parent::toArray(); |
97 | 97 | if ($objectArray['image']) { |
98 | - $objectArray['image'] = $this->getImageDir() . $objectArray['image']; |
|
98 | + $objectArray['image'] = $this->getImageDir().$objectArray['image']; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return $objectArray; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function getCategoryPath($withAllLink = true, $currentCategory = false) |
113 | 113 | { |
114 | - require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
|
114 | + require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php'; |
|
115 | 115 | $controller = new SmartObjectController($this->handler); |
116 | 116 | |
117 | 117 | if (!$this->_categoryPath) { |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | exit; |
129 | 129 | } |
130 | 130 | $parentid = $parentObj->getVar('parentid'); |
131 | - $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory) . ' > ' . $ret; |
|
131 | + $ret = $parentObj->getCategoryPath($withAllLink, $currentCategory).' > '.$ret; |
|
132 | 132 | } |
133 | 133 | $this->_categoryPath = $ret; |
134 | 134 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | { |
204 | 204 | if (!$this->allCategoriesId) { |
205 | 205 | $ret = []; |
206 | - $sql = 'SELECT categoryid, parentid FROM ' . $this->table . ' AS ' . $this->_itemname . ' ORDER BY parentid'; |
|
206 | + $sql = 'SELECT categoryid, parentid FROM '.$this->table.' AS '.$this->_itemname.' ORDER BY parentid'; |
|
207 | 207 | |
208 | 208 | $result = $this->db->query($sql); |
209 | 209 |
@@ -24,82 +24,82 @@ discard block |
||
24 | 24 | */ |
25 | 25 | class SmartMlObject extends SmartObject |
26 | 26 | { |
27 | - /** |
|
28 | - * SmartMlObject constructor. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
33 | - $this->setControl('language', 'language'); |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * If object is not new, change the control of the not-multilanguage fields |
|
38 | - * |
|
39 | - * We need to intercept this function from SmartObject because if the object is not new... |
|
40 | - */ |
|
41 | - // function getForm() { |
|
42 | - |
|
43 | - //} |
|
44 | - |
|
45 | - /** |
|
46 | - * Strip Multilanguage Fields |
|
47 | - * |
|
48 | - * Get rid of all the multilanguage fields to have an object with only global fields. |
|
49 | - * This will be usefull when creating the ML object for the first time. Then we will be able |
|
50 | - * to create translations. |
|
51 | - */ |
|
52 | - public function stripMultilanguageFields() |
|
53 | - { |
|
54 | - $objectVars =& $this->getVars(); |
|
55 | - $newObjectVars = []; |
|
56 | - foreach ($objectVars as $key => $var) { |
|
57 | - if (!$var['multilingual']) { |
|
58 | - $newObjectVars[$key] = $var; |
|
59 | - } |
|
60 | - } |
|
61 | - $this->vars = $newObjectVars; |
|
62 | - } |
|
63 | - |
|
64 | - public function stripNonMultilanguageFields() |
|
65 | - { |
|
66 | - $objectVars =& $this->getVars(); |
|
67 | - $newObjectVars = []; |
|
68 | - foreach ($objectVars as $key => $var) { |
|
69 | - if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
70 | - $newObjectVars[$key] = $var; |
|
71 | - } |
|
72 | - } |
|
73 | - $this->vars = $newObjectVars; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Make non multilanguage fields read only |
|
78 | - * |
|
79 | - * This is used when we are creating/editing a translation. |
|
80 | - * We only want to edit the multilanguag fields, not the global one. |
|
81 | - */ |
|
82 | - public function makeNonMLFieldReadOnly() |
|
83 | - { |
|
84 | - foreach ($this->getVars() as $key => $var) { |
|
85 | - //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
86 | - if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
87 | - $this->setControl($key, 'label'); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param bool $onlyUrl |
|
94 | - * @param bool $withimage |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
98 | - { |
|
99 | - $controller = new SmartObjectController($this->handler); |
|
100 | - |
|
101 | - return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
102 | - } |
|
27 | + /** |
|
28 | + * SmartMlObject constructor. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->initVar('language', XOBJ_DTYPE_TXTBOX, 'english', false, null, '', true, _CO_SOBJECT_LANGUAGE_CAPTION, _CO_SOBJECT_LANGUAGE_DSC, true, true); |
|
33 | + $this->setControl('language', 'language'); |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * If object is not new, change the control of the not-multilanguage fields |
|
38 | + * |
|
39 | + * We need to intercept this function from SmartObject because if the object is not new... |
|
40 | + */ |
|
41 | + // function getForm() { |
|
42 | + |
|
43 | + //} |
|
44 | + |
|
45 | + /** |
|
46 | + * Strip Multilanguage Fields |
|
47 | + * |
|
48 | + * Get rid of all the multilanguage fields to have an object with only global fields. |
|
49 | + * This will be usefull when creating the ML object for the first time. Then we will be able |
|
50 | + * to create translations. |
|
51 | + */ |
|
52 | + public function stripMultilanguageFields() |
|
53 | + { |
|
54 | + $objectVars =& $this->getVars(); |
|
55 | + $newObjectVars = []; |
|
56 | + foreach ($objectVars as $key => $var) { |
|
57 | + if (!$var['multilingual']) { |
|
58 | + $newObjectVars[$key] = $var; |
|
59 | + } |
|
60 | + } |
|
61 | + $this->vars = $newObjectVars; |
|
62 | + } |
|
63 | + |
|
64 | + public function stripNonMultilanguageFields() |
|
65 | + { |
|
66 | + $objectVars =& $this->getVars(); |
|
67 | + $newObjectVars = []; |
|
68 | + foreach ($objectVars as $key => $var) { |
|
69 | + if ($var['multilingual'] || $key == $this->handler->keyName) { |
|
70 | + $newObjectVars[$key] = $var; |
|
71 | + } |
|
72 | + } |
|
73 | + $this->vars = $newObjectVars; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Make non multilanguage fields read only |
|
78 | + * |
|
79 | + * This is used when we are creating/editing a translation. |
|
80 | + * We only want to edit the multilanguag fields, not the global one. |
|
81 | + */ |
|
82 | + public function makeNonMLFieldReadOnly() |
|
83 | + { |
|
84 | + foreach ($this->getVars() as $key => $var) { |
|
85 | + //if (($key == 'language') || (!$var['multilingual'] && $key <> $this->handler->keyName)) { |
|
86 | + if (!$var['multilingual'] && $key != $this->handler->keyName) { |
|
87 | + $this->setControl($key, 'label'); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param bool $onlyUrl |
|
94 | + * @param bool $withimage |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function getEditLanguageLink($onlyUrl = false, $withimage = true) |
|
98 | + { |
|
99 | + $controller = new SmartObjectController($this->handler); |
|
100 | + |
|
101 | + return $controller->getEditLanguageLink($this, $onlyUrl, $withimage); |
|
102 | + } |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -107,60 +107,60 @@ discard block |
||
107 | 107 | */ |
108 | 108 | class SmartPersistableMlObjectHandler extends SmartPersistableObjectHandler |
109 | 109 | { |
110 | - /** |
|
111 | - * @param null $criteria |
|
112 | - * @param bool $id_as_key |
|
113 | - * @param bool $as_object |
|
114 | - * @param bool $debug |
|
115 | - * @param bool $language |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - public function getObjects( |
|
119 | - $criteria = null, |
|
120 | - $id_as_key = false, |
|
121 | - $as_object = true, |
|
122 | - $debug = false, |
|
123 | - $language = false |
|
124 | - ) { |
|
125 | - // Create the first part of the SQL query to join the "_text" table |
|
126 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
127 | - |
|
128 | - if ($language) { |
|
129 | - // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
130 | - |
|
131 | - // if no criteria was previously created, let's create it |
|
132 | - if (!$criteria) { |
|
133 | - $criteria = new CriteriaCompo(); |
|
134 | - } |
|
135 | - $criteria->add(new Criteria('language', $language)); |
|
136 | - |
|
137 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
138 | - } |
|
139 | - |
|
140 | - return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param mixed $id |
|
145 | - * @param bool $language |
|
146 | - * @param bool $as_object |
|
147 | - * @param bool $debug |
|
148 | - * @return mixed |
|
149 | - */ |
|
150 | - public function &get($id, $language = false, $as_object = true, $debug = false) |
|
151 | - { |
|
152 | - if (!$language) { |
|
153 | - return parent::get($id, $as_object, $debug); |
|
154 | - } else { |
|
155 | - $criteria = new CriteriaCompo(); |
|
156 | - $criteria->add(new Criteria('language', $language)); |
|
157 | - |
|
158 | - return parent::get($id, $as_object, $debug, $criteria); |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - public function changeTableNameForML() |
|
163 | - { |
|
164 | - $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
165 | - } |
|
110 | + /** |
|
111 | + * @param null $criteria |
|
112 | + * @param bool $id_as_key |
|
113 | + * @param bool $as_object |
|
114 | + * @param bool $debug |
|
115 | + * @param bool $language |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + public function getObjects( |
|
119 | + $criteria = null, |
|
120 | + $id_as_key = false, |
|
121 | + $as_object = true, |
|
122 | + $debug = false, |
|
123 | + $language = false |
|
124 | + ) { |
|
125 | + // Create the first part of the SQL query to join the "_text" table |
|
126 | + $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
127 | + |
|
128 | + if ($language) { |
|
129 | + // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
|
130 | + |
|
131 | + // if no criteria was previously created, let's create it |
|
132 | + if (!$criteria) { |
|
133 | + $criteria = new CriteriaCompo(); |
|
134 | + } |
|
135 | + $criteria->add(new Criteria('language', $language)); |
|
136 | + |
|
137 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
138 | + } |
|
139 | + |
|
140 | + return parent::getObjects($criteria, $id_as_key, $as_object, $debug, $sql); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param mixed $id |
|
145 | + * @param bool $language |
|
146 | + * @param bool $as_object |
|
147 | + * @param bool $debug |
|
148 | + * @return mixed |
|
149 | + */ |
|
150 | + public function &get($id, $language = false, $as_object = true, $debug = false) |
|
151 | + { |
|
152 | + if (!$language) { |
|
153 | + return parent::get($id, $as_object, $debug); |
|
154 | + } else { |
|
155 | + $criteria = new CriteriaCompo(); |
|
156 | + $criteria->add(new Criteria('language', $language)); |
|
157 | + |
|
158 | + return parent::get($id, $as_object, $debug, $criteria); |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + public function changeTableNameForML() |
|
163 | + { |
|
164 | + $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
165 | + } |
|
166 | 166 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // defined('XOOPS_ROOT_PATH') || exit('Restricted access.'); |
14 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php'; |
|
14 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/class/smartobject.php'; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * SmartObject base Multilanguage-enabled class |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function stripMultilanguageFields() |
53 | 53 | { |
54 | - $objectVars =& $this->getVars(); |
|
54 | + $objectVars = & $this->getVars(); |
|
55 | 55 | $newObjectVars = []; |
56 | 56 | foreach ($objectVars as $key => $var) { |
57 | 57 | if (!$var['multilingual']) { |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function stripNonMultilanguageFields() |
65 | 65 | { |
66 | - $objectVars =& $this->getVars(); |
|
66 | + $objectVars = & $this->getVars(); |
|
67 | 67 | $newObjectVars = []; |
68 | 68 | foreach ($objectVars as $key => $var) { |
69 | 69 | if ($var['multilingual'] || $key == $this->handler->keyName) { |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $language = false |
124 | 124 | ) { |
125 | 125 | // Create the first part of the SQL query to join the "_text" table |
126 | - $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->table . '_text AS ' . $this->_itemname . '_text ON ' . $this->_itemname . '.' . $this->keyName . '=' . $this->_itemname . '_text.' . $this->keyName; |
|
126 | + $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname.' INNER JOIN '.$this->table.'_text AS '.$this->_itemname.'_text ON '.$this->_itemname.'.'.$this->keyName.'='.$this->_itemname.'_text.'.$this->keyName; |
|
127 | 127 | |
128 | 128 | if ($language) { |
129 | 129 | // If a language was specified, then let's create a WHERE clause to only return the objects associated with this language |
@@ -161,6 +161,6 @@ discard block |
||
161 | 161 | |
162 | 162 | public function changeTableNameForML() |
163 | 163 | { |
164 | - $this->table = $this->db->prefix($this->_moduleName . '_' . $this->_itemname . '_text'); |
|
164 | + $this->table = $this->db->prefix($this->_moduleName.'_'.$this->_itemname.'_text'); |
|
165 | 165 | } |
166 | 166 | } |