@@ -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 | } |
@@ -24,34 +24,34 @@ |
||
24 | 24 | */ |
25 | 25 | class references_handler |
26 | 26 | { |
27 | - public $h_references_articles = null; |
|
28 | - public $h_references_categories = null; |
|
29 | - private static $instance = false; |
|
27 | + public $h_references_articles = null; |
|
28 | + public $h_references_categories = null; |
|
29 | + private static $instance = false; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Singleton |
|
33 | - */ |
|
34 | - private function __construct() |
|
35 | - { |
|
36 | - $handlersNames = array('references_articles', 'references_categories'); |
|
37 | - foreach ($handlersNames as $handlerName) { |
|
38 | - $internalName = 'h_' . $handlerName; |
|
39 | - $this->$internalName = xoops_getModuleHandler($handlerName, REFERENCES_DIRNAME); |
|
40 | - } |
|
41 | - } |
|
31 | + /** |
|
32 | + * Singleton |
|
33 | + */ |
|
34 | + private function __construct() |
|
35 | + { |
|
36 | + $handlersNames = array('references_articles', 'references_categories'); |
|
37 | + foreach ($handlersNames as $handlerName) { |
|
38 | + $internalName = 'h_' . $handlerName; |
|
39 | + $this->$internalName = xoops_getModuleHandler($handlerName, REFERENCES_DIRNAME); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Retourne l'instance unique de la clanss |
|
45 | - * |
|
46 | - * @return object |
|
47 | - */ |
|
48 | - public static function getInstance() |
|
49 | - { |
|
50 | - static $instance; |
|
51 | - if (null === $instance) { |
|
52 | - $instance = new static(); |
|
53 | - } |
|
43 | + /** |
|
44 | + * Retourne l'instance unique de la clanss |
|
45 | + * |
|
46 | + * @return object |
|
47 | + */ |
|
48 | + public static function getInstance() |
|
49 | + { |
|
50 | + static $instance; |
|
51 | + if (null === $instance) { |
|
52 | + $instance = new static(); |
|
53 | + } |
|
54 | 54 | |
55 | - return $instance; |
|
56 | - } |
|
55 | + return $instance; |
|
56 | + } |
|
57 | 57 | } |
@@ -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 | } |
@@ -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 | /* |
@@ -30,62 +30,62 @@ |
||
30 | 30 | */ |
31 | 31 | class references_parameters extends ArrayObject |
32 | 32 | { |
33 | - /** |
|
34 | - * Permet de valoriser un indice de la classe comme si c'était une propriété de la classe |
|
35 | - * |
|
36 | - * @example $enregistrement->nom_du_champ = 'ma chaine' |
|
37 | - * |
|
38 | - * @param string $key Le nom du champ à traiter |
|
39 | - * @param mixed $value La valeur à lui attribuer |
|
40 | - * @return object |
|
41 | - */ |
|
42 | - public function __set($key, $value) |
|
43 | - { |
|
44 | - parent::offsetSet($key, $value); |
|
33 | + /** |
|
34 | + * Permet de valoriser un indice de la classe comme si c'était une propriété de la classe |
|
35 | + * |
|
36 | + * @example $enregistrement->nom_du_champ = 'ma chaine' |
|
37 | + * |
|
38 | + * @param string $key Le nom du champ à traiter |
|
39 | + * @param mixed $value La valeur à lui attribuer |
|
40 | + * @return object |
|
41 | + */ |
|
42 | + public function __set($key, $value) |
|
43 | + { |
|
44 | + parent::offsetSet($key, $value); |
|
45 | 45 | |
46 | - return $this; |
|
47 | - } |
|
46 | + return $this; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Valorisation d'un indice de la classe en utilisant un appel de fonction basé sur le principe suivant : |
|
51 | - * $maClasse->setLimit(10); |
|
52 | - * Il est possible de chainer comme ceci : $maClasse->setStart(0)->setLimit(10); |
|
53 | - * |
|
54 | - * @param string $method |
|
55 | - * @param mixed $args |
|
56 | - * @return object |
|
57 | - */ |
|
58 | - public function __call($method, $args) |
|
59 | - { |
|
60 | - if (substr($method, 0, 3) === 'set') { |
|
61 | - parent::offsetSet(strtolower(substr($method, 3, 1)) . substr($method, 4), $args[0]); |
|
49 | + /** |
|
50 | + * Valorisation d'un indice de la classe en utilisant un appel de fonction basé sur le principe suivant : |
|
51 | + * $maClasse->setLimit(10); |
|
52 | + * Il est possible de chainer comme ceci : $maClasse->setStart(0)->setLimit(10); |
|
53 | + * |
|
54 | + * @param string $method |
|
55 | + * @param mixed $args |
|
56 | + * @return object |
|
57 | + */ |
|
58 | + public function __call($method, $args) |
|
59 | + { |
|
60 | + if (substr($method, 0, 3) === 'set') { |
|
61 | + parent::offsetSet(strtolower(substr($method, 3, 1)) . substr($method, 4), $args[0]); |
|
62 | 62 | |
63 | - return $this; |
|
64 | - } else { // Affichage de la valeur |
|
63 | + return $this; |
|
64 | + } else { // Affichage de la valeur |
|
65 | 65 | |
66 | - return parent::offsetGet($method); |
|
67 | - } |
|
68 | - } |
|
66 | + return parent::offsetGet($method); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Méthode qui essaye de faire la même chose que la méthode extend() de jQuery |
|
72 | - * |
|
73 | - * On lui passe les valeurs par défaut que l'on attend et la méthode les compare avec les valeurs actuelles |
|
74 | - * Si des valeurs manquent, elles sont ajoutées |
|
75 | - * |
|
76 | - * @param references_parameters $defaultValues |
|
77 | - * @return references_parameters |
|
78 | - */ |
|
79 | - public function extend(self $defaultValues) |
|
80 | - { |
|
81 | - $result = new self; |
|
82 | - $result = $this; |
|
83 | - foreach ($defaultValues as $key => $value) { |
|
84 | - if (!isset($result[$key])) { |
|
85 | - $result[$key] = $value; |
|
86 | - } |
|
87 | - } |
|
70 | + /** |
|
71 | + * Méthode qui essaye de faire la même chose que la méthode extend() de jQuery |
|
72 | + * |
|
73 | + * On lui passe les valeurs par défaut que l'on attend et la méthode les compare avec les valeurs actuelles |
|
74 | + * Si des valeurs manquent, elles sont ajoutées |
|
75 | + * |
|
76 | + * @param references_parameters $defaultValues |
|
77 | + * @return references_parameters |
|
78 | + */ |
|
79 | + public function extend(self $defaultValues) |
|
80 | + { |
|
81 | + $result = new self; |
|
82 | + $result = $this; |
|
83 | + foreach ($defaultValues as $key => $value) { |
|
84 | + if (!isset($result[$key])) { |
|
85 | + $result[$key] = $value; |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - return $result; |
|
90 | - } |
|
89 | + return $result; |
|
90 | + } |
|
91 | 91 | } |
@@ -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 | } |
@@ -34,21 +34,21 @@ discard block |
||
34 | 34 | |
35 | 35 | $category_id = isset($_GET['category_id']) ? (int)$_GET['category_id'] : 0; |
36 | 36 | if ($category_id == 0) { |
37 | - header('Location: index.php', true, 301); |
|
38 | - exit; |
|
39 | - //references_utils::redirect('', 'index.php', 0); |
|
37 | + header('Location: index.php', true, 301); |
|
38 | + exit; |
|
39 | + //references_utils::redirect('', 'index.php', 0); |
|
40 | 40 | } |
41 | 41 | // Chargement de la catégorie |
42 | 42 | $category = null; |
43 | 43 | $category = $h_references_categories->get($category_id); |
44 | 44 | if (!is_object($category)) { |
45 | - references_utils::redirect(_MD_REFERENCES_ERROR2, 'index.php', 4); |
|
45 | + references_utils::redirect(_MD_REFERENCES_ERROR2, 'index.php', 4); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | // Vérification des permissions |
49 | 49 | $handlers = references_handler::getInstance(); |
50 | 50 | if (!$handlers->h_references_categories->userCanSeeCategory($category)) { |
51 | - references_utils::redirect(_NOPERM, 'index.php', 4); |
|
51 | + references_utils::redirect(_NOPERM, 'index.php', 4); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $xoopsTpl->assign('category', $category->toArray()); |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | $xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools.js'); |
65 | 65 | $xoTheme->addScript(REFERENCES_JS_URL . 'js/mootools-1.2-more.js'); |
66 | 66 | if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/slimbox.js')) { |
67 | - $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
67 | + $xoTheme->addScript(REFERENCES_URL . 'language/' . $xoopsConfig['language'] . '/slimbox.js'); |
|
68 | 68 | } else { |
69 | - $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
69 | + $xoTheme->addScript(REFERENCES_JS_URL . 'js/slimbox.js'); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $categoriesSelect = $h_references_categories->getCategoriesSelect('categoriesSelect', $category->getVar('category_id')); |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $xoopsTpl->assign('thumbsWidth', references_utils::getModuleOption('thumbs_width')); |
79 | 79 | $xoopsTpl->assign('thumbsHeight', references_utils::getModuleOption('thumbs_height')); |
80 | 80 | if ($limit > 0) { |
81 | - $items = array(); |
|
82 | - $items = $h_references_articles->getRecentArticles($start, $limit, references_utils::getModuleOption('sort_field'), references_utils::getModuleOption('sort_order'), true, $category_id); |
|
83 | - $categoryTitle = $category->getVar('category_title'); |
|
84 | - $categoryWeight = $category->getVar('category_weight'); |
|
85 | - if (count($items) > 0) { |
|
86 | - foreach ($items as $item) { |
|
87 | - $xoopsTpl->append('articles', $item->toArray()); |
|
88 | - } |
|
89 | - } |
|
81 | + $items = array(); |
|
82 | + $items = $h_references_articles->getRecentArticles($start, $limit, references_utils::getModuleOption('sort_field'), references_utils::getModuleOption('sort_order'), true, $category_id); |
|
83 | + $categoryTitle = $category->getVar('category_title'); |
|
84 | + $categoryWeight = $category->getVar('category_weight'); |
|
85 | + if (count($items) > 0) { |
|
86 | + foreach ($items as $item) { |
|
87 | + $xoopsTpl->append('articles', $item->toArray()); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | $xoopsTpl->assign('isAdmin', references_utils::isAdmin()); |
92 | 92 | $title = $category->getVar('category_title', 'n') . ' - ' . $xoopsModule->name(); |
@@ -19,27 +19,27 @@ |
||
19 | 19 | * **************************************************************************** |
20 | 20 | */ |
21 | 21 | if (!defined('REFERENCES_CACHE_PATH')) { |
22 | - // Le chemin du cache (il est conseillé de le mettre en dehors de la portée du web) |
|
23 | - define('REFERENCES_CACHE_PATH', XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . REFERENCES_DIRNAME . '_cache' . DIRECTORY_SEPARATOR); |
|
22 | + // Le chemin du cache (il est conseillé de le mettre en dehors de la portée du web) |
|
23 | + define('REFERENCES_CACHE_PATH', XOOPS_UPLOAD_PATH . DIRECTORY_SEPARATOR . REFERENCES_DIRNAME . '_cache' . DIRECTORY_SEPARATOR); |
|
24 | 24 | |
25 | - // Thumbs / Vignettes prefixe |
|
26 | - define('REFERENCES_THUMBS_PREFIX', 'thumb_'); // Thumbs prefix (when thumbs are automatically created) |
|
25 | + // Thumbs / Vignettes prefixe |
|
26 | + define('REFERENCES_THUMBS_PREFIX', 'thumb_'); // Thumbs prefix (when thumbs are automatically created) |
|
27 | 27 | |
28 | - // Short text length / Longueur des textes raccourcis |
|
29 | - define('REFERENCES_SHORTEN_TEXT', '200'); // Characters count / Nombre de caract�res |
|
28 | + // Short text length / Longueur des textes raccourcis |
|
29 | + define('REFERENCES_SHORTEN_TEXT', '200'); // Characters count / Nombre de caract�res |
|
30 | 30 | |
31 | - define('REFERENCES_METAGEN_MAX_KEYWORDS', 40); |
|
32 | - define('REFERENCES_METAGEN_KEYWORDS_ORDER', 0); |
|
31 | + define('REFERENCES_METAGEN_MAX_KEYWORDS', 40); |
|
32 | + define('REFERENCES_METAGEN_KEYWORDS_ORDER', 0); |
|
33 | 33 | |
34 | - // Automatically fill the manual date when creating a reference ? / Remplir automatiquement la date manuelle lorsqu'on crée une référence |
|
35 | - define('REFERENCES_AUTO_FILL_MANUAL_DATE', true); |
|
34 | + // Automatically fill the manual date when creating a reference ? / Remplir automatiquement la date manuelle lorsqu'on crée une référence |
|
35 | + define('REFERENCES_AUTO_FILL_MANUAL_DATE', true); |
|
36 | 36 | |
37 | - /** |
|
38 | - * Si la valeur est à false, alors dans les listes de recherche, côté admin, on recherche tout ce qui contient quelque chose. |
|
39 | - * Par exemple si on tape "a", le module trouvera "abajour" et "cartable". |
|
40 | - * Par contre si on met cette valeur à true alors le module cherchera tout ce qui commence par ... |
|
41 | - * Par exemple si on tape "a", lemodule trouvera "abajour" MAIS PAS "cartable" |
|
42 | - * PAR CONTRE "%a" trouvera tout ce qui contient la lettre a |
|
43 | - */ |
|
44 | - define('REFERENCES_EXACT_SEARCH', true); |
|
37 | + /** |
|
38 | + * Si la valeur est à false, alors dans les listes de recherche, côté admin, on recherche tout ce qui contient quelque chose. |
|
39 | + * Par exemple si on tape "a", le module trouvera "abajour" et "cartable". |
|
40 | + * Par contre si on met cette valeur à true alors le module cherchera tout ce qui commence par ... |
|
41 | + * Par exemple si on tape "a", lemodule trouvera "abajour" MAIS PAS "cartable" |
|
42 | + * PAR CONTRE "%a" trouvera tout ce qui contient la lettre a |
|
43 | + */ |
|
44 | + define('REFERENCES_EXACT_SEARCH', true); |
|
45 | 45 | } |
@@ -19,8 +19,8 @@ |
||
19 | 19 | * **************************************************************************** |
20 | 20 | */ |
21 | 21 | if (file_exists('../../mainfile.php')) { |
22 | - require __DIR__ . '/../../mainfile.php'; |
|
22 | + require __DIR__ . '/../../mainfile.php'; |
|
23 | 23 | } elseif (file_exists('../../../mainfile.php')) { |
24 | - require __DIR__ . '/../../../mainfile.php'; |
|
24 | + require __DIR__ . '/../../../mainfile.php'; |
|
25 | 25 | } |
26 | 26 | require_once XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |