@@ -492,7 +492,7 @@ |
||
492 | 492 | * handling applied. If the $mode and $options parameters are not |
493 | 493 | * specified, the object's defaults are used. |
494 | 494 | * |
495 | - * @param mixed $message a text error message or a PEAR error object |
|
495 | + * @param string|null $message a text error message or a PEAR error object |
|
496 | 496 | * |
497 | 497 | * @param int $code a numeric error code (it is up to your class |
498 | 498 | * to define these if you want to use codes) |
@@ -40,25 +40,25 @@ discard block |
||
40 | 40 | define('references_PEAR_ERROR_EXCEPTION', 32); |
41 | 41 | /**#@-*/ |
42 | 42 | define('references_PEAR_ZE2', function_exists('version_compare') |
43 | - && version_compare(zend_version(), '2-dev', 'ge')); |
|
43 | + && version_compare(zend_version(), '2-dev', 'ge')); |
|
44 | 44 | |
45 | 45 | if (substr(PHP_OS, 0, 3) == 'WIN') { |
46 | - define('references_OS_WINDOWS', true); |
|
47 | - define('references_OS_UNIX', false); |
|
48 | - define('references_PEAR_OS', 'Windows'); |
|
46 | + define('references_OS_WINDOWS', true); |
|
47 | + define('references_OS_UNIX', false); |
|
48 | + define('references_PEAR_OS', 'Windows'); |
|
49 | 49 | } else { |
50 | - define('references_OS_WINDOWS', false); |
|
51 | - define('references_OS_UNIX', true); |
|
52 | - define('references_PEAR_OS', 'Unix'); // blatant assumption |
|
50 | + define('references_OS_WINDOWS', false); |
|
51 | + define('references_OS_UNIX', true); |
|
52 | + define('references_PEAR_OS', 'Unix'); // blatant assumption |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // instant backwards compatibility |
56 | 56 | if (!defined('PATH_SEPARATOR')) { |
57 | - if (references_OS_WINDOWS) { |
|
58 | - define('PATH_SEPARATOR', ';'); |
|
59 | - } else { |
|
60 | - define('PATH_SEPARATOR', ':'); |
|
61 | - } |
|
57 | + if (references_OS_WINDOWS) { |
|
58 | + define('PATH_SEPARATOR', ';'); |
|
59 | + } else { |
|
60 | + define('PATH_SEPARATOR', ':'); |
|
61 | + } |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $GLOBALS['_PEAR_default_error_mode'] = references_PEAR_ERROR_RETURN; |
@@ -101,712 +101,712 @@ discard block |
||
101 | 101 | */ |
102 | 102 | class references_PEAR |
103 | 103 | { |
104 | - // {{{ properties |
|
105 | - |
|
106 | - /** |
|
107 | - * Whether to enable internal debug messages. |
|
108 | - * |
|
109 | - * @var bool |
|
110 | - * @access private |
|
111 | - */ |
|
112 | - public $_debug = false; |
|
113 | - |
|
114 | - /** |
|
115 | - * Default error mode for this object. |
|
116 | - * |
|
117 | - * @var int |
|
118 | - * @access private |
|
119 | - */ |
|
120 | - public $_default_error_mode = null; |
|
121 | - |
|
122 | - /** |
|
123 | - * Default error options used for this object when error mode |
|
124 | - * is references_PEAR_ERROR_TRIGGER. |
|
125 | - * |
|
126 | - * @var int |
|
127 | - * @access private |
|
128 | - */ |
|
129 | - public $_default_error_options = null; |
|
130 | - |
|
131 | - /** |
|
132 | - * Default error handler (callback) for this object, if error mode is |
|
133 | - * references_PEAR_ERROR_CALLBACK. |
|
134 | - * |
|
135 | - * @var string |
|
136 | - * @access private |
|
137 | - */ |
|
138 | - public $_default_error_handler = ''; |
|
139 | - |
|
140 | - /** |
|
141 | - * Which class to use for error objects. |
|
142 | - * |
|
143 | - * @var string |
|
144 | - * @access private |
|
145 | - */ |
|
146 | - public $_error_class = 'PEAR_Error'; |
|
147 | - |
|
148 | - /** |
|
149 | - * An array of expected errors. |
|
150 | - * |
|
151 | - * @var array |
|
152 | - * @access private |
|
153 | - */ |
|
154 | - public $_expected_errors = array(); |
|
155 | - |
|
156 | - // }}} |
|
157 | - |
|
158 | - // {{{ constructor |
|
159 | - |
|
160 | - /** |
|
161 | - * Constructor. Registers this object in |
|
162 | - * $_PEAR_destructor_object_list for destructor emulation if a |
|
163 | - * destructor object exists. |
|
164 | - * |
|
165 | - * @param string $error_class (optional) which class to use for |
|
166 | - * error objects, defaults to PEAR_Error. |
|
167 | - * @access public |
|
168 | - */ |
|
169 | - public function __construct($error_class = null) |
|
170 | - { |
|
171 | - $classname = strtolower(get_class($this)); |
|
172 | - if ($this->_debug) { |
|
173 | - print "PEAR constructor called, class=$classname\n"; |
|
174 | - } |
|
175 | - if ($error_class !== null) { |
|
176 | - $this->_error_class = $error_class; |
|
177 | - } |
|
178 | - while ($classname && strcasecmp($classname, 'pear')) { |
|
179 | - $destructor = "_$classname"; |
|
180 | - if (method_exists($this, $destructor)) { |
|
181 | - global $_PEAR_destructor_object_list; |
|
182 | - $_PEAR_destructor_object_list[] = &$this; |
|
183 | - if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { |
|
184 | - register_shutdown_function('references_PEAR_call_destructors'); |
|
185 | - $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; |
|
186 | - } |
|
187 | - break; |
|
188 | - } else { |
|
189 | - $classname = get_parent_class($classname); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - // }}} |
|
195 | - // {{{ destructor |
|
196 | - |
|
197 | - /** |
|
198 | - * Destructor (the emulated type of...). Does nothing right now, |
|
199 | - * but is included for forward compatibility, so subclass |
|
200 | - * destructors should always call it. |
|
201 | - * |
|
202 | - * See the note in the class desciption about output from |
|
203 | - * destructors. |
|
204 | - * |
|
205 | - * @access public |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - public function _PEAR() |
|
209 | - { |
|
210 | - if ($this->_debug) { |
|
211 | - printf("PEAR destructor called, class=%s\n", strtolower(get_class($this))); |
|
212 | - } |
|
213 | - } |
|
214 | - |
|
215 | - // }}} |
|
216 | - // {{{ getStaticProperty() |
|
217 | - |
|
218 | - /** |
|
219 | - * If you have a class that's mostly/entirely static, and you need static |
|
220 | - * properties, you can use this method to simulate them. Eg. in your method(s) |
|
221 | - * do this: $myVar = &references_PEAR::getStaticProperty('myclass', 'myVar'); |
|
222 | - * You MUST use a reference, or they will not persist! |
|
223 | - * |
|
224 | - * @access public |
|
225 | - * @param string $class The calling classname, to prevent clashes |
|
226 | - * @param string $var The variable to retrieve. |
|
227 | - * @return mixed A reference to the variable. If not set it will be |
|
228 | - * auto initialised to NULL. |
|
229 | - */ |
|
230 | - public function &getStaticProperty($class, $var) |
|
231 | - { |
|
232 | - static $properties; |
|
233 | - if (!isset($properties[$class])) { |
|
234 | - $properties[$class] = array(); |
|
235 | - } |
|
236 | - if (!array_key_exists($var, $properties[$class])) { |
|
237 | - $properties[$class][$var] = null; |
|
238 | - } |
|
239 | - |
|
240 | - return $properties[$class][$var]; |
|
241 | - } |
|
242 | - |
|
243 | - // }}} |
|
244 | - // {{{ registerShutdownFunc() |
|
245 | - |
|
246 | - /** |
|
247 | - * Use this function to register a shutdown method for static |
|
248 | - * classes. |
|
249 | - * |
|
250 | - * @access public |
|
251 | - * @param mixed $func The function name (or array of class/method) to call |
|
252 | - * @param mixed $args The arguments to pass to the function |
|
253 | - * @return void |
|
254 | - */ |
|
255 | - public function registerShutdownFunc($func, $args = array()) |
|
256 | - { |
|
257 | - // if we are called statically, there is a potential |
|
258 | - // that no shutdown func is registered. Bug #6445 |
|
259 | - if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { |
|
260 | - register_shutdown_function('references__PEAR_call_destructors'); |
|
261 | - $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; |
|
262 | - } |
|
263 | - $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); |
|
264 | - } |
|
265 | - |
|
266 | - // }}} |
|
267 | - // {{{ isError() |
|
268 | - |
|
269 | - /** |
|
270 | - * Tell whether a value is a PEAR error. |
|
271 | - * |
|
272 | - * @param mixed $data the value to test |
|
273 | - * @param int $code if $data is an error object, return true |
|
274 | - * only if $code is a string and |
|
275 | - * $obj->getMessage() == $code or |
|
276 | - * $code is an integer and $obj->getCode() == $code |
|
277 | - * @access public |
|
278 | - * @return bool true if parameter is an error |
|
279 | - */ |
|
280 | - public function isError($data, $code = null) |
|
281 | - { |
|
282 | - if (is_a($data, 'PEAR_Error')) { |
|
283 | - if (is_null($code)) { |
|
284 | - return true; |
|
285 | - } elseif (is_string($code)) { |
|
286 | - return $data->getMessage() == $code; |
|
287 | - } else { |
|
288 | - return $data->getCode() == $code; |
|
289 | - } |
|
290 | - } |
|
291 | - |
|
292 | - return false; |
|
293 | - } |
|
294 | - |
|
295 | - // }}} |
|
296 | - // {{{ setErrorHandling() |
|
297 | - |
|
298 | - /** |
|
299 | - * Sets how errors generated by this object should be handled. |
|
300 | - * Can be invoked both in objects and statically. If called |
|
301 | - * statically, setErrorHandling sets the default behaviour for all |
|
302 | - * PEAR objects. If called in an object, setErrorHandling sets |
|
303 | - * the default behaviour for that object. |
|
304 | - * |
|
305 | - * @param int $mode |
|
306 | - * One of references_PEAR_ERROR_RETURN, references_PEAR_ERROR_PRINT, |
|
307 | - * references_PEAR_ERROR_TRIGGER, references_PEAR_ERROR_DIE, |
|
308 | - * references_PEAR_ERROR_CALLBACK or references_PEAR_ERROR_EXCEPTION. |
|
309 | - * |
|
310 | - * @param mixed $options |
|
311 | - * When $mode is references_PEAR_ERROR_TRIGGER, this is the error level (one |
|
312 | - * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
|
313 | - * |
|
314 | - * When $mode is references_PEAR_ERROR_CALLBACK, this parameter is expected |
|
315 | - * to be the callback function or method. A callback |
|
316 | - * function is a string with the name of the function, a |
|
317 | - * callback method is an array of two elements: the element |
|
318 | - * at index 0 is the object, and the element at index 1 is |
|
319 | - * the name of the method to call in the object. |
|
320 | - * |
|
321 | - * When $mode is references_PEAR_ERROR_PRINT or references_PEAR_ERROR_DIE, this is |
|
322 | - * a printf format string used when printing the error |
|
323 | - * message. |
|
324 | - * |
|
325 | - * @access public |
|
326 | - * @return void |
|
327 | - * @see references_PEAR_ERROR_RETURN |
|
328 | - * @see references_PEAR_ERROR_PRINT |
|
329 | - * @see references_PEAR_ERROR_TRIGGER |
|
330 | - * @see references_PEAR_ERROR_DIE |
|
331 | - * @see references_PEAR_ERROR_CALLBACK |
|
332 | - * @see references_PEAR_ERROR_EXCEPTION |
|
333 | - * |
|
334 | - */ |
|
335 | - |
|
336 | - public function setErrorHandling($mode = null, $options = null) |
|
337 | - { |
|
338 | - if (isset($this) && is_a($this, 'PEAR')) { |
|
339 | - $setmode = &$this->_default_error_mode; |
|
340 | - $setoptions = &$this->_default_error_options; |
|
341 | - } else { |
|
342 | - $setmode = &$GLOBALS['_PEAR_default_error_mode']; |
|
343 | - $setoptions = &$GLOBALS['_PEAR_default_error_options']; |
|
344 | - } |
|
345 | - |
|
346 | - switch ($mode) { |
|
347 | - case references_PEAR_ERROR_EXCEPTION: |
|
348 | - case references_PEAR_ERROR_RETURN: |
|
349 | - case references_PEAR_ERROR_PRINT: |
|
350 | - case references_PEAR_ERROR_TRIGGER: |
|
351 | - case references_PEAR_ERROR_DIE: |
|
352 | - case null: |
|
353 | - $setmode = $mode; |
|
354 | - $setoptions = $options; |
|
355 | - break; |
|
356 | - |
|
357 | - case references_PEAR_ERROR_CALLBACK: |
|
358 | - $setmode = $mode; |
|
359 | - // class/object method callback |
|
360 | - if (is_callable($options)) { |
|
361 | - $setoptions = $options; |
|
362 | - } else { |
|
363 | - trigger_error('invalid error callback', E_USER_WARNING); |
|
364 | - } |
|
365 | - break; |
|
366 | - |
|
367 | - default: |
|
368 | - trigger_error('invalid error mode', E_USER_WARNING); |
|
369 | - break; |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - // }}} |
|
374 | - // {{{ expectError() |
|
375 | - |
|
376 | - /** |
|
377 | - * This method is used to tell which errors you expect to get. |
|
378 | - * Expected errors are always returned with error mode |
|
379 | - * references_PEAR_ERROR_RETURN. Expected error codes are stored in a stack, |
|
380 | - * and this method pushes a new element onto it. The list of |
|
381 | - * expected errors are in effect until they are popped off the |
|
382 | - * stack with the popExpect() method. |
|
383 | - * |
|
384 | - * Note that this method can not be called statically |
|
385 | - * |
|
386 | - * @param mixed $code a single error code or an array of error codes to expect |
|
387 | - * |
|
388 | - * @return int the new depth of the "expected errors" stack |
|
389 | - * @access public |
|
390 | - */ |
|
391 | - public function expectError($code = '*') |
|
392 | - { |
|
393 | - if (is_array($code)) { |
|
394 | - array_push($this->_expected_errors, $code); |
|
395 | - } else { |
|
396 | - array_push($this->_expected_errors, array($code)); |
|
397 | - } |
|
398 | - |
|
399 | - return count($this->_expected_errors); |
|
400 | - } |
|
401 | - |
|
402 | - // }}} |
|
403 | - // {{{ popExpect() |
|
404 | - |
|
405 | - /** |
|
406 | - * This method pops one element off the expected error codes |
|
407 | - * stack. |
|
408 | - * |
|
409 | - * @return array the list of error codes that were popped |
|
410 | - */ |
|
411 | - public function popExpect() |
|
412 | - { |
|
413 | - return array_pop($this->_expected_errors); |
|
414 | - } |
|
415 | - |
|
416 | - // }}} |
|
417 | - // {{{ _checkDelExpect() |
|
418 | - |
|
419 | - /** |
|
420 | - * This method checks unsets an error code if available |
|
421 | - * |
|
422 | - * @param mixed error code |
|
423 | - * @return bool true if the error code was unset, false otherwise |
|
424 | - * @access private |
|
425 | - */ |
|
426 | - public function _checkDelExpect($error_code) |
|
427 | - { |
|
428 | - $deleted = false; |
|
429 | - |
|
430 | - foreach ($this->_expected_errors as $key => $error_array) { |
|
431 | - if (in_array($error_code, $error_array)) { |
|
432 | - unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); |
|
433 | - $deleted = true; |
|
434 | - } |
|
435 | - |
|
436 | - // clean up empty arrays |
|
437 | - if (0 == count($this->_expected_errors[$key])) { |
|
438 | - unset($this->_expected_errors[$key]); |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - return $deleted; |
|
443 | - } |
|
444 | - |
|
445 | - // }}} |
|
446 | - // {{{ delExpect() |
|
447 | - |
|
448 | - /** |
|
449 | - * This method deletes all occurences of the specified element from |
|
450 | - * the expected error codes stack. |
|
451 | - * |
|
452 | - * @param mixed $error_code error code that should be deleted |
|
453 | - * @return mixed list of error codes that were deleted or error |
|
454 | - * @access public |
|
455 | - */ |
|
456 | - public function delExpect($error_code) |
|
457 | - { |
|
458 | - $deleted = false; |
|
459 | - |
|
460 | - if (is_array($error_code) && (0 != count($error_code))) { |
|
461 | - // $error_code is a non-empty array here; |
|
462 | - // we walk through it trying to unset all |
|
463 | - // values |
|
464 | - foreach ($error_code as $key => $error) { |
|
465 | - if ($this->_checkDelExpect($error)) { |
|
466 | - $deleted = true; |
|
467 | - } else { |
|
468 | - $deleted = false; |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - return $deleted ? true : references_PEAR::raiseError('The expected error you submitted does not exist'); // IMPROVE ME |
|
473 | - } elseif (!empty($error_code)) { |
|
474 | - // $error_code comes alone, trying to unset it |
|
475 | - if ($this->_checkDelExpect($error_code)) { |
|
476 | - return true; |
|
477 | - } else { |
|
478 | - return references_PEAR::raiseError('The expected error you submitted does not exist'); // IMPROVE ME |
|
479 | - } |
|
480 | - } else { |
|
481 | - // $error_code is empty |
|
482 | - return references_PEAR::raiseError('The expected error you submitted is empty'); // IMPROVE ME |
|
483 | - } |
|
484 | - } |
|
485 | - |
|
486 | - // }}} |
|
487 | - // {{{ raiseError() |
|
488 | - |
|
489 | - /** |
|
490 | - * This method is a wrapper that returns an instance of the |
|
491 | - * configured error class with this object's default error |
|
492 | - * handling applied. If the $mode and $options parameters are not |
|
493 | - * specified, the object's defaults are used. |
|
494 | - * |
|
495 | - * @param mixed $message a text error message or a PEAR error object |
|
496 | - * |
|
497 | - * @param int $code a numeric error code (it is up to your class |
|
498 | - * to define these if you want to use codes) |
|
499 | - * |
|
500 | - * @param int $mode One of references_PEAR_ERROR_RETURN, references_PEAR_ERROR_PRINT, |
|
501 | - * references_PEAR_ERROR_TRIGGER, references_PEAR_ERROR_DIE, |
|
502 | - * references_PEAR_ERROR_CALLBACK, references_PEAR_ERROR_EXCEPTION. |
|
503 | - * |
|
504 | - * @param mixed $options If $mode is references_PEAR_ERROR_TRIGGER, this parameter |
|
505 | - * specifies the PHP-internal error level (one of |
|
506 | - * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
|
507 | - * If $mode is references_PEAR_ERROR_CALLBACK, this |
|
508 | - * parameter specifies the callback function or |
|
509 | - * method. In other error modes this parameter |
|
510 | - * is ignored. |
|
511 | - * |
|
512 | - * @param string $userinfo If you need to pass along for example debug |
|
513 | - * information, this parameter is meant for that. |
|
514 | - * |
|
515 | - * @param string $error_class The returned error object will be |
|
516 | - * instantiated from this class, if specified. |
|
517 | - * |
|
518 | - * @param bool $skipmsg If true, raiseError will only pass error codes, |
|
519 | - * the error message parameter will be dropped. |
|
520 | - * |
|
521 | - * @access public |
|
522 | - * @return object a PEAR error object |
|
523 | - * @see references_PEAR::setErrorHandling |
|
524 | - * @since PHP 4.0.5 |
|
525 | - */ |
|
526 | - public function &raiseError($message = null, $code = null, $mode = null, $options = null, $userinfo = null, $error_class = null, $skipmsg = false) |
|
527 | - { |
|
528 | - // The error is yet a PEAR error object |
|
529 | - if (is_object($message)) { |
|
530 | - $code = $message->getCode(); |
|
531 | - $userinfo = $message->getUserInfo(); |
|
532 | - $error_class = $message->getType(); |
|
533 | - $message->error_message_prefix = ''; |
|
534 | - $message = $message->getMessage(); |
|
535 | - } |
|
536 | - |
|
537 | - if (isset($this) && isset($this->_expected_errors) && count($this->_expected_errors) > 0 && count($exp = end($this->_expected_errors))) { |
|
538 | - if ($exp[0] === '*' |
|
539 | - || (is_int(reset($exp)) && in_array($code, $exp)) |
|
540 | - || (is_string(reset($exp)) && in_array($message, $exp)) |
|
541 | - ) { |
|
542 | - $mode = references_PEAR_ERROR_RETURN; |
|
543 | - } |
|
544 | - } |
|
545 | - // No mode given, try global ones |
|
546 | - if ($mode === null) { |
|
547 | - // Class error handler |
|
548 | - if (isset($this) && isset($this->_default_error_mode)) { |
|
549 | - $mode = $this->_default_error_mode; |
|
550 | - $options = $this->_default_error_options; |
|
551 | - // Global error handler |
|
552 | - } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) { |
|
553 | - $mode = $GLOBALS['_PEAR_default_error_mode']; |
|
554 | - $options = $GLOBALS['_PEAR_default_error_options']; |
|
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - if ($error_class !== null) { |
|
559 | - $ec = $error_class; |
|
560 | - } elseif (isset($this) && isset($this->_error_class)) { |
|
561 | - $ec = $this->_error_class; |
|
562 | - } else { |
|
563 | - $ec = 'references_PEAR_Error'; |
|
564 | - } |
|
565 | - if ($skipmsg) { |
|
566 | - $a = new $ec($code, $mode, $options, $userinfo); |
|
567 | - |
|
568 | - return $a; |
|
569 | - } else { |
|
570 | - $a = new $ec($message, $code, $mode, $options, $userinfo); |
|
571 | - |
|
572 | - return $a; |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - // }}} |
|
577 | - // {{{ throwError() |
|
578 | - |
|
579 | - /** |
|
580 | - * Simpler form of raiseError with fewer options. In most cases |
|
581 | - * message, code and userinfo are enough. |
|
582 | - * |
|
583 | - * @param string $message |
|
584 | - * |
|
585 | - * @param null $code |
|
586 | - * @param null $userinfo |
|
587 | - * @return object |
|
588 | - */ |
|
589 | - public function &throwError($message = null, $code = null, $userinfo = null) |
|
590 | - { |
|
591 | - if (isset($this) && is_a($this, 'PEAR')) { |
|
592 | - $a = &$this->raiseError($message, $code, null, null, $userinfo); |
|
593 | - |
|
594 | - return $a; |
|
595 | - } else { |
|
596 | - $a = &references_PEAR::raiseError($message, $code, null, null, $userinfo); |
|
597 | - |
|
598 | - return $a; |
|
599 | - } |
|
600 | - } |
|
601 | - |
|
602 | - // }}} |
|
603 | - public function staticPushErrorHandling($mode, $options = null) |
|
604 | - { |
|
605 | - $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
606 | - $def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
|
607 | - $def_options = &$GLOBALS['_PEAR_default_error_options']; |
|
608 | - $stack[] = array($def_mode, $def_options); |
|
609 | - switch ($mode) { |
|
610 | - case references_PEAR_ERROR_EXCEPTION: |
|
611 | - case references_PEAR_ERROR_RETURN: |
|
612 | - case references_PEAR_ERROR_PRINT: |
|
613 | - case references_PEAR_ERROR_TRIGGER: |
|
614 | - case references_PEAR_ERROR_DIE: |
|
615 | - case null: |
|
616 | - $def_mode = $mode; |
|
617 | - $def_options = $options; |
|
618 | - break; |
|
619 | - |
|
620 | - case references_PEAR_ERROR_CALLBACK: |
|
621 | - $def_mode = $mode; |
|
622 | - // class/object method callback |
|
623 | - if (is_callable($options)) { |
|
624 | - $def_options = $options; |
|
625 | - } else { |
|
626 | - trigger_error('invalid error callback', E_USER_WARNING); |
|
627 | - } |
|
628 | - break; |
|
629 | - |
|
630 | - default: |
|
631 | - trigger_error('invalid error mode', E_USER_WARNING); |
|
632 | - break; |
|
633 | - } |
|
634 | - $stack[] = array($mode, $options); |
|
635 | - |
|
636 | - return true; |
|
637 | - } |
|
638 | - |
|
639 | - public function staticPopErrorHandling() |
|
640 | - { |
|
641 | - $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
642 | - $setmode = &$GLOBALS['_PEAR_default_error_mode']; |
|
643 | - $setoptions = &$GLOBALS['_PEAR_default_error_options']; |
|
644 | - array_pop($stack); |
|
645 | - list($mode, $options) = $stack[count($stack) - 1]; |
|
646 | - array_pop($stack); |
|
647 | - switch ($mode) { |
|
648 | - case references_PEAR_ERROR_EXCEPTION: |
|
649 | - case references_PEAR_ERROR_RETURN: |
|
650 | - case references_PEAR_ERROR_PRINT: |
|
651 | - case references_PEAR_ERROR_TRIGGER: |
|
652 | - case references_PEAR_ERROR_DIE: |
|
653 | - case null: |
|
654 | - $setmode = $mode; |
|
655 | - $setoptions = $options; |
|
656 | - break; |
|
657 | - |
|
658 | - case references_PEAR_ERROR_CALLBACK: |
|
659 | - $setmode = $mode; |
|
660 | - // class/object method callback |
|
661 | - if (is_callable($options)) { |
|
662 | - $setoptions = $options; |
|
663 | - } else { |
|
664 | - trigger_error('invalid error callback', E_USER_WARNING); |
|
665 | - } |
|
666 | - break; |
|
667 | - |
|
668 | - default: |
|
669 | - trigger_error('invalid error mode', E_USER_WARNING); |
|
670 | - break; |
|
671 | - } |
|
672 | - |
|
673 | - return true; |
|
674 | - } |
|
675 | - |
|
676 | - // {{{ pushErrorHandling() |
|
677 | - |
|
678 | - /** |
|
679 | - * Push a new error handler on top of the error handler options stack. With this |
|
680 | - * you can easily override the actual error handler for some code and restore |
|
681 | - * it later with popErrorHandling. |
|
682 | - * |
|
683 | - * @param mixed $mode (same as setErrorHandling) |
|
684 | - * @param mixed $options (same as setErrorHandling) |
|
685 | - * |
|
686 | - * @return bool Always true |
|
687 | - * |
|
688 | - * @see references_PEAR::setErrorHandling |
|
689 | - */ |
|
690 | - public function pushErrorHandling($mode, $options = null) |
|
691 | - { |
|
692 | - $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
693 | - if (isset($this) && is_a($this, 'PEAR')) { |
|
694 | - $def_mode = &$this->_default_error_mode; |
|
695 | - $def_options = &$this->_default_error_options; |
|
696 | - } else { |
|
697 | - $def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
|
698 | - $def_options = &$GLOBALS['_PEAR_default_error_options']; |
|
699 | - } |
|
700 | - $stack[] = array($def_mode, $def_options); |
|
701 | - |
|
702 | - if (isset($this) && is_a($this, 'PEAR')) { |
|
703 | - $this->setErrorHandling($mode, $options); |
|
704 | - } else { |
|
705 | - references_PEAR::setErrorHandling($mode, $options); |
|
706 | - } |
|
707 | - $stack[] = array($mode, $options); |
|
708 | - |
|
709 | - return true; |
|
710 | - } |
|
711 | - |
|
712 | - // }}} |
|
713 | - // {{{ popErrorHandling() |
|
714 | - |
|
715 | - /** |
|
716 | - * Pop the last error handler used |
|
717 | - * |
|
718 | - * @return bool Always true |
|
719 | - * |
|
720 | - * @see references_PEAR::pushErrorHandling |
|
721 | - */ |
|
722 | - public function popErrorHandling() |
|
723 | - { |
|
724 | - $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
725 | - array_pop($stack); |
|
726 | - list($mode, $options) = $stack[count($stack) - 1]; |
|
727 | - array_pop($stack); |
|
728 | - if (isset($this) && is_a($this, 'PEAR')) { |
|
729 | - $this->setErrorHandling($mode, $options); |
|
730 | - } else { |
|
731 | - references_PEAR::setErrorHandling($mode, $options); |
|
732 | - } |
|
733 | - |
|
734 | - return true; |
|
735 | - } |
|
736 | - |
|
737 | - // }}} |
|
738 | - // {{{ loadExtension() |
|
739 | - |
|
740 | - /** |
|
741 | - * OS independant PHP extension load. Remember to take care |
|
742 | - * on the correct extension name for case sensitive OSes. |
|
743 | - * |
|
744 | - * @param string $ext The extension name |
|
745 | - * @return bool Success or not on the dl() call |
|
746 | - */ |
|
747 | - public function loadExtension($ext) |
|
748 | - { |
|
749 | - if (!extension_loaded($ext)) { |
|
750 | - // if either returns true dl() will produce a FATAL error, stop that |
|
751 | - if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { |
|
752 | - return false; |
|
753 | - } |
|
754 | - if (references_OS_WINDOWS) { |
|
755 | - $suffix = '.dll'; |
|
756 | - } elseif (PHP_OS === 'HP-UX') { |
|
757 | - $suffix = '.sl'; |
|
758 | - } elseif (PHP_OS === 'AIX') { |
|
759 | - $suffix = '.a'; |
|
760 | - } elseif (PHP_OS === 'OSX') { |
|
761 | - $suffix = '.bundle'; |
|
762 | - } else { |
|
763 | - $suffix = '.so'; |
|
764 | - } |
|
765 | - |
|
766 | - return @dl('php_' . $ext . $suffix) || @dl($ext . $suffix); |
|
767 | - } |
|
768 | - |
|
769 | - return true; |
|
770 | - } |
|
771 | - |
|
772 | - // }}} |
|
104 | + // {{{ properties |
|
105 | + |
|
106 | + /** |
|
107 | + * Whether to enable internal debug messages. |
|
108 | + * |
|
109 | + * @var bool |
|
110 | + * @access private |
|
111 | + */ |
|
112 | + public $_debug = false; |
|
113 | + |
|
114 | + /** |
|
115 | + * Default error mode for this object. |
|
116 | + * |
|
117 | + * @var int |
|
118 | + * @access private |
|
119 | + */ |
|
120 | + public $_default_error_mode = null; |
|
121 | + |
|
122 | + /** |
|
123 | + * Default error options used for this object when error mode |
|
124 | + * is references_PEAR_ERROR_TRIGGER. |
|
125 | + * |
|
126 | + * @var int |
|
127 | + * @access private |
|
128 | + */ |
|
129 | + public $_default_error_options = null; |
|
130 | + |
|
131 | + /** |
|
132 | + * Default error handler (callback) for this object, if error mode is |
|
133 | + * references_PEAR_ERROR_CALLBACK. |
|
134 | + * |
|
135 | + * @var string |
|
136 | + * @access private |
|
137 | + */ |
|
138 | + public $_default_error_handler = ''; |
|
139 | + |
|
140 | + /** |
|
141 | + * Which class to use for error objects. |
|
142 | + * |
|
143 | + * @var string |
|
144 | + * @access private |
|
145 | + */ |
|
146 | + public $_error_class = 'PEAR_Error'; |
|
147 | + |
|
148 | + /** |
|
149 | + * An array of expected errors. |
|
150 | + * |
|
151 | + * @var array |
|
152 | + * @access private |
|
153 | + */ |
|
154 | + public $_expected_errors = array(); |
|
155 | + |
|
156 | + // }}} |
|
157 | + |
|
158 | + // {{{ constructor |
|
159 | + |
|
160 | + /** |
|
161 | + * Constructor. Registers this object in |
|
162 | + * $_PEAR_destructor_object_list for destructor emulation if a |
|
163 | + * destructor object exists. |
|
164 | + * |
|
165 | + * @param string $error_class (optional) which class to use for |
|
166 | + * error objects, defaults to PEAR_Error. |
|
167 | + * @access public |
|
168 | + */ |
|
169 | + public function __construct($error_class = null) |
|
170 | + { |
|
171 | + $classname = strtolower(get_class($this)); |
|
172 | + if ($this->_debug) { |
|
173 | + print "PEAR constructor called, class=$classname\n"; |
|
174 | + } |
|
175 | + if ($error_class !== null) { |
|
176 | + $this->_error_class = $error_class; |
|
177 | + } |
|
178 | + while ($classname && strcasecmp($classname, 'pear')) { |
|
179 | + $destructor = "_$classname"; |
|
180 | + if (method_exists($this, $destructor)) { |
|
181 | + global $_PEAR_destructor_object_list; |
|
182 | + $_PEAR_destructor_object_list[] = &$this; |
|
183 | + if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { |
|
184 | + register_shutdown_function('references_PEAR_call_destructors'); |
|
185 | + $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; |
|
186 | + } |
|
187 | + break; |
|
188 | + } else { |
|
189 | + $classname = get_parent_class($classname); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + // }}} |
|
195 | + // {{{ destructor |
|
196 | + |
|
197 | + /** |
|
198 | + * Destructor (the emulated type of...). Does nothing right now, |
|
199 | + * but is included for forward compatibility, so subclass |
|
200 | + * destructors should always call it. |
|
201 | + * |
|
202 | + * See the note in the class desciption about output from |
|
203 | + * destructors. |
|
204 | + * |
|
205 | + * @access public |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + public function _PEAR() |
|
209 | + { |
|
210 | + if ($this->_debug) { |
|
211 | + printf("PEAR destructor called, class=%s\n", strtolower(get_class($this))); |
|
212 | + } |
|
213 | + } |
|
214 | + |
|
215 | + // }}} |
|
216 | + // {{{ getStaticProperty() |
|
217 | + |
|
218 | + /** |
|
219 | + * If you have a class that's mostly/entirely static, and you need static |
|
220 | + * properties, you can use this method to simulate them. Eg. in your method(s) |
|
221 | + * do this: $myVar = &references_PEAR::getStaticProperty('myclass', 'myVar'); |
|
222 | + * You MUST use a reference, or they will not persist! |
|
223 | + * |
|
224 | + * @access public |
|
225 | + * @param string $class The calling classname, to prevent clashes |
|
226 | + * @param string $var The variable to retrieve. |
|
227 | + * @return mixed A reference to the variable. If not set it will be |
|
228 | + * auto initialised to NULL. |
|
229 | + */ |
|
230 | + public function &getStaticProperty($class, $var) |
|
231 | + { |
|
232 | + static $properties; |
|
233 | + if (!isset($properties[$class])) { |
|
234 | + $properties[$class] = array(); |
|
235 | + } |
|
236 | + if (!array_key_exists($var, $properties[$class])) { |
|
237 | + $properties[$class][$var] = null; |
|
238 | + } |
|
239 | + |
|
240 | + return $properties[$class][$var]; |
|
241 | + } |
|
242 | + |
|
243 | + // }}} |
|
244 | + // {{{ registerShutdownFunc() |
|
245 | + |
|
246 | + /** |
|
247 | + * Use this function to register a shutdown method for static |
|
248 | + * classes. |
|
249 | + * |
|
250 | + * @access public |
|
251 | + * @param mixed $func The function name (or array of class/method) to call |
|
252 | + * @param mixed $args The arguments to pass to the function |
|
253 | + * @return void |
|
254 | + */ |
|
255 | + public function registerShutdownFunc($func, $args = array()) |
|
256 | + { |
|
257 | + // if we are called statically, there is a potential |
|
258 | + // that no shutdown func is registered. Bug #6445 |
|
259 | + if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { |
|
260 | + register_shutdown_function('references__PEAR_call_destructors'); |
|
261 | + $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; |
|
262 | + } |
|
263 | + $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); |
|
264 | + } |
|
265 | + |
|
266 | + // }}} |
|
267 | + // {{{ isError() |
|
268 | + |
|
269 | + /** |
|
270 | + * Tell whether a value is a PEAR error. |
|
271 | + * |
|
272 | + * @param mixed $data the value to test |
|
273 | + * @param int $code if $data is an error object, return true |
|
274 | + * only if $code is a string and |
|
275 | + * $obj->getMessage() == $code or |
|
276 | + * $code is an integer and $obj->getCode() == $code |
|
277 | + * @access public |
|
278 | + * @return bool true if parameter is an error |
|
279 | + */ |
|
280 | + public function isError($data, $code = null) |
|
281 | + { |
|
282 | + if (is_a($data, 'PEAR_Error')) { |
|
283 | + if (is_null($code)) { |
|
284 | + return true; |
|
285 | + } elseif (is_string($code)) { |
|
286 | + return $data->getMessage() == $code; |
|
287 | + } else { |
|
288 | + return $data->getCode() == $code; |
|
289 | + } |
|
290 | + } |
|
291 | + |
|
292 | + return false; |
|
293 | + } |
|
294 | + |
|
295 | + // }}} |
|
296 | + // {{{ setErrorHandling() |
|
297 | + |
|
298 | + /** |
|
299 | + * Sets how errors generated by this object should be handled. |
|
300 | + * Can be invoked both in objects and statically. If called |
|
301 | + * statically, setErrorHandling sets the default behaviour for all |
|
302 | + * PEAR objects. If called in an object, setErrorHandling sets |
|
303 | + * the default behaviour for that object. |
|
304 | + * |
|
305 | + * @param int $mode |
|
306 | + * One of references_PEAR_ERROR_RETURN, references_PEAR_ERROR_PRINT, |
|
307 | + * references_PEAR_ERROR_TRIGGER, references_PEAR_ERROR_DIE, |
|
308 | + * references_PEAR_ERROR_CALLBACK or references_PEAR_ERROR_EXCEPTION. |
|
309 | + * |
|
310 | + * @param mixed $options |
|
311 | + * When $mode is references_PEAR_ERROR_TRIGGER, this is the error level (one |
|
312 | + * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
|
313 | + * |
|
314 | + * When $mode is references_PEAR_ERROR_CALLBACK, this parameter is expected |
|
315 | + * to be the callback function or method. A callback |
|
316 | + * function is a string with the name of the function, a |
|
317 | + * callback method is an array of two elements: the element |
|
318 | + * at index 0 is the object, and the element at index 1 is |
|
319 | + * the name of the method to call in the object. |
|
320 | + * |
|
321 | + * When $mode is references_PEAR_ERROR_PRINT or references_PEAR_ERROR_DIE, this is |
|
322 | + * a printf format string used when printing the error |
|
323 | + * message. |
|
324 | + * |
|
325 | + * @access public |
|
326 | + * @return void |
|
327 | + * @see references_PEAR_ERROR_RETURN |
|
328 | + * @see references_PEAR_ERROR_PRINT |
|
329 | + * @see references_PEAR_ERROR_TRIGGER |
|
330 | + * @see references_PEAR_ERROR_DIE |
|
331 | + * @see references_PEAR_ERROR_CALLBACK |
|
332 | + * @see references_PEAR_ERROR_EXCEPTION |
|
333 | + * |
|
334 | + */ |
|
335 | + |
|
336 | + public function setErrorHandling($mode = null, $options = null) |
|
337 | + { |
|
338 | + if (isset($this) && is_a($this, 'PEAR')) { |
|
339 | + $setmode = &$this->_default_error_mode; |
|
340 | + $setoptions = &$this->_default_error_options; |
|
341 | + } else { |
|
342 | + $setmode = &$GLOBALS['_PEAR_default_error_mode']; |
|
343 | + $setoptions = &$GLOBALS['_PEAR_default_error_options']; |
|
344 | + } |
|
345 | + |
|
346 | + switch ($mode) { |
|
347 | + case references_PEAR_ERROR_EXCEPTION: |
|
348 | + case references_PEAR_ERROR_RETURN: |
|
349 | + case references_PEAR_ERROR_PRINT: |
|
350 | + case references_PEAR_ERROR_TRIGGER: |
|
351 | + case references_PEAR_ERROR_DIE: |
|
352 | + case null: |
|
353 | + $setmode = $mode; |
|
354 | + $setoptions = $options; |
|
355 | + break; |
|
356 | + |
|
357 | + case references_PEAR_ERROR_CALLBACK: |
|
358 | + $setmode = $mode; |
|
359 | + // class/object method callback |
|
360 | + if (is_callable($options)) { |
|
361 | + $setoptions = $options; |
|
362 | + } else { |
|
363 | + trigger_error('invalid error callback', E_USER_WARNING); |
|
364 | + } |
|
365 | + break; |
|
366 | + |
|
367 | + default: |
|
368 | + trigger_error('invalid error mode', E_USER_WARNING); |
|
369 | + break; |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + // }}} |
|
374 | + // {{{ expectError() |
|
375 | + |
|
376 | + /** |
|
377 | + * This method is used to tell which errors you expect to get. |
|
378 | + * Expected errors are always returned with error mode |
|
379 | + * references_PEAR_ERROR_RETURN. Expected error codes are stored in a stack, |
|
380 | + * and this method pushes a new element onto it. The list of |
|
381 | + * expected errors are in effect until they are popped off the |
|
382 | + * stack with the popExpect() method. |
|
383 | + * |
|
384 | + * Note that this method can not be called statically |
|
385 | + * |
|
386 | + * @param mixed $code a single error code or an array of error codes to expect |
|
387 | + * |
|
388 | + * @return int the new depth of the "expected errors" stack |
|
389 | + * @access public |
|
390 | + */ |
|
391 | + public function expectError($code = '*') |
|
392 | + { |
|
393 | + if (is_array($code)) { |
|
394 | + array_push($this->_expected_errors, $code); |
|
395 | + } else { |
|
396 | + array_push($this->_expected_errors, array($code)); |
|
397 | + } |
|
398 | + |
|
399 | + return count($this->_expected_errors); |
|
400 | + } |
|
401 | + |
|
402 | + // }}} |
|
403 | + // {{{ popExpect() |
|
404 | + |
|
405 | + /** |
|
406 | + * This method pops one element off the expected error codes |
|
407 | + * stack. |
|
408 | + * |
|
409 | + * @return array the list of error codes that were popped |
|
410 | + */ |
|
411 | + public function popExpect() |
|
412 | + { |
|
413 | + return array_pop($this->_expected_errors); |
|
414 | + } |
|
415 | + |
|
416 | + // }}} |
|
417 | + // {{{ _checkDelExpect() |
|
418 | + |
|
419 | + /** |
|
420 | + * This method checks unsets an error code if available |
|
421 | + * |
|
422 | + * @param mixed error code |
|
423 | + * @return bool true if the error code was unset, false otherwise |
|
424 | + * @access private |
|
425 | + */ |
|
426 | + public function _checkDelExpect($error_code) |
|
427 | + { |
|
428 | + $deleted = false; |
|
429 | + |
|
430 | + foreach ($this->_expected_errors as $key => $error_array) { |
|
431 | + if (in_array($error_code, $error_array)) { |
|
432 | + unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); |
|
433 | + $deleted = true; |
|
434 | + } |
|
435 | + |
|
436 | + // clean up empty arrays |
|
437 | + if (0 == count($this->_expected_errors[$key])) { |
|
438 | + unset($this->_expected_errors[$key]); |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + return $deleted; |
|
443 | + } |
|
444 | + |
|
445 | + // }}} |
|
446 | + // {{{ delExpect() |
|
447 | + |
|
448 | + /** |
|
449 | + * This method deletes all occurences of the specified element from |
|
450 | + * the expected error codes stack. |
|
451 | + * |
|
452 | + * @param mixed $error_code error code that should be deleted |
|
453 | + * @return mixed list of error codes that were deleted or error |
|
454 | + * @access public |
|
455 | + */ |
|
456 | + public function delExpect($error_code) |
|
457 | + { |
|
458 | + $deleted = false; |
|
459 | + |
|
460 | + if (is_array($error_code) && (0 != count($error_code))) { |
|
461 | + // $error_code is a non-empty array here; |
|
462 | + // we walk through it trying to unset all |
|
463 | + // values |
|
464 | + foreach ($error_code as $key => $error) { |
|
465 | + if ($this->_checkDelExpect($error)) { |
|
466 | + $deleted = true; |
|
467 | + } else { |
|
468 | + $deleted = false; |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + return $deleted ? true : references_PEAR::raiseError('The expected error you submitted does not exist'); // IMPROVE ME |
|
473 | + } elseif (!empty($error_code)) { |
|
474 | + // $error_code comes alone, trying to unset it |
|
475 | + if ($this->_checkDelExpect($error_code)) { |
|
476 | + return true; |
|
477 | + } else { |
|
478 | + return references_PEAR::raiseError('The expected error you submitted does not exist'); // IMPROVE ME |
|
479 | + } |
|
480 | + } else { |
|
481 | + // $error_code is empty |
|
482 | + return references_PEAR::raiseError('The expected error you submitted is empty'); // IMPROVE ME |
|
483 | + } |
|
484 | + } |
|
485 | + |
|
486 | + // }}} |
|
487 | + // {{{ raiseError() |
|
488 | + |
|
489 | + /** |
|
490 | + * This method is a wrapper that returns an instance of the |
|
491 | + * configured error class with this object's default error |
|
492 | + * handling applied. If the $mode and $options parameters are not |
|
493 | + * specified, the object's defaults are used. |
|
494 | + * |
|
495 | + * @param mixed $message a text error message or a PEAR error object |
|
496 | + * |
|
497 | + * @param int $code a numeric error code (it is up to your class |
|
498 | + * to define these if you want to use codes) |
|
499 | + * |
|
500 | + * @param int $mode One of references_PEAR_ERROR_RETURN, references_PEAR_ERROR_PRINT, |
|
501 | + * references_PEAR_ERROR_TRIGGER, references_PEAR_ERROR_DIE, |
|
502 | + * references_PEAR_ERROR_CALLBACK, references_PEAR_ERROR_EXCEPTION. |
|
503 | + * |
|
504 | + * @param mixed $options If $mode is references_PEAR_ERROR_TRIGGER, this parameter |
|
505 | + * specifies the PHP-internal error level (one of |
|
506 | + * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
|
507 | + * If $mode is references_PEAR_ERROR_CALLBACK, this |
|
508 | + * parameter specifies the callback function or |
|
509 | + * method. In other error modes this parameter |
|
510 | + * is ignored. |
|
511 | + * |
|
512 | + * @param string $userinfo If you need to pass along for example debug |
|
513 | + * information, this parameter is meant for that. |
|
514 | + * |
|
515 | + * @param string $error_class The returned error object will be |
|
516 | + * instantiated from this class, if specified. |
|
517 | + * |
|
518 | + * @param bool $skipmsg If true, raiseError will only pass error codes, |
|
519 | + * the error message parameter will be dropped. |
|
520 | + * |
|
521 | + * @access public |
|
522 | + * @return object a PEAR error object |
|
523 | + * @see references_PEAR::setErrorHandling |
|
524 | + * @since PHP 4.0.5 |
|
525 | + */ |
|
526 | + public function &raiseError($message = null, $code = null, $mode = null, $options = null, $userinfo = null, $error_class = null, $skipmsg = false) |
|
527 | + { |
|
528 | + // The error is yet a PEAR error object |
|
529 | + if (is_object($message)) { |
|
530 | + $code = $message->getCode(); |
|
531 | + $userinfo = $message->getUserInfo(); |
|
532 | + $error_class = $message->getType(); |
|
533 | + $message->error_message_prefix = ''; |
|
534 | + $message = $message->getMessage(); |
|
535 | + } |
|
536 | + |
|
537 | + if (isset($this) && isset($this->_expected_errors) && count($this->_expected_errors) > 0 && count($exp = end($this->_expected_errors))) { |
|
538 | + if ($exp[0] === '*' |
|
539 | + || (is_int(reset($exp)) && in_array($code, $exp)) |
|
540 | + || (is_string(reset($exp)) && in_array($message, $exp)) |
|
541 | + ) { |
|
542 | + $mode = references_PEAR_ERROR_RETURN; |
|
543 | + } |
|
544 | + } |
|
545 | + // No mode given, try global ones |
|
546 | + if ($mode === null) { |
|
547 | + // Class error handler |
|
548 | + if (isset($this) && isset($this->_default_error_mode)) { |
|
549 | + $mode = $this->_default_error_mode; |
|
550 | + $options = $this->_default_error_options; |
|
551 | + // Global error handler |
|
552 | + } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) { |
|
553 | + $mode = $GLOBALS['_PEAR_default_error_mode']; |
|
554 | + $options = $GLOBALS['_PEAR_default_error_options']; |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + if ($error_class !== null) { |
|
559 | + $ec = $error_class; |
|
560 | + } elseif (isset($this) && isset($this->_error_class)) { |
|
561 | + $ec = $this->_error_class; |
|
562 | + } else { |
|
563 | + $ec = 'references_PEAR_Error'; |
|
564 | + } |
|
565 | + if ($skipmsg) { |
|
566 | + $a = new $ec($code, $mode, $options, $userinfo); |
|
567 | + |
|
568 | + return $a; |
|
569 | + } else { |
|
570 | + $a = new $ec($message, $code, $mode, $options, $userinfo); |
|
571 | + |
|
572 | + return $a; |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + // }}} |
|
577 | + // {{{ throwError() |
|
578 | + |
|
579 | + /** |
|
580 | + * Simpler form of raiseError with fewer options. In most cases |
|
581 | + * message, code and userinfo are enough. |
|
582 | + * |
|
583 | + * @param string $message |
|
584 | + * |
|
585 | + * @param null $code |
|
586 | + * @param null $userinfo |
|
587 | + * @return object |
|
588 | + */ |
|
589 | + public function &throwError($message = null, $code = null, $userinfo = null) |
|
590 | + { |
|
591 | + if (isset($this) && is_a($this, 'PEAR')) { |
|
592 | + $a = &$this->raiseError($message, $code, null, null, $userinfo); |
|
593 | + |
|
594 | + return $a; |
|
595 | + } else { |
|
596 | + $a = &references_PEAR::raiseError($message, $code, null, null, $userinfo); |
|
597 | + |
|
598 | + return $a; |
|
599 | + } |
|
600 | + } |
|
601 | + |
|
602 | + // }}} |
|
603 | + public function staticPushErrorHandling($mode, $options = null) |
|
604 | + { |
|
605 | + $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
606 | + $def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
|
607 | + $def_options = &$GLOBALS['_PEAR_default_error_options']; |
|
608 | + $stack[] = array($def_mode, $def_options); |
|
609 | + switch ($mode) { |
|
610 | + case references_PEAR_ERROR_EXCEPTION: |
|
611 | + case references_PEAR_ERROR_RETURN: |
|
612 | + case references_PEAR_ERROR_PRINT: |
|
613 | + case references_PEAR_ERROR_TRIGGER: |
|
614 | + case references_PEAR_ERROR_DIE: |
|
615 | + case null: |
|
616 | + $def_mode = $mode; |
|
617 | + $def_options = $options; |
|
618 | + break; |
|
619 | + |
|
620 | + case references_PEAR_ERROR_CALLBACK: |
|
621 | + $def_mode = $mode; |
|
622 | + // class/object method callback |
|
623 | + if (is_callable($options)) { |
|
624 | + $def_options = $options; |
|
625 | + } else { |
|
626 | + trigger_error('invalid error callback', E_USER_WARNING); |
|
627 | + } |
|
628 | + break; |
|
629 | + |
|
630 | + default: |
|
631 | + trigger_error('invalid error mode', E_USER_WARNING); |
|
632 | + break; |
|
633 | + } |
|
634 | + $stack[] = array($mode, $options); |
|
635 | + |
|
636 | + return true; |
|
637 | + } |
|
638 | + |
|
639 | + public function staticPopErrorHandling() |
|
640 | + { |
|
641 | + $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
642 | + $setmode = &$GLOBALS['_PEAR_default_error_mode']; |
|
643 | + $setoptions = &$GLOBALS['_PEAR_default_error_options']; |
|
644 | + array_pop($stack); |
|
645 | + list($mode, $options) = $stack[count($stack) - 1]; |
|
646 | + array_pop($stack); |
|
647 | + switch ($mode) { |
|
648 | + case references_PEAR_ERROR_EXCEPTION: |
|
649 | + case references_PEAR_ERROR_RETURN: |
|
650 | + case references_PEAR_ERROR_PRINT: |
|
651 | + case references_PEAR_ERROR_TRIGGER: |
|
652 | + case references_PEAR_ERROR_DIE: |
|
653 | + case null: |
|
654 | + $setmode = $mode; |
|
655 | + $setoptions = $options; |
|
656 | + break; |
|
657 | + |
|
658 | + case references_PEAR_ERROR_CALLBACK: |
|
659 | + $setmode = $mode; |
|
660 | + // class/object method callback |
|
661 | + if (is_callable($options)) { |
|
662 | + $setoptions = $options; |
|
663 | + } else { |
|
664 | + trigger_error('invalid error callback', E_USER_WARNING); |
|
665 | + } |
|
666 | + break; |
|
667 | + |
|
668 | + default: |
|
669 | + trigger_error('invalid error mode', E_USER_WARNING); |
|
670 | + break; |
|
671 | + } |
|
672 | + |
|
673 | + return true; |
|
674 | + } |
|
675 | + |
|
676 | + // {{{ pushErrorHandling() |
|
677 | + |
|
678 | + /** |
|
679 | + * Push a new error handler on top of the error handler options stack. With this |
|
680 | + * you can easily override the actual error handler for some code and restore |
|
681 | + * it later with popErrorHandling. |
|
682 | + * |
|
683 | + * @param mixed $mode (same as setErrorHandling) |
|
684 | + * @param mixed $options (same as setErrorHandling) |
|
685 | + * |
|
686 | + * @return bool Always true |
|
687 | + * |
|
688 | + * @see references_PEAR::setErrorHandling |
|
689 | + */ |
|
690 | + public function pushErrorHandling($mode, $options = null) |
|
691 | + { |
|
692 | + $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
693 | + if (isset($this) && is_a($this, 'PEAR')) { |
|
694 | + $def_mode = &$this->_default_error_mode; |
|
695 | + $def_options = &$this->_default_error_options; |
|
696 | + } else { |
|
697 | + $def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
|
698 | + $def_options = &$GLOBALS['_PEAR_default_error_options']; |
|
699 | + } |
|
700 | + $stack[] = array($def_mode, $def_options); |
|
701 | + |
|
702 | + if (isset($this) && is_a($this, 'PEAR')) { |
|
703 | + $this->setErrorHandling($mode, $options); |
|
704 | + } else { |
|
705 | + references_PEAR::setErrorHandling($mode, $options); |
|
706 | + } |
|
707 | + $stack[] = array($mode, $options); |
|
708 | + |
|
709 | + return true; |
|
710 | + } |
|
711 | + |
|
712 | + // }}} |
|
713 | + // {{{ popErrorHandling() |
|
714 | + |
|
715 | + /** |
|
716 | + * Pop the last error handler used |
|
717 | + * |
|
718 | + * @return bool Always true |
|
719 | + * |
|
720 | + * @see references_PEAR::pushErrorHandling |
|
721 | + */ |
|
722 | + public function popErrorHandling() |
|
723 | + { |
|
724 | + $stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
725 | + array_pop($stack); |
|
726 | + list($mode, $options) = $stack[count($stack) - 1]; |
|
727 | + array_pop($stack); |
|
728 | + if (isset($this) && is_a($this, 'PEAR')) { |
|
729 | + $this->setErrorHandling($mode, $options); |
|
730 | + } else { |
|
731 | + references_PEAR::setErrorHandling($mode, $options); |
|
732 | + } |
|
733 | + |
|
734 | + return true; |
|
735 | + } |
|
736 | + |
|
737 | + // }}} |
|
738 | + // {{{ loadExtension() |
|
739 | + |
|
740 | + /** |
|
741 | + * OS independant PHP extension load. Remember to take care |
|
742 | + * on the correct extension name for case sensitive OSes. |
|
743 | + * |
|
744 | + * @param string $ext The extension name |
|
745 | + * @return bool Success or not on the dl() call |
|
746 | + */ |
|
747 | + public function loadExtension($ext) |
|
748 | + { |
|
749 | + if (!extension_loaded($ext)) { |
|
750 | + // if either returns true dl() will produce a FATAL error, stop that |
|
751 | + if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) { |
|
752 | + return false; |
|
753 | + } |
|
754 | + if (references_OS_WINDOWS) { |
|
755 | + $suffix = '.dll'; |
|
756 | + } elseif (PHP_OS === 'HP-UX') { |
|
757 | + $suffix = '.sl'; |
|
758 | + } elseif (PHP_OS === 'AIX') { |
|
759 | + $suffix = '.a'; |
|
760 | + } elseif (PHP_OS === 'OSX') { |
|
761 | + $suffix = '.bundle'; |
|
762 | + } else { |
|
763 | + $suffix = '.so'; |
|
764 | + } |
|
765 | + |
|
766 | + return @dl('php_' . $ext . $suffix) || @dl($ext . $suffix); |
|
767 | + } |
|
768 | + |
|
769 | + return true; |
|
770 | + } |
|
771 | + |
|
772 | + // }}} |
|
773 | 773 | } |
774 | 774 | |
775 | 775 | // {{{ _PEAR_call_destructors() |
776 | 776 | |
777 | 777 | function references_PEAR_call_destructors() |
778 | 778 | { |
779 | - global $_PEAR_destructor_object_list; |
|
780 | - if (is_array($_PEAR_destructor_object_list) |
|
781 | - && count($_PEAR_destructor_object_list) |
|
782 | - ) { |
|
783 | - reset($_PEAR_destructor_object_list); |
|
784 | - if (references_PEAR::getStaticProperty('PEAR', 'destructlifo')) { |
|
785 | - $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); |
|
786 | - } |
|
787 | - while (list($k, $objref) = each($_PEAR_destructor_object_list)) { |
|
788 | - $classname = get_class($objref); |
|
789 | - while ($classname) { |
|
790 | - $destructor = "_$classname"; |
|
791 | - if (method_exists($objref, $destructor)) { |
|
792 | - $objref->$destructor(); |
|
793 | - break; |
|
794 | - } else { |
|
795 | - $classname = get_parent_class($classname); |
|
796 | - } |
|
797 | - } |
|
798 | - } |
|
799 | - // Empty the object list to ensure that destructors are |
|
800 | - // not called more than once. |
|
801 | - $_PEAR_destructor_object_list = array(); |
|
802 | - } |
|
803 | - |
|
804 | - // Now call the shutdown functions |
|
805 | - if (is_array($GLOBALS['_PEAR_shutdown_funcs']) and !empty($GLOBALS['_PEAR_shutdown_funcs'])) { |
|
806 | - foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { |
|
807 | - call_user_func_array($value[0], $value[1]); |
|
808 | - } |
|
809 | - } |
|
779 | + global $_PEAR_destructor_object_list; |
|
780 | + if (is_array($_PEAR_destructor_object_list) |
|
781 | + && count($_PEAR_destructor_object_list) |
|
782 | + ) { |
|
783 | + reset($_PEAR_destructor_object_list); |
|
784 | + if (references_PEAR::getStaticProperty('PEAR', 'destructlifo')) { |
|
785 | + $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); |
|
786 | + } |
|
787 | + while (list($k, $objref) = each($_PEAR_destructor_object_list)) { |
|
788 | + $classname = get_class($objref); |
|
789 | + while ($classname) { |
|
790 | + $destructor = "_$classname"; |
|
791 | + if (method_exists($objref, $destructor)) { |
|
792 | + $objref->$destructor(); |
|
793 | + break; |
|
794 | + } else { |
|
795 | + $classname = get_parent_class($classname); |
|
796 | + } |
|
797 | + } |
|
798 | + } |
|
799 | + // Empty the object list to ensure that destructors are |
|
800 | + // not called more than once. |
|
801 | + $_PEAR_destructor_object_list = array(); |
|
802 | + } |
|
803 | + |
|
804 | + // Now call the shutdown functions |
|
805 | + if (is_array($GLOBALS['_PEAR_shutdown_funcs']) and !empty($GLOBALS['_PEAR_shutdown_funcs'])) { |
|
806 | + foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { |
|
807 | + call_user_func_array($value[0], $value[1]); |
|
808 | + } |
|
809 | + } |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | // }}} |
@@ -829,274 +829,274 @@ discard block |
||
829 | 829 | */ |
830 | 830 | class references_PEAR_Error |
831 | 831 | { |
832 | - // {{{ properties |
|
833 | - |
|
834 | - public $error_message_prefix = ''; |
|
835 | - public $mode = references_PEAR_ERROR_RETURN; |
|
836 | - public $level = E_USER_NOTICE; |
|
837 | - public $code = -1; |
|
838 | - public $message = ''; |
|
839 | - public $userinfo = ''; |
|
840 | - public $backtrace = null; |
|
841 | - |
|
842 | - // }}} |
|
843 | - // {{{ constructor |
|
844 | - |
|
845 | - /** |
|
846 | - * PEAR_Error constructor |
|
847 | - * |
|
848 | - * @param string $message message |
|
849 | - * |
|
850 | - * @param int $code (optional) error code |
|
851 | - * |
|
852 | - * @param int $mode (optional) error mode, one of: references_PEAR_ERROR_RETURN, |
|
853 | - * references_PEAR_ERROR_PRINT, references_PEAR_ERROR_DIE, references_PEAR_ERROR_TRIGGER, |
|
854 | - * references_PEAR_ERROR_CALLBACK or references_PEAR_ERROR_EXCEPTION |
|
855 | - * |
|
856 | - * @param mixed $options (optional) error level, _OR_ in the case of |
|
857 | - * references_PEAR_ERROR_CALLBACK, the callback function or object/method |
|
858 | - * tuple. |
|
859 | - * |
|
860 | - * @param string $userinfo (optional) additional user/debug info |
|
861 | - * |
|
862 | - * @access public |
|
863 | - * |
|
864 | - */ |
|
865 | - public function __construct($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null) |
|
866 | - { |
|
867 | - if ($mode === null) { |
|
868 | - $mode = references_PEAR_ERROR_RETURN; |
|
869 | - } |
|
870 | - $this->message = $message; |
|
871 | - $this->code = $code; |
|
872 | - $this->mode = $mode; |
|
873 | - $this->userinfo = $userinfo; |
|
874 | - if (!references_PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) { |
|
875 | - $this->backtrace = debug_backtrace(); |
|
876 | - if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) { |
|
877 | - unset($this->backtrace[0]['object']); |
|
878 | - } |
|
879 | - } |
|
880 | - if ($mode & references_PEAR_ERROR_CALLBACK) { |
|
881 | - $this->level = E_USER_NOTICE; |
|
882 | - $this->callback = $options; |
|
883 | - } else { |
|
884 | - if ($options === null) { |
|
885 | - $options = E_USER_NOTICE; |
|
886 | - } |
|
887 | - $this->level = $options; |
|
888 | - $this->callback = null; |
|
889 | - } |
|
890 | - if ($this->mode & references_PEAR_ERROR_PRINT) { |
|
891 | - if (is_null($options) || is_int($options)) { |
|
892 | - $format = '%s'; |
|
893 | - } else { |
|
894 | - $format = $options; |
|
895 | - } |
|
896 | - printf($format, $this->getMessage()); |
|
897 | - } |
|
898 | - if ($this->mode & references_PEAR_ERROR_TRIGGER) { |
|
899 | - trigger_error($this->getMessage(), $this->level); |
|
900 | - } |
|
901 | - if ($this->mode & references_PEAR_ERROR_DIE) { |
|
902 | - $msg = $this->getMessage(); |
|
903 | - if (is_null($options) || is_int($options)) { |
|
904 | - $format = '%s'; |
|
905 | - if (substr($msg, -1) !== "\n") { |
|
906 | - $msg .= "\n"; |
|
907 | - } |
|
908 | - } else { |
|
909 | - $format = $options; |
|
910 | - } |
|
911 | - die(sprintf($format, $msg)); |
|
912 | - } |
|
913 | - if ($this->mode & references_PEAR_ERROR_CALLBACK) { |
|
914 | - if (is_callable($this->callback)) { |
|
915 | - call_user_func($this->callback, $this); |
|
916 | - } |
|
917 | - } |
|
918 | - if ($this->mode & references_PEAR_ERROR_EXCEPTION) { |
|
919 | - trigger_error('references_PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions', E_USER_WARNING); |
|
920 | - eval('$e = new Exception($this->message, $this->code);throw($e);'); |
|
921 | - } |
|
922 | - } |
|
923 | - |
|
924 | - // }}} |
|
925 | - // {{{ getMode() |
|
926 | - |
|
927 | - /** |
|
928 | - * Get the error mode from an error object. |
|
929 | - * |
|
930 | - * @return int error mode |
|
931 | - * @access public |
|
932 | - */ |
|
933 | - public function getMode() |
|
934 | - { |
|
935 | - return $this->mode; |
|
936 | - } |
|
937 | - |
|
938 | - // }}} |
|
939 | - // {{{ getCallback() |
|
940 | - |
|
941 | - /** |
|
942 | - * Get the callback function/method from an error object. |
|
943 | - * |
|
944 | - * @return mixed callback function or object/method array |
|
945 | - * @access public |
|
946 | - */ |
|
947 | - public function getCallback() |
|
948 | - { |
|
949 | - return $this->callback; |
|
950 | - } |
|
951 | - |
|
952 | - // }}} |
|
953 | - // {{{ getMessage() |
|
954 | - |
|
955 | - /** |
|
956 | - * Get the error message from an error object. |
|
957 | - * |
|
958 | - * @return string full error message |
|
959 | - * @access public |
|
960 | - */ |
|
961 | - public function getMessage() |
|
962 | - { |
|
963 | - return ($this->error_message_prefix . $this->message); |
|
964 | - } |
|
965 | - |
|
966 | - // }}} |
|
967 | - // {{{ getCode() |
|
968 | - |
|
969 | - /** |
|
970 | - * Get error code from an error object |
|
971 | - * |
|
972 | - * @return int error code |
|
973 | - * @access public |
|
974 | - */ |
|
975 | - public function getCode() |
|
976 | - { |
|
977 | - return $this->code; |
|
978 | - } |
|
979 | - |
|
980 | - // }}} |
|
981 | - // {{{ getType() |
|
982 | - |
|
983 | - /** |
|
984 | - * Get the name of this error/exception. |
|
985 | - * |
|
986 | - * @return string error/exception name (type) |
|
987 | - * @access public |
|
988 | - */ |
|
989 | - public function getType() |
|
990 | - { |
|
991 | - return get_class($this); |
|
992 | - } |
|
993 | - |
|
994 | - // }}} |
|
995 | - // {{{ getUserInfo() |
|
996 | - |
|
997 | - /** |
|
998 | - * Get additional user-supplied information. |
|
999 | - * |
|
1000 | - * @return string user-supplied information |
|
1001 | - * @access public |
|
1002 | - */ |
|
1003 | - public function getUserInfo() |
|
1004 | - { |
|
1005 | - return $this->userinfo; |
|
1006 | - } |
|
1007 | - |
|
1008 | - // }}} |
|
1009 | - // {{{ getDebugInfo() |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Get additional debug information supplied by the application. |
|
1013 | - * |
|
1014 | - * @return string debug information |
|
1015 | - * @access public |
|
1016 | - */ |
|
1017 | - public function getDebugInfo() |
|
1018 | - { |
|
1019 | - return $this->getUserInfo(); |
|
1020 | - } |
|
1021 | - |
|
1022 | - // }}} |
|
1023 | - // {{{ getBacktrace() |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Get the call backtrace from where the error was generated. |
|
1027 | - * Supported with PHP 4.3.0 or newer. |
|
1028 | - * |
|
1029 | - * @param int $frame (optional) what frame to fetch |
|
1030 | - * @return array Backtrace, or NULL if not available. |
|
1031 | - * @access public |
|
1032 | - */ |
|
1033 | - public function getBacktrace($frame = null) |
|
1034 | - { |
|
1035 | - if (defined('PEAR_IGNORE_BACKTRACE')) { |
|
1036 | - return null; |
|
1037 | - } |
|
1038 | - if ($frame === null) { |
|
1039 | - return $this->backtrace; |
|
1040 | - } |
|
1041 | - |
|
1042 | - return $this->backtrace[$frame]; |
|
1043 | - } |
|
1044 | - |
|
1045 | - // }}} |
|
1046 | - // {{{ addUserInfo() |
|
1047 | - |
|
1048 | - public function addUserInfo($info) |
|
1049 | - { |
|
1050 | - if (empty($this->userinfo)) { |
|
1051 | - $this->userinfo = $info; |
|
1052 | - } else { |
|
1053 | - $this->userinfo .= " ** $info"; |
|
1054 | - } |
|
1055 | - } |
|
1056 | - |
|
1057 | - // }}} |
|
1058 | - // {{{ toString() |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Make a string representation of this object. |
|
1062 | - * |
|
1063 | - * @return string a string with an object summary |
|
1064 | - * @access public |
|
1065 | - */ |
|
1066 | - public function toString() |
|
1067 | - { |
|
1068 | - $modes = array(); |
|
1069 | - $levels = array( |
|
1070 | - E_USER_NOTICE => 'notice', |
|
1071 | - E_USER_WARNING => 'warning', |
|
1072 | - E_USER_ERROR => 'error' |
|
1073 | - ); |
|
1074 | - if ($this->mode & references_PEAR_ERROR_CALLBACK) { |
|
1075 | - if (is_array($this->callback)) { |
|
1076 | - $callback = (is_object($this->callback[0]) ? strtolower(get_class($this->callback[0])) : $this->callback[0]) . '::' . $this->callback[1]; |
|
1077 | - } else { |
|
1078 | - $callback = $this->callback; |
|
1079 | - } |
|
1080 | - |
|
1081 | - return sprintf('[%s: message="%s" code=%d mode=callback ' . 'callback=%s prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo); |
|
1082 | - } |
|
1083 | - if ($this->mode & references_PEAR_ERROR_PRINT) { |
|
1084 | - $modes[] = 'print'; |
|
1085 | - } |
|
1086 | - if ($this->mode & references_PEAR_ERROR_TRIGGER) { |
|
1087 | - $modes[] = 'trigger'; |
|
1088 | - } |
|
1089 | - if ($this->mode & references_PEAR_ERROR_DIE) { |
|
1090 | - $modes[] = 'die'; |
|
1091 | - } |
|
1092 | - if ($this->mode & references_PEAR_ERROR_RETURN) { |
|
1093 | - $modes[] = 'return'; |
|
1094 | - } |
|
1095 | - |
|
1096 | - return sprintf('[%s: message="%s" code=%d mode=%s level=%s ' . 'prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, implode('|', $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo); |
|
1097 | - } |
|
1098 | - |
|
1099 | - // }}} |
|
832 | + // {{{ properties |
|
833 | + |
|
834 | + public $error_message_prefix = ''; |
|
835 | + public $mode = references_PEAR_ERROR_RETURN; |
|
836 | + public $level = E_USER_NOTICE; |
|
837 | + public $code = -1; |
|
838 | + public $message = ''; |
|
839 | + public $userinfo = ''; |
|
840 | + public $backtrace = null; |
|
841 | + |
|
842 | + // }}} |
|
843 | + // {{{ constructor |
|
844 | + |
|
845 | + /** |
|
846 | + * PEAR_Error constructor |
|
847 | + * |
|
848 | + * @param string $message message |
|
849 | + * |
|
850 | + * @param int $code (optional) error code |
|
851 | + * |
|
852 | + * @param int $mode (optional) error mode, one of: references_PEAR_ERROR_RETURN, |
|
853 | + * references_PEAR_ERROR_PRINT, references_PEAR_ERROR_DIE, references_PEAR_ERROR_TRIGGER, |
|
854 | + * references_PEAR_ERROR_CALLBACK or references_PEAR_ERROR_EXCEPTION |
|
855 | + * |
|
856 | + * @param mixed $options (optional) error level, _OR_ in the case of |
|
857 | + * references_PEAR_ERROR_CALLBACK, the callback function or object/method |
|
858 | + * tuple. |
|
859 | + * |
|
860 | + * @param string $userinfo (optional) additional user/debug info |
|
861 | + * |
|
862 | + * @access public |
|
863 | + * |
|
864 | + */ |
|
865 | + public function __construct($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null) |
|
866 | + { |
|
867 | + if ($mode === null) { |
|
868 | + $mode = references_PEAR_ERROR_RETURN; |
|
869 | + } |
|
870 | + $this->message = $message; |
|
871 | + $this->code = $code; |
|
872 | + $this->mode = $mode; |
|
873 | + $this->userinfo = $userinfo; |
|
874 | + if (!references_PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) { |
|
875 | + $this->backtrace = debug_backtrace(); |
|
876 | + if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) { |
|
877 | + unset($this->backtrace[0]['object']); |
|
878 | + } |
|
879 | + } |
|
880 | + if ($mode & references_PEAR_ERROR_CALLBACK) { |
|
881 | + $this->level = E_USER_NOTICE; |
|
882 | + $this->callback = $options; |
|
883 | + } else { |
|
884 | + if ($options === null) { |
|
885 | + $options = E_USER_NOTICE; |
|
886 | + } |
|
887 | + $this->level = $options; |
|
888 | + $this->callback = null; |
|
889 | + } |
|
890 | + if ($this->mode & references_PEAR_ERROR_PRINT) { |
|
891 | + if (is_null($options) || is_int($options)) { |
|
892 | + $format = '%s'; |
|
893 | + } else { |
|
894 | + $format = $options; |
|
895 | + } |
|
896 | + printf($format, $this->getMessage()); |
|
897 | + } |
|
898 | + if ($this->mode & references_PEAR_ERROR_TRIGGER) { |
|
899 | + trigger_error($this->getMessage(), $this->level); |
|
900 | + } |
|
901 | + if ($this->mode & references_PEAR_ERROR_DIE) { |
|
902 | + $msg = $this->getMessage(); |
|
903 | + if (is_null($options) || is_int($options)) { |
|
904 | + $format = '%s'; |
|
905 | + if (substr($msg, -1) !== "\n") { |
|
906 | + $msg .= "\n"; |
|
907 | + } |
|
908 | + } else { |
|
909 | + $format = $options; |
|
910 | + } |
|
911 | + die(sprintf($format, $msg)); |
|
912 | + } |
|
913 | + if ($this->mode & references_PEAR_ERROR_CALLBACK) { |
|
914 | + if (is_callable($this->callback)) { |
|
915 | + call_user_func($this->callback, $this); |
|
916 | + } |
|
917 | + } |
|
918 | + if ($this->mode & references_PEAR_ERROR_EXCEPTION) { |
|
919 | + trigger_error('references_PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions', E_USER_WARNING); |
|
920 | + eval('$e = new Exception($this->message, $this->code);throw($e);'); |
|
921 | + } |
|
922 | + } |
|
923 | + |
|
924 | + // }}} |
|
925 | + // {{{ getMode() |
|
926 | + |
|
927 | + /** |
|
928 | + * Get the error mode from an error object. |
|
929 | + * |
|
930 | + * @return int error mode |
|
931 | + * @access public |
|
932 | + */ |
|
933 | + public function getMode() |
|
934 | + { |
|
935 | + return $this->mode; |
|
936 | + } |
|
937 | + |
|
938 | + // }}} |
|
939 | + // {{{ getCallback() |
|
940 | + |
|
941 | + /** |
|
942 | + * Get the callback function/method from an error object. |
|
943 | + * |
|
944 | + * @return mixed callback function or object/method array |
|
945 | + * @access public |
|
946 | + */ |
|
947 | + public function getCallback() |
|
948 | + { |
|
949 | + return $this->callback; |
|
950 | + } |
|
951 | + |
|
952 | + // }}} |
|
953 | + // {{{ getMessage() |
|
954 | + |
|
955 | + /** |
|
956 | + * Get the error message from an error object. |
|
957 | + * |
|
958 | + * @return string full error message |
|
959 | + * @access public |
|
960 | + */ |
|
961 | + public function getMessage() |
|
962 | + { |
|
963 | + return ($this->error_message_prefix . $this->message); |
|
964 | + } |
|
965 | + |
|
966 | + // }}} |
|
967 | + // {{{ getCode() |
|
968 | + |
|
969 | + /** |
|
970 | + * Get error code from an error object |
|
971 | + * |
|
972 | + * @return int error code |
|
973 | + * @access public |
|
974 | + */ |
|
975 | + public function getCode() |
|
976 | + { |
|
977 | + return $this->code; |
|
978 | + } |
|
979 | + |
|
980 | + // }}} |
|
981 | + // {{{ getType() |
|
982 | + |
|
983 | + /** |
|
984 | + * Get the name of this error/exception. |
|
985 | + * |
|
986 | + * @return string error/exception name (type) |
|
987 | + * @access public |
|
988 | + */ |
|
989 | + public function getType() |
|
990 | + { |
|
991 | + return get_class($this); |
|
992 | + } |
|
993 | + |
|
994 | + // }}} |
|
995 | + // {{{ getUserInfo() |
|
996 | + |
|
997 | + /** |
|
998 | + * Get additional user-supplied information. |
|
999 | + * |
|
1000 | + * @return string user-supplied information |
|
1001 | + * @access public |
|
1002 | + */ |
|
1003 | + public function getUserInfo() |
|
1004 | + { |
|
1005 | + return $this->userinfo; |
|
1006 | + } |
|
1007 | + |
|
1008 | + // }}} |
|
1009 | + // {{{ getDebugInfo() |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Get additional debug information supplied by the application. |
|
1013 | + * |
|
1014 | + * @return string debug information |
|
1015 | + * @access public |
|
1016 | + */ |
|
1017 | + public function getDebugInfo() |
|
1018 | + { |
|
1019 | + return $this->getUserInfo(); |
|
1020 | + } |
|
1021 | + |
|
1022 | + // }}} |
|
1023 | + // {{{ getBacktrace() |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Get the call backtrace from where the error was generated. |
|
1027 | + * Supported with PHP 4.3.0 or newer. |
|
1028 | + * |
|
1029 | + * @param int $frame (optional) what frame to fetch |
|
1030 | + * @return array Backtrace, or NULL if not available. |
|
1031 | + * @access public |
|
1032 | + */ |
|
1033 | + public function getBacktrace($frame = null) |
|
1034 | + { |
|
1035 | + if (defined('PEAR_IGNORE_BACKTRACE')) { |
|
1036 | + return null; |
|
1037 | + } |
|
1038 | + if ($frame === null) { |
|
1039 | + return $this->backtrace; |
|
1040 | + } |
|
1041 | + |
|
1042 | + return $this->backtrace[$frame]; |
|
1043 | + } |
|
1044 | + |
|
1045 | + // }}} |
|
1046 | + // {{{ addUserInfo() |
|
1047 | + |
|
1048 | + public function addUserInfo($info) |
|
1049 | + { |
|
1050 | + if (empty($this->userinfo)) { |
|
1051 | + $this->userinfo = $info; |
|
1052 | + } else { |
|
1053 | + $this->userinfo .= " ** $info"; |
|
1054 | + } |
|
1055 | + } |
|
1056 | + |
|
1057 | + // }}} |
|
1058 | + // {{{ toString() |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Make a string representation of this object. |
|
1062 | + * |
|
1063 | + * @return string a string with an object summary |
|
1064 | + * @access public |
|
1065 | + */ |
|
1066 | + public function toString() |
|
1067 | + { |
|
1068 | + $modes = array(); |
|
1069 | + $levels = array( |
|
1070 | + E_USER_NOTICE => 'notice', |
|
1071 | + E_USER_WARNING => 'warning', |
|
1072 | + E_USER_ERROR => 'error' |
|
1073 | + ); |
|
1074 | + if ($this->mode & references_PEAR_ERROR_CALLBACK) { |
|
1075 | + if (is_array($this->callback)) { |
|
1076 | + $callback = (is_object($this->callback[0]) ? strtolower(get_class($this->callback[0])) : $this->callback[0]) . '::' . $this->callback[1]; |
|
1077 | + } else { |
|
1078 | + $callback = $this->callback; |
|
1079 | + } |
|
1080 | + |
|
1081 | + return sprintf('[%s: message="%s" code=%d mode=callback ' . 'callback=%s prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo); |
|
1082 | + } |
|
1083 | + if ($this->mode & references_PEAR_ERROR_PRINT) { |
|
1084 | + $modes[] = 'print'; |
|
1085 | + } |
|
1086 | + if ($this->mode & references_PEAR_ERROR_TRIGGER) { |
|
1087 | + $modes[] = 'trigger'; |
|
1088 | + } |
|
1089 | + if ($this->mode & references_PEAR_ERROR_DIE) { |
|
1090 | + $modes[] = 'die'; |
|
1091 | + } |
|
1092 | + if ($this->mode & references_PEAR_ERROR_RETURN) { |
|
1093 | + $modes[] = 'return'; |
|
1094 | + } |
|
1095 | + |
|
1096 | + return sprintf('[%s: message="%s" code=%d mode=%s level=%s ' . 'prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, implode('|', $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo); |
|
1097 | + } |
|
1098 | + |
|
1099 | + // }}} |
|
1100 | 1100 | } |
1101 | 1101 | |
1102 | 1102 | /* |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | $suffix = '.so'; |
764 | 764 | } |
765 | 765 | |
766 | - return @dl('php_' . $ext . $suffix) || @dl($ext . $suffix); |
|
766 | + return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | return true; |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | unset($this->backtrace[0]['object']); |
878 | 878 | } |
879 | 879 | } |
880 | - if ($mode & references_PEAR_ERROR_CALLBACK) { |
|
880 | + if ($mode&references_PEAR_ERROR_CALLBACK) { |
|
881 | 881 | $this->level = E_USER_NOTICE; |
882 | 882 | $this->callback = $options; |
883 | 883 | } else { |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | $this->level = $options; |
888 | 888 | $this->callback = null; |
889 | 889 | } |
890 | - if ($this->mode & references_PEAR_ERROR_PRINT) { |
|
890 | + if ($this->mode&references_PEAR_ERROR_PRINT) { |
|
891 | 891 | if (is_null($options) || is_int($options)) { |
892 | 892 | $format = '%s'; |
893 | 893 | } else { |
@@ -895,10 +895,10 @@ discard block |
||
895 | 895 | } |
896 | 896 | printf($format, $this->getMessage()); |
897 | 897 | } |
898 | - if ($this->mode & references_PEAR_ERROR_TRIGGER) { |
|
898 | + if ($this->mode&references_PEAR_ERROR_TRIGGER) { |
|
899 | 899 | trigger_error($this->getMessage(), $this->level); |
900 | 900 | } |
901 | - if ($this->mode & references_PEAR_ERROR_DIE) { |
|
901 | + if ($this->mode&references_PEAR_ERROR_DIE) { |
|
902 | 902 | $msg = $this->getMessage(); |
903 | 903 | if (is_null($options) || is_int($options)) { |
904 | 904 | $format = '%s'; |
@@ -910,12 +910,12 @@ discard block |
||
910 | 910 | } |
911 | 911 | die(sprintf($format, $msg)); |
912 | 912 | } |
913 | - if ($this->mode & references_PEAR_ERROR_CALLBACK) { |
|
913 | + if ($this->mode&references_PEAR_ERROR_CALLBACK) { |
|
914 | 914 | if (is_callable($this->callback)) { |
915 | 915 | call_user_func($this->callback, $this); |
916 | 916 | } |
917 | 917 | } |
918 | - if ($this->mode & references_PEAR_ERROR_EXCEPTION) { |
|
918 | + if ($this->mode&references_PEAR_ERROR_EXCEPTION) { |
|
919 | 919 | trigger_error('references_PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions', E_USER_WARNING); |
920 | 920 | eval('$e = new Exception($this->message, $this->code);throw($e);'); |
921 | 921 | } |
@@ -960,7 +960,7 @@ discard block |
||
960 | 960 | */ |
961 | 961 | public function getMessage() |
962 | 962 | { |
963 | - return ($this->error_message_prefix . $this->message); |
|
963 | + return ($this->error_message_prefix.$this->message); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | // }}} |
@@ -1071,29 +1071,29 @@ discard block |
||
1071 | 1071 | E_USER_WARNING => 'warning', |
1072 | 1072 | E_USER_ERROR => 'error' |
1073 | 1073 | ); |
1074 | - if ($this->mode & references_PEAR_ERROR_CALLBACK) { |
|
1074 | + if ($this->mode&references_PEAR_ERROR_CALLBACK) { |
|
1075 | 1075 | if (is_array($this->callback)) { |
1076 | - $callback = (is_object($this->callback[0]) ? strtolower(get_class($this->callback[0])) : $this->callback[0]) . '::' . $this->callback[1]; |
|
1076 | + $callback = (is_object($this->callback[0]) ? strtolower(get_class($this->callback[0])) : $this->callback[0]).'::'.$this->callback[1]; |
|
1077 | 1077 | } else { |
1078 | 1078 | $callback = $this->callback; |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - return sprintf('[%s: message="%s" code=%d mode=callback ' . 'callback=%s prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo); |
|
1081 | + return sprintf('[%s: message="%s" code=%d mode=callback '.'callback=%s prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo); |
|
1082 | 1082 | } |
1083 | - if ($this->mode & references_PEAR_ERROR_PRINT) { |
|
1083 | + if ($this->mode&references_PEAR_ERROR_PRINT) { |
|
1084 | 1084 | $modes[] = 'print'; |
1085 | 1085 | } |
1086 | - if ($this->mode & references_PEAR_ERROR_TRIGGER) { |
|
1086 | + if ($this->mode&references_PEAR_ERROR_TRIGGER) { |
|
1087 | 1087 | $modes[] = 'trigger'; |
1088 | 1088 | } |
1089 | - if ($this->mode & references_PEAR_ERROR_DIE) { |
|
1089 | + if ($this->mode&references_PEAR_ERROR_DIE) { |
|
1090 | 1090 | $modes[] = 'die'; |
1091 | 1091 | } |
1092 | - if ($this->mode & references_PEAR_ERROR_RETURN) { |
|
1092 | + if ($this->mode&references_PEAR_ERROR_RETURN) { |
|
1093 | 1093 | $modes[] = 'return'; |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - return sprintf('[%s: message="%s" code=%d mode=%s level=%s ' . 'prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, implode('|', $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo); |
|
1096 | + return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.'prefix="%s" info="%s"]', strtolower(get_class($this)), $this->message, $this->code, implode('|', $modes), $levels[$this->level], $this->error_message_prefix, $this->userinfo); |
|
1097 | 1097 | } |
1098 | 1098 | |
1099 | 1099 | // }}} |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param boolean $as_object |
236 | 236 | * @param string $fields Requested fields from the query |
237 | 237 | * |
238 | - * @return array |
|
238 | + * @return string |
|
239 | 239 | */ |
240 | 240 | protected function convertResultSet($result, $id_as_key = false, $as_object = true, $fields = '*') |
241 | 241 | { |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | /** |
503 | 503 | * delete an object from the database |
504 | 504 | * |
505 | - * @param XoopsObject $obj reference to the object to delete |
|
505 | + * @param references_articles $obj reference to the object to delete |
|
506 | 506 | * @param bool $force |
507 | 507 | * @return bool FALSE if failed. |
508 | 508 | */ |
@@ -22,49 +22,49 @@ discard block |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | if (!defined('XOOPS_ROOT_PATH')) { |
25 | - die('XOOPS root path not defined'); |
|
25 | + die('XOOPS root path not defined'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class references_Object extends XoopsObject |
29 | 29 | { |
30 | - public function toArray($format = 's') |
|
31 | - { |
|
32 | - $ret = array(); |
|
33 | - foreach ($this->vars as $k => $v) { |
|
34 | - $ret[$k] = $this->getVar($k, $format); |
|
35 | - } |
|
36 | - |
|
37 | - return $ret; |
|
38 | - } |
|
39 | - |
|
40 | - // TODO: Rajouter une méthode intsert() et delete() |
|
41 | - |
|
42 | - /** |
|
43 | - * Permet de valoriser un champ de la table comme si c'était une propriété de la classe |
|
44 | - * |
|
45 | - * @example $enregistrement->nom_du_champ = 'ma chaine' |
|
46 | - * |
|
47 | - * @param string $key Le nom du champ à traiter |
|
48 | - * @param mixed $value La valeur à lui attribuer |
|
49 | - * @return void |
|
50 | - */ |
|
51 | - public function __set($key, $value) |
|
52 | - { |
|
53 | - return $this->setVar($key, $value); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Permet d'accéder aux champs de la table comme à des propriétés de la classe |
|
58 | - * |
|
59 | - * @example echo $enregistrement->nom_du_champ; |
|
60 | - * |
|
61 | - * @param string $key Le nom du champ que l'on souhaite récupérer |
|
62 | - * @return mixed |
|
63 | - */ |
|
64 | - public function __get($key) |
|
65 | - { |
|
66 | - return $this->getVar($key); |
|
67 | - } |
|
30 | + public function toArray($format = 's') |
|
31 | + { |
|
32 | + $ret = array(); |
|
33 | + foreach ($this->vars as $k => $v) { |
|
34 | + $ret[$k] = $this->getVar($k, $format); |
|
35 | + } |
|
36 | + |
|
37 | + return $ret; |
|
38 | + } |
|
39 | + |
|
40 | + // TODO: Rajouter une méthode intsert() et delete() |
|
41 | + |
|
42 | + /** |
|
43 | + * Permet de valoriser un champ de la table comme si c'était une propriété de la classe |
|
44 | + * |
|
45 | + * @example $enregistrement->nom_du_champ = 'ma chaine' |
|
46 | + * |
|
47 | + * @param string $key Le nom du champ à traiter |
|
48 | + * @param mixed $value La valeur à lui attribuer |
|
49 | + * @return void |
|
50 | + */ |
|
51 | + public function __set($key, $value) |
|
52 | + { |
|
53 | + return $this->setVar($key, $value); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Permet d'accéder aux champs de la table comme à des propriétés de la classe |
|
58 | + * |
|
59 | + * @example echo $enregistrement->nom_du_champ; |
|
60 | + * |
|
61 | + * @param string $key Le nom du champ que l'on souhaite récupérer |
|
62 | + * @return mixed |
|
63 | + */ |
|
64 | + public function __get($key) |
|
65 | + { |
|
66 | + return $this->getVar($key); |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -75,778 +75,778 @@ discard block |
||
75 | 75 | */ |
76 | 76 | class references_XoopsPersistableObjectHandler extends XoopsObjectHandler |
77 | 77 | { |
78 | - /**#@+ |
|
78 | + /**#@+ |
|
79 | 79 | * Information about the class, the handler is managing |
80 | 80 | * |
81 | 81 | * @var string |
82 | 82 | */ |
83 | - public $table; |
|
84 | - public $keyName; |
|
85 | - public $className; |
|
86 | - public $identifierName; |
|
87 | - protected $cacheOptions = array(); |
|
88 | - /**#@-*/ |
|
89 | - |
|
90 | - /** |
|
91 | - * Constructor - called from child classes |
|
92 | - * @param object $db {@link XoopsDatabase} object |
|
93 | - * @param string $tablename Name of database table |
|
94 | - * @param string $classname Name of Class, this handler is managing |
|
95 | - * @param string $keyname Name of the property, holding the key |
|
96 | - * @param string $idenfierName Name of the property, holding the label |
|
97 | - * @param array $cacheOptions Optional, options for the cache |
|
98 | - * |
|
99 | - */ |
|
100 | - public function __construct(&$db, $tablename, $classname, $keyname, $idenfierName = '', $cacheOptions = null) |
|
101 | - { |
|
102 | - parent::__construct($db); |
|
103 | - $this->table = $db->prefix($tablename); |
|
104 | - $this->keyName = $keyname; |
|
105 | - $this->className = $classname; |
|
106 | - if (trim($idenfierName) != '') { |
|
107 | - $this->identifierName = $idenfierName; |
|
108 | - } |
|
109 | - // To diable cache, add this line after the first one : 'caching' => false, |
|
110 | - if (is_null($cacheOptions)) { |
|
111 | - $this->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
112 | - } else { |
|
113 | - $this->setCachingOptions($cacheOptions); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - public function setCachingOptions($cacheOptions) |
|
118 | - { |
|
119 | - $this->cacheOptions = $cacheOptions; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Generates a unique ID for a Sql Query |
|
124 | - * |
|
125 | - * @param string $query The SQL query for which we want a unidque ID |
|
126 | - * @param integer $start Which record to start at |
|
127 | - * @param integer $limit Max number of objects to fetch |
|
128 | - * @return string An MD5 of the query |
|
129 | - */ |
|
130 | - protected function _getIdForCache($query, $start, $limit) |
|
131 | - { |
|
132 | - $id = md5($query . '-' . (string)$start . '-' . (string)$limit); |
|
133 | - |
|
134 | - return $id; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * create a new object |
|
139 | - * |
|
140 | - * @param bool $isNew Flag the new objects as "new"? |
|
141 | - * |
|
142 | - * @return object |
|
143 | - */ |
|
144 | - public function &create($isNew = true) |
|
145 | - { |
|
146 | - $obj = new $this->className(); |
|
147 | - if ($isNew === true) { |
|
148 | - $obj->setNew(); |
|
149 | - } |
|
150 | - |
|
151 | - return $obj; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * retrieve an object |
|
156 | - * |
|
157 | - * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
158 | - * @param bool $as_object whether to return an object or an array |
|
159 | - * @return mixed reference to the object, FALSE if failed |
|
160 | - */ |
|
161 | - public function &get($id, $as_object = true) |
|
162 | - { |
|
163 | - if (is_array($this->keyName)) { |
|
164 | - $criteria = new CriteriaCompo(); |
|
165 | - $vnb = count($this->keyName); |
|
166 | - for ($i = 0; $i < $vnb; ++$i) { |
|
167 | - $criteria->add(new Criteria($this->keyName[$i], (int)$id[$i])); |
|
168 | - } |
|
169 | - } else { |
|
170 | - $criteria = new Criteria($this->keyName, (int)$id); |
|
171 | - } |
|
172 | - $criteria->setLimit(1); |
|
173 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
174 | - if (count($obj_array) != 1) { |
|
175 | - $ret = null; |
|
176 | - } else { |
|
177 | - $ret =& $obj_array[0]; |
|
178 | - } |
|
179 | - |
|
180 | - return $ret; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * retrieve objects from the database |
|
185 | - * |
|
186 | - * @param null|CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
187 | - * @param bool $id_as_key use the ID as key for the array? |
|
188 | - * @param bool $as_object return an array of objects? |
|
189 | - * |
|
190 | - * @param string $fields |
|
191 | - * @param bool $autoSort |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $fields = '*', $autoSort = true) |
|
195 | - { |
|
196 | - require_once __DIR__ . '/lite.php'; |
|
197 | - $ret = array(); |
|
198 | - $limit = $start = 0; |
|
199 | - $sql = 'SELECT ' . $fields . ' FROM ' . $this->table; |
|
200 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
201 | - $sql .= ' ' . $criteria->renderWhere(); |
|
202 | - if ($criteria->groupby != '') { |
|
203 | - $sql .= $criteria->getGroupby(); |
|
204 | - } |
|
205 | - if ($criteria->getSort() != '') { |
|
206 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
207 | - } elseif ($this->identifierName != '' && $autoSort) { |
|
208 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
209 | - } |
|
210 | - $limit = $criteria->getLimit(); |
|
211 | - $start = $criteria->getStart(); |
|
212 | - } |
|
213 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
214 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
215 | - $cacheData = $Cache_Lite->get($id); |
|
216 | - if ($cacheData === false) { |
|
217 | - $result = $this->db->query($sql, $limit, $start); |
|
218 | - if (!$result) { |
|
219 | - return $ret; |
|
220 | - } |
|
221 | - $ret = $this->convertResultSet($result, $id_as_key, $as_object, $fields); |
|
222 | - $Cache_Lite->save($ret); |
|
223 | - |
|
224 | - return $ret; |
|
225 | - } else { |
|
226 | - return $cacheData; |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Convert a database resultset to a returnable array |
|
232 | - * |
|
233 | - * @param object $result database resultset |
|
234 | - * @param boolean $id_as_key - should NOT be used with joint keys |
|
235 | - * @param boolean $as_object |
|
236 | - * @param string $fields Requested fields from the query |
|
237 | - * |
|
238 | - * @return array |
|
239 | - */ |
|
240 | - protected function convertResultSet($result, $id_as_key = false, $as_object = true, $fields = '*') |
|
241 | - { |
|
242 | - $ret = array(); |
|
243 | - while ($myrow = $this->db->fetchArray($result)) { |
|
244 | - $obj =& $this->create(false); |
|
245 | - $obj->assignVars($myrow); |
|
246 | - if (!$id_as_key) { |
|
247 | - if ($as_object) { |
|
248 | - $ret[] =& $obj; |
|
249 | - } else { |
|
250 | - $row = array(); |
|
251 | - $vars = $obj->getVars(); |
|
252 | - $tbl_tmp = array_keys($vars); |
|
253 | - foreach ($tbl_tmp as $i) { |
|
254 | - $row[$i] = $obj->getVar($i); |
|
255 | - } |
|
256 | - $ret[] = $row; |
|
257 | - } |
|
258 | - } else { |
|
259 | - if ($as_object) { |
|
260 | - if ($fields === '*') { |
|
261 | - $ret[$myrow[$this->keyName]] =& $obj; |
|
262 | - } else { |
|
263 | - $ret[] =& $obj; |
|
264 | - } |
|
265 | - } else { |
|
266 | - $row = array(); |
|
267 | - $vars = $obj->getVars(); |
|
268 | - $tbl_tmp = array_keys($vars); |
|
269 | - foreach ($tbl_tmp as $i) { |
|
270 | - $row[$i] = $obj->getVar($i); |
|
271 | - } |
|
272 | - $ret[$myrow[$this->keyName]] = $row; |
|
273 | - } |
|
274 | - } |
|
275 | - unset($obj); |
|
276 | - } |
|
277 | - |
|
278 | - return $ret; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * get IDs of objects matching a condition |
|
283 | - * |
|
284 | - * @param object $criteria {@link CriteriaElement} to match |
|
285 | - * @return array of object IDs |
|
286 | - */ |
|
287 | - public function getIds($criteria = null) |
|
288 | - { |
|
289 | - require_once __DIR__ . '/lite.php'; |
|
290 | - $limit = $start = 0; |
|
291 | - |
|
292 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
293 | - $sql = 'SELECT ' . $this->keyName . ' FROM ' . $this->table; |
|
294 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
295 | - $sql .= ' ' . $criteria->renderWhere(); |
|
296 | - if ($criteria->groupby != '') { |
|
297 | - $sql .= $criteria->getGroupby(); |
|
298 | - } |
|
299 | - if ($criteria->getSort() != '') { |
|
300 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
301 | - } elseif ($this->identifierName != '') { |
|
302 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
303 | - } |
|
304 | - $limit = $criteria->getLimit(); |
|
305 | - $start = $criteria->getStart(); |
|
306 | - } |
|
307 | - |
|
308 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
309 | - $cacheData = $Cache_Lite->get($id); |
|
310 | - if ($cacheData === false) { |
|
311 | - $result = $this->db->query($sql, $limit, $start); |
|
312 | - $ret = array(); |
|
313 | - while ($myrow = $this->db->fetchArray($result)) { |
|
314 | - $ret[] = $myrow[$this->keyName]; |
|
315 | - } |
|
316 | - $Cache_Lite->save($ret); |
|
317 | - |
|
318 | - return $ret; |
|
319 | - } else { |
|
320 | - return $cacheData; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
326 | - * |
|
327 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
328 | - * @return array |
|
329 | - */ |
|
330 | - public function getList($criteria = null) |
|
331 | - { |
|
332 | - require_once __DIR__ . '/lite.php'; |
|
333 | - $limit = $start = 0; |
|
334 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
335 | - |
|
336 | - $ret = array(); |
|
337 | - |
|
338 | - $sql = 'SELECT ' . $this->keyName; |
|
339 | - if (!empty($this->identifierName)) { |
|
340 | - $sql .= ', ' . $this->identifierName; |
|
341 | - } |
|
342 | - $sql .= ' FROM ' . $this->table; |
|
343 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
344 | - $sql .= ' ' . $criteria->renderWhere(); |
|
345 | - if ($criteria->groupby != '') { |
|
346 | - $sql .= $criteria->getGroupby(); |
|
347 | - } |
|
348 | - if ($criteria->getSort() != '') { |
|
349 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
350 | - } elseif ($this->identifierName != '') { |
|
351 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
352 | - } |
|
353 | - $limit = $criteria->getLimit(); |
|
354 | - $start = $criteria->getStart(); |
|
355 | - } |
|
356 | - |
|
357 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
358 | - $cacheData = $Cache_Lite->get($id); |
|
359 | - if ($cacheData === false) { |
|
360 | - $result = $this->db->query($sql, $limit, $start); |
|
361 | - if (!$result) { |
|
362 | - $Cache_Lite->save($ret); |
|
363 | - |
|
364 | - return $ret; |
|
365 | - } |
|
366 | - |
|
367 | - $myts = MyTextSanitizer::getInstance(); |
|
368 | - while ($myrow = $this->db->fetchArray($result)) { |
|
369 | - //identifiers should be textboxes, so sanitize them like that |
|
370 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->htmlSpecialChars($myrow[$this->identifierName]); |
|
371 | - } |
|
372 | - $Cache_Lite->save($ret); |
|
373 | - |
|
374 | - return $ret; |
|
375 | - } else { |
|
376 | - return $cacheData; |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Retourne des éléments selon leur ID |
|
382 | - * |
|
383 | - * @param array $ids Les ID des éléments à retrouver |
|
384 | - * @param null $additionnal |
|
385 | - * @return array Tableau d'objets |
|
386 | - */ |
|
387 | - public function getItemsFromIds($ids, $additionnal = null) |
|
388 | - { |
|
389 | - $ret = array(); |
|
390 | - if (is_array($ids) && count($ids) > 0) { |
|
391 | - $criteria = new CriteriaCompo(); |
|
392 | - $criteria->add(new Criteria($this->keyName, '(' . implode(',', $ids) . ')', 'IN')); |
|
393 | - if (!is_null($additionnal)) { |
|
394 | - $criteria->add($additionnal); |
|
395 | - } |
|
396 | - $ret =& $this->getObjects($criteria, true); |
|
397 | - } |
|
398 | - |
|
399 | - return $ret; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * count objects matching a condition |
|
404 | - * |
|
405 | - * @param object $criteria {@link CriteriaElement} to match |
|
406 | - * @return int count of objects |
|
407 | - */ |
|
408 | - public function getCount($criteria = null) |
|
409 | - { |
|
410 | - $field = ''; |
|
411 | - $groupby = false; |
|
412 | - $limit = $start = 0; |
|
413 | - require_once __DIR__ . '/lite.php'; |
|
414 | - |
|
415 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
416 | - if ($criteria->groupby != '') { |
|
417 | - $groupby = true; |
|
418 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
419 | - } |
|
420 | - } |
|
421 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table; |
|
422 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
423 | - $sql .= ' ' . $criteria->renderWhere(); |
|
424 | - if ($criteria->groupby != '') { |
|
425 | - $sql .= $criteria->getGroupby(); |
|
426 | - } |
|
427 | - $limit = $criteria->getLimit(); |
|
428 | - $start = $criteria->getStart(); |
|
429 | - } |
|
430 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
431 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
432 | - $cacheData = $Cache_Lite->get($id); |
|
433 | - if ($cacheData === false) { |
|
434 | - $result = $this->db->query($sql, $limit, $start); |
|
435 | - if (!$result) { |
|
436 | - $ret = 0; |
|
437 | - $Cache_Lite->save($ret); |
|
438 | - |
|
439 | - return $ret; |
|
440 | - } |
|
441 | - if ($groupby == false) { |
|
442 | - list($count) = $this->db->fetchRow($result); |
|
443 | - $Cache_Lite->save($count); |
|
444 | - |
|
445 | - return $count; |
|
446 | - } else { |
|
447 | - $ret = array(); |
|
448 | - while (list($id, $count) = $this->db->fetchRow($result)) { |
|
449 | - $ret[$id] = $count; |
|
450 | - } |
|
451 | - $Cache_Lite->save($ret); |
|
452 | - |
|
453 | - return $ret; |
|
454 | - } |
|
455 | - } else { |
|
456 | - return $cacheData; |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Retourne le total d'un champ |
|
462 | - * |
|
463 | - * @param string $field Le champ dont on veut calculer le total |
|
464 | - * @param object $criteria {@link CriteriaElement} to match |
|
465 | - * @return integer le total |
|
466 | - */ |
|
467 | - public function getSum($field, $criteria = null) |
|
468 | - { |
|
469 | - $limit = $start = 0; |
|
470 | - require_once __DIR__ . '/lite.php'; |
|
471 | - |
|
472 | - $sql = 'SELECT Sum(' . $field . ') as cpt FROM ' . $this->table; |
|
473 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
474 | - $sql .= ' ' . $criteria->renderWhere(); |
|
475 | - if ($criteria->groupby != '') { |
|
476 | - $sql .= $criteria->getGroupby(); |
|
477 | - } |
|
478 | - $limit = $criteria->getLimit(); |
|
479 | - $start = $criteria->getStart(); |
|
480 | - } |
|
481 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
482 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
483 | - $cacheData = $Cache_Lite->get($id); |
|
484 | - if ($cacheData === false) { |
|
485 | - $result = $this->db->query($sql, $limit, $start); |
|
486 | - if (!$result) { |
|
487 | - $ret = 0; |
|
488 | - $Cache_Lite->save($ret); |
|
489 | - |
|
490 | - return $ret; |
|
491 | - } |
|
492 | - $row = $this->db->fetchArray($result); |
|
493 | - $count = $row['cpt']; |
|
494 | - $Cache_Lite->save($count); |
|
495 | - |
|
496 | - return $count; |
|
497 | - } else { |
|
498 | - return $cacheData; |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * delete an object from the database |
|
504 | - * |
|
505 | - * @param XoopsObject $obj reference to the object to delete |
|
506 | - * @param bool $force |
|
507 | - * @return bool FALSE if failed. |
|
508 | - */ |
|
509 | - public function delete(XoopsObject $obj, $force = false) |
|
510 | - { |
|
511 | - if (is_array($this->keyName)) { |
|
512 | - $clause = array(); |
|
513 | - $vnb = count($this->keyName); |
|
514 | - for ($i = 0; $i < $vnb; ++$i) { |
|
515 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
516 | - } |
|
517 | - $whereclause = implode(' AND ', $clause); |
|
518 | - } else { |
|
519 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
520 | - } |
|
521 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
522 | - if (false != $force) { |
|
523 | - $result = $this->db->queryF($sql); |
|
524 | - } else { |
|
525 | - $result = $this->db->query($sql); |
|
526 | - } |
|
527 | - // Clear cache |
|
528 | - $this->forceCacheClean(); |
|
529 | - |
|
530 | - if (!$result) { |
|
531 | - return false; |
|
532 | - } |
|
533 | - |
|
534 | - return true; |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Quickly insert a record like this $myobject_handler->quickInsert('field1' => field1value, 'field2' => $field2value) |
|
539 | - * |
|
540 | - * @param array $vars Array containing the fields name and value |
|
541 | - * @param bool $force whether to force the query execution despite security settings |
|
542 | - * @return bool @link insert's value |
|
543 | - */ |
|
544 | - public function quickInsert($vars = null, $force = true) |
|
545 | - { |
|
546 | - $object = $this->create(true); |
|
547 | - $object->setVars($vars); |
|
548 | - $retval =& $this->insert($object, $force); |
|
549 | - unset($object); |
|
550 | - |
|
551 | - // Clear cache |
|
552 | - $this->forceCacheClean(); |
|
553 | - |
|
554 | - return $retval; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * insert a new object in the database |
|
559 | - * |
|
560 | - * @param XoopsObject $obj reference to the object |
|
561 | - * @param bool $force whether to force the query execution despite security settings |
|
562 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
563 | - * @param bool $ignoreInsert |
|
564 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
565 | - */ |
|
566 | - |
|
567 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true, $ignoreInsert = false) |
|
568 | - { |
|
569 | - if ($checkObject != false) { |
|
570 | - if (!is_object($obj)) { |
|
571 | - trigger_error('Error, not object'); |
|
572 | - |
|
573 | - return false; |
|
574 | - } |
|
575 | - /** |
|
576 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
577 | - */ |
|
578 | - if (!is_a($obj, $this->className)) { |
|
579 | - $obj->setErrors(get_class($obj) . ' Differs from ' . $this->className); |
|
580 | - |
|
581 | - return false; |
|
582 | - } |
|
583 | - if (!$obj->isDirty()) { |
|
584 | - $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
585 | - |
|
586 | - return true; |
|
587 | - } |
|
588 | - } |
|
589 | - if (!$obj->cleanVars()) { |
|
590 | - foreach ($obj->getErrors() as $oneerror) { |
|
591 | - trigger_error($oneerror); |
|
592 | - } |
|
593 | - |
|
594 | - return false; |
|
595 | - } |
|
596 | - foreach ($obj->cleanVars as $k => $v) { |
|
597 | - if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
598 | - $cleanvars[$k] = (int)$v; |
|
599 | - } elseif (is_array($v)) { |
|
600 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
601 | - } else { |
|
602 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
603 | - } |
|
604 | - } |
|
605 | - if (isset($cleanvars['dohtml'])) { // Modification Herv� to be able to use dohtml |
|
606 | - unset($cleanvars['dohtml']); |
|
607 | - } |
|
608 | - if ($obj->isNew()) { |
|
609 | - if (!is_array($this->keyName)) { |
|
610 | - if ($cleanvars[$this->keyName] < 1) { |
|
611 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
612 | - } |
|
613 | - } |
|
614 | - $ignore = ''; |
|
615 | - if ($ignoreInsert) { |
|
616 | - $ignore = 'IGNORE'; |
|
617 | - } |
|
618 | - $sql = "INSERT $ignore INTO " . $this->table . ' (' . implode(',', array_keys($cleanvars)) . ') VALUES (' . implode(',', array_values($cleanvars)) . ')'; |
|
619 | - } else { |
|
620 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
621 | - foreach ($cleanvars as $key => $value) { |
|
622 | - if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
623 | - continue; |
|
624 | - } |
|
625 | - if (isset($notfirst)) { |
|
626 | - $sql .= ','; |
|
627 | - } |
|
628 | - $sql .= ' ' . $key . ' = ' . $value; |
|
629 | - $notfirst = true; |
|
630 | - } |
|
631 | - if (is_array($this->keyName)) { |
|
632 | - $whereclause = ''; |
|
633 | - $vnb = count($this->keyName); |
|
634 | - for ($i = 0; $i < $vnb; ++$i) { |
|
635 | - if ($i > 0) { |
|
636 | - $whereclause .= ' AND '; |
|
637 | - } |
|
638 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
639 | - } |
|
640 | - } else { |
|
641 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
642 | - } |
|
643 | - $sql .= ' WHERE ' . $whereclause; |
|
644 | - } |
|
645 | - |
|
646 | - if (false != $force) { |
|
647 | - $result = $this->db->queryF($sql); |
|
648 | - } else { |
|
649 | - $result = $this->db->query($sql); |
|
650 | - } |
|
651 | - |
|
652 | - // Clear cache |
|
653 | - $this->forceCacheClean(); |
|
654 | - |
|
655 | - if (!$result) { |
|
656 | - return false; |
|
657 | - } |
|
658 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
659 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
660 | - } |
|
661 | - |
|
662 | - return true; |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Change a value for objects with a certain criteria |
|
667 | - * |
|
668 | - * @param string $fieldname Name of the field |
|
669 | - * @param string $fieldvalue Value to write |
|
670 | - * @param object $criteria {@link CriteriaElement} |
|
671 | - * |
|
672 | - * @param bool $force |
|
673 | - * @return bool |
|
674 | - */ |
|
675 | - public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
|
676 | - { |
|
677 | - $set_clause = $fieldname . ' = '; |
|
678 | - if (is_numeric($fieldvalue)) { |
|
679 | - $set_clause .= $fieldvalue; |
|
680 | - } elseif (is_array($fieldvalue)) { |
|
681 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
682 | - } else { |
|
683 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
684 | - } |
|
685 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
686 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
687 | - $sql .= ' ' . $criteria->renderWhere(); |
|
688 | - } |
|
689 | - if ($force) { |
|
690 | - $result = $this->db->queryF($sql); |
|
691 | - } else { |
|
692 | - $result = $this->db->query($sql); |
|
693 | - } |
|
694 | - |
|
695 | - // Clear cache |
|
696 | - $this->forceCacheClean(); |
|
697 | - |
|
698 | - if (!$result) { |
|
699 | - return false; |
|
700 | - } |
|
701 | - |
|
702 | - return true; |
|
703 | - } |
|
704 | - |
|
705 | - // check if target object is attempting to use duplicated info |
|
706 | - public function isDuplicated(&$obj, $field = '', $error = '') |
|
707 | - { |
|
708 | - if (empty($field)) { |
|
709 | - return false; |
|
710 | - } |
|
711 | - $criteria = new CriteriaCompo(); |
|
712 | - $criteria->add(new Criteria($field, $obj->getVar($field))); |
|
713 | - // one more condition if target object exisits in database |
|
714 | - if (!$obj->isNew()) { |
|
715 | - $criteria->add(new Criteria($this->_key, $obj->getVar($this->_key), '!=')); |
|
716 | - } |
|
717 | - if ($this->getCount($criteria)) { |
|
718 | - $obj->setErrors($error); |
|
719 | - |
|
720 | - return true; |
|
721 | - } |
|
722 | - |
|
723 | - return false; |
|
724 | - } |
|
725 | - |
|
726 | - /** |
|
727 | - * delete all objects meeting the conditions |
|
728 | - * |
|
729 | - * @param object $criteria {@link CriteriaElement} with conditions to meet |
|
730 | - * @return bool |
|
731 | - */ |
|
732 | - public function deleteAll($criteria = null) |
|
733 | - { |
|
734 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
735 | - $sql = 'DELETE FROM ' . $this->table; |
|
736 | - $sql .= ' ' . $criteria->renderWhere(); |
|
737 | - if (!$this->db->queryF($sql)) { |
|
738 | - return false; |
|
739 | - } |
|
740 | - $rows = $this->db->getAffectedRows(); |
|
741 | - |
|
742 | - // Clear cache |
|
743 | - $this->forceCacheClean(); |
|
744 | - |
|
745 | - return $rows > 0 ? $rows : true; |
|
746 | - } |
|
747 | - |
|
748 | - return false; |
|
749 | - } |
|
750 | - |
|
751 | - /** |
|
752 | - * Compare two objects and returns, in an array, the differences |
|
753 | - * |
|
754 | - * @param XoopsObject $old_object The first object to compare |
|
755 | - * @param XoopsObject $new_object The new object |
|
756 | - * @return array differences key = fieldname, value = array('old_value', 'new_value') |
|
757 | - */ |
|
758 | - public function compareObjects($old_object, $new_object) |
|
759 | - { |
|
760 | - $ret = array(); |
|
761 | - $vars_name = array_keys($old_object->getVars()); |
|
762 | - foreach ($vars_name as $one_var) { |
|
763 | - if ($old_object->getVar($one_var, 'f') == $new_object->getVar($one_var, 'f')) { |
|
764 | - } else { |
|
765 | - $ret[$one_var] = array($old_object->getVar($one_var), $new_object->getVar($one_var)); |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - return $ret; |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Get distincted values of a field in the table |
|
774 | - * |
|
775 | - * @param string $field Field's name |
|
776 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
777 | - * @param string $format Format in wich we want the datas |
|
778 | - * @return array containing the distinct values |
|
779 | - */ |
|
780 | - public function getDistincts($field, $criteria = null, $format = 's') |
|
781 | - { |
|
782 | - require_once __DIR__ . '/lite.php'; |
|
783 | - $limit = $start = 0; |
|
784 | - $sql = 'SELECT ' . $this->keyName . ', ' . $field . ' FROM ' . $this->table; |
|
785 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
786 | - $sql .= ' ' . $criteria->renderWhere(); |
|
787 | - $limit = $criteria->getLimit(); |
|
788 | - $start = $criteria->getStart(); |
|
789 | - } |
|
790 | - $sql .= ' GROUP BY ' . $field . ' ORDER BY ' . $field; |
|
791 | - |
|
792 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
793 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
794 | - $cacheData = $Cache_Lite->get($id); |
|
795 | - if ($cacheData === false) { |
|
796 | - $result = $this->db->query($sql, $limit, $start); |
|
797 | - $ret = array(); |
|
798 | - $obj = new $this->className(); |
|
799 | - while ($myrow = $this->db->fetchArray($result)) { |
|
800 | - $obj->setVar($field, $myrow[$field]); |
|
801 | - $ret[$myrow[$this->keyName]] = $obj->getVar($field, $format); |
|
802 | - } |
|
803 | - $Cache_Lite->save($ret); |
|
804 | - |
|
805 | - return $ret; |
|
806 | - } else { |
|
807 | - return $cacheData; |
|
808 | - } |
|
809 | - } |
|
810 | - |
|
811 | - /** |
|
812 | - * A generic shortcut to getObjects |
|
813 | - * |
|
814 | - * @author Herve Thouzard - Instant Zero |
|
815 | - * |
|
816 | - * @param integer $start Starting position |
|
817 | - * @param integer $limit Maximum count of elements to return |
|
818 | - * @param string $sort Field to use for the sort |
|
819 | - * @param string $order Sort order |
|
820 | - * @param boolean $idAsKey Do we have to return an array whoses keys are the record's ID ? |
|
821 | - * @return array Array of current objects |
|
822 | - */ |
|
823 | - public function getItems($start = 0, $limit = 0, $sort = '', $order = 'ASC', $idAsKey = true) |
|
824 | - { |
|
825 | - if (trim($order) == '') { |
|
826 | - if (isset($this->identifierName) && trim($this->identifierName) != '') { |
|
827 | - $order = $this->identifierName; |
|
828 | - } else { |
|
829 | - $order = $this->keyName; |
|
830 | - } |
|
831 | - } |
|
832 | - $items = array(); |
|
833 | - $critere = new Criteria($this->keyName, 0, '<>'); |
|
834 | - $critere->setLimit($limit); |
|
835 | - $critere->setStart($start); |
|
836 | - $critere->setSort($sort); |
|
837 | - $critere->setOrder($order); |
|
838 | - $items =& $this->getObjects($critere, $idAsKey); |
|
839 | - |
|
840 | - return $items; |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Forces the cache to be cleaned |
|
845 | - */ |
|
846 | - public function forceCacheClean() |
|
847 | - { |
|
848 | - require_once __DIR__ . '/lite.php'; |
|
849 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
850 | - $Cache_Lite->clean(); |
|
851 | - } |
|
83 | + public $table; |
|
84 | + public $keyName; |
|
85 | + public $className; |
|
86 | + public $identifierName; |
|
87 | + protected $cacheOptions = array(); |
|
88 | + /**#@-*/ |
|
89 | + |
|
90 | + /** |
|
91 | + * Constructor - called from child classes |
|
92 | + * @param object $db {@link XoopsDatabase} object |
|
93 | + * @param string $tablename Name of database table |
|
94 | + * @param string $classname Name of Class, this handler is managing |
|
95 | + * @param string $keyname Name of the property, holding the key |
|
96 | + * @param string $idenfierName Name of the property, holding the label |
|
97 | + * @param array $cacheOptions Optional, options for the cache |
|
98 | + * |
|
99 | + */ |
|
100 | + public function __construct(&$db, $tablename, $classname, $keyname, $idenfierName = '', $cacheOptions = null) |
|
101 | + { |
|
102 | + parent::__construct($db); |
|
103 | + $this->table = $db->prefix($tablename); |
|
104 | + $this->keyName = $keyname; |
|
105 | + $this->className = $classname; |
|
106 | + if (trim($idenfierName) != '') { |
|
107 | + $this->identifierName = $idenfierName; |
|
108 | + } |
|
109 | + // To diable cache, add this line after the first one : 'caching' => false, |
|
110 | + if (is_null($cacheOptions)) { |
|
111 | + $this->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
112 | + } else { |
|
113 | + $this->setCachingOptions($cacheOptions); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + public function setCachingOptions($cacheOptions) |
|
118 | + { |
|
119 | + $this->cacheOptions = $cacheOptions; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Generates a unique ID for a Sql Query |
|
124 | + * |
|
125 | + * @param string $query The SQL query for which we want a unidque ID |
|
126 | + * @param integer $start Which record to start at |
|
127 | + * @param integer $limit Max number of objects to fetch |
|
128 | + * @return string An MD5 of the query |
|
129 | + */ |
|
130 | + protected function _getIdForCache($query, $start, $limit) |
|
131 | + { |
|
132 | + $id = md5($query . '-' . (string)$start . '-' . (string)$limit); |
|
133 | + |
|
134 | + return $id; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * create a new object |
|
139 | + * |
|
140 | + * @param bool $isNew Flag the new objects as "new"? |
|
141 | + * |
|
142 | + * @return object |
|
143 | + */ |
|
144 | + public function &create($isNew = true) |
|
145 | + { |
|
146 | + $obj = new $this->className(); |
|
147 | + if ($isNew === true) { |
|
148 | + $obj->setNew(); |
|
149 | + } |
|
150 | + |
|
151 | + return $obj; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * retrieve an object |
|
156 | + * |
|
157 | + * @param mixed $id ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor |
|
158 | + * @param bool $as_object whether to return an object or an array |
|
159 | + * @return mixed reference to the object, FALSE if failed |
|
160 | + */ |
|
161 | + public function &get($id, $as_object = true) |
|
162 | + { |
|
163 | + if (is_array($this->keyName)) { |
|
164 | + $criteria = new CriteriaCompo(); |
|
165 | + $vnb = count($this->keyName); |
|
166 | + for ($i = 0; $i < $vnb; ++$i) { |
|
167 | + $criteria->add(new Criteria($this->keyName[$i], (int)$id[$i])); |
|
168 | + } |
|
169 | + } else { |
|
170 | + $criteria = new Criteria($this->keyName, (int)$id); |
|
171 | + } |
|
172 | + $criteria->setLimit(1); |
|
173 | + $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
174 | + if (count($obj_array) != 1) { |
|
175 | + $ret = null; |
|
176 | + } else { |
|
177 | + $ret =& $obj_array[0]; |
|
178 | + } |
|
179 | + |
|
180 | + return $ret; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * retrieve objects from the database |
|
185 | + * |
|
186 | + * @param null|CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
187 | + * @param bool $id_as_key use the ID as key for the array? |
|
188 | + * @param bool $as_object return an array of objects? |
|
189 | + * |
|
190 | + * @param string $fields |
|
191 | + * @param bool $autoSort |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $fields = '*', $autoSort = true) |
|
195 | + { |
|
196 | + require_once __DIR__ . '/lite.php'; |
|
197 | + $ret = array(); |
|
198 | + $limit = $start = 0; |
|
199 | + $sql = 'SELECT ' . $fields . ' FROM ' . $this->table; |
|
200 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
201 | + $sql .= ' ' . $criteria->renderWhere(); |
|
202 | + if ($criteria->groupby != '') { |
|
203 | + $sql .= $criteria->getGroupby(); |
|
204 | + } |
|
205 | + if ($criteria->getSort() != '') { |
|
206 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
207 | + } elseif ($this->identifierName != '' && $autoSort) { |
|
208 | + $sql .= ' ORDER BY ' . $this->identifierName; |
|
209 | + } |
|
210 | + $limit = $criteria->getLimit(); |
|
211 | + $start = $criteria->getStart(); |
|
212 | + } |
|
213 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
214 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
215 | + $cacheData = $Cache_Lite->get($id); |
|
216 | + if ($cacheData === false) { |
|
217 | + $result = $this->db->query($sql, $limit, $start); |
|
218 | + if (!$result) { |
|
219 | + return $ret; |
|
220 | + } |
|
221 | + $ret = $this->convertResultSet($result, $id_as_key, $as_object, $fields); |
|
222 | + $Cache_Lite->save($ret); |
|
223 | + |
|
224 | + return $ret; |
|
225 | + } else { |
|
226 | + return $cacheData; |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Convert a database resultset to a returnable array |
|
232 | + * |
|
233 | + * @param object $result database resultset |
|
234 | + * @param boolean $id_as_key - should NOT be used with joint keys |
|
235 | + * @param boolean $as_object |
|
236 | + * @param string $fields Requested fields from the query |
|
237 | + * |
|
238 | + * @return array |
|
239 | + */ |
|
240 | + protected function convertResultSet($result, $id_as_key = false, $as_object = true, $fields = '*') |
|
241 | + { |
|
242 | + $ret = array(); |
|
243 | + while ($myrow = $this->db->fetchArray($result)) { |
|
244 | + $obj =& $this->create(false); |
|
245 | + $obj->assignVars($myrow); |
|
246 | + if (!$id_as_key) { |
|
247 | + if ($as_object) { |
|
248 | + $ret[] =& $obj; |
|
249 | + } else { |
|
250 | + $row = array(); |
|
251 | + $vars = $obj->getVars(); |
|
252 | + $tbl_tmp = array_keys($vars); |
|
253 | + foreach ($tbl_tmp as $i) { |
|
254 | + $row[$i] = $obj->getVar($i); |
|
255 | + } |
|
256 | + $ret[] = $row; |
|
257 | + } |
|
258 | + } else { |
|
259 | + if ($as_object) { |
|
260 | + if ($fields === '*') { |
|
261 | + $ret[$myrow[$this->keyName]] =& $obj; |
|
262 | + } else { |
|
263 | + $ret[] =& $obj; |
|
264 | + } |
|
265 | + } else { |
|
266 | + $row = array(); |
|
267 | + $vars = $obj->getVars(); |
|
268 | + $tbl_tmp = array_keys($vars); |
|
269 | + foreach ($tbl_tmp as $i) { |
|
270 | + $row[$i] = $obj->getVar($i); |
|
271 | + } |
|
272 | + $ret[$myrow[$this->keyName]] = $row; |
|
273 | + } |
|
274 | + } |
|
275 | + unset($obj); |
|
276 | + } |
|
277 | + |
|
278 | + return $ret; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * get IDs of objects matching a condition |
|
283 | + * |
|
284 | + * @param object $criteria {@link CriteriaElement} to match |
|
285 | + * @return array of object IDs |
|
286 | + */ |
|
287 | + public function getIds($criteria = null) |
|
288 | + { |
|
289 | + require_once __DIR__ . '/lite.php'; |
|
290 | + $limit = $start = 0; |
|
291 | + |
|
292 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
293 | + $sql = 'SELECT ' . $this->keyName . ' FROM ' . $this->table; |
|
294 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
295 | + $sql .= ' ' . $criteria->renderWhere(); |
|
296 | + if ($criteria->groupby != '') { |
|
297 | + $sql .= $criteria->getGroupby(); |
|
298 | + } |
|
299 | + if ($criteria->getSort() != '') { |
|
300 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
301 | + } elseif ($this->identifierName != '') { |
|
302 | + $sql .= ' ORDER BY ' . $this->identifierName; |
|
303 | + } |
|
304 | + $limit = $criteria->getLimit(); |
|
305 | + $start = $criteria->getStart(); |
|
306 | + } |
|
307 | + |
|
308 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
309 | + $cacheData = $Cache_Lite->get($id); |
|
310 | + if ($cacheData === false) { |
|
311 | + $result = $this->db->query($sql, $limit, $start); |
|
312 | + $ret = array(); |
|
313 | + while ($myrow = $this->db->fetchArray($result)) { |
|
314 | + $ret[] = $myrow[$this->keyName]; |
|
315 | + } |
|
316 | + $Cache_Lite->save($ret); |
|
317 | + |
|
318 | + return $ret; |
|
319 | + } else { |
|
320 | + return $cacheData; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
326 | + * |
|
327 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
328 | + * @return array |
|
329 | + */ |
|
330 | + public function getList($criteria = null) |
|
331 | + { |
|
332 | + require_once __DIR__ . '/lite.php'; |
|
333 | + $limit = $start = 0; |
|
334 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
335 | + |
|
336 | + $ret = array(); |
|
337 | + |
|
338 | + $sql = 'SELECT ' . $this->keyName; |
|
339 | + if (!empty($this->identifierName)) { |
|
340 | + $sql .= ', ' . $this->identifierName; |
|
341 | + } |
|
342 | + $sql .= ' FROM ' . $this->table; |
|
343 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
344 | + $sql .= ' ' . $criteria->renderWhere(); |
|
345 | + if ($criteria->groupby != '') { |
|
346 | + $sql .= $criteria->getGroupby(); |
|
347 | + } |
|
348 | + if ($criteria->getSort() != '') { |
|
349 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
350 | + } elseif ($this->identifierName != '') { |
|
351 | + $sql .= ' ORDER BY ' . $this->identifierName; |
|
352 | + } |
|
353 | + $limit = $criteria->getLimit(); |
|
354 | + $start = $criteria->getStart(); |
|
355 | + } |
|
356 | + |
|
357 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
358 | + $cacheData = $Cache_Lite->get($id); |
|
359 | + if ($cacheData === false) { |
|
360 | + $result = $this->db->query($sql, $limit, $start); |
|
361 | + if (!$result) { |
|
362 | + $Cache_Lite->save($ret); |
|
363 | + |
|
364 | + return $ret; |
|
365 | + } |
|
366 | + |
|
367 | + $myts = MyTextSanitizer::getInstance(); |
|
368 | + while ($myrow = $this->db->fetchArray($result)) { |
|
369 | + //identifiers should be textboxes, so sanitize them like that |
|
370 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->htmlSpecialChars($myrow[$this->identifierName]); |
|
371 | + } |
|
372 | + $Cache_Lite->save($ret); |
|
373 | + |
|
374 | + return $ret; |
|
375 | + } else { |
|
376 | + return $cacheData; |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Retourne des éléments selon leur ID |
|
382 | + * |
|
383 | + * @param array $ids Les ID des éléments à retrouver |
|
384 | + * @param null $additionnal |
|
385 | + * @return array Tableau d'objets |
|
386 | + */ |
|
387 | + public function getItemsFromIds($ids, $additionnal = null) |
|
388 | + { |
|
389 | + $ret = array(); |
|
390 | + if (is_array($ids) && count($ids) > 0) { |
|
391 | + $criteria = new CriteriaCompo(); |
|
392 | + $criteria->add(new Criteria($this->keyName, '(' . implode(',', $ids) . ')', 'IN')); |
|
393 | + if (!is_null($additionnal)) { |
|
394 | + $criteria->add($additionnal); |
|
395 | + } |
|
396 | + $ret =& $this->getObjects($criteria, true); |
|
397 | + } |
|
398 | + |
|
399 | + return $ret; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * count objects matching a condition |
|
404 | + * |
|
405 | + * @param object $criteria {@link CriteriaElement} to match |
|
406 | + * @return int count of objects |
|
407 | + */ |
|
408 | + public function getCount($criteria = null) |
|
409 | + { |
|
410 | + $field = ''; |
|
411 | + $groupby = false; |
|
412 | + $limit = $start = 0; |
|
413 | + require_once __DIR__ . '/lite.php'; |
|
414 | + |
|
415 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
416 | + if ($criteria->groupby != '') { |
|
417 | + $groupby = true; |
|
418 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
419 | + } |
|
420 | + } |
|
421 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table; |
|
422 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
423 | + $sql .= ' ' . $criteria->renderWhere(); |
|
424 | + if ($criteria->groupby != '') { |
|
425 | + $sql .= $criteria->getGroupby(); |
|
426 | + } |
|
427 | + $limit = $criteria->getLimit(); |
|
428 | + $start = $criteria->getStart(); |
|
429 | + } |
|
430 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
431 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
432 | + $cacheData = $Cache_Lite->get($id); |
|
433 | + if ($cacheData === false) { |
|
434 | + $result = $this->db->query($sql, $limit, $start); |
|
435 | + if (!$result) { |
|
436 | + $ret = 0; |
|
437 | + $Cache_Lite->save($ret); |
|
438 | + |
|
439 | + return $ret; |
|
440 | + } |
|
441 | + if ($groupby == false) { |
|
442 | + list($count) = $this->db->fetchRow($result); |
|
443 | + $Cache_Lite->save($count); |
|
444 | + |
|
445 | + return $count; |
|
446 | + } else { |
|
447 | + $ret = array(); |
|
448 | + while (list($id, $count) = $this->db->fetchRow($result)) { |
|
449 | + $ret[$id] = $count; |
|
450 | + } |
|
451 | + $Cache_Lite->save($ret); |
|
452 | + |
|
453 | + return $ret; |
|
454 | + } |
|
455 | + } else { |
|
456 | + return $cacheData; |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Retourne le total d'un champ |
|
462 | + * |
|
463 | + * @param string $field Le champ dont on veut calculer le total |
|
464 | + * @param object $criteria {@link CriteriaElement} to match |
|
465 | + * @return integer le total |
|
466 | + */ |
|
467 | + public function getSum($field, $criteria = null) |
|
468 | + { |
|
469 | + $limit = $start = 0; |
|
470 | + require_once __DIR__ . '/lite.php'; |
|
471 | + |
|
472 | + $sql = 'SELECT Sum(' . $field . ') as cpt FROM ' . $this->table; |
|
473 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
474 | + $sql .= ' ' . $criteria->renderWhere(); |
|
475 | + if ($criteria->groupby != '') { |
|
476 | + $sql .= $criteria->getGroupby(); |
|
477 | + } |
|
478 | + $limit = $criteria->getLimit(); |
|
479 | + $start = $criteria->getStart(); |
|
480 | + } |
|
481 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
482 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
483 | + $cacheData = $Cache_Lite->get($id); |
|
484 | + if ($cacheData === false) { |
|
485 | + $result = $this->db->query($sql, $limit, $start); |
|
486 | + if (!$result) { |
|
487 | + $ret = 0; |
|
488 | + $Cache_Lite->save($ret); |
|
489 | + |
|
490 | + return $ret; |
|
491 | + } |
|
492 | + $row = $this->db->fetchArray($result); |
|
493 | + $count = $row['cpt']; |
|
494 | + $Cache_Lite->save($count); |
|
495 | + |
|
496 | + return $count; |
|
497 | + } else { |
|
498 | + return $cacheData; |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * delete an object from the database |
|
504 | + * |
|
505 | + * @param XoopsObject $obj reference to the object to delete |
|
506 | + * @param bool $force |
|
507 | + * @return bool FALSE if failed. |
|
508 | + */ |
|
509 | + public function delete(XoopsObject $obj, $force = false) |
|
510 | + { |
|
511 | + if (is_array($this->keyName)) { |
|
512 | + $clause = array(); |
|
513 | + $vnb = count($this->keyName); |
|
514 | + for ($i = 0; $i < $vnb; ++$i) { |
|
515 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
516 | + } |
|
517 | + $whereclause = implode(' AND ', $clause); |
|
518 | + } else { |
|
519 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
520 | + } |
|
521 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
522 | + if (false != $force) { |
|
523 | + $result = $this->db->queryF($sql); |
|
524 | + } else { |
|
525 | + $result = $this->db->query($sql); |
|
526 | + } |
|
527 | + // Clear cache |
|
528 | + $this->forceCacheClean(); |
|
529 | + |
|
530 | + if (!$result) { |
|
531 | + return false; |
|
532 | + } |
|
533 | + |
|
534 | + return true; |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Quickly insert a record like this $myobject_handler->quickInsert('field1' => field1value, 'field2' => $field2value) |
|
539 | + * |
|
540 | + * @param array $vars Array containing the fields name and value |
|
541 | + * @param bool $force whether to force the query execution despite security settings |
|
542 | + * @return bool @link insert's value |
|
543 | + */ |
|
544 | + public function quickInsert($vars = null, $force = true) |
|
545 | + { |
|
546 | + $object = $this->create(true); |
|
547 | + $object->setVars($vars); |
|
548 | + $retval =& $this->insert($object, $force); |
|
549 | + unset($object); |
|
550 | + |
|
551 | + // Clear cache |
|
552 | + $this->forceCacheClean(); |
|
553 | + |
|
554 | + return $retval; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * insert a new object in the database |
|
559 | + * |
|
560 | + * @param XoopsObject $obj reference to the object |
|
561 | + * @param bool $force whether to force the query execution despite security settings |
|
562 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
563 | + * @param bool $ignoreInsert |
|
564 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
565 | + */ |
|
566 | + |
|
567 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true, $ignoreInsert = false) |
|
568 | + { |
|
569 | + if ($checkObject != false) { |
|
570 | + if (!is_object($obj)) { |
|
571 | + trigger_error('Error, not object'); |
|
572 | + |
|
573 | + return false; |
|
574 | + } |
|
575 | + /** |
|
576 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
577 | + */ |
|
578 | + if (!is_a($obj, $this->className)) { |
|
579 | + $obj->setErrors(get_class($obj) . ' Differs from ' . $this->className); |
|
580 | + |
|
581 | + return false; |
|
582 | + } |
|
583 | + if (!$obj->isDirty()) { |
|
584 | + $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith |
|
585 | + |
|
586 | + return true; |
|
587 | + } |
|
588 | + } |
|
589 | + if (!$obj->cleanVars()) { |
|
590 | + foreach ($obj->getErrors() as $oneerror) { |
|
591 | + trigger_error($oneerror); |
|
592 | + } |
|
593 | + |
|
594 | + return false; |
|
595 | + } |
|
596 | + foreach ($obj->cleanVars as $k => $v) { |
|
597 | + if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
598 | + $cleanvars[$k] = (int)$v; |
|
599 | + } elseif (is_array($v)) { |
|
600 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
601 | + } else { |
|
602 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
603 | + } |
|
604 | + } |
|
605 | + if (isset($cleanvars['dohtml'])) { // Modification Herv� to be able to use dohtml |
|
606 | + unset($cleanvars['dohtml']); |
|
607 | + } |
|
608 | + if ($obj->isNew()) { |
|
609 | + if (!is_array($this->keyName)) { |
|
610 | + if ($cleanvars[$this->keyName] < 1) { |
|
611 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
612 | + } |
|
613 | + } |
|
614 | + $ignore = ''; |
|
615 | + if ($ignoreInsert) { |
|
616 | + $ignore = 'IGNORE'; |
|
617 | + } |
|
618 | + $sql = "INSERT $ignore INTO " . $this->table . ' (' . implode(',', array_keys($cleanvars)) . ') VALUES (' . implode(',', array_values($cleanvars)) . ')'; |
|
619 | + } else { |
|
620 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
621 | + foreach ($cleanvars as $key => $value) { |
|
622 | + if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
623 | + continue; |
|
624 | + } |
|
625 | + if (isset($notfirst)) { |
|
626 | + $sql .= ','; |
|
627 | + } |
|
628 | + $sql .= ' ' . $key . ' = ' . $value; |
|
629 | + $notfirst = true; |
|
630 | + } |
|
631 | + if (is_array($this->keyName)) { |
|
632 | + $whereclause = ''; |
|
633 | + $vnb = count($this->keyName); |
|
634 | + for ($i = 0; $i < $vnb; ++$i) { |
|
635 | + if ($i > 0) { |
|
636 | + $whereclause .= ' AND '; |
|
637 | + } |
|
638 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
639 | + } |
|
640 | + } else { |
|
641 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
642 | + } |
|
643 | + $sql .= ' WHERE ' . $whereclause; |
|
644 | + } |
|
645 | + |
|
646 | + if (false != $force) { |
|
647 | + $result = $this->db->queryF($sql); |
|
648 | + } else { |
|
649 | + $result = $this->db->query($sql); |
|
650 | + } |
|
651 | + |
|
652 | + // Clear cache |
|
653 | + $this->forceCacheClean(); |
|
654 | + |
|
655 | + if (!$result) { |
|
656 | + return false; |
|
657 | + } |
|
658 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
659 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
660 | + } |
|
661 | + |
|
662 | + return true; |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Change a value for objects with a certain criteria |
|
667 | + * |
|
668 | + * @param string $fieldname Name of the field |
|
669 | + * @param string $fieldvalue Value to write |
|
670 | + * @param object $criteria {@link CriteriaElement} |
|
671 | + * |
|
672 | + * @param bool $force |
|
673 | + * @return bool |
|
674 | + */ |
|
675 | + public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
|
676 | + { |
|
677 | + $set_clause = $fieldname . ' = '; |
|
678 | + if (is_numeric($fieldvalue)) { |
|
679 | + $set_clause .= $fieldvalue; |
|
680 | + } elseif (is_array($fieldvalue)) { |
|
681 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
682 | + } else { |
|
683 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
684 | + } |
|
685 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
686 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
687 | + $sql .= ' ' . $criteria->renderWhere(); |
|
688 | + } |
|
689 | + if ($force) { |
|
690 | + $result = $this->db->queryF($sql); |
|
691 | + } else { |
|
692 | + $result = $this->db->query($sql); |
|
693 | + } |
|
694 | + |
|
695 | + // Clear cache |
|
696 | + $this->forceCacheClean(); |
|
697 | + |
|
698 | + if (!$result) { |
|
699 | + return false; |
|
700 | + } |
|
701 | + |
|
702 | + return true; |
|
703 | + } |
|
704 | + |
|
705 | + // check if target object is attempting to use duplicated info |
|
706 | + public function isDuplicated(&$obj, $field = '', $error = '') |
|
707 | + { |
|
708 | + if (empty($field)) { |
|
709 | + return false; |
|
710 | + } |
|
711 | + $criteria = new CriteriaCompo(); |
|
712 | + $criteria->add(new Criteria($field, $obj->getVar($field))); |
|
713 | + // one more condition if target object exisits in database |
|
714 | + if (!$obj->isNew()) { |
|
715 | + $criteria->add(new Criteria($this->_key, $obj->getVar($this->_key), '!=')); |
|
716 | + } |
|
717 | + if ($this->getCount($criteria)) { |
|
718 | + $obj->setErrors($error); |
|
719 | + |
|
720 | + return true; |
|
721 | + } |
|
722 | + |
|
723 | + return false; |
|
724 | + } |
|
725 | + |
|
726 | + /** |
|
727 | + * delete all objects meeting the conditions |
|
728 | + * |
|
729 | + * @param object $criteria {@link CriteriaElement} with conditions to meet |
|
730 | + * @return bool |
|
731 | + */ |
|
732 | + public function deleteAll($criteria = null) |
|
733 | + { |
|
734 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
735 | + $sql = 'DELETE FROM ' . $this->table; |
|
736 | + $sql .= ' ' . $criteria->renderWhere(); |
|
737 | + if (!$this->db->queryF($sql)) { |
|
738 | + return false; |
|
739 | + } |
|
740 | + $rows = $this->db->getAffectedRows(); |
|
741 | + |
|
742 | + // Clear cache |
|
743 | + $this->forceCacheClean(); |
|
744 | + |
|
745 | + return $rows > 0 ? $rows : true; |
|
746 | + } |
|
747 | + |
|
748 | + return false; |
|
749 | + } |
|
750 | + |
|
751 | + /** |
|
752 | + * Compare two objects and returns, in an array, the differences |
|
753 | + * |
|
754 | + * @param XoopsObject $old_object The first object to compare |
|
755 | + * @param XoopsObject $new_object The new object |
|
756 | + * @return array differences key = fieldname, value = array('old_value', 'new_value') |
|
757 | + */ |
|
758 | + public function compareObjects($old_object, $new_object) |
|
759 | + { |
|
760 | + $ret = array(); |
|
761 | + $vars_name = array_keys($old_object->getVars()); |
|
762 | + foreach ($vars_name as $one_var) { |
|
763 | + if ($old_object->getVar($one_var, 'f') == $new_object->getVar($one_var, 'f')) { |
|
764 | + } else { |
|
765 | + $ret[$one_var] = array($old_object->getVar($one_var), $new_object->getVar($one_var)); |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + return $ret; |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Get distincted values of a field in the table |
|
774 | + * |
|
775 | + * @param string $field Field's name |
|
776 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
777 | + * @param string $format Format in wich we want the datas |
|
778 | + * @return array containing the distinct values |
|
779 | + */ |
|
780 | + public function getDistincts($field, $criteria = null, $format = 's') |
|
781 | + { |
|
782 | + require_once __DIR__ . '/lite.php'; |
|
783 | + $limit = $start = 0; |
|
784 | + $sql = 'SELECT ' . $this->keyName . ', ' . $field . ' FROM ' . $this->table; |
|
785 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
786 | + $sql .= ' ' . $criteria->renderWhere(); |
|
787 | + $limit = $criteria->getLimit(); |
|
788 | + $start = $criteria->getStart(); |
|
789 | + } |
|
790 | + $sql .= ' GROUP BY ' . $field . ' ORDER BY ' . $field; |
|
791 | + |
|
792 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
793 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
794 | + $cacheData = $Cache_Lite->get($id); |
|
795 | + if ($cacheData === false) { |
|
796 | + $result = $this->db->query($sql, $limit, $start); |
|
797 | + $ret = array(); |
|
798 | + $obj = new $this->className(); |
|
799 | + while ($myrow = $this->db->fetchArray($result)) { |
|
800 | + $obj->setVar($field, $myrow[$field]); |
|
801 | + $ret[$myrow[$this->keyName]] = $obj->getVar($field, $format); |
|
802 | + } |
|
803 | + $Cache_Lite->save($ret); |
|
804 | + |
|
805 | + return $ret; |
|
806 | + } else { |
|
807 | + return $cacheData; |
|
808 | + } |
|
809 | + } |
|
810 | + |
|
811 | + /** |
|
812 | + * A generic shortcut to getObjects |
|
813 | + * |
|
814 | + * @author Herve Thouzard - Instant Zero |
|
815 | + * |
|
816 | + * @param integer $start Starting position |
|
817 | + * @param integer $limit Maximum count of elements to return |
|
818 | + * @param string $sort Field to use for the sort |
|
819 | + * @param string $order Sort order |
|
820 | + * @param boolean $idAsKey Do we have to return an array whoses keys are the record's ID ? |
|
821 | + * @return array Array of current objects |
|
822 | + */ |
|
823 | + public function getItems($start = 0, $limit = 0, $sort = '', $order = 'ASC', $idAsKey = true) |
|
824 | + { |
|
825 | + if (trim($order) == '') { |
|
826 | + if (isset($this->identifierName) && trim($this->identifierName) != '') { |
|
827 | + $order = $this->identifierName; |
|
828 | + } else { |
|
829 | + $order = $this->keyName; |
|
830 | + } |
|
831 | + } |
|
832 | + $items = array(); |
|
833 | + $critere = new Criteria($this->keyName, 0, '<>'); |
|
834 | + $critere->setLimit($limit); |
|
835 | + $critere->setStart($start); |
|
836 | + $critere->setSort($sort); |
|
837 | + $critere->setOrder($order); |
|
838 | + $items =& $this->getObjects($critere, $idAsKey); |
|
839 | + |
|
840 | + return $items; |
|
841 | + } |
|
842 | + |
|
843 | + /** |
|
844 | + * Forces the cache to be cleaned |
|
845 | + */ |
|
846 | + public function forceCacheClean() |
|
847 | + { |
|
848 | + require_once __DIR__ . '/lite.php'; |
|
849 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
850 | + $Cache_Lite->clean(); |
|
851 | + } |
|
852 | 852 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | protected function _getIdForCache($query, $start, $limit) |
131 | 131 | { |
132 | - $id = md5($query . '-' . (string)$start . '-' . (string)$limit); |
|
132 | + $id = md5($query.'-'.(string) $start.'-'.(string) $limit); |
|
133 | 133 | |
134 | 134 | return $id; |
135 | 135 | } |
@@ -164,17 +164,17 @@ discard block |
||
164 | 164 | $criteria = new CriteriaCompo(); |
165 | 165 | $vnb = count($this->keyName); |
166 | 166 | for ($i = 0; $i < $vnb; ++$i) { |
167 | - $criteria->add(new Criteria($this->keyName[$i], (int)$id[$i])); |
|
167 | + $criteria->add(new Criteria($this->keyName[$i], (int) $id[$i])); |
|
168 | 168 | } |
169 | 169 | } else { |
170 | - $criteria = new Criteria($this->keyName, (int)$id); |
|
170 | + $criteria = new Criteria($this->keyName, (int) $id); |
|
171 | 171 | } |
172 | 172 | $criteria->setLimit(1); |
173 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
173 | + $obj_array = & $this->getObjects($criteria, false, $as_object); |
|
174 | 174 | if (count($obj_array) != 1) { |
175 | 175 | $ret = null; |
176 | 176 | } else { |
177 | - $ret =& $obj_array[0]; |
|
177 | + $ret = & $obj_array[0]; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | return $ret; |
@@ -193,19 +193,19 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $fields = '*', $autoSort = true) |
195 | 195 | { |
196 | - require_once __DIR__ . '/lite.php'; |
|
196 | + require_once __DIR__.'/lite.php'; |
|
197 | 197 | $ret = array(); |
198 | 198 | $limit = $start = 0; |
199 | - $sql = 'SELECT ' . $fields . ' FROM ' . $this->table; |
|
199 | + $sql = 'SELECT '.$fields.' FROM '.$this->table; |
|
200 | 200 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
201 | - $sql .= ' ' . $criteria->renderWhere(); |
|
201 | + $sql .= ' '.$criteria->renderWhere(); |
|
202 | 202 | if ($criteria->groupby != '') { |
203 | 203 | $sql .= $criteria->getGroupby(); |
204 | 204 | } |
205 | 205 | if ($criteria->getSort() != '') { |
206 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
206 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
207 | 207 | } elseif ($this->identifierName != '' && $autoSort) { |
208 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
208 | + $sql .= ' ORDER BY '.$this->identifierName; |
|
209 | 209 | } |
210 | 210 | $limit = $criteria->getLimit(); |
211 | 211 | $start = $criteria->getStart(); |
@@ -241,11 +241,11 @@ discard block |
||
241 | 241 | { |
242 | 242 | $ret = array(); |
243 | 243 | while ($myrow = $this->db->fetchArray($result)) { |
244 | - $obj =& $this->create(false); |
|
244 | + $obj = & $this->create(false); |
|
245 | 245 | $obj->assignVars($myrow); |
246 | 246 | if (!$id_as_key) { |
247 | 247 | if ($as_object) { |
248 | - $ret[] =& $obj; |
|
248 | + $ret[] = & $obj; |
|
249 | 249 | } else { |
250 | 250 | $row = array(); |
251 | 251 | $vars = $obj->getVars(); |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | } else { |
259 | 259 | if ($as_object) { |
260 | 260 | if ($fields === '*') { |
261 | - $ret[$myrow[$this->keyName]] =& $obj; |
|
261 | + $ret[$myrow[$this->keyName]] = & $obj; |
|
262 | 262 | } else { |
263 | - $ret[] =& $obj; |
|
263 | + $ret[] = & $obj; |
|
264 | 264 | } |
265 | 265 | } else { |
266 | 266 | $row = array(); |
@@ -286,20 +286,20 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function getIds($criteria = null) |
288 | 288 | { |
289 | - require_once __DIR__ . '/lite.php'; |
|
289 | + require_once __DIR__.'/lite.php'; |
|
290 | 290 | $limit = $start = 0; |
291 | 291 | |
292 | 292 | $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
293 | - $sql = 'SELECT ' . $this->keyName . ' FROM ' . $this->table; |
|
293 | + $sql = 'SELECT '.$this->keyName.' FROM '.$this->table; |
|
294 | 294 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
295 | - $sql .= ' ' . $criteria->renderWhere(); |
|
295 | + $sql .= ' '.$criteria->renderWhere(); |
|
296 | 296 | if ($criteria->groupby != '') { |
297 | 297 | $sql .= $criteria->getGroupby(); |
298 | 298 | } |
299 | 299 | if ($criteria->getSort() != '') { |
300 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
300 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
301 | 301 | } elseif ($this->identifierName != '') { |
302 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
302 | + $sql .= ' ORDER BY '.$this->identifierName; |
|
303 | 303 | } |
304 | 304 | $limit = $criteria->getLimit(); |
305 | 305 | $start = $criteria->getStart(); |
@@ -329,26 +329,26 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public function getList($criteria = null) |
331 | 331 | { |
332 | - require_once __DIR__ . '/lite.php'; |
|
332 | + require_once __DIR__.'/lite.php'; |
|
333 | 333 | $limit = $start = 0; |
334 | 334 | $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
335 | 335 | |
336 | 336 | $ret = array(); |
337 | 337 | |
338 | - $sql = 'SELECT ' . $this->keyName; |
|
338 | + $sql = 'SELECT '.$this->keyName; |
|
339 | 339 | if (!empty($this->identifierName)) { |
340 | - $sql .= ', ' . $this->identifierName; |
|
340 | + $sql .= ', '.$this->identifierName; |
|
341 | 341 | } |
342 | - $sql .= ' FROM ' . $this->table; |
|
342 | + $sql .= ' FROM '.$this->table; |
|
343 | 343 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
344 | - $sql .= ' ' . $criteria->renderWhere(); |
|
344 | + $sql .= ' '.$criteria->renderWhere(); |
|
345 | 345 | if ($criteria->groupby != '') { |
346 | 346 | $sql .= $criteria->getGroupby(); |
347 | 347 | } |
348 | 348 | if ($criteria->getSort() != '') { |
349 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
349 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
350 | 350 | } elseif ($this->identifierName != '') { |
351 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
351 | + $sql .= ' ORDER BY '.$this->identifierName; |
|
352 | 352 | } |
353 | 353 | $limit = $criteria->getLimit(); |
354 | 354 | $start = $criteria->getStart(); |
@@ -389,11 +389,11 @@ discard block |
||
389 | 389 | $ret = array(); |
390 | 390 | if (is_array($ids) && count($ids) > 0) { |
391 | 391 | $criteria = new CriteriaCompo(); |
392 | - $criteria->add(new Criteria($this->keyName, '(' . implode(',', $ids) . ')', 'IN')); |
|
392 | + $criteria->add(new Criteria($this->keyName, '('.implode(',', $ids).')', 'IN')); |
|
393 | 393 | if (!is_null($additionnal)) { |
394 | 394 | $criteria->add($additionnal); |
395 | 395 | } |
396 | - $ret =& $this->getObjects($criteria, true); |
|
396 | + $ret = & $this->getObjects($criteria, true); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | return $ret; |
@@ -410,17 +410,17 @@ discard block |
||
410 | 410 | $field = ''; |
411 | 411 | $groupby = false; |
412 | 412 | $limit = $start = 0; |
413 | - require_once __DIR__ . '/lite.php'; |
|
413 | + require_once __DIR__.'/lite.php'; |
|
414 | 414 | |
415 | 415 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
416 | 416 | if ($criteria->groupby != '') { |
417 | 417 | $groupby = true; |
418 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
418 | + $field = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
419 | 419 | } |
420 | 420 | } |
421 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table; |
|
421 | + $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table; |
|
422 | 422 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
423 | - $sql .= ' ' . $criteria->renderWhere(); |
|
423 | + $sql .= ' '.$criteria->renderWhere(); |
|
424 | 424 | if ($criteria->groupby != '') { |
425 | 425 | $sql .= $criteria->getGroupby(); |
426 | 426 | } |
@@ -467,11 +467,11 @@ discard block |
||
467 | 467 | public function getSum($field, $criteria = null) |
468 | 468 | { |
469 | 469 | $limit = $start = 0; |
470 | - require_once __DIR__ . '/lite.php'; |
|
470 | + require_once __DIR__.'/lite.php'; |
|
471 | 471 | |
472 | - $sql = 'SELECT Sum(' . $field . ') as cpt FROM ' . $this->table; |
|
472 | + $sql = 'SELECT Sum('.$field.') as cpt FROM '.$this->table; |
|
473 | 473 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
474 | - $sql .= ' ' . $criteria->renderWhere(); |
|
474 | + $sql .= ' '.$criteria->renderWhere(); |
|
475 | 475 | if ($criteria->groupby != '') { |
476 | 476 | $sql .= $criteria->getGroupby(); |
477 | 477 | } |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | $clause = array(); |
513 | 513 | $vnb = count($this->keyName); |
514 | 514 | for ($i = 0; $i < $vnb; ++$i) { |
515 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
515 | + $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
516 | 516 | } |
517 | 517 | $whereclause = implode(' AND ', $clause); |
518 | 518 | } else { |
519 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
519 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
520 | 520 | } |
521 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
521 | + $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause; |
|
522 | 522 | if (false != $force) { |
523 | 523 | $result = $this->db->queryF($sql); |
524 | 524 | } else { |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | { |
546 | 546 | $object = $this->create(true); |
547 | 547 | $object->setVars($vars); |
548 | - $retval =& $this->insert($object, $force); |
|
548 | + $retval = & $this->insert($object, $force); |
|
549 | 549 | unset($object); |
550 | 550 | |
551 | 551 | // Clear cache |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
577 | 577 | */ |
578 | 578 | if (!is_a($obj, $this->className)) { |
579 | - $obj->setErrors(get_class($obj) . ' Differs from ' . $this->className); |
|
579 | + $obj->setErrors(get_class($obj).' Differs from '.$this->className); |
|
580 | 580 | |
581 | 581 | return false; |
582 | 582 | } |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | } |
596 | 596 | foreach ($obj->cleanVars as $k => $v) { |
597 | 597 | if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
598 | - $cleanvars[$k] = (int)$v; |
|
598 | + $cleanvars[$k] = (int) $v; |
|
599 | 599 | } elseif (is_array($v)) { |
600 | 600 | $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
601 | 601 | } else { |
@@ -608,16 +608,16 @@ discard block |
||
608 | 608 | if ($obj->isNew()) { |
609 | 609 | if (!is_array($this->keyName)) { |
610 | 610 | if ($cleanvars[$this->keyName] < 1) { |
611 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
611 | + $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq'); |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | $ignore = ''; |
615 | 615 | if ($ignoreInsert) { |
616 | 616 | $ignore = 'IGNORE'; |
617 | 617 | } |
618 | - $sql = "INSERT $ignore INTO " . $this->table . ' (' . implode(',', array_keys($cleanvars)) . ') VALUES (' . implode(',', array_values($cleanvars)) . ')'; |
|
618 | + $sql = "INSERT $ignore INTO ".$this->table.' ('.implode(',', array_keys($cleanvars)).') VALUES ('.implode(',', array_values($cleanvars)).')'; |
|
619 | 619 | } else { |
620 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
620 | + $sql = 'UPDATE '.$this->table.' SET'; |
|
621 | 621 | foreach ($cleanvars as $key => $value) { |
622 | 622 | if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
623 | 623 | continue; |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | if (isset($notfirst)) { |
626 | 626 | $sql .= ','; |
627 | 627 | } |
628 | - $sql .= ' ' . $key . ' = ' . $value; |
|
628 | + $sql .= ' '.$key.' = '.$value; |
|
629 | 629 | $notfirst = true; |
630 | 630 | } |
631 | 631 | if (is_array($this->keyName)) { |
@@ -635,12 +635,12 @@ discard block |
||
635 | 635 | if ($i > 0) { |
636 | 636 | $whereclause .= ' AND '; |
637 | 637 | } |
638 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
638 | + $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]); |
|
639 | 639 | } |
640 | 640 | } else { |
641 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
641 | + $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName); |
|
642 | 642 | } |
643 | - $sql .= ' WHERE ' . $whereclause; |
|
643 | + $sql .= ' WHERE '.$whereclause; |
|
644 | 644 | } |
645 | 645 | |
646 | 646 | if (false != $force) { |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | */ |
675 | 675 | public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
676 | 676 | { |
677 | - $set_clause = $fieldname . ' = '; |
|
677 | + $set_clause = $fieldname.' = '; |
|
678 | 678 | if (is_numeric($fieldvalue)) { |
679 | 679 | $set_clause .= $fieldvalue; |
680 | 680 | } elseif (is_array($fieldvalue)) { |
@@ -682,9 +682,9 @@ discard block |
||
682 | 682 | } else { |
683 | 683 | $set_clause .= $this->db->quoteString($fieldvalue); |
684 | 684 | } |
685 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
685 | + $sql = 'UPDATE '.$this->table.' SET '.$set_clause; |
|
686 | 686 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
687 | - $sql .= ' ' . $criteria->renderWhere(); |
|
687 | + $sql .= ' '.$criteria->renderWhere(); |
|
688 | 688 | } |
689 | 689 | if ($force) { |
690 | 690 | $result = $this->db->queryF($sql); |
@@ -732,8 +732,8 @@ discard block |
||
732 | 732 | public function deleteAll($criteria = null) |
733 | 733 | { |
734 | 734 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
735 | - $sql = 'DELETE FROM ' . $this->table; |
|
736 | - $sql .= ' ' . $criteria->renderWhere(); |
|
735 | + $sql = 'DELETE FROM '.$this->table; |
|
736 | + $sql .= ' '.$criteria->renderWhere(); |
|
737 | 737 | if (!$this->db->queryF($sql)) { |
738 | 738 | return false; |
739 | 739 | } |
@@ -779,15 +779,15 @@ discard block |
||
779 | 779 | */ |
780 | 780 | public function getDistincts($field, $criteria = null, $format = 's') |
781 | 781 | { |
782 | - require_once __DIR__ . '/lite.php'; |
|
782 | + require_once __DIR__.'/lite.php'; |
|
783 | 783 | $limit = $start = 0; |
784 | - $sql = 'SELECT ' . $this->keyName . ', ' . $field . ' FROM ' . $this->table; |
|
784 | + $sql = 'SELECT '.$this->keyName.', '.$field.' FROM '.$this->table; |
|
785 | 785 | if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
786 | - $sql .= ' ' . $criteria->renderWhere(); |
|
786 | + $sql .= ' '.$criteria->renderWhere(); |
|
787 | 787 | $limit = $criteria->getLimit(); |
788 | 788 | $start = $criteria->getStart(); |
789 | 789 | } |
790 | - $sql .= ' GROUP BY ' . $field . ' ORDER BY ' . $field; |
|
790 | + $sql .= ' GROUP BY '.$field.' ORDER BY '.$field; |
|
791 | 791 | |
792 | 792 | $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
793 | 793 | $id = $this->_getIdForCache($sql, $start, $limit); |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $critere->setStart($start); |
836 | 836 | $critere->setSort($sort); |
837 | 837 | $critere->setOrder($order); |
838 | - $items =& $this->getObjects($critere, $idAsKey); |
|
838 | + $items = & $this->getObjects($critere, $idAsKey); |
|
839 | 839 | |
840 | 840 | return $items; |
841 | 841 | } |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | */ |
846 | 846 | public function forceCacheClean() |
847 | 847 | { |
848 | - require_once __DIR__ . '/lite.php'; |
|
848 | + require_once __DIR__.'/lite.php'; |
|
849 | 849 | $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
850 | 850 | $Cache_Lite->clean(); |
851 | 851 | } |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | /** |
500 | 500 | * Notification de la publication d'une nouvelle référence |
501 | 501 | * |
502 | - * @param object|references_articles $article L'annonce pour laquelle on fait la notification |
|
502 | + * @param references_articles $article L'annonce pour laquelle on fait la notification |
|
503 | 503 | * @return bool |
504 | 504 | */ |
505 | 505 | public function notifyNewArticle(references_articles $article) |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | /** |
575 | 575 | * Indique si une référence est visible d'un utilisateur |
576 | 576 | * |
577 | - * @param object|references_articles $article L'article à controler |
|
577 | + * @param references_articles $article L'article à controler |
|
578 | 578 | * @param integer $uid L'id de l'utilisateur à controler |
579 | 579 | * @return bool |
580 | 580 | */ |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * **************************************************************************** |
20 | 20 | */ |
21 | 21 | if (!defined('XOOPS_ROOT_PATH')) { |
22 | - die('XOOPS root path not defined'); |
|
22 | + die('XOOPS root path not defined'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
26 | 26 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
27 | - require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
27 | + require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | define('REFERENCES_STATUS_ONLINE', 1); // Articles en ligne |
@@ -32,610 +32,610 @@ discard block |
||
32 | 32 | |
33 | 33 | class references_articles extends references_Object |
34 | 34 | { |
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->initVar('article_id', XOBJ_DTYPE_INT, null, false); |
|
38 | - $this->initVar('article_category_id', XOBJ_DTYPE_INT, null, false); |
|
39 | - $this->initVar('article_timestamp', XOBJ_DTYPE_INT, null, false); |
|
40 | - $this->initVar('article_weight', XOBJ_DTYPE_INT, null, false); |
|
41 | - $this->initVar('article_date', XOBJ_DTYPE_TXTBOX, null, false); |
|
42 | - $this->initVar('article_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
43 | - $this->initVar('article_text', XOBJ_DTYPE_TXTAREA, null, false); |
|
44 | - $this->initVar('article_externalurl', XOBJ_DTYPE_TXTBOX, null, false); |
|
45 | - $this->initVar('article_picture1', XOBJ_DTYPE_TXTBOX, null, false); |
|
46 | - $this->initVar('article_picture1_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
47 | - $this->initVar('article_picture2', XOBJ_DTYPE_TXTBOX, null, false); |
|
48 | - $this->initVar('article_picture2_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
49 | - $this->initVar('article_picture3', XOBJ_DTYPE_TXTBOX, null, false); |
|
50 | - $this->initVar('article_picture3_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
51 | - $this->initVar('article_picture4', XOBJ_DTYPE_TXTBOX, null, false); |
|
52 | - $this->initVar('article_picture4_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
53 | - $this->initVar('article_picture5', XOBJ_DTYPE_TXTBOX, null, false); |
|
54 | - $this->initVar('article_picture5_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
55 | - $this->initVar('article_picture6', XOBJ_DTYPE_TXTBOX, null, false); |
|
56 | - $this->initVar('article_picture6_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
57 | - $this->initVar('article_picture7', XOBJ_DTYPE_TXTBOX, null, false); |
|
58 | - $this->initVar('article_picture7_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
59 | - $this->initVar('article_picture8', XOBJ_DTYPE_TXTBOX, null, false); |
|
60 | - $this->initVar('article_picture8_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
61 | - $this->initVar('article_picture9', XOBJ_DTYPE_TXTBOX, null, false); |
|
62 | - $this->initVar('article_picture9_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
63 | - $this->initVar('article_picture10', XOBJ_DTYPE_TXTBOX, null, false); |
|
64 | - $this->initVar('article_picture10_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
65 | - $this->initVar('article_author', XOBJ_DTYPE_INT, null, false); |
|
66 | - $this->initVar('article_online', XOBJ_DTYPE_INT, null, false); |
|
67 | - $this->initVar('article_attached_file', XOBJ_DTYPE_TXTBOX, null, false); |
|
68 | - $this->initVar('article_readmore', XOBJ_DTYPE_TXTAREA, null, false); |
|
69 | - |
|
70 | - // Pour autoriser le html |
|
71 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Indique si l'article en cours est visible |
|
76 | - * |
|
77 | - * @return boolean |
|
78 | - */ |
|
79 | - public function isArticleOnline() |
|
80 | - { |
|
81 | - return $this->getVar('article_online') == REFERENCES_STATUS_ONLINE ? true : false; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Retourne une image qui indique si l'article est en ligne ou pas |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function getOnlinePicture() |
|
90 | - { |
|
91 | - if ($this->isArticleOnline()) { |
|
92 | - return REFERENCES_IMAGES_URL . 'status_online.png'; |
|
93 | - } else { |
|
94 | - return REFERENCES_IMAGES_URL . 'status_offline.png'; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getHrefTitle() |
|
104 | - { |
|
105 | - return references_utils::makeHrefTitle($this->getVar('article_title')); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Indique si une image de l'article existe |
|
110 | - * |
|
111 | - * @param integer $indice L'indice de l'image recherchée |
|
112 | - * @return boolean Vrai si l'image existe sinon faux |
|
113 | - */ |
|
114 | - public function pictureExists($indice) |
|
115 | - { |
|
116 | - $return = false; |
|
117 | - $fieldName = 'article_picture' . $indice; |
|
118 | - if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName))) { |
|
119 | - $return = true; |
|
120 | - } |
|
121 | - |
|
122 | - return $return; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Supprime l'image associée à un article |
|
127 | - * |
|
128 | - * @param integer $indice L'indice de l'image recherchée |
|
129 | - * @return void |
|
130 | - */ |
|
131 | - public function deletePicture($indice) |
|
132 | - { |
|
133 | - $fieldName = 'article_picture' . $indice; |
|
134 | - if ($this->pictureExists($indice)) { |
|
135 | - @unlink(references_utils::getModuleOption('images_path') . references_utils::getModuleOption('images_path') . $this->getVar($fieldName)); |
|
136 | - } |
|
137 | - $this->setVar($fieldName, ''); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Retourne l'URL de l'image de l'article courant |
|
142 | - * |
|
143 | - * @param integer $indice L'indice de l'image recherchée |
|
144 | - * @return string L'URL |
|
145 | - */ |
|
146 | - public function getPictureUrl($indice) |
|
147 | - { |
|
148 | - $fieldName = 'article_picture' . $indice; |
|
149 | - if (xoops_trim($this->getVar($fieldName)) != '' && $this->pictureExists($indice)) { |
|
150 | - return references_utils::getModuleOption('images_url') . '/' . $this->getVar($fieldName); |
|
151 | - } else { |
|
152 | - return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Retourne le chemin de l'image de l'article courante |
|
158 | - * |
|
159 | - * @param integer $indice L'indice de l'image recherchée |
|
160 | - * @return string Le chemin |
|
161 | - */ |
|
162 | - public function getPicturePath($indice) |
|
163 | - { |
|
164 | - $fieldName = 'article_picture' . $indice; |
|
165 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
166 | - return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName); |
|
167 | - } else { |
|
168 | - return ''; |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Indique si la vignette de l'image de l'article existe |
|
174 | - * |
|
175 | - * @param integer $indice L'indice de l'image recherchée |
|
176 | - * @return boolean Vrai si l'image existe sinon faux |
|
177 | - */ |
|
178 | - public function thumbExists($indice) |
|
179 | - { |
|
180 | - $fieldName = 'article_picture' . $indice; |
|
181 | - $return = false; |
|
182 | - if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName))) { |
|
183 | - $return = true; |
|
184 | - } |
|
185 | - |
|
186 | - return $return; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Retourne l'URL de la vignette de l'article |
|
191 | - * |
|
192 | - * @param integer $indice L'indice de l'image recherchée |
|
193 | - * @return string L'URL |
|
194 | - */ |
|
195 | - public function getThumbUrl($indice) |
|
196 | - { |
|
197 | - $fieldName = 'article_picture' . $indice; |
|
198 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
199 | - return references_utils::getModuleOption('images_url') . '/' . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
200 | - } else { |
|
201 | - return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Retourne le chemin de la vignette de l'annonce |
|
207 | - * |
|
208 | - * @param integer $indice L'indice de l'image recherchée |
|
209 | - * @return string L'URL |
|
210 | - */ |
|
211 | - public function getThumbPath($indice) |
|
212 | - { |
|
213 | - $fieldName = 'article_picture' . $indice; |
|
214 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
215 | - return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
216 | - } else { |
|
217 | - return ''; |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Indique si le fichier attaché à un article existe |
|
223 | - * |
|
224 | - * @return boolean |
|
225 | - */ |
|
226 | - public function attachmentExists() |
|
227 | - { |
|
228 | - $return = false; |
|
229 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'))) { |
|
230 | - $return = true; |
|
231 | - } |
|
232 | - |
|
233 | - return $return; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Retourne l'URL du fichier attaché |
|
238 | - * |
|
239 | - * @return string L'url du fichier attaché sinon une chaine vide |
|
240 | - */ |
|
241 | - public function getAttachmentUrl() |
|
242 | - { |
|
243 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
244 | - return references_utils::getModuleOption('attached_url') . '/' . $this->getVar('article_attached_file'); |
|
245 | - } else { |
|
246 | - return ''; |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Retourne le chemin du fichier attaché |
|
252 | - * |
|
253 | - * @return string Le chemin du fichier attaché sinon une chaine vide |
|
254 | - */ |
|
255 | - public function getAttachmentPath() |
|
256 | - { |
|
257 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
258 | - return references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'); |
|
259 | - } else { |
|
260 | - return ''; |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Supprime le fichier attaché à un article |
|
266 | - */ |
|
267 | - public function deleteAttachment() |
|
268 | - { |
|
269 | - if ($this->attachmentExists()) { |
|
270 | - @unlink(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file')); |
|
271 | - } |
|
272 | - $this->setVar('article_attached_file', ''); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Supprime la miniature associée à l'article |
|
277 | - * |
|
278 | - * @param integer $indice L'indice de l'image recherchée |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function deleteThumb($indice) |
|
282 | - { |
|
283 | - $fieldName = 'article_picture' . $indice; |
|
284 | - if ($this->thumbExists($indice)) { |
|
285 | - @unlink(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName)); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * Supprime l'image (et vignette) d'un article (raccourcis) |
|
291 | - * |
|
292 | - * @return void |
|
293 | - */ |
|
294 | - public function deletePicturesAndThumbs() |
|
295 | - { |
|
296 | - for ($i = 1; $i <= 10; ++$i) { |
|
297 | - $this->deleteThumb($i); |
|
298 | - $this->deletePicture($i); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Retourne le timestamp de création formaté |
|
304 | - * |
|
305 | - * @return string |
|
306 | - */ |
|
307 | - public function getFormatedTimeStamp() |
|
308 | - { |
|
309 | - return formatTimestamp($this->getVar('article_timestamp'), 's'); |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Indique s'il existe au moins une image pour l'article |
|
314 | - * |
|
315 | - * @return boolean |
|
316 | - */ |
|
317 | - public function isThereAPicture() |
|
318 | - { |
|
319 | - for ($i = 1; $i <= 10; ++$i) { |
|
320 | - if ($this->pictureExists($i)) { |
|
321 | - return true; |
|
322 | - } |
|
323 | - } |
|
324 | - |
|
325 | - return false; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * Inidique s'il existe au moins une vignette pour l'article |
|
330 | - * |
|
331 | - * @return boolean |
|
332 | - */ |
|
333 | - public function isThereAThumb() |
|
334 | - { |
|
335 | - for ($i = 1; $i <= 10; ++$i) { |
|
336 | - if ($this->thumbExists($i)) { |
|
337 | - return true; |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - return false; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Retourne l'url pour atteindre l'élément |
|
346 | - * |
|
347 | - * @param bool $shortVersion |
|
348 | - * @return string |
|
349 | - */ |
|
350 | - public function getUrl($shortVersion = false) |
|
351 | - { |
|
352 | - if (!$shortVersion) { |
|
353 | - return REFERENCES_URL . 'reference.php?article_id=' . $this->getVar('article_id'); |
|
354 | - } else { |
|
355 | - return 'reference.php?article_id=' . $this->getVar('article_id'); |
|
356 | - } |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Retourne les éléments de l'annnonce formatés pour affichage |
|
361 | - * |
|
362 | - * @param string $format Format à utiliser |
|
363 | - * @return array |
|
364 | - */ |
|
365 | - public function toArray($format = 's') |
|
366 | - { |
|
367 | - $ret = array(); |
|
368 | - $ret = parent::toArray($format); |
|
369 | - $hrefTitle = $this->getHrefTitle(); |
|
370 | - $ret['article_href_title'] = $hrefTitle; |
|
371 | - $ret['article_url'] = $this->getUrl(); |
|
372 | - // Indique si une annonce est expirée |
|
373 | - $ret['article_is_online'] = $this->isArticleOnline(); |
|
374 | - if ($this->isThereAPicture()) { |
|
375 | - $ret['article_picture_exists'] = true; |
|
376 | - for ($i = 1; $i <= 10; ++$i) { |
|
377 | - if ($this->pictureExists($i)) { |
|
378 | - $ret['article_picture_url' . $i] = $this->getPictureUrl($i); |
|
379 | - $ret['article_picture_path' . $i] = $this->getPicturePath($i); |
|
380 | - $ret['article_pictures_urls'][] = $this->getPictureUrl($i); |
|
381 | - $ret['article_pictures_paths'][] = $this->getPicturePath($i); |
|
382 | - $fieldName = 'article_picture' . $i . '_text'; |
|
383 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
384 | - $ret['article_pictures_texts'][] = references_utils::makeHrefTitle($this->getVar($fieldName)); |
|
385 | - } else { |
|
386 | - $ret['article_pictures_texts'][] = $hrefTitle; |
|
387 | - } |
|
388 | - } |
|
389 | - } |
|
390 | - } else { |
|
391 | - $ret['article_picture_exists'] = false; |
|
392 | - } |
|
393 | - $ret['article_short_text'] = references_utils::truncate_tagsafe($this->getVar('article_text'), REFERENCES_SHORTEN_TEXT); |
|
394 | - |
|
395 | - if ($this->attachmentExists()) { |
|
396 | - $ret['article_attachment_exists'] = true; |
|
397 | - $ret['article_attachment_url'] = $this->getAttachmentUrl(); |
|
398 | - $ret['article_attachment_path'] = $this->getAttachmentPath(); |
|
399 | - } else { |
|
400 | - $ret['attachment_exists'] = false; |
|
401 | - } |
|
402 | - |
|
403 | - if ($this->isThereAThumb()) { |
|
404 | - $ret['article_thumb_exists'] = true; |
|
405 | - for ($i = 1; $i <= 10; ++$i) { |
|
406 | - if ($this->thumbExists($i)) { |
|
407 | - $ret['article_thumb_url' . $i] = $this->getThumbUrl($i); |
|
408 | - $ret['article_thumb_path' . $i] = $this->getThumbPath($i); |
|
409 | - $ret['article_thumbs_urls'][] = $this->getThumbUrl($i); |
|
410 | - $ret['article_thumbs_paths'][] = $this->getThumbPath($i); |
|
411 | - } |
|
412 | - } |
|
413 | - } else { |
|
414 | - $ret['article_thumb_exists'] = false; |
|
415 | - } |
|
416 | - |
|
417 | - $ret['article_timestamp_formated'] = $this->getFormatedTimeStamp(); |
|
418 | - |
|
419 | - return $ret; |
|
420 | - } |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->initVar('article_id', XOBJ_DTYPE_INT, null, false); |
|
38 | + $this->initVar('article_category_id', XOBJ_DTYPE_INT, null, false); |
|
39 | + $this->initVar('article_timestamp', XOBJ_DTYPE_INT, null, false); |
|
40 | + $this->initVar('article_weight', XOBJ_DTYPE_INT, null, false); |
|
41 | + $this->initVar('article_date', XOBJ_DTYPE_TXTBOX, null, false); |
|
42 | + $this->initVar('article_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
43 | + $this->initVar('article_text', XOBJ_DTYPE_TXTAREA, null, false); |
|
44 | + $this->initVar('article_externalurl', XOBJ_DTYPE_TXTBOX, null, false); |
|
45 | + $this->initVar('article_picture1', XOBJ_DTYPE_TXTBOX, null, false); |
|
46 | + $this->initVar('article_picture1_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
47 | + $this->initVar('article_picture2', XOBJ_DTYPE_TXTBOX, null, false); |
|
48 | + $this->initVar('article_picture2_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
49 | + $this->initVar('article_picture3', XOBJ_DTYPE_TXTBOX, null, false); |
|
50 | + $this->initVar('article_picture3_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
51 | + $this->initVar('article_picture4', XOBJ_DTYPE_TXTBOX, null, false); |
|
52 | + $this->initVar('article_picture4_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
53 | + $this->initVar('article_picture5', XOBJ_DTYPE_TXTBOX, null, false); |
|
54 | + $this->initVar('article_picture5_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
55 | + $this->initVar('article_picture6', XOBJ_DTYPE_TXTBOX, null, false); |
|
56 | + $this->initVar('article_picture6_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
57 | + $this->initVar('article_picture7', XOBJ_DTYPE_TXTBOX, null, false); |
|
58 | + $this->initVar('article_picture7_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
59 | + $this->initVar('article_picture8', XOBJ_DTYPE_TXTBOX, null, false); |
|
60 | + $this->initVar('article_picture8_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
61 | + $this->initVar('article_picture9', XOBJ_DTYPE_TXTBOX, null, false); |
|
62 | + $this->initVar('article_picture9_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
63 | + $this->initVar('article_picture10', XOBJ_DTYPE_TXTBOX, null, false); |
|
64 | + $this->initVar('article_picture10_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
65 | + $this->initVar('article_author', XOBJ_DTYPE_INT, null, false); |
|
66 | + $this->initVar('article_online', XOBJ_DTYPE_INT, null, false); |
|
67 | + $this->initVar('article_attached_file', XOBJ_DTYPE_TXTBOX, null, false); |
|
68 | + $this->initVar('article_readmore', XOBJ_DTYPE_TXTAREA, null, false); |
|
69 | + |
|
70 | + // Pour autoriser le html |
|
71 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Indique si l'article en cours est visible |
|
76 | + * |
|
77 | + * @return boolean |
|
78 | + */ |
|
79 | + public function isArticleOnline() |
|
80 | + { |
|
81 | + return $this->getVar('article_online') == REFERENCES_STATUS_ONLINE ? true : false; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Retourne une image qui indique si l'article est en ligne ou pas |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function getOnlinePicture() |
|
90 | + { |
|
91 | + if ($this->isArticleOnline()) { |
|
92 | + return REFERENCES_IMAGES_URL . 'status_online.png'; |
|
93 | + } else { |
|
94 | + return REFERENCES_IMAGES_URL . 'status_offline.png'; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getHrefTitle() |
|
104 | + { |
|
105 | + return references_utils::makeHrefTitle($this->getVar('article_title')); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Indique si une image de l'article existe |
|
110 | + * |
|
111 | + * @param integer $indice L'indice de l'image recherchée |
|
112 | + * @return boolean Vrai si l'image existe sinon faux |
|
113 | + */ |
|
114 | + public function pictureExists($indice) |
|
115 | + { |
|
116 | + $return = false; |
|
117 | + $fieldName = 'article_picture' . $indice; |
|
118 | + if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName))) { |
|
119 | + $return = true; |
|
120 | + } |
|
121 | + |
|
122 | + return $return; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Supprime l'image associée à un article |
|
127 | + * |
|
128 | + * @param integer $indice L'indice de l'image recherchée |
|
129 | + * @return void |
|
130 | + */ |
|
131 | + public function deletePicture($indice) |
|
132 | + { |
|
133 | + $fieldName = 'article_picture' . $indice; |
|
134 | + if ($this->pictureExists($indice)) { |
|
135 | + @unlink(references_utils::getModuleOption('images_path') . references_utils::getModuleOption('images_path') . $this->getVar($fieldName)); |
|
136 | + } |
|
137 | + $this->setVar($fieldName, ''); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Retourne l'URL de l'image de l'article courant |
|
142 | + * |
|
143 | + * @param integer $indice L'indice de l'image recherchée |
|
144 | + * @return string L'URL |
|
145 | + */ |
|
146 | + public function getPictureUrl($indice) |
|
147 | + { |
|
148 | + $fieldName = 'article_picture' . $indice; |
|
149 | + if (xoops_trim($this->getVar($fieldName)) != '' && $this->pictureExists($indice)) { |
|
150 | + return references_utils::getModuleOption('images_url') . '/' . $this->getVar($fieldName); |
|
151 | + } else { |
|
152 | + return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Retourne le chemin de l'image de l'article courante |
|
158 | + * |
|
159 | + * @param integer $indice L'indice de l'image recherchée |
|
160 | + * @return string Le chemin |
|
161 | + */ |
|
162 | + public function getPicturePath($indice) |
|
163 | + { |
|
164 | + $fieldName = 'article_picture' . $indice; |
|
165 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
166 | + return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName); |
|
167 | + } else { |
|
168 | + return ''; |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Indique si la vignette de l'image de l'article existe |
|
174 | + * |
|
175 | + * @param integer $indice L'indice de l'image recherchée |
|
176 | + * @return boolean Vrai si l'image existe sinon faux |
|
177 | + */ |
|
178 | + public function thumbExists($indice) |
|
179 | + { |
|
180 | + $fieldName = 'article_picture' . $indice; |
|
181 | + $return = false; |
|
182 | + if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName))) { |
|
183 | + $return = true; |
|
184 | + } |
|
185 | + |
|
186 | + return $return; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Retourne l'URL de la vignette de l'article |
|
191 | + * |
|
192 | + * @param integer $indice L'indice de l'image recherchée |
|
193 | + * @return string L'URL |
|
194 | + */ |
|
195 | + public function getThumbUrl($indice) |
|
196 | + { |
|
197 | + $fieldName = 'article_picture' . $indice; |
|
198 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
199 | + return references_utils::getModuleOption('images_url') . '/' . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
200 | + } else { |
|
201 | + return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Retourne le chemin de la vignette de l'annonce |
|
207 | + * |
|
208 | + * @param integer $indice L'indice de l'image recherchée |
|
209 | + * @return string L'URL |
|
210 | + */ |
|
211 | + public function getThumbPath($indice) |
|
212 | + { |
|
213 | + $fieldName = 'article_picture' . $indice; |
|
214 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
215 | + return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
216 | + } else { |
|
217 | + return ''; |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Indique si le fichier attaché à un article existe |
|
223 | + * |
|
224 | + * @return boolean |
|
225 | + */ |
|
226 | + public function attachmentExists() |
|
227 | + { |
|
228 | + $return = false; |
|
229 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'))) { |
|
230 | + $return = true; |
|
231 | + } |
|
232 | + |
|
233 | + return $return; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Retourne l'URL du fichier attaché |
|
238 | + * |
|
239 | + * @return string L'url du fichier attaché sinon une chaine vide |
|
240 | + */ |
|
241 | + public function getAttachmentUrl() |
|
242 | + { |
|
243 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
244 | + return references_utils::getModuleOption('attached_url') . '/' . $this->getVar('article_attached_file'); |
|
245 | + } else { |
|
246 | + return ''; |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Retourne le chemin du fichier attaché |
|
252 | + * |
|
253 | + * @return string Le chemin du fichier attaché sinon une chaine vide |
|
254 | + */ |
|
255 | + public function getAttachmentPath() |
|
256 | + { |
|
257 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
258 | + return references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'); |
|
259 | + } else { |
|
260 | + return ''; |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Supprime le fichier attaché à un article |
|
266 | + */ |
|
267 | + public function deleteAttachment() |
|
268 | + { |
|
269 | + if ($this->attachmentExists()) { |
|
270 | + @unlink(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file')); |
|
271 | + } |
|
272 | + $this->setVar('article_attached_file', ''); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Supprime la miniature associée à l'article |
|
277 | + * |
|
278 | + * @param integer $indice L'indice de l'image recherchée |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function deleteThumb($indice) |
|
282 | + { |
|
283 | + $fieldName = 'article_picture' . $indice; |
|
284 | + if ($this->thumbExists($indice)) { |
|
285 | + @unlink(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName)); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * Supprime l'image (et vignette) d'un article (raccourcis) |
|
291 | + * |
|
292 | + * @return void |
|
293 | + */ |
|
294 | + public function deletePicturesAndThumbs() |
|
295 | + { |
|
296 | + for ($i = 1; $i <= 10; ++$i) { |
|
297 | + $this->deleteThumb($i); |
|
298 | + $this->deletePicture($i); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Retourne le timestamp de création formaté |
|
304 | + * |
|
305 | + * @return string |
|
306 | + */ |
|
307 | + public function getFormatedTimeStamp() |
|
308 | + { |
|
309 | + return formatTimestamp($this->getVar('article_timestamp'), 's'); |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Indique s'il existe au moins une image pour l'article |
|
314 | + * |
|
315 | + * @return boolean |
|
316 | + */ |
|
317 | + public function isThereAPicture() |
|
318 | + { |
|
319 | + for ($i = 1; $i <= 10; ++$i) { |
|
320 | + if ($this->pictureExists($i)) { |
|
321 | + return true; |
|
322 | + } |
|
323 | + } |
|
324 | + |
|
325 | + return false; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * Inidique s'il existe au moins une vignette pour l'article |
|
330 | + * |
|
331 | + * @return boolean |
|
332 | + */ |
|
333 | + public function isThereAThumb() |
|
334 | + { |
|
335 | + for ($i = 1; $i <= 10; ++$i) { |
|
336 | + if ($this->thumbExists($i)) { |
|
337 | + return true; |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + return false; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Retourne l'url pour atteindre l'élément |
|
346 | + * |
|
347 | + * @param bool $shortVersion |
|
348 | + * @return string |
|
349 | + */ |
|
350 | + public function getUrl($shortVersion = false) |
|
351 | + { |
|
352 | + if (!$shortVersion) { |
|
353 | + return REFERENCES_URL . 'reference.php?article_id=' . $this->getVar('article_id'); |
|
354 | + } else { |
|
355 | + return 'reference.php?article_id=' . $this->getVar('article_id'); |
|
356 | + } |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Retourne les éléments de l'annnonce formatés pour affichage |
|
361 | + * |
|
362 | + * @param string $format Format à utiliser |
|
363 | + * @return array |
|
364 | + */ |
|
365 | + public function toArray($format = 's') |
|
366 | + { |
|
367 | + $ret = array(); |
|
368 | + $ret = parent::toArray($format); |
|
369 | + $hrefTitle = $this->getHrefTitle(); |
|
370 | + $ret['article_href_title'] = $hrefTitle; |
|
371 | + $ret['article_url'] = $this->getUrl(); |
|
372 | + // Indique si une annonce est expirée |
|
373 | + $ret['article_is_online'] = $this->isArticleOnline(); |
|
374 | + if ($this->isThereAPicture()) { |
|
375 | + $ret['article_picture_exists'] = true; |
|
376 | + for ($i = 1; $i <= 10; ++$i) { |
|
377 | + if ($this->pictureExists($i)) { |
|
378 | + $ret['article_picture_url' . $i] = $this->getPictureUrl($i); |
|
379 | + $ret['article_picture_path' . $i] = $this->getPicturePath($i); |
|
380 | + $ret['article_pictures_urls'][] = $this->getPictureUrl($i); |
|
381 | + $ret['article_pictures_paths'][] = $this->getPicturePath($i); |
|
382 | + $fieldName = 'article_picture' . $i . '_text'; |
|
383 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
384 | + $ret['article_pictures_texts'][] = references_utils::makeHrefTitle($this->getVar($fieldName)); |
|
385 | + } else { |
|
386 | + $ret['article_pictures_texts'][] = $hrefTitle; |
|
387 | + } |
|
388 | + } |
|
389 | + } |
|
390 | + } else { |
|
391 | + $ret['article_picture_exists'] = false; |
|
392 | + } |
|
393 | + $ret['article_short_text'] = references_utils::truncate_tagsafe($this->getVar('article_text'), REFERENCES_SHORTEN_TEXT); |
|
394 | + |
|
395 | + if ($this->attachmentExists()) { |
|
396 | + $ret['article_attachment_exists'] = true; |
|
397 | + $ret['article_attachment_url'] = $this->getAttachmentUrl(); |
|
398 | + $ret['article_attachment_path'] = $this->getAttachmentPath(); |
|
399 | + } else { |
|
400 | + $ret['attachment_exists'] = false; |
|
401 | + } |
|
402 | + |
|
403 | + if ($this->isThereAThumb()) { |
|
404 | + $ret['article_thumb_exists'] = true; |
|
405 | + for ($i = 1; $i <= 10; ++$i) { |
|
406 | + if ($this->thumbExists($i)) { |
|
407 | + $ret['article_thumb_url' . $i] = $this->getThumbUrl($i); |
|
408 | + $ret['article_thumb_path' . $i] = $this->getThumbPath($i); |
|
409 | + $ret['article_thumbs_urls'][] = $this->getThumbUrl($i); |
|
410 | + $ret['article_thumbs_paths'][] = $this->getThumbPath($i); |
|
411 | + } |
|
412 | + } |
|
413 | + } else { |
|
414 | + $ret['article_thumb_exists'] = false; |
|
415 | + } |
|
416 | + |
|
417 | + $ret['article_timestamp_formated'] = $this->getFormatedTimeStamp(); |
|
418 | + |
|
419 | + return $ret; |
|
420 | + } |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | class ReferencesReferences_articlesHandler extends references_XoopsPersistableObjectHandler |
424 | 424 | { |
425 | - public function __construct($db) |
|
426 | - { // Table Classe Id Descr. |
|
427 | - parent::__construct($db, 'references_articles', 'references_articles', 'article_id', 'article_title'); |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Retourne le critère à utiliser pour voir les catégories en respectant les permissions |
|
432 | - * |
|
433 | - * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
434 | - * @return obejct de type Criteria |
|
435 | - */ |
|
436 | - public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
437 | - { |
|
438 | - global $xoopsUser; |
|
439 | - static $permissions = array(); |
|
440 | - if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
441 | - return $permissions[$permissionsType]; |
|
442 | - } |
|
443 | - $categories = array(); |
|
444 | - $currentModule = references_utils::getModule(); |
|
445 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
446 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
447 | - $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
448 | - if (is_array($categories) && count($categories) > 0) { |
|
449 | - $permissions[$permissionsType] = new Criteria('article_category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
450 | - } else { // Ne peut rien voir |
|
451 | - $permissions[$permissionsType] = new Criteria('article_category_id', '0', '='); |
|
452 | - } |
|
453 | - |
|
454 | - return $permissions[$permissionsType]; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * Retourne les articles récents en tenant compte des permissions de consultation sur les catégories |
|
459 | - * |
|
460 | - * @param integer $start Indice de début |
|
461 | - * @param integer $limit Nombre d'objets à renvoyer |
|
462 | - * @param string $sort Zone de tri |
|
463 | - * @param string $order Sens du tri |
|
464 | - * @param boolean $onlyOnline Uniquement les articles en ligne ? |
|
465 | - * @param integer $categoryId Identifiant d'une catégorie à laquelle se limiter |
|
466 | - * @return array Objets de type references_articles |
|
467 | - */ |
|
468 | - public function getRecentArticles($start = 0, $limit = 0, $sort = 'article_timestamp', $order = 'DESC', $onlyOnline = true, $categoryId = 0) |
|
469 | - { |
|
470 | - $criteria = new CriteriaCompo(); |
|
471 | - $criteria->add(new Criteria('article_id', 0, '<>')); |
|
472 | - $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
473 | - if ($onlyOnline) { |
|
474 | - $criteria->add(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
475 | - } |
|
476 | - if (is_array($categoryId) && count($categoryId) > 0) { |
|
477 | - $criteria->add(new Criteria('article_category_id', '(' . implode(',', $categoryId) . ')', 'IN')); |
|
478 | - } elseif ($categoryId > 0) { |
|
479 | - $criteria->add(new Criteria('article_category_id', $categoryId, '=')); |
|
480 | - } |
|
481 | - $criteria->setStart($start); |
|
482 | - $criteria->setSort($sort); |
|
483 | - $criteria->setOrder($order); |
|
484 | - $criteria->setLimit($limit); |
|
485 | - |
|
486 | - return $this->getObjects($criteria); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Retourne le nombre total d'articles en ligne |
|
491 | - * |
|
492 | - * @return integer |
|
493 | - */ |
|
494 | - public function getOnlineArticlesCount() |
|
495 | - { |
|
496 | - return $this->getCount(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Notification de la publication d'une nouvelle référence |
|
501 | - * |
|
502 | - * @param object|references_articles $article L'annonce pour laquelle on fait la notification |
|
503 | - * @return bool |
|
504 | - */ |
|
505 | - public function notifyNewArticle(references_articles $article) |
|
506 | - { |
|
507 | - $plugins = references_plugins::getInstance(); |
|
508 | - $plugins->fireAction(references_plugins::EVENT_ON_REFERENCE_CREATE, new references_parameters(array('reference' => $article))); |
|
509 | - |
|
510 | - return true; |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Effectue la suppression d'un article (et de ses images et fichier attaché) |
|
515 | - * |
|
516 | - * @param references_articles $article L'article à supprimer |
|
517 | - * @return boolean Le résultat de la suppression |
|
518 | - */ |
|
519 | - public function deleteArticle(references_articles $article) |
|
520 | - { |
|
521 | - $article->deletePicturesAndThumbs(); |
|
522 | - $article->deleteAttachment(); |
|
523 | - |
|
524 | - return $this->delete($article, true); |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * Retourne la liste des catégories uniques utilisées par les références |
|
529 | - * |
|
530 | - */ |
|
531 | - public function getDistinctCategoriesIds() |
|
532 | - { |
|
533 | - $ret = array(); |
|
534 | - $sql = 'SELECT distinct(article_category_id) FROM ' . $this->table; |
|
535 | - $sql .= ' ' . $this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
|
536 | - $sql .= ' GROUP BY article_category_id ORDER BY article_category_id'; |
|
537 | - $result = $this->db->query($sql); |
|
538 | - if (!$result) { |
|
539 | - return $ret; |
|
540 | - } |
|
541 | - while ($row = $this->db->fetchArray($result)) { |
|
542 | - $ret[$row['article_category_id']] = $row['article_category_id']; |
|
543 | - } |
|
544 | - |
|
545 | - return $ret; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * Passe un article en ligne |
|
550 | - * |
|
551 | - * @param references_articles $article |
|
552 | - * @return boolean |
|
553 | - */ |
|
554 | - public function onlineArticle(references_articles $article) |
|
555 | - { |
|
556 | - $article->setVar('article_online', REFERENCES_STATUS_ONLINE); |
|
557 | - |
|
558 | - return $this->insert($article, true); |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Passe un article hors ligne |
|
563 | - * |
|
564 | - * @param references_articles $article |
|
565 | - * @return boolean |
|
566 | - */ |
|
567 | - public function offlineArticle(references_articles $article) |
|
568 | - { |
|
569 | - $article->setVar('article_online', REFERENCES_STATUS_OFFLINE); |
|
570 | - |
|
571 | - return $this->insert($article, true); |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Indique si une référence est visible d'un utilisateur |
|
576 | - * |
|
577 | - * @param object|references_articles $article L'article à controler |
|
578 | - * @param integer $uid L'id de l'utilisateur à controler |
|
579 | - * @return bool |
|
580 | - */ |
|
581 | - public function userCanSeeReference(references_articles $article, $uid = 0) |
|
582 | - { |
|
583 | - global $xoopsUser; |
|
584 | - if ($uid == 0) { |
|
585 | - $uid = references_utils::getCurrentUserID(); |
|
586 | - } |
|
587 | - $currentModule = references_utils::getModule(); |
|
588 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
589 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
590 | - |
|
591 | - return $gperm_handler->checkRight(REFERENCES_PERM_READ, $article->article_category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
592 | - } |
|
593 | - |
|
594 | - /** |
|
595 | - * Remonte un article d'un cran dans l'ordre global des articles |
|
596 | - * |
|
597 | - * @param integer $currentId L'ID de l'article courant dont on souhaite remonter l'ordre |
|
598 | - * @param integer $currentOrder L'ordre de l'élément courant à remonter |
|
599 | - * @return void |
|
600 | - */ |
|
601 | - public function moveUp($currentId, $currentOrder) |
|
602 | - { |
|
603 | - $sql_plus = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder - 1); |
|
604 | - $res_plus = $this->db->query($sql_plus); |
|
605 | - if ($this->db->getRowsNum($res_plus) == 0) { |
|
606 | - return; |
|
607 | - } |
|
608 | - $row_plus = $this->db->fetchArray($res_plus); |
|
609 | - |
|
610 | - $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight + 1) WHERE article_id = ' . $row_plus['article_id']; |
|
611 | - $this->db->queryF($upd1); |
|
612 | - |
|
613 | - $upd2 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . (int)$currentId; |
|
614 | - $this->db->queryF($upd2); |
|
615 | - $this->forceCacheClean(); |
|
616 | - } |
|
617 | - |
|
618 | - /** |
|
619 | - * Descend un article d'un cran dans l'ordre global des articles |
|
620 | - * |
|
621 | - * @param integer $currentId L'Id de l'article courant dont on souhaite descendre l'ordre |
|
622 | - * @param integer $currentOrder L'orde de l'élément courant à remonter |
|
623 | - * @return void |
|
624 | - */ |
|
625 | - public function moveDown($currentId, $currentOrder) |
|
626 | - { |
|
627 | - $sql_moins = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder + 1); |
|
628 | - $res_moins = $this->db->query($sql_moins); |
|
629 | - if ($this->db->getRowsNum($res_moins) == 0) { |
|
630 | - return; |
|
631 | - } |
|
632 | - |
|
633 | - $row_moins = $this->db->fetchArray($res_moins); |
|
634 | - $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . $row_moins['article_id']; |
|
635 | - $this->db->queryF($upd1); |
|
636 | - |
|
637 | - $upd2 = 'UPDATE ' . $this->table . ' SET article_weight =( article_weight + 1) WHERE article_id = ' . (int)$currentId; |
|
638 | - $this->db->queryF($upd2); |
|
639 | - $this->forceCacheClean(); |
|
640 | - } |
|
425 | + public function __construct($db) |
|
426 | + { // Table Classe Id Descr. |
|
427 | + parent::__construct($db, 'references_articles', 'references_articles', 'article_id', 'article_title'); |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Retourne le critère à utiliser pour voir les catégories en respectant les permissions |
|
432 | + * |
|
433 | + * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
434 | + * @return obejct de type Criteria |
|
435 | + */ |
|
436 | + public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
437 | + { |
|
438 | + global $xoopsUser; |
|
439 | + static $permissions = array(); |
|
440 | + if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
441 | + return $permissions[$permissionsType]; |
|
442 | + } |
|
443 | + $categories = array(); |
|
444 | + $currentModule = references_utils::getModule(); |
|
445 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
446 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
447 | + $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
448 | + if (is_array($categories) && count($categories) > 0) { |
|
449 | + $permissions[$permissionsType] = new Criteria('article_category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
450 | + } else { // Ne peut rien voir |
|
451 | + $permissions[$permissionsType] = new Criteria('article_category_id', '0', '='); |
|
452 | + } |
|
453 | + |
|
454 | + return $permissions[$permissionsType]; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * Retourne les articles récents en tenant compte des permissions de consultation sur les catégories |
|
459 | + * |
|
460 | + * @param integer $start Indice de début |
|
461 | + * @param integer $limit Nombre d'objets à renvoyer |
|
462 | + * @param string $sort Zone de tri |
|
463 | + * @param string $order Sens du tri |
|
464 | + * @param boolean $onlyOnline Uniquement les articles en ligne ? |
|
465 | + * @param integer $categoryId Identifiant d'une catégorie à laquelle se limiter |
|
466 | + * @return array Objets de type references_articles |
|
467 | + */ |
|
468 | + public function getRecentArticles($start = 0, $limit = 0, $sort = 'article_timestamp', $order = 'DESC', $onlyOnline = true, $categoryId = 0) |
|
469 | + { |
|
470 | + $criteria = new CriteriaCompo(); |
|
471 | + $criteria->add(new Criteria('article_id', 0, '<>')); |
|
472 | + $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
473 | + if ($onlyOnline) { |
|
474 | + $criteria->add(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
475 | + } |
|
476 | + if (is_array($categoryId) && count($categoryId) > 0) { |
|
477 | + $criteria->add(new Criteria('article_category_id', '(' . implode(',', $categoryId) . ')', 'IN')); |
|
478 | + } elseif ($categoryId > 0) { |
|
479 | + $criteria->add(new Criteria('article_category_id', $categoryId, '=')); |
|
480 | + } |
|
481 | + $criteria->setStart($start); |
|
482 | + $criteria->setSort($sort); |
|
483 | + $criteria->setOrder($order); |
|
484 | + $criteria->setLimit($limit); |
|
485 | + |
|
486 | + return $this->getObjects($criteria); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Retourne le nombre total d'articles en ligne |
|
491 | + * |
|
492 | + * @return integer |
|
493 | + */ |
|
494 | + public function getOnlineArticlesCount() |
|
495 | + { |
|
496 | + return $this->getCount(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Notification de la publication d'une nouvelle référence |
|
501 | + * |
|
502 | + * @param object|references_articles $article L'annonce pour laquelle on fait la notification |
|
503 | + * @return bool |
|
504 | + */ |
|
505 | + public function notifyNewArticle(references_articles $article) |
|
506 | + { |
|
507 | + $plugins = references_plugins::getInstance(); |
|
508 | + $plugins->fireAction(references_plugins::EVENT_ON_REFERENCE_CREATE, new references_parameters(array('reference' => $article))); |
|
509 | + |
|
510 | + return true; |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Effectue la suppression d'un article (et de ses images et fichier attaché) |
|
515 | + * |
|
516 | + * @param references_articles $article L'article à supprimer |
|
517 | + * @return boolean Le résultat de la suppression |
|
518 | + */ |
|
519 | + public function deleteArticle(references_articles $article) |
|
520 | + { |
|
521 | + $article->deletePicturesAndThumbs(); |
|
522 | + $article->deleteAttachment(); |
|
523 | + |
|
524 | + return $this->delete($article, true); |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * Retourne la liste des catégories uniques utilisées par les références |
|
529 | + * |
|
530 | + */ |
|
531 | + public function getDistinctCategoriesIds() |
|
532 | + { |
|
533 | + $ret = array(); |
|
534 | + $sql = 'SELECT distinct(article_category_id) FROM ' . $this->table; |
|
535 | + $sql .= ' ' . $this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
|
536 | + $sql .= ' GROUP BY article_category_id ORDER BY article_category_id'; |
|
537 | + $result = $this->db->query($sql); |
|
538 | + if (!$result) { |
|
539 | + return $ret; |
|
540 | + } |
|
541 | + while ($row = $this->db->fetchArray($result)) { |
|
542 | + $ret[$row['article_category_id']] = $row['article_category_id']; |
|
543 | + } |
|
544 | + |
|
545 | + return $ret; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * Passe un article en ligne |
|
550 | + * |
|
551 | + * @param references_articles $article |
|
552 | + * @return boolean |
|
553 | + */ |
|
554 | + public function onlineArticle(references_articles $article) |
|
555 | + { |
|
556 | + $article->setVar('article_online', REFERENCES_STATUS_ONLINE); |
|
557 | + |
|
558 | + return $this->insert($article, true); |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Passe un article hors ligne |
|
563 | + * |
|
564 | + * @param references_articles $article |
|
565 | + * @return boolean |
|
566 | + */ |
|
567 | + public function offlineArticle(references_articles $article) |
|
568 | + { |
|
569 | + $article->setVar('article_online', REFERENCES_STATUS_OFFLINE); |
|
570 | + |
|
571 | + return $this->insert($article, true); |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Indique si une référence est visible d'un utilisateur |
|
576 | + * |
|
577 | + * @param object|references_articles $article L'article à controler |
|
578 | + * @param integer $uid L'id de l'utilisateur à controler |
|
579 | + * @return bool |
|
580 | + */ |
|
581 | + public function userCanSeeReference(references_articles $article, $uid = 0) |
|
582 | + { |
|
583 | + global $xoopsUser; |
|
584 | + if ($uid == 0) { |
|
585 | + $uid = references_utils::getCurrentUserID(); |
|
586 | + } |
|
587 | + $currentModule = references_utils::getModule(); |
|
588 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
589 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
590 | + |
|
591 | + return $gperm_handler->checkRight(REFERENCES_PERM_READ, $article->article_category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
592 | + } |
|
593 | + |
|
594 | + /** |
|
595 | + * Remonte un article d'un cran dans l'ordre global des articles |
|
596 | + * |
|
597 | + * @param integer $currentId L'ID de l'article courant dont on souhaite remonter l'ordre |
|
598 | + * @param integer $currentOrder L'ordre de l'élément courant à remonter |
|
599 | + * @return void |
|
600 | + */ |
|
601 | + public function moveUp($currentId, $currentOrder) |
|
602 | + { |
|
603 | + $sql_plus = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder - 1); |
|
604 | + $res_plus = $this->db->query($sql_plus); |
|
605 | + if ($this->db->getRowsNum($res_plus) == 0) { |
|
606 | + return; |
|
607 | + } |
|
608 | + $row_plus = $this->db->fetchArray($res_plus); |
|
609 | + |
|
610 | + $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight + 1) WHERE article_id = ' . $row_plus['article_id']; |
|
611 | + $this->db->queryF($upd1); |
|
612 | + |
|
613 | + $upd2 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . (int)$currentId; |
|
614 | + $this->db->queryF($upd2); |
|
615 | + $this->forceCacheClean(); |
|
616 | + } |
|
617 | + |
|
618 | + /** |
|
619 | + * Descend un article d'un cran dans l'ordre global des articles |
|
620 | + * |
|
621 | + * @param integer $currentId L'Id de l'article courant dont on souhaite descendre l'ordre |
|
622 | + * @param integer $currentOrder L'orde de l'élément courant à remonter |
|
623 | + * @return void |
|
624 | + */ |
|
625 | + public function moveDown($currentId, $currentOrder) |
|
626 | + { |
|
627 | + $sql_moins = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder + 1); |
|
628 | + $res_moins = $this->db->query($sql_moins); |
|
629 | + if ($this->db->getRowsNum($res_moins) == 0) { |
|
630 | + return; |
|
631 | + } |
|
632 | + |
|
633 | + $row_moins = $this->db->fetchArray($res_moins); |
|
634 | + $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . $row_moins['article_id']; |
|
635 | + $this->db->queryF($upd1); |
|
636 | + |
|
637 | + $upd2 = 'UPDATE ' . $this->table . ' SET article_weight =( article_weight + 1) WHERE article_id = ' . (int)$currentId; |
|
638 | + $this->db->queryF($upd2); |
|
639 | + $this->forceCacheClean(); |
|
640 | + } |
|
641 | 641 | } |
@@ -22,13 +22,13 @@ discard block |
||
22 | 22 | die('XOOPS root path not defined'); |
23 | 23 | } |
24 | 24 | |
25 | -require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
|
25 | +require_once XOOPS_ROOT_PATH.'/kernel/object.php'; |
|
26 | 26 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
27 | - require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
27 | + require_once XOOPS_ROOT_PATH.'/modules/references/class/PersistableObjectHandler.php'; |
|
28 | 28 | } |
29 | 29 | |
30 | -define('REFERENCES_STATUS_ONLINE', 1); // Articles en ligne |
|
31 | -define('REFERENCES_STATUS_OFFLINE', 0); // Articles hors ligne |
|
30 | +define('REFERENCES_STATUS_ONLINE', 1); // Articles en ligne |
|
31 | +define('REFERENCES_STATUS_OFFLINE', 0); // Articles hors ligne |
|
32 | 32 | |
33 | 33 | class references_articles extends references_Object |
34 | 34 | { |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | public function getOnlinePicture() |
90 | 90 | { |
91 | 91 | if ($this->isArticleOnline()) { |
92 | - return REFERENCES_IMAGES_URL . 'status_online.png'; |
|
92 | + return REFERENCES_IMAGES_URL.'status_online.png'; |
|
93 | 93 | } else { |
94 | - return REFERENCES_IMAGES_URL . 'status_offline.png'; |
|
94 | + return REFERENCES_IMAGES_URL.'status_offline.png'; |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | public function pictureExists($indice) |
115 | 115 | { |
116 | 116 | $return = false; |
117 | - $fieldName = 'article_picture' . $indice; |
|
118 | - if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName))) { |
|
117 | + $fieldName = 'article_picture'.$indice; |
|
118 | + if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path').DIRECTORY_SEPARATOR.$this->getVar($fieldName))) { |
|
119 | 119 | $return = true; |
120 | 120 | } |
121 | 121 | |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function deletePicture($indice) |
132 | 132 | { |
133 | - $fieldName = 'article_picture' . $indice; |
|
133 | + $fieldName = 'article_picture'.$indice; |
|
134 | 134 | if ($this->pictureExists($indice)) { |
135 | - @unlink(references_utils::getModuleOption('images_path') . references_utils::getModuleOption('images_path') . $this->getVar($fieldName)); |
|
135 | + @unlink(references_utils::getModuleOption('images_path').references_utils::getModuleOption('images_path').$this->getVar($fieldName)); |
|
136 | 136 | } |
137 | 137 | $this->setVar($fieldName, ''); |
138 | 138 | } |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function getPictureUrl($indice) |
147 | 147 | { |
148 | - $fieldName = 'article_picture' . $indice; |
|
148 | + $fieldName = 'article_picture'.$indice; |
|
149 | 149 | if (xoops_trim($this->getVar($fieldName)) != '' && $this->pictureExists($indice)) { |
150 | - return references_utils::getModuleOption('images_url') . '/' . $this->getVar($fieldName); |
|
150 | + return references_utils::getModuleOption('images_url').'/'.$this->getVar($fieldName); |
|
151 | 151 | } else { |
152 | - return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
152 | + return REFERENCES_IMAGES_URL.'blank.gif'; |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function getPicturePath($indice) |
163 | 163 | { |
164 | - $fieldName = 'article_picture' . $indice; |
|
164 | + $fieldName = 'article_picture'.$indice; |
|
165 | 165 | if (xoops_trim($this->getVar($fieldName)) != '') { |
166 | - return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName); |
|
166 | + return references_utils::getModuleOption('images_path').DIRECTORY_SEPARATOR.$this->getVar($fieldName); |
|
167 | 167 | } else { |
168 | 168 | return ''; |
169 | 169 | } |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function thumbExists($indice) |
179 | 179 | { |
180 | - $fieldName = 'article_picture' . $indice; |
|
180 | + $fieldName = 'article_picture'.$indice; |
|
181 | 181 | $return = false; |
182 | - if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName))) { |
|
182 | + if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path').DIRECTORY_SEPARATOR.REFERENCES_THUMBS_PREFIX.$this->getVar($fieldName))) { |
|
183 | 183 | $return = true; |
184 | 184 | } |
185 | 185 | |
@@ -194,11 +194,11 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function getThumbUrl($indice) |
196 | 196 | { |
197 | - $fieldName = 'article_picture' . $indice; |
|
197 | + $fieldName = 'article_picture'.$indice; |
|
198 | 198 | if (xoops_trim($this->getVar($fieldName)) != '') { |
199 | - return references_utils::getModuleOption('images_url') . '/' . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
199 | + return references_utils::getModuleOption('images_url').'/'.REFERENCES_THUMBS_PREFIX.$this->getVar($fieldName); |
|
200 | 200 | } else { |
201 | - return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
201 | + return REFERENCES_IMAGES_URL.'blank.gif'; |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | */ |
211 | 211 | public function getThumbPath($indice) |
212 | 212 | { |
213 | - $fieldName = 'article_picture' . $indice; |
|
213 | + $fieldName = 'article_picture'.$indice; |
|
214 | 214 | if (xoops_trim($this->getVar($fieldName)) != '') { |
215 | - return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
215 | + return references_utils::getModuleOption('images_path').DIRECTORY_SEPARATOR.REFERENCES_THUMBS_PREFIX.$this->getVar($fieldName); |
|
216 | 216 | } else { |
217 | 217 | return ''; |
218 | 218 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | public function attachmentExists() |
227 | 227 | { |
228 | 228 | $return = false; |
229 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'))) { |
|
229 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path').DIRECTORY_SEPARATOR.$this->getVar('article_attached_file'))) { |
|
230 | 230 | $return = true; |
231 | 231 | } |
232 | 232 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | public function getAttachmentUrl() |
242 | 242 | { |
243 | 243 | if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
244 | - return references_utils::getModuleOption('attached_url') . '/' . $this->getVar('article_attached_file'); |
|
244 | + return references_utils::getModuleOption('attached_url').'/'.$this->getVar('article_attached_file'); |
|
245 | 245 | } else { |
246 | 246 | return ''; |
247 | 247 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function getAttachmentPath() |
256 | 256 | { |
257 | 257 | if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
258 | - return references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'); |
|
258 | + return references_utils::getModuleOption('attached_path').DIRECTORY_SEPARATOR.$this->getVar('article_attached_file'); |
|
259 | 259 | } else { |
260 | 260 | return ''; |
261 | 261 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | public function deleteAttachment() |
268 | 268 | { |
269 | 269 | if ($this->attachmentExists()) { |
270 | - @unlink(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file')); |
|
270 | + @unlink(references_utils::getModuleOption('attached_path').DIRECTORY_SEPARATOR.$this->getVar('article_attached_file')); |
|
271 | 271 | } |
272 | 272 | $this->setVar('article_attached_file', ''); |
273 | 273 | } |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function deleteThumb($indice) |
282 | 282 | { |
283 | - $fieldName = 'article_picture' . $indice; |
|
283 | + $fieldName = 'article_picture'.$indice; |
|
284 | 284 | if ($this->thumbExists($indice)) { |
285 | - @unlink(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName)); |
|
285 | + @unlink(references_utils::getModuleOption('images_path').DIRECTORY_SEPARATOR.REFERENCES_THUMBS_PREFIX.$this->getVar($fieldName)); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -350,9 +350,9 @@ discard block |
||
350 | 350 | public function getUrl($shortVersion = false) |
351 | 351 | { |
352 | 352 | if (!$shortVersion) { |
353 | - return REFERENCES_URL . 'reference.php?article_id=' . $this->getVar('article_id'); |
|
353 | + return REFERENCES_URL.'reference.php?article_id='.$this->getVar('article_id'); |
|
354 | 354 | } else { |
355 | - return 'reference.php?article_id=' . $this->getVar('article_id'); |
|
355 | + return 'reference.php?article_id='.$this->getVar('article_id'); |
|
356 | 356 | } |
357 | 357 | } |
358 | 358 | |
@@ -375,11 +375,11 @@ discard block |
||
375 | 375 | $ret['article_picture_exists'] = true; |
376 | 376 | for ($i = 1; $i <= 10; ++$i) { |
377 | 377 | if ($this->pictureExists($i)) { |
378 | - $ret['article_picture_url' . $i] = $this->getPictureUrl($i); |
|
379 | - $ret['article_picture_path' . $i] = $this->getPicturePath($i); |
|
378 | + $ret['article_picture_url'.$i] = $this->getPictureUrl($i); |
|
379 | + $ret['article_picture_path'.$i] = $this->getPicturePath($i); |
|
380 | 380 | $ret['article_pictures_urls'][] = $this->getPictureUrl($i); |
381 | 381 | $ret['article_pictures_paths'][] = $this->getPicturePath($i); |
382 | - $fieldName = 'article_picture' . $i . '_text'; |
|
382 | + $fieldName = 'article_picture'.$i.'_text'; |
|
383 | 383 | if (xoops_trim($this->getVar($fieldName)) != '') { |
384 | 384 | $ret['article_pictures_texts'][] = references_utils::makeHrefTitle($this->getVar($fieldName)); |
385 | 385 | } else { |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | $ret['article_thumb_exists'] = true; |
405 | 405 | for ($i = 1; $i <= 10; ++$i) { |
406 | 406 | if ($this->thumbExists($i)) { |
407 | - $ret['article_thumb_url' . $i] = $this->getThumbUrl($i); |
|
408 | - $ret['article_thumb_path' . $i] = $this->getThumbPath($i); |
|
407 | + $ret['article_thumb_url'.$i] = $this->getThumbUrl($i); |
|
408 | + $ret['article_thumb_path'.$i] = $this->getThumbPath($i); |
|
409 | 409 | $ret['article_thumbs_urls'][] = $this->getThumbUrl($i); |
410 | 410 | $ret['article_thumbs_paths'][] = $this->getThumbPath($i); |
411 | 411 | } |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | $gperm_handler = xoops_getHandler('groupperm'); |
447 | 447 | $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
448 | 448 | if (is_array($categories) && count($categories) > 0) { |
449 | - $permissions[$permissionsType] = new Criteria('article_category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
449 | + $permissions[$permissionsType] = new Criteria('article_category_id', '('.implode(',', $categories).')', 'IN'); |
|
450 | 450 | } else { // Ne peut rien voir |
451 | 451 | $permissions[$permissionsType] = new Criteria('article_category_id', '0', '='); |
452 | 452 | } |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | $criteria->add(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
475 | 475 | } |
476 | 476 | if (is_array($categoryId) && count($categoryId) > 0) { |
477 | - $criteria->add(new Criteria('article_category_id', '(' . implode(',', $categoryId) . ')', 'IN')); |
|
477 | + $criteria->add(new Criteria('article_category_id', '('.implode(',', $categoryId).')', 'IN')); |
|
478 | 478 | } elseif ($categoryId > 0) { |
479 | 479 | $criteria->add(new Criteria('article_category_id', $categoryId, '=')); |
480 | 480 | } |
@@ -531,8 +531,8 @@ discard block |
||
531 | 531 | public function getDistinctCategoriesIds() |
532 | 532 | { |
533 | 533 | $ret = array(); |
534 | - $sql = 'SELECT distinct(article_category_id) FROM ' . $this->table; |
|
535 | - $sql .= ' ' . $this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
|
534 | + $sql = 'SELECT distinct(article_category_id) FROM '.$this->table; |
|
535 | + $sql .= ' '.$this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
|
536 | 536 | $sql .= ' GROUP BY article_category_id ORDER BY article_category_id'; |
537 | 537 | $result = $this->db->query($sql); |
538 | 538 | if (!$result) { |
@@ -600,17 +600,17 @@ discard block |
||
600 | 600 | */ |
601 | 601 | public function moveUp($currentId, $currentOrder) |
602 | 602 | { |
603 | - $sql_plus = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder - 1); |
|
603 | + $sql_plus = 'SELECT article_id FROM '.$this->table.' WHERE article_weight = '.((int) $currentOrder - 1); |
|
604 | 604 | $res_plus = $this->db->query($sql_plus); |
605 | 605 | if ($this->db->getRowsNum($res_plus) == 0) { |
606 | 606 | return; |
607 | 607 | } |
608 | 608 | $row_plus = $this->db->fetchArray($res_plus); |
609 | 609 | |
610 | - $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight + 1) WHERE article_id = ' . $row_plus['article_id']; |
|
610 | + $upd1 = 'UPDATE '.$this->table.' SET article_weight = (article_weight + 1) WHERE article_id = '.$row_plus['article_id']; |
|
611 | 611 | $this->db->queryF($upd1); |
612 | 612 | |
613 | - $upd2 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . (int)$currentId; |
|
613 | + $upd2 = 'UPDATE '.$this->table.' SET article_weight = (article_weight - 1) WHERE article_id = '.(int) $currentId; |
|
614 | 614 | $this->db->queryF($upd2); |
615 | 615 | $this->forceCacheClean(); |
616 | 616 | } |
@@ -624,17 +624,17 @@ discard block |
||
624 | 624 | */ |
625 | 625 | public function moveDown($currentId, $currentOrder) |
626 | 626 | { |
627 | - $sql_moins = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder + 1); |
|
627 | + $sql_moins = 'SELECT article_id FROM '.$this->table.' WHERE article_weight = '.((int) $currentOrder + 1); |
|
628 | 628 | $res_moins = $this->db->query($sql_moins); |
629 | 629 | if ($this->db->getRowsNum($res_moins) == 0) { |
630 | 630 | return; |
631 | 631 | } |
632 | 632 | |
633 | 633 | $row_moins = $this->db->fetchArray($res_moins); |
634 | - $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . $row_moins['article_id']; |
|
634 | + $upd1 = 'UPDATE '.$this->table.' SET article_weight = (article_weight - 1) WHERE article_id = '.$row_moins['article_id']; |
|
635 | 635 | $this->db->queryF($upd1); |
636 | 636 | |
637 | - $upd2 = 'UPDATE ' . $this->table . ' SET article_weight =( article_weight + 1) WHERE article_id = ' . (int)$currentId; |
|
637 | + $upd2 = 'UPDATE '.$this->table.' SET article_weight =( article_weight + 1) WHERE article_id = '.(int) $currentId; |
|
638 | 638 | $this->db->queryF($upd2); |
639 | 639 | $this->forceCacheClean(); |
640 | 640 | } |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | /** |
186 | 186 | * Notification de la création d'une nouvelle catégorie |
187 | 187 | * |
188 | - * @param object|references_categories $category |
|
188 | + * @param references_categories $category |
|
189 | 189 | * @return bool |
190 | 190 | */ |
191 | 191 | public function notifyNewCategory(references_categories $category) |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | /** |
200 | 200 | * Indique si une catégorie est visible d'un utilisateur |
201 | 201 | * |
202 | - * @param object|references_categories $category La catégorie à controler |
|
202 | + * @param references_categories $category La catégorie à controler |
|
203 | 203 | * @param integer $uid L'id de l'utilisateur à controler |
204 | 204 | * @return bool |
205 | 205 | */ |
@@ -19,200 +19,200 @@ |
||
19 | 19 | * **************************************************************************** |
20 | 20 | */ |
21 | 21 | if (!defined('XOOPS_ROOT_PATH')) { |
22 | - die('XOOPS root path not defined'); |
|
22 | + die('XOOPS root path not defined'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
26 | 26 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
27 | - require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
27 | + require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | class references_categories extends references_Object |
31 | 31 | { |
32 | - public function __construct() |
|
33 | - { |
|
34 | - $this->initVar('category_id', XOBJ_DTYPE_INT, null, false); |
|
35 | - $this->initVar('category_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
36 | - $this->initVar('category_weight', XOBJ_DTYPE_INT, null, false); |
|
37 | - $this->initVar('category_description', XOBJ_DTYPE_TXTAREA, null, false); |
|
38 | - // Pour autoriser le html |
|
39 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getHrefTitle() |
|
48 | - { |
|
49 | - return references_utils::makeHrefTitle($this->getVar('category_title')); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Retourne l'url à utiliser pour atteindre la catégorie |
|
54 | - * |
|
55 | - * @param bool $shortVersion |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function getUrl($shortVersion = false) |
|
59 | - { |
|
60 | - if (!$shortVersion) { |
|
61 | - return REFERENCES_URL . 'category.php?category_id=' . $this->getVar('category_id'); |
|
62 | - } else { |
|
63 | - return 'category.php?category_id=' . $this->getVar('category_id'); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Retourne les éléments de l'annnonce formatés pour affichage |
|
69 | - * |
|
70 | - * @param string $format Format à utiliser |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function toArray($format = 's') |
|
74 | - { |
|
75 | - $ret = array(); |
|
76 | - $ret = parent::toArray($format); |
|
77 | - $ret['category_href_title'] = $this->getHrefTitle(); |
|
78 | - $ret['category_url_rewrited'] = $this->getUrl(); |
|
79 | - |
|
80 | - return $ret; |
|
81 | - } |
|
32 | + public function __construct() |
|
33 | + { |
|
34 | + $this->initVar('category_id', XOBJ_DTYPE_INT, null, false); |
|
35 | + $this->initVar('category_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
36 | + $this->initVar('category_weight', XOBJ_DTYPE_INT, null, false); |
|
37 | + $this->initVar('category_description', XOBJ_DTYPE_TXTAREA, null, false); |
|
38 | + // Pour autoriser le html |
|
39 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getHrefTitle() |
|
48 | + { |
|
49 | + return references_utils::makeHrefTitle($this->getVar('category_title')); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Retourne l'url à utiliser pour atteindre la catégorie |
|
54 | + * |
|
55 | + * @param bool $shortVersion |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function getUrl($shortVersion = false) |
|
59 | + { |
|
60 | + if (!$shortVersion) { |
|
61 | + return REFERENCES_URL . 'category.php?category_id=' . $this->getVar('category_id'); |
|
62 | + } else { |
|
63 | + return 'category.php?category_id=' . $this->getVar('category_id'); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Retourne les éléments de l'annnonce formatés pour affichage |
|
69 | + * |
|
70 | + * @param string $format Format à utiliser |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function toArray($format = 's') |
|
74 | + { |
|
75 | + $ret = array(); |
|
76 | + $ret = parent::toArray($format); |
|
77 | + $ret['category_href_title'] = $this->getHrefTitle(); |
|
78 | + $ret['category_url_rewrited'] = $this->getUrl(); |
|
79 | + |
|
80 | + return $ret; |
|
81 | + } |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | class ReferencesReferences_categoriesHandler extends references_XoopsPersistableObjectHandler |
85 | 85 | { |
86 | - public function __construct($db) |
|
87 | - { // Table Classe Id Descr. |
|
88 | - parent::__construct($db, 'references_categories', 'references_categories', 'category_id', 'category_title'); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Retourne le crit�re � utiliser pour voir les cat�gories en respectant les permissions |
|
93 | - * |
|
94 | - * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
95 | - * @return obejct de type Criteria |
|
96 | - */ |
|
97 | - public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
98 | - { |
|
99 | - global $xoopsUser; |
|
100 | - static $permissions = array(); |
|
101 | - if (references_utils::isAdmin()) { |
|
102 | - return new Criteria('category_id', '0', '>'); |
|
103 | - } |
|
104 | - if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
105 | - return $permissions[$permissionsType]; |
|
106 | - } |
|
107 | - $categories = array(); |
|
108 | - $currentModule = references_utils::getModule(); |
|
109 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
110 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
111 | - $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
112 | - if (is_array($categories) && count($categories) > 0) { |
|
113 | - $permissions[$permissionsType] = new Criteria('category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
114 | - } else { // Ne peut rien voir |
|
115 | - $permissions[$permissionsType] = new Criteria('category_id', '0', '='); |
|
116 | - } |
|
117 | - |
|
118 | - return $permissions[$permissionsType]; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Retourne les catégories |
|
123 | - * |
|
124 | - * @param integer $start Indice de début |
|
125 | - * @param integer $limit Nombre d'objets à renvoyer |
|
126 | - * @param string $sort Zone de tri |
|
127 | - * @param string $order Sens du tri |
|
128 | - * @return array Objets de type references_categories |
|
129 | - */ |
|
130 | - public function getCategories($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
131 | - { |
|
132 | - $criteria = new CriteriaCompo(); |
|
133 | - $criteria->add(new Criteria('category_id', 0, '<>')); |
|
134 | - $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
135 | - $criteria->setStart($start); |
|
136 | - $criteria->setSort($sort); |
|
137 | - $criteria->setOrder($order); |
|
138 | - $criteria->setLimit($limit); |
|
139 | - |
|
140 | - return $this->getObjects($criteria, true); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Retourne la liste des catégories en tant que tableau |
|
145 | - * @param integer $start Position de départ |
|
146 | - * @param integer $limit Nombre maximum d'objets à retourner |
|
147 | - * @param string $sort ordre de tri |
|
148 | - * @param string $order Sens du tri |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function getListArray($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
152 | - { |
|
153 | - $criteria = new CriteriaCompo(); |
|
154 | - $criteria->add(new Criteria('category_id', 0, '<>')); |
|
155 | - $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
156 | - $criteria->setStart($start); |
|
157 | - $criteria->setSort($sort); |
|
158 | - $criteria->setOrder($order); |
|
159 | - $criteria->setLimit($limit); |
|
160 | - |
|
161 | - return $this->getList($criteria); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Retourne le sélecteur à utiliser pour voir la liste des catégies |
|
166 | - * |
|
167 | - * @param string $selectName Le nom du sélecteur |
|
168 | - * @param integer $selected L'élément sélectionné |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function getCategoriesSelect($selectName = 'categoriesSelect', $selected = 0) |
|
172 | - { |
|
173 | - $categories = array(); |
|
174 | - $ret = ''; |
|
175 | - $categories = $this->getListArray(0, 0, 'category_weight ASC, category_title', 'ASC'); |
|
176 | - if (count($categories) == 0) { |
|
177 | - return $ret; |
|
178 | - } |
|
179 | - $jump = REFERENCES_URL . 'category.php?category_id='; |
|
180 | - $extra = " onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'"; |
|
181 | - |
|
182 | - return references_utils::htmlSelect($selectName, $categories, $selected, true, '', false, 1, $extra); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Notification de la création d'une nouvelle catégorie |
|
187 | - * |
|
188 | - * @param object|references_categories $category |
|
189 | - * @return bool |
|
190 | - */ |
|
191 | - public function notifyNewCategory(references_categories $category) |
|
192 | - { |
|
193 | - $plugins = references_plugins::getInstance(); |
|
194 | - $plugins->fireAction(references_plugins::EVENT_ON_CATEGORY_CREATE, new references_parameters(array('category' => $category))); |
|
195 | - |
|
196 | - return true; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Indique si une catégorie est visible d'un utilisateur |
|
201 | - * |
|
202 | - * @param object|references_categories $category La catégorie à controler |
|
203 | - * @param integer $uid L'id de l'utilisateur à controler |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function userCanSeeCategory(references_categories $category, $uid = 0) |
|
207 | - { |
|
208 | - global $xoopsUser; |
|
209 | - if ($uid == 0) { |
|
210 | - $uid = references_utils::getCurrentUserID(); |
|
211 | - } |
|
212 | - $currentModule = references_utils::getModule(); |
|
213 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
214 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
215 | - |
|
216 | - return $gperm_handler->checkRight(REFERENCES_PERM_READ, $category->category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
217 | - } |
|
86 | + public function __construct($db) |
|
87 | + { // Table Classe Id Descr. |
|
88 | + parent::__construct($db, 'references_categories', 'references_categories', 'category_id', 'category_title'); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Retourne le crit�re � utiliser pour voir les cat�gories en respectant les permissions |
|
93 | + * |
|
94 | + * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
95 | + * @return obejct de type Criteria |
|
96 | + */ |
|
97 | + public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
98 | + { |
|
99 | + global $xoopsUser; |
|
100 | + static $permissions = array(); |
|
101 | + if (references_utils::isAdmin()) { |
|
102 | + return new Criteria('category_id', '0', '>'); |
|
103 | + } |
|
104 | + if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
105 | + return $permissions[$permissionsType]; |
|
106 | + } |
|
107 | + $categories = array(); |
|
108 | + $currentModule = references_utils::getModule(); |
|
109 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
110 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
111 | + $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
112 | + if (is_array($categories) && count($categories) > 0) { |
|
113 | + $permissions[$permissionsType] = new Criteria('category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
114 | + } else { // Ne peut rien voir |
|
115 | + $permissions[$permissionsType] = new Criteria('category_id', '0', '='); |
|
116 | + } |
|
117 | + |
|
118 | + return $permissions[$permissionsType]; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Retourne les catégories |
|
123 | + * |
|
124 | + * @param integer $start Indice de début |
|
125 | + * @param integer $limit Nombre d'objets à renvoyer |
|
126 | + * @param string $sort Zone de tri |
|
127 | + * @param string $order Sens du tri |
|
128 | + * @return array Objets de type references_categories |
|
129 | + */ |
|
130 | + public function getCategories($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
131 | + { |
|
132 | + $criteria = new CriteriaCompo(); |
|
133 | + $criteria->add(new Criteria('category_id', 0, '<>')); |
|
134 | + $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
135 | + $criteria->setStart($start); |
|
136 | + $criteria->setSort($sort); |
|
137 | + $criteria->setOrder($order); |
|
138 | + $criteria->setLimit($limit); |
|
139 | + |
|
140 | + return $this->getObjects($criteria, true); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Retourne la liste des catégories en tant que tableau |
|
145 | + * @param integer $start Position de départ |
|
146 | + * @param integer $limit Nombre maximum d'objets à retourner |
|
147 | + * @param string $sort ordre de tri |
|
148 | + * @param string $order Sens du tri |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function getListArray($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
152 | + { |
|
153 | + $criteria = new CriteriaCompo(); |
|
154 | + $criteria->add(new Criteria('category_id', 0, '<>')); |
|
155 | + $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
156 | + $criteria->setStart($start); |
|
157 | + $criteria->setSort($sort); |
|
158 | + $criteria->setOrder($order); |
|
159 | + $criteria->setLimit($limit); |
|
160 | + |
|
161 | + return $this->getList($criteria); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Retourne le sélecteur à utiliser pour voir la liste des catégies |
|
166 | + * |
|
167 | + * @param string $selectName Le nom du sélecteur |
|
168 | + * @param integer $selected L'élément sélectionné |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function getCategoriesSelect($selectName = 'categoriesSelect', $selected = 0) |
|
172 | + { |
|
173 | + $categories = array(); |
|
174 | + $ret = ''; |
|
175 | + $categories = $this->getListArray(0, 0, 'category_weight ASC, category_title', 'ASC'); |
|
176 | + if (count($categories) == 0) { |
|
177 | + return $ret; |
|
178 | + } |
|
179 | + $jump = REFERENCES_URL . 'category.php?category_id='; |
|
180 | + $extra = " onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'"; |
|
181 | + |
|
182 | + return references_utils::htmlSelect($selectName, $categories, $selected, true, '', false, 1, $extra); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Notification de la création d'une nouvelle catégorie |
|
187 | + * |
|
188 | + * @param object|references_categories $category |
|
189 | + * @return bool |
|
190 | + */ |
|
191 | + public function notifyNewCategory(references_categories $category) |
|
192 | + { |
|
193 | + $plugins = references_plugins::getInstance(); |
|
194 | + $plugins->fireAction(references_plugins::EVENT_ON_CATEGORY_CREATE, new references_parameters(array('category' => $category))); |
|
195 | + |
|
196 | + return true; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Indique si une catégorie est visible d'un utilisateur |
|
201 | + * |
|
202 | + * @param object|references_categories $category La catégorie à controler |
|
203 | + * @param integer $uid L'id de l'utilisateur à controler |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function userCanSeeCategory(references_categories $category, $uid = 0) |
|
207 | + { |
|
208 | + global $xoopsUser; |
|
209 | + if ($uid == 0) { |
|
210 | + $uid = references_utils::getCurrentUserID(); |
|
211 | + } |
|
212 | + $currentModule = references_utils::getModule(); |
|
213 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
214 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
215 | + |
|
216 | + return $gperm_handler->checkRight(REFERENCES_PERM_READ, $category->category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
217 | + } |
|
218 | 218 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | die('XOOPS root path not defined'); |
23 | 23 | } |
24 | 24 | |
25 | -require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
|
25 | +require_once XOOPS_ROOT_PATH.'/kernel/object.php'; |
|
26 | 26 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
27 | - require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
27 | + require_once XOOPS_ROOT_PATH.'/modules/references/class/PersistableObjectHandler.php'; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | class references_categories extends references_Object |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | public function getUrl($shortVersion = false) |
59 | 59 | { |
60 | 60 | if (!$shortVersion) { |
61 | - return REFERENCES_URL . 'category.php?category_id=' . $this->getVar('category_id'); |
|
61 | + return REFERENCES_URL.'category.php?category_id='.$this->getVar('category_id'); |
|
62 | 62 | } else { |
63 | - return 'category.php?category_id=' . $this->getVar('category_id'); |
|
63 | + return 'category.php?category_id='.$this->getVar('category_id'); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $gperm_handler = xoops_getHandler('groupperm'); |
111 | 111 | $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
112 | 112 | if (is_array($categories) && count($categories) > 0) { |
113 | - $permissions[$permissionsType] = new Criteria('category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
113 | + $permissions[$permissionsType] = new Criteria('category_id', '('.implode(',', $categories).')', 'IN'); |
|
114 | 114 | } else { // Ne peut rien voir |
115 | 115 | $permissions[$permissionsType] = new Criteria('category_id', '0', '='); |
116 | 116 | } |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | if (count($categories) == 0) { |
177 | 177 | return $ret; |
178 | 178 | } |
179 | - $jump = REFERENCES_URL . 'category.php?category_id='; |
|
180 | - $extra = " onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'"; |
|
179 | + $jump = REFERENCES_URL.'category.php?category_id='; |
|
180 | + $extra = " onchange='location=\"".$jump."\"+this.options[this.selectedIndex].value'"; |
|
181 | 181 | |
182 | 182 | return references_utils::htmlSelect($selectName, $categories, $selected, true, '', false, 1, $extra); |
183 | 183 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | /** |
254 | 254 | * Retourne les noms à utiliser pour les champs de tri (sélecteur de champ et ordre de tri) |
255 | 255 | * |
256 | - * @return array [0] = Nom du sélecteur de champs, [1] = Nom du sélecteur pour le sens du tri |
|
256 | + * @return string[] [0] = Nom du sélecteur de champs, [1] = Nom du sélecteur pour le sens du tri |
|
257 | 257 | */ |
258 | 258 | private function getSortPlaceHolderNames() |
259 | 259 | { |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @param string $optionName |
281 | 281 | * @param mixed $optionValue |
282 | - * @return object |
|
282 | + * @return references_listFilter |
|
283 | 283 | */ |
284 | 284 | public function setOption($optionName, $optionValue) |
285 | 285 | { |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * [data] A ne pas renseigner, contient la valeur saisie par l'utilisateur |
409 | 409 | * [operator] Opérateur de comparaison pour le Criteria |
410 | 410 | * [autoComplete] Indique si on active l'auto complétion sur le champs |
411 | - * @return object L'objet courant pour pouvoir chainer |
|
411 | + * @return references_listFilter L'objet courant pour pouvoir chainer |
|
412 | 412 | */ |
413 | 413 | public function initFilter($fieldName, $parameters) |
414 | 414 | { |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | /** |
465 | 465 | * Ajoute les critères par défaut au critère général |
466 | 466 | * |
467 | - * @return void |
|
467 | + * @return references_listFilter |
|
468 | 468 | */ |
469 | 469 | private function addDefaultCriterias() |
470 | 470 | { |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | /** |
593 | 593 | * Méthode à appeler juste après le constructeur pour qu'elle récupère les données saisies |
594 | 594 | * |
595 | - * @return object L'objet courant pour pouvoir chainer |
|
595 | + * @return references_listFilter L'objet courant pour pouvoir chainer |
|
596 | 596 | */ |
597 | 597 | public function filter() |
598 | 598 | { |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | * |
718 | 718 | * @param string $key |
719 | 719 | * @param string $value |
720 | - * @return object |
|
720 | + * @return references_listFilter |
|
721 | 721 | */ |
722 | 722 | public function addAdditionnalParameterToPager($key, $value = '') |
723 | 723 | { |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | * |
732 | 732 | * @param string $key |
733 | 733 | * @param string $value |
734 | - * @return object |
|
734 | + * @return references_listFilter |
|
735 | 735 | */ |
736 | 736 | public function addAdditionnalParameterToClearButton($key, $value = '') |
737 | 737 | { |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * Permet d'ajouter des paramètres supplémentaires au pager |
745 | 745 | * |
746 | 746 | * @param $array |
747 | - * @return object |
|
747 | + * @return references_listFilter |
|
748 | 748 | * @internal param string $key |
749 | 749 | * @internal param string $value |
750 | 750 | */ |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | /** |
763 | 763 | * Retourne le pager à utiliser |
764 | 764 | * |
765 | - * @return mixed Null s'il n'y a pas lieu d'y avoir un pager, sinon un objet de type {@link XoopsPageNav} |
|
765 | + * @return XoopsPageNav|null Null s'il n'y a pas lieu d'y avoir un pager, sinon un objet de type {@link XoopsPageNav} |
|
766 | 766 | */ |
767 | 767 | public function getPager() |
768 | 768 | { |
@@ -35,930 +35,930 @@ |
||
35 | 35 | */ |
36 | 36 | class references_listFilter |
37 | 37 | { |
38 | - const FILTER_DATA_TEXT = 1; |
|
39 | - const FILTER_DATA_NUMERIC = 2; |
|
40 | - |
|
41 | - const FILTER_FIELD_TEXT = 1; |
|
42 | - const FILTER_FIELD_SELECT = 2; |
|
43 | - const FILTER_FIELD_SELECT_YES_NO = 3; |
|
44 | - |
|
45 | - /** |
|
46 | - * Préfixe des variables de sélection |
|
47 | - */ |
|
48 | - const PREFIX = 'filter_'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Nom du module (utilisé pour la session) |
|
52 | - */ |
|
53 | - const MODULE_NAME = 'references'; |
|
54 | - |
|
55 | - /** |
|
56 | - * Contient toutes les variables participant au filtre (avec leur type et description) |
|
57 | - * |
|
58 | - * @var array |
|
59 | - */ |
|
60 | - private $vars = array(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Handler des données |
|
64 | - * |
|
65 | - * @var reference |
|
66 | - */ |
|
67 | - private $handler = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * Nom de la zone d'opération (par exemple op=products) |
|
71 | - * |
|
72 | - * @var string |
|
73 | - */ |
|
74 | - private $op = ''; |
|
75 | - |
|
76 | - /** |
|
77 | - * action de l'opération en cour (par exemple op=products) |
|
78 | - * |
|
79 | - * @var string |
|
80 | - */ |
|
81 | - private $operationName = ''; |
|
82 | - |
|
83 | - /** |
|
84 | - * Nombre maximum d'éléments pas page |
|
85 | - * |
|
86 | - * @var intger |
|
87 | - */ |
|
88 | - private $limit = 10; |
|
89 | - |
|
90 | - /** |
|
91 | - * Nom de la variable start |
|
92 | - * |
|
93 | - * @var string |
|
94 | - */ |
|
95 | - private $startName = ''; |
|
96 | - |
|
97 | - /** |
|
98 | - * Critère {@link Criteria} servant à choisir les données |
|
99 | - * |
|
100 | - * @var object |
|
101 | - */ |
|
102 | - private $criteria = null; |
|
103 | - |
|
104 | - /** |
|
105 | - * Indique s'il y a un nouveau critère |
|
106 | - * |
|
107 | - * @var boolean |
|
108 | - */ |
|
109 | - private $newFilter = false; |
|
110 | - |
|
111 | - /** |
|
112 | - * Indique si la méthode filter() a été appelée |
|
113 | - * |
|
114 | - * @var boolean |
|
115 | - */ |
|
116 | - private $isInitialized = false; |
|
117 | - |
|
118 | - /** |
|
119 | - * Zone de tri pour retourner les données (dans getObjects) |
|
120 | - * |
|
121 | - * @var string |
|
122 | - */ |
|
123 | - private $sortField = ''; |
|
124 | - |
|
125 | - /** |
|
126 | - * Sens de tri |
|
127 | - * |
|
128 | - * @var string |
|
129 | - */ |
|
130 | - private $sortOrder = ''; |
|
131 | - |
|
132 | - /** |
|
133 | - * Liste de critères par défaut |
|
134 | - * |
|
135 | - * @var array |
|
136 | - */ |
|
137 | - private $defaultCriterias = array(); |
|
138 | - |
|
139 | - /** |
|
140 | - * L'url complète du script qui appelle |
|
141 | - * |
|
142 | - * @var string |
|
143 | - */ |
|
144 | - private $baseUrl = ''; |
|
145 | - |
|
146 | - /** |
|
147 | - * Indique si on conserve en session la position de départ |
|
148 | - * |
|
149 | - * @var boolean |
|
150 | - */ |
|
151 | - private $keepStart = true; |
|
152 | - |
|
153 | - /** |
|
154 | - * Indique si l'autocomplétion est activée |
|
155 | - * |
|
156 | - * @var boolean |
|
157 | - */ |
|
158 | - private $hasAutoComplete = false; |
|
159 | - |
|
160 | - /** |
|
161 | - * Url du dossier js dans le module |
|
162 | - * |
|
163 | - * @var string |
|
164 | - */ |
|
165 | - private $jsFolderUrl = ''; |
|
166 | - |
|
167 | - /** |
|
168 | - * Paramètres additionnels à ajouter aux paramètres du pager |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - private $additionnalPagerParameters = array(); |
|
172 | - |
|
173 | - /** |
|
174 | - * Paramètres additionnels à ajouter au bouton permettant de supprimer le filtre en cours |
|
175 | - * @var array |
|
176 | - */ |
|
177 | - private $additionnalClearButtonParameters = array(); |
|
178 | - |
|
179 | - /** |
|
180 | - * Tableau des champs triables [clé] = nom du champ dans la base, valeur = libellé |
|
181 | - * @var array |
|
182 | - */ |
|
183 | - private $sortFields = array(); |
|
184 | - |
|
185 | - /** |
|
186 | - * Initialise les paramètres avec des valeurs par défaut |
|
187 | - */ |
|
188 | - private function setDefaultValues() |
|
189 | - { |
|
190 | - $this->handler = null; |
|
191 | - $this->op = ''; |
|
192 | - $this->limit = 10; |
|
193 | - $this->startName = 'start'; |
|
194 | - $this->operationName = 'op'; |
|
195 | - $this->sortField = ''; |
|
196 | - $this->sortOrder = 'asc'; |
|
197 | - $this->baseUrl = ''; |
|
198 | - $this->keepStart = true; |
|
199 | - $this->hasAutoComplete = false; |
|
200 | - $this->jsFolderUrl = ''; |
|
201 | - $this->additionnalPagerParameters = array(); |
|
202 | - $this->additionnalClearButtonParameters = array(); |
|
203 | - $this->sortFields = array(); // Les champs qui peuvent être utilisés pour trier |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Initialisation des données, handler et opération courante dans l'appelant |
|
208 | - * |
|
209 | - * @param mixed $handler Soit une référence au handler de données soit un tableau qui contient toutes les options (auxquel cas les autres paramètres sont inutiles) |
|
210 | - * @param string $operationName |
|
211 | - * @param string $operation Opération courante dans l'appelant |
|
212 | - * @param string $startName Nom du paramètre start |
|
213 | - * @param integer $limit Nombre maximum d'éléments par page |
|
214 | - * @param string $baseUrl L'url complète du script appelant |
|
215 | - * @param string $sortField Zone de tri |
|
216 | - * @param string $sortOrder Sens de tri |
|
217 | - * @param boolean $keepStart Indique si on conserve la position de départ |
|
218 | - * @param string $jsFolderUrl |
|
219 | - * @package string $jsFolderUrl Url du répertoire qui contient les scripts Javascript |
|
220 | - */ |
|
221 | - public function __construct($handler, $operationName = 'op', $operation = '', $startName = 'start', $limit = 10, $baseUrl = '', $sortField = '', $sortOrder = 'asc', $keepStart = true, $jsFolderUrl = '') |
|
222 | - { |
|
223 | - $this->setDefaultValues(); |
|
224 | - if (!is_array($handler)) { |
|
225 | - $this->handler = $handler; |
|
226 | - $this->op = $operation; |
|
227 | - $this->limit = $limit; |
|
228 | - $this->startName = $startName; |
|
229 | - $this->operationName = $operationName; |
|
230 | - $this->sortField = $sortField; |
|
231 | - $this->sortOrder = $sortOrder; |
|
232 | - $this->baseUrl = $baseUrl; |
|
233 | - $this->keepStart = $keepStart; |
|
234 | - $this->jsFolderUrl = $jsFolderUrl; |
|
235 | - } else { |
|
236 | - foreach ($handler as $key => $value) { |
|
237 | - $this->$key = $value; |
|
238 | - } |
|
239 | - } |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Donne à la classe le nom des champs sur lesquels on peut faire le tri |
|
244 | - * |
|
245 | - * @param array $fields [clé] = nom du champ dans la base, valeur = libellé |
|
246 | - * @return object |
|
247 | - */ |
|
248 | - public function setSortFields($fields) |
|
249 | - { |
|
250 | - $this->sortFields = $fields; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Retourne les noms à utiliser pour les champs de tri (sélecteur de champ et ordre de tri) |
|
255 | - * |
|
256 | - * @return array [0] = Nom du sélecteur de champs, [1] = Nom du sélecteur pour le sens du tri |
|
257 | - */ |
|
258 | - private function getSortPlaceHolderNames() |
|
259 | - { |
|
260 | - return array(self::PREFIX . 'sortFields', self::PREFIX . 'sortOrder'); |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * Retourne 2 sélecteurs html pour choisir la zone de tri et le sens du tri |
|
265 | - * |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public function getSortPlaceHolderHtmlCode() |
|
269 | - { |
|
270 | - $sortNames = $this->getSortPlaceHolderNames(); |
|
271 | - $sortFieldsHtml = references_utils::htmlSelect($sortNames[0], $this->sortFields, $this->sortField, false); |
|
272 | - $sortOrderHtml = references_utils::htmlSelect($sortNames[1], array('asc' => _MD_REFERENCES_ASC, 'desc' => _MD_REFERENCES_DESC), $this->sortOrder, false); |
|
273 | - |
|
274 | - return _MD_REFERENCES_SORT_BY . ' ' . $sortFieldsHtml . ' ' . $sortOrderHtml; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Permet de valoriser une option directement tout en chainant |
|
279 | - * |
|
280 | - * @param string $optionName |
|
281 | - * @param mixed $optionValue |
|
282 | - * @return object |
|
283 | - */ |
|
284 | - public function setOption($optionName, $optionValue) |
|
285 | - { |
|
286 | - $this->$optionName = $optionValue; |
|
287 | - |
|
288 | - return $this; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Ajoute un nouveau critère par défaut à la liste des critères par défaut |
|
293 | - * |
|
294 | - * @param Criteria $criteria |
|
295 | - */ |
|
296 | - public function addDefaultCriteria(Criteria $criteria) |
|
297 | - { |
|
298 | - $this->defaultCriterias[] = $criteria; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * Retourne une valeur d'un tableau ou null si l'index n'existe pas |
|
303 | - * |
|
304 | - * @param array $array Le tableau à traiter |
|
305 | - * @param string $index L'index recherché |
|
306 | - * @param mixed $defaultValue La valeur par défaut |
|
307 | - * @return mixed |
|
308 | - */ |
|
309 | - private function getArrayValue($array, $index, $defaultValue = false) |
|
310 | - { |
|
311 | - if ($index === 'autoComplete' && isset($array[$index]) && isset($array[$index]) == true) { |
|
312 | - $this->hasAutoComplete = true; // On en profite pour vérifier si un champ utilise l'autocomplétion |
|
313 | - } |
|
314 | - |
|
315 | - return isset($array[$index]) ? $array[$index] : $defaultValue; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Permet de faire l'autocomplétion d'un champ |
|
320 | - * |
|
321 | - * @param string $query |
|
322 | - * @param $limit |
|
323 | - * @param string $fieldName |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function autoComplete($query, $limit, $fieldName) |
|
327 | - { |
|
328 | - $return = ''; |
|
329 | - if (!$this->hasAutoComplete) { // Si aucun champ n'est en autocomplétion, c'est pas la peine d'aller plus loin |
|
330 | - |
|
331 | - return $return; |
|
332 | - } |
|
333 | - if (isset($this->vars[$fieldName])) { // On vérifie que le champ demandé est bien en autocomplétion |
|
334 | - if ($this->vars[$fieldName]['autoComplete'] == true) { |
|
335 | - if ($this->vars[$fieldName]['dataType'] == self::FILTER_DATA_TEXT) { |
|
336 | - $criteria = new Criteria($fieldName, $query . '%', 'LIKE'); |
|
337 | - } |
|
338 | - $criteria->setLimit((int)$limit); |
|
339 | - $ret = $this->handler->getObjects($criteria); |
|
340 | - |
|
341 | - if (count($ret) > 0) { |
|
342 | - foreach ($ret as $object) { |
|
343 | - $return .= $object->getVar($fieldName, 'n') . "\n"; |
|
344 | - } |
|
345 | - } |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - return $return; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Retourne le code Javascript à utiliser pour initialiser l'auto complétion (et donc à coller dans le code html) |
|
354 | - * |
|
355 | - * @param boolean $jqueryAlreadyLoaded Indique si jQuery est déjà chargé par l'appelant, auquel cas rien ne sert de le recharger |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function getJavascriptInitCode($jqueryAlreadyLoaded = false) |
|
359 | - { |
|
360 | - $return = ''; |
|
361 | - if (!$this->hasAutoComplete) { |
|
362 | - return $return; |
|
363 | - } |
|
364 | - $return = ''; |
|
365 | - $return .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" title=\"Style sheet\" href=\"" . $this->jsFolderUrl . "autocomplete/jquery.autocomplete.css\" />\n"; |
|
366 | - if (!$jqueryAlreadyLoaded) { |
|
367 | - $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "jquery/jquery.js\"></script>\n"; |
|
368 | - } |
|
369 | - $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "noconflict.js\"></script>\n"; |
|
370 | - $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "autocomplete/jquery.autocomplete.min.js\"></script>\n"; |
|
371 | - $return .= "<script type=\"text/javascript\">\n"; |
|
372 | - $return .= "jQuery(function($) {\n"; |
|
373 | - $return .= "var url='" . $this->baseUrl . "';\n"; // TODO: Supprimer "var" car cela limite sa portée ! |
|
374 | - $return .= "var handlerName='" . $this->handler->className . "';\n"; |
|
375 | - |
|
376 | - foreach ($this->vars as $fieldName => $parameters) { |
|
377 | - if ($parameters['autoComplete'] == true) { |
|
378 | - $field = self::PREFIX . $fieldName; |
|
379 | - $return .= "$('#" . $field . "').autocomplete(url, {\n"; |
|
380 | - $return .= "extraParams: {\n"; |
|
381 | - $return .= " field: '" . $fieldName . "',\n"; |
|
382 | - $return .= " op: 'autocomplete',\n"; |
|
383 | - $return .= " handler: handlerName\n"; |
|
384 | - $return .= "}\n"; |
|
385 | - $return .= "});\n"; |
|
386 | - } |
|
387 | - } |
|
388 | - $return .= "});\n"; |
|
389 | - $return .= "</script>\n"; |
|
390 | - |
|
391 | - return $return; |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Initialisation des données du filtre |
|
396 | - * Permet d'indiquer quelles sont les zones sur lesquelles on effectue des filtres ainsi que leur type |
|
397 | - * |
|
398 | - * @param string $fieldName Le nom du champs dans la table |
|
399 | - * @param array $parameters Les paramètres de la zone sous la forme d'un tableau : |
|
400 | - * [dataType] Entier représentant le type de donnée (numérique ou chaine) |
|
401 | - * [fieldType] Le type de zone de saisie (zone de texte, liste déroulante, liste déroulante Oui/Non) |
|
402 | - * [values] La ou les valeurs de la zone de saisie (utilisé dans le cas d'un select) |
|
403 | - * [size] Largeur d'affichage pour les textbox |
|
404 | - * [maxLength] Largeur maximale pour les textbox |
|
405 | - * [withNull] Dans le cas des listes déroulantes, indique s'il faut une valeur nulle |
|
406 | - * [minusOne] Indique s'il faut retrancher 1 à la valeur saisie récupérée (cas classique des listes Oui/Non avec une valeur nulle) |
|
407 | - * [style] Dans le cas des liste déroulante, le style à appliquer à la liste |
|
408 | - * [data] A ne pas renseigner, contient la valeur saisie par l'utilisateur |
|
409 | - * [operator] Opérateur de comparaison pour le Criteria |
|
410 | - * [autoComplete] Indique si on active l'auto complétion sur le champs |
|
411 | - * @return object L'objet courant pour pouvoir chainer |
|
412 | - */ |
|
413 | - public function initFilter($fieldName, $parameters) |
|
414 | - { |
|
415 | - // Tableau des valeurs attendues avec leur valeur par défaut |
|
416 | - $indexNames = array('dataType' => self::FILTER_DATA_TEXT, 'fieldType' => self::FILTER_FIELD_TEXT, 'values' => null, 'withNull' => false, 'size' => 5, 'maxLength' => 255, 'minusOne' => false, 'data' => null, 'style' => '', 'operator' => '=', 'autoComplete' => false); |
|
417 | - $data = array(); |
|
418 | - foreach ($indexNames as $indexName => $defaultValue) { |
|
419 | - $data[$indexName] = $this->getArrayValue($parameters, $indexName, $defaultValue); |
|
420 | - } |
|
421 | - $this->vars[$fieldName] = $data; |
|
422 | - |
|
423 | - return $this; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Retourne le nom du tableau à utiliser pour la session |
|
428 | - * @note : Le nom de la session est composé de : nom du module_nom du handler, par exemple references_references_articles |
|
429 | - * |
|
430 | - * @return string |
|
431 | - */ |
|
432 | - private function getSessionName() |
|
433 | - { |
|
434 | - return self::MODULE_NAME . '_' . $this->handler->table; |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Retourne le nom de la clé à utiliser pour la conservation du start en session |
|
439 | - * |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - private function getStartSessionName() |
|
443 | - { |
|
444 | - return $this->getSessionName() . '_start'; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Réinitialisation des données avant traitement |
|
449 | - * |
|
450 | - * @return void |
|
451 | - */ |
|
452 | - private function reinitializeFieldsValue() |
|
453 | - { |
|
454 | - foreach ($this->vars as $fieldName => $fieldProperties) { |
|
455 | - if ($fieldProperties['dataType'] == self::FILTER_DATA_NUMERIC) { // Zone numérique |
|
456 | - $fieldProperties['data'] = 0; |
|
457 | - } else { |
|
458 | - $fieldProperties['data'] = ''; |
|
459 | - } |
|
460 | - $this->vars[$fieldName] = $fieldProperties; |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Ajoute les critères par défaut au critère général |
|
466 | - * |
|
467 | - * @return void |
|
468 | - */ |
|
469 | - private function addDefaultCriterias() |
|
470 | - { |
|
471 | - if (is_array($this->defaultCriterias) && count($this->defaultCriterias) > 0) { |
|
472 | - foreach ($this->defaultCriterias as $criteria) { |
|
473 | - $this->criteria->add($criteria); |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - return $this; |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Indique s'il y a des champs de tri |
|
482 | - * |
|
483 | - * @return boolean |
|
484 | - */ |
|
485 | - private function areThereSortFields() |
|
486 | - { |
|
487 | - $return = false; |
|
488 | - if (is_array($this->sortFields) && count($this->sortFields) > 0) { |
|
489 | - $return = true; |
|
490 | - } |
|
491 | - |
|
492 | - return $return; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Indique si le nom du champ passé en paramètre fait partie de la liste des champs "triables" |
|
497 | - * |
|
498 | - * @param string $fieldName |
|
499 | - * @return boolean |
|
500 | - */ |
|
501 | - private function isInSortFieldsList($fieldName) |
|
502 | - { |
|
503 | - return array_key_exists($fieldName, $this->sortFields); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Indique si le sens de tri passé en paramètre fait partie de la liste autorisée |
|
508 | - * |
|
509 | - * @param string $order |
|
510 | - * @return boolean |
|
511 | - */ |
|
512 | - private function isInSortOrderList($order) |
|
513 | - { |
|
514 | - return in_array($order, array('asc', 'desc')); |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Récupère, depuis la requête d'entrée, la zone de tri à utiliser et le sens du tri et place l'information en cookie |
|
519 | - * pour que lorsque l'utilisateur se reconnecte, il retrouve ses informations de tri |
|
520 | - * |
|
521 | - * @return void |
|
522 | - */ |
|
523 | - private function setSortFieldsFromRequest() |
|
524 | - { |
|
525 | - if (!$this->areThereSortFields()) { // S'il n'y a pas de champs triables, on laisse tomber |
|
526 | - |
|
527 | - return; |
|
528 | - } |
|
529 | - $sortField = $sortOrder = ''; |
|
530 | - $cookieName = $this->getSessionName(); |
|
531 | - $orderFieldsNames = $this->getSortPlaceHolderNames(); |
|
532 | - if (isset($_REQUEST[$orderFieldsNames[0]]) && isset($_REQUEST[$orderFieldsNames[1]])) { |
|
533 | - $sortField = $_REQUEST[$orderFieldsNames[0]]; |
|
534 | - $sortOrder = $_REQUEST[$orderFieldsNames[1]]; |
|
535 | - } else { |
|
536 | - if (isset($_SESSION[$cookieName . '_sortField'])) { |
|
537 | - $sortField = $_SESSION[$cookieName . '_sortField']; |
|
538 | - } |
|
539 | - if (isset($_SESSION[$cookieName . '_sortOrder'])) { |
|
540 | - $sortOrder = $_SESSION[$cookieName . '_sortOrder']; |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - if ($this->isInSortFieldsList($sortField) && $this->isInSortOrderList($sortOrder)) { |
|
545 | - $this->sortField = $sortField; |
|
546 | - $this->sortOrder = $sortOrder; |
|
547 | - } |
|
548 | - if (trim($sortField) != '' && trim($sortOrder) != '') { |
|
549 | - $_SESSION[$cookieName . '_sortField'] = $sortField; |
|
550 | - $_SESSION[$cookieName . '_sortOrder'] = $sortOrder; |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Réinitialisation des données avant traitement |
|
556 | - * |
|
557 | - * @return void |
|
558 | - */ |
|
559 | - private function setupFilter() |
|
560 | - { |
|
561 | - $this->reinitializeFieldsValue(); |
|
562 | - $this->newFilter = false; |
|
563 | - $this->isInitialized = true; |
|
564 | - $this->criteria = new CriteriaCompo(); |
|
565 | - $this->criteria->add(new Criteria($this->handler->keyName, 0, '<>')); |
|
566 | - $this->addDefaultCriterias(); |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * RAZ des données du filtre si cela a été demandé dans la requête |
|
571 | - * |
|
572 | - * @return void |
|
573 | - */ |
|
574 | - private function isSetCleanFilter() |
|
575 | - { |
|
576 | - if (isset($_REQUEST['cleanFilter'])) { |
|
577 | - $this->setStartInSession(0); |
|
578 | - unset($_SESSION[$this->getSessionName()]); |
|
579 | - } |
|
580 | - } |
|
581 | - |
|
582 | - /** |
|
583 | - * Retourne le critère de filtrage courant |
|
584 | - * |
|
585 | - * @return object |
|
586 | - */ |
|
587 | - public function getCriteria() |
|
588 | - { |
|
589 | - return $this->criteria; |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Méthode à appeler juste après le constructeur pour qu'elle récupère les données saisies |
|
594 | - * |
|
595 | - * @return object L'objet courant pour pouvoir chainer |
|
596 | - */ |
|
597 | - public function filter() |
|
598 | - { |
|
599 | - $this->setupFilter(); // Réinitialisations |
|
600 | - $ts = MyTextSanitizer::getInstance(); |
|
601 | - $this->setSortFieldsFromRequest(); // On récupère la zone de tri éventuellement passée dans la requête |
|
602 | - $this->isSetCleanFilter(); |
|
603 | - |
|
604 | - foreach ($this->vars as $fieldName => $fieldProperties) { |
|
605 | - // On commence par récupérer toutes les valeurs |
|
606 | - $formFieldName = self::PREFIX . $fieldName; // "filter_website_id" par exemple |
|
607 | - $fieldProperties['data'] = null; // Valeur par défaut |
|
608 | - if (isset($_REQUEST[$formFieldName])) { |
|
609 | - if ($fieldProperties['dataType'] == self::FILTER_DATA_NUMERIC) { // Zone numérique |
|
610 | - if ((int)$_REQUEST[$formFieldName] != 0) { |
|
611 | - $fieldProperties['data'] = (int)$_REQUEST[$formFieldName]; |
|
612 | - if (!$fieldProperties['minusOne']) { |
|
613 | - $this->criteria->add(new Criteria($fieldName, $fieldProperties['data'], $fieldProperties['operator'])); |
|
614 | - } else { |
|
615 | - $this->criteria->add(new Criteria($fieldName, $fieldProperties['data'] - 1, $fieldProperties['operator'])); |
|
616 | - } |
|
617 | - $this->newFilter = true; |
|
618 | - } |
|
619 | - } else { // Zone texte |
|
620 | - if (trim($_REQUEST[$formFieldName]) != '') { |
|
621 | - $fieldProperties['data'] = $_REQUEST[$formFieldName]; |
|
622 | - if (!REFERENCES_EXACT_SEARCH) { |
|
623 | - $this->criteria->add(new Criteria($fieldName, '%' . $ts->addSlashes($fieldProperties['data']) . '%', 'LIKE')); |
|
624 | - } else { |
|
625 | - $this->criteria->add(new Criteria($fieldName, $ts->addSlashes($fieldProperties['data']) . '%', 'LIKE')); |
|
626 | - } |
|
627 | - $this->newFilter = true; |
|
628 | - } |
|
629 | - } |
|
630 | - } |
|
631 | - $this->vars[$fieldName] = $fieldProperties; |
|
632 | - } |
|
633 | - |
|
634 | - if ($this->newFilter) { |
|
635 | - $this->setStartInSession(0); |
|
636 | - } |
|
637 | - |
|
638 | - // Récupération des donées de la session s'il n'y a pas eu de filtre(s) |
|
639 | - if (!$this->newFilter && isset($_SESSION[$this->getSessionName()])) { |
|
640 | - $sessionFilterData = unserialize($_SESSION[$this->getSessionName()]); |
|
641 | - if (isset($sessionFilterData['criteria']) && is_object($sessionFilterData['criteria'])) { |
|
642 | - $this->criteria = $sessionFilterData['criteria']; |
|
643 | - unset($sessionFilterData['criteria']); |
|
644 | - } |
|
645 | - foreach ($this->vars as $fieldName => $fieldProperties) { |
|
646 | - if (isset($sessionFilterData[$fieldName])) { |
|
647 | - $fieldProperties['data'] = $sessionFilterData[$fieldName]; |
|
648 | - } |
|
649 | - $this->vars[$fieldName] = $fieldProperties; |
|
650 | - } |
|
651 | - unset($_SESSION[$this->getSessionName()]); |
|
652 | - } |
|
653 | - |
|
654 | - // Mise en place des données dans la session |
|
655 | - $dataForSession = array(); |
|
656 | - $dataForSession['criteria'] = $this->criteria; |
|
657 | - foreach ($this->vars as $fieldName => $fieldProperties) { |
|
658 | - $dataForSession[$fieldName] = $fieldProperties['data']; |
|
659 | - } |
|
660 | - $_SESSION[$this->getSessionName()] = serialize($dataForSession); |
|
661 | - |
|
662 | - return $this; |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Retourne le nombre d'enregistrement en fonction des critères courants |
|
667 | - * |
|
668 | - * @return integer |
|
669 | - */ |
|
670 | - public function getCount() |
|
671 | - { |
|
672 | - if (!$this->isInitialized) { |
|
673 | - $this->filter(); |
|
674 | - } |
|
675 | - |
|
676 | - return $this->handler->getCount($this->criteria); |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * Conserve la valeur de start en session |
|
681 | - * |
|
682 | - * @param integer $start |
|
683 | - * @return void |
|
684 | - */ |
|
685 | - private function setStartInSession($start) |
|
686 | - { |
|
687 | - if ($this->keepStart) { |
|
688 | - $startSessionName = $this->getStartSessionName(); |
|
689 | - $_SESSION[$startSessionName] = (int)$start; |
|
690 | - } |
|
691 | - } |
|
692 | - |
|
693 | - /** |
|
694 | - * Retourne la valeur de ?start=x |
|
695 | - * |
|
696 | - * @return integer |
|
697 | - */ |
|
698 | - private function getStartValue() |
|
699 | - { |
|
700 | - $start = 0; |
|
701 | - if (isset($_REQUEST[$this->startName])) { |
|
702 | - $start = (int)$_REQUEST[$this->startName]; |
|
703 | - } elseif ($this->keepStart) { |
|
704 | - $startSessionName = $this->getStartSessionName(); |
|
705 | - if (isset($_SESSION[$startSessionName])) { |
|
706 | - $start = (int)$_SESSION[$startSessionName]; |
|
707 | - } |
|
708 | - } |
|
709 | - // Mise en session |
|
710 | - $this->setStartInSession($start); |
|
711 | - |
|
712 | - return $start; |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Permet d'ajouter un paramètre supplémentaire au pager |
|
717 | - * |
|
718 | - * @param string $key |
|
719 | - * @param string $value |
|
720 | - * @return object |
|
721 | - */ |
|
722 | - public function addAdditionnalParameterToPager($key, $value = '') |
|
723 | - { |
|
724 | - $this->additionnalPagerParameters[$key] = $value; |
|
725 | - |
|
726 | - return $this; |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * Permet d'ajouter un paramètre supplémentaire au bouton permettant de supprimer le filtre |
|
731 | - * |
|
732 | - * @param string $key |
|
733 | - * @param string $value |
|
734 | - * @return object |
|
735 | - */ |
|
736 | - public function addAdditionnalParameterToClearButton($key, $value = '') |
|
737 | - { |
|
738 | - $this->additionnalClearButtonParameters[$key] = $value; |
|
739 | - |
|
740 | - return $this; |
|
741 | - } |
|
742 | - |
|
743 | - /** |
|
744 | - * Permet d'ajouter des paramètres supplémentaires au pager |
|
745 | - * |
|
746 | - * @param $array |
|
747 | - * @return object |
|
748 | - * @internal param string $key |
|
749 | - * @internal param string $value |
|
750 | - */ |
|
751 | - public function addAditionnalArrayParametersToPager($array) |
|
752 | - { |
|
753 | - if (count($array) > 0) { |
|
754 | - foreach ($array as $key => $value) { |
|
755 | - $this->addAdditionnalParameterToPager($key, $value); |
|
756 | - } |
|
757 | - } |
|
758 | - |
|
759 | - return $this; |
|
760 | - } |
|
761 | - |
|
762 | - /** |
|
763 | - * Retourne le pager à utiliser |
|
764 | - * |
|
765 | - * @return mixed Null s'il n'y a pas lieu d'y avoir un pager, sinon un objet de type {@link XoopsPageNav} |
|
766 | - */ |
|
767 | - public function getPager() |
|
768 | - { |
|
769 | - if (!$this->isInitialized) { |
|
770 | - $this->filter(); |
|
771 | - } |
|
772 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
773 | - $itemsCount = $this->getCount(); |
|
774 | - $queryString = array(); |
|
775 | - if (trim($this->op) != '') { |
|
776 | - $queryString[$this->operationName] = $this->op; |
|
777 | - } |
|
778 | - $pagenav = null; |
|
779 | - |
|
780 | - if ($itemsCount > $this->limit) { |
|
781 | - foreach ($this->vars as $fieldName => $fieldProperties) { |
|
782 | - $formFieldName = self::PREFIX . $fieldName; // "filter_website_id" par exemple |
|
783 | - $queryString[$formFieldName] = $fieldProperties['data']; |
|
784 | - } |
|
785 | - // Ajout des paramètres supplémentaires éventuels |
|
786 | - if (count($this->additionnalPagerParameters) > 0) { |
|
787 | - foreach ($this->additionnalPagerParameters as $key => $value) { |
|
788 | - $queryString[$key] = $value; |
|
789 | - } |
|
790 | - } |
|
791 | - $start = $this->getStartValue(); |
|
792 | - $pagenav = new XoopsPageNav($itemsCount, $this->limit, $start, $this->startName, http_build_query($queryString)); |
|
793 | - } |
|
794 | - |
|
795 | - return $pagenav; |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * Retourne une liste d'objets en fonction des critères définis |
|
800 | - * |
|
801 | - * @return array |
|
802 | - */ |
|
803 | - public function getObjects() |
|
804 | - { |
|
805 | - if (!$this->isInitialized) { |
|
806 | - $this->filter(); |
|
807 | - } |
|
808 | - $start = $this->getStartValue(); |
|
809 | - $limit = $this->limit; |
|
810 | - $criteria = $this->criteria; |
|
811 | - $criteria->setStart($start); |
|
812 | - $criteria->setLimit($limit); |
|
813 | - |
|
814 | - $criteria->setOrder($this->sortOrder); |
|
815 | - if (trim($this->sortField) != '') { |
|
816 | - $criteria->setSort($this->sortField); |
|
817 | - } elseif (trim($this->handler->identifierName) != '') { |
|
818 | - $criteria->setSort($this->handler->identifierName); |
|
819 | - } |
|
820 | - |
|
821 | - return $this->handler->getObjects($this->criteria); |
|
822 | - } |
|
823 | - |
|
824 | - /** |
|
825 | - * Retourne la zone html à utiliser pour créer la zone de filtre (avec sa valeur saisie si c'est le cas) |
|
826 | - * |
|
827 | - * @param string $fieldName La zone de saisie dont on veut récupérer le code html |
|
828 | - * @return string |
|
829 | - */ |
|
830 | - public function getFilterField($fieldName) |
|
831 | - { |
|
832 | - $html = ''; |
|
833 | - if (!$this->isInitialized) { |
|
834 | - $this->filter(); |
|
835 | - } |
|
836 | - if (!isset($this->vars[$fieldName])) { |
|
837 | - trigger_error('Error, unknow field'); |
|
838 | - |
|
839 | - return $html; |
|
840 | - } |
|
841 | - $fieldData = $this->vars[$fieldName]; |
|
842 | - $htmlFieldName = self::PREFIX . $fieldName; |
|
843 | - |
|
844 | - switch ($fieldData['fieldType']) { |
|
845 | - case self::FILTER_FIELD_TEXT: // Zone de texte |
|
846 | - $ts = MyTextSanitizer::getInstance(); |
|
847 | - $html = "<input type='text' name='$htmlFieldName' id='$htmlFieldName' size='" . $fieldData['size'] . "' maxlength='" . $fieldData['maxLength'] . "' value='" . $ts->htmlSpecialChars($fieldData['data']) . "' />"; |
|
848 | - break; |
|
849 | - |
|
850 | - case self::FILTER_FIELD_SELECT; // Select |
|
851 | - $style = ''; |
|
852 | - if (isset($fieldData['style']) && trim($fieldData['style']) != '') { |
|
853 | - $style = $fieldData['style']; |
|
854 | - } |
|
855 | - $html = references_utils::htmlSelect($htmlFieldName, $fieldData['values'], $fieldData['data'], $fieldData['withNull'], $style); |
|
856 | - break; |
|
857 | - |
|
858 | - case self::FILTER_FIELD_SELECT_YES_NO: // Select de type Oui/Non |
|
859 | - $html = references_utils::htmlSelect($htmlFieldName, array(2 => _YES, 1 => NO), $fieldData['data'], $fieldData['withNull']); |
|
860 | - break; |
|
861 | - } |
|
862 | - |
|
863 | - return $html; |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * Assigne toutes les zones de filtre à un template |
|
868 | - * |
|
869 | - * @param object $xoopsTpl |
|
870 | - * @param boolean $asArray Est-ce qu'il faut placer le résultat dans un tableau ou assigner par nom de zone de filtre |
|
871 | - * @param string $arrayName Le nom du tableau à utiliser |
|
872 | - * @return void |
|
873 | - */ |
|
874 | - public function assignFilterFieldsToTemplate(&$xoopsTpl, $asArray = true, $arrayName = 'filterFields') |
|
875 | - { |
|
876 | - $fields = array_keys($this->vars); |
|
877 | - foreach ($fields as $field) { |
|
878 | - if (!$asArray) { |
|
879 | - $xoopsTpl->assign($field, $this->getFilterField($field)); |
|
880 | - } else { |
|
881 | - $xoopsTpl->append($arrayName, $this->getFilterField($field)); |
|
882 | - } |
|
883 | - } |
|
884 | - } |
|
885 | - |
|
886 | - /** |
|
887 | - * Retourne le bouton utilisé pour supprimer le filtre en cours |
|
888 | - * |
|
889 | - * @return string |
|
890 | - */ |
|
891 | - public function getClearFilterbutton() |
|
892 | - { |
|
893 | - $queryString = array(); |
|
894 | - $queryString[$this->operationName] = $this->op; |
|
895 | - if (count($this->additionnalClearButtonParameters) > 0) { |
|
896 | - foreach ($this->additionnalClearButtonParameters as $key => $value) { |
|
897 | - $queryString[$key] = $value; |
|
898 | - } |
|
899 | - } |
|
900 | - $queryString['cleanFilter'] = '1'; |
|
901 | - $baseurl = $this->baseUrl; |
|
902 | - |
|
903 | - return " <a href='$baseurl?" . http_build_query($queryString) . "' title='" . _MD_REFERENCES_CLEAN_FILTER . "'><img align='top' src='../assets/images/clear_left.png' alt='" . _MD_REFERENCES_CLEAN_FILTER . "' /></a>"; |
|
904 | - } |
|
905 | - |
|
906 | - /** |
|
907 | - * Retourne le bouton permettant de lancer le filtrage |
|
908 | - * |
|
909 | - * @param string $description Texte à faire apparaître sur le bouton |
|
910 | - * @param array $additionnals Champs supplémentaires à faire apparaître avec le bouton |
|
911 | - * @return string |
|
912 | - */ |
|
913 | - public function getGoButton($description = _GO, $additionnals = null) |
|
914 | - { |
|
915 | - $html = ''; |
|
916 | - if (trim($this->operationName) != '' && trim($this->op) != '') { |
|
917 | - $html .= "<input type='hidden' name='" . $this->operationName . "' id='" . $this->operationName . "' value='" . $this->op . "' />"; |
|
918 | - } |
|
919 | - if (!is_null($additionnals)) { |
|
920 | - foreach ($additionnals as $key => $value) { |
|
921 | - $html .= "<input type='hidden' name='" . $key . "' id='" . $key . "' value='" . $value . "' />"; |
|
922 | - } |
|
923 | - } |
|
924 | - $html .= "<input type='submit' name='btngo' id='btngo' value='$description' />"; |
|
925 | - |
|
926 | - return $html; |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * Retourne le nom de la zone utilisée pour trier les données |
|
931 | - * |
|
932 | - * @return string |
|
933 | - */ |
|
934 | - public function getSortField() |
|
935 | - { |
|
936 | - return $this->sortField; |
|
937 | - } |
|
938 | - |
|
939 | - /** |
|
940 | - * Retourne le sens de tri utilisé pour trier les données |
|
941 | - * |
|
942 | - * @return string |
|
943 | - */ |
|
944 | - public function getSortOrder() |
|
945 | - { |
|
946 | - return $this->sortOrder(); |
|
947 | - } |
|
948 | - |
|
949 | - /** |
|
950 | - * Retourne la valeur d'un champ |
|
951 | - * |
|
952 | - * @param string $fieldName |
|
953 | - * @return mixed La valeur du champ ou null si on ne trouve pas la zone |
|
954 | - */ |
|
955 | - public function getFieldValue($fieldName) |
|
956 | - { |
|
957 | - $ret = null; |
|
958 | - if (isset($this->vars[$fieldName])) { |
|
959 | - $ret = $this->vars[$fieldName]['data']; |
|
960 | - } |
|
961 | - |
|
962 | - return $ret; |
|
963 | - } |
|
38 | + const FILTER_DATA_TEXT = 1; |
|
39 | + const FILTER_DATA_NUMERIC = 2; |
|
40 | + |
|
41 | + const FILTER_FIELD_TEXT = 1; |
|
42 | + const FILTER_FIELD_SELECT = 2; |
|
43 | + const FILTER_FIELD_SELECT_YES_NO = 3; |
|
44 | + |
|
45 | + /** |
|
46 | + * Préfixe des variables de sélection |
|
47 | + */ |
|
48 | + const PREFIX = 'filter_'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Nom du module (utilisé pour la session) |
|
52 | + */ |
|
53 | + const MODULE_NAME = 'references'; |
|
54 | + |
|
55 | + /** |
|
56 | + * Contient toutes les variables participant au filtre (avec leur type et description) |
|
57 | + * |
|
58 | + * @var array |
|
59 | + */ |
|
60 | + private $vars = array(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Handler des données |
|
64 | + * |
|
65 | + * @var reference |
|
66 | + */ |
|
67 | + private $handler = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * Nom de la zone d'opération (par exemple op=products) |
|
71 | + * |
|
72 | + * @var string |
|
73 | + */ |
|
74 | + private $op = ''; |
|
75 | + |
|
76 | + /** |
|
77 | + * action de l'opération en cour (par exemple op=products) |
|
78 | + * |
|
79 | + * @var string |
|
80 | + */ |
|
81 | + private $operationName = ''; |
|
82 | + |
|
83 | + /** |
|
84 | + * Nombre maximum d'éléments pas page |
|
85 | + * |
|
86 | + * @var intger |
|
87 | + */ |
|
88 | + private $limit = 10; |
|
89 | + |
|
90 | + /** |
|
91 | + * Nom de la variable start |
|
92 | + * |
|
93 | + * @var string |
|
94 | + */ |
|
95 | + private $startName = ''; |
|
96 | + |
|
97 | + /** |
|
98 | + * Critère {@link Criteria} servant à choisir les données |
|
99 | + * |
|
100 | + * @var object |
|
101 | + */ |
|
102 | + private $criteria = null; |
|
103 | + |
|
104 | + /** |
|
105 | + * Indique s'il y a un nouveau critère |
|
106 | + * |
|
107 | + * @var boolean |
|
108 | + */ |
|
109 | + private $newFilter = false; |
|
110 | + |
|
111 | + /** |
|
112 | + * Indique si la méthode filter() a été appelée |
|
113 | + * |
|
114 | + * @var boolean |
|
115 | + */ |
|
116 | + private $isInitialized = false; |
|
117 | + |
|
118 | + /** |
|
119 | + * Zone de tri pour retourner les données (dans getObjects) |
|
120 | + * |
|
121 | + * @var string |
|
122 | + */ |
|
123 | + private $sortField = ''; |
|
124 | + |
|
125 | + /** |
|
126 | + * Sens de tri |
|
127 | + * |
|
128 | + * @var string |
|
129 | + */ |
|
130 | + private $sortOrder = ''; |
|
131 | + |
|
132 | + /** |
|
133 | + * Liste de critères par défaut |
|
134 | + * |
|
135 | + * @var array |
|
136 | + */ |
|
137 | + private $defaultCriterias = array(); |
|
138 | + |
|
139 | + /** |
|
140 | + * L'url complète du script qui appelle |
|
141 | + * |
|
142 | + * @var string |
|
143 | + */ |
|
144 | + private $baseUrl = ''; |
|
145 | + |
|
146 | + /** |
|
147 | + * Indique si on conserve en session la position de départ |
|
148 | + * |
|
149 | + * @var boolean |
|
150 | + */ |
|
151 | + private $keepStart = true; |
|
152 | + |
|
153 | + /** |
|
154 | + * Indique si l'autocomplétion est activée |
|
155 | + * |
|
156 | + * @var boolean |
|
157 | + */ |
|
158 | + private $hasAutoComplete = false; |
|
159 | + |
|
160 | + /** |
|
161 | + * Url du dossier js dans le module |
|
162 | + * |
|
163 | + * @var string |
|
164 | + */ |
|
165 | + private $jsFolderUrl = ''; |
|
166 | + |
|
167 | + /** |
|
168 | + * Paramètres additionnels à ajouter aux paramètres du pager |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + private $additionnalPagerParameters = array(); |
|
172 | + |
|
173 | + /** |
|
174 | + * Paramètres additionnels à ajouter au bouton permettant de supprimer le filtre en cours |
|
175 | + * @var array |
|
176 | + */ |
|
177 | + private $additionnalClearButtonParameters = array(); |
|
178 | + |
|
179 | + /** |
|
180 | + * Tableau des champs triables [clé] = nom du champ dans la base, valeur = libellé |
|
181 | + * @var array |
|
182 | + */ |
|
183 | + private $sortFields = array(); |
|
184 | + |
|
185 | + /** |
|
186 | + * Initialise les paramètres avec des valeurs par défaut |
|
187 | + */ |
|
188 | + private function setDefaultValues() |
|
189 | + { |
|
190 | + $this->handler = null; |
|
191 | + $this->op = ''; |
|
192 | + $this->limit = 10; |
|
193 | + $this->startName = 'start'; |
|
194 | + $this->operationName = 'op'; |
|
195 | + $this->sortField = ''; |
|
196 | + $this->sortOrder = 'asc'; |
|
197 | + $this->baseUrl = ''; |
|
198 | + $this->keepStart = true; |
|
199 | + $this->hasAutoComplete = false; |
|
200 | + $this->jsFolderUrl = ''; |
|
201 | + $this->additionnalPagerParameters = array(); |
|
202 | + $this->additionnalClearButtonParameters = array(); |
|
203 | + $this->sortFields = array(); // Les champs qui peuvent être utilisés pour trier |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Initialisation des données, handler et opération courante dans l'appelant |
|
208 | + * |
|
209 | + * @param mixed $handler Soit une référence au handler de données soit un tableau qui contient toutes les options (auxquel cas les autres paramètres sont inutiles) |
|
210 | + * @param string $operationName |
|
211 | + * @param string $operation Opération courante dans l'appelant |
|
212 | + * @param string $startName Nom du paramètre start |
|
213 | + * @param integer $limit Nombre maximum d'éléments par page |
|
214 | + * @param string $baseUrl L'url complète du script appelant |
|
215 | + * @param string $sortField Zone de tri |
|
216 | + * @param string $sortOrder Sens de tri |
|
217 | + * @param boolean $keepStart Indique si on conserve la position de départ |
|
218 | + * @param string $jsFolderUrl |
|
219 | + * @package string $jsFolderUrl Url du répertoire qui contient les scripts Javascript |
|
220 | + */ |
|
221 | + public function __construct($handler, $operationName = 'op', $operation = '', $startName = 'start', $limit = 10, $baseUrl = '', $sortField = '', $sortOrder = 'asc', $keepStart = true, $jsFolderUrl = '') |
|
222 | + { |
|
223 | + $this->setDefaultValues(); |
|
224 | + if (!is_array($handler)) { |
|
225 | + $this->handler = $handler; |
|
226 | + $this->op = $operation; |
|
227 | + $this->limit = $limit; |
|
228 | + $this->startName = $startName; |
|
229 | + $this->operationName = $operationName; |
|
230 | + $this->sortField = $sortField; |
|
231 | + $this->sortOrder = $sortOrder; |
|
232 | + $this->baseUrl = $baseUrl; |
|
233 | + $this->keepStart = $keepStart; |
|
234 | + $this->jsFolderUrl = $jsFolderUrl; |
|
235 | + } else { |
|
236 | + foreach ($handler as $key => $value) { |
|
237 | + $this->$key = $value; |
|
238 | + } |
|
239 | + } |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Donne à la classe le nom des champs sur lesquels on peut faire le tri |
|
244 | + * |
|
245 | + * @param array $fields [clé] = nom du champ dans la base, valeur = libellé |
|
246 | + * @return object |
|
247 | + */ |
|
248 | + public function setSortFields($fields) |
|
249 | + { |
|
250 | + $this->sortFields = $fields; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Retourne les noms à utiliser pour les champs de tri (sélecteur de champ et ordre de tri) |
|
255 | + * |
|
256 | + * @return array [0] = Nom du sélecteur de champs, [1] = Nom du sélecteur pour le sens du tri |
|
257 | + */ |
|
258 | + private function getSortPlaceHolderNames() |
|
259 | + { |
|
260 | + return array(self::PREFIX . 'sortFields', self::PREFIX . 'sortOrder'); |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * Retourne 2 sélecteurs html pour choisir la zone de tri et le sens du tri |
|
265 | + * |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public function getSortPlaceHolderHtmlCode() |
|
269 | + { |
|
270 | + $sortNames = $this->getSortPlaceHolderNames(); |
|
271 | + $sortFieldsHtml = references_utils::htmlSelect($sortNames[0], $this->sortFields, $this->sortField, false); |
|
272 | + $sortOrderHtml = references_utils::htmlSelect($sortNames[1], array('asc' => _MD_REFERENCES_ASC, 'desc' => _MD_REFERENCES_DESC), $this->sortOrder, false); |
|
273 | + |
|
274 | + return _MD_REFERENCES_SORT_BY . ' ' . $sortFieldsHtml . ' ' . $sortOrderHtml; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Permet de valoriser une option directement tout en chainant |
|
279 | + * |
|
280 | + * @param string $optionName |
|
281 | + * @param mixed $optionValue |
|
282 | + * @return object |
|
283 | + */ |
|
284 | + public function setOption($optionName, $optionValue) |
|
285 | + { |
|
286 | + $this->$optionName = $optionValue; |
|
287 | + |
|
288 | + return $this; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Ajoute un nouveau critère par défaut à la liste des critères par défaut |
|
293 | + * |
|
294 | + * @param Criteria $criteria |
|
295 | + */ |
|
296 | + public function addDefaultCriteria(Criteria $criteria) |
|
297 | + { |
|
298 | + $this->defaultCriterias[] = $criteria; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * Retourne une valeur d'un tableau ou null si l'index n'existe pas |
|
303 | + * |
|
304 | + * @param array $array Le tableau à traiter |
|
305 | + * @param string $index L'index recherché |
|
306 | + * @param mixed $defaultValue La valeur par défaut |
|
307 | + * @return mixed |
|
308 | + */ |
|
309 | + private function getArrayValue($array, $index, $defaultValue = false) |
|
310 | + { |
|
311 | + if ($index === 'autoComplete' && isset($array[$index]) && isset($array[$index]) == true) { |
|
312 | + $this->hasAutoComplete = true; // On en profite pour vérifier si un champ utilise l'autocomplétion |
|
313 | + } |
|
314 | + |
|
315 | + return isset($array[$index]) ? $array[$index] : $defaultValue; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Permet de faire l'autocomplétion d'un champ |
|
320 | + * |
|
321 | + * @param string $query |
|
322 | + * @param $limit |
|
323 | + * @param string $fieldName |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function autoComplete($query, $limit, $fieldName) |
|
327 | + { |
|
328 | + $return = ''; |
|
329 | + if (!$this->hasAutoComplete) { // Si aucun champ n'est en autocomplétion, c'est pas la peine d'aller plus loin |
|
330 | + |
|
331 | + return $return; |
|
332 | + } |
|
333 | + if (isset($this->vars[$fieldName])) { // On vérifie que le champ demandé est bien en autocomplétion |
|
334 | + if ($this->vars[$fieldName]['autoComplete'] == true) { |
|
335 | + if ($this->vars[$fieldName]['dataType'] == self::FILTER_DATA_TEXT) { |
|
336 | + $criteria = new Criteria($fieldName, $query . '%', 'LIKE'); |
|
337 | + } |
|
338 | + $criteria->setLimit((int)$limit); |
|
339 | + $ret = $this->handler->getObjects($criteria); |
|
340 | + |
|
341 | + if (count($ret) > 0) { |
|
342 | + foreach ($ret as $object) { |
|
343 | + $return .= $object->getVar($fieldName, 'n') . "\n"; |
|
344 | + } |
|
345 | + } |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + return $return; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Retourne le code Javascript à utiliser pour initialiser l'auto complétion (et donc à coller dans le code html) |
|
354 | + * |
|
355 | + * @param boolean $jqueryAlreadyLoaded Indique si jQuery est déjà chargé par l'appelant, auquel cas rien ne sert de le recharger |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function getJavascriptInitCode($jqueryAlreadyLoaded = false) |
|
359 | + { |
|
360 | + $return = ''; |
|
361 | + if (!$this->hasAutoComplete) { |
|
362 | + return $return; |
|
363 | + } |
|
364 | + $return = ''; |
|
365 | + $return .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" title=\"Style sheet\" href=\"" . $this->jsFolderUrl . "autocomplete/jquery.autocomplete.css\" />\n"; |
|
366 | + if (!$jqueryAlreadyLoaded) { |
|
367 | + $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "jquery/jquery.js\"></script>\n"; |
|
368 | + } |
|
369 | + $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "noconflict.js\"></script>\n"; |
|
370 | + $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "autocomplete/jquery.autocomplete.min.js\"></script>\n"; |
|
371 | + $return .= "<script type=\"text/javascript\">\n"; |
|
372 | + $return .= "jQuery(function($) {\n"; |
|
373 | + $return .= "var url='" . $this->baseUrl . "';\n"; // TODO: Supprimer "var" car cela limite sa portée ! |
|
374 | + $return .= "var handlerName='" . $this->handler->className . "';\n"; |
|
375 | + |
|
376 | + foreach ($this->vars as $fieldName => $parameters) { |
|
377 | + if ($parameters['autoComplete'] == true) { |
|
378 | + $field = self::PREFIX . $fieldName; |
|
379 | + $return .= "$('#" . $field . "').autocomplete(url, {\n"; |
|
380 | + $return .= "extraParams: {\n"; |
|
381 | + $return .= " field: '" . $fieldName . "',\n"; |
|
382 | + $return .= " op: 'autocomplete',\n"; |
|
383 | + $return .= " handler: handlerName\n"; |
|
384 | + $return .= "}\n"; |
|
385 | + $return .= "});\n"; |
|
386 | + } |
|
387 | + } |
|
388 | + $return .= "});\n"; |
|
389 | + $return .= "</script>\n"; |
|
390 | + |
|
391 | + return $return; |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Initialisation des données du filtre |
|
396 | + * Permet d'indiquer quelles sont les zones sur lesquelles on effectue des filtres ainsi que leur type |
|
397 | + * |
|
398 | + * @param string $fieldName Le nom du champs dans la table |
|
399 | + * @param array $parameters Les paramètres de la zone sous la forme d'un tableau : |
|
400 | + * [dataType] Entier représentant le type de donnée (numérique ou chaine) |
|
401 | + * [fieldType] Le type de zone de saisie (zone de texte, liste déroulante, liste déroulante Oui/Non) |
|
402 | + * [values] La ou les valeurs de la zone de saisie (utilisé dans le cas d'un select) |
|
403 | + * [size] Largeur d'affichage pour les textbox |
|
404 | + * [maxLength] Largeur maximale pour les textbox |
|
405 | + * [withNull] Dans le cas des listes déroulantes, indique s'il faut une valeur nulle |
|
406 | + * [minusOne] Indique s'il faut retrancher 1 à la valeur saisie récupérée (cas classique des listes Oui/Non avec une valeur nulle) |
|
407 | + * [style] Dans le cas des liste déroulante, le style à appliquer à la liste |
|
408 | + * [data] A ne pas renseigner, contient la valeur saisie par l'utilisateur |
|
409 | + * [operator] Opérateur de comparaison pour le Criteria |
|
410 | + * [autoComplete] Indique si on active l'auto complétion sur le champs |
|
411 | + * @return object L'objet courant pour pouvoir chainer |
|
412 | + */ |
|
413 | + public function initFilter($fieldName, $parameters) |
|
414 | + { |
|
415 | + // Tableau des valeurs attendues avec leur valeur par défaut |
|
416 | + $indexNames = array('dataType' => self::FILTER_DATA_TEXT, 'fieldType' => self::FILTER_FIELD_TEXT, 'values' => null, 'withNull' => false, 'size' => 5, 'maxLength' => 255, 'minusOne' => false, 'data' => null, 'style' => '', 'operator' => '=', 'autoComplete' => false); |
|
417 | + $data = array(); |
|
418 | + foreach ($indexNames as $indexName => $defaultValue) { |
|
419 | + $data[$indexName] = $this->getArrayValue($parameters, $indexName, $defaultValue); |
|
420 | + } |
|
421 | + $this->vars[$fieldName] = $data; |
|
422 | + |
|
423 | + return $this; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Retourne le nom du tableau à utiliser pour la session |
|
428 | + * @note : Le nom de la session est composé de : nom du module_nom du handler, par exemple references_references_articles |
|
429 | + * |
|
430 | + * @return string |
|
431 | + */ |
|
432 | + private function getSessionName() |
|
433 | + { |
|
434 | + return self::MODULE_NAME . '_' . $this->handler->table; |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Retourne le nom de la clé à utiliser pour la conservation du start en session |
|
439 | + * |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + private function getStartSessionName() |
|
443 | + { |
|
444 | + return $this->getSessionName() . '_start'; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Réinitialisation des données avant traitement |
|
449 | + * |
|
450 | + * @return void |
|
451 | + */ |
|
452 | + private function reinitializeFieldsValue() |
|
453 | + { |
|
454 | + foreach ($this->vars as $fieldName => $fieldProperties) { |
|
455 | + if ($fieldProperties['dataType'] == self::FILTER_DATA_NUMERIC) { // Zone numérique |
|
456 | + $fieldProperties['data'] = 0; |
|
457 | + } else { |
|
458 | + $fieldProperties['data'] = ''; |
|
459 | + } |
|
460 | + $this->vars[$fieldName] = $fieldProperties; |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Ajoute les critères par défaut au critère général |
|
466 | + * |
|
467 | + * @return void |
|
468 | + */ |
|
469 | + private function addDefaultCriterias() |
|
470 | + { |
|
471 | + if (is_array($this->defaultCriterias) && count($this->defaultCriterias) > 0) { |
|
472 | + foreach ($this->defaultCriterias as $criteria) { |
|
473 | + $this->criteria->add($criteria); |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + return $this; |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Indique s'il y a des champs de tri |
|
482 | + * |
|
483 | + * @return boolean |
|
484 | + */ |
|
485 | + private function areThereSortFields() |
|
486 | + { |
|
487 | + $return = false; |
|
488 | + if (is_array($this->sortFields) && count($this->sortFields) > 0) { |
|
489 | + $return = true; |
|
490 | + } |
|
491 | + |
|
492 | + return $return; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Indique si le nom du champ passé en paramètre fait partie de la liste des champs "triables" |
|
497 | + * |
|
498 | + * @param string $fieldName |
|
499 | + * @return boolean |
|
500 | + */ |
|
501 | + private function isInSortFieldsList($fieldName) |
|
502 | + { |
|
503 | + return array_key_exists($fieldName, $this->sortFields); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Indique si le sens de tri passé en paramètre fait partie de la liste autorisée |
|
508 | + * |
|
509 | + * @param string $order |
|
510 | + * @return boolean |
|
511 | + */ |
|
512 | + private function isInSortOrderList($order) |
|
513 | + { |
|
514 | + return in_array($order, array('asc', 'desc')); |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Récupère, depuis la requête d'entrée, la zone de tri à utiliser et le sens du tri et place l'information en cookie |
|
519 | + * pour que lorsque l'utilisateur se reconnecte, il retrouve ses informations de tri |
|
520 | + * |
|
521 | + * @return void |
|
522 | + */ |
|
523 | + private function setSortFieldsFromRequest() |
|
524 | + { |
|
525 | + if (!$this->areThereSortFields()) { // S'il n'y a pas de champs triables, on laisse tomber |
|
526 | + |
|
527 | + return; |
|
528 | + } |
|
529 | + $sortField = $sortOrder = ''; |
|
530 | + $cookieName = $this->getSessionName(); |
|
531 | + $orderFieldsNames = $this->getSortPlaceHolderNames(); |
|
532 | + if (isset($_REQUEST[$orderFieldsNames[0]]) && isset($_REQUEST[$orderFieldsNames[1]])) { |
|
533 | + $sortField = $_REQUEST[$orderFieldsNames[0]]; |
|
534 | + $sortOrder = $_REQUEST[$orderFieldsNames[1]]; |
|
535 | + } else { |
|
536 | + if (isset($_SESSION[$cookieName . '_sortField'])) { |
|
537 | + $sortField = $_SESSION[$cookieName . '_sortField']; |
|
538 | + } |
|
539 | + if (isset($_SESSION[$cookieName . '_sortOrder'])) { |
|
540 | + $sortOrder = $_SESSION[$cookieName . '_sortOrder']; |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + if ($this->isInSortFieldsList($sortField) && $this->isInSortOrderList($sortOrder)) { |
|
545 | + $this->sortField = $sortField; |
|
546 | + $this->sortOrder = $sortOrder; |
|
547 | + } |
|
548 | + if (trim($sortField) != '' && trim($sortOrder) != '') { |
|
549 | + $_SESSION[$cookieName . '_sortField'] = $sortField; |
|
550 | + $_SESSION[$cookieName . '_sortOrder'] = $sortOrder; |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Réinitialisation des données avant traitement |
|
556 | + * |
|
557 | + * @return void |
|
558 | + */ |
|
559 | + private function setupFilter() |
|
560 | + { |
|
561 | + $this->reinitializeFieldsValue(); |
|
562 | + $this->newFilter = false; |
|
563 | + $this->isInitialized = true; |
|
564 | + $this->criteria = new CriteriaCompo(); |
|
565 | + $this->criteria->add(new Criteria($this->handler->keyName, 0, '<>')); |
|
566 | + $this->addDefaultCriterias(); |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * RAZ des données du filtre si cela a été demandé dans la requête |
|
571 | + * |
|
572 | + * @return void |
|
573 | + */ |
|
574 | + private function isSetCleanFilter() |
|
575 | + { |
|
576 | + if (isset($_REQUEST['cleanFilter'])) { |
|
577 | + $this->setStartInSession(0); |
|
578 | + unset($_SESSION[$this->getSessionName()]); |
|
579 | + } |
|
580 | + } |
|
581 | + |
|
582 | + /** |
|
583 | + * Retourne le critère de filtrage courant |
|
584 | + * |
|
585 | + * @return object |
|
586 | + */ |
|
587 | + public function getCriteria() |
|
588 | + { |
|
589 | + return $this->criteria; |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Méthode à appeler juste après le constructeur pour qu'elle récupère les données saisies |
|
594 | + * |
|
595 | + * @return object L'objet courant pour pouvoir chainer |
|
596 | + */ |
|
597 | + public function filter() |
|
598 | + { |
|
599 | + $this->setupFilter(); // Réinitialisations |
|
600 | + $ts = MyTextSanitizer::getInstance(); |
|
601 | + $this->setSortFieldsFromRequest(); // On récupère la zone de tri éventuellement passée dans la requête |
|
602 | + $this->isSetCleanFilter(); |
|
603 | + |
|
604 | + foreach ($this->vars as $fieldName => $fieldProperties) { |
|
605 | + // On commence par récupérer toutes les valeurs |
|
606 | + $formFieldName = self::PREFIX . $fieldName; // "filter_website_id" par exemple |
|
607 | + $fieldProperties['data'] = null; // Valeur par défaut |
|
608 | + if (isset($_REQUEST[$formFieldName])) { |
|
609 | + if ($fieldProperties['dataType'] == self::FILTER_DATA_NUMERIC) { // Zone numérique |
|
610 | + if ((int)$_REQUEST[$formFieldName] != 0) { |
|
611 | + $fieldProperties['data'] = (int)$_REQUEST[$formFieldName]; |
|
612 | + if (!$fieldProperties['minusOne']) { |
|
613 | + $this->criteria->add(new Criteria($fieldName, $fieldProperties['data'], $fieldProperties['operator'])); |
|
614 | + } else { |
|
615 | + $this->criteria->add(new Criteria($fieldName, $fieldProperties['data'] - 1, $fieldProperties['operator'])); |
|
616 | + } |
|
617 | + $this->newFilter = true; |
|
618 | + } |
|
619 | + } else { // Zone texte |
|
620 | + if (trim($_REQUEST[$formFieldName]) != '') { |
|
621 | + $fieldProperties['data'] = $_REQUEST[$formFieldName]; |
|
622 | + if (!REFERENCES_EXACT_SEARCH) { |
|
623 | + $this->criteria->add(new Criteria($fieldName, '%' . $ts->addSlashes($fieldProperties['data']) . '%', 'LIKE')); |
|
624 | + } else { |
|
625 | + $this->criteria->add(new Criteria($fieldName, $ts->addSlashes($fieldProperties['data']) . '%', 'LIKE')); |
|
626 | + } |
|
627 | + $this->newFilter = true; |
|
628 | + } |
|
629 | + } |
|
630 | + } |
|
631 | + $this->vars[$fieldName] = $fieldProperties; |
|
632 | + } |
|
633 | + |
|
634 | + if ($this->newFilter) { |
|
635 | + $this->setStartInSession(0); |
|
636 | + } |
|
637 | + |
|
638 | + // Récupération des donées de la session s'il n'y a pas eu de filtre(s) |
|
639 | + if (!$this->newFilter && isset($_SESSION[$this->getSessionName()])) { |
|
640 | + $sessionFilterData = unserialize($_SESSION[$this->getSessionName()]); |
|
641 | + if (isset($sessionFilterData['criteria']) && is_object($sessionFilterData['criteria'])) { |
|
642 | + $this->criteria = $sessionFilterData['criteria']; |
|
643 | + unset($sessionFilterData['criteria']); |
|
644 | + } |
|
645 | + foreach ($this->vars as $fieldName => $fieldProperties) { |
|
646 | + if (isset($sessionFilterData[$fieldName])) { |
|
647 | + $fieldProperties['data'] = $sessionFilterData[$fieldName]; |
|
648 | + } |
|
649 | + $this->vars[$fieldName] = $fieldProperties; |
|
650 | + } |
|
651 | + unset($_SESSION[$this->getSessionName()]); |
|
652 | + } |
|
653 | + |
|
654 | + // Mise en place des données dans la session |
|
655 | + $dataForSession = array(); |
|
656 | + $dataForSession['criteria'] = $this->criteria; |
|
657 | + foreach ($this->vars as $fieldName => $fieldProperties) { |
|
658 | + $dataForSession[$fieldName] = $fieldProperties['data']; |
|
659 | + } |
|
660 | + $_SESSION[$this->getSessionName()] = serialize($dataForSession); |
|
661 | + |
|
662 | + return $this; |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Retourne le nombre d'enregistrement en fonction des critères courants |
|
667 | + * |
|
668 | + * @return integer |
|
669 | + */ |
|
670 | + public function getCount() |
|
671 | + { |
|
672 | + if (!$this->isInitialized) { |
|
673 | + $this->filter(); |
|
674 | + } |
|
675 | + |
|
676 | + return $this->handler->getCount($this->criteria); |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * Conserve la valeur de start en session |
|
681 | + * |
|
682 | + * @param integer $start |
|
683 | + * @return void |
|
684 | + */ |
|
685 | + private function setStartInSession($start) |
|
686 | + { |
|
687 | + if ($this->keepStart) { |
|
688 | + $startSessionName = $this->getStartSessionName(); |
|
689 | + $_SESSION[$startSessionName] = (int)$start; |
|
690 | + } |
|
691 | + } |
|
692 | + |
|
693 | + /** |
|
694 | + * Retourne la valeur de ?start=x |
|
695 | + * |
|
696 | + * @return integer |
|
697 | + */ |
|
698 | + private function getStartValue() |
|
699 | + { |
|
700 | + $start = 0; |
|
701 | + if (isset($_REQUEST[$this->startName])) { |
|
702 | + $start = (int)$_REQUEST[$this->startName]; |
|
703 | + } elseif ($this->keepStart) { |
|
704 | + $startSessionName = $this->getStartSessionName(); |
|
705 | + if (isset($_SESSION[$startSessionName])) { |
|
706 | + $start = (int)$_SESSION[$startSessionName]; |
|
707 | + } |
|
708 | + } |
|
709 | + // Mise en session |
|
710 | + $this->setStartInSession($start); |
|
711 | + |
|
712 | + return $start; |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Permet d'ajouter un paramètre supplémentaire au pager |
|
717 | + * |
|
718 | + * @param string $key |
|
719 | + * @param string $value |
|
720 | + * @return object |
|
721 | + */ |
|
722 | + public function addAdditionnalParameterToPager($key, $value = '') |
|
723 | + { |
|
724 | + $this->additionnalPagerParameters[$key] = $value; |
|
725 | + |
|
726 | + return $this; |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Permet d'ajouter un paramètre supplémentaire au bouton permettant de supprimer le filtre |
|
731 | + * |
|
732 | + * @param string $key |
|
733 | + * @param string $value |
|
734 | + * @return object |
|
735 | + */ |
|
736 | + public function addAdditionnalParameterToClearButton($key, $value = '') |
|
737 | + { |
|
738 | + $this->additionnalClearButtonParameters[$key] = $value; |
|
739 | + |
|
740 | + return $this; |
|
741 | + } |
|
742 | + |
|
743 | + /** |
|
744 | + * Permet d'ajouter des paramètres supplémentaires au pager |
|
745 | + * |
|
746 | + * @param $array |
|
747 | + * @return object |
|
748 | + * @internal param string $key |
|
749 | + * @internal param string $value |
|
750 | + */ |
|
751 | + public function addAditionnalArrayParametersToPager($array) |
|
752 | + { |
|
753 | + if (count($array) > 0) { |
|
754 | + foreach ($array as $key => $value) { |
|
755 | + $this->addAdditionnalParameterToPager($key, $value); |
|
756 | + } |
|
757 | + } |
|
758 | + |
|
759 | + return $this; |
|
760 | + } |
|
761 | + |
|
762 | + /** |
|
763 | + * Retourne le pager à utiliser |
|
764 | + * |
|
765 | + * @return mixed Null s'il n'y a pas lieu d'y avoir un pager, sinon un objet de type {@link XoopsPageNav} |
|
766 | + */ |
|
767 | + public function getPager() |
|
768 | + { |
|
769 | + if (!$this->isInitialized) { |
|
770 | + $this->filter(); |
|
771 | + } |
|
772 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
773 | + $itemsCount = $this->getCount(); |
|
774 | + $queryString = array(); |
|
775 | + if (trim($this->op) != '') { |
|
776 | + $queryString[$this->operationName] = $this->op; |
|
777 | + } |
|
778 | + $pagenav = null; |
|
779 | + |
|
780 | + if ($itemsCount > $this->limit) { |
|
781 | + foreach ($this->vars as $fieldName => $fieldProperties) { |
|
782 | + $formFieldName = self::PREFIX . $fieldName; // "filter_website_id" par exemple |
|
783 | + $queryString[$formFieldName] = $fieldProperties['data']; |
|
784 | + } |
|
785 | + // Ajout des paramètres supplémentaires éventuels |
|
786 | + if (count($this->additionnalPagerParameters) > 0) { |
|
787 | + foreach ($this->additionnalPagerParameters as $key => $value) { |
|
788 | + $queryString[$key] = $value; |
|
789 | + } |
|
790 | + } |
|
791 | + $start = $this->getStartValue(); |
|
792 | + $pagenav = new XoopsPageNav($itemsCount, $this->limit, $start, $this->startName, http_build_query($queryString)); |
|
793 | + } |
|
794 | + |
|
795 | + return $pagenav; |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * Retourne une liste d'objets en fonction des critères définis |
|
800 | + * |
|
801 | + * @return array |
|
802 | + */ |
|
803 | + public function getObjects() |
|
804 | + { |
|
805 | + if (!$this->isInitialized) { |
|
806 | + $this->filter(); |
|
807 | + } |
|
808 | + $start = $this->getStartValue(); |
|
809 | + $limit = $this->limit; |
|
810 | + $criteria = $this->criteria; |
|
811 | + $criteria->setStart($start); |
|
812 | + $criteria->setLimit($limit); |
|
813 | + |
|
814 | + $criteria->setOrder($this->sortOrder); |
|
815 | + if (trim($this->sortField) != '') { |
|
816 | + $criteria->setSort($this->sortField); |
|
817 | + } elseif (trim($this->handler->identifierName) != '') { |
|
818 | + $criteria->setSort($this->handler->identifierName); |
|
819 | + } |
|
820 | + |
|
821 | + return $this->handler->getObjects($this->criteria); |
|
822 | + } |
|
823 | + |
|
824 | + /** |
|
825 | + * Retourne la zone html à utiliser pour créer la zone de filtre (avec sa valeur saisie si c'est le cas) |
|
826 | + * |
|
827 | + * @param string $fieldName La zone de saisie dont on veut récupérer le code html |
|
828 | + * @return string |
|
829 | + */ |
|
830 | + public function getFilterField($fieldName) |
|
831 | + { |
|
832 | + $html = ''; |
|
833 | + if (!$this->isInitialized) { |
|
834 | + $this->filter(); |
|
835 | + } |
|
836 | + if (!isset($this->vars[$fieldName])) { |
|
837 | + trigger_error('Error, unknow field'); |
|
838 | + |
|
839 | + return $html; |
|
840 | + } |
|
841 | + $fieldData = $this->vars[$fieldName]; |
|
842 | + $htmlFieldName = self::PREFIX . $fieldName; |
|
843 | + |
|
844 | + switch ($fieldData['fieldType']) { |
|
845 | + case self::FILTER_FIELD_TEXT: // Zone de texte |
|
846 | + $ts = MyTextSanitizer::getInstance(); |
|
847 | + $html = "<input type='text' name='$htmlFieldName' id='$htmlFieldName' size='" . $fieldData['size'] . "' maxlength='" . $fieldData['maxLength'] . "' value='" . $ts->htmlSpecialChars($fieldData['data']) . "' />"; |
|
848 | + break; |
|
849 | + |
|
850 | + case self::FILTER_FIELD_SELECT; // Select |
|
851 | + $style = ''; |
|
852 | + if (isset($fieldData['style']) && trim($fieldData['style']) != '') { |
|
853 | + $style = $fieldData['style']; |
|
854 | + } |
|
855 | + $html = references_utils::htmlSelect($htmlFieldName, $fieldData['values'], $fieldData['data'], $fieldData['withNull'], $style); |
|
856 | + break; |
|
857 | + |
|
858 | + case self::FILTER_FIELD_SELECT_YES_NO: // Select de type Oui/Non |
|
859 | + $html = references_utils::htmlSelect($htmlFieldName, array(2 => _YES, 1 => NO), $fieldData['data'], $fieldData['withNull']); |
|
860 | + break; |
|
861 | + } |
|
862 | + |
|
863 | + return $html; |
|
864 | + } |
|
865 | + |
|
866 | + /** |
|
867 | + * Assigne toutes les zones de filtre à un template |
|
868 | + * |
|
869 | + * @param object $xoopsTpl |
|
870 | + * @param boolean $asArray Est-ce qu'il faut placer le résultat dans un tableau ou assigner par nom de zone de filtre |
|
871 | + * @param string $arrayName Le nom du tableau à utiliser |
|
872 | + * @return void |
|
873 | + */ |
|
874 | + public function assignFilterFieldsToTemplate(&$xoopsTpl, $asArray = true, $arrayName = 'filterFields') |
|
875 | + { |
|
876 | + $fields = array_keys($this->vars); |
|
877 | + foreach ($fields as $field) { |
|
878 | + if (!$asArray) { |
|
879 | + $xoopsTpl->assign($field, $this->getFilterField($field)); |
|
880 | + } else { |
|
881 | + $xoopsTpl->append($arrayName, $this->getFilterField($field)); |
|
882 | + } |
|
883 | + } |
|
884 | + } |
|
885 | + |
|
886 | + /** |
|
887 | + * Retourne le bouton utilisé pour supprimer le filtre en cours |
|
888 | + * |
|
889 | + * @return string |
|
890 | + */ |
|
891 | + public function getClearFilterbutton() |
|
892 | + { |
|
893 | + $queryString = array(); |
|
894 | + $queryString[$this->operationName] = $this->op; |
|
895 | + if (count($this->additionnalClearButtonParameters) > 0) { |
|
896 | + foreach ($this->additionnalClearButtonParameters as $key => $value) { |
|
897 | + $queryString[$key] = $value; |
|
898 | + } |
|
899 | + } |
|
900 | + $queryString['cleanFilter'] = '1'; |
|
901 | + $baseurl = $this->baseUrl; |
|
902 | + |
|
903 | + return " <a href='$baseurl?" . http_build_query($queryString) . "' title='" . _MD_REFERENCES_CLEAN_FILTER . "'><img align='top' src='../assets/images/clear_left.png' alt='" . _MD_REFERENCES_CLEAN_FILTER . "' /></a>"; |
|
904 | + } |
|
905 | + |
|
906 | + /** |
|
907 | + * Retourne le bouton permettant de lancer le filtrage |
|
908 | + * |
|
909 | + * @param string $description Texte à faire apparaître sur le bouton |
|
910 | + * @param array $additionnals Champs supplémentaires à faire apparaître avec le bouton |
|
911 | + * @return string |
|
912 | + */ |
|
913 | + public function getGoButton($description = _GO, $additionnals = null) |
|
914 | + { |
|
915 | + $html = ''; |
|
916 | + if (trim($this->operationName) != '' && trim($this->op) != '') { |
|
917 | + $html .= "<input type='hidden' name='" . $this->operationName . "' id='" . $this->operationName . "' value='" . $this->op . "' />"; |
|
918 | + } |
|
919 | + if (!is_null($additionnals)) { |
|
920 | + foreach ($additionnals as $key => $value) { |
|
921 | + $html .= "<input type='hidden' name='" . $key . "' id='" . $key . "' value='" . $value . "' />"; |
|
922 | + } |
|
923 | + } |
|
924 | + $html .= "<input type='submit' name='btngo' id='btngo' value='$description' />"; |
|
925 | + |
|
926 | + return $html; |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * Retourne le nom de la zone utilisée pour trier les données |
|
931 | + * |
|
932 | + * @return string |
|
933 | + */ |
|
934 | + public function getSortField() |
|
935 | + { |
|
936 | + return $this->sortField; |
|
937 | + } |
|
938 | + |
|
939 | + /** |
|
940 | + * Retourne le sens de tri utilisé pour trier les données |
|
941 | + * |
|
942 | + * @return string |
|
943 | + */ |
|
944 | + public function getSortOrder() |
|
945 | + { |
|
946 | + return $this->sortOrder(); |
|
947 | + } |
|
948 | + |
|
949 | + /** |
|
950 | + * Retourne la valeur d'un champ |
|
951 | + * |
|
952 | + * @param string $fieldName |
|
953 | + * @return mixed La valeur du champ ou null si on ne trouve pas la zone |
|
954 | + */ |
|
955 | + public function getFieldValue($fieldName) |
|
956 | + { |
|
957 | + $ret = null; |
|
958 | + if (isset($this->vars[$fieldName])) { |
|
959 | + $ret = $this->vars[$fieldName]['data']; |
|
960 | + } |
|
961 | + |
|
962 | + return $ret; |
|
963 | + } |
|
964 | 964 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $this->jsFolderUrl = ''; |
201 | 201 | $this->additionnalPagerParameters = array(); |
202 | 202 | $this->additionnalClearButtonParameters = array(); |
203 | - $this->sortFields = array(); // Les champs qui peuvent être utilisés pour trier |
|
203 | + $this->sortFields = array(); // Les champs qui peuvent être utilisés pour trier |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | private function getSortPlaceHolderNames() |
259 | 259 | { |
260 | - return array(self::PREFIX . 'sortFields', self::PREFIX . 'sortOrder'); |
|
260 | + return array(self::PREFIX.'sortFields', self::PREFIX.'sortOrder'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $sortFieldsHtml = references_utils::htmlSelect($sortNames[0], $this->sortFields, $this->sortField, false); |
272 | 272 | $sortOrderHtml = references_utils::htmlSelect($sortNames[1], array('asc' => _MD_REFERENCES_ASC, 'desc' => _MD_REFERENCES_DESC), $this->sortOrder, false); |
273 | 273 | |
274 | - return _MD_REFERENCES_SORT_BY . ' ' . $sortFieldsHtml . ' ' . $sortOrderHtml; |
|
274 | + return _MD_REFERENCES_SORT_BY.' '.$sortFieldsHtml.' '.$sortOrderHtml; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | private function getArrayValue($array, $index, $defaultValue = false) |
310 | 310 | { |
311 | 311 | if ($index === 'autoComplete' && isset($array[$index]) && isset($array[$index]) == true) { |
312 | - $this->hasAutoComplete = true; // On en profite pour vérifier si un champ utilise l'autocomplétion |
|
312 | + $this->hasAutoComplete = true; // On en profite pour vérifier si un champ utilise l'autocomplétion |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | return isset($array[$index]) ? $array[$index] : $defaultValue; |
@@ -333,14 +333,14 @@ discard block |
||
333 | 333 | if (isset($this->vars[$fieldName])) { // On vérifie que le champ demandé est bien en autocomplétion |
334 | 334 | if ($this->vars[$fieldName]['autoComplete'] == true) { |
335 | 335 | if ($this->vars[$fieldName]['dataType'] == self::FILTER_DATA_TEXT) { |
336 | - $criteria = new Criteria($fieldName, $query . '%', 'LIKE'); |
|
336 | + $criteria = new Criteria($fieldName, $query.'%', 'LIKE'); |
|
337 | 337 | } |
338 | - $criteria->setLimit((int)$limit); |
|
338 | + $criteria->setLimit((int) $limit); |
|
339 | 339 | $ret = $this->handler->getObjects($criteria); |
340 | 340 | |
341 | 341 | if (count($ret) > 0) { |
342 | 342 | foreach ($ret as $object) { |
343 | - $return .= $object->getVar($fieldName, 'n') . "\n"; |
|
343 | + $return .= $object->getVar($fieldName, 'n')."\n"; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | } |
@@ -362,23 +362,23 @@ discard block |
||
362 | 362 | return $return; |
363 | 363 | } |
364 | 364 | $return = ''; |
365 | - $return .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" title=\"Style sheet\" href=\"" . $this->jsFolderUrl . "autocomplete/jquery.autocomplete.css\" />\n"; |
|
365 | + $return .= "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" title=\"Style sheet\" href=\"".$this->jsFolderUrl."autocomplete/jquery.autocomplete.css\" />\n"; |
|
366 | 366 | if (!$jqueryAlreadyLoaded) { |
367 | - $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "jquery/jquery.js\"></script>\n"; |
|
367 | + $return .= "<script type=\"text/javascript\" src=\"".$this->jsFolderUrl."jquery/jquery.js\"></script>\n"; |
|
368 | 368 | } |
369 | - $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "noconflict.js\"></script>\n"; |
|
370 | - $return .= "<script type=\"text/javascript\" src=\"" . $this->jsFolderUrl . "autocomplete/jquery.autocomplete.min.js\"></script>\n"; |
|
369 | + $return .= "<script type=\"text/javascript\" src=\"".$this->jsFolderUrl."noconflict.js\"></script>\n"; |
|
370 | + $return .= "<script type=\"text/javascript\" src=\"".$this->jsFolderUrl."autocomplete/jquery.autocomplete.min.js\"></script>\n"; |
|
371 | 371 | $return .= "<script type=\"text/javascript\">\n"; |
372 | 372 | $return .= "jQuery(function($) {\n"; |
373 | - $return .= "var url='" . $this->baseUrl . "';\n"; // TODO: Supprimer "var" car cela limite sa portée ! |
|
374 | - $return .= "var handlerName='" . $this->handler->className . "';\n"; |
|
373 | + $return .= "var url='".$this->baseUrl."';\n"; // TODO: Supprimer "var" car cela limite sa portée ! |
|
374 | + $return .= "var handlerName='".$this->handler->className."';\n"; |
|
375 | 375 | |
376 | 376 | foreach ($this->vars as $fieldName => $parameters) { |
377 | 377 | if ($parameters['autoComplete'] == true) { |
378 | - $field = self::PREFIX . $fieldName; |
|
379 | - $return .= "$('#" . $field . "').autocomplete(url, {\n"; |
|
378 | + $field = self::PREFIX.$fieldName; |
|
379 | + $return .= "$('#".$field."').autocomplete(url, {\n"; |
|
380 | 380 | $return .= "extraParams: {\n"; |
381 | - $return .= " field: '" . $fieldName . "',\n"; |
|
381 | + $return .= " field: '".$fieldName."',\n"; |
|
382 | 382 | $return .= " op: 'autocomplete',\n"; |
383 | 383 | $return .= " handler: handlerName\n"; |
384 | 384 | $return .= "}\n"; |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | */ |
432 | 432 | private function getSessionName() |
433 | 433 | { |
434 | - return self::MODULE_NAME . '_' . $this->handler->table; |
|
434 | + return self::MODULE_NAME.'_'.$this->handler->table; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | /** |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | */ |
442 | 442 | private function getStartSessionName() |
443 | 443 | { |
444 | - return $this->getSessionName() . '_start'; |
|
444 | + return $this->getSessionName().'_start'; |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -533,11 +533,11 @@ discard block |
||
533 | 533 | $sortField = $_REQUEST[$orderFieldsNames[0]]; |
534 | 534 | $sortOrder = $_REQUEST[$orderFieldsNames[1]]; |
535 | 535 | } else { |
536 | - if (isset($_SESSION[$cookieName . '_sortField'])) { |
|
537 | - $sortField = $_SESSION[$cookieName . '_sortField']; |
|
536 | + if (isset($_SESSION[$cookieName.'_sortField'])) { |
|
537 | + $sortField = $_SESSION[$cookieName.'_sortField']; |
|
538 | 538 | } |
539 | - if (isset($_SESSION[$cookieName . '_sortOrder'])) { |
|
540 | - $sortOrder = $_SESSION[$cookieName . '_sortOrder']; |
|
539 | + if (isset($_SESSION[$cookieName.'_sortOrder'])) { |
|
540 | + $sortOrder = $_SESSION[$cookieName.'_sortOrder']; |
|
541 | 541 | } |
542 | 542 | } |
543 | 543 | |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | $this->sortOrder = $sortOrder; |
547 | 547 | } |
548 | 548 | if (trim($sortField) != '' && trim($sortOrder) != '') { |
549 | - $_SESSION[$cookieName . '_sortField'] = $sortField; |
|
550 | - $_SESSION[$cookieName . '_sortOrder'] = $sortOrder; |
|
549 | + $_SESSION[$cookieName.'_sortField'] = $sortField; |
|
550 | + $_SESSION[$cookieName.'_sortOrder'] = $sortOrder; |
|
551 | 551 | } |
552 | 552 | } |
553 | 553 | |
@@ -596,19 +596,19 @@ discard block |
||
596 | 596 | */ |
597 | 597 | public function filter() |
598 | 598 | { |
599 | - $this->setupFilter(); // Réinitialisations |
|
599 | + $this->setupFilter(); // Réinitialisations |
|
600 | 600 | $ts = MyTextSanitizer::getInstance(); |
601 | - $this->setSortFieldsFromRequest(); // On récupère la zone de tri éventuellement passée dans la requête |
|
601 | + $this->setSortFieldsFromRequest(); // On récupère la zone de tri éventuellement passée dans la requête |
|
602 | 602 | $this->isSetCleanFilter(); |
603 | 603 | |
604 | 604 | foreach ($this->vars as $fieldName => $fieldProperties) { |
605 | 605 | // On commence par récupérer toutes les valeurs |
606 | - $formFieldName = self::PREFIX . $fieldName; // "filter_website_id" par exemple |
|
607 | - $fieldProperties['data'] = null; // Valeur par défaut |
|
606 | + $formFieldName = self::PREFIX.$fieldName; // "filter_website_id" par exemple |
|
607 | + $fieldProperties['data'] = null; // Valeur par défaut |
|
608 | 608 | if (isset($_REQUEST[$formFieldName])) { |
609 | 609 | if ($fieldProperties['dataType'] == self::FILTER_DATA_NUMERIC) { // Zone numérique |
610 | - if ((int)$_REQUEST[$formFieldName] != 0) { |
|
611 | - $fieldProperties['data'] = (int)$_REQUEST[$formFieldName]; |
|
610 | + if ((int) $_REQUEST[$formFieldName] != 0) { |
|
611 | + $fieldProperties['data'] = (int) $_REQUEST[$formFieldName]; |
|
612 | 612 | if (!$fieldProperties['minusOne']) { |
613 | 613 | $this->criteria->add(new Criteria($fieldName, $fieldProperties['data'], $fieldProperties['operator'])); |
614 | 614 | } else { |
@@ -620,9 +620,9 @@ discard block |
||
620 | 620 | if (trim($_REQUEST[$formFieldName]) != '') { |
621 | 621 | $fieldProperties['data'] = $_REQUEST[$formFieldName]; |
622 | 622 | if (!REFERENCES_EXACT_SEARCH) { |
623 | - $this->criteria->add(new Criteria($fieldName, '%' . $ts->addSlashes($fieldProperties['data']) . '%', 'LIKE')); |
|
623 | + $this->criteria->add(new Criteria($fieldName, '%'.$ts->addSlashes($fieldProperties['data']).'%', 'LIKE')); |
|
624 | 624 | } else { |
625 | - $this->criteria->add(new Criteria($fieldName, $ts->addSlashes($fieldProperties['data']) . '%', 'LIKE')); |
|
625 | + $this->criteria->add(new Criteria($fieldName, $ts->addSlashes($fieldProperties['data']).'%', 'LIKE')); |
|
626 | 626 | } |
627 | 627 | $this->newFilter = true; |
628 | 628 | } |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | { |
687 | 687 | if ($this->keepStart) { |
688 | 688 | $startSessionName = $this->getStartSessionName(); |
689 | - $_SESSION[$startSessionName] = (int)$start; |
|
689 | + $_SESSION[$startSessionName] = (int) $start; |
|
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
@@ -699,11 +699,11 @@ discard block |
||
699 | 699 | { |
700 | 700 | $start = 0; |
701 | 701 | if (isset($_REQUEST[$this->startName])) { |
702 | - $start = (int)$_REQUEST[$this->startName]; |
|
702 | + $start = (int) $_REQUEST[$this->startName]; |
|
703 | 703 | } elseif ($this->keepStart) { |
704 | 704 | $startSessionName = $this->getStartSessionName(); |
705 | 705 | if (isset($_SESSION[$startSessionName])) { |
706 | - $start = (int)$_SESSION[$startSessionName]; |
|
706 | + $start = (int) $_SESSION[$startSessionName]; |
|
707 | 707 | } |
708 | 708 | } |
709 | 709 | // Mise en session |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | if (!$this->isInitialized) { |
770 | 770 | $this->filter(); |
771 | 771 | } |
772 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
772 | + require_once XOOPS_ROOT_PATH.'/class/pagenav.php'; |
|
773 | 773 | $itemsCount = $this->getCount(); |
774 | 774 | $queryString = array(); |
775 | 775 | if (trim($this->op) != '') { |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | |
780 | 780 | if ($itemsCount > $this->limit) { |
781 | 781 | foreach ($this->vars as $fieldName => $fieldProperties) { |
782 | - $formFieldName = self::PREFIX . $fieldName; // "filter_website_id" par exemple |
|
782 | + $formFieldName = self::PREFIX.$fieldName; // "filter_website_id" par exemple |
|
783 | 783 | $queryString[$formFieldName] = $fieldProperties['data']; |
784 | 784 | } |
785 | 785 | // Ajout des paramètres supplémentaires éventuels |
@@ -839,15 +839,15 @@ discard block |
||
839 | 839 | return $html; |
840 | 840 | } |
841 | 841 | $fieldData = $this->vars[$fieldName]; |
842 | - $htmlFieldName = self::PREFIX . $fieldName; |
|
842 | + $htmlFieldName = self::PREFIX.$fieldName; |
|
843 | 843 | |
844 | 844 | switch ($fieldData['fieldType']) { |
845 | 845 | case self::FILTER_FIELD_TEXT: // Zone de texte |
846 | 846 | $ts = MyTextSanitizer::getInstance(); |
847 | - $html = "<input type='text' name='$htmlFieldName' id='$htmlFieldName' size='" . $fieldData['size'] . "' maxlength='" . $fieldData['maxLength'] . "' value='" . $ts->htmlSpecialChars($fieldData['data']) . "' />"; |
|
847 | + $html = "<input type='text' name='$htmlFieldName' id='$htmlFieldName' size='".$fieldData['size']."' maxlength='".$fieldData['maxLength']."' value='".$ts->htmlSpecialChars($fieldData['data'])."' />"; |
|
848 | 848 | break; |
849 | 849 | |
850 | - case self::FILTER_FIELD_SELECT; // Select |
|
850 | + case self::FILTER_FIELD_SELECT; // Select |
|
851 | 851 | $style = ''; |
852 | 852 | if (isset($fieldData['style']) && trim($fieldData['style']) != '') { |
853 | 853 | $style = $fieldData['style']; |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | $queryString['cleanFilter'] = '1'; |
901 | 901 | $baseurl = $this->baseUrl; |
902 | 902 | |
903 | - return " <a href='$baseurl?" . http_build_query($queryString) . "' title='" . _MD_REFERENCES_CLEAN_FILTER . "'><img align='top' src='../assets/images/clear_left.png' alt='" . _MD_REFERENCES_CLEAN_FILTER . "' /></a>"; |
|
903 | + return " <a href='$baseurl?".http_build_query($queryString)."' title='"._MD_REFERENCES_CLEAN_FILTER."'><img align='top' src='../assets/images/clear_left.png' alt='"._MD_REFERENCES_CLEAN_FILTER."' /></a>"; |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | /** |
@@ -914,11 +914,11 @@ discard block |
||
914 | 914 | { |
915 | 915 | $html = ''; |
916 | 916 | if (trim($this->operationName) != '' && trim($this->op) != '') { |
917 | - $html .= "<input type='hidden' name='" . $this->operationName . "' id='" . $this->operationName . "' value='" . $this->op . "' />"; |
|
917 | + $html .= "<input type='hidden' name='".$this->operationName."' id='".$this->operationName."' value='".$this->op."' />"; |
|
918 | 918 | } |
919 | 919 | if (!is_null($additionnals)) { |
920 | 920 | foreach ($additionnals as $key => $value) { |
921 | - $html .= "<input type='hidden' name='" . $key . "' id='" . $key . "' value='" . $value . "' />"; |
|
921 | + $html .= "<input type='hidden' name='".$key."' id='".$key."' value='".$value."' />"; |
|
922 | 922 | } |
923 | 923 | } |
924 | 924 | $html .= "<input type='submit' name='btngo' id='btngo' value='$description' />"; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * Retourne l'instance unique de la classe |
97 | 97 | * |
98 | - * @return object |
|
98 | + * @return references_plugins |
|
99 | 99 | */ |
100 | 100 | public static function getInstance() |
101 | 101 | { |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | * Déclenchement d'une action et appel des plugins liés |
178 | 178 | * |
179 | 179 | * @param string $eventToFire L'action déclenchée |
180 | - * @param object|references_parameters $parameters Les paramètres à passer à chaque plugin |
|
181 | - * @return object L'objet lui même pour chaîner |
|
180 | + * @param references_parameters $parameters Les paramètres à passer à chaque plugin |
|
181 | + * @return references_plugins L'objet lui même pour chaîner |
|
182 | 182 | */ |
183 | 183 | public function fireAction($eventToFire, references_parameters $parameters = null) |
184 | 184 | { |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * Déclenchement d'un filtre et appel des plugins liés |
213 | 213 | * |
214 | 214 | * @param string $eventToFire Le filtre appelé |
215 | - * @param object|references_parameters $parameters Les paramètres à passer à chaque plugin |
|
215 | + * @param references_parameters $parameters Les paramètres à passer à chaque plugin |
|
216 | 216 | * @return object Le contenu de l'objet passé en paramètre |
217 | 217 | */ |
218 | 218 | public function fireFilter($eventToFire, references_parameters $parameters) |
@@ -25,266 +25,266 @@ |
||
25 | 25 | */ |
26 | 26 | class references_plugins |
27 | 27 | { |
28 | - /** |
|
29 | - * Dictionnaire des évènements |
|
30 | - */ |
|
31 | - const EVENT_ON_REFERENCE_CREATE = 'onReferenceCreate'; |
|
32 | - const EVENT_ON_CATEGORY_CREATE = 'onCategoryCreate'; |
|
28 | + /** |
|
29 | + * Dictionnaire des évènements |
|
30 | + */ |
|
31 | + const EVENT_ON_REFERENCE_CREATE = 'onReferenceCreate'; |
|
32 | + const EVENT_ON_CATEGORY_CREATE = 'onCategoryCreate'; |
|
33 | 33 | |
34 | - // Pour limiter les dépendances |
|
35 | - const MODULE_DIRNAME = REFERENCES_DIRNAME; |
|
34 | + // Pour limiter les dépendances |
|
35 | + const MODULE_DIRNAME = REFERENCES_DIRNAME; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Types d'évènements |
|
39 | - */ |
|
40 | - const PLUGIN_ACTION = 0; |
|
41 | - const PLUGIN_FILTER = 1; |
|
37 | + /** |
|
38 | + * Types d'évènements |
|
39 | + */ |
|
40 | + const PLUGIN_ACTION = 0; |
|
41 | + const PLUGIN_FILTER = 1; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Nom du script Php inclut qui contient l'inscription des plugins |
|
45 | - */ |
|
46 | - const PLUGIN_SCRIPT_NAME = 'plugins.php'; |
|
43 | + /** |
|
44 | + * Nom du script Php inclut qui contient l'inscription des plugins |
|
45 | + */ |
|
46 | + const PLUGIN_SCRIPT_NAME = 'plugins.php'; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Dans le fichier Php qui contient l'inscription des plugins, méthode à appeler pour récupérer la liste des plugins |
|
50 | - */ |
|
51 | - const PLUGIN_DESCRIBE_METHOD = 'registerEvents'; |
|
48 | + /** |
|
49 | + * Dans le fichier Php qui contient l'inscription des plugins, méthode à appeler pour récupérer la liste des plugins |
|
50 | + */ |
|
51 | + const PLUGIN_DESCRIBE_METHOD = 'registerEvents'; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Nom de la variable de session qui contient la liste des plugins détachés |
|
55 | - */ |
|
56 | - const PLUGIN_UNPLUG_SESSION_NAME = 'references_plugins'; |
|
53 | + /** |
|
54 | + * Nom de la variable de session qui contient la liste des plugins détachés |
|
55 | + */ |
|
56 | + const PLUGIN_UNPLUG_SESSION_NAME = 'references_plugins'; |
|
57 | 57 | |
58 | - /** |
|
59 | - * Priorités des plugins |
|
60 | - * @var constant |
|
61 | - */ |
|
62 | - const EVENT_PRIORITY_1 = 1; // Priorité la plus haute |
|
63 | - const EVENT_PRIORITY_2 = 2; |
|
64 | - const EVENT_PRIORITY_3 = 3; |
|
65 | - const EVENT_PRIORITY_4 = 4; |
|
66 | - const EVENT_PRIORITY_5 = 5; // Priorité la plus basse |
|
58 | + /** |
|
59 | + * Priorités des plugins |
|
60 | + * @var constant |
|
61 | + */ |
|
62 | + const EVENT_PRIORITY_1 = 1; // Priorité la plus haute |
|
63 | + const EVENT_PRIORITY_2 = 2; |
|
64 | + const EVENT_PRIORITY_3 = 3; |
|
65 | + const EVENT_PRIORITY_4 = 4; |
|
66 | + const EVENT_PRIORITY_5 = 5; // Priorité la plus basse |
|
67 | 67 | |
68 | - /** |
|
69 | - * Utilisé pour construire le nom de la classe |
|
70 | - */ |
|
71 | - private $pluginsTypeLabel = array(self::PLUGIN_ACTION => 'Action', self::PLUGIN_FILTER => 'Filter'); |
|
68 | + /** |
|
69 | + * Utilisé pour construire le nom de la classe |
|
70 | + */ |
|
71 | + private $pluginsTypeLabel = array(self::PLUGIN_ACTION => 'Action', self::PLUGIN_FILTER => 'Filter'); |
|
72 | 72 | |
73 | - /** |
|
74 | - * Nom des classes qu'il faut étendre en tant que plugin |
|
75 | - */ |
|
76 | - private $pluginsClassName = array(self::PLUGIN_ACTION => 'references_action', self::PLUGIN_FILTER => 'references_filter'); |
|
73 | + /** |
|
74 | + * Nom des classes qu'il faut étendre en tant que plugin |
|
75 | + */ |
|
76 | + private $pluginsClassName = array(self::PLUGIN_ACTION => 'references_action', self::PLUGIN_FILTER => 'references_filter'); |
|
77 | 77 | |
78 | - /** |
|
79 | - * Nom de chacun des dossiers en fonction du type de plugin |
|
80 | - */ |
|
81 | - private $pluginsTypesFolder = array(self::PLUGIN_ACTION => 'actions', self::PLUGIN_FILTER => 'filters'); |
|
78 | + /** |
|
79 | + * Nom de chacun des dossiers en fonction du type de plugin |
|
80 | + */ |
|
81 | + private $pluginsTypesFolder = array(self::PLUGIN_ACTION => 'actions', self::PLUGIN_FILTER => 'filters'); |
|
82 | 82 | |
83 | - /** |
|
84 | - * Contient l'unique instance de l'objet |
|
85 | - * @var object |
|
86 | - */ |
|
87 | - private static $instance = false; |
|
83 | + /** |
|
84 | + * Contient l'unique instance de l'objet |
|
85 | + * @var object |
|
86 | + */ |
|
87 | + private static $instance = false; |
|
88 | 88 | |
89 | - /** |
|
90 | - * Liste des évènements |
|
91 | - * @var array |
|
92 | - */ |
|
93 | - private static $events = array(); |
|
89 | + /** |
|
90 | + * Liste des évènements |
|
91 | + * @var array |
|
92 | + */ |
|
93 | + private static $events = array(); |
|
94 | 94 | |
95 | - /** |
|
96 | - * Retourne l'instance unique de la classe |
|
97 | - * |
|
98 | - * @return object |
|
99 | - */ |
|
100 | - public static function getInstance() |
|
101 | - { |
|
102 | - static $instance; |
|
103 | - if (null === $instance) { |
|
104 | - $instance = new static(); |
|
105 | - } |
|
95 | + /** |
|
96 | + * Retourne l'instance unique de la classe |
|
97 | + * |
|
98 | + * @return object |
|
99 | + */ |
|
100 | + public static function getInstance() |
|
101 | + { |
|
102 | + static $instance; |
|
103 | + if (null === $instance) { |
|
104 | + $instance = new static(); |
|
105 | + } |
|
106 | 106 | |
107 | - return $instance; |
|
108 | - } |
|
107 | + return $instance; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Chargement des 2 types de plugins |
|
112 | - * |
|
113 | - */ |
|
114 | - private function __construct() |
|
115 | - { |
|
116 | - $this->events = array(); |
|
117 | - $this->loadPlugins(); |
|
118 | - } |
|
110 | + /** |
|
111 | + * Chargement des 2 types de plugins |
|
112 | + * |
|
113 | + */ |
|
114 | + private function __construct() |
|
115 | + { |
|
116 | + $this->events = array(); |
|
117 | + $this->loadPlugins(); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Chargement des plugins (actions et filtres) |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function loadPlugins() |
|
125 | - { |
|
126 | - $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[self::PLUGIN_ACTION], self::PLUGIN_ACTION); |
|
127 | - $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[self::PLUGIN_FILTER], self::PLUGIN_FILTER); |
|
128 | - } |
|
120 | + /** |
|
121 | + * Chargement des plugins (actions et filtres) |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function loadPlugins() |
|
125 | + { |
|
126 | + $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[self::PLUGIN_ACTION], self::PLUGIN_ACTION); |
|
127 | + $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[self::PLUGIN_FILTER], self::PLUGIN_FILTER); |
|
128 | + } |
|
129 | 129 | |
130 | - /** |
|
131 | - * Vérifie que le fichier Php passé en paramètre contient bien une classe de filtre ou d'action et si c'est le cas, le charge dans la liste des plugins |
|
132 | - * @param string $fullPathName Chemin complet vers le fichier (répertoire + nom) |
|
133 | - * @param integer $type Type de plugin recherché (action ou filtre) |
|
134 | - * @param string $pluginFolder Le nom du répertoire dans lequel se trouve le fichier (le "dernier nom") |
|
135 | - * @return void |
|
136 | - */ |
|
137 | - private function loadClass($fullPathName, $type, $pluginFolder) |
|
138 | - { |
|
139 | - require_once $fullPathName; |
|
140 | - // Du style referencesRegionalizationFilter |
|
141 | - $className = self::MODULE_DIRNAME . ucfirst(strtolower($pluginFolder)) . $this->pluginsTypeLabel[$type]; |
|
142 | - if (class_exists($className) && get_parent_class($className) == $this->pluginsClassName[$type]) { |
|
143 | - // TODO: Vérifier que l'évènement n'est pas déjà en mémoire |
|
144 | - $events = call_user_func(array($className, self::PLUGIN_DESCRIBE_METHOD)); |
|
145 | - foreach ($events as $event) { |
|
146 | - $eventName = $event[0]; |
|
147 | - $eventPriority = $event[1]; |
|
148 | - $fileToInclude = REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[$type] . DIRECTORY_SEPARATOR . $pluginFolder . DIRECTORY_SEPARATOR . $event[2]; |
|
149 | - $classToCall = $event[3]; |
|
150 | - $methodToCall = $event[4]; |
|
151 | - $this->events[$type][$eventName][$eventPriority][] = array('fullPathName' => $fileToInclude, 'className' => $classToCall, 'method' => $methodToCall); |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
130 | + /** |
|
131 | + * Vérifie que le fichier Php passé en paramètre contient bien une classe de filtre ou d'action et si c'est le cas, le charge dans la liste des plugins |
|
132 | + * @param string $fullPathName Chemin complet vers le fichier (répertoire + nom) |
|
133 | + * @param integer $type Type de plugin recherché (action ou filtre) |
|
134 | + * @param string $pluginFolder Le nom du répertoire dans lequel se trouve le fichier (le "dernier nom") |
|
135 | + * @return void |
|
136 | + */ |
|
137 | + private function loadClass($fullPathName, $type, $pluginFolder) |
|
138 | + { |
|
139 | + require_once $fullPathName; |
|
140 | + // Du style referencesRegionalizationFilter |
|
141 | + $className = self::MODULE_DIRNAME . ucfirst(strtolower($pluginFolder)) . $this->pluginsTypeLabel[$type]; |
|
142 | + if (class_exists($className) && get_parent_class($className) == $this->pluginsClassName[$type]) { |
|
143 | + // TODO: Vérifier que l'évènement n'est pas déjà en mémoire |
|
144 | + $events = call_user_func(array($className, self::PLUGIN_DESCRIBE_METHOD)); |
|
145 | + foreach ($events as $event) { |
|
146 | + $eventName = $event[0]; |
|
147 | + $eventPriority = $event[1]; |
|
148 | + $fileToInclude = REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[$type] . DIRECTORY_SEPARATOR . $pluginFolder . DIRECTORY_SEPARATOR . $event[2]; |
|
149 | + $classToCall = $event[3]; |
|
150 | + $methodToCall = $event[4]; |
|
151 | + $this->events[$type][$eventName][$eventPriority][] = array('fullPathName' => $fileToInclude, 'className' => $classToCall, 'method' => $methodToCall); |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Part à la recherche d'un type de plugin dans les répertoires |
|
158 | - * |
|
159 | - * @param string $path La racine |
|
160 | - * @param integer $type Le type de plugin recherché (action ou filtre) |
|
161 | - * @return void |
|
162 | - */ |
|
163 | - private function loadPluginsFiles($path, $type) |
|
164 | - { |
|
165 | - $objects = new DirectoryIterator($path); |
|
166 | - foreach ($objects as $object) { |
|
167 | - if ($object->isDir() && !$object->isDot()) { |
|
168 | - $file = $path . DIRECTORY_SEPARATOR . $object->current() . DIRECTORY_SEPARATOR . self::PLUGIN_SCRIPT_NAME; |
|
169 | - if (file_exists($file)) { |
|
170 | - $this->loadClass($file, $type, $object->current()); |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - } |
|
156 | + /** |
|
157 | + * Part à la recherche d'un type de plugin dans les répertoires |
|
158 | + * |
|
159 | + * @param string $path La racine |
|
160 | + * @param integer $type Le type de plugin recherché (action ou filtre) |
|
161 | + * @return void |
|
162 | + */ |
|
163 | + private function loadPluginsFiles($path, $type) |
|
164 | + { |
|
165 | + $objects = new DirectoryIterator($path); |
|
166 | + foreach ($objects as $object) { |
|
167 | + if ($object->isDir() && !$object->isDot()) { |
|
168 | + $file = $path . DIRECTORY_SEPARATOR . $object->current() . DIRECTORY_SEPARATOR . self::PLUGIN_SCRIPT_NAME; |
|
169 | + if (file_exists($file)) { |
|
170 | + $this->loadClass($file, $type, $object->current()); |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Déclenchement d'une action et appel des plugins liés |
|
178 | - * |
|
179 | - * @param string $eventToFire L'action déclenchée |
|
180 | - * @param object|references_parameters $parameters Les paramètres à passer à chaque plugin |
|
181 | - * @return object L'objet lui même pour chaîner |
|
182 | - */ |
|
183 | - public function fireAction($eventToFire, references_parameters $parameters = null) |
|
184 | - { |
|
185 | - if (!isset($this->events[self::PLUGIN_ACTION][$eventToFire])) { |
|
186 | - trigger_error(sprintf(_MD_REFERENCES_PLUGINS_ERROR_1, $eventToFire)); |
|
176 | + /** |
|
177 | + * Déclenchement d'une action et appel des plugins liés |
|
178 | + * |
|
179 | + * @param string $eventToFire L'action déclenchée |
|
180 | + * @param object|references_parameters $parameters Les paramètres à passer à chaque plugin |
|
181 | + * @return object L'objet lui même pour chaîner |
|
182 | + */ |
|
183 | + public function fireAction($eventToFire, references_parameters $parameters = null) |
|
184 | + { |
|
185 | + if (!isset($this->events[self::PLUGIN_ACTION][$eventToFire])) { |
|
186 | + trigger_error(sprintf(_MD_REFERENCES_PLUGINS_ERROR_1, $eventToFire)); |
|
187 | 187 | |
188 | - return $this; |
|
189 | - } |
|
190 | - ksort($this->events[self::PLUGIN_ACTION][$eventToFire]); // Tri par priorit� |
|
191 | - foreach ($this->events[self::PLUGIN_ACTION][$eventToFire] as $priority => $events) { |
|
192 | - foreach ($events as $event) { |
|
193 | - if ($this->isUnplug(self::PLUGIN_ACTION, $eventToFire, $event['fullPathName'], $event['className'], $event['method'])) { |
|
194 | - continue; |
|
195 | - } |
|
196 | - require_once $event['fullPathName']; |
|
197 | - if (!class_exists($event['className'])) { |
|
198 | - $class = new $event['className']; |
|
199 | - } |
|
200 | - if (!method_exists($event['className'], $event['method'])) { |
|
201 | - continue; |
|
202 | - } |
|
203 | - call_user_func(array($event['className'], $event['method']), $parameters); |
|
204 | - unset($class); |
|
205 | - } |
|
206 | - } |
|
188 | + return $this; |
|
189 | + } |
|
190 | + ksort($this->events[self::PLUGIN_ACTION][$eventToFire]); // Tri par priorit� |
|
191 | + foreach ($this->events[self::PLUGIN_ACTION][$eventToFire] as $priority => $events) { |
|
192 | + foreach ($events as $event) { |
|
193 | + if ($this->isUnplug(self::PLUGIN_ACTION, $eventToFire, $event['fullPathName'], $event['className'], $event['method'])) { |
|
194 | + continue; |
|
195 | + } |
|
196 | + require_once $event['fullPathName']; |
|
197 | + if (!class_exists($event['className'])) { |
|
198 | + $class = new $event['className']; |
|
199 | + } |
|
200 | + if (!method_exists($event['className'], $event['method'])) { |
|
201 | + continue; |
|
202 | + } |
|
203 | + call_user_func(array($event['className'], $event['method']), $parameters); |
|
204 | + unset($class); |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - return $this; |
|
209 | - } |
|
208 | + return $this; |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * Déclenchement d'un filtre et appel des plugins liés |
|
213 | - * |
|
214 | - * @param string $eventToFire Le filtre appelé |
|
215 | - * @param object|references_parameters $parameters Les paramètres à passer à chaque plugin |
|
216 | - * @return object Le contenu de l'objet passé en paramètre |
|
217 | - */ |
|
218 | - public function fireFilter($eventToFire, references_parameters $parameters) |
|
219 | - { |
|
220 | - if (!isset($this->events[self::PLUGIN_FILTER][$eventToFire])) { |
|
221 | - trigger_error(sprintf(_MD_REFERENCES_PLUGINS_ERROR_1, $eventToFire)); |
|
211 | + /** |
|
212 | + * Déclenchement d'un filtre et appel des plugins liés |
|
213 | + * |
|
214 | + * @param string $eventToFire Le filtre appelé |
|
215 | + * @param object|references_parameters $parameters Les paramètres à passer à chaque plugin |
|
216 | + * @return object Le contenu de l'objet passé en paramètre |
|
217 | + */ |
|
218 | + public function fireFilter($eventToFire, references_parameters $parameters) |
|
219 | + { |
|
220 | + if (!isset($this->events[self::PLUGIN_FILTER][$eventToFire])) { |
|
221 | + trigger_error(sprintf(_MD_REFERENCES_PLUGINS_ERROR_1, $eventToFire)); |
|
222 | 222 | |
223 | - return $this; |
|
224 | - } |
|
225 | - ksort($this->events[self::PLUGIN_FILTER][$eventToFire]); // Tri par priorité |
|
226 | - foreach ($this->events[self::PLUGIN_FILTER][$eventToFire] as $priority => $events) { |
|
227 | - foreach ($events as $event) { |
|
228 | - if ($this->isUnplug(self::PLUGIN_FILTER, $eventToFire, $event['fullPathName'], $event['className'], $event['method'])) { |
|
229 | - continue; |
|
230 | - } |
|
231 | - require_once $event['fullPathName']; |
|
232 | - if (!method_exists($event['className'], $event['method'])) { |
|
233 | - continue; |
|
234 | - } |
|
235 | - //if (!class_exists($event['className'])) { |
|
236 | - $class = new $event['className']; |
|
237 | - //} |
|
238 | - $class->$event['method']($parameters); |
|
239 | - //call_user_func(array($event['className'], $event['method']), $parameters); |
|
240 | - unset($class); |
|
241 | - } |
|
242 | - } |
|
223 | + return $this; |
|
224 | + } |
|
225 | + ksort($this->events[self::PLUGIN_FILTER][$eventToFire]); // Tri par priorité |
|
226 | + foreach ($this->events[self::PLUGIN_FILTER][$eventToFire] as $priority => $events) { |
|
227 | + foreach ($events as $event) { |
|
228 | + if ($this->isUnplug(self::PLUGIN_FILTER, $eventToFire, $event['fullPathName'], $event['className'], $event['method'])) { |
|
229 | + continue; |
|
230 | + } |
|
231 | + require_once $event['fullPathName']; |
|
232 | + if (!method_exists($event['className'], $event['method'])) { |
|
233 | + continue; |
|
234 | + } |
|
235 | + //if (!class_exists($event['className'])) { |
|
236 | + $class = new $event['className']; |
|
237 | + //} |
|
238 | + $class->$event['method']($parameters); |
|
239 | + //call_user_func(array($event['className'], $event['method']), $parameters); |
|
240 | + unset($class); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | - if (!is_null($parameters)) { |
|
245 | - return $parameters; |
|
246 | - } |
|
247 | - } |
|
244 | + if (!is_null($parameters)) { |
|
245 | + return $parameters; |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Indique si un plugin s'est détaché d'un évènement particulier |
|
251 | - * |
|
252 | - * @param integer $eventType |
|
253 | - * @param string $eventToFire |
|
254 | - * @param string $fullPathName |
|
255 | - * @param string $className |
|
256 | - * @param string $method |
|
257 | - * @return boolean |
|
258 | - */ |
|
259 | - public function isUnplug($eventType, $eventToFire, $fullPathName, $className, $method) |
|
260 | - { |
|
261 | - $unplug = array(); |
|
262 | - if (isset($_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME])) { |
|
263 | - $unplug = $_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME]; |
|
264 | - } else { |
|
265 | - return false; |
|
266 | - } |
|
249 | + /** |
|
250 | + * Indique si un plugin s'est détaché d'un évènement particulier |
|
251 | + * |
|
252 | + * @param integer $eventType |
|
253 | + * @param string $eventToFire |
|
254 | + * @param string $fullPathName |
|
255 | + * @param string $className |
|
256 | + * @param string $method |
|
257 | + * @return boolean |
|
258 | + */ |
|
259 | + public function isUnplug($eventType, $eventToFire, $fullPathName, $className, $method) |
|
260 | + { |
|
261 | + $unplug = array(); |
|
262 | + if (isset($_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME])) { |
|
263 | + $unplug = $_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME]; |
|
264 | + } else { |
|
265 | + return false; |
|
266 | + } |
|
267 | 267 | |
268 | - return isset($unplug[$eventType][$eventToFire][$fullPathName][$className][$method]); |
|
269 | - } |
|
268 | + return isset($unplug[$eventType][$eventToFire][$fullPathName][$className][$method]); |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * Permet à un plugin de se détacher d'un évènement |
|
273 | - * |
|
274 | - * @param integer $eventType |
|
275 | - * @param string $eventToFire |
|
276 | - * @param string $fullPathName |
|
277 | - * @param string $className |
|
278 | - * @param string $method |
|
279 | - * @return void |
|
280 | - */ |
|
281 | - public function unplugFromEvent($eventType, $eventToFire, $fullPathName, $className, $method) |
|
282 | - { |
|
283 | - $unplug = array(); |
|
284 | - if (isset($_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME])) { |
|
285 | - $unplug = $_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME]; |
|
286 | - } |
|
287 | - $unplug[$eventType][$eventToFire][$fullPathName][$className][$method] = true; |
|
288 | - $_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME] = $unplug; |
|
289 | - } |
|
271 | + /** |
|
272 | + * Permet à un plugin de se détacher d'un évènement |
|
273 | + * |
|
274 | + * @param integer $eventType |
|
275 | + * @param string $eventToFire |
|
276 | + * @param string $fullPathName |
|
277 | + * @param string $className |
|
278 | + * @param string $method |
|
279 | + * @return void |
|
280 | + */ |
|
281 | + public function unplugFromEvent($eventType, $eventToFire, $fullPathName, $className, $method) |
|
282 | + { |
|
283 | + $unplug = array(); |
|
284 | + if (isset($_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME])) { |
|
285 | + $unplug = $_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME]; |
|
286 | + } |
|
287 | + $unplug[$eventType][$eventToFire][$fullPathName][$className][$method] = true; |
|
288 | + $_SESSION[self::PLUGIN_UNPLUG_SESSION_NAME] = $unplug; |
|
289 | + } |
|
290 | 290 | } |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | * Priorités des plugins |
60 | 60 | * @var constant |
61 | 61 | */ |
62 | - const EVENT_PRIORITY_1 = 1; // Priorité la plus haute |
|
62 | + const EVENT_PRIORITY_1 = 1; // Priorité la plus haute |
|
63 | 63 | const EVENT_PRIORITY_2 = 2; |
64 | 64 | const EVENT_PRIORITY_3 = 3; |
65 | 65 | const EVENT_PRIORITY_4 = 4; |
66 | - const EVENT_PRIORITY_5 = 5; // Priorité la plus basse |
|
66 | + const EVENT_PRIORITY_5 = 5; // Priorité la plus basse |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * Utilisé pour construire le nom de la classe |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function loadPlugins() |
125 | 125 | { |
126 | - $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[self::PLUGIN_ACTION], self::PLUGIN_ACTION); |
|
127 | - $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[self::PLUGIN_FILTER], self::PLUGIN_FILTER); |
|
126 | + $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH.$this->pluginsTypesFolder[self::PLUGIN_ACTION], self::PLUGIN_ACTION); |
|
127 | + $this->loadPluginsFiles(REFERENCES_PLUGINS_PATH.$this->pluginsTypesFolder[self::PLUGIN_FILTER], self::PLUGIN_FILTER); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -138,14 +138,14 @@ discard block |
||
138 | 138 | { |
139 | 139 | require_once $fullPathName; |
140 | 140 | // Du style referencesRegionalizationFilter |
141 | - $className = self::MODULE_DIRNAME . ucfirst(strtolower($pluginFolder)) . $this->pluginsTypeLabel[$type]; |
|
141 | + $className = self::MODULE_DIRNAME.ucfirst(strtolower($pluginFolder)).$this->pluginsTypeLabel[$type]; |
|
142 | 142 | if (class_exists($className) && get_parent_class($className) == $this->pluginsClassName[$type]) { |
143 | 143 | // TODO: Vérifier que l'évènement n'est pas déjà en mémoire |
144 | 144 | $events = call_user_func(array($className, self::PLUGIN_DESCRIBE_METHOD)); |
145 | 145 | foreach ($events as $event) { |
146 | 146 | $eventName = $event[0]; |
147 | 147 | $eventPriority = $event[1]; |
148 | - $fileToInclude = REFERENCES_PLUGINS_PATH . $this->pluginsTypesFolder[$type] . DIRECTORY_SEPARATOR . $pluginFolder . DIRECTORY_SEPARATOR . $event[2]; |
|
148 | + $fileToInclude = REFERENCES_PLUGINS_PATH.$this->pluginsTypesFolder[$type].DIRECTORY_SEPARATOR.$pluginFolder.DIRECTORY_SEPARATOR.$event[2]; |
|
149 | 149 | $classToCall = $event[3]; |
150 | 150 | $methodToCall = $event[4]; |
151 | 151 | $this->events[$type][$eventName][$eventPriority][] = array('fullPathName' => $fileToInclude, 'className' => $classToCall, 'method' => $methodToCall); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $objects = new DirectoryIterator($path); |
166 | 166 | foreach ($objects as $object) { |
167 | 167 | if ($object->isDir() && !$object->isDot()) { |
168 | - $file = $path . DIRECTORY_SEPARATOR . $object->current() . DIRECTORY_SEPARATOR . self::PLUGIN_SCRIPT_NAME; |
|
168 | + $file = $path.DIRECTORY_SEPARATOR.$object->current().DIRECTORY_SEPARATOR.self::PLUGIN_SCRIPT_NAME; |
|
169 | 169 | if (file_exists($file)) { |
170 | 170 | $this->loadClass($file, $type, $object->current()); |
171 | 171 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | |
188 | 188 | return $this; |
189 | 189 | } |
190 | - ksort($this->events[self::PLUGIN_ACTION][$eventToFire]); // Tri par priorit� |
|
190 | + ksort($this->events[self::PLUGIN_ACTION][$eventToFire]); // Tri par priorit� |
|
191 | 191 | foreach ($this->events[self::PLUGIN_ACTION][$eventToFire] as $priority => $events) { |
192 | 192 | foreach ($events as $event) { |
193 | 193 | if ($this->isUnplug(self::PLUGIN_ACTION, $eventToFire, $event['fullPathName'], $event['className'], $event['method'])) { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | return $this; |
224 | 224 | } |
225 | - ksort($this->events[self::PLUGIN_FILTER][$eventToFire]); // Tri par priorité |
|
225 | + ksort($this->events[self::PLUGIN_FILTER][$eventToFire]); // Tri par priorité |
|
226 | 226 | foreach ($this->events[self::PLUGIN_FILTER][$eventToFire] as $priority => $events) { |
227 | 227 | foreach ($events as $event) { |
228 | 228 | if ($this->isUnplug(self::PLUGIN_FILTER, $eventToFire, $event['fullPathName'], $event['className'], $event['method'])) { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | /** |
49 | 49 | * Access the only instance of this class |
50 | 50 | * |
51 | - * @return object |
|
51 | + * @return references_utils |
|
52 | 52 | * |
53 | 53 | * @static |
54 | 54 | * @staticvar object |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | /** |
387 | 387 | * Internal function used to get the handler of the current module |
388 | 388 | * |
389 | - * @return object The module |
|
389 | + * @return integer The module |
|
390 | 390 | */ |
391 | 391 | public static function getModule() |
392 | 392 | { |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | /** |
490 | 490 | * V�rifie que l'utilisateur courant fait partie du groupe des administrateurs |
491 | 491 | * |
492 | - * @return booleean Admin or not |
|
492 | + * @return boolean Admin or not |
|
493 | 493 | */ |
494 | 494 | public static function isAdmin() |
495 | 495 | { |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | /** |
551 | 551 | * Conversion d'un dateTime Mysql en date lisible en fran�ais |
552 | 552 | * @param $dateTime |
553 | - * @return bool|string |
|
553 | + * @return string |
|
554 | 554 | */ |
555 | 555 | public static function sqlDateTimeToFrench($dateTime) |
556 | 556 | { |
@@ -943,7 +943,7 @@ discard block |
||
943 | 943 | * @param null $uploadMaxSize |
944 | 944 | * @param null $maxWidth |
945 | 945 | * @param null $maxHeight |
946 | - * @return mixed True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
|
946 | + * @return boolean|string True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
|
947 | 947 | */ |
948 | 948 | public static function uploadFile($indice, $dstpath = XOOPS_UPLOAD_PATH, $mimeTypes = null, $uploadMaxSize = null, $maxWidth = null, $maxHeight = null) |
949 | 949 | { |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | * |
1032 | 1032 | * @param int $duration |
1033 | 1033 | * @param integer $startingDate Date de départ (timestamp) |
1034 | - * @return bool|string |
|
1034 | + * @return string |
|
1035 | 1035 | * @internal param int $durations Durée en jours |
1036 | 1036 | */ |
1037 | 1037 | public static function addDaysToDate($duration = 1, $startingDate = 0) |
@@ -1073,6 +1073,9 @@ discard block |
||
1073 | 1073 | return $breadcrumb; |
1074 | 1074 | } |
1075 | 1075 | |
1076 | + /** |
|
1077 | + * @param string $string |
|
1078 | + */ |
|
1076 | 1079 | public static function close_tags($string) |
1077 | 1080 | { |
1078 | 1081 | // match opened tags |
@@ -1394,7 +1397,7 @@ discard block |
||
1394 | 1397 | * Create the <option> of an html select |
1395 | 1398 | * |
1396 | 1399 | * @param array $array Array of index and labels |
1397 | - * @param mixed $default the default value |
|
1400 | + * @param integer $default the default value |
|
1398 | 1401 | * @param bool $withNull |
1399 | 1402 | * @return string |
1400 | 1403 | */ |
@@ -33,654 +33,654 @@ discard block |
||
33 | 33 | use WideImage\WideImage; |
34 | 34 | |
35 | 35 | if (!defined('XOOPS_ROOT_PATH')) { |
36 | - die('XOOPS root path not defined'); |
|
36 | + die('XOOPS root path not defined'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | class references_utils |
40 | 40 | { |
41 | - // Pour la portabilité de module à module |
|
42 | - const MODULE_NAME = 'references'; |
|
43 | - const MODULE_DIRNAME = REFERENCES_DIRNAME; |
|
44 | - const MODULE_PATH = REFERENCES_PATH; |
|
45 | - const MODULE_URL = REFERENCES_URL; |
|
46 | - const MODULE_JS_URL = REFERENCES_JS_URL; |
|
47 | - |
|
48 | - /** |
|
49 | - * Access the only instance of this class |
|
50 | - * |
|
51 | - * @return object |
|
52 | - * |
|
53 | - * @static |
|
54 | - * @staticvar object |
|
55 | - */ |
|
56 | - public static function &getInstance() |
|
57 | - { |
|
58 | - static $instance; |
|
59 | - if (!isset($instance)) { |
|
60 | - $instance = new references_utils(); |
|
61 | - } |
|
62 | - |
|
63 | - return $instance; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Returns a module's option (with cache) |
|
68 | - * |
|
69 | - * @param string $option module option's name |
|
70 | - * @param boolean $withCache Do we have to use some cache ? |
|
71 | - * @return mixed option's value |
|
72 | - */ |
|
73 | - public static function getModuleOption($option, $withCache = true) |
|
74 | - { |
|
75 | - global $xoopsModuleConfig, $xoopsModule; |
|
76 | - $repmodule = self::MODULE_NAME; |
|
77 | - static $options = array(); |
|
78 | - if (is_array($options) && array_key_exists($option, $options) && $withCache) { |
|
79 | - return $options[$option]; |
|
80 | - } |
|
81 | - |
|
82 | - $retval = false; |
|
83 | - if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) { |
|
84 | - if (isset($xoopsModuleConfig[$option])) { |
|
85 | - $retval = $xoopsModuleConfig[$option]; |
|
86 | - } |
|
87 | - } else { |
|
88 | - $module_handler = xoops_getHandler('module'); |
|
89 | - $module = $module_handler->getByDirname($repmodule); |
|
90 | - $config_handler = xoops_getHandler('config'); |
|
91 | - if ($module) { |
|
92 | - $moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
|
93 | - if (isset($moduleConfig[$option])) { |
|
94 | - $retval = $moduleConfig[$option]; |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - $options[$option] = $retval; |
|
99 | - |
|
100 | - return $retval; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Is Xoops 2.3.x ? |
|
105 | - * |
|
106 | - * @return boolean need to say it ? |
|
107 | - */ |
|
108 | - public static function isX23() |
|
109 | - { |
|
110 | - $x23 = false; |
|
111 | - $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
112 | - if ((int)substr($xv, 2, 1) >= 3) { |
|
113 | - $x23 = true; |
|
114 | - } |
|
115 | - |
|
116 | - return $x23; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Retreive an editor according to the module's option "form_options" |
|
121 | - * |
|
122 | - * @param string $caption Caption to give to the editor |
|
123 | - * @param string $name Editor's name |
|
124 | - * @param string $value Editor's value |
|
125 | - * @param string $width Editor's width |
|
126 | - * @param string $height Editor's height |
|
127 | - * @param string $supplemental |
|
128 | - * @return object The editor to use |
|
129 | - */ |
|
130 | - public static function getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental = '') |
|
131 | - { |
|
132 | - $editor = false; |
|
133 | - $editor_configs = array(); |
|
134 | - $editor_configs['name'] = $name; |
|
135 | - $editor_configs['value'] = $value; |
|
136 | - $editor_configs['rows'] = 35; |
|
137 | - $editor_configs['cols'] = 60; |
|
138 | - $editor_configs['width'] = '100%'; |
|
139 | - $editor_configs['height'] = '400px'; |
|
140 | - |
|
141 | - $editor_option = strtolower(self::getModuleOption('form_options')); |
|
142 | - |
|
143 | - if (self::isX23()) { |
|
144 | - $editor = new XoopsFormEditor($caption, $editor_option, $editor_configs); |
|
145 | - |
|
146 | - return $editor; |
|
147 | - } |
|
148 | - |
|
149 | - // Only for Xoops 2.0.x |
|
150 | - switch ($editor_option) { |
|
151 | - case 'fckeditor': |
|
152 | - if (is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { |
|
153 | - require_once(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'); |
|
154 | - $editor = new XoopsFormFckeditor($caption, $name, $value); |
|
155 | - } |
|
156 | - break; |
|
157 | - |
|
158 | - case 'htmlarea': |
|
159 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
160 | - require_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
161 | - $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
162 | - } |
|
163 | - break; |
|
164 | - |
|
165 | - case 'dhtmltextarea': |
|
166 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); |
|
167 | - break; |
|
168 | - |
|
169 | - case 'textarea': |
|
170 | - $editor = new XoopsFormTextArea($caption, $name, $value); |
|
171 | - break; |
|
172 | - |
|
173 | - case 'tinyeditor': |
|
174 | - case 'tinymce': |
|
175 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
|
176 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
|
177 | - $editor = new XoopsFormTinyeditorTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '400px')); |
|
178 | - } |
|
179 | - break; |
|
180 | - |
|
181 | - case 'koivi': |
|
182 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
183 | - require_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
184 | - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); |
|
185 | - } |
|
186 | - break; |
|
187 | - } |
|
188 | - if (!is_object($editor)) { |
|
189 | - trigger_error('Error, impossible to get the requested text editor', E_USER_ERROR); |
|
190 | - } |
|
191 | - |
|
192 | - return $editor; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Create (in a link) a javascript confirmation's box |
|
197 | - * |
|
198 | - * @param string $message Message to display |
|
199 | - * @param boolean $form Is this a confirmation for a form ? |
|
200 | - * @return string the javascript code to insert in the link (or in the form) |
|
201 | - */ |
|
202 | - public static function javascriptLinkConfirm($message, $form = false) |
|
203 | - { |
|
204 | - if (!$form) { |
|
205 | - return "onclick=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
|
206 | - } else { |
|
207 | - return "onSubmit=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Get current user IP |
|
213 | - * |
|
214 | - * @return string IP address (format Ipv4) |
|
215 | - */ |
|
216 | - public static function IP() |
|
217 | - { |
|
218 | - $proxy_ip = ''; |
|
219 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
220 | - $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
221 | - } elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) { |
|
222 | - $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; |
|
223 | - } elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { |
|
224 | - $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; |
|
225 | - } elseif (!empty($_SERVER['HTTP_FORWARDED'])) { |
|
226 | - $proxy_ip = $_SERVER['HTTP_FORWARDED']; |
|
227 | - } elseif (!empty($_SERVER['HTTP_VIA'])) { |
|
228 | - $proxy_ip = $_SERVER['HTTP_VIA']; |
|
229 | - } elseif (!empty($_SERVER['HTTP_X_COMING_FROM'])) { |
|
230 | - $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; |
|
231 | - } elseif (!empty($_SERVER['HTTP_COMING_FROM'])) { |
|
232 | - $proxy_ip = $_SERVER['HTTP_COMING_FROM']; |
|
233 | - } |
|
234 | - $regs = array(); |
|
235 | - if (!empty($proxy_ip) && $is_ip = ereg('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $proxy_ip, $regs) && count($regs) > 0) { |
|
236 | - $the_IP = $regs[0]; |
|
237 | - } else { |
|
238 | - $the_IP = $_SERVER['REMOTE_ADDR']; |
|
239 | - } |
|
240 | - |
|
241 | - return $the_IP; |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Set the page's title, meta description and meta keywords |
|
246 | - * Datas are supposed to be sanitized |
|
247 | - * |
|
248 | - * @param string $pageTitle Page's Title |
|
249 | - * @param string $metaDescription Page's meta description |
|
250 | - * @param string $metaKeywords Page's meta keywords |
|
251 | - * @return void |
|
252 | - */ |
|
253 | - public static function setMetas($pageTitle = '', $metaDescription = '', $metaKeywords = '') |
|
254 | - { |
|
255 | - global $xoTheme, $xoTheme, $xoopsTpl; |
|
256 | - $xoopsTpl->assign('xoops_pagetitle', $pageTitle); |
|
257 | - if (isset($xoTheme) && is_object($xoTheme)) { |
|
258 | - if (!empty($metaKeywords)) { |
|
259 | - $xoTheme->addMeta('meta', 'keywords', $metaKeywords); |
|
260 | - } |
|
261 | - if (!empty($metaDescription)) { |
|
262 | - $xoTheme->addMeta('meta', 'description', $metaDescription); |
|
263 | - } |
|
264 | - } elseif (isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
|
265 | - if (!empty($metaKeywords)) { |
|
266 | - $xoopsTpl->assign('xoops_meta_keywords', $metaKeywords); |
|
267 | - } |
|
268 | - if (!empty($metaDescription)) { |
|
269 | - $xoopsTpl->assign('xoops_meta_description', $metaDescription); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Send an email from a template to a list of recipients |
|
276 | - * |
|
277 | - * @param $tplName |
|
278 | - * @param array $recipients List of recipients |
|
279 | - * @param string $subject Email's subject |
|
280 | - * @param array $variables Varirables to give to the template |
|
281 | - * @return bool Result of the send |
|
282 | - * @internal param string $tpl_name Template's name |
|
283 | - */ |
|
284 | - public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
|
285 | - { |
|
286 | - global $xoopsConfig; |
|
287 | - require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
|
288 | - if (!is_array($recipients)) { |
|
289 | - if (trim($recipients) == '') { |
|
290 | - return false; |
|
291 | - } |
|
292 | - } else { |
|
293 | - if (count($recipients) == 0) { |
|
294 | - return false; |
|
295 | - } |
|
296 | - } |
|
297 | - if (function_exists('xoops_getMailer')) { |
|
298 | - $xoopsMailer =& xoops_getMailer(); |
|
299 | - } else { |
|
300 | - $xoopsMailer =& getMailer(); |
|
301 | - } |
|
302 | - |
|
303 | - $xoopsMailer->useMail(); |
|
304 | - $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'); |
|
305 | - $xoopsMailer->setTemplate($tplName); |
|
306 | - $xoopsMailer->setToEmails($recipients); |
|
307 | - // TODO: Change ! |
|
308 | - // $xoopsMailer->setFromEmail('[email protected]'); |
|
309 | - //$xoopsMailer->setFromName('MonSite'); |
|
310 | - $xoopsMailer->setSubject($subject); |
|
311 | - foreach ($variables as $key => $value) { |
|
312 | - $xoopsMailer->assign($key, $value); |
|
313 | - } |
|
314 | - $res = $xoopsMailer->send(); |
|
315 | - unset($xoopsMailer); |
|
316 | - $filename = XOOPS_UPLOAD_PATH . '/logmail_' . self::MODULE_NAME . '.php'; |
|
317 | - if (!file_exists($filename)) { |
|
318 | - $fp = @fopen($filename, 'a'); |
|
319 | - if ($fp) { |
|
320 | - fwrite($fp, '<?php exit(); ?>'); |
|
321 | - fclose($fp); |
|
322 | - } |
|
323 | - } |
|
324 | - $fp = @fopen($filename, 'a'); |
|
325 | - |
|
326 | - if ($fp) { |
|
327 | - fwrite($fp, str_repeat('-', 120) . "\n"); |
|
328 | - fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
|
329 | - fwrite($fp, 'Template name : ' . $tplName . "\n"); |
|
330 | - fwrite($fp, 'Email subject : ' . $subject . "\n"); |
|
331 | - if (is_array($recipients)) { |
|
332 | - fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
|
333 | - } else { |
|
334 | - fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
|
335 | - } |
|
336 | - fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
|
337 | - fclose($fp); |
|
338 | - } |
|
339 | - |
|
340 | - return $res; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Remove module's cache |
|
345 | - */ |
|
346 | - public static function updateCache() |
|
347 | - { |
|
348 | - global $xoopsModule; |
|
349 | - $folder = $xoopsModule->getVar('dirname'); |
|
350 | - $tpllist = array(); |
|
351 | - require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
|
352 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
353 | - $tplfile_handler = xoops_getHandler('tplfile'); |
|
354 | - $tpllist = $tplfile_handler->find(null, null, null, $folder); |
|
355 | - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
|
356 | - |
|
357 | - foreach ($tpllist as $onetemplate) { // Remove cache for each page. |
|
358 | - if ($onetemplate->getVar('tpl_type') === 'module') { |
|
359 | - // Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
|
360 | - $files_del = array(); |
|
361 | - $files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*'); |
|
362 | - if (count($files_del) > 0 && is_array($files_del)) { |
|
363 | - foreach ($files_del as $one_file) { |
|
364 | - if (is_file($one_file)) { |
|
365 | - unlink($one_file); |
|
366 | - } |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Redirect user with a message |
|
375 | - * |
|
376 | - * @param string $message message to display |
|
377 | - * @param string $url The place where to go |
|
378 | - * @param integer timeout Time to wait before to redirect |
|
379 | - */ |
|
380 | - public static function redirect($message = '', $url = 'index.php', $time = 2) |
|
381 | - { |
|
382 | - redirect_header($url, $time, $message); |
|
383 | - exit(); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Internal function used to get the handler of the current module |
|
388 | - * |
|
389 | - * @return object The module |
|
390 | - */ |
|
391 | - public static function getModule() |
|
392 | - { |
|
393 | - static $mymodule; |
|
394 | - if (!isset($mymodule)) { |
|
395 | - global $xoopsModule; |
|
396 | - if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == REFERENCES_DIRNAME) { |
|
397 | - $mymodule =& $xoopsModule; |
|
398 | - } else { |
|
399 | - $hModule = xoops_getHandler('module'); |
|
400 | - $mymodule = $hModule->getByDirname(REFERENCES_DIRNAME); |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - return $mymodule; |
|
405 | - } |
|
406 | - |
|
407 | - /** |
|
408 | - * Returns the module's name (as defined by the user in the module manager) with cache |
|
409 | - * @return string Module's name |
|
410 | - */ |
|
411 | - public static function getModuleName() |
|
412 | - { |
|
413 | - static $moduleName; |
|
414 | - if (!isset($moduleName)) { |
|
415 | - $mymodule = self::getModule(); |
|
416 | - $moduleName = $mymodule->getVar('name'); |
|
417 | - } |
|
418 | - |
|
419 | - return $moduleName; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Create a title for the href tags inside html links |
|
424 | - * |
|
425 | - * @param string $title Text to use |
|
426 | - * @return string Formated text |
|
427 | - */ |
|
428 | - public static function makeHrefTitle($title) |
|
429 | - { |
|
430 | - $s = "\"'"; |
|
431 | - $r = ' '; |
|
432 | - |
|
433 | - return strtr($title, $s, $r); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * Retourne la liste des utilisateurs appartenants � un groupe |
|
438 | - * |
|
439 | - * @param int $groupId Searched group |
|
440 | - * @return array Array of XoopsUsers |
|
441 | - */ |
|
442 | - public static function getUsersFromGroup($groupId) |
|
443 | - { |
|
444 | - $users = array(); |
|
445 | - $member_handler = xoops_getHandler('member'); |
|
446 | - $users = $member_handler->getUsersByGroup($groupId, true); |
|
447 | - |
|
448 | - return $users; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Retourne les ID des utilisateurs faisant partie de plusieurs groupes |
|
453 | - * @param array $groups Les ID des groupes dont on recherche les ID utilisateurs |
|
454 | - * @return array Les ID utilisateurs |
|
455 | - */ |
|
456 | - public static function getUsersIdsFromGroups($groups) |
|
457 | - { |
|
458 | - $usersIds = array(); |
|
459 | - $member_handler = xoops_getHandler('member'); |
|
460 | - foreach ($groups as $groupId) { |
|
461 | - $temporaryGroup = array(); |
|
462 | - $temporaryGroup = $member_handler->getUsersByGroup($groupId); |
|
463 | - if (count($temporaryGroup) > 0) { |
|
464 | - $usersIds = array_merge($usersIds, $temporaryGroup); |
|
465 | - } |
|
466 | - } |
|
467 | - |
|
468 | - return array_unique($usersIds); |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * Retourne la liste des emails des utilisateurs membres d'un groupe |
|
473 | - * |
|
474 | - * @param $groupId |
|
475 | - * @return array Emails list |
|
476 | - * @internal param int $group_id Group's number |
|
477 | - */ |
|
478 | - public static function getEmailsFromGroup($groupId) |
|
479 | - { |
|
480 | - $ret = array(); |
|
481 | - $users = self::getUsersFromGroup($groupId); |
|
482 | - foreach ($users as $user) { |
|
483 | - $ret[] = $user->getVar('email'); |
|
484 | - } |
|
485 | - |
|
486 | - return $ret; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * V�rifie que l'utilisateur courant fait partie du groupe des administrateurs |
|
491 | - * |
|
492 | - * @return booleean Admin or not |
|
493 | - */ |
|
494 | - public static function isAdmin() |
|
495 | - { |
|
496 | - global $xoopsUser, $xoopsModule; |
|
497 | - if (is_object($xoopsUser)) { |
|
498 | - if (in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups())) { |
|
499 | - return true; |
|
500 | - } elseif (isset($xoopsModule) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
|
501 | - return true; |
|
502 | - } |
|
503 | - } |
|
504 | - |
|
505 | - return false; |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Returns the current date in the Mysql format |
|
510 | - * |
|
511 | - * @return string Date in the Mysql format |
|
512 | - */ |
|
513 | - public static function getCurrentSQLDate() |
|
514 | - { |
|
515 | - return date('Y-m-d'); // 2007-05-02 |
|
516 | - } |
|
517 | - |
|
518 | - public static function getCurrentSQLDateTime() |
|
519 | - { |
|
520 | - return date('Y-m-d H:i:s'); // 2007-05-02 |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Convert a Mysql date to the human's format |
|
525 | - * |
|
526 | - * @param string $date The date to convert |
|
527 | - * @param string $format |
|
528 | - * @return string The date in a human form |
|
529 | - */ |
|
530 | - public static function SQLDateToHuman($date, $format = 'l') |
|
531 | - { |
|
532 | - if ($date != '0000-00-00' && xoops_trim($date) != '') { |
|
533 | - return formatTimestamp(strtotime($date), $format); |
|
534 | - } else { |
|
535 | - return ''; |
|
536 | - } |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Convert a timestamp to a Mysql date |
|
541 | - * |
|
542 | - * @param integer $timestamp The timestamp to use |
|
543 | - * @return string The date in the Mysql format |
|
544 | - */ |
|
545 | - public static function timestampToMysqlDate($timestamp) |
|
546 | - { |
|
547 | - return date('Y-m-d', (int)$timestamp); |
|
548 | - } |
|
549 | - |
|
550 | - /** |
|
551 | - * Conversion d'un dateTime Mysql en date lisible en fran�ais |
|
552 | - * @param $dateTime |
|
553 | - * @return bool|string |
|
554 | - */ |
|
555 | - public static function sqlDateTimeToFrench($dateTime) |
|
556 | - { |
|
557 | - return date('d/m/Y H:i:s', strtotime($dateTime)); |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * Convert a timestamp to a Mysql datetime form |
|
562 | - * @param integer $timestamp The timestamp to use |
|
563 | - * @return string The date and time in the Mysql format |
|
564 | - */ |
|
565 | - public static function timestampToMysqlDateTime($timestamp) |
|
566 | - { |
|
567 | - return date('Y-m-d H:i:s', $timestamp); |
|
568 | - } |
|
569 | - |
|
570 | - /** |
|
571 | - * This function indicates if the current Xoops version needs to add asterisks to required fields in forms |
|
572 | - * |
|
573 | - * @return boolean Yes = we need to add them, false = no |
|
574 | - */ |
|
575 | - public static function needsAsterisk() |
|
576 | - { |
|
577 | - if (self::isX23()) { |
|
578 | - return false; |
|
579 | - } |
|
580 | - if (strpos(strtolower(XOOPS_VERSION), 'impresscms') !== false) { |
|
581 | - return false; |
|
582 | - } |
|
583 | - if (strpos(strtolower(XOOPS_VERSION), 'legacy') === false) { |
|
584 | - $xv = xoops_trim(str_replace('XOOPS ', '', XOOPS_VERSION)); |
|
585 | - if ((int)substr($xv, 4, 2) >= 17) { |
|
586 | - return false; |
|
587 | - } |
|
588 | - } |
|
589 | - |
|
590 | - return true; |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Mark the mandatory fields of a form with a star |
|
595 | - * |
|
596 | - * @param object $sform The form to modify |
|
597 | - * @return object The modified form |
|
598 | - * @internal param string $caracter The character to use to mark fields |
|
599 | - */ |
|
600 | - public static function &formMarkRequiredFields(&$sform) |
|
601 | - { |
|
602 | - if (self::needsAsterisk()) { |
|
603 | - $required = array(); |
|
604 | - foreach ($sform->getRequired() as $item) { |
|
605 | - $required[] = $item->_name; |
|
606 | - } |
|
607 | - $elements = array(); |
|
608 | - $elements = &$sform->getElements(); |
|
609 | - $cnt = count($elements); |
|
610 | - for ($i = 0; $i < $cnt; ++$i) { |
|
611 | - if (is_object($elements[$i]) && in_array($elements[$i]->_name, $required)) { |
|
612 | - $elements[$i]->_caption .= ' *'; |
|
613 | - } |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - return $sform; |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Create an html heading (from h1 to h6) |
|
622 | - * |
|
623 | - * @param string $title The text to use |
|
624 | - * @param integer $level Level to return |
|
625 | - * @return string The heading |
|
626 | - */ |
|
627 | - public static function htitle($title = '', $level = 1) |
|
628 | - { |
|
629 | - printf('<h%01d>%s</h%01d>', $level, $title, $level); |
|
630 | - } |
|
631 | - |
|
632 | - /** |
|
633 | - * Create a unique upload filename |
|
634 | - * |
|
635 | - * @param string $folder The folder where the file will be saved |
|
636 | - * @param string $fileName Original filename (coming from the user) |
|
637 | - * @param boolean $trimName Do we need to create a short unique name ? |
|
638 | - * @return string The unique filename to use (with its extension) |
|
639 | - */ |
|
640 | - public static function createUploadName($folder, $fileName, $trimName = false) |
|
641 | - { |
|
642 | - $workingfolder = $folder; |
|
643 | - if (substr($workingfolder, strlen($workingfolder) - 1, 1) !== '/') { |
|
644 | - $workingfolder .= '/'; |
|
645 | - } |
|
646 | - $ext = basename($fileName); |
|
647 | - $ext = explode('.', $ext); |
|
648 | - $ext = '.' . $ext[count($ext) - 1]; |
|
649 | - $true = true; |
|
650 | - while ($true) { |
|
651 | - $ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
|
652 | - list($usec, $sec) = explode(' ', microtime()); |
|
653 | - $usec = (integer)($usec * 65536); |
|
654 | - $sec = ((integer)$sec) & 0xFFFF; |
|
655 | - |
|
656 | - if ($trimName) { |
|
657 | - $uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
|
658 | - } else { |
|
659 | - $uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
|
660 | - } |
|
661 | - if (!file_exists($workingfolder . $uid . $ext)) { |
|
662 | - $true = false; |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - return $uid . $ext; |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Replace html entities with their ASCII equivalent |
|
671 | - * |
|
672 | - * @param string $chaine The string undecode |
|
673 | - * @return string The undecoded string |
|
674 | - */ |
|
675 | - public static function unhtml($chaine) |
|
676 | - { |
|
677 | - $search = $replace = array(); |
|
678 | - $chaine = html_entity_decode($chaine); |
|
679 | - |
|
680 | - for ($i = 0; $i <= 255; ++$i) { |
|
681 | - $search[] = '&#' . $i . ';'; |
|
682 | - $replace[] = chr($i); |
|
683 | - } |
|
41 | + // Pour la portabilité de module à module |
|
42 | + const MODULE_NAME = 'references'; |
|
43 | + const MODULE_DIRNAME = REFERENCES_DIRNAME; |
|
44 | + const MODULE_PATH = REFERENCES_PATH; |
|
45 | + const MODULE_URL = REFERENCES_URL; |
|
46 | + const MODULE_JS_URL = REFERENCES_JS_URL; |
|
47 | + |
|
48 | + /** |
|
49 | + * Access the only instance of this class |
|
50 | + * |
|
51 | + * @return object |
|
52 | + * |
|
53 | + * @static |
|
54 | + * @staticvar object |
|
55 | + */ |
|
56 | + public static function &getInstance() |
|
57 | + { |
|
58 | + static $instance; |
|
59 | + if (!isset($instance)) { |
|
60 | + $instance = new references_utils(); |
|
61 | + } |
|
62 | + |
|
63 | + return $instance; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Returns a module's option (with cache) |
|
68 | + * |
|
69 | + * @param string $option module option's name |
|
70 | + * @param boolean $withCache Do we have to use some cache ? |
|
71 | + * @return mixed option's value |
|
72 | + */ |
|
73 | + public static function getModuleOption($option, $withCache = true) |
|
74 | + { |
|
75 | + global $xoopsModuleConfig, $xoopsModule; |
|
76 | + $repmodule = self::MODULE_NAME; |
|
77 | + static $options = array(); |
|
78 | + if (is_array($options) && array_key_exists($option, $options) && $withCache) { |
|
79 | + return $options[$option]; |
|
80 | + } |
|
81 | + |
|
82 | + $retval = false; |
|
83 | + if (isset($xoopsModuleConfig) && (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule && $xoopsModule->getVar('isactive'))) { |
|
84 | + if (isset($xoopsModuleConfig[$option])) { |
|
85 | + $retval = $xoopsModuleConfig[$option]; |
|
86 | + } |
|
87 | + } else { |
|
88 | + $module_handler = xoops_getHandler('module'); |
|
89 | + $module = $module_handler->getByDirname($repmodule); |
|
90 | + $config_handler = xoops_getHandler('config'); |
|
91 | + if ($module) { |
|
92 | + $moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid')); |
|
93 | + if (isset($moduleConfig[$option])) { |
|
94 | + $retval = $moduleConfig[$option]; |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + $options[$option] = $retval; |
|
99 | + |
|
100 | + return $retval; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Is Xoops 2.3.x ? |
|
105 | + * |
|
106 | + * @return boolean need to say it ? |
|
107 | + */ |
|
108 | + public static function isX23() |
|
109 | + { |
|
110 | + $x23 = false; |
|
111 | + $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
|
112 | + if ((int)substr($xv, 2, 1) >= 3) { |
|
113 | + $x23 = true; |
|
114 | + } |
|
115 | + |
|
116 | + return $x23; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Retreive an editor according to the module's option "form_options" |
|
121 | + * |
|
122 | + * @param string $caption Caption to give to the editor |
|
123 | + * @param string $name Editor's name |
|
124 | + * @param string $value Editor's value |
|
125 | + * @param string $width Editor's width |
|
126 | + * @param string $height Editor's height |
|
127 | + * @param string $supplemental |
|
128 | + * @return object The editor to use |
|
129 | + */ |
|
130 | + public static function getWysiwygForm($caption, $name, $value = '', $width = '100%', $height = '400px', $supplemental = '') |
|
131 | + { |
|
132 | + $editor = false; |
|
133 | + $editor_configs = array(); |
|
134 | + $editor_configs['name'] = $name; |
|
135 | + $editor_configs['value'] = $value; |
|
136 | + $editor_configs['rows'] = 35; |
|
137 | + $editor_configs['cols'] = 60; |
|
138 | + $editor_configs['width'] = '100%'; |
|
139 | + $editor_configs['height'] = '400px'; |
|
140 | + |
|
141 | + $editor_option = strtolower(self::getModuleOption('form_options')); |
|
142 | + |
|
143 | + if (self::isX23()) { |
|
144 | + $editor = new XoopsFormEditor($caption, $editor_option, $editor_configs); |
|
145 | + |
|
146 | + return $editor; |
|
147 | + } |
|
148 | + |
|
149 | + // Only for Xoops 2.0.x |
|
150 | + switch ($editor_option) { |
|
151 | + case 'fckeditor': |
|
152 | + if (is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { |
|
153 | + require_once(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'); |
|
154 | + $editor = new XoopsFormFckeditor($caption, $name, $value); |
|
155 | + } |
|
156 | + break; |
|
157 | + |
|
158 | + case 'htmlarea': |
|
159 | + if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
160 | + require_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
161 | + $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
162 | + } |
|
163 | + break; |
|
164 | + |
|
165 | + case 'dhtmltextarea': |
|
166 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); |
|
167 | + break; |
|
168 | + |
|
169 | + case 'textarea': |
|
170 | + $editor = new XoopsFormTextArea($caption, $name, $value); |
|
171 | + break; |
|
172 | + |
|
173 | + case 'tinyeditor': |
|
174 | + case 'tinymce': |
|
175 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
|
176 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
|
177 | + $editor = new XoopsFormTinyeditorTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '400px')); |
|
178 | + } |
|
179 | + break; |
|
180 | + |
|
181 | + case 'koivi': |
|
182 | + if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
183 | + require_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
184 | + $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); |
|
185 | + } |
|
186 | + break; |
|
187 | + } |
|
188 | + if (!is_object($editor)) { |
|
189 | + trigger_error('Error, impossible to get the requested text editor', E_USER_ERROR); |
|
190 | + } |
|
191 | + |
|
192 | + return $editor; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Create (in a link) a javascript confirmation's box |
|
197 | + * |
|
198 | + * @param string $message Message to display |
|
199 | + * @param boolean $form Is this a confirmation for a form ? |
|
200 | + * @return string the javascript code to insert in the link (or in the form) |
|
201 | + */ |
|
202 | + public static function javascriptLinkConfirm($message, $form = false) |
|
203 | + { |
|
204 | + if (!$form) { |
|
205 | + return "onclick=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
|
206 | + } else { |
|
207 | + return "onSubmit=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Get current user IP |
|
213 | + * |
|
214 | + * @return string IP address (format Ipv4) |
|
215 | + */ |
|
216 | + public static function IP() |
|
217 | + { |
|
218 | + $proxy_ip = ''; |
|
219 | + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
220 | + $proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
221 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) { |
|
222 | + $proxy_ip = $_SERVER['HTTP_X_FORWARDED']; |
|
223 | + } elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { |
|
224 | + $proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; |
|
225 | + } elseif (!empty($_SERVER['HTTP_FORWARDED'])) { |
|
226 | + $proxy_ip = $_SERVER['HTTP_FORWARDED']; |
|
227 | + } elseif (!empty($_SERVER['HTTP_VIA'])) { |
|
228 | + $proxy_ip = $_SERVER['HTTP_VIA']; |
|
229 | + } elseif (!empty($_SERVER['HTTP_X_COMING_FROM'])) { |
|
230 | + $proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; |
|
231 | + } elseif (!empty($_SERVER['HTTP_COMING_FROM'])) { |
|
232 | + $proxy_ip = $_SERVER['HTTP_COMING_FROM']; |
|
233 | + } |
|
234 | + $regs = array(); |
|
235 | + if (!empty($proxy_ip) && $is_ip = ereg('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $proxy_ip, $regs) && count($regs) > 0) { |
|
236 | + $the_IP = $regs[0]; |
|
237 | + } else { |
|
238 | + $the_IP = $_SERVER['REMOTE_ADDR']; |
|
239 | + } |
|
240 | + |
|
241 | + return $the_IP; |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Set the page's title, meta description and meta keywords |
|
246 | + * Datas are supposed to be sanitized |
|
247 | + * |
|
248 | + * @param string $pageTitle Page's Title |
|
249 | + * @param string $metaDescription Page's meta description |
|
250 | + * @param string $metaKeywords Page's meta keywords |
|
251 | + * @return void |
|
252 | + */ |
|
253 | + public static function setMetas($pageTitle = '', $metaDescription = '', $metaKeywords = '') |
|
254 | + { |
|
255 | + global $xoTheme, $xoTheme, $xoopsTpl; |
|
256 | + $xoopsTpl->assign('xoops_pagetitle', $pageTitle); |
|
257 | + if (isset($xoTheme) && is_object($xoTheme)) { |
|
258 | + if (!empty($metaKeywords)) { |
|
259 | + $xoTheme->addMeta('meta', 'keywords', $metaKeywords); |
|
260 | + } |
|
261 | + if (!empty($metaDescription)) { |
|
262 | + $xoTheme->addMeta('meta', 'description', $metaDescription); |
|
263 | + } |
|
264 | + } elseif (isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
|
265 | + if (!empty($metaKeywords)) { |
|
266 | + $xoopsTpl->assign('xoops_meta_keywords', $metaKeywords); |
|
267 | + } |
|
268 | + if (!empty($metaDescription)) { |
|
269 | + $xoopsTpl->assign('xoops_meta_description', $metaDescription); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Send an email from a template to a list of recipients |
|
276 | + * |
|
277 | + * @param $tplName |
|
278 | + * @param array $recipients List of recipients |
|
279 | + * @param string $subject Email's subject |
|
280 | + * @param array $variables Varirables to give to the template |
|
281 | + * @return bool Result of the send |
|
282 | + * @internal param string $tpl_name Template's name |
|
283 | + */ |
|
284 | + public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
|
285 | + { |
|
286 | + global $xoopsConfig; |
|
287 | + require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
|
288 | + if (!is_array($recipients)) { |
|
289 | + if (trim($recipients) == '') { |
|
290 | + return false; |
|
291 | + } |
|
292 | + } else { |
|
293 | + if (count($recipients) == 0) { |
|
294 | + return false; |
|
295 | + } |
|
296 | + } |
|
297 | + if (function_exists('xoops_getMailer')) { |
|
298 | + $xoopsMailer =& xoops_getMailer(); |
|
299 | + } else { |
|
300 | + $xoopsMailer =& getMailer(); |
|
301 | + } |
|
302 | + |
|
303 | + $xoopsMailer->useMail(); |
|
304 | + $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'); |
|
305 | + $xoopsMailer->setTemplate($tplName); |
|
306 | + $xoopsMailer->setToEmails($recipients); |
|
307 | + // TODO: Change ! |
|
308 | + // $xoopsMailer->setFromEmail('[email protected]'); |
|
309 | + //$xoopsMailer->setFromName('MonSite'); |
|
310 | + $xoopsMailer->setSubject($subject); |
|
311 | + foreach ($variables as $key => $value) { |
|
312 | + $xoopsMailer->assign($key, $value); |
|
313 | + } |
|
314 | + $res = $xoopsMailer->send(); |
|
315 | + unset($xoopsMailer); |
|
316 | + $filename = XOOPS_UPLOAD_PATH . '/logmail_' . self::MODULE_NAME . '.php'; |
|
317 | + if (!file_exists($filename)) { |
|
318 | + $fp = @fopen($filename, 'a'); |
|
319 | + if ($fp) { |
|
320 | + fwrite($fp, '<?php exit(); ?>'); |
|
321 | + fclose($fp); |
|
322 | + } |
|
323 | + } |
|
324 | + $fp = @fopen($filename, 'a'); |
|
325 | + |
|
326 | + if ($fp) { |
|
327 | + fwrite($fp, str_repeat('-', 120) . "\n"); |
|
328 | + fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
|
329 | + fwrite($fp, 'Template name : ' . $tplName . "\n"); |
|
330 | + fwrite($fp, 'Email subject : ' . $subject . "\n"); |
|
331 | + if (is_array($recipients)) { |
|
332 | + fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
|
333 | + } else { |
|
334 | + fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
|
335 | + } |
|
336 | + fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
|
337 | + fclose($fp); |
|
338 | + } |
|
339 | + |
|
340 | + return $res; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Remove module's cache |
|
345 | + */ |
|
346 | + public static function updateCache() |
|
347 | + { |
|
348 | + global $xoopsModule; |
|
349 | + $folder = $xoopsModule->getVar('dirname'); |
|
350 | + $tpllist = array(); |
|
351 | + require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
|
352 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
353 | + $tplfile_handler = xoops_getHandler('tplfile'); |
|
354 | + $tpllist = $tplfile_handler->find(null, null, null, $folder); |
|
355 | + xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
|
356 | + |
|
357 | + foreach ($tpllist as $onetemplate) { // Remove cache for each page. |
|
358 | + if ($onetemplate->getVar('tpl_type') === 'module') { |
|
359 | + // Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
|
360 | + $files_del = array(); |
|
361 | + $files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*'); |
|
362 | + if (count($files_del) > 0 && is_array($files_del)) { |
|
363 | + foreach ($files_del as $one_file) { |
|
364 | + if (is_file($one_file)) { |
|
365 | + unlink($one_file); |
|
366 | + } |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Redirect user with a message |
|
375 | + * |
|
376 | + * @param string $message message to display |
|
377 | + * @param string $url The place where to go |
|
378 | + * @param integer timeout Time to wait before to redirect |
|
379 | + */ |
|
380 | + public static function redirect($message = '', $url = 'index.php', $time = 2) |
|
381 | + { |
|
382 | + redirect_header($url, $time, $message); |
|
383 | + exit(); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Internal function used to get the handler of the current module |
|
388 | + * |
|
389 | + * @return object The module |
|
390 | + */ |
|
391 | + public static function getModule() |
|
392 | + { |
|
393 | + static $mymodule; |
|
394 | + if (!isset($mymodule)) { |
|
395 | + global $xoopsModule; |
|
396 | + if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == REFERENCES_DIRNAME) { |
|
397 | + $mymodule =& $xoopsModule; |
|
398 | + } else { |
|
399 | + $hModule = xoops_getHandler('module'); |
|
400 | + $mymodule = $hModule->getByDirname(REFERENCES_DIRNAME); |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + return $mymodule; |
|
405 | + } |
|
406 | + |
|
407 | + /** |
|
408 | + * Returns the module's name (as defined by the user in the module manager) with cache |
|
409 | + * @return string Module's name |
|
410 | + */ |
|
411 | + public static function getModuleName() |
|
412 | + { |
|
413 | + static $moduleName; |
|
414 | + if (!isset($moduleName)) { |
|
415 | + $mymodule = self::getModule(); |
|
416 | + $moduleName = $mymodule->getVar('name'); |
|
417 | + } |
|
418 | + |
|
419 | + return $moduleName; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Create a title for the href tags inside html links |
|
424 | + * |
|
425 | + * @param string $title Text to use |
|
426 | + * @return string Formated text |
|
427 | + */ |
|
428 | + public static function makeHrefTitle($title) |
|
429 | + { |
|
430 | + $s = "\"'"; |
|
431 | + $r = ' '; |
|
432 | + |
|
433 | + return strtr($title, $s, $r); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * Retourne la liste des utilisateurs appartenants � un groupe |
|
438 | + * |
|
439 | + * @param int $groupId Searched group |
|
440 | + * @return array Array of XoopsUsers |
|
441 | + */ |
|
442 | + public static function getUsersFromGroup($groupId) |
|
443 | + { |
|
444 | + $users = array(); |
|
445 | + $member_handler = xoops_getHandler('member'); |
|
446 | + $users = $member_handler->getUsersByGroup($groupId, true); |
|
447 | + |
|
448 | + return $users; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Retourne les ID des utilisateurs faisant partie de plusieurs groupes |
|
453 | + * @param array $groups Les ID des groupes dont on recherche les ID utilisateurs |
|
454 | + * @return array Les ID utilisateurs |
|
455 | + */ |
|
456 | + public static function getUsersIdsFromGroups($groups) |
|
457 | + { |
|
458 | + $usersIds = array(); |
|
459 | + $member_handler = xoops_getHandler('member'); |
|
460 | + foreach ($groups as $groupId) { |
|
461 | + $temporaryGroup = array(); |
|
462 | + $temporaryGroup = $member_handler->getUsersByGroup($groupId); |
|
463 | + if (count($temporaryGroup) > 0) { |
|
464 | + $usersIds = array_merge($usersIds, $temporaryGroup); |
|
465 | + } |
|
466 | + } |
|
467 | + |
|
468 | + return array_unique($usersIds); |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * Retourne la liste des emails des utilisateurs membres d'un groupe |
|
473 | + * |
|
474 | + * @param $groupId |
|
475 | + * @return array Emails list |
|
476 | + * @internal param int $group_id Group's number |
|
477 | + */ |
|
478 | + public static function getEmailsFromGroup($groupId) |
|
479 | + { |
|
480 | + $ret = array(); |
|
481 | + $users = self::getUsersFromGroup($groupId); |
|
482 | + foreach ($users as $user) { |
|
483 | + $ret[] = $user->getVar('email'); |
|
484 | + } |
|
485 | + |
|
486 | + return $ret; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * V�rifie que l'utilisateur courant fait partie du groupe des administrateurs |
|
491 | + * |
|
492 | + * @return booleean Admin or not |
|
493 | + */ |
|
494 | + public static function isAdmin() |
|
495 | + { |
|
496 | + global $xoopsUser, $xoopsModule; |
|
497 | + if (is_object($xoopsUser)) { |
|
498 | + if (in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups())) { |
|
499 | + return true; |
|
500 | + } elseif (isset($xoopsModule) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
|
501 | + return true; |
|
502 | + } |
|
503 | + } |
|
504 | + |
|
505 | + return false; |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * Returns the current date in the Mysql format |
|
510 | + * |
|
511 | + * @return string Date in the Mysql format |
|
512 | + */ |
|
513 | + public static function getCurrentSQLDate() |
|
514 | + { |
|
515 | + return date('Y-m-d'); // 2007-05-02 |
|
516 | + } |
|
517 | + |
|
518 | + public static function getCurrentSQLDateTime() |
|
519 | + { |
|
520 | + return date('Y-m-d H:i:s'); // 2007-05-02 |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Convert a Mysql date to the human's format |
|
525 | + * |
|
526 | + * @param string $date The date to convert |
|
527 | + * @param string $format |
|
528 | + * @return string The date in a human form |
|
529 | + */ |
|
530 | + public static function SQLDateToHuman($date, $format = 'l') |
|
531 | + { |
|
532 | + if ($date != '0000-00-00' && xoops_trim($date) != '') { |
|
533 | + return formatTimestamp(strtotime($date), $format); |
|
534 | + } else { |
|
535 | + return ''; |
|
536 | + } |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Convert a timestamp to a Mysql date |
|
541 | + * |
|
542 | + * @param integer $timestamp The timestamp to use |
|
543 | + * @return string The date in the Mysql format |
|
544 | + */ |
|
545 | + public static function timestampToMysqlDate($timestamp) |
|
546 | + { |
|
547 | + return date('Y-m-d', (int)$timestamp); |
|
548 | + } |
|
549 | + |
|
550 | + /** |
|
551 | + * Conversion d'un dateTime Mysql en date lisible en fran�ais |
|
552 | + * @param $dateTime |
|
553 | + * @return bool|string |
|
554 | + */ |
|
555 | + public static function sqlDateTimeToFrench($dateTime) |
|
556 | + { |
|
557 | + return date('d/m/Y H:i:s', strtotime($dateTime)); |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * Convert a timestamp to a Mysql datetime form |
|
562 | + * @param integer $timestamp The timestamp to use |
|
563 | + * @return string The date and time in the Mysql format |
|
564 | + */ |
|
565 | + public static function timestampToMysqlDateTime($timestamp) |
|
566 | + { |
|
567 | + return date('Y-m-d H:i:s', $timestamp); |
|
568 | + } |
|
569 | + |
|
570 | + /** |
|
571 | + * This function indicates if the current Xoops version needs to add asterisks to required fields in forms |
|
572 | + * |
|
573 | + * @return boolean Yes = we need to add them, false = no |
|
574 | + */ |
|
575 | + public static function needsAsterisk() |
|
576 | + { |
|
577 | + if (self::isX23()) { |
|
578 | + return false; |
|
579 | + } |
|
580 | + if (strpos(strtolower(XOOPS_VERSION), 'impresscms') !== false) { |
|
581 | + return false; |
|
582 | + } |
|
583 | + if (strpos(strtolower(XOOPS_VERSION), 'legacy') === false) { |
|
584 | + $xv = xoops_trim(str_replace('XOOPS ', '', XOOPS_VERSION)); |
|
585 | + if ((int)substr($xv, 4, 2) >= 17) { |
|
586 | + return false; |
|
587 | + } |
|
588 | + } |
|
589 | + |
|
590 | + return true; |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Mark the mandatory fields of a form with a star |
|
595 | + * |
|
596 | + * @param object $sform The form to modify |
|
597 | + * @return object The modified form |
|
598 | + * @internal param string $caracter The character to use to mark fields |
|
599 | + */ |
|
600 | + public static function &formMarkRequiredFields(&$sform) |
|
601 | + { |
|
602 | + if (self::needsAsterisk()) { |
|
603 | + $required = array(); |
|
604 | + foreach ($sform->getRequired() as $item) { |
|
605 | + $required[] = $item->_name; |
|
606 | + } |
|
607 | + $elements = array(); |
|
608 | + $elements = &$sform->getElements(); |
|
609 | + $cnt = count($elements); |
|
610 | + for ($i = 0; $i < $cnt; ++$i) { |
|
611 | + if (is_object($elements[$i]) && in_array($elements[$i]->_name, $required)) { |
|
612 | + $elements[$i]->_caption .= ' *'; |
|
613 | + } |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + return $sform; |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * Create an html heading (from h1 to h6) |
|
622 | + * |
|
623 | + * @param string $title The text to use |
|
624 | + * @param integer $level Level to return |
|
625 | + * @return string The heading |
|
626 | + */ |
|
627 | + public static function htitle($title = '', $level = 1) |
|
628 | + { |
|
629 | + printf('<h%01d>%s</h%01d>', $level, $title, $level); |
|
630 | + } |
|
631 | + |
|
632 | + /** |
|
633 | + * Create a unique upload filename |
|
634 | + * |
|
635 | + * @param string $folder The folder where the file will be saved |
|
636 | + * @param string $fileName Original filename (coming from the user) |
|
637 | + * @param boolean $trimName Do we need to create a short unique name ? |
|
638 | + * @return string The unique filename to use (with its extension) |
|
639 | + */ |
|
640 | + public static function createUploadName($folder, $fileName, $trimName = false) |
|
641 | + { |
|
642 | + $workingfolder = $folder; |
|
643 | + if (substr($workingfolder, strlen($workingfolder) - 1, 1) !== '/') { |
|
644 | + $workingfolder .= '/'; |
|
645 | + } |
|
646 | + $ext = basename($fileName); |
|
647 | + $ext = explode('.', $ext); |
|
648 | + $ext = '.' . $ext[count($ext) - 1]; |
|
649 | + $true = true; |
|
650 | + while ($true) { |
|
651 | + $ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
|
652 | + list($usec, $sec) = explode(' ', microtime()); |
|
653 | + $usec = (integer)($usec * 65536); |
|
654 | + $sec = ((integer)$sec) & 0xFFFF; |
|
655 | + |
|
656 | + if ($trimName) { |
|
657 | + $uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
|
658 | + } else { |
|
659 | + $uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
|
660 | + } |
|
661 | + if (!file_exists($workingfolder . $uid . $ext)) { |
|
662 | + $true = false; |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + return $uid . $ext; |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Replace html entities with their ASCII equivalent |
|
671 | + * |
|
672 | + * @param string $chaine The string undecode |
|
673 | + * @return string The undecoded string |
|
674 | + */ |
|
675 | + public static function unhtml($chaine) |
|
676 | + { |
|
677 | + $search = $replace = array(); |
|
678 | + $chaine = html_entity_decode($chaine); |
|
679 | + |
|
680 | + for ($i = 0; $i <= 255; ++$i) { |
|
681 | + $search[] = '&#' . $i . ';'; |
|
682 | + $replace[] = chr($i); |
|
683 | + } |
|
684 | 684 | $replace[]='...'; $search[]='…'; |
685 | 685 | $replace[]="'"; $search[]='‘'; |
686 | 686 | $replace[]="'"; $search[]= '’'; |
@@ -806,765 +806,765 @@ discard block |
||
806 | 806 | $replace[]='Ý'; $search[]='Ý'; |
807 | 807 | $replace[]='ÿ'; $search[]='ÿ'; |
808 | 808 | $replace[]='Ÿ'; $search[]='Ÿ'; |
809 | - $chaine = str_replace($search, $replace, $chaine); |
|
810 | - |
|
811 | - return $chaine; |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Création d'une titre pour être utilisé par l'url rewriting |
|
816 | - * |
|
817 | - * @param string $content Le texte à utiliser pour créer l'url |
|
818 | - * @param integer $urw La limite basse pour créer les mots |
|
819 | - * @return string Le texte à utiliser pour l'url |
|
820 | - * Note, some parts are from Solo's code |
|
821 | - */ |
|
822 | - public static function makeSeoUrl($content, $urw = 1) |
|
823 | - { |
|
824 | - $s = "ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÇÌÍÎÏÙÚÛÜŸÑàáâãäåòóôõöøèéêëçìíîïùúûüÿñ '()"; |
|
825 | - $r = 'AAAAAAOOOOOOEEEECIIIIUUUUYNaaaaaaooooooeeeeciiiiuuuuyn----'; |
|
826 | - $content = self::unhtml($content); // First, remove html entities |
|
827 | - $content = strtr($content, $s, $r); |
|
828 | - $content = strip_tags($content); |
|
829 | - $content = strtolower($content); |
|
830 | - $content = htmlentities($content); // TODO: Vérifier |
|
831 | - $content = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $content); |
|
832 | - $content = html_entity_decode($content); |
|
833 | - $content = eregi_replace('quot', ' ', $content); |
|
834 | - $content = eregi_replace("'", ' ', $content); |
|
835 | - $content = eregi_replace('-', ' ', $content); |
|
836 | - $content = eregi_replace('[[:punct:]]', '', $content); |
|
837 | - // Selon option mais attention au fichier .htaccess ! |
|
838 | - // $content = eregi_replace('[[:digit:]]','', $content); |
|
839 | - $content = preg_replace('/[^a-z|A-Z|0-9]/', '-', $content); |
|
840 | - |
|
841 | - $words = explode(' ', $content); |
|
842 | - $keywords = ''; |
|
843 | - foreach ($words as $word) { |
|
844 | - if (strlen($word) >= $urw) { |
|
845 | - $keywords .= '-' . trim($word); |
|
846 | - } |
|
847 | - } |
|
848 | - if (!$keywords) { |
|
849 | - $keywords = '-'; |
|
850 | - } |
|
851 | - // Supprime les tirets en double |
|
852 | - $keywords = str_replace('---', '-', $keywords); |
|
853 | - $keywords = str_replace('--', '-', $keywords); |
|
854 | - // Supprime un éventuel tiret à la fin de la chaine |
|
855 | - if (substr($keywords, strlen($keywords) - 1, 1) == '-') { |
|
856 | - $keywords = substr($keywords, 0, strlen($keywords) - 1); |
|
857 | - } |
|
858 | - |
|
859 | - return $keywords; |
|
860 | - } |
|
861 | - |
|
862 | - /** |
|
863 | - * Create the meta keywords based on the content |
|
864 | - * |
|
865 | - * @param string $content Content from which we have to create metakeywords |
|
866 | - * @return string The list of meta keywords |
|
867 | - */ |
|
868 | - public static function createMetaKeywords($content) |
|
869 | - { |
|
870 | - $keywordscount = REFERENCES_METAGEN_MAX_KEYWORDS; |
|
871 | - $keywordsorder = REFERENCES_METAGEN_KEYWORDS_ORDER; |
|
872 | - |
|
873 | - $tmp = array(); |
|
874 | - // Search for the "Minimum keyword length" |
|
875 | - // TODO: Remplacer references_keywords_limit par une constante |
|
876 | - if (isset($_SESSION['references_keywords_limit'])) { |
|
877 | - $limit = $_SESSION['references_keywords_limit']; |
|
878 | - } else { |
|
879 | - $config_handler = xoops_getHandler('config'); |
|
880 | - $xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
|
881 | - $limit = $xoopsConfigSearch['keyword_min']; |
|
882 | - $_SESSION['references_keywords_limit'] = $limit; |
|
883 | - } |
|
884 | - $myts = MyTextSanitizer::getInstance(); |
|
885 | - $content = str_replace('<br>', ' ', $content); |
|
886 | - $content = $myts->undoHtmlSpecialChars($content); |
|
887 | - $content = strip_tags($content); |
|
888 | - $content = strtolower($content); |
|
889 | - $search_pattern = array(' ', "\t", "\r\n", "\r", "\n", ',', '.', "'", ';', ':', ')', '(', '"', '?', '!', '{', '}', '[', ']', '<', '>', '/', '+', '-', '_', '\\', '*'); |
|
890 | - $replace_pattern = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); |
|
891 | - $content = str_replace($search_pattern, $replace_pattern, $content); |
|
892 | - $keywords = explode(' ', $content); |
|
893 | - switch ($keywordsorder) { |
|
894 | - case 0: // Ordre d'apparition dans le texte |
|
895 | - $keywords = array_unique($keywords); |
|
896 | - break; |
|
897 | - case 1: // Ordre de fréquence des mots |
|
898 | - $keywords = array_count_values($keywords); |
|
899 | - asort($keywords); |
|
900 | - $keywords = array_keys($keywords); |
|
901 | - break; |
|
902 | - case 2: // Ordre inverse de la fréquence des mots |
|
903 | - $keywords = array_count_values($keywords); |
|
904 | - arsort($keywords); |
|
905 | - $keywords = array_keys($keywords); |
|
906 | - break; |
|
907 | - } |
|
908 | - // Remove black listed words |
|
909 | - if (xoops_trim(self::getModuleOption('metagen_blacklist')) != '') { |
|
910 | - $metagen_blacklist = str_replace("\r", '', self::getModuleOption('metagen_blacklist')); |
|
911 | - $metablack = explode("\n", $metagen_blacklist); |
|
912 | - array_walk($metablack, 'trim'); |
|
913 | - $keywords = array_diff($keywords, $metablack); |
|
914 | - } |
|
915 | - |
|
916 | - foreach ($keywords as $keyword) { |
|
917 | - if (strlen($keyword) >= $limit && !is_numeric($keyword)) { |
|
918 | - $tmp[] = $keyword; |
|
919 | - } |
|
920 | - } |
|
921 | - $tmp = array_slice($tmp, 0, $keywordscount); |
|
922 | - if (count($tmp) > 0) { |
|
923 | - return implode(',', $tmp); |
|
924 | - } else { |
|
925 | - if (!isset($config_handler) || !is_object($config_handler)) { |
|
926 | - $config_handler = xoops_getHandler('config'); |
|
927 | - } |
|
928 | - $xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
|
929 | - if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
|
930 | - return $xoopsConfigMetaFooter['meta_keywords']; |
|
931 | - } else { |
|
932 | - return ''; |
|
933 | - } |
|
934 | - } |
|
935 | - } |
|
936 | - |
|
937 | - /** |
|
938 | - * Fonction chargée de gérer l'upload |
|
939 | - * |
|
940 | - * @param integer $indice L'indice du fichier à télécharger |
|
941 | - * @param string $dstpath |
|
942 | - * @param null $mimeTypes |
|
943 | - * @param null $uploadMaxSize |
|
944 | - * @param null $maxWidth |
|
945 | - * @param null $maxHeight |
|
946 | - * @return mixed True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
|
947 | - */ |
|
948 | - public static function uploadFile($indice, $dstpath = XOOPS_UPLOAD_PATH, $mimeTypes = null, $uploadMaxSize = null, $maxWidth = null, $maxHeight = null) |
|
949 | - { |
|
950 | - require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
951 | - global $destname; |
|
952 | - if (isset($_POST['xoops_upload_file'])) { |
|
953 | - require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
954 | - $fldname = ''; |
|
955 | - $fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
|
956 | - $fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; |
|
957 | - if (xoops_trim($fldname != '')) { |
|
958 | - $destname = self::createUploadName($dstpath, $fldname, true); |
|
959 | - if ($mimeTypes === null) { |
|
960 | - $permittedtypes = explode("\n", str_replace("\r", '', self::getModuleOption('mimetypes'))); |
|
961 | - array_walk($permittedtypes, 'trim'); |
|
962 | - } else { |
|
963 | - $permittedtypes = $mimeTypes; |
|
964 | - } |
|
965 | - if ($uploadMaxSize === null) { |
|
966 | - $uploadSize = self::getModuleOption('maxuploadsize'); |
|
967 | - } else { |
|
968 | - $uploadSize = $uploadMaxSize; |
|
969 | - } |
|
970 | - $uploader = new XoopsMediaUploader($dstpath, $permittedtypes, $uploadSize, $maxWidth, $maxHeight); |
|
971 | - //$uploader->allowUnknownTypes = true; |
|
972 | - $uploader->setTargetFileName($destname); |
|
973 | - if ($uploader->fetchMedia($_POST['xoops_upload_file'][$indice])) { |
|
974 | - if ($uploader->upload()) { |
|
975 | - return true; |
|
976 | - } else { |
|
977 | - return _ERRORS . ' ' . htmlentities($uploader->getErrors()); |
|
978 | - } |
|
979 | - } else { |
|
980 | - return htmlentities($uploader->getErrors()); |
|
981 | - } |
|
982 | - } else { |
|
983 | - return false; |
|
984 | - } |
|
985 | - } else { |
|
986 | - return false; |
|
987 | - } |
|
988 | - } |
|
989 | - |
|
990 | - /** |
|
991 | - * Resize a Picture to some given dimensions (using the wideImage library) |
|
992 | - * |
|
993 | - * @param string $src_path Picture's source |
|
994 | - * @param string $dst_path Picture's destination |
|
995 | - * @param integer $param_width Maximum picture's width |
|
996 | - * @param integer $param_height Maximum picture's height |
|
997 | - * @param boolean $keep_original Do we have to keep the original picture ? |
|
998 | - * @param string $fit Resize mode (see the wideImage library for more information) |
|
999 | - * @return bool |
|
1000 | - */ |
|
1001 | - public static function resizePicture($src_path, $dst_path, $param_width, $param_height, $keep_original = false, $fit = 'inside') |
|
1002 | - { |
|
1003 | - // require_once self::MODULE_PATH . 'class/wideimage/WideImage.php'; |
|
1004 | - $img = WideImage::load($src_path); |
|
1005 | - $result = $img->resize($param_width, $param_height, $fit); |
|
1006 | - $result->saveToFile($dst_path, null); |
|
1007 | - if (!$keep_original) { |
|
1008 | - @unlink($src_path); |
|
1009 | - } |
|
1010 | - |
|
1011 | - return true; |
|
1012 | - } |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * Déclenchement d'une alerte Xoops suite à un évènement |
|
1016 | - * |
|
1017 | - * @param string $category La catégorie de l'évènement |
|
1018 | - * @param integer $itemId L'ID de l'élément (trop général pour être décris précisément) |
|
1019 | - * @param unknown_type $event L'évènement qui est déclencé |
|
1020 | - * @param unknown_type $tags Les variables à passer au template |
|
1021 | - */ |
|
1022 | - public static function notify($category, $itemId, $event, $tags) |
|
1023 | - { |
|
1024 | - $notification_handler = xoops_getHandler('notification'); |
|
1025 | - $tags['X_MODULE_URL'] = REFERENCES_URL; |
|
1026 | - $notification_handler->triggerEvent($category, $itemId, $event, $tags); |
|
1027 | - } |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * Ajoute des jours à une date et retourne la nouvelle date au format Date de Mysql |
|
1031 | - * |
|
1032 | - * @param int $duration |
|
1033 | - * @param integer $startingDate Date de départ (timestamp) |
|
1034 | - * @return bool|string |
|
1035 | - * @internal param int $durations Durée en jours |
|
1036 | - */ |
|
1037 | - public static function addDaysToDate($duration = 1, $startingDate = 0) |
|
1038 | - { |
|
1039 | - if ($startingDate == 0) { |
|
1040 | - $startingDate = time(); |
|
1041 | - } |
|
1042 | - $endingDate = $startingDate + ($duration * 86400); |
|
1043 | - |
|
1044 | - return date('Y-m-d', $endingDate); |
|
1045 | - } |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * Retourne un breadcrumb en fonction des paramètres passés et en partant (d'office) de la racine du module |
|
1049 | - * |
|
1050 | - * @param array $path Le chemin complet (excepté la racine) du breadcrumb sous la forme clé=url valeur=titre |
|
1051 | - * @param string $raquo Le séparateur par défaut à utiliser |
|
1052 | - * @return string le breadcrumb |
|
1053 | - */ |
|
1054 | - public static function breadcrumb($path, $raquo = ' » ') |
|
1055 | - { |
|
1056 | - $breadcrumb = ''; |
|
1057 | - $workingBreadcrumb = array(); |
|
1058 | - if (is_array($path)) { |
|
1059 | - $moduleName = self::getModuleName(); |
|
1060 | - $workingBreadcrumb[] = "<a href='" . REFERENCES_URL . "' title='" . self::makeHrefTitle($moduleName) . "'>" . $moduleName . '</a>'; |
|
1061 | - foreach ($path as $url => $title) { |
|
1062 | - $workingBreadcrumb[] = "<a href='" . $url . "'>" . $title . '</a>'; |
|
1063 | - } |
|
1064 | - $cnt = count($workingBreadcrumb); |
|
1065 | - for ($i = 0; $i < $cnt; ++$i) { |
|
1066 | - if ($i == $cnt - 1) { |
|
1067 | - $workingBreadcrumb[$i] = strip_tags($workingBreadcrumb[$i]); |
|
1068 | - } |
|
1069 | - } |
|
1070 | - $breadcrumb = implode($raquo, $workingBreadcrumb); |
|
1071 | - } |
|
1072 | - |
|
1073 | - return $breadcrumb; |
|
1074 | - } |
|
1075 | - |
|
1076 | - public static function close_tags($string) |
|
1077 | - { |
|
1078 | - // match opened tags |
|
1079 | - if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
|
1080 | - $start_tags = $start_tags[1]; |
|
1081 | - |
|
1082 | - // match closed tags |
|
1083 | - if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
|
1084 | - $complete_tags = array(); |
|
1085 | - $end_tags = $end_tags[1]; |
|
1086 | - |
|
1087 | - foreach ($start_tags as $key => $val) { |
|
1088 | - $posb = array_search($val, $end_tags); |
|
1089 | - if (is_int($posb)) { |
|
1090 | - unset($end_tags[$posb]); |
|
1091 | - } else { |
|
1092 | - $complete_tags[] = $val; |
|
1093 | - } |
|
1094 | - } |
|
1095 | - } else { |
|
1096 | - $complete_tags = $start_tags; |
|
1097 | - } |
|
1098 | - |
|
1099 | - $complete_tags = array_reverse($complete_tags); |
|
1100 | - for ($i = 0; $i < count($complete_tags); ++$i) { |
|
1101 | - $string .= '</' . $complete_tags[$i] . '>'; |
|
1102 | - } |
|
1103 | - } |
|
1104 | - |
|
1105 | - return $string; |
|
1106 | - } |
|
1107 | - |
|
1108 | - public static function truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) |
|
1109 | - { |
|
1110 | - if ($length == 0) { |
|
1111 | - return ''; |
|
1112 | - } |
|
1113 | - |
|
1114 | - if (strlen($string) > $length) { |
|
1115 | - $length -= strlen($etc); |
|
1116 | - if (!$break_words) { |
|
1117 | - $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); |
|
1118 | - $string = preg_replace('/<[^>]*$/', '', $string); |
|
1119 | - $string = self::close_tags($string); |
|
1120 | - } |
|
1121 | - |
|
1122 | - return $string . $etc; |
|
1123 | - } else { |
|
1124 | - return $string; |
|
1125 | - } |
|
1126 | - } |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * Create an infotip |
|
1130 | - * @param $text |
|
1131 | - * @return string |
|
1132 | - */ |
|
1133 | - public static function makeInfotips($text) |
|
1134 | - { |
|
1135 | - $ret = ''; |
|
1136 | - $infotips = self::getModuleOption('infotips'); |
|
1137 | - if ($infotips > 0) { |
|
1138 | - $myts = MyTextSanitizer::getInstance(); |
|
1139 | - $ret = $myts->htmlSpecialChars(substr(strip_tags($text), 0, $infotips)); |
|
1140 | - } |
|
1141 | - |
|
1142 | - return $ret; |
|
1143 | - } |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * Retourne le type Mime d'un fichier en utilisant d'abord finfo puis mime_content |
|
1147 | - * |
|
1148 | - * @param string $filename Le fichier (avec son chemin d'accès complet) dont on veut connaître le type mime |
|
1149 | - * @return string |
|
1150 | - */ |
|
1151 | - public static function getMimeType($filename) |
|
1152 | - { |
|
1153 | - if (function_exists('finfo_open')) { |
|
1154 | - $pathToMagic = REFERENCES_PATH . 'mime/magic'; |
|
1155 | - $finfo = new finfo(FILEINFO_MIME, $pathToMagic); |
|
1156 | - $mimetype = $finfo->file($filename); |
|
1157 | - finfo_close($finfo); |
|
1158 | - unset($finfo); |
|
1159 | - |
|
1160 | - return $mimetype; |
|
1161 | - } else { |
|
1162 | - if (function_exists('mime_content_type')) { |
|
1163 | - return mime_content_type($filename); |
|
1164 | - } else { |
|
1165 | - return ''; |
|
1166 | - } |
|
1167 | - } |
|
1168 | - } |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * Retourne une liste d'objets XoopsUsers à partir d'une liste d'identifiants |
|
1172 | - * |
|
1173 | - * @param array $xoopsUsersIDs La liste des ID |
|
1174 | - * @return array Les objets XoopsUsers |
|
1175 | - */ |
|
1176 | - public static function getUsersFromIds($xoopsUsersIDs) |
|
1177 | - { |
|
1178 | - $users = array(); |
|
1179 | - if (is_array($xoopsUsersIDs) && count($xoopsUsersIDs) > 0) { |
|
1180 | - $xoopsUsersIDs = array_unique($xoopsUsersIDs); |
|
1181 | - sort($xoopsUsersIDs); |
|
1182 | - if (count($xoopsUsersIDs) > 0) { |
|
1183 | - $member_handler = xoops_getHandler('user'); |
|
1184 | - $criteria = new Criteria('uid', '(' . implode(',', $xoopsUsersIDs) . ')', 'IN'); |
|
1185 | - $criteria->setSort('uid'); |
|
1186 | - $users = $member_handler->getObjects($criteria, true); |
|
1187 | - } |
|
1188 | - } |
|
1189 | - |
|
1190 | - return $users; |
|
1191 | - } |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * Retourne l'ID de l'utilisateur courant (s'il est connecté) |
|
1195 | - * @return integer L'uid ou 0 |
|
1196 | - */ |
|
1197 | - public static function getCurrentUserID() |
|
1198 | - { |
|
1199 | - global $xoopsUser; |
|
1200 | - $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
|
1201 | - |
|
1202 | - return $uid; |
|
1203 | - } |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * Retourne la liste des groupes de l'utilisateur courant (avec cache) |
|
1207 | - * @param int $uid |
|
1208 | - * @return array Les ID des groupes auquel l'utilisateur courant appartient |
|
1209 | - */ |
|
1210 | - public static function getMemberGroups($uid = 0) |
|
1211 | - { |
|
1212 | - static $buffer = array(); |
|
1213 | - if ($uid == 0) { |
|
1214 | - $uid = self::getCurrentUserID(); |
|
1215 | - } |
|
1216 | - |
|
1217 | - if (is_array($buffer) && count($buffer) > 0 && isset($buffer[$uid])) { |
|
1218 | - return $buffer[$uid]; |
|
1219 | - } else { |
|
1220 | - if ($uid > 0) { |
|
1221 | - $member_handler = xoops_getHandler('member'); |
|
1222 | - $buffer[$uid] = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1223 | - } else { |
|
1224 | - $buffer[$uid] = array(XOOPS_GROUP_ANONYMOUS); |
|
1225 | - } |
|
1226 | - } |
|
1227 | - |
|
1228 | - return $buffer[$uid]; |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * Indique si l'utilisateur courant fait partie d'une groupe donné (avec gestion de cache) |
|
1233 | - * |
|
1234 | - * @param integer $group Groupe recherché |
|
1235 | - * @param int $uid |
|
1236 | - * @return bool vrai si l'utilisateur fait partie du groupe, faux sinon |
|
1237 | - */ |
|
1238 | - public static function isMemberOfGroup($group = 0, $uid = 0) |
|
1239 | - { |
|
1240 | - static $buffer = array(); |
|
1241 | - $retval = false; |
|
1242 | - if ($uid == 0) { |
|
1243 | - $uid = self::getCurrentUserID(); |
|
1244 | - } |
|
1245 | - if (is_array($buffer) && array_key_exists($group, $buffer)) { |
|
1246 | - $retval = $buffer[$group]; |
|
1247 | - } else { |
|
1248 | - $member_handler = xoops_getHandler('member'); |
|
1249 | - $groups = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1250 | - $retval = in_array($group, $groups); |
|
1251 | - $buffer[$group] = $retval; |
|
1252 | - } |
|
1253 | - |
|
1254 | - return $retval; |
|
1255 | - } |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * Indique si un utilisateur fait partie de plusieurs groupes |
|
1259 | - * La fonction renvoie vrai dès qu'on trouve que le membre fait partir d'un des groupes |
|
1260 | - * @param array $groups La liste des groupes à vérifier |
|
1261 | - * @param integer $uid L'ID de l'utilisateur |
|
1262 | - * @return boolean |
|
1263 | - */ |
|
1264 | - public static function isMemberOfGroups($groups, $uid = 0) |
|
1265 | - { |
|
1266 | - if (count($groups) == 0) { |
|
1267 | - return false; |
|
1268 | - } |
|
1269 | - if ($uid == 0) { |
|
1270 | - $uid = self::getCurrentUserID(); |
|
1271 | - } |
|
1272 | - foreach ($groups as $groupId) { |
|
1273 | - if (self::isMemberOfGroup($groupId, $uid)) { |
|
1274 | - return true; |
|
1275 | - } |
|
1276 | - } |
|
1277 | - |
|
1278 | - return false; |
|
1279 | - } |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * Retourne le nombre total de groupes (y compris les anonymes) |
|
1283 | - */ |
|
1284 | - public static function getGroupsCount() |
|
1285 | - { |
|
1286 | - static $cache = -1; |
|
1287 | - if ($cache == -1) { |
|
1288 | - global $xoopsDB; |
|
1289 | - $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('groups'); |
|
1290 | - $result = $xoopsDB->query($sql); |
|
1291 | - if (!$result) { |
|
1292 | - return false; |
|
1293 | - } |
|
1294 | - list($cache) = $xoopsDB->fetchRow($result); |
|
1295 | - } |
|
1296 | - |
|
1297 | - return $cache; |
|
1298 | - } |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * Fonction chargée de vérifier qu'un répertoire existe, qu'on peut écrire dedans et création d'un fichier index.html |
|
1302 | - * |
|
1303 | - * @param string $folder Le chemin complet du répertoire à vérifier |
|
1304 | - * @return void |
|
1305 | - */ |
|
1306 | - public static function prepareFolder($folder) |
|
1307 | - { |
|
1308 | - if (!is_dir($folder)) { |
|
1309 | - mkdir($folder, 0777); |
|
1310 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
1311 | - } else { |
|
1312 | - if (!is_writable($folder)) { |
|
1313 | - chmod($folder, 0777); |
|
1314 | - } |
|
1315 | - } |
|
1316 | - } |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * Load a language file |
|
1320 | - * |
|
1321 | - * @param string $languageFile The required language file |
|
1322 | - * @param string $defaultExtension Default extension to use |
|
1323 | - */ |
|
1324 | - public static function loadLanguageFile($languageFile, $defaultExtension = '.php') |
|
1325 | - { |
|
1326 | - global $xoopsConfig; |
|
1327 | - $root = self::MODULE_PATH; |
|
1328 | - if (strstr($languageFile, $defaultExtension) === false) { |
|
1329 | - $languageFile .= $defaultExtension; |
|
1330 | - } |
|
1331 | - if (file_exists($root . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . $languageFile)) { |
|
1332 | - require_once $root . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . $languageFile; |
|
1333 | - } else { // Fallback |
|
1334 | - require_once $root . 'language' . DIRECTORY_SEPARATOR . 'english' . DIRECTORY_SEPARATOR . $languageFile; |
|
1335 | - } |
|
1336 | - } |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * Création d'une vignette en tenant compte des options du module concernant le mode de création des vignettes |
|
1340 | - * |
|
1341 | - * @param string $src_path |
|
1342 | - * @param string $dst_path |
|
1343 | - * @param integer $param_width |
|
1344 | - * @param integer $param_height |
|
1345 | - * @param boolean $keep_original |
|
1346 | - * @param string $fit Utilisé uniquement pour la méthode 0 (redimensionnement) |
|
1347 | - * @return boolean |
|
1348 | - */ |
|
1349 | - public static function createThumb($src_path, $dst_path, $param_width, $param_height, $keep_original = false, $fit = 'inside') |
|
1350 | - { |
|
1351 | - // require_once self::MODULE_PATH . 'class/wideimage/WideImage.php'; |
|
1352 | - $resize = true; |
|
1353 | - // On commence par vérifier que l'image originale n'est pas plus petite que les dimensions demandées auquel cas il n'y a rien à faire |
|
1354 | - $pictureDimensions = getimagesize($src_path); |
|
1355 | - if (is_array($pictureDimensions)) { |
|
1356 | - $pictureWidth = $pictureDimensions[0]; |
|
1357 | - $pictureHeight = $pictureDimensions[1]; |
|
1358 | - if ($pictureWidth < $param_width && $pictureHeight < $param_height) { |
|
1359 | - $resize = false; |
|
1360 | - } |
|
1361 | - } |
|
1362 | - $img = WideImage::load($src_path); |
|
1363 | - if ($resize) { // L'image est suffisament grande pour être réduite |
|
1364 | - $thumbMethod = 0; |
|
1365 | - if ($thumbMethod == 0) { // Redimensionnement de l'image |
|
1366 | - $result = $img->resize($param_width, $param_height, $fit); |
|
1367 | - } else { // Récupération d'une partie de l'image depuis le centre |
|
1368 | - // Calcul de left et top |
|
1369 | - $left = $top = 0; |
|
1370 | - if (is_array($pictureDimensions)) { |
|
1371 | - if ($pictureWidth > $param_width) { |
|
1372 | - $left = (int)(($pictureWidth / 2) - ($param_width / 2)); |
|
1373 | - } |
|
1374 | - if ($pictureHeight > $param_height) { |
|
1375 | - $top = (int)(($pictureHeight / 2) - ($param_height / 2)); |
|
1376 | - } |
|
1377 | - } |
|
1378 | - $result = $img->crop($left, $top, $param_width, $param_height); |
|
1379 | - } |
|
1380 | - $result->saveToFile($dst_path, null); |
|
1381 | - } else { |
|
1382 | - if ($src_path != $dst_path) { |
|
1383 | - @copy($src_path, $dst_path); |
|
1384 | - } |
|
1385 | - } |
|
1386 | - if (!$keep_original) { |
|
1387 | - @unlink($src_path); |
|
1388 | - } |
|
1389 | - |
|
1390 | - return true; |
|
1391 | - } |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * Create the <option> of an html select |
|
1395 | - * |
|
1396 | - * @param array $array Array of index and labels |
|
1397 | - * @param mixed $default the default value |
|
1398 | - * @param bool $withNull |
|
1399 | - * @return string |
|
1400 | - */ |
|
1401 | - private static function htmlSelectOptions($array, $default = 0, $withNull = true) |
|
1402 | - { |
|
1403 | - $ret = array(); |
|
1404 | - $selected = ''; |
|
1405 | - if ($withNull) { |
|
1406 | - if (!is_array($default)) { |
|
1407 | - if ($default === 0) { |
|
1408 | - $selected = " selected = 'selected'"; |
|
1409 | - } |
|
1410 | - } else { |
|
1411 | - if (in_array(0, $default)) { |
|
1412 | - $selected = " selected = 'selected'"; |
|
1413 | - } |
|
1414 | - } |
|
1415 | - $ret[] = '<option value=0' . $selected . '>---</option>'; |
|
1416 | - } |
|
1417 | - |
|
1418 | - foreach ($array as $index => $label) { |
|
1419 | - $selected = ''; |
|
1420 | - if (!is_array($default)) { |
|
1421 | - if ($index == $default) { |
|
1422 | - $selected = " selected = 'selected'"; |
|
1423 | - } |
|
1424 | - } else { |
|
1425 | - if (in_array($index, $default)) { |
|
1426 | - $selected = " selected = 'selected'"; |
|
1427 | - } |
|
1428 | - } |
|
1429 | - $ret[] = "<option value=\"" . $index . "\"" . $selected . '>' . $label . '</option>'; |
|
1430 | - } |
|
1431 | - |
|
1432 | - return implode("\n", $ret); |
|
1433 | - } |
|
1434 | - |
|
1435 | - /** |
|
1436 | - * Creates an html select an returns its code |
|
1437 | - * |
|
1438 | - * @param string $selectName Select's name |
|
1439 | - * @param array $array Key = value of each option, value = label of each option |
|
1440 | - * @param mixed $default Default's value |
|
1441 | - * @param boolean $withNull Do we want a null option |
|
1442 | - * @param string $style Is there a style to apply ? |
|
1443 | - * @param boolean $multiple Can we select multiple elements ? |
|
1444 | - * @param integer $size Size of the selectbox, only used with multiple selectboxes |
|
1445 | - * @param string $extra |
|
1446 | - * @return string |
|
1447 | - */ |
|
1448 | - public static function htmlSelect($selectName, $array, $default, $withNull = true, $style = '', $multiple = false, $size = 1, $extra = '') |
|
1449 | - { |
|
1450 | - $ret = ''; |
|
1451 | - $ret .= "<select name='" . $selectName . "' id='" . $selectName . "'"; |
|
1452 | - if (xoops_trim($style) != '') { |
|
1453 | - $ret .= " style='" . $style . "' "; |
|
1454 | - } |
|
1455 | - if (xoops_trim($multiple) != '') { |
|
1456 | - $ret .= " multiple = 'multiple' size='" . $size . "' "; |
|
1457 | - } |
|
1458 | - $ret .= $extra . ">\n"; |
|
1459 | - $ret .= self::htmlSelectOptions($array, $default, $withNull); |
|
1460 | - $ret .= "</select>\n"; |
|
1461 | - |
|
1462 | - return $ret; |
|
1463 | - } |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * Verify that a mysql table exists |
|
1467 | - * @param $tablename |
|
1468 | - * @return bool |
|
1469 | - */ |
|
1470 | - public static function tableExists($tablename) |
|
1471 | - { |
|
1472 | - global $xoopsDB; |
|
1473 | - $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
|
1474 | - |
|
1475 | - return ($xoopsDB->getRowsNum($result) > 0); |
|
1476 | - } |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * Verify that a field exists inside a mysql table |
|
1480 | - * @param $fieldname |
|
1481 | - * @param $table |
|
1482 | - * @return bool |
|
1483 | - */ |
|
1484 | - public static function fieldExists($fieldname, $table) |
|
1485 | - { |
|
1486 | - global $xoopsDB; |
|
1487 | - $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
1488 | - |
|
1489 | - return ($xoopsDB->getRowsNum($result) > 0); |
|
1490 | - } |
|
1491 | - |
|
1492 | - /** |
|
1493 | - * Retourne la définition d'un champ |
|
1494 | - * |
|
1495 | - * @param string $fieldname |
|
1496 | - * @param string $table |
|
1497 | - * @return array |
|
1498 | - */ |
|
1499 | - public static function getFieldDefinition($fieldname, $table) |
|
1500 | - { |
|
1501 | - global $xoopsDB; |
|
1502 | - $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
1503 | - if ($result) { |
|
1504 | - return $xoopsDB->fetchArray($result); |
|
1505 | - } |
|
1506 | - |
|
1507 | - return ''; |
|
1508 | - } |
|
1509 | - |
|
1510 | - /** |
|
1511 | - * Add a field to a mysql table |
|
1512 | - * @param $field |
|
1513 | - * @param $table |
|
1514 | - * @return resource |
|
1515 | - */ |
|
1516 | - public static function addField($field, $table) |
|
1517 | - { |
|
1518 | - global $xoopsDB; |
|
1519 | - $result = $xoopsDB->queryF("ALTER TABLE $table ADD $field;"); |
|
1520 | - |
|
1521 | - return $result; |
|
1522 | - } |
|
1523 | - |
|
1524 | - /** |
|
1525 | - * Maintenance des tables du module et de son cache de requêtes |
|
1526 | - * |
|
1527 | - * @return void |
|
1528 | - */ |
|
1529 | - public static function maintainTablesCache() |
|
1530 | - { |
|
1531 | - global $xoopsDB; |
|
1532 | - define('REFERENCES_MAINTAIN', true); |
|
1533 | - require self::MODULE_PATH . 'xoops_version.php'; |
|
1534 | - $tables = array(); |
|
1535 | - foreach ($modversion['tables'] as $table) { |
|
1536 | - $tables[] = $xoopsDB->prefix($table); |
|
1537 | - } |
|
1538 | - if (count($tables) > 0) { |
|
1539 | - $list = implode(',', $tables); |
|
1540 | - $xoopsDB->queryF('CHECK TABLE ' . $list); |
|
1541 | - $xoopsDB->queryF('ANALYZE TABLE ' . $list); |
|
1542 | - $xoopsDB->queryF('OPTIMIZE TABLE ' . $list); |
|
1543 | - } |
|
1544 | - self::updateCache(); |
|
1545 | - $handlers = references_handler::getInstance(); |
|
1546 | - $handlers->h_references_articles->forceCacheClean(); |
|
1547 | - } |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Indique si le module Tag existe et est activé |
|
1551 | - * |
|
1552 | - * @return boolean |
|
1553 | - * @credit: smartfactory |
|
1554 | - */ |
|
1555 | - public static function tagModuleExists() |
|
1556 | - { |
|
1557 | - static $moduleExistsAndIsActive; |
|
1558 | - if (!isset($moduleExistsAndIsActive)) { |
|
1559 | - $modules_handler = xoops_getHandler('module'); |
|
1560 | - $tagModule = $modules_handler->getByDirName('tag'); |
|
1561 | - if (!$tagModule) { |
|
1562 | - $moduleExistsAndIsActive = false; |
|
1563 | - } else { |
|
1564 | - $moduleExistsAndIsActive = $tagModule->getVar('isactive') == 1; |
|
1565 | - } |
|
1566 | - } |
|
1567 | - |
|
1568 | - return $moduleExistsAndIsActive; |
|
1569 | - } |
|
809 | + $chaine = str_replace($search, $replace, $chaine); |
|
810 | + |
|
811 | + return $chaine; |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * Création d'une titre pour être utilisé par l'url rewriting |
|
816 | + * |
|
817 | + * @param string $content Le texte à utiliser pour créer l'url |
|
818 | + * @param integer $urw La limite basse pour créer les mots |
|
819 | + * @return string Le texte à utiliser pour l'url |
|
820 | + * Note, some parts are from Solo's code |
|
821 | + */ |
|
822 | + public static function makeSeoUrl($content, $urw = 1) |
|
823 | + { |
|
824 | + $s = "ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÇÌÍÎÏÙÚÛÜŸÑàáâãäåòóôõöøèéêëçìíîïùúûüÿñ '()"; |
|
825 | + $r = 'AAAAAAOOOOOOEEEECIIIIUUUUYNaaaaaaooooooeeeeciiiiuuuuyn----'; |
|
826 | + $content = self::unhtml($content); // First, remove html entities |
|
827 | + $content = strtr($content, $s, $r); |
|
828 | + $content = strip_tags($content); |
|
829 | + $content = strtolower($content); |
|
830 | + $content = htmlentities($content); // TODO: Vérifier |
|
831 | + $content = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $content); |
|
832 | + $content = html_entity_decode($content); |
|
833 | + $content = eregi_replace('quot', ' ', $content); |
|
834 | + $content = eregi_replace("'", ' ', $content); |
|
835 | + $content = eregi_replace('-', ' ', $content); |
|
836 | + $content = eregi_replace('[[:punct:]]', '', $content); |
|
837 | + // Selon option mais attention au fichier .htaccess ! |
|
838 | + // $content = eregi_replace('[[:digit:]]','', $content); |
|
839 | + $content = preg_replace('/[^a-z|A-Z|0-9]/', '-', $content); |
|
840 | + |
|
841 | + $words = explode(' ', $content); |
|
842 | + $keywords = ''; |
|
843 | + foreach ($words as $word) { |
|
844 | + if (strlen($word) >= $urw) { |
|
845 | + $keywords .= '-' . trim($word); |
|
846 | + } |
|
847 | + } |
|
848 | + if (!$keywords) { |
|
849 | + $keywords = '-'; |
|
850 | + } |
|
851 | + // Supprime les tirets en double |
|
852 | + $keywords = str_replace('---', '-', $keywords); |
|
853 | + $keywords = str_replace('--', '-', $keywords); |
|
854 | + // Supprime un éventuel tiret à la fin de la chaine |
|
855 | + if (substr($keywords, strlen($keywords) - 1, 1) == '-') { |
|
856 | + $keywords = substr($keywords, 0, strlen($keywords) - 1); |
|
857 | + } |
|
858 | + |
|
859 | + return $keywords; |
|
860 | + } |
|
861 | + |
|
862 | + /** |
|
863 | + * Create the meta keywords based on the content |
|
864 | + * |
|
865 | + * @param string $content Content from which we have to create metakeywords |
|
866 | + * @return string The list of meta keywords |
|
867 | + */ |
|
868 | + public static function createMetaKeywords($content) |
|
869 | + { |
|
870 | + $keywordscount = REFERENCES_METAGEN_MAX_KEYWORDS; |
|
871 | + $keywordsorder = REFERENCES_METAGEN_KEYWORDS_ORDER; |
|
872 | + |
|
873 | + $tmp = array(); |
|
874 | + // Search for the "Minimum keyword length" |
|
875 | + // TODO: Remplacer references_keywords_limit par une constante |
|
876 | + if (isset($_SESSION['references_keywords_limit'])) { |
|
877 | + $limit = $_SESSION['references_keywords_limit']; |
|
878 | + } else { |
|
879 | + $config_handler = xoops_getHandler('config'); |
|
880 | + $xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
|
881 | + $limit = $xoopsConfigSearch['keyword_min']; |
|
882 | + $_SESSION['references_keywords_limit'] = $limit; |
|
883 | + } |
|
884 | + $myts = MyTextSanitizer::getInstance(); |
|
885 | + $content = str_replace('<br>', ' ', $content); |
|
886 | + $content = $myts->undoHtmlSpecialChars($content); |
|
887 | + $content = strip_tags($content); |
|
888 | + $content = strtolower($content); |
|
889 | + $search_pattern = array(' ', "\t", "\r\n", "\r", "\n", ',', '.', "'", ';', ':', ')', '(', '"', '?', '!', '{', '}', '[', ']', '<', '>', '/', '+', '-', '_', '\\', '*'); |
|
890 | + $replace_pattern = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); |
|
891 | + $content = str_replace($search_pattern, $replace_pattern, $content); |
|
892 | + $keywords = explode(' ', $content); |
|
893 | + switch ($keywordsorder) { |
|
894 | + case 0: // Ordre d'apparition dans le texte |
|
895 | + $keywords = array_unique($keywords); |
|
896 | + break; |
|
897 | + case 1: // Ordre de fréquence des mots |
|
898 | + $keywords = array_count_values($keywords); |
|
899 | + asort($keywords); |
|
900 | + $keywords = array_keys($keywords); |
|
901 | + break; |
|
902 | + case 2: // Ordre inverse de la fréquence des mots |
|
903 | + $keywords = array_count_values($keywords); |
|
904 | + arsort($keywords); |
|
905 | + $keywords = array_keys($keywords); |
|
906 | + break; |
|
907 | + } |
|
908 | + // Remove black listed words |
|
909 | + if (xoops_trim(self::getModuleOption('metagen_blacklist')) != '') { |
|
910 | + $metagen_blacklist = str_replace("\r", '', self::getModuleOption('metagen_blacklist')); |
|
911 | + $metablack = explode("\n", $metagen_blacklist); |
|
912 | + array_walk($metablack, 'trim'); |
|
913 | + $keywords = array_diff($keywords, $metablack); |
|
914 | + } |
|
915 | + |
|
916 | + foreach ($keywords as $keyword) { |
|
917 | + if (strlen($keyword) >= $limit && !is_numeric($keyword)) { |
|
918 | + $tmp[] = $keyword; |
|
919 | + } |
|
920 | + } |
|
921 | + $tmp = array_slice($tmp, 0, $keywordscount); |
|
922 | + if (count($tmp) > 0) { |
|
923 | + return implode(',', $tmp); |
|
924 | + } else { |
|
925 | + if (!isset($config_handler) || !is_object($config_handler)) { |
|
926 | + $config_handler = xoops_getHandler('config'); |
|
927 | + } |
|
928 | + $xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
|
929 | + if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
|
930 | + return $xoopsConfigMetaFooter['meta_keywords']; |
|
931 | + } else { |
|
932 | + return ''; |
|
933 | + } |
|
934 | + } |
|
935 | + } |
|
936 | + |
|
937 | + /** |
|
938 | + * Fonction chargée de gérer l'upload |
|
939 | + * |
|
940 | + * @param integer $indice L'indice du fichier à télécharger |
|
941 | + * @param string $dstpath |
|
942 | + * @param null $mimeTypes |
|
943 | + * @param null $uploadMaxSize |
|
944 | + * @param null $maxWidth |
|
945 | + * @param null $maxHeight |
|
946 | + * @return mixed True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
|
947 | + */ |
|
948 | + public static function uploadFile($indice, $dstpath = XOOPS_UPLOAD_PATH, $mimeTypes = null, $uploadMaxSize = null, $maxWidth = null, $maxHeight = null) |
|
949 | + { |
|
950 | + require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
951 | + global $destname; |
|
952 | + if (isset($_POST['xoops_upload_file'])) { |
|
953 | + require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
954 | + $fldname = ''; |
|
955 | + $fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
|
956 | + $fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; |
|
957 | + if (xoops_trim($fldname != '')) { |
|
958 | + $destname = self::createUploadName($dstpath, $fldname, true); |
|
959 | + if ($mimeTypes === null) { |
|
960 | + $permittedtypes = explode("\n", str_replace("\r", '', self::getModuleOption('mimetypes'))); |
|
961 | + array_walk($permittedtypes, 'trim'); |
|
962 | + } else { |
|
963 | + $permittedtypes = $mimeTypes; |
|
964 | + } |
|
965 | + if ($uploadMaxSize === null) { |
|
966 | + $uploadSize = self::getModuleOption('maxuploadsize'); |
|
967 | + } else { |
|
968 | + $uploadSize = $uploadMaxSize; |
|
969 | + } |
|
970 | + $uploader = new XoopsMediaUploader($dstpath, $permittedtypes, $uploadSize, $maxWidth, $maxHeight); |
|
971 | + //$uploader->allowUnknownTypes = true; |
|
972 | + $uploader->setTargetFileName($destname); |
|
973 | + if ($uploader->fetchMedia($_POST['xoops_upload_file'][$indice])) { |
|
974 | + if ($uploader->upload()) { |
|
975 | + return true; |
|
976 | + } else { |
|
977 | + return _ERRORS . ' ' . htmlentities($uploader->getErrors()); |
|
978 | + } |
|
979 | + } else { |
|
980 | + return htmlentities($uploader->getErrors()); |
|
981 | + } |
|
982 | + } else { |
|
983 | + return false; |
|
984 | + } |
|
985 | + } else { |
|
986 | + return false; |
|
987 | + } |
|
988 | + } |
|
989 | + |
|
990 | + /** |
|
991 | + * Resize a Picture to some given dimensions (using the wideImage library) |
|
992 | + * |
|
993 | + * @param string $src_path Picture's source |
|
994 | + * @param string $dst_path Picture's destination |
|
995 | + * @param integer $param_width Maximum picture's width |
|
996 | + * @param integer $param_height Maximum picture's height |
|
997 | + * @param boolean $keep_original Do we have to keep the original picture ? |
|
998 | + * @param string $fit Resize mode (see the wideImage library for more information) |
|
999 | + * @return bool |
|
1000 | + */ |
|
1001 | + public static function resizePicture($src_path, $dst_path, $param_width, $param_height, $keep_original = false, $fit = 'inside') |
|
1002 | + { |
|
1003 | + // require_once self::MODULE_PATH . 'class/wideimage/WideImage.php'; |
|
1004 | + $img = WideImage::load($src_path); |
|
1005 | + $result = $img->resize($param_width, $param_height, $fit); |
|
1006 | + $result->saveToFile($dst_path, null); |
|
1007 | + if (!$keep_original) { |
|
1008 | + @unlink($src_path); |
|
1009 | + } |
|
1010 | + |
|
1011 | + return true; |
|
1012 | + } |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * Déclenchement d'une alerte Xoops suite à un évènement |
|
1016 | + * |
|
1017 | + * @param string $category La catégorie de l'évènement |
|
1018 | + * @param integer $itemId L'ID de l'élément (trop général pour être décris précisément) |
|
1019 | + * @param unknown_type $event L'évènement qui est déclencé |
|
1020 | + * @param unknown_type $tags Les variables à passer au template |
|
1021 | + */ |
|
1022 | + public static function notify($category, $itemId, $event, $tags) |
|
1023 | + { |
|
1024 | + $notification_handler = xoops_getHandler('notification'); |
|
1025 | + $tags['X_MODULE_URL'] = REFERENCES_URL; |
|
1026 | + $notification_handler->triggerEvent($category, $itemId, $event, $tags); |
|
1027 | + } |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * Ajoute des jours à une date et retourne la nouvelle date au format Date de Mysql |
|
1031 | + * |
|
1032 | + * @param int $duration |
|
1033 | + * @param integer $startingDate Date de départ (timestamp) |
|
1034 | + * @return bool|string |
|
1035 | + * @internal param int $durations Durée en jours |
|
1036 | + */ |
|
1037 | + public static function addDaysToDate($duration = 1, $startingDate = 0) |
|
1038 | + { |
|
1039 | + if ($startingDate == 0) { |
|
1040 | + $startingDate = time(); |
|
1041 | + } |
|
1042 | + $endingDate = $startingDate + ($duration * 86400); |
|
1043 | + |
|
1044 | + return date('Y-m-d', $endingDate); |
|
1045 | + } |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * Retourne un breadcrumb en fonction des paramètres passés et en partant (d'office) de la racine du module |
|
1049 | + * |
|
1050 | + * @param array $path Le chemin complet (excepté la racine) du breadcrumb sous la forme clé=url valeur=titre |
|
1051 | + * @param string $raquo Le séparateur par défaut à utiliser |
|
1052 | + * @return string le breadcrumb |
|
1053 | + */ |
|
1054 | + public static function breadcrumb($path, $raquo = ' » ') |
|
1055 | + { |
|
1056 | + $breadcrumb = ''; |
|
1057 | + $workingBreadcrumb = array(); |
|
1058 | + if (is_array($path)) { |
|
1059 | + $moduleName = self::getModuleName(); |
|
1060 | + $workingBreadcrumb[] = "<a href='" . REFERENCES_URL . "' title='" . self::makeHrefTitle($moduleName) . "'>" . $moduleName . '</a>'; |
|
1061 | + foreach ($path as $url => $title) { |
|
1062 | + $workingBreadcrumb[] = "<a href='" . $url . "'>" . $title . '</a>'; |
|
1063 | + } |
|
1064 | + $cnt = count($workingBreadcrumb); |
|
1065 | + for ($i = 0; $i < $cnt; ++$i) { |
|
1066 | + if ($i == $cnt - 1) { |
|
1067 | + $workingBreadcrumb[$i] = strip_tags($workingBreadcrumb[$i]); |
|
1068 | + } |
|
1069 | + } |
|
1070 | + $breadcrumb = implode($raquo, $workingBreadcrumb); |
|
1071 | + } |
|
1072 | + |
|
1073 | + return $breadcrumb; |
|
1074 | + } |
|
1075 | + |
|
1076 | + public static function close_tags($string) |
|
1077 | + { |
|
1078 | + // match opened tags |
|
1079 | + if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
|
1080 | + $start_tags = $start_tags[1]; |
|
1081 | + |
|
1082 | + // match closed tags |
|
1083 | + if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
|
1084 | + $complete_tags = array(); |
|
1085 | + $end_tags = $end_tags[1]; |
|
1086 | + |
|
1087 | + foreach ($start_tags as $key => $val) { |
|
1088 | + $posb = array_search($val, $end_tags); |
|
1089 | + if (is_int($posb)) { |
|
1090 | + unset($end_tags[$posb]); |
|
1091 | + } else { |
|
1092 | + $complete_tags[] = $val; |
|
1093 | + } |
|
1094 | + } |
|
1095 | + } else { |
|
1096 | + $complete_tags = $start_tags; |
|
1097 | + } |
|
1098 | + |
|
1099 | + $complete_tags = array_reverse($complete_tags); |
|
1100 | + for ($i = 0; $i < count($complete_tags); ++$i) { |
|
1101 | + $string .= '</' . $complete_tags[$i] . '>'; |
|
1102 | + } |
|
1103 | + } |
|
1104 | + |
|
1105 | + return $string; |
|
1106 | + } |
|
1107 | + |
|
1108 | + public static function truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) |
|
1109 | + { |
|
1110 | + if ($length == 0) { |
|
1111 | + return ''; |
|
1112 | + } |
|
1113 | + |
|
1114 | + if (strlen($string) > $length) { |
|
1115 | + $length -= strlen($etc); |
|
1116 | + if (!$break_words) { |
|
1117 | + $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); |
|
1118 | + $string = preg_replace('/<[^>]*$/', '', $string); |
|
1119 | + $string = self::close_tags($string); |
|
1120 | + } |
|
1121 | + |
|
1122 | + return $string . $etc; |
|
1123 | + } else { |
|
1124 | + return $string; |
|
1125 | + } |
|
1126 | + } |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * Create an infotip |
|
1130 | + * @param $text |
|
1131 | + * @return string |
|
1132 | + */ |
|
1133 | + public static function makeInfotips($text) |
|
1134 | + { |
|
1135 | + $ret = ''; |
|
1136 | + $infotips = self::getModuleOption('infotips'); |
|
1137 | + if ($infotips > 0) { |
|
1138 | + $myts = MyTextSanitizer::getInstance(); |
|
1139 | + $ret = $myts->htmlSpecialChars(substr(strip_tags($text), 0, $infotips)); |
|
1140 | + } |
|
1141 | + |
|
1142 | + return $ret; |
|
1143 | + } |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * Retourne le type Mime d'un fichier en utilisant d'abord finfo puis mime_content |
|
1147 | + * |
|
1148 | + * @param string $filename Le fichier (avec son chemin d'accès complet) dont on veut connaître le type mime |
|
1149 | + * @return string |
|
1150 | + */ |
|
1151 | + public static function getMimeType($filename) |
|
1152 | + { |
|
1153 | + if (function_exists('finfo_open')) { |
|
1154 | + $pathToMagic = REFERENCES_PATH . 'mime/magic'; |
|
1155 | + $finfo = new finfo(FILEINFO_MIME, $pathToMagic); |
|
1156 | + $mimetype = $finfo->file($filename); |
|
1157 | + finfo_close($finfo); |
|
1158 | + unset($finfo); |
|
1159 | + |
|
1160 | + return $mimetype; |
|
1161 | + } else { |
|
1162 | + if (function_exists('mime_content_type')) { |
|
1163 | + return mime_content_type($filename); |
|
1164 | + } else { |
|
1165 | + return ''; |
|
1166 | + } |
|
1167 | + } |
|
1168 | + } |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * Retourne une liste d'objets XoopsUsers à partir d'une liste d'identifiants |
|
1172 | + * |
|
1173 | + * @param array $xoopsUsersIDs La liste des ID |
|
1174 | + * @return array Les objets XoopsUsers |
|
1175 | + */ |
|
1176 | + public static function getUsersFromIds($xoopsUsersIDs) |
|
1177 | + { |
|
1178 | + $users = array(); |
|
1179 | + if (is_array($xoopsUsersIDs) && count($xoopsUsersIDs) > 0) { |
|
1180 | + $xoopsUsersIDs = array_unique($xoopsUsersIDs); |
|
1181 | + sort($xoopsUsersIDs); |
|
1182 | + if (count($xoopsUsersIDs) > 0) { |
|
1183 | + $member_handler = xoops_getHandler('user'); |
|
1184 | + $criteria = new Criteria('uid', '(' . implode(',', $xoopsUsersIDs) . ')', 'IN'); |
|
1185 | + $criteria->setSort('uid'); |
|
1186 | + $users = $member_handler->getObjects($criteria, true); |
|
1187 | + } |
|
1188 | + } |
|
1189 | + |
|
1190 | + return $users; |
|
1191 | + } |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * Retourne l'ID de l'utilisateur courant (s'il est connecté) |
|
1195 | + * @return integer L'uid ou 0 |
|
1196 | + */ |
|
1197 | + public static function getCurrentUserID() |
|
1198 | + { |
|
1199 | + global $xoopsUser; |
|
1200 | + $uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
|
1201 | + |
|
1202 | + return $uid; |
|
1203 | + } |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * Retourne la liste des groupes de l'utilisateur courant (avec cache) |
|
1207 | + * @param int $uid |
|
1208 | + * @return array Les ID des groupes auquel l'utilisateur courant appartient |
|
1209 | + */ |
|
1210 | + public static function getMemberGroups($uid = 0) |
|
1211 | + { |
|
1212 | + static $buffer = array(); |
|
1213 | + if ($uid == 0) { |
|
1214 | + $uid = self::getCurrentUserID(); |
|
1215 | + } |
|
1216 | + |
|
1217 | + if (is_array($buffer) && count($buffer) > 0 && isset($buffer[$uid])) { |
|
1218 | + return $buffer[$uid]; |
|
1219 | + } else { |
|
1220 | + if ($uid > 0) { |
|
1221 | + $member_handler = xoops_getHandler('member'); |
|
1222 | + $buffer[$uid] = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1223 | + } else { |
|
1224 | + $buffer[$uid] = array(XOOPS_GROUP_ANONYMOUS); |
|
1225 | + } |
|
1226 | + } |
|
1227 | + |
|
1228 | + return $buffer[$uid]; |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * Indique si l'utilisateur courant fait partie d'une groupe donné (avec gestion de cache) |
|
1233 | + * |
|
1234 | + * @param integer $group Groupe recherché |
|
1235 | + * @param int $uid |
|
1236 | + * @return bool vrai si l'utilisateur fait partie du groupe, faux sinon |
|
1237 | + */ |
|
1238 | + public static function isMemberOfGroup($group = 0, $uid = 0) |
|
1239 | + { |
|
1240 | + static $buffer = array(); |
|
1241 | + $retval = false; |
|
1242 | + if ($uid == 0) { |
|
1243 | + $uid = self::getCurrentUserID(); |
|
1244 | + } |
|
1245 | + if (is_array($buffer) && array_key_exists($group, $buffer)) { |
|
1246 | + $retval = $buffer[$group]; |
|
1247 | + } else { |
|
1248 | + $member_handler = xoops_getHandler('member'); |
|
1249 | + $groups = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1250 | + $retval = in_array($group, $groups); |
|
1251 | + $buffer[$group] = $retval; |
|
1252 | + } |
|
1253 | + |
|
1254 | + return $retval; |
|
1255 | + } |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * Indique si un utilisateur fait partie de plusieurs groupes |
|
1259 | + * La fonction renvoie vrai dès qu'on trouve que le membre fait partir d'un des groupes |
|
1260 | + * @param array $groups La liste des groupes à vérifier |
|
1261 | + * @param integer $uid L'ID de l'utilisateur |
|
1262 | + * @return boolean |
|
1263 | + */ |
|
1264 | + public static function isMemberOfGroups($groups, $uid = 0) |
|
1265 | + { |
|
1266 | + if (count($groups) == 0) { |
|
1267 | + return false; |
|
1268 | + } |
|
1269 | + if ($uid == 0) { |
|
1270 | + $uid = self::getCurrentUserID(); |
|
1271 | + } |
|
1272 | + foreach ($groups as $groupId) { |
|
1273 | + if (self::isMemberOfGroup($groupId, $uid)) { |
|
1274 | + return true; |
|
1275 | + } |
|
1276 | + } |
|
1277 | + |
|
1278 | + return false; |
|
1279 | + } |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * Retourne le nombre total de groupes (y compris les anonymes) |
|
1283 | + */ |
|
1284 | + public static function getGroupsCount() |
|
1285 | + { |
|
1286 | + static $cache = -1; |
|
1287 | + if ($cache == -1) { |
|
1288 | + global $xoopsDB; |
|
1289 | + $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('groups'); |
|
1290 | + $result = $xoopsDB->query($sql); |
|
1291 | + if (!$result) { |
|
1292 | + return false; |
|
1293 | + } |
|
1294 | + list($cache) = $xoopsDB->fetchRow($result); |
|
1295 | + } |
|
1296 | + |
|
1297 | + return $cache; |
|
1298 | + } |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * Fonction chargée de vérifier qu'un répertoire existe, qu'on peut écrire dedans et création d'un fichier index.html |
|
1302 | + * |
|
1303 | + * @param string $folder Le chemin complet du répertoire à vérifier |
|
1304 | + * @return void |
|
1305 | + */ |
|
1306 | + public static function prepareFolder($folder) |
|
1307 | + { |
|
1308 | + if (!is_dir($folder)) { |
|
1309 | + mkdir($folder, 0777); |
|
1310 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
1311 | + } else { |
|
1312 | + if (!is_writable($folder)) { |
|
1313 | + chmod($folder, 0777); |
|
1314 | + } |
|
1315 | + } |
|
1316 | + } |
|
1317 | + |
|
1318 | + /** |
|
1319 | + * Load a language file |
|
1320 | + * |
|
1321 | + * @param string $languageFile The required language file |
|
1322 | + * @param string $defaultExtension Default extension to use |
|
1323 | + */ |
|
1324 | + public static function loadLanguageFile($languageFile, $defaultExtension = '.php') |
|
1325 | + { |
|
1326 | + global $xoopsConfig; |
|
1327 | + $root = self::MODULE_PATH; |
|
1328 | + if (strstr($languageFile, $defaultExtension) === false) { |
|
1329 | + $languageFile .= $defaultExtension; |
|
1330 | + } |
|
1331 | + if (file_exists($root . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . $languageFile)) { |
|
1332 | + require_once $root . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . $languageFile; |
|
1333 | + } else { // Fallback |
|
1334 | + require_once $root . 'language' . DIRECTORY_SEPARATOR . 'english' . DIRECTORY_SEPARATOR . $languageFile; |
|
1335 | + } |
|
1336 | + } |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * Création d'une vignette en tenant compte des options du module concernant le mode de création des vignettes |
|
1340 | + * |
|
1341 | + * @param string $src_path |
|
1342 | + * @param string $dst_path |
|
1343 | + * @param integer $param_width |
|
1344 | + * @param integer $param_height |
|
1345 | + * @param boolean $keep_original |
|
1346 | + * @param string $fit Utilisé uniquement pour la méthode 0 (redimensionnement) |
|
1347 | + * @return boolean |
|
1348 | + */ |
|
1349 | + public static function createThumb($src_path, $dst_path, $param_width, $param_height, $keep_original = false, $fit = 'inside') |
|
1350 | + { |
|
1351 | + // require_once self::MODULE_PATH . 'class/wideimage/WideImage.php'; |
|
1352 | + $resize = true; |
|
1353 | + // On commence par vérifier que l'image originale n'est pas plus petite que les dimensions demandées auquel cas il n'y a rien à faire |
|
1354 | + $pictureDimensions = getimagesize($src_path); |
|
1355 | + if (is_array($pictureDimensions)) { |
|
1356 | + $pictureWidth = $pictureDimensions[0]; |
|
1357 | + $pictureHeight = $pictureDimensions[1]; |
|
1358 | + if ($pictureWidth < $param_width && $pictureHeight < $param_height) { |
|
1359 | + $resize = false; |
|
1360 | + } |
|
1361 | + } |
|
1362 | + $img = WideImage::load($src_path); |
|
1363 | + if ($resize) { // L'image est suffisament grande pour être réduite |
|
1364 | + $thumbMethod = 0; |
|
1365 | + if ($thumbMethod == 0) { // Redimensionnement de l'image |
|
1366 | + $result = $img->resize($param_width, $param_height, $fit); |
|
1367 | + } else { // Récupération d'une partie de l'image depuis le centre |
|
1368 | + // Calcul de left et top |
|
1369 | + $left = $top = 0; |
|
1370 | + if (is_array($pictureDimensions)) { |
|
1371 | + if ($pictureWidth > $param_width) { |
|
1372 | + $left = (int)(($pictureWidth / 2) - ($param_width / 2)); |
|
1373 | + } |
|
1374 | + if ($pictureHeight > $param_height) { |
|
1375 | + $top = (int)(($pictureHeight / 2) - ($param_height / 2)); |
|
1376 | + } |
|
1377 | + } |
|
1378 | + $result = $img->crop($left, $top, $param_width, $param_height); |
|
1379 | + } |
|
1380 | + $result->saveToFile($dst_path, null); |
|
1381 | + } else { |
|
1382 | + if ($src_path != $dst_path) { |
|
1383 | + @copy($src_path, $dst_path); |
|
1384 | + } |
|
1385 | + } |
|
1386 | + if (!$keep_original) { |
|
1387 | + @unlink($src_path); |
|
1388 | + } |
|
1389 | + |
|
1390 | + return true; |
|
1391 | + } |
|
1392 | + |
|
1393 | + /** |
|
1394 | + * Create the <option> of an html select |
|
1395 | + * |
|
1396 | + * @param array $array Array of index and labels |
|
1397 | + * @param mixed $default the default value |
|
1398 | + * @param bool $withNull |
|
1399 | + * @return string |
|
1400 | + */ |
|
1401 | + private static function htmlSelectOptions($array, $default = 0, $withNull = true) |
|
1402 | + { |
|
1403 | + $ret = array(); |
|
1404 | + $selected = ''; |
|
1405 | + if ($withNull) { |
|
1406 | + if (!is_array($default)) { |
|
1407 | + if ($default === 0) { |
|
1408 | + $selected = " selected = 'selected'"; |
|
1409 | + } |
|
1410 | + } else { |
|
1411 | + if (in_array(0, $default)) { |
|
1412 | + $selected = " selected = 'selected'"; |
|
1413 | + } |
|
1414 | + } |
|
1415 | + $ret[] = '<option value=0' . $selected . '>---</option>'; |
|
1416 | + } |
|
1417 | + |
|
1418 | + foreach ($array as $index => $label) { |
|
1419 | + $selected = ''; |
|
1420 | + if (!is_array($default)) { |
|
1421 | + if ($index == $default) { |
|
1422 | + $selected = " selected = 'selected'"; |
|
1423 | + } |
|
1424 | + } else { |
|
1425 | + if (in_array($index, $default)) { |
|
1426 | + $selected = " selected = 'selected'"; |
|
1427 | + } |
|
1428 | + } |
|
1429 | + $ret[] = "<option value=\"" . $index . "\"" . $selected . '>' . $label . '</option>'; |
|
1430 | + } |
|
1431 | + |
|
1432 | + return implode("\n", $ret); |
|
1433 | + } |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * Creates an html select an returns its code |
|
1437 | + * |
|
1438 | + * @param string $selectName Select's name |
|
1439 | + * @param array $array Key = value of each option, value = label of each option |
|
1440 | + * @param mixed $default Default's value |
|
1441 | + * @param boolean $withNull Do we want a null option |
|
1442 | + * @param string $style Is there a style to apply ? |
|
1443 | + * @param boolean $multiple Can we select multiple elements ? |
|
1444 | + * @param integer $size Size of the selectbox, only used with multiple selectboxes |
|
1445 | + * @param string $extra |
|
1446 | + * @return string |
|
1447 | + */ |
|
1448 | + public static function htmlSelect($selectName, $array, $default, $withNull = true, $style = '', $multiple = false, $size = 1, $extra = '') |
|
1449 | + { |
|
1450 | + $ret = ''; |
|
1451 | + $ret .= "<select name='" . $selectName . "' id='" . $selectName . "'"; |
|
1452 | + if (xoops_trim($style) != '') { |
|
1453 | + $ret .= " style='" . $style . "' "; |
|
1454 | + } |
|
1455 | + if (xoops_trim($multiple) != '') { |
|
1456 | + $ret .= " multiple = 'multiple' size='" . $size . "' "; |
|
1457 | + } |
|
1458 | + $ret .= $extra . ">\n"; |
|
1459 | + $ret .= self::htmlSelectOptions($array, $default, $withNull); |
|
1460 | + $ret .= "</select>\n"; |
|
1461 | + |
|
1462 | + return $ret; |
|
1463 | + } |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * Verify that a mysql table exists |
|
1467 | + * @param $tablename |
|
1468 | + * @return bool |
|
1469 | + */ |
|
1470 | + public static function tableExists($tablename) |
|
1471 | + { |
|
1472 | + global $xoopsDB; |
|
1473 | + $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
|
1474 | + |
|
1475 | + return ($xoopsDB->getRowsNum($result) > 0); |
|
1476 | + } |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * Verify that a field exists inside a mysql table |
|
1480 | + * @param $fieldname |
|
1481 | + * @param $table |
|
1482 | + * @return bool |
|
1483 | + */ |
|
1484 | + public static function fieldExists($fieldname, $table) |
|
1485 | + { |
|
1486 | + global $xoopsDB; |
|
1487 | + $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
1488 | + |
|
1489 | + return ($xoopsDB->getRowsNum($result) > 0); |
|
1490 | + } |
|
1491 | + |
|
1492 | + /** |
|
1493 | + * Retourne la définition d'un champ |
|
1494 | + * |
|
1495 | + * @param string $fieldname |
|
1496 | + * @param string $table |
|
1497 | + * @return array |
|
1498 | + */ |
|
1499 | + public static function getFieldDefinition($fieldname, $table) |
|
1500 | + { |
|
1501 | + global $xoopsDB; |
|
1502 | + $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
1503 | + if ($result) { |
|
1504 | + return $xoopsDB->fetchArray($result); |
|
1505 | + } |
|
1506 | + |
|
1507 | + return ''; |
|
1508 | + } |
|
1509 | + |
|
1510 | + /** |
|
1511 | + * Add a field to a mysql table |
|
1512 | + * @param $field |
|
1513 | + * @param $table |
|
1514 | + * @return resource |
|
1515 | + */ |
|
1516 | + public static function addField($field, $table) |
|
1517 | + { |
|
1518 | + global $xoopsDB; |
|
1519 | + $result = $xoopsDB->queryF("ALTER TABLE $table ADD $field;"); |
|
1520 | + |
|
1521 | + return $result; |
|
1522 | + } |
|
1523 | + |
|
1524 | + /** |
|
1525 | + * Maintenance des tables du module et de son cache de requêtes |
|
1526 | + * |
|
1527 | + * @return void |
|
1528 | + */ |
|
1529 | + public static function maintainTablesCache() |
|
1530 | + { |
|
1531 | + global $xoopsDB; |
|
1532 | + define('REFERENCES_MAINTAIN', true); |
|
1533 | + require self::MODULE_PATH . 'xoops_version.php'; |
|
1534 | + $tables = array(); |
|
1535 | + foreach ($modversion['tables'] as $table) { |
|
1536 | + $tables[] = $xoopsDB->prefix($table); |
|
1537 | + } |
|
1538 | + if (count($tables) > 0) { |
|
1539 | + $list = implode(',', $tables); |
|
1540 | + $xoopsDB->queryF('CHECK TABLE ' . $list); |
|
1541 | + $xoopsDB->queryF('ANALYZE TABLE ' . $list); |
|
1542 | + $xoopsDB->queryF('OPTIMIZE TABLE ' . $list); |
|
1543 | + } |
|
1544 | + self::updateCache(); |
|
1545 | + $handlers = references_handler::getInstance(); |
|
1546 | + $handlers->h_references_articles->forceCacheClean(); |
|
1547 | + } |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Indique si le module Tag existe et est activé |
|
1551 | + * |
|
1552 | + * @return boolean |
|
1553 | + * @credit: smartfactory |
|
1554 | + */ |
|
1555 | + public static function tagModuleExists() |
|
1556 | + { |
|
1557 | + static $moduleExistsAndIsActive; |
|
1558 | + if (!isset($moduleExistsAndIsActive)) { |
|
1559 | + $modules_handler = xoops_getHandler('module'); |
|
1560 | + $tagModule = $modules_handler->getByDirName('tag'); |
|
1561 | + if (!$tagModule) { |
|
1562 | + $moduleExistsAndIsActive = false; |
|
1563 | + } else { |
|
1564 | + $moduleExistsAndIsActive = $tagModule->getVar('isactive') == 1; |
|
1565 | + } |
|
1566 | + } |
|
1567 | + |
|
1568 | + return $moduleExistsAndIsActive; |
|
1569 | + } |
|
1570 | 1570 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | { |
110 | 110 | $x23 = false; |
111 | 111 | $xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
112 | - if ((int)substr($xv, 2, 1) >= 3) { |
|
112 | + if ((int) substr($xv, 2, 1) >= 3) { |
|
113 | 113 | $x23 = true; |
114 | 114 | } |
115 | 115 | |
@@ -149,15 +149,15 @@ discard block |
||
149 | 149 | // Only for Xoops 2.0.x |
150 | 150 | switch ($editor_option) { |
151 | 151 | case 'fckeditor': |
152 | - if (is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { |
|
153 | - require_once(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'); |
|
152 | + if (is_readable(XOOPS_ROOT_PATH.'/class/fckeditor/formfckeditor.php')) { |
|
153 | + require_once(XOOPS_ROOT_PATH.'/class/fckeditor/formfckeditor.php'); |
|
154 | 154 | $editor = new XoopsFormFckeditor($caption, $name, $value); |
155 | 155 | } |
156 | 156 | break; |
157 | 157 | |
158 | 158 | case 'htmlarea': |
159 | - if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
|
160 | - require_once(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'); |
|
159 | + if (is_readable(XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php')) { |
|
160 | + require_once(XOOPS_ROOT_PATH.'/class/htmlarea/formhtmlarea.php'); |
|
161 | 161 | $editor = new XoopsFormHtmlarea($caption, $name, $value); |
162 | 162 | } |
163 | 163 | break; |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | |
173 | 173 | case 'tinyeditor': |
174 | 174 | case 'tinymce': |
175 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
|
176 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
|
175 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
|
176 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
|
177 | 177 | $editor = new XoopsFormTinyeditorTextArea(array('caption' => $caption, 'name' => $name, 'value' => $value, 'width' => '100%', 'height' => '400px')); |
178 | 178 | } |
179 | 179 | break; |
180 | 180 | |
181 | 181 | case 'koivi': |
182 | - if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
|
183 | - require_once(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'); |
|
182 | + if (is_readable(XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php')) { |
|
183 | + require_once(XOOPS_ROOT_PATH.'/class/wysiwyg/formwysiwygtextarea.php'); |
|
184 | 184 | $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); |
185 | 185 | } |
186 | 186 | break; |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | public static function javascriptLinkConfirm($message, $form = false) |
203 | 203 | { |
204 | 204 | if (!$form) { |
205 | - return "onclick=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
|
205 | + return "onclick=\"javascript:return confirm('".str_replace("'", ' ', $message)."')\""; |
|
206 | 206 | } else { |
207 | - return "onSubmit=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
|
207 | + return "onSubmit=\"javascript:return confirm('".str_replace("'", ' ', $message)."')\""; |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
285 | 285 | { |
286 | 286 | global $xoopsConfig; |
287 | - require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
|
287 | + require_once XOOPS_ROOT_PATH.'/class/xoopsmailer.php'; |
|
288 | 288 | if (!is_array($recipients)) { |
289 | 289 | if (trim($recipients) == '') { |
290 | 290 | return false; |
@@ -295,13 +295,13 @@ discard block |
||
295 | 295 | } |
296 | 296 | } |
297 | 297 | if (function_exists('xoops_getMailer')) { |
298 | - $xoopsMailer =& xoops_getMailer(); |
|
298 | + $xoopsMailer = & xoops_getMailer(); |
|
299 | 299 | } else { |
300 | - $xoopsMailer =& getMailer(); |
|
300 | + $xoopsMailer = & getMailer(); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | $xoopsMailer->useMail(); |
304 | - $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH . '/modules/' . self::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'); |
|
304 | + $xoopsMailer->setTemplateDir(XOOPS_ROOT_PATH.'/modules/'.self::MODULE_NAME.'/language/'.$xoopsConfig['language'].'/mail_template'); |
|
305 | 305 | $xoopsMailer->setTemplate($tplName); |
306 | 306 | $xoopsMailer->setToEmails($recipients); |
307 | 307 | // TODO: Change ! |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | } |
314 | 314 | $res = $xoopsMailer->send(); |
315 | 315 | unset($xoopsMailer); |
316 | - $filename = XOOPS_UPLOAD_PATH . '/logmail_' . self::MODULE_NAME . '.php'; |
|
316 | + $filename = XOOPS_UPLOAD_PATH.'/logmail_'.self::MODULE_NAME.'.php'; |
|
317 | 317 | if (!file_exists($filename)) { |
318 | 318 | $fp = @fopen($filename, 'a'); |
319 | 319 | if ($fp) { |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | $fp = @fopen($filename, 'a'); |
325 | 325 | |
326 | 326 | if ($fp) { |
327 | - fwrite($fp, str_repeat('-', 120) . "\n"); |
|
328 | - fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
|
329 | - fwrite($fp, 'Template name : ' . $tplName . "\n"); |
|
330 | - fwrite($fp, 'Email subject : ' . $subject . "\n"); |
|
327 | + fwrite($fp, str_repeat('-', 120)."\n"); |
|
328 | + fwrite($fp, date('d/m/Y H:i:s')."\n"); |
|
329 | + fwrite($fp, 'Template name : '.$tplName."\n"); |
|
330 | + fwrite($fp, 'Email subject : '.$subject."\n"); |
|
331 | 331 | if (is_array($recipients)) { |
332 | - fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
|
332 | + fwrite($fp, 'Recipient(s) : '.implode(',', $recipients)."\n"); |
|
333 | 333 | } else { |
334 | - fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
|
334 | + fwrite($fp, 'Recipient(s) : '.$recipients."\n"); |
|
335 | 335 | } |
336 | - fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
|
336 | + fwrite($fp, 'Transmited variables : '.implode(',', $variables)."\n"); |
|
337 | 337 | fclose($fp); |
338 | 338 | } |
339 | 339 | |
@@ -348,17 +348,17 @@ discard block |
||
348 | 348 | global $xoopsModule; |
349 | 349 | $folder = $xoopsModule->getVar('dirname'); |
350 | 350 | $tpllist = array(); |
351 | - require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
|
352 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
351 | + require_once XOOPS_ROOT_PATH.'/class/xoopsblock.php'; |
|
352 | + require_once XOOPS_ROOT_PATH.'/class/template.php'; |
|
353 | 353 | $tplfile_handler = xoops_getHandler('tplfile'); |
354 | 354 | $tpllist = $tplfile_handler->find(null, null, null, $folder); |
355 | - xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
|
355 | + xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
|
356 | 356 | |
357 | 357 | foreach ($tpllist as $onetemplate) { // Remove cache for each page. |
358 | 358 | if ($onetemplate->getVar('tpl_type') === 'module') { |
359 | 359 | // Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
360 | 360 | $files_del = array(); |
361 | - $files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*'); |
|
361 | + $files_del = glob(XOOPS_CACHE_PATH.'/*'.$onetemplate->getVar('tpl_file').'*'); |
|
362 | 362 | if (count($files_del) > 0 && is_array($files_del)) { |
363 | 363 | foreach ($files_del as $one_file) { |
364 | 364 | if (is_file($one_file)) { |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | if (!isset($mymodule)) { |
395 | 395 | global $xoopsModule; |
396 | 396 | if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == REFERENCES_DIRNAME) { |
397 | - $mymodule =& $xoopsModule; |
|
397 | + $mymodule = & $xoopsModule; |
|
398 | 398 | } else { |
399 | 399 | $hModule = xoops_getHandler('module'); |
400 | 400 | $mymodule = $hModule->getByDirname(REFERENCES_DIRNAME); |
@@ -512,12 +512,12 @@ discard block |
||
512 | 512 | */ |
513 | 513 | public static function getCurrentSQLDate() |
514 | 514 | { |
515 | - return date('Y-m-d'); // 2007-05-02 |
|
515 | + return date('Y-m-d'); // 2007-05-02 |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | public static function getCurrentSQLDateTime() |
519 | 519 | { |
520 | - return date('Y-m-d H:i:s'); // 2007-05-02 |
|
520 | + return date('Y-m-d H:i:s'); // 2007-05-02 |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | /** |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | */ |
545 | 545 | public static function timestampToMysqlDate($timestamp) |
546 | 546 | { |
547 | - return date('Y-m-d', (int)$timestamp); |
|
547 | + return date('Y-m-d', (int) $timestamp); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | /** |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | } |
583 | 583 | if (strpos(strtolower(XOOPS_VERSION), 'legacy') === false) { |
584 | 584 | $xv = xoops_trim(str_replace('XOOPS ', '', XOOPS_VERSION)); |
585 | - if ((int)substr($xv, 4, 2) >= 17) { |
|
585 | + if ((int) substr($xv, 4, 2) >= 17) { |
|
586 | 586 | return false; |
587 | 587 | } |
588 | 588 | } |
@@ -645,25 +645,25 @@ discard block |
||
645 | 645 | } |
646 | 646 | $ext = basename($fileName); |
647 | 647 | $ext = explode('.', $ext); |
648 | - $ext = '.' . $ext[count($ext) - 1]; |
|
648 | + $ext = '.'.$ext[count($ext) - 1]; |
|
649 | 649 | $true = true; |
650 | 650 | while ($true) { |
651 | 651 | $ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
652 | 652 | list($usec, $sec) = explode(' ', microtime()); |
653 | - $usec = (integer)($usec * 65536); |
|
654 | - $sec = ((integer)$sec) & 0xFFFF; |
|
653 | + $usec = (integer) ($usec * 65536); |
|
654 | + $sec = ((integer) $sec)&0xFFFF; |
|
655 | 655 | |
656 | 656 | if ($trimName) { |
657 | - $uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
|
657 | + $uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24)|($ipbits[1] << 16)|($ipbits[2] << 8)|$ipbits[3], $sec, $usec); |
|
658 | 658 | } else { |
659 | - $uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
|
659 | + $uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24)|($ipbits[1] << 16)|($ipbits[2] << 8)|$ipbits[3], $sec, $usec); |
|
660 | 660 | } |
661 | - if (!file_exists($workingfolder . $uid . $ext)) { |
|
661 | + if (!file_exists($workingfolder.$uid.$ext)) { |
|
662 | 662 | $true = false; |
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
666 | - return $uid . $ext; |
|
666 | + return $uid.$ext; |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | /** |
@@ -678,135 +678,135 @@ discard block |
||
678 | 678 | $chaine = html_entity_decode($chaine); |
679 | 679 | |
680 | 680 | for ($i = 0; $i <= 255; ++$i) { |
681 | - $search[] = '&#' . $i . ';'; |
|
681 | + $search[] = '&#'.$i.';'; |
|
682 | 682 | $replace[] = chr($i); |
683 | 683 | } |
684 | - $replace[]='...'; $search[]='…'; |
|
685 | - $replace[]="'"; $search[]='‘'; |
|
686 | - $replace[]="'"; $search[]= '’'; |
|
687 | - $replace[]='-'; $search[] = '•'; // $replace[] = '•'; |
|
688 | - $replace[]='—'; $search[]='—'; |
|
689 | - $replace[]='-'; $search[]='–'; |
|
690 | - $replace[]='-'; $search[]='­'; |
|
691 | - $replace[]='"'; $search[]='"'; |
|
692 | - $replace[]='&'; $search[]='&'; |
|
693 | - $replace[]='ˆ'; $search[]='ˆ'; |
|
694 | - $replace[]='¡'; $search[]='¡'; |
|
695 | - $replace[]='¦'; $search[]='¦'; |
|
696 | - $replace[]='¨'; $search[]='¨'; |
|
697 | - $replace[]='¯'; $search[]='¯'; |
|
698 | - $replace[]='´'; $search[]='´'; |
|
699 | - $replace[]='¸'; $search[]='¸'; |
|
700 | - $replace[]='¿'; $search[]='¿'; |
|
701 | - $replace[]='˜'; $search[]='˜'; |
|
702 | - $replace[]="'"; $search[]='‘'; // $replace[]='‘'; |
|
703 | - $replace[]="'"; $search[]='’'; // $replace[]='’'; |
|
704 | - $replace[]='‚'; $search[]='‚'; |
|
705 | - $replace[]="'"; $search[]='“'; // $replace[]='“'; |
|
706 | - $replace[]="'"; $search[]='”'; // $replace[]='”'; |
|
707 | - $replace[]='„'; $search[]='„'; |
|
708 | - $replace[]='‹'; $search[]='‹'; |
|
709 | - $replace[]='›'; $search[]='›'; |
|
710 | - $replace[]='<'; $search[]='<'; |
|
711 | - $replace[]='>'; $search[]='>'; |
|
712 | - $replace[]='±'; $search[]='±'; |
|
713 | - $replace[]='«'; $search[]='«'; |
|
714 | - $replace[]='»'; $search[]='»'; |
|
715 | - $replace[]='×'; $search[]='×'; |
|
716 | - $replace[]='÷'; $search[]='÷'; |
|
717 | - $replace[]='¢'; $search[]='¢'; |
|
718 | - $replace[]='£'; $search[]='£'; |
|
719 | - $replace[]='¤'; $search[]='¤'; |
|
720 | - $replace[]='¥'; $search[]='¥'; |
|
721 | - $replace[]='§'; $search[]='§'; |
|
722 | - $replace[]='©'; $search[]='©'; |
|
723 | - $replace[]='¬'; $search[]='¬'; |
|
724 | - $replace[]='®'; $search[]='®'; |
|
725 | - $replace[]='°'; $search[]='°'; |
|
726 | - $replace[]='µ'; $search[]='µ'; |
|
727 | - $replace[]='¶'; $search[]='¶'; |
|
728 | - $replace[]='·'; $search[]='·'; |
|
729 | - $replace[]='†'; $search[]='†'; |
|
730 | - $replace[]='‡'; $search[]='‡'; |
|
731 | - $replace[]='‰'; $search[]='‰'; |
|
732 | - $replace[]='Euro'; $search[]='€'; // $replace[]='€' |
|
733 | - $replace[]='¼'; $search[]='¼'; |
|
734 | - $replace[]='½'; $search[]='½'; |
|
735 | - $replace[]='¾'; $search[]='¾'; |
|
736 | - $replace[]='¹'; $search[]='¹'; |
|
737 | - $replace[]='²'; $search[]='²'; |
|
738 | - $replace[]='³'; $search[]='³'; |
|
739 | - $replace[]='á'; $search[]='á'; |
|
740 | - $replace[]='Á'; $search[]='Á'; |
|
741 | - $replace[]='â'; $search[]='â'; |
|
742 | - $replace[]='Â'; $search[]='Â'; |
|
743 | - $replace[]='à'; $search[]='à'; |
|
744 | - $replace[]='À'; $search[]='À'; |
|
745 | - $replace[]='å'; $search[]='å'; |
|
746 | - $replace[]='Å'; $search[]='Å'; |
|
747 | - $replace[]='ã'; $search[]='ã'; |
|
748 | - $replace[]='Ã'; $search[]='Ã'; |
|
749 | - $replace[]='ä'; $search[]='ä'; |
|
750 | - $replace[]='Ä'; $search[]='Ä'; |
|
751 | - $replace[]='ª'; $search[]='ª'; |
|
752 | - $replace[]='æ'; $search[]='æ'; |
|
753 | - $replace[]='Æ'; $search[]='Æ'; |
|
754 | - $replace[]='ç'; $search[]='ç'; |
|
755 | - $replace[]='Ç'; $search[]='Ç'; |
|
756 | - $replace[]='ð'; $search[]='ð'; |
|
757 | - $replace[]='Ð'; $search[]='Ð'; |
|
758 | - $replace[]='é'; $search[]='é'; |
|
759 | - $replace[]='É'; $search[]='É'; |
|
760 | - $replace[]='ê'; $search[]='ê'; |
|
761 | - $replace[]='Ê'; $search[]='Ê'; |
|
762 | - $replace[]='è'; $search[]='è'; |
|
763 | - $replace[]='È'; $search[]='È'; |
|
764 | - $replace[]='ë'; $search[]='ë'; |
|
765 | - $replace[]='Ë'; $search[]='Ë'; |
|
766 | - $replace[]='ƒ'; $search[]='ƒ'; |
|
767 | - $replace[]='í'; $search[]='í'; |
|
768 | - $replace[]='Í'; $search[]='Í'; |
|
769 | - $replace[]='î'; $search[]='î'; |
|
770 | - $replace[]='Î'; $search[]='Î'; |
|
771 | - $replace[]='ì'; $search[]='ì'; |
|
772 | - $replace[]='Ì'; $search[]='Ì'; |
|
773 | - $replace[]='ï'; $search[]='ï'; |
|
774 | - $replace[]='Ï'; $search[]='Ï'; |
|
775 | - $replace[]='ñ'; $search[]='ñ'; |
|
776 | - $replace[]='Ñ'; $search[]='Ñ'; |
|
777 | - $replace[]='ó'; $search[]='ó'; |
|
778 | - $replace[]='Ó'; $search[]='Ó'; |
|
779 | - $replace[]='ô'; $search[]='ô'; |
|
780 | - $replace[]='Ô'; $search[]='Ô'; |
|
781 | - $replace[]='ò'; $search[]='ò'; |
|
782 | - $replace[]='Ò'; $search[]='Ò'; |
|
783 | - $replace[]='º'; $search[]='º'; |
|
784 | - $replace[]='ø'; $search[]='ø'; |
|
785 | - $replace[]='Ø'; $search[]='Ø'; |
|
786 | - $replace[]='õ'; $search[]='õ'; |
|
787 | - $replace[]='Õ'; $search[]='Õ'; |
|
788 | - $replace[]='ö'; $search[]='ö'; |
|
789 | - $replace[]='Ö'; $search[]='Ö'; |
|
790 | - $replace[]='œ'; $search[]='œ'; |
|
791 | - $replace[]='Œ'; $search[]='Œ'; |
|
792 | - $replace[]='š'; $search[]='š'; |
|
793 | - $replace[]='Š'; $search[]='Š'; |
|
794 | - $replace[]='ß'; $search[]='ß'; |
|
795 | - $replace[]='þ'; $search[]='þ'; |
|
796 | - $replace[]='Þ'; $search[]='Þ'; |
|
797 | - $replace[]='ú'; $search[]='ú'; |
|
798 | - $replace[]='Ú'; $search[]='Ú'; |
|
799 | - $replace[]='û'; $search[]='û'; |
|
800 | - $replace[]='Û'; $search[]='Û'; |
|
801 | - $replace[]='ù'; $search[]='ù'; |
|
802 | - $replace[]='Ù'; $search[]='Ù'; |
|
803 | - $replace[]='ü'; $search[]='ü'; |
|
804 | - $replace[]='Ü'; $search[]='Ü'; |
|
805 | - $replace[]='ý'; $search[]='ý'; |
|
806 | - $replace[]='Ý'; $search[]='Ý'; |
|
807 | - $replace[]='ÿ'; $search[]='ÿ'; |
|
808 | - $replace[]='Ÿ'; $search[]='Ÿ'; |
|
809 | - $chaine = str_replace($search, $replace, $chaine); |
|
684 | + $replace[] = '...'; $search[] = '…'; |
|
685 | + $replace[] = "'"; $search[] = '‘'; |
|
686 | + $replace[] = "'"; $search[] = '’'; |
|
687 | + $replace[] = '-'; $search[] = '•'; // $replace[] = '•'; |
|
688 | + $replace[] = '—'; $search[] = '—'; |
|
689 | + $replace[] = '-'; $search[] = '–'; |
|
690 | + $replace[] = '-'; $search[] = '­'; |
|
691 | + $replace[] = '"'; $search[] = '"'; |
|
692 | + $replace[] = '&'; $search[] = '&'; |
|
693 | + $replace[] = 'ˆ'; $search[] = 'ˆ'; |
|
694 | + $replace[] = '¡'; $search[] = '¡'; |
|
695 | + $replace[] = '¦'; $search[] = '¦'; |
|
696 | + $replace[] = '¨'; $search[] = '¨'; |
|
697 | + $replace[] = '¯'; $search[] = '¯'; |
|
698 | + $replace[] = '´'; $search[] = '´'; |
|
699 | + $replace[] = '¸'; $search[] = '¸'; |
|
700 | + $replace[] = '¿'; $search[] = '¿'; |
|
701 | + $replace[] = '˜'; $search[] = '˜'; |
|
702 | + $replace[] = "'"; $search[] = '‘'; // $replace[]='‘'; |
|
703 | + $replace[] = "'"; $search[] = '’'; // $replace[]='’'; |
|
704 | + $replace[] = '‚'; $search[] = '‚'; |
|
705 | + $replace[] = "'"; $search[] = '“'; // $replace[]='“'; |
|
706 | + $replace[] = "'"; $search[] = '”'; // $replace[]='”'; |
|
707 | + $replace[] = '„'; $search[] = '„'; |
|
708 | + $replace[] = '‹'; $search[] = '‹'; |
|
709 | + $replace[] = '›'; $search[] = '›'; |
|
710 | + $replace[] = '<'; $search[] = '<'; |
|
711 | + $replace[] = '>'; $search[] = '>'; |
|
712 | + $replace[] = '±'; $search[] = '±'; |
|
713 | + $replace[] = '«'; $search[] = '«'; |
|
714 | + $replace[] = '»'; $search[] = '»'; |
|
715 | + $replace[] = '×'; $search[] = '×'; |
|
716 | + $replace[] = '÷'; $search[] = '÷'; |
|
717 | + $replace[] = '¢'; $search[] = '¢'; |
|
718 | + $replace[] = '£'; $search[] = '£'; |
|
719 | + $replace[] = '¤'; $search[] = '¤'; |
|
720 | + $replace[] = '¥'; $search[] = '¥'; |
|
721 | + $replace[] = '§'; $search[] = '§'; |
|
722 | + $replace[] = '©'; $search[] = '©'; |
|
723 | + $replace[] = '¬'; $search[] = '¬'; |
|
724 | + $replace[] = '®'; $search[] = '®'; |
|
725 | + $replace[] = '°'; $search[] = '°'; |
|
726 | + $replace[] = 'µ'; $search[] = 'µ'; |
|
727 | + $replace[] = '¶'; $search[] = '¶'; |
|
728 | + $replace[] = '·'; $search[] = '·'; |
|
729 | + $replace[] = '†'; $search[] = '†'; |
|
730 | + $replace[] = '‡'; $search[] = '‡'; |
|
731 | + $replace[] = '‰'; $search[] = '‰'; |
|
732 | + $replace[] = 'Euro'; $search[] = '€'; // $replace[]='€' |
|
733 | + $replace[] = '¼'; $search[] = '¼'; |
|
734 | + $replace[] = '½'; $search[] = '½'; |
|
735 | + $replace[] = '¾'; $search[] = '¾'; |
|
736 | + $replace[] = '¹'; $search[] = '¹'; |
|
737 | + $replace[] = '²'; $search[] = '²'; |
|
738 | + $replace[] = '³'; $search[] = '³'; |
|
739 | + $replace[] = 'á'; $search[] = 'á'; |
|
740 | + $replace[] = 'Á'; $search[] = 'Á'; |
|
741 | + $replace[] = 'â'; $search[] = 'â'; |
|
742 | + $replace[] = 'Â'; $search[] = 'Â'; |
|
743 | + $replace[] = 'à'; $search[] = 'à'; |
|
744 | + $replace[] = 'À'; $search[] = 'À'; |
|
745 | + $replace[] = 'å'; $search[] = 'å'; |
|
746 | + $replace[] = 'Å'; $search[] = 'Å'; |
|
747 | + $replace[] = 'ã'; $search[] = 'ã'; |
|
748 | + $replace[] = 'Ã'; $search[] = 'Ã'; |
|
749 | + $replace[] = 'ä'; $search[] = 'ä'; |
|
750 | + $replace[] = 'Ä'; $search[] = 'Ä'; |
|
751 | + $replace[] = 'ª'; $search[] = 'ª'; |
|
752 | + $replace[] = 'æ'; $search[] = 'æ'; |
|
753 | + $replace[] = 'Æ'; $search[] = 'Æ'; |
|
754 | + $replace[] = 'ç'; $search[] = 'ç'; |
|
755 | + $replace[] = 'Ç'; $search[] = 'Ç'; |
|
756 | + $replace[] = 'ð'; $search[] = 'ð'; |
|
757 | + $replace[] = 'Ð'; $search[] = 'Ð'; |
|
758 | + $replace[] = 'é'; $search[] = 'é'; |
|
759 | + $replace[] = 'É'; $search[] = 'É'; |
|
760 | + $replace[] = 'ê'; $search[] = 'ê'; |
|
761 | + $replace[] = 'Ê'; $search[] = 'Ê'; |
|
762 | + $replace[] = 'è'; $search[] = 'è'; |
|
763 | + $replace[] = 'È'; $search[] = 'È'; |
|
764 | + $replace[] = 'ë'; $search[] = 'ë'; |
|
765 | + $replace[] = 'Ë'; $search[] = 'Ë'; |
|
766 | + $replace[] = 'ƒ'; $search[] = 'ƒ'; |
|
767 | + $replace[] = 'í'; $search[] = 'í'; |
|
768 | + $replace[] = 'Í'; $search[] = 'Í'; |
|
769 | + $replace[] = 'î'; $search[] = 'î'; |
|
770 | + $replace[] = 'Î'; $search[] = 'Î'; |
|
771 | + $replace[] = 'ì'; $search[] = 'ì'; |
|
772 | + $replace[] = 'Ì'; $search[] = 'Ì'; |
|
773 | + $replace[] = 'ï'; $search[] = 'ï'; |
|
774 | + $replace[] = 'Ï'; $search[] = 'Ï'; |
|
775 | + $replace[] = 'ñ'; $search[] = 'ñ'; |
|
776 | + $replace[] = 'Ñ'; $search[] = 'Ñ'; |
|
777 | + $replace[] = 'ó'; $search[] = 'ó'; |
|
778 | + $replace[] = 'Ó'; $search[] = 'Ó'; |
|
779 | + $replace[] = 'ô'; $search[] = 'ô'; |
|
780 | + $replace[] = 'Ô'; $search[] = 'Ô'; |
|
781 | + $replace[] = 'ò'; $search[] = 'ò'; |
|
782 | + $replace[] = 'Ò'; $search[] = 'Ò'; |
|
783 | + $replace[] = 'º'; $search[] = 'º'; |
|
784 | + $replace[] = 'ø'; $search[] = 'ø'; |
|
785 | + $replace[] = 'Ø'; $search[] = 'Ø'; |
|
786 | + $replace[] = 'õ'; $search[] = 'õ'; |
|
787 | + $replace[] = 'Õ'; $search[] = 'Õ'; |
|
788 | + $replace[] = 'ö'; $search[] = 'ö'; |
|
789 | + $replace[] = 'Ö'; $search[] = 'Ö'; |
|
790 | + $replace[] = 'œ'; $search[] = 'œ'; |
|
791 | + $replace[] = 'Œ'; $search[] = 'Œ'; |
|
792 | + $replace[] = 'š'; $search[] = 'š'; |
|
793 | + $replace[] = 'Š'; $search[] = 'Š'; |
|
794 | + $replace[] = 'ß'; $search[] = 'ß'; |
|
795 | + $replace[] = 'þ'; $search[] = 'þ'; |
|
796 | + $replace[] = 'Þ'; $search[] = 'Þ'; |
|
797 | + $replace[] = 'ú'; $search[] = 'ú'; |
|
798 | + $replace[] = 'Ú'; $search[] = 'Ú'; |
|
799 | + $replace[] = 'û'; $search[] = 'û'; |
|
800 | + $replace[] = 'Û'; $search[] = 'Û'; |
|
801 | + $replace[] = 'ù'; $search[] = 'ù'; |
|
802 | + $replace[] = 'Ù'; $search[] = 'Ù'; |
|
803 | + $replace[] = 'ü'; $search[] = 'ü'; |
|
804 | + $replace[] = 'Ü'; $search[] = 'Ü'; |
|
805 | + $replace[] = 'ý'; $search[] = 'ý'; |
|
806 | + $replace[] = 'Ý'; $search[] = 'Ý'; |
|
807 | + $replace[] = 'ÿ'; $search[] = 'ÿ'; |
|
808 | + $replace[] = 'Ÿ'; $search[] = 'Ÿ'; |
|
809 | + $chaine = str_replace($search, $replace, $chaine); |
|
810 | 810 | |
811 | 811 | return $chaine; |
812 | 812 | } |
@@ -823,11 +823,11 @@ discard block |
||
823 | 823 | { |
824 | 824 | $s = "ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÇÌÍÎÏÙÚÛÜŸÑàáâãäåòóôõöøèéêëçìíîïùúûüÿñ '()"; |
825 | 825 | $r = 'AAAAAAOOOOOOEEEECIIIIUUUUYNaaaaaaooooooeeeeciiiiuuuuyn----'; |
826 | - $content = self::unhtml($content); // First, remove html entities |
|
826 | + $content = self::unhtml($content); // First, remove html entities |
|
827 | 827 | $content = strtr($content, $s, $r); |
828 | 828 | $content = strip_tags($content); |
829 | 829 | $content = strtolower($content); |
830 | - $content = htmlentities($content); // TODO: Vérifier |
|
830 | + $content = htmlentities($content); // TODO: Vérifier |
|
831 | 831 | $content = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $content); |
832 | 832 | $content = html_entity_decode($content); |
833 | 833 | $content = eregi_replace('quot', ' ', $content); |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | $keywords = ''; |
843 | 843 | foreach ($words as $word) { |
844 | 844 | if (strlen($word) >= $urw) { |
845 | - $keywords .= '-' . trim($word); |
|
845 | + $keywords .= '-'.trim($word); |
|
846 | 846 | } |
847 | 847 | } |
848 | 848 | if (!$keywords) { |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | $limit = $_SESSION['references_keywords_limit']; |
878 | 878 | } else { |
879 | 879 | $config_handler = xoops_getHandler('config'); |
880 | - $xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
|
880 | + $xoopsConfigSearch = & $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH); |
|
881 | 881 | $limit = $xoopsConfigSearch['keyword_min']; |
882 | 882 | $_SESSION['references_keywords_limit'] = $limit; |
883 | 883 | } |
@@ -925,7 +925,7 @@ discard block |
||
925 | 925 | if (!isset($config_handler) || !is_object($config_handler)) { |
926 | 926 | $config_handler = xoops_getHandler('config'); |
927 | 927 | } |
928 | - $xoopsConfigMetaFooter =& $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
|
928 | + $xoopsConfigMetaFooter = & $config_handler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
|
929 | 929 | if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
930 | 930 | return $xoopsConfigMetaFooter['meta_keywords']; |
931 | 931 | } else { |
@@ -947,10 +947,10 @@ discard block |
||
947 | 947 | */ |
948 | 948 | public static function uploadFile($indice, $dstpath = XOOPS_UPLOAD_PATH, $mimeTypes = null, $uploadMaxSize = null, $maxWidth = null, $maxHeight = null) |
949 | 949 | { |
950 | - require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
950 | + require_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
|
951 | 951 | global $destname; |
952 | 952 | if (isset($_POST['xoops_upload_file'])) { |
953 | - require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
|
953 | + require_once XOOPS_ROOT_PATH.'/class/uploader.php'; |
|
954 | 954 | $fldname = ''; |
955 | 955 | $fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
956 | 956 | $fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | if ($uploader->upload()) { |
975 | 975 | return true; |
976 | 976 | } else { |
977 | - return _ERRORS . ' ' . htmlentities($uploader->getErrors()); |
|
977 | + return _ERRORS.' '.htmlentities($uploader->getErrors()); |
|
978 | 978 | } |
979 | 979 | } else { |
980 | 980 | return htmlentities($uploader->getErrors()); |
@@ -1057,9 +1057,9 @@ discard block |
||
1057 | 1057 | $workingBreadcrumb = array(); |
1058 | 1058 | if (is_array($path)) { |
1059 | 1059 | $moduleName = self::getModuleName(); |
1060 | - $workingBreadcrumb[] = "<a href='" . REFERENCES_URL . "' title='" . self::makeHrefTitle($moduleName) . "'>" . $moduleName . '</a>'; |
|
1060 | + $workingBreadcrumb[] = "<a href='".REFERENCES_URL."' title='".self::makeHrefTitle($moduleName)."'>".$moduleName.'</a>'; |
|
1061 | 1061 | foreach ($path as $url => $title) { |
1062 | - $workingBreadcrumb[] = "<a href='" . $url . "'>" . $title . '</a>'; |
|
1062 | + $workingBreadcrumb[] = "<a href='".$url."'>".$title.'</a>'; |
|
1063 | 1063 | } |
1064 | 1064 | $cnt = count($workingBreadcrumb); |
1065 | 1065 | for ($i = 0; $i < $cnt; ++$i) { |
@@ -1098,7 +1098,7 @@ discard block |
||
1098 | 1098 | |
1099 | 1099 | $complete_tags = array_reverse($complete_tags); |
1100 | 1100 | for ($i = 0; $i < count($complete_tags); ++$i) { |
1101 | - $string .= '</' . $complete_tags[$i] . '>'; |
|
1101 | + $string .= '</'.$complete_tags[$i].'>'; |
|
1102 | 1102 | } |
1103 | 1103 | } |
1104 | 1104 | |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | $string = self::close_tags($string); |
1120 | 1120 | } |
1121 | 1121 | |
1122 | - return $string . $etc; |
|
1122 | + return $string.$etc; |
|
1123 | 1123 | } else { |
1124 | 1124 | return $string; |
1125 | 1125 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | public static function getMimeType($filename) |
1152 | 1152 | { |
1153 | 1153 | if (function_exists('finfo_open')) { |
1154 | - $pathToMagic = REFERENCES_PATH . 'mime/magic'; |
|
1154 | + $pathToMagic = REFERENCES_PATH.'mime/magic'; |
|
1155 | 1155 | $finfo = new finfo(FILEINFO_MIME, $pathToMagic); |
1156 | 1156 | $mimetype = $finfo->file($filename); |
1157 | 1157 | finfo_close($finfo); |
@@ -1181,7 +1181,7 @@ discard block |
||
1181 | 1181 | sort($xoopsUsersIDs); |
1182 | 1182 | if (count($xoopsUsersIDs) > 0) { |
1183 | 1183 | $member_handler = xoops_getHandler('user'); |
1184 | - $criteria = new Criteria('uid', '(' . implode(',', $xoopsUsersIDs) . ')', 'IN'); |
|
1184 | + $criteria = new Criteria('uid', '('.implode(',', $xoopsUsersIDs).')', 'IN'); |
|
1185 | 1185 | $criteria->setSort('uid'); |
1186 | 1186 | $users = $member_handler->getObjects($criteria, true); |
1187 | 1187 | } |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | } else { |
1220 | 1220 | if ($uid > 0) { |
1221 | 1221 | $member_handler = xoops_getHandler('member'); |
1222 | - $buffer[$uid] = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1222 | + $buffer[$uid] = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1223 | 1223 | } else { |
1224 | 1224 | $buffer[$uid] = array(XOOPS_GROUP_ANONYMOUS); |
1225 | 1225 | } |
@@ -1246,7 +1246,7 @@ discard block |
||
1246 | 1246 | $retval = $buffer[$group]; |
1247 | 1247 | } else { |
1248 | 1248 | $member_handler = xoops_getHandler('member'); |
1249 | - $groups = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1249 | + $groups = $member_handler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
|
1250 | 1250 | $retval = in_array($group, $groups); |
1251 | 1251 | $buffer[$group] = $retval; |
1252 | 1252 | } |
@@ -1286,7 +1286,7 @@ discard block |
||
1286 | 1286 | static $cache = -1; |
1287 | 1287 | if ($cache == -1) { |
1288 | 1288 | global $xoopsDB; |
1289 | - $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('groups'); |
|
1289 | + $sql = 'SELECT COUNT(*) FROM '.$xoopsDB->prefix('groups'); |
|
1290 | 1290 | $result = $xoopsDB->query($sql); |
1291 | 1291 | if (!$result) { |
1292 | 1292 | return false; |
@@ -1307,7 +1307,7 @@ discard block |
||
1307 | 1307 | { |
1308 | 1308 | if (!is_dir($folder)) { |
1309 | 1309 | mkdir($folder, 0777); |
1310 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
1310 | + file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>'); |
|
1311 | 1311 | } else { |
1312 | 1312 | if (!is_writable($folder)) { |
1313 | 1313 | chmod($folder, 0777); |
@@ -1328,10 +1328,10 @@ discard block |
||
1328 | 1328 | if (strstr($languageFile, $defaultExtension) === false) { |
1329 | 1329 | $languageFile .= $defaultExtension; |
1330 | 1330 | } |
1331 | - if (file_exists($root . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . $languageFile)) { |
|
1332 | - require_once $root . 'language' . DIRECTORY_SEPARATOR . $xoopsConfig['language'] . DIRECTORY_SEPARATOR . $languageFile; |
|
1331 | + if (file_exists($root.'language'.DIRECTORY_SEPARATOR.$xoopsConfig['language'].DIRECTORY_SEPARATOR.$languageFile)) { |
|
1332 | + require_once $root.'language'.DIRECTORY_SEPARATOR.$xoopsConfig['language'].DIRECTORY_SEPARATOR.$languageFile; |
|
1333 | 1333 | } else { // Fallback |
1334 | - require_once $root . 'language' . DIRECTORY_SEPARATOR . 'english' . DIRECTORY_SEPARATOR . $languageFile; |
|
1334 | + require_once $root.'language'.DIRECTORY_SEPARATOR.'english'.DIRECTORY_SEPARATOR.$languageFile; |
|
1335 | 1335 | } |
1336 | 1336 | } |
1337 | 1337 | |
@@ -1369,10 +1369,10 @@ discard block |
||
1369 | 1369 | $left = $top = 0; |
1370 | 1370 | if (is_array($pictureDimensions)) { |
1371 | 1371 | if ($pictureWidth > $param_width) { |
1372 | - $left = (int)(($pictureWidth / 2) - ($param_width / 2)); |
|
1372 | + $left = (int) (($pictureWidth / 2) - ($param_width / 2)); |
|
1373 | 1373 | } |
1374 | 1374 | if ($pictureHeight > $param_height) { |
1375 | - $top = (int)(($pictureHeight / 2) - ($param_height / 2)); |
|
1375 | + $top = (int) (($pictureHeight / 2) - ($param_height / 2)); |
|
1376 | 1376 | } |
1377 | 1377 | } |
1378 | 1378 | $result = $img->crop($left, $top, $param_width, $param_height); |
@@ -1412,7 +1412,7 @@ discard block |
||
1412 | 1412 | $selected = " selected = 'selected'"; |
1413 | 1413 | } |
1414 | 1414 | } |
1415 | - $ret[] = '<option value=0' . $selected . '>---</option>'; |
|
1415 | + $ret[] = '<option value=0'.$selected.'>---</option>'; |
|
1416 | 1416 | } |
1417 | 1417 | |
1418 | 1418 | foreach ($array as $index => $label) { |
@@ -1426,7 +1426,7 @@ discard block |
||
1426 | 1426 | $selected = " selected = 'selected'"; |
1427 | 1427 | } |
1428 | 1428 | } |
1429 | - $ret[] = "<option value=\"" . $index . "\"" . $selected . '>' . $label . '</option>'; |
|
1429 | + $ret[] = "<option value=\"".$index."\"".$selected.'>'.$label.'</option>'; |
|
1430 | 1430 | } |
1431 | 1431 | |
1432 | 1432 | return implode("\n", $ret); |
@@ -1448,14 +1448,14 @@ discard block |
||
1448 | 1448 | public static function htmlSelect($selectName, $array, $default, $withNull = true, $style = '', $multiple = false, $size = 1, $extra = '') |
1449 | 1449 | { |
1450 | 1450 | $ret = ''; |
1451 | - $ret .= "<select name='" . $selectName . "' id='" . $selectName . "'"; |
|
1451 | + $ret .= "<select name='".$selectName."' id='".$selectName."'"; |
|
1452 | 1452 | if (xoops_trim($style) != '') { |
1453 | - $ret .= " style='" . $style . "' "; |
|
1453 | + $ret .= " style='".$style."' "; |
|
1454 | 1454 | } |
1455 | 1455 | if (xoops_trim($multiple) != '') { |
1456 | - $ret .= " multiple = 'multiple' size='" . $size . "' "; |
|
1456 | + $ret .= " multiple = 'multiple' size='".$size."' "; |
|
1457 | 1457 | } |
1458 | - $ret .= $extra . ">\n"; |
|
1458 | + $ret .= $extra.">\n"; |
|
1459 | 1459 | $ret .= self::htmlSelectOptions($array, $default, $withNull); |
1460 | 1460 | $ret .= "</select>\n"; |
1461 | 1461 | |
@@ -1530,16 +1530,16 @@ discard block |
||
1530 | 1530 | { |
1531 | 1531 | global $xoopsDB; |
1532 | 1532 | define('REFERENCES_MAINTAIN', true); |
1533 | - require self::MODULE_PATH . 'xoops_version.php'; |
|
1533 | + require self::MODULE_PATH.'xoops_version.php'; |
|
1534 | 1534 | $tables = array(); |
1535 | 1535 | foreach ($modversion['tables'] as $table) { |
1536 | 1536 | $tables[] = $xoopsDB->prefix($table); |
1537 | 1537 | } |
1538 | 1538 | if (count($tables) > 0) { |
1539 | 1539 | $list = implode(',', $tables); |
1540 | - $xoopsDB->queryF('CHECK TABLE ' . $list); |
|
1541 | - $xoopsDB->queryF('ANALYZE TABLE ' . $list); |
|
1542 | - $xoopsDB->queryF('OPTIMIZE TABLE ' . $list); |
|
1540 | + $xoopsDB->queryF('CHECK TABLE '.$list); |
|
1541 | + $xoopsDB->queryF('ANALYZE TABLE '.$list); |
|
1542 | + $xoopsDB->queryF('OPTIMIZE TABLE '.$list); |
|
1543 | 1543 | } |
1544 | 1544 | self::updateCache(); |
1545 | 1545 | $handlers = references_handler::getInstance(); |
@@ -26,7 +26,7 @@ |
||
26 | 26 | /** |
27 | 27 | * Access the only instance of this class |
28 | 28 | * |
29 | - * @return object |
|
29 | + * @return references_registryfile |
|
30 | 30 | * |
31 | 31 | * @static |
32 | 32 | * @staticvar object |
@@ -21,68 +21,68 @@ |
||
21 | 21 | */ |
22 | 22 | class references_registryfile |
23 | 23 | { |
24 | - public $filename; // Nom du fichier � traiter |
|
24 | + public $filename; // Nom du fichier � traiter |
|
25 | 25 | |
26 | - /** |
|
27 | - * Access the only instance of this class |
|
28 | - * |
|
29 | - * @return object |
|
30 | - * |
|
31 | - * @static |
|
32 | - * @staticvar object |
|
33 | - */ |
|
34 | - public static function getInstance() |
|
35 | - { |
|
36 | - static $instance; |
|
37 | - if (null === $instance) { |
|
38 | - $instance = new static(); |
|
39 | - } |
|
26 | + /** |
|
27 | + * Access the only instance of this class |
|
28 | + * |
|
29 | + * @return object |
|
30 | + * |
|
31 | + * @static |
|
32 | + * @staticvar object |
|
33 | + */ |
|
34 | + public static function getInstance() |
|
35 | + { |
|
36 | + static $instance; |
|
37 | + if (null === $instance) { |
|
38 | + $instance = new static(); |
|
39 | + } |
|
40 | 40 | |
41 | - return $instance; |
|
42 | - } |
|
41 | + return $instance; |
|
42 | + } |
|
43 | 43 | |
44 | - public function __construct($fichier = null) |
|
45 | - { |
|
46 | - $this->setfile($fichier); |
|
47 | - } |
|
44 | + public function __construct($fichier = null) |
|
45 | + { |
|
46 | + $this->setfile($fichier); |
|
47 | + } |
|
48 | 48 | |
49 | - public function setfile($fichier = null) |
|
50 | - { |
|
51 | - if ($fichier) { |
|
52 | - $this->filename = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
53 | - } |
|
54 | - } |
|
49 | + public function setfile($fichier = null) |
|
50 | + { |
|
51 | + if ($fichier) { |
|
52 | + $this->filename = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - public function getfile($fichier = null) |
|
57 | - { |
|
58 | - $fw = ''; |
|
59 | - if (!$fichier) { |
|
60 | - $fw = $this->filename; |
|
61 | - } else { |
|
62 | - $fw = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
63 | - } |
|
64 | - if (file_exists($fw)) { |
|
65 | - return file_get_contents($fw); |
|
66 | - } else { |
|
67 | - return ''; |
|
68 | - } |
|
69 | - } |
|
56 | + public function getfile($fichier = null) |
|
57 | + { |
|
58 | + $fw = ''; |
|
59 | + if (!$fichier) { |
|
60 | + $fw = $this->filename; |
|
61 | + } else { |
|
62 | + $fw = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
63 | + } |
|
64 | + if (file_exists($fw)) { |
|
65 | + return file_get_contents($fw); |
|
66 | + } else { |
|
67 | + return ''; |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | - public function savefile($content, $fichier = null) |
|
72 | - { |
|
73 | - $fw = ''; |
|
74 | - if (!$fichier) { |
|
75 | - $fw = $this->filename; |
|
76 | - } else { |
|
77 | - $fw = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
78 | - } |
|
79 | - if (file_exists($fw)) { |
|
80 | - @unlink($fw); |
|
81 | - } |
|
82 | - $fp = fopen($fw, 'w') || exit('Error, impossible to create the file ' . $this->filename); |
|
83 | - fwrite($fp, $content); |
|
84 | - fclose($fp); |
|
71 | + public function savefile($content, $fichier = null) |
|
72 | + { |
|
73 | + $fw = ''; |
|
74 | + if (!$fichier) { |
|
75 | + $fw = $this->filename; |
|
76 | + } else { |
|
77 | + $fw = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
78 | + } |
|
79 | + if (file_exists($fw)) { |
|
80 | + @unlink($fw); |
|
81 | + } |
|
82 | + $fp = fopen($fw, 'w') || exit('Error, impossible to create the file ' . $this->filename); |
|
83 | + fwrite($fp, $content); |
|
84 | + fclose($fp); |
|
85 | 85 | |
86 | - return true; |
|
87 | - } |
|
86 | + return true; |
|
87 | + } |
|
88 | 88 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class references_registryfile |
23 | 23 | { |
24 | - public $filename; // Nom du fichier � traiter |
|
24 | + public $filename; // Nom du fichier � traiter |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Access the only instance of this class |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | public function setfile($fichier = null) |
50 | 50 | { |
51 | 51 | if ($fichier) { |
52 | - $this->filename = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
52 | + $this->filename = XOOPS_UPLOAD_PATH.DIRECTORY_SEPARATOR.$fichier; |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | if (!$fichier) { |
60 | 60 | $fw = $this->filename; |
61 | 61 | } else { |
62 | - $fw = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
62 | + $fw = XOOPS_UPLOAD_PATH.DIRECTORY_SEPARATOR.$fichier; |
|
63 | 63 | } |
64 | 64 | if (file_exists($fw)) { |
65 | 65 | return file_get_contents($fw); |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | if (!$fichier) { |
75 | 75 | $fw = $this->filename; |
76 | 76 | } else { |
77 | - $fw = XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . $fichier; |
|
77 | + $fw = XOOPS_UPLOAD_PATH.DIRECTORY_SEPARATOR.$fichier; |
|
78 | 78 | } |
79 | 79 | if (file_exists($fw)) { |
80 | 80 | @unlink($fw); |
81 | 81 | } |
82 | - $fp = fopen($fw, 'w') || exit('Error, impossible to create the file ' . $this->filename); |
|
82 | + $fp = fopen($fw, 'w') || exit('Error, impossible to create the file '.$this->filename); |
|
83 | 83 | fwrite($fp, $content); |
84 | 84 | fclose($fp); |
85 | 85 |
@@ -16,6 +16,10 @@ discard block |
||
16 | 16 | private $debug = false; |
17 | 17 | public $error = false; |
18 | 18 | |
19 | + /** |
|
20 | + * @param string $user |
|
21 | + * @param string $pass |
|
22 | + */ |
|
19 | 23 | function __construct($user, $pass, $debug = false) |
20 | 24 | { |
21 | 25 | // Store an auth key for the HTTP Authorization: header |
@@ -23,6 +27,9 @@ discard block |
||
23 | 27 | $this->debug = $debug; |
24 | 28 | } |
25 | 29 | |
30 | + /** |
|
31 | + * @param string $new_status |
|
32 | + */ |
|
26 | 33 | function update($new_status) |
27 | 34 | { |
28 | 35 | if (strlen($new_status) > 140) { |
@@ -6,70 +6,70 @@ |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | if (class_exists('Twitter')) { |
9 | - return true; |
|
9 | + return true; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | class Twitter |
13 | 13 | { |
14 | 14 | |
15 | - private $auth = false; |
|
16 | - private $debug = false; |
|
17 | - public $error = false; |
|
15 | + private $auth = false; |
|
16 | + private $debug = false; |
|
17 | + public $error = false; |
|
18 | 18 | |
19 | - function __construct($user, $pass, $debug = false) |
|
20 | - { |
|
21 | - // Store an auth key for the HTTP Authorization: header |
|
22 | - $this->auth = base64_encode($user . ':' . $pass); |
|
23 | - $this->debug = $debug; |
|
24 | - } |
|
19 | + function __construct($user, $pass, $debug = false) |
|
20 | + { |
|
21 | + // Store an auth key for the HTTP Authorization: header |
|
22 | + $this->auth = base64_encode($user . ':' . $pass); |
|
23 | + $this->debug = $debug; |
|
24 | + } |
|
25 | 25 | |
26 | - function update($new_status) |
|
27 | - { |
|
28 | - if (strlen($new_status) > 140) { |
|
29 | - $this->error = "Status too long: {$new_status}."; |
|
30 | - return false; |
|
31 | - } |
|
32 | - $fp = @fsockopen('twitter.com', 80, $errno, $errstr); |
|
33 | - if (!$fp) { |
|
34 | - $this->error = "Socket error #{$errno}: {$errstr}"; |
|
35 | - return false; |
|
36 | - } |
|
37 | - $post_data = 'status=' . urlencode($new_status); |
|
38 | - $to_send = "POST /statuses/update.xml HTTP/1.1\r\n"; |
|
39 | - $to_send .= "Host: twitter.com\r\n"; |
|
40 | - $to_send .= 'Content-Length: ' . strlen($post_data) . "\r\n"; |
|
41 | - $to_send .= "Authorization: Basic {$this->auth}\r\n\r\n"; |
|
42 | - $to_send .= $post_data . "\r\n\r\n"; |
|
43 | - $bytes = fwrite($fp, $to_send); |
|
44 | - if ($bytes === false) { |
|
45 | - $this->error = 'Socket error: Error sending data.'; |
|
46 | - return false; |
|
47 | - } elseif ($bytes < strlen($to_send)) { |
|
48 | - $this->error = 'Socket error: Could not send all data.'; |
|
49 | - return false; |
|
50 | - } |
|
51 | - if ($this->debug) echo "Sent:\n{$to_send}\n\n"; |
|
52 | - $response = ''; |
|
53 | - while (!feof($fp)) { |
|
54 | - $buf = fread($fp, 1024); |
|
55 | - if ($buf === false) { |
|
56 | - $this->error = 'Socket error: Error reading data.'; |
|
57 | - return false; |
|
58 | - } |
|
59 | - $response .= $buf; |
|
60 | - } |
|
61 | - if ($this->debug) echo "Received:\n{$response}"; |
|
62 | - $was_error = preg_match('#' . preg_quote('<error>') . '(.+)' . preg_quote('</error>') . '#i', $response, $matches); |
|
63 | - if ($was_error) { |
|
64 | - $this->error = "Twitter error: {$matches[1]}"; |
|
65 | - return false; |
|
66 | - } |
|
67 | - list($first_line) = explode("\r\n", $response); |
|
68 | - if ($first_line !== 'HTTP/1.1 200 OK') { |
|
69 | - $this->error = "Request error: {$first_line}"; |
|
70 | - return false; |
|
71 | - } |
|
72 | - return true; |
|
73 | - } |
|
26 | + function update($new_status) |
|
27 | + { |
|
28 | + if (strlen($new_status) > 140) { |
|
29 | + $this->error = "Status too long: {$new_status}."; |
|
30 | + return false; |
|
31 | + } |
|
32 | + $fp = @fsockopen('twitter.com', 80, $errno, $errstr); |
|
33 | + if (!$fp) { |
|
34 | + $this->error = "Socket error #{$errno}: {$errstr}"; |
|
35 | + return false; |
|
36 | + } |
|
37 | + $post_data = 'status=' . urlencode($new_status); |
|
38 | + $to_send = "POST /statuses/update.xml HTTP/1.1\r\n"; |
|
39 | + $to_send .= "Host: twitter.com\r\n"; |
|
40 | + $to_send .= 'Content-Length: ' . strlen($post_data) . "\r\n"; |
|
41 | + $to_send .= "Authorization: Basic {$this->auth}\r\n\r\n"; |
|
42 | + $to_send .= $post_data . "\r\n\r\n"; |
|
43 | + $bytes = fwrite($fp, $to_send); |
|
44 | + if ($bytes === false) { |
|
45 | + $this->error = 'Socket error: Error sending data.'; |
|
46 | + return false; |
|
47 | + } elseif ($bytes < strlen($to_send)) { |
|
48 | + $this->error = 'Socket error: Could not send all data.'; |
|
49 | + return false; |
|
50 | + } |
|
51 | + if ($this->debug) echo "Sent:\n{$to_send}\n\n"; |
|
52 | + $response = ''; |
|
53 | + while (!feof($fp)) { |
|
54 | + $buf = fread($fp, 1024); |
|
55 | + if ($buf === false) { |
|
56 | + $this->error = 'Socket error: Error reading data.'; |
|
57 | + return false; |
|
58 | + } |
|
59 | + $response .= $buf; |
|
60 | + } |
|
61 | + if ($this->debug) echo "Received:\n{$response}"; |
|
62 | + $was_error = preg_match('#' . preg_quote('<error>') . '(.+)' . preg_quote('</error>') . '#i', $response, $matches); |
|
63 | + if ($was_error) { |
|
64 | + $this->error = "Twitter error: {$matches[1]}"; |
|
65 | + return false; |
|
66 | + } |
|
67 | + list($first_line) = explode("\r\n", $response); |
|
68 | + if ($first_line !== 'HTTP/1.1 200 OK') { |
|
69 | + $this->error = "Request error: {$first_line}"; |
|
70 | + return false; |
|
71 | + } |
|
72 | + return true; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | function __construct($user, $pass, $debug = false) |
20 | 20 | { |
21 | 21 | // Store an auth key for the HTTP Authorization: header |
22 | - $this->auth = base64_encode($user . ':' . $pass); |
|
22 | + $this->auth = base64_encode($user.':'.$pass); |
|
23 | 23 | $this->debug = $debug; |
24 | 24 | } |
25 | 25 | |
@@ -34,12 +34,12 @@ discard block |
||
34 | 34 | $this->error = "Socket error #{$errno}: {$errstr}"; |
35 | 35 | return false; |
36 | 36 | } |
37 | - $post_data = 'status=' . urlencode($new_status); |
|
37 | + $post_data = 'status='.urlencode($new_status); |
|
38 | 38 | $to_send = "POST /statuses/update.xml HTTP/1.1\r\n"; |
39 | 39 | $to_send .= "Host: twitter.com\r\n"; |
40 | - $to_send .= 'Content-Length: ' . strlen($post_data) . "\r\n"; |
|
40 | + $to_send .= 'Content-Length: '.strlen($post_data)."\r\n"; |
|
41 | 41 | $to_send .= "Authorization: Basic {$this->auth}\r\n\r\n"; |
42 | - $to_send .= $post_data . "\r\n\r\n"; |
|
42 | + $to_send .= $post_data."\r\n\r\n"; |
|
43 | 43 | $bytes = fwrite($fp, $to_send); |
44 | 44 | if ($bytes === false) { |
45 | 45 | $this->error = 'Socket error: Error sending data.'; |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $response .= $buf; |
60 | 60 | } |
61 | 61 | if ($this->debug) echo "Received:\n{$response}"; |
62 | - $was_error = preg_match('#' . preg_quote('<error>') . '(.+)' . preg_quote('</error>') . '#i', $response, $matches); |
|
62 | + $was_error = preg_match('#'.preg_quote('<error>').'(.+)'.preg_quote('</error>').'#i', $response, $matches); |
|
63 | 63 | if ($was_error) { |
64 | 64 | $this->error = "Twitter error: {$matches[1]}"; |
65 | 65 | return false; |
@@ -48,7 +48,9 @@ discard block |
||
48 | 48 | $this->error = 'Socket error: Could not send all data.'; |
49 | 49 | return false; |
50 | 50 | } |
51 | - if ($this->debug) echo "Sent:\n{$to_send}\n\n"; |
|
51 | + if ($this->debug) { |
|
52 | + echo "Sent:\n{$to_send}\n\n"; |
|
53 | + } |
|
52 | 54 | $response = ''; |
53 | 55 | while (!feof($fp)) { |
54 | 56 | $buf = fread($fp, 1024); |
@@ -58,7 +60,9 @@ discard block |
||
58 | 60 | } |
59 | 61 | $response .= $buf; |
60 | 62 | } |
61 | - if ($this->debug) echo "Received:\n{$response}"; |
|
63 | + if ($this->debug) { |
|
64 | + echo "Received:\n{$response}"; |
|
65 | + } |
|
62 | 66 | $was_error = preg_match('#' . preg_quote('<error>') . '(.+)' . preg_quote('</error>') . '#i', $response, $matches); |
63 | 67 | if ($was_error) { |
64 | 68 | $this->error = "Twitter error: {$matches[1]}"; |