@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | $modversion['min_xoops'] = '2.5.8'; |
47 | 47 | $modversion['min_admin'] = '1.2'; |
48 | 48 | $modversion['min_db'] = array( |
49 | - 'mysql' => '5.0.7', |
|
50 | - 'mysqli' => '5.0.7' |
|
49 | + 'mysql' => '5.0.7', |
|
50 | + 'mysqli' => '5.0.7' |
|
51 | 51 | ); |
52 | 52 | |
53 | 53 | // **************************************************************************** |
@@ -102,13 +102,13 @@ discard block |
||
102 | 102 | * $options[3] - min font size (px or %) |
103 | 103 | */ |
104 | 104 | $modversion['blocks'][] = array( |
105 | - 'file' => 'references_block_tag.php', |
|
106 | - 'name' => _MI_REFERENCES_BNAME3, |
|
107 | - 'description' => 'Show tag cloud', |
|
108 | - 'show_func' => 'references_tag_block_cloud_show', |
|
109 | - 'edit_func' => 'references_tag_block_cloud_edit', |
|
110 | - 'options' => '100|0|150|80', |
|
111 | - 'template' => 'references_tag_block_cloud.tpl' |
|
105 | + 'file' => 'references_block_tag.php', |
|
106 | + 'name' => _MI_REFERENCES_BNAME3, |
|
107 | + 'description' => 'Show tag cloud', |
|
108 | + 'show_func' => 'references_tag_block_cloud_show', |
|
109 | + 'edit_func' => 'references_tag_block_cloud_edit', |
|
110 | + 'options' => '100|0|150|80', |
|
111 | + 'template' => 'references_tag_block_cloud.tpl' |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | /* |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | * $options[2] - sort: a - alphabet; c - count; t - time |
119 | 119 | */ |
120 | 120 | $modversion['blocks'][] = array( |
121 | - 'file' => 'references_block_tag.php', |
|
122 | - 'name' => _MI_REFERENCES_BNAME4, |
|
123 | - 'description' => 'Show top tags', |
|
124 | - 'show_func' => 'references_tag_block_top_show', |
|
125 | - 'edit_func' => 'references_tag_block_top_edit', |
|
126 | - 'options' => '50|30|c', |
|
127 | - 'template' => 'references_tag_block_top.tpl' |
|
121 | + 'file' => 'references_block_tag.php', |
|
122 | + 'name' => _MI_REFERENCES_BNAME4, |
|
123 | + 'description' => 'Show top tags', |
|
124 | + 'show_func' => 'references_tag_block_top_show', |
|
125 | + 'edit_func' => 'references_tag_block_top_edit', |
|
126 | + 'options' => '50|30|c', |
|
127 | + 'template' => 'references_tag_block_top.tpl' |
|
128 | 128 | ); |
129 | 129 | |
130 | 130 | // **************************************************************************** |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | |
162 | 162 | require_once XOOPS_ROOT_PATH . '/modules/references/class/references_utils.php'; |
163 | 163 | if (references_utils::getModuleOption('use_rss')) { |
164 | - ++$cptm; |
|
165 | - $modversion['sub'][$cptm]['name'] = _MI_REFERENCES_SMENU1; |
|
166 | - $modversion['sub'][$cptm]['url'] = 'rss.php'; |
|
164 | + ++$cptm; |
|
165 | + $modversion['sub'][$cptm]['name'] = _MI_REFERENCES_SMENU1; |
|
166 | + $modversion['sub'][$cptm]['url'] = 'rss.php'; |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // **************************************************************************** |
@@ -204,16 +204,16 @@ discard block |
||
204 | 204 | * Editor to use |
205 | 205 | */ |
206 | 206 | if (!defined('REFERENCES_MAINTAIN')) { |
207 | - ++$cpto; |
|
208 | - $modversion['config'][$cpto]['name'] = 'form_options'; |
|
209 | - $modversion['config'][$cpto]['title'] = '_MI_REFERENCES_OPTION2'; |
|
210 | - $modversion['config'][$cpto]['description'] = ''; |
|
211 | - $modversion['config'][$cpto]['formtype'] = 'select'; |
|
212 | - $modversion['config'][$cpto]['valuetype'] = 'text'; |
|
213 | - $modversion['config'][$cpto]['default'] = 'dhtmltextarea'; |
|
214 | - xoops_load('xoopseditorhandler'); |
|
215 | - $editor_handler = XoopsEditorHandler::getInstance(); |
|
216 | - $modversion['config'][$cpto]['options'] = array_flip($editor_handler->getList()); |
|
207 | + ++$cpto; |
|
208 | + $modversion['config'][$cpto]['name'] = 'form_options'; |
|
209 | + $modversion['config'][$cpto]['title'] = '_MI_REFERENCES_OPTION2'; |
|
210 | + $modversion['config'][$cpto]['description'] = ''; |
|
211 | + $modversion['config'][$cpto]['formtype'] = 'select'; |
|
212 | + $modversion['config'][$cpto]['valuetype'] = 'text'; |
|
213 | + $modversion['config'][$cpto]['default'] = 'dhtmltextarea'; |
|
214 | + xoops_load('xoopseditorhandler'); |
|
215 | + $editor_handler = XoopsEditorHandler::getInstance(); |
|
216 | + $modversion['config'][$cpto]['options'] = array_flip($editor_handler->getList()); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | $modversion['config'][$cpto]['formtype'] = 'select'; |
371 | 371 | $modversion['config'][$cpto]['valuetype'] = 'text'; |
372 | 372 | $modversion['config'][$cpto]['options'] = array( |
373 | - _MI_REFERENCES_SORT_DATE => 'article_timestamp', |
|
374 | - _MI_REFERENCES_SORT_WEIGHT => 'article_weight' |
|
373 | + _MI_REFERENCES_SORT_DATE => 'article_timestamp', |
|
374 | + _MI_REFERENCES_SORT_WEIGHT => 'article_weight' |
|
375 | 375 | ); |
376 | 376 | $modversion['config'][$cpto]['default'] = 'article_timestamp'; |
377 | 377 | |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | $modversion['config'][$cpto]['formtype'] = 'select'; |
386 | 386 | $modversion['config'][$cpto]['valuetype'] = 'text'; |
387 | 387 | $modversion['config'][$cpto]['options'] = array( |
388 | - _MI_REFERENCES_SORT_ASC => 'ASC', |
|
389 | - _MI_REFERENCES_SORT_DESC => 'DESC' |
|
388 | + _MI_REFERENCES_SORT_ASC => 'ASC', |
|
389 | + _MI_REFERENCES_SORT_DESC => 'DESC' |
|
390 | 390 | ); |
391 | 391 | $modversion['config'][$cpto]['default'] = 'DESC'; |
392 | 392 | |
@@ -400,9 +400,9 @@ discard block |
||
400 | 400 | $modversion['config'][$cpto]['formtype'] = 'select'; |
401 | 401 | $modversion['config'][$cpto]['valuetype'] = 'text'; |
402 | 402 | $modversion['config'][$cpto]['options'] = array( |
403 | - _MI_REFERENCES_SORT_DATE => 'article_timestamp', |
|
404 | - _MI_REFERENCES_SORT_WEIGHT => 'article_weight', |
|
405 | - _MI_REFERENCES_SORT_TITLE => 'article_title' |
|
403 | + _MI_REFERENCES_SORT_DATE => 'article_timestamp', |
|
404 | + _MI_REFERENCES_SORT_WEIGHT => 'article_weight', |
|
405 | + _MI_REFERENCES_SORT_TITLE => 'article_title' |
|
406 | 406 | ); |
407 | 407 | $modversion['config'][$cpto]['default'] = 'article_weight'; |
408 | 408 | |
@@ -416,8 +416,8 @@ discard block |
||
416 | 416 | $modversion['config'][$cpto]['formtype'] = 'select'; |
417 | 417 | $modversion['config'][$cpto]['valuetype'] = 'text'; |
418 | 418 | $modversion['config'][$cpto]['options'] = array( |
419 | - _MI_REFERENCES_SORT_ASC => 'ASC', |
|
420 | - _MI_REFERENCES_SORT_DESC => 'DESC' |
|
419 | + _MI_REFERENCES_SORT_ASC => 'ASC', |
|
420 | + _MI_REFERENCES_SORT_DESC => 'DESC' |
|
421 | 421 | ); |
422 | 422 | $modversion['config'][$cpto]['default'] = 'ASC'; |
423 | 423 |
@@ -21,17 +21,17 @@ discard block |
||
21 | 21 | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
22 | 22 | |
23 | 23 | if (!defined('REFERENCES_DIRNAME')) { |
24 | - define('REFERENCES_DIRNAME', 'references'); |
|
25 | - define('REFERENCES_URL', XOOPS_URL . '/modules/' . REFERENCES_DIRNAME . '/'); |
|
26 | - define('REFERENCES_PATH', XOOPS_ROOT_PATH . '/modules/' . REFERENCES_DIRNAME . '/'); |
|
27 | - define('REFERENCES_IMAGES_URL', REFERENCES_URL . 'assets/images/'); // Les images du module (l'url) |
|
28 | - define('REFERENCES_IMAGES_PATH', REFERENCES_PATH . 'assets/images/'); // Les images du module (le chemin) |
|
29 | - define('REFERENCES_CLASS_PATH', REFERENCES_PATH . 'class/'); |
|
30 | - define('REFERENCES_PLUGINS_PATH', REFERENCES_PATH . 'plugins/'); |
|
31 | - define('REFERENCES_PLUGINS_URL', REFERENCES_URL . 'plugins/'); |
|
32 | - define('REFERENCES_JS_URL', REFERENCES_URL . 'js/'); |
|
33 | - define('REFERENCES_TEXTFILE1', 'references_index.tpl'); |
|
34 | - define('REFERENCES_PERM_READ', 'references_view'); // Nom de la permission de lire |
|
24 | + define('REFERENCES_DIRNAME', 'references'); |
|
25 | + define('REFERENCES_URL', XOOPS_URL . '/modules/' . REFERENCES_DIRNAME . '/'); |
|
26 | + define('REFERENCES_PATH', XOOPS_ROOT_PATH . '/modules/' . REFERENCES_DIRNAME . '/'); |
|
27 | + define('REFERENCES_IMAGES_URL', REFERENCES_URL . 'assets/images/'); // Les images du module (l'url) |
|
28 | + define('REFERENCES_IMAGES_PATH', REFERENCES_PATH . 'assets/images/'); // Les images du module (le chemin) |
|
29 | + define('REFERENCES_CLASS_PATH', REFERENCES_PATH . 'class/'); |
|
30 | + define('REFERENCES_PLUGINS_PATH', REFERENCES_PATH . 'plugins/'); |
|
31 | + define('REFERENCES_PLUGINS_URL', REFERENCES_URL . 'plugins/'); |
|
32 | + define('REFERENCES_JS_URL', REFERENCES_URL . 'js/'); |
|
33 | + define('REFERENCES_TEXTFILE1', 'references_index.tpl'); |
|
34 | + define('REFERENCES_PERM_READ', 'references_view'); // Nom de la permission de lire |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // Chargement des handler et des autres classes |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | |
56 | 56 | // Définition des images |
57 | 57 | if (!defined('_REFERENCES_EDIT')) { |
58 | - global $xoopsConfig; |
|
59 | - if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/main.php')) { |
|
60 | - require REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/main.php'; |
|
61 | - } else { |
|
62 | - require REFERENCES_PATH . 'language/english/main.php'; |
|
63 | - } |
|
58 | + global $xoopsConfig; |
|
59 | + if (isset($xoopsConfig) && file_exists(REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/main.php')) { |
|
60 | + require REFERENCES_PATH . 'language/' . $xoopsConfig['language'] . '/main.php'; |
|
61 | + } else { |
|
62 | + require REFERENCES_PATH . 'language/english/main.php'; |
|
63 | + } |
|
64 | 64 | |
65 | - $icones = array( |
|
66 | - 'edit' => "<img src='" . REFERENCES_IMAGES_URL . "edit.gif' alt='" . _REFERENCES_EDIT . "' align='middle' />", |
|
67 | - 'delete' => "<img src='" . REFERENCES_IMAGES_URL . "delete.gif' alt='" . _REFERENCES_DELETE . "' align='middle' />" |
|
68 | - ); |
|
65 | + $icones = array( |
|
66 | + 'edit' => "<img src='" . REFERENCES_IMAGES_URL . "edit.gif' alt='" . _REFERENCES_EDIT . "' align='middle' />", |
|
67 | + 'delete' => "<img src='" . REFERENCES_IMAGES_URL . "delete.gif' alt='" . _REFERENCES_DELETE . "' align='middle' />" |
|
68 | + ); |
|
69 | 69 | } |
@@ -22,66 +22,66 @@ |
||
22 | 22 | |
23 | 23 | function references_search($queryarray, $andor, $limit, $offset, $userid) |
24 | 24 | { |
25 | - global $xoopsDB; |
|
26 | - include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
25 | + global $xoopsDB; |
|
26 | + include XOOPS_ROOT_PATH . '/modules/references/include/common.php'; |
|
27 | 27 | |
28 | - // Recherche dans les articles |
|
29 | - $sql = 'SELECT article_id, article_title, article_text, article_timestamp, article_author FROM ' . $xoopsDB->prefix('references_articles') . ' WHERE (article_online = ' . REFERENCES_STATUS_ONLINE . ')'; |
|
30 | - // Permissions |
|
31 | - $handlers = references_handler::getInstance(); |
|
32 | - $permissions = $handlers->h_references_articles->getPermissionsCategoriesCriteria()->renderWhere(); |
|
33 | - $sql .= ' AND (' . trim(str_replace('WHERE ', '', $permissions)) . ')'; |
|
34 | - // ***** |
|
28 | + // Recherche dans les articles |
|
29 | + $sql = 'SELECT article_id, article_title, article_text, article_timestamp, article_author FROM ' . $xoopsDB->prefix('references_articles') . ' WHERE (article_online = ' . REFERENCES_STATUS_ONLINE . ')'; |
|
30 | + // Permissions |
|
31 | + $handlers = references_handler::getInstance(); |
|
32 | + $permissions = $handlers->h_references_articles->getPermissionsCategoriesCriteria()->renderWhere(); |
|
33 | + $sql .= ' AND (' . trim(str_replace('WHERE ', '', $permissions)) . ')'; |
|
34 | + // ***** |
|
35 | 35 | |
36 | - // Auteur |
|
37 | - if ($userid != 0) { |
|
38 | - $sql .= ' AND (article_author = ' . $userid . ') '; |
|
39 | - } |
|
36 | + // Auteur |
|
37 | + if ($userid != 0) { |
|
38 | + $sql .= ' AND (article_author = ' . $userid . ') '; |
|
39 | + } |
|
40 | 40 | |
41 | - $tmpObject = new references_articles(); |
|
42 | - $datas = $tmpObject->getVars(); |
|
43 | - $tblFields = array(); |
|
44 | - $cnt = 0; |
|
45 | - foreach ($datas as $key => $value) { |
|
46 | - if ($value['data_type'] == XOBJ_DTYPE_TXTBOX || $value['data_type'] == XOBJ_DTYPE_TXTAREA) { |
|
47 | - if ($cnt == 0) { |
|
48 | - $tblFields[] = $key; |
|
49 | - } else { |
|
50 | - $tblFields[] = ' OR ' . $key; |
|
51 | - } |
|
52 | - ++$cnt; |
|
53 | - } |
|
54 | - } |
|
41 | + $tmpObject = new references_articles(); |
|
42 | + $datas = $tmpObject->getVars(); |
|
43 | + $tblFields = array(); |
|
44 | + $cnt = 0; |
|
45 | + foreach ($datas as $key => $value) { |
|
46 | + if ($value['data_type'] == XOBJ_DTYPE_TXTBOX || $value['data_type'] == XOBJ_DTYPE_TXTAREA) { |
|
47 | + if ($cnt == 0) { |
|
48 | + $tblFields[] = $key; |
|
49 | + } else { |
|
50 | + $tblFields[] = ' OR ' . $key; |
|
51 | + } |
|
52 | + ++$cnt; |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - $count = count($queryarray); |
|
57 | - $more = ''; |
|
58 | - if (is_array($queryarray) && $count > 0) { |
|
59 | - $cnt = 0; |
|
60 | - $sql .= ' AND ('; |
|
61 | - $more = ')'; |
|
62 | - foreach ($queryarray as $oneQuery) { |
|
63 | - $sql .= '('; |
|
64 | - $cond = " LIKE '%" . $oneQuery . "%' "; |
|
65 | - $sql .= implode($cond, $tblFields) . $cond . ')'; |
|
66 | - ++$cnt; |
|
67 | - if ($cnt != $count) { |
|
68 | - $sql .= ' ' . $andor . ' '; |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - $sql .= $more . ' ORDER BY article_timestamp DESC'; |
|
73 | - $i = 0; |
|
74 | - $ret = array(); |
|
75 | - $myts = MyTextSanitizer::getInstance(); |
|
76 | - $result = $xoopsDB->query($sql, $limit, $offset); |
|
77 | - while ($myrow = $xoopsDB->fetchArray($result)) { |
|
78 | - $ret[$i]['image'] = 'assets/images/newspaper.png'; |
|
79 | - $ret[$i]['link'] = REFERENCES_URL . 'reference.php?article_id=' . $myrow['article_id']; |
|
80 | - $ret[$i]['title'] = $myts->htmlSpecialChars($myrow['article_title']); |
|
81 | - $ret[$i]['time'] = $myrow['article_timestamp']; |
|
82 | - $ret[$i]['uid'] = $myrow['article_author']; |
|
83 | - ++$i; |
|
84 | - } |
|
56 | + $count = count($queryarray); |
|
57 | + $more = ''; |
|
58 | + if (is_array($queryarray) && $count > 0) { |
|
59 | + $cnt = 0; |
|
60 | + $sql .= ' AND ('; |
|
61 | + $more = ')'; |
|
62 | + foreach ($queryarray as $oneQuery) { |
|
63 | + $sql .= '('; |
|
64 | + $cond = " LIKE '%" . $oneQuery . "%' "; |
|
65 | + $sql .= implode($cond, $tblFields) . $cond . ')'; |
|
66 | + ++$cnt; |
|
67 | + if ($cnt != $count) { |
|
68 | + $sql .= ' ' . $andor . ' '; |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + $sql .= $more . ' ORDER BY article_timestamp DESC'; |
|
73 | + $i = 0; |
|
74 | + $ret = array(); |
|
75 | + $myts = MyTextSanitizer::getInstance(); |
|
76 | + $result = $xoopsDB->query($sql, $limit, $offset); |
|
77 | + while ($myrow = $xoopsDB->fetchArray($result)) { |
|
78 | + $ret[$i]['image'] = 'assets/images/newspaper.png'; |
|
79 | + $ret[$i]['link'] = REFERENCES_URL . 'reference.php?article_id=' . $myrow['article_id']; |
|
80 | + $ret[$i]['title'] = $myts->htmlSpecialChars($myrow['article_title']); |
|
81 | + $ret[$i]['time'] = $myrow['article_timestamp']; |
|
82 | + $ret[$i]['uid'] = $myrow['article_author']; |
|
83 | + ++$i; |
|
84 | + } |
|
85 | 85 | |
86 | - return $ret; |
|
86 | + return $ret; |
|
87 | 87 | } |
@@ -28,111 +28,111 @@ |
||
28 | 28 | */ |
29 | 29 | class referencesTwitterAction extends references_action |
30 | 30 | { |
31 | - public function registerEvents() |
|
32 | - { |
|
33 | - /** |
|
34 | - * La liste des évènements traités par le plugin se présente sous la forme d'un tableau compposé comme ceci : |
|
35 | - * |
|
36 | - * Indice Signification |
|
37 | - * ---------------------- |
|
38 | - * 0 Evènement sur lequel se raccrocher (voir class/references_plugins.php::EVENT_ON_PRODUCT_CREATE |
|
39 | - * 1 Priorité du plugin (de 1 à 5) |
|
40 | - * 2 Script Php à inclure |
|
41 | - * 3 Classe à instancier |
|
42 | - * 4 Méthode à appeler |
|
43 | - */ |
|
44 | - $events = array(); |
|
45 | - $events[] = array( |
|
46 | - references_plugins::EVENT_ON_REFERENCE_CREATE, |
|
47 | - references_plugins::EVENT_PRIORITY_1, |
|
48 | - basename(__FILE__), |
|
49 | - __CLASS__, |
|
50 | - 'fireNewReference' |
|
51 | - ); |
|
52 | - $events[] = array( |
|
53 | - references_plugins::EVENT_ON_CATEGORY_CREATE, |
|
54 | - references_plugins::EVENT_PRIORITY_1, |
|
55 | - basename(__FILE__), |
|
56 | - __CLASS__, |
|
57 | - 'fireNewCategory' |
|
58 | - ); |
|
59 | - return $events; |
|
60 | - } |
|
31 | + public function registerEvents() |
|
32 | + { |
|
33 | + /** |
|
34 | + * La liste des évènements traités par le plugin se présente sous la forme d'un tableau compposé comme ceci : |
|
35 | + * |
|
36 | + * Indice Signification |
|
37 | + * ---------------------- |
|
38 | + * 0 Evènement sur lequel se raccrocher (voir class/references_plugins.php::EVENT_ON_PRODUCT_CREATE |
|
39 | + * 1 Priorité du plugin (de 1 à 5) |
|
40 | + * 2 Script Php à inclure |
|
41 | + * 3 Classe à instancier |
|
42 | + * 4 Méthode à appeler |
|
43 | + */ |
|
44 | + $events = array(); |
|
45 | + $events[] = array( |
|
46 | + references_plugins::EVENT_ON_REFERENCE_CREATE, |
|
47 | + references_plugins::EVENT_PRIORITY_1, |
|
48 | + basename(__FILE__), |
|
49 | + __CLASS__, |
|
50 | + 'fireNewReference' |
|
51 | + ); |
|
52 | + $events[] = array( |
|
53 | + references_plugins::EVENT_ON_CATEGORY_CREATE, |
|
54 | + references_plugins::EVENT_PRIORITY_1, |
|
55 | + basename(__FILE__), |
|
56 | + __CLASS__, |
|
57 | + 'fireNewCategory' |
|
58 | + ); |
|
59 | + return $events; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Méthode générique chargée d'envoyer un texte sur un compte twitter avec une url |
|
64 | - * |
|
65 | - * @param string $textToSend Le texte à envoyer |
|
66 | - * @param string $mask Le masque à utiliser |
|
67 | - * @param string $elementUrl L'url de l'élément concerné |
|
68 | - * @return string Le texte qui a été envoyé à twitter |
|
69 | - */ |
|
70 | - private function sendTextToTwitter($textToSend, $mask, $elementUrl) |
|
71 | - { |
|
72 | - if (!defined('REFERENCES_TWITTER_PLUGIN_PATH')) { |
|
73 | - define('REFERENCES_TWITTER_PLUGIN_PATH', REFERENCES_PLUGINS_PATH . 'actions' . DIRECTORY_SEPARATOR . 'twitter' . DIRECTORY_SEPARATOR); |
|
74 | - } |
|
75 | - require_once REFERENCES_TWITTER_PLUGIN_PATH . 'config.php'; |
|
76 | - //require_once REFERENCES_TWITTER_PLUGIN_PATH.'twitter.php'; |
|
77 | - require_once REFERENCES_TWITTER_PLUGIN_PATH . 'Twitter.class.php'; |
|
78 | - require_once REFERENCES_TWITTER_PLUGIN_PATH . 'bitly.class.php'; |
|
79 | - if (REFERENCES_BITLY_LOGIN == '') { |
|
80 | - return ''; |
|
81 | - } |
|
82 | - $sentText = ''; |
|
83 | - $bitly = new Bitly(REFERENCES_BITLY_LOGIN, REFERENCES_BITLY_API_KEY); |
|
84 | - $shortUrl = $bitly->shortenSingle($elementUrl); |
|
85 | - $searches = array('[itemname]', '[url]'); |
|
86 | - $replaces = array($textToSend, $shortUrl); |
|
87 | - $sentText = str_replace($searches, $replaces, $mask); |
|
88 | - $totalLength = strlen($sentText); |
|
89 | - if ($totalLength > REFERENCES_TWITTER_TWIT_MAX_LENGTH) { |
|
90 | - $tooLongOf = $totalLength - REFERENCES_TWITTER_TWIT_MAX_LENGTH; |
|
91 | - $searches = array('[itemname]', '[url]'); |
|
92 | - $replaces = array(substr($textToSend, 0, strlen($textToSend) - $tooLongOf), $shortUrl); |
|
93 | - $sentText = str_replace($searches, $replaces, $mask); |
|
94 | - } |
|
95 | - if (trim($sentText) != '') { |
|
96 | - // $twitter = new Twitter(REFERENCES_TWITTER_USERNAME, REFERENCES_TWITTER_PASSWORD); |
|
97 | - // $twitter->setUserAgent('references'); |
|
98 | - // $twitter->updateStatus($sentText); |
|
99 | - $tweet = new Twitter(REFERENCES_TWITTER_USERNAME, REFERENCES_TWITTER_PASSWORD); |
|
100 | - $tweet->update($sentText); |
|
101 | - } |
|
102 | - return $sentText; |
|
103 | - } |
|
62 | + /** |
|
63 | + * Méthode générique chargée d'envoyer un texte sur un compte twitter avec une url |
|
64 | + * |
|
65 | + * @param string $textToSend Le texte à envoyer |
|
66 | + * @param string $mask Le masque à utiliser |
|
67 | + * @param string $elementUrl L'url de l'élément concerné |
|
68 | + * @return string Le texte qui a été envoyé à twitter |
|
69 | + */ |
|
70 | + private function sendTextToTwitter($textToSend, $mask, $elementUrl) |
|
71 | + { |
|
72 | + if (!defined('REFERENCES_TWITTER_PLUGIN_PATH')) { |
|
73 | + define('REFERENCES_TWITTER_PLUGIN_PATH', REFERENCES_PLUGINS_PATH . 'actions' . DIRECTORY_SEPARATOR . 'twitter' . DIRECTORY_SEPARATOR); |
|
74 | + } |
|
75 | + require_once REFERENCES_TWITTER_PLUGIN_PATH . 'config.php'; |
|
76 | + //require_once REFERENCES_TWITTER_PLUGIN_PATH.'twitter.php'; |
|
77 | + require_once REFERENCES_TWITTER_PLUGIN_PATH . 'Twitter.class.php'; |
|
78 | + require_once REFERENCES_TWITTER_PLUGIN_PATH . 'bitly.class.php'; |
|
79 | + if (REFERENCES_BITLY_LOGIN == '') { |
|
80 | + return ''; |
|
81 | + } |
|
82 | + $sentText = ''; |
|
83 | + $bitly = new Bitly(REFERENCES_BITLY_LOGIN, REFERENCES_BITLY_API_KEY); |
|
84 | + $shortUrl = $bitly->shortenSingle($elementUrl); |
|
85 | + $searches = array('[itemname]', '[url]'); |
|
86 | + $replaces = array($textToSend, $shortUrl); |
|
87 | + $sentText = str_replace($searches, $replaces, $mask); |
|
88 | + $totalLength = strlen($sentText); |
|
89 | + if ($totalLength > REFERENCES_TWITTER_TWIT_MAX_LENGTH) { |
|
90 | + $tooLongOf = $totalLength - REFERENCES_TWITTER_TWIT_MAX_LENGTH; |
|
91 | + $searches = array('[itemname]', '[url]'); |
|
92 | + $replaces = array(substr($textToSend, 0, strlen($textToSend) - $tooLongOf), $shortUrl); |
|
93 | + $sentText = str_replace($searches, $replaces, $mask); |
|
94 | + } |
|
95 | + if (trim($sentText) != '') { |
|
96 | + // $twitter = new Twitter(REFERENCES_TWITTER_USERNAME, REFERENCES_TWITTER_PASSWORD); |
|
97 | + // $twitter->setUserAgent('references'); |
|
98 | + // $twitter->updateStatus($sentText); |
|
99 | + $tweet = new Twitter(REFERENCES_TWITTER_USERNAME, REFERENCES_TWITTER_PASSWORD); |
|
100 | + $tweet->update($sentText); |
|
101 | + } |
|
102 | + return $sentText; |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Méthode appelée pour indiquer qu'une nouvelle référence a été publié |
|
107 | - * |
|
108 | - * @param object $parameters La référence qui vient d'être publiée |
|
109 | - * @return void |
|
110 | - */ |
|
111 | - public function fireNewReference($parameters) |
|
112 | - { |
|
113 | - if (!defined('REFERENCES_TWITTER_PLUGIN_PATH')) { |
|
114 | - define('REFERENCES_TWITTER_PLUGIN_PATH', REFERENCES_PLUGINS_PATH . 'actions' . DIRECTORY_SEPARATOR . 'twitter' . DIRECTORY_SEPARATOR); |
|
115 | - } |
|
116 | - require_once REFERENCES_TWITTER_PLUGIN_PATH . 'config.php'; |
|
117 | - $reference = $parameters['reference']; |
|
118 | - $this->sendTextToTwitter(utf8_encode($reference->getVar('article_title', 'n')), utf8_encode(REFERENCES_TWITTER_NEW_REFERENCE_INTRO), $reference->getUrl()); |
|
119 | - } |
|
105 | + /** |
|
106 | + * Méthode appelée pour indiquer qu'une nouvelle référence a été publié |
|
107 | + * |
|
108 | + * @param object $parameters La référence qui vient d'être publiée |
|
109 | + * @return void |
|
110 | + */ |
|
111 | + public function fireNewReference($parameters) |
|
112 | + { |
|
113 | + if (!defined('REFERENCES_TWITTER_PLUGIN_PATH')) { |
|
114 | + define('REFERENCES_TWITTER_PLUGIN_PATH', REFERENCES_PLUGINS_PATH . 'actions' . DIRECTORY_SEPARATOR . 'twitter' . DIRECTORY_SEPARATOR); |
|
115 | + } |
|
116 | + require_once REFERENCES_TWITTER_PLUGIN_PATH . 'config.php'; |
|
117 | + $reference = $parameters['reference']; |
|
118 | + $this->sendTextToTwitter(utf8_encode($reference->getVar('article_title', 'n')), utf8_encode(REFERENCES_TWITTER_NEW_REFERENCE_INTRO), $reference->getUrl()); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Méthode appelée pour indiquer qu'une nouvelle catégorie de références a été créée |
|
123 | - * |
|
124 | - * @param object $parameters La catégorie qui vient d'être publiée |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public function fireNewCategory($parameters) |
|
128 | - { |
|
129 | - if (!defined('REFERENCES_TWITTER_PLUGIN_PATH')) { |
|
130 | - define('REFERENCES_TWITTER_PLUGIN_PATH', REFERENCES_PLUGINS_PATH . 'actions' . DIRECTORY_SEPARATOR . 'twitter' . DIRECTORY_SEPARATOR); |
|
131 | - } |
|
132 | - require_once REFERENCES_TWITTER_PLUGIN_PATH . 'config.php'; |
|
133 | - if (trim(REFERENCES_TWITTER_NEW_CATEGORY_INTRO) != '') { |
|
134 | - $category = $parameters['category']; |
|
135 | - $this->sendTextToTwitter(utf8_encode($category->getVar('category_title', 'n')), utf8_encode(REFERENCES_TWITTER_NEW_CATEGORY_INTRO), $category->getUrl()); |
|
136 | - } |
|
137 | - } |
|
121 | + /** |
|
122 | + * Méthode appelée pour indiquer qu'une nouvelle catégorie de références a été créée |
|
123 | + * |
|
124 | + * @param object $parameters La catégorie qui vient d'être publiée |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public function fireNewCategory($parameters) |
|
128 | + { |
|
129 | + if (!defined('REFERENCES_TWITTER_PLUGIN_PATH')) { |
|
130 | + define('REFERENCES_TWITTER_PLUGIN_PATH', REFERENCES_PLUGINS_PATH . 'actions' . DIRECTORY_SEPARATOR . 'twitter' . DIRECTORY_SEPARATOR); |
|
131 | + } |
|
132 | + require_once REFERENCES_TWITTER_PLUGIN_PATH . 'config.php'; |
|
133 | + if (trim(REFERENCES_TWITTER_NEW_CATEGORY_INTRO) != '') { |
|
134 | + $category = $parameters['category']; |
|
135 | + $this->sendTextToTwitter(utf8_encode($category->getVar('category_title', 'n')), utf8_encode(REFERENCES_TWITTER_NEW_CATEGORY_INTRO), $category->getUrl()); |
|
136 | + } |
|
137 | + } |
|
138 | 138 | } |
@@ -26,9 +26,9 @@ |
||
26 | 26 | |
27 | 27 | abstract class references_action |
28 | 28 | { |
29 | - /** |
|
30 | - * Retourne la liste des évènements traités par le plugin |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - abstract public function registerEvents(); |
|
29 | + /** |
|
30 | + * Retourne la liste des évènements traités par le plugin |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + abstract public function registerEvents(); |
|
34 | 34 | } |
@@ -26,9 +26,9 @@ |
||
26 | 26 | |
27 | 27 | abstract class references_filter |
28 | 28 | { |
29 | - /** |
|
30 | - * Retourne la liste des évènements traités par le plugin |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - abstract public function registerEvents(); |
|
29 | + /** |
|
30 | + * Retourne la liste des évènements traités par le plugin |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + abstract public function registerEvents(); |
|
34 | 34 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
24 | 24 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
25 | - require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
25 | + require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | define('REFERENCES_STATUS_ONLINE', 1); // Articles en ligne |
@@ -30,610 +30,610 @@ discard block |
||
30 | 30 | |
31 | 31 | class references_articles extends references_Object |
32 | 32 | { |
33 | - public function __construct() |
|
34 | - { |
|
35 | - $this->initVar('article_id', XOBJ_DTYPE_INT, null, false); |
|
36 | - $this->initVar('article_category_id', XOBJ_DTYPE_INT, null, false); |
|
37 | - $this->initVar('article_timestamp', XOBJ_DTYPE_INT, null, false); |
|
38 | - $this->initVar('article_weight', XOBJ_DTYPE_INT, null, false); |
|
39 | - $this->initVar('article_date', XOBJ_DTYPE_TXTBOX, null, false); |
|
40 | - $this->initVar('article_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
41 | - $this->initVar('article_text', XOBJ_DTYPE_TXTAREA, null, false); |
|
42 | - $this->initVar('article_externalurl', XOBJ_DTYPE_TXTBOX, null, false); |
|
43 | - $this->initVar('article_picture1', XOBJ_DTYPE_TXTBOX, null, false); |
|
44 | - $this->initVar('article_picture1_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
45 | - $this->initVar('article_picture2', XOBJ_DTYPE_TXTBOX, null, false); |
|
46 | - $this->initVar('article_picture2_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
47 | - $this->initVar('article_picture3', XOBJ_DTYPE_TXTBOX, null, false); |
|
48 | - $this->initVar('article_picture3_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
49 | - $this->initVar('article_picture4', XOBJ_DTYPE_TXTBOX, null, false); |
|
50 | - $this->initVar('article_picture4_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
51 | - $this->initVar('article_picture5', XOBJ_DTYPE_TXTBOX, null, false); |
|
52 | - $this->initVar('article_picture5_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
53 | - $this->initVar('article_picture6', XOBJ_DTYPE_TXTBOX, null, false); |
|
54 | - $this->initVar('article_picture6_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
55 | - $this->initVar('article_picture7', XOBJ_DTYPE_TXTBOX, null, false); |
|
56 | - $this->initVar('article_picture7_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
57 | - $this->initVar('article_picture8', XOBJ_DTYPE_TXTBOX, null, false); |
|
58 | - $this->initVar('article_picture8_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
59 | - $this->initVar('article_picture9', XOBJ_DTYPE_TXTBOX, null, false); |
|
60 | - $this->initVar('article_picture9_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
61 | - $this->initVar('article_picture10', XOBJ_DTYPE_TXTBOX, null, false); |
|
62 | - $this->initVar('article_picture10_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
63 | - $this->initVar('article_author', XOBJ_DTYPE_INT, null, false); |
|
64 | - $this->initVar('article_online', XOBJ_DTYPE_INT, null, false); |
|
65 | - $this->initVar('article_attached_file', XOBJ_DTYPE_TXTBOX, null, false); |
|
66 | - $this->initVar('article_readmore', XOBJ_DTYPE_TXTAREA, null, false); |
|
67 | - |
|
68 | - // Pour autoriser le html |
|
69 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Indique si l'article en cours est visible |
|
74 | - * |
|
75 | - * @return boolean |
|
76 | - */ |
|
77 | - public function isArticleOnline() |
|
78 | - { |
|
79 | - return $this->getVar('article_online') == REFERENCES_STATUS_ONLINE ? true : false; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Retourne une image qui indique si l'article est en ligne ou pas |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function getOnlinePicture() |
|
88 | - { |
|
89 | - if ($this->isArticleOnline()) { |
|
90 | - return REFERENCES_IMAGES_URL . 'status_online.png'; |
|
91 | - } else { |
|
92 | - return REFERENCES_IMAGES_URL . 'status_offline.png'; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
98 | - * |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - public function getHrefTitle() |
|
102 | - { |
|
103 | - return references_utils::makeHrefTitle($this->getVar('article_title')); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Indique si une image de l'article existe |
|
108 | - * |
|
109 | - * @param integer $indice L'indice de l'image recherchée |
|
110 | - * @return boolean Vrai si l'image existe sinon faux |
|
111 | - */ |
|
112 | - public function pictureExists($indice) |
|
113 | - { |
|
114 | - $return = false; |
|
115 | - $fieldName = 'article_picture' . $indice; |
|
116 | - if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName))) { |
|
117 | - $return = true; |
|
118 | - } |
|
119 | - |
|
120 | - return $return; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Supprime l'image associée à un article |
|
125 | - * |
|
126 | - * @param integer $indice L'indice de l'image recherchée |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public function deletePicture($indice) |
|
130 | - { |
|
131 | - $fieldName = 'article_picture' . $indice; |
|
132 | - if ($this->pictureExists($indice)) { |
|
133 | - @unlink(references_utils::getModuleOption('images_path') . references_utils::getModuleOption('images_path') . $this->getVar($fieldName)); |
|
134 | - } |
|
135 | - $this->setVar($fieldName, ''); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Retourne l'URL de l'image de l'article courant |
|
140 | - * |
|
141 | - * @param integer $indice L'indice de l'image recherchée |
|
142 | - * @return string L'URL |
|
143 | - */ |
|
144 | - public function getPictureUrl($indice) |
|
145 | - { |
|
146 | - $fieldName = 'article_picture' . $indice; |
|
147 | - if (xoops_trim($this->getVar($fieldName)) != '' && $this->pictureExists($indice)) { |
|
148 | - return references_utils::getModuleOption('images_url') . '/' . $this->getVar($fieldName); |
|
149 | - } else { |
|
150 | - return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Retourne le chemin de l'image de l'article courante |
|
156 | - * |
|
157 | - * @param integer $indice L'indice de l'image recherchée |
|
158 | - * @return string Le chemin |
|
159 | - */ |
|
160 | - public function getPicturePath($indice) |
|
161 | - { |
|
162 | - $fieldName = 'article_picture' . $indice; |
|
163 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
164 | - return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName); |
|
165 | - } else { |
|
166 | - return ''; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Indique si la vignette de l'image de l'article existe |
|
172 | - * |
|
173 | - * @param integer $indice L'indice de l'image recherchée |
|
174 | - * @return boolean Vrai si l'image existe sinon faux |
|
175 | - */ |
|
176 | - public function thumbExists($indice) |
|
177 | - { |
|
178 | - $fieldName = 'article_picture' . $indice; |
|
179 | - $return = false; |
|
180 | - if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName))) { |
|
181 | - $return = true; |
|
182 | - } |
|
183 | - |
|
184 | - return $return; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Retourne l'URL de la vignette de l'article |
|
189 | - * |
|
190 | - * @param integer $indice L'indice de l'image recherchée |
|
191 | - * @return string L'URL |
|
192 | - */ |
|
193 | - public function getThumbUrl($indice) |
|
194 | - { |
|
195 | - $fieldName = 'article_picture' . $indice; |
|
196 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
197 | - return references_utils::getModuleOption('images_url') . '/' . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
198 | - } else { |
|
199 | - return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Retourne le chemin de la vignette de l'annonce |
|
205 | - * |
|
206 | - * @param integer $indice L'indice de l'image recherchée |
|
207 | - * @return string L'URL |
|
208 | - */ |
|
209 | - public function getThumbPath($indice) |
|
210 | - { |
|
211 | - $fieldName = 'article_picture' . $indice; |
|
212 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
213 | - return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
214 | - } else { |
|
215 | - return ''; |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Indique si le fichier attaché à un article existe |
|
221 | - * |
|
222 | - * @return boolean |
|
223 | - */ |
|
224 | - public function attachmentExists() |
|
225 | - { |
|
226 | - $return = false; |
|
227 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'))) { |
|
228 | - $return = true; |
|
229 | - } |
|
230 | - |
|
231 | - return $return; |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Retourne l'URL du fichier attaché |
|
236 | - * |
|
237 | - * @return string L'url du fichier attaché sinon une chaine vide |
|
238 | - */ |
|
239 | - public function getAttachmentUrl() |
|
240 | - { |
|
241 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
242 | - return references_utils::getModuleOption('attached_url') . '/' . $this->getVar('article_attached_file'); |
|
243 | - } else { |
|
244 | - return ''; |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Retourne le chemin du fichier attaché |
|
250 | - * |
|
251 | - * @return string Le chemin du fichier attaché sinon une chaine vide |
|
252 | - */ |
|
253 | - public function getAttachmentPath() |
|
254 | - { |
|
255 | - if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
256 | - return references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'); |
|
257 | - } else { |
|
258 | - return ''; |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Supprime le fichier attaché à un article |
|
264 | - */ |
|
265 | - public function deleteAttachment() |
|
266 | - { |
|
267 | - if ($this->attachmentExists()) { |
|
268 | - @unlink(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file')); |
|
269 | - } |
|
270 | - $this->setVar('article_attached_file', ''); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Supprime la miniature associée à l'article |
|
275 | - * |
|
276 | - * @param integer $indice L'indice de l'image recherchée |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - public function deleteThumb($indice) |
|
280 | - { |
|
281 | - $fieldName = 'article_picture' . $indice; |
|
282 | - if ($this->thumbExists($indice)) { |
|
283 | - @unlink(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName)); |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Supprime l'image (et vignette) d'un article (raccourcis) |
|
289 | - * |
|
290 | - * @return void |
|
291 | - */ |
|
292 | - public function deletePicturesAndThumbs() |
|
293 | - { |
|
294 | - for ($i = 1; $i <= 10; ++$i) { |
|
295 | - $this->deleteThumb($i); |
|
296 | - $this->deletePicture($i); |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Retourne le timestamp de création formaté |
|
302 | - * |
|
303 | - * @return string |
|
304 | - */ |
|
305 | - public function getFormatedTimeStamp() |
|
306 | - { |
|
307 | - return formatTimestamp($this->getVar('article_timestamp'), 's'); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Indique s'il existe au moins une image pour l'article |
|
312 | - * |
|
313 | - * @return boolean |
|
314 | - */ |
|
315 | - public function isThereAPicture() |
|
316 | - { |
|
317 | - for ($i = 1; $i <= 10; ++$i) { |
|
318 | - if ($this->pictureExists($i)) { |
|
319 | - return true; |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - return false; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Inidique s'il existe au moins une vignette pour l'article |
|
328 | - * |
|
329 | - * @return boolean |
|
330 | - */ |
|
331 | - public function isThereAThumb() |
|
332 | - { |
|
333 | - for ($i = 1; $i <= 10; ++$i) { |
|
334 | - if ($this->thumbExists($i)) { |
|
335 | - return true; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - return false; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Retourne l'url pour atteindre l'élément |
|
344 | - * |
|
345 | - * @param bool $shortVersion |
|
346 | - * @return string |
|
347 | - */ |
|
348 | - public function getUrl($shortVersion = false) |
|
349 | - { |
|
350 | - if (!$shortVersion) { |
|
351 | - return REFERENCES_URL . 'reference.php?article_id=' . $this->getVar('article_id'); |
|
352 | - } else { |
|
353 | - return 'reference.php?article_id=' . $this->getVar('article_id'); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Retourne les éléments de l'annnonce formatés pour affichage |
|
359 | - * |
|
360 | - * @param string $format Format à utiliser |
|
361 | - * @return array |
|
362 | - */ |
|
363 | - public function toArray($format = 's') |
|
364 | - { |
|
365 | - $ret = array(); |
|
366 | - $ret = parent::toArray($format); |
|
367 | - $hrefTitle = $this->getHrefTitle(); |
|
368 | - $ret['article_href_title'] = $hrefTitle; |
|
369 | - $ret['article_url'] = $this->getUrl(); |
|
370 | - // Indique si une annonce est expirée |
|
371 | - $ret['article_is_online'] = $this->isArticleOnline(); |
|
372 | - if ($this->isThereAPicture()) { |
|
373 | - $ret['article_picture_exists'] = true; |
|
374 | - for ($i = 1; $i <= 10; ++$i) { |
|
375 | - if ($this->pictureExists($i)) { |
|
376 | - $ret['article_picture_url' . $i] = $this->getPictureUrl($i); |
|
377 | - $ret['article_picture_path' . $i] = $this->getPicturePath($i); |
|
378 | - $ret['article_pictures_urls'][] = $this->getPictureUrl($i); |
|
379 | - $ret['article_pictures_paths'][] = $this->getPicturePath($i); |
|
380 | - $fieldName = 'article_picture' . $i . '_text'; |
|
381 | - if (xoops_trim($this->getVar($fieldName)) != '') { |
|
382 | - $ret['article_pictures_texts'][] = references_utils::makeHrefTitle($this->getVar($fieldName)); |
|
383 | - } else { |
|
384 | - $ret['article_pictures_texts'][] = $hrefTitle; |
|
385 | - } |
|
386 | - } |
|
387 | - } |
|
388 | - } else { |
|
389 | - $ret['article_picture_exists'] = false; |
|
390 | - } |
|
391 | - $ret['article_short_text'] = references_utils::truncate_tagsafe($this->getVar('article_text'), REFERENCES_SHORTEN_TEXT); |
|
392 | - |
|
393 | - if ($this->attachmentExists()) { |
|
394 | - $ret['article_attachment_exists'] = true; |
|
395 | - $ret['article_attachment_url'] = $this->getAttachmentUrl(); |
|
396 | - $ret['article_attachment_path'] = $this->getAttachmentPath(); |
|
397 | - } else { |
|
398 | - $ret['attachment_exists'] = false; |
|
399 | - } |
|
400 | - |
|
401 | - if ($this->isThereAThumb()) { |
|
402 | - $ret['article_thumb_exists'] = true; |
|
403 | - for ($i = 1; $i <= 10; ++$i) { |
|
404 | - if ($this->thumbExists($i)) { |
|
405 | - $ret['article_thumb_url' . $i] = $this->getThumbUrl($i); |
|
406 | - $ret['article_thumb_path' . $i] = $this->getThumbPath($i); |
|
407 | - $ret['article_thumbs_urls'][] = $this->getThumbUrl($i); |
|
408 | - $ret['article_thumbs_paths'][] = $this->getThumbPath($i); |
|
409 | - } |
|
410 | - } |
|
411 | - } else { |
|
412 | - $ret['article_thumb_exists'] = false; |
|
413 | - } |
|
414 | - |
|
415 | - $ret['article_timestamp_formated'] = $this->getFormatedTimeStamp(); |
|
416 | - |
|
417 | - return $ret; |
|
418 | - } |
|
33 | + public function __construct() |
|
34 | + { |
|
35 | + $this->initVar('article_id', XOBJ_DTYPE_INT, null, false); |
|
36 | + $this->initVar('article_category_id', XOBJ_DTYPE_INT, null, false); |
|
37 | + $this->initVar('article_timestamp', XOBJ_DTYPE_INT, null, false); |
|
38 | + $this->initVar('article_weight', XOBJ_DTYPE_INT, null, false); |
|
39 | + $this->initVar('article_date', XOBJ_DTYPE_TXTBOX, null, false); |
|
40 | + $this->initVar('article_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
41 | + $this->initVar('article_text', XOBJ_DTYPE_TXTAREA, null, false); |
|
42 | + $this->initVar('article_externalurl', XOBJ_DTYPE_TXTBOX, null, false); |
|
43 | + $this->initVar('article_picture1', XOBJ_DTYPE_TXTBOX, null, false); |
|
44 | + $this->initVar('article_picture1_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
45 | + $this->initVar('article_picture2', XOBJ_DTYPE_TXTBOX, null, false); |
|
46 | + $this->initVar('article_picture2_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
47 | + $this->initVar('article_picture3', XOBJ_DTYPE_TXTBOX, null, false); |
|
48 | + $this->initVar('article_picture3_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
49 | + $this->initVar('article_picture4', XOBJ_DTYPE_TXTBOX, null, false); |
|
50 | + $this->initVar('article_picture4_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
51 | + $this->initVar('article_picture5', XOBJ_DTYPE_TXTBOX, null, false); |
|
52 | + $this->initVar('article_picture5_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
53 | + $this->initVar('article_picture6', XOBJ_DTYPE_TXTBOX, null, false); |
|
54 | + $this->initVar('article_picture6_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
55 | + $this->initVar('article_picture7', XOBJ_DTYPE_TXTBOX, null, false); |
|
56 | + $this->initVar('article_picture7_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
57 | + $this->initVar('article_picture8', XOBJ_DTYPE_TXTBOX, null, false); |
|
58 | + $this->initVar('article_picture8_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
59 | + $this->initVar('article_picture9', XOBJ_DTYPE_TXTBOX, null, false); |
|
60 | + $this->initVar('article_picture9_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
61 | + $this->initVar('article_picture10', XOBJ_DTYPE_TXTBOX, null, false); |
|
62 | + $this->initVar('article_picture10_text', XOBJ_DTYPE_TXTBOX, null, false); |
|
63 | + $this->initVar('article_author', XOBJ_DTYPE_INT, null, false); |
|
64 | + $this->initVar('article_online', XOBJ_DTYPE_INT, null, false); |
|
65 | + $this->initVar('article_attached_file', XOBJ_DTYPE_TXTBOX, null, false); |
|
66 | + $this->initVar('article_readmore', XOBJ_DTYPE_TXTAREA, null, false); |
|
67 | + |
|
68 | + // Pour autoriser le html |
|
69 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Indique si l'article en cours est visible |
|
74 | + * |
|
75 | + * @return boolean |
|
76 | + */ |
|
77 | + public function isArticleOnline() |
|
78 | + { |
|
79 | + return $this->getVar('article_online') == REFERENCES_STATUS_ONLINE ? true : false; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Retourne une image qui indique si l'article est en ligne ou pas |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function getOnlinePicture() |
|
88 | + { |
|
89 | + if ($this->isArticleOnline()) { |
|
90 | + return REFERENCES_IMAGES_URL . 'status_online.png'; |
|
91 | + } else { |
|
92 | + return REFERENCES_IMAGES_URL . 'status_offline.png'; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
98 | + * |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + public function getHrefTitle() |
|
102 | + { |
|
103 | + return references_utils::makeHrefTitle($this->getVar('article_title')); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Indique si une image de l'article existe |
|
108 | + * |
|
109 | + * @param integer $indice L'indice de l'image recherchée |
|
110 | + * @return boolean Vrai si l'image existe sinon faux |
|
111 | + */ |
|
112 | + public function pictureExists($indice) |
|
113 | + { |
|
114 | + $return = false; |
|
115 | + $fieldName = 'article_picture' . $indice; |
|
116 | + if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName))) { |
|
117 | + $return = true; |
|
118 | + } |
|
119 | + |
|
120 | + return $return; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Supprime l'image associée à un article |
|
125 | + * |
|
126 | + * @param integer $indice L'indice de l'image recherchée |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public function deletePicture($indice) |
|
130 | + { |
|
131 | + $fieldName = 'article_picture' . $indice; |
|
132 | + if ($this->pictureExists($indice)) { |
|
133 | + @unlink(references_utils::getModuleOption('images_path') . references_utils::getModuleOption('images_path') . $this->getVar($fieldName)); |
|
134 | + } |
|
135 | + $this->setVar($fieldName, ''); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Retourne l'URL de l'image de l'article courant |
|
140 | + * |
|
141 | + * @param integer $indice L'indice de l'image recherchée |
|
142 | + * @return string L'URL |
|
143 | + */ |
|
144 | + public function getPictureUrl($indice) |
|
145 | + { |
|
146 | + $fieldName = 'article_picture' . $indice; |
|
147 | + if (xoops_trim($this->getVar($fieldName)) != '' && $this->pictureExists($indice)) { |
|
148 | + return references_utils::getModuleOption('images_url') . '/' . $this->getVar($fieldName); |
|
149 | + } else { |
|
150 | + return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Retourne le chemin de l'image de l'article courante |
|
156 | + * |
|
157 | + * @param integer $indice L'indice de l'image recherchée |
|
158 | + * @return string Le chemin |
|
159 | + */ |
|
160 | + public function getPicturePath($indice) |
|
161 | + { |
|
162 | + $fieldName = 'article_picture' . $indice; |
|
163 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
164 | + return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName); |
|
165 | + } else { |
|
166 | + return ''; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Indique si la vignette de l'image de l'article existe |
|
172 | + * |
|
173 | + * @param integer $indice L'indice de l'image recherchée |
|
174 | + * @return boolean Vrai si l'image existe sinon faux |
|
175 | + */ |
|
176 | + public function thumbExists($indice) |
|
177 | + { |
|
178 | + $fieldName = 'article_picture' . $indice; |
|
179 | + $return = false; |
|
180 | + if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName))) { |
|
181 | + $return = true; |
|
182 | + } |
|
183 | + |
|
184 | + return $return; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Retourne l'URL de la vignette de l'article |
|
189 | + * |
|
190 | + * @param integer $indice L'indice de l'image recherchée |
|
191 | + * @return string L'URL |
|
192 | + */ |
|
193 | + public function getThumbUrl($indice) |
|
194 | + { |
|
195 | + $fieldName = 'article_picture' . $indice; |
|
196 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
197 | + return references_utils::getModuleOption('images_url') . '/' . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
198 | + } else { |
|
199 | + return REFERENCES_IMAGES_URL . 'blank.gif'; |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Retourne le chemin de la vignette de l'annonce |
|
205 | + * |
|
206 | + * @param integer $indice L'indice de l'image recherchée |
|
207 | + * @return string L'URL |
|
208 | + */ |
|
209 | + public function getThumbPath($indice) |
|
210 | + { |
|
211 | + $fieldName = 'article_picture' . $indice; |
|
212 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
213 | + return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
|
214 | + } else { |
|
215 | + return ''; |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Indique si le fichier attaché à un article existe |
|
221 | + * |
|
222 | + * @return boolean |
|
223 | + */ |
|
224 | + public function attachmentExists() |
|
225 | + { |
|
226 | + $return = false; |
|
227 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'))) { |
|
228 | + $return = true; |
|
229 | + } |
|
230 | + |
|
231 | + return $return; |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Retourne l'URL du fichier attaché |
|
236 | + * |
|
237 | + * @return string L'url du fichier attaché sinon une chaine vide |
|
238 | + */ |
|
239 | + public function getAttachmentUrl() |
|
240 | + { |
|
241 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
242 | + return references_utils::getModuleOption('attached_url') . '/' . $this->getVar('article_attached_file'); |
|
243 | + } else { |
|
244 | + return ''; |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Retourne le chemin du fichier attaché |
|
250 | + * |
|
251 | + * @return string Le chemin du fichier attaché sinon une chaine vide |
|
252 | + */ |
|
253 | + public function getAttachmentPath() |
|
254 | + { |
|
255 | + if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
|
256 | + return references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'); |
|
257 | + } else { |
|
258 | + return ''; |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Supprime le fichier attaché à un article |
|
264 | + */ |
|
265 | + public function deleteAttachment() |
|
266 | + { |
|
267 | + if ($this->attachmentExists()) { |
|
268 | + @unlink(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file')); |
|
269 | + } |
|
270 | + $this->setVar('article_attached_file', ''); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Supprime la miniature associée à l'article |
|
275 | + * |
|
276 | + * @param integer $indice L'indice de l'image recherchée |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + public function deleteThumb($indice) |
|
280 | + { |
|
281 | + $fieldName = 'article_picture' . $indice; |
|
282 | + if ($this->thumbExists($indice)) { |
|
283 | + @unlink(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName)); |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Supprime l'image (et vignette) d'un article (raccourcis) |
|
289 | + * |
|
290 | + * @return void |
|
291 | + */ |
|
292 | + public function deletePicturesAndThumbs() |
|
293 | + { |
|
294 | + for ($i = 1; $i <= 10; ++$i) { |
|
295 | + $this->deleteThumb($i); |
|
296 | + $this->deletePicture($i); |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Retourne le timestamp de création formaté |
|
302 | + * |
|
303 | + * @return string |
|
304 | + */ |
|
305 | + public function getFormatedTimeStamp() |
|
306 | + { |
|
307 | + return formatTimestamp($this->getVar('article_timestamp'), 's'); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Indique s'il existe au moins une image pour l'article |
|
312 | + * |
|
313 | + * @return boolean |
|
314 | + */ |
|
315 | + public function isThereAPicture() |
|
316 | + { |
|
317 | + for ($i = 1; $i <= 10; ++$i) { |
|
318 | + if ($this->pictureExists($i)) { |
|
319 | + return true; |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + return false; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Inidique s'il existe au moins une vignette pour l'article |
|
328 | + * |
|
329 | + * @return boolean |
|
330 | + */ |
|
331 | + public function isThereAThumb() |
|
332 | + { |
|
333 | + for ($i = 1; $i <= 10; ++$i) { |
|
334 | + if ($this->thumbExists($i)) { |
|
335 | + return true; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + return false; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Retourne l'url pour atteindre l'élément |
|
344 | + * |
|
345 | + * @param bool $shortVersion |
|
346 | + * @return string |
|
347 | + */ |
|
348 | + public function getUrl($shortVersion = false) |
|
349 | + { |
|
350 | + if (!$shortVersion) { |
|
351 | + return REFERENCES_URL . 'reference.php?article_id=' . $this->getVar('article_id'); |
|
352 | + } else { |
|
353 | + return 'reference.php?article_id=' . $this->getVar('article_id'); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Retourne les éléments de l'annnonce formatés pour affichage |
|
359 | + * |
|
360 | + * @param string $format Format à utiliser |
|
361 | + * @return array |
|
362 | + */ |
|
363 | + public function toArray($format = 's') |
|
364 | + { |
|
365 | + $ret = array(); |
|
366 | + $ret = parent::toArray($format); |
|
367 | + $hrefTitle = $this->getHrefTitle(); |
|
368 | + $ret['article_href_title'] = $hrefTitle; |
|
369 | + $ret['article_url'] = $this->getUrl(); |
|
370 | + // Indique si une annonce est expirée |
|
371 | + $ret['article_is_online'] = $this->isArticleOnline(); |
|
372 | + if ($this->isThereAPicture()) { |
|
373 | + $ret['article_picture_exists'] = true; |
|
374 | + for ($i = 1; $i <= 10; ++$i) { |
|
375 | + if ($this->pictureExists($i)) { |
|
376 | + $ret['article_picture_url' . $i] = $this->getPictureUrl($i); |
|
377 | + $ret['article_picture_path' . $i] = $this->getPicturePath($i); |
|
378 | + $ret['article_pictures_urls'][] = $this->getPictureUrl($i); |
|
379 | + $ret['article_pictures_paths'][] = $this->getPicturePath($i); |
|
380 | + $fieldName = 'article_picture' . $i . '_text'; |
|
381 | + if (xoops_trim($this->getVar($fieldName)) != '') { |
|
382 | + $ret['article_pictures_texts'][] = references_utils::makeHrefTitle($this->getVar($fieldName)); |
|
383 | + } else { |
|
384 | + $ret['article_pictures_texts'][] = $hrefTitle; |
|
385 | + } |
|
386 | + } |
|
387 | + } |
|
388 | + } else { |
|
389 | + $ret['article_picture_exists'] = false; |
|
390 | + } |
|
391 | + $ret['article_short_text'] = references_utils::truncate_tagsafe($this->getVar('article_text'), REFERENCES_SHORTEN_TEXT); |
|
392 | + |
|
393 | + if ($this->attachmentExists()) { |
|
394 | + $ret['article_attachment_exists'] = true; |
|
395 | + $ret['article_attachment_url'] = $this->getAttachmentUrl(); |
|
396 | + $ret['article_attachment_path'] = $this->getAttachmentPath(); |
|
397 | + } else { |
|
398 | + $ret['attachment_exists'] = false; |
|
399 | + } |
|
400 | + |
|
401 | + if ($this->isThereAThumb()) { |
|
402 | + $ret['article_thumb_exists'] = true; |
|
403 | + for ($i = 1; $i <= 10; ++$i) { |
|
404 | + if ($this->thumbExists($i)) { |
|
405 | + $ret['article_thumb_url' . $i] = $this->getThumbUrl($i); |
|
406 | + $ret['article_thumb_path' . $i] = $this->getThumbPath($i); |
|
407 | + $ret['article_thumbs_urls'][] = $this->getThumbUrl($i); |
|
408 | + $ret['article_thumbs_paths'][] = $this->getThumbPath($i); |
|
409 | + } |
|
410 | + } |
|
411 | + } else { |
|
412 | + $ret['article_thumb_exists'] = false; |
|
413 | + } |
|
414 | + |
|
415 | + $ret['article_timestamp_formated'] = $this->getFormatedTimeStamp(); |
|
416 | + |
|
417 | + return $ret; |
|
418 | + } |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | class ReferencesReferences_articlesHandler extends references_XoopsPersistableObjectHandler |
422 | 422 | { |
423 | - public function __construct($db) |
|
424 | - { // Table Classe Id Descr. |
|
425 | - parent::__construct($db, 'references_articles', 'references_articles', 'article_id', 'article_title'); |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Retourne le critère à utiliser pour voir les catégories en respectant les permissions |
|
430 | - * |
|
431 | - * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
432 | - * @return obejct de type Criteria |
|
433 | - */ |
|
434 | - public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
435 | - { |
|
436 | - global $xoopsUser; |
|
437 | - static $permissions = array(); |
|
438 | - if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
439 | - return $permissions[$permissionsType]; |
|
440 | - } |
|
441 | - $categories = array(); |
|
442 | - $currentModule = references_utils::getModule(); |
|
443 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
444 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
445 | - $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
446 | - if (is_array($categories) && count($categories) > 0) { |
|
447 | - $permissions[$permissionsType] = new Criteria('article_category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
448 | - } else { // Ne peut rien voir |
|
449 | - $permissions[$permissionsType] = new Criteria('article_category_id', '0', '='); |
|
450 | - } |
|
451 | - |
|
452 | - return $permissions[$permissionsType]; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Retourne les articles récents en tenant compte des permissions de consultation sur les catégories |
|
457 | - * |
|
458 | - * @param integer $start Indice de début |
|
459 | - * @param integer $limit Nombre d'objets à renvoyer |
|
460 | - * @param string $sort Zone de tri |
|
461 | - * @param string $order Sens du tri |
|
462 | - * @param boolean $onlyOnline Uniquement les articles en ligne ? |
|
463 | - * @param integer $categoryId Identifiant d'une catégorie à laquelle se limiter |
|
464 | - * @return array Objets de type references_articles |
|
465 | - */ |
|
466 | - public function getRecentArticles($start = 0, $limit = 0, $sort = 'article_timestamp', $order = 'DESC', $onlyOnline = true, $categoryId = 0) |
|
467 | - { |
|
468 | - $criteria = new CriteriaCompo(); |
|
469 | - $criteria->add(new Criteria('article_id', 0, '<>')); |
|
470 | - $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
471 | - if ($onlyOnline) { |
|
472 | - $criteria->add(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
473 | - } |
|
474 | - if (is_array($categoryId) && count($categoryId) > 0) { |
|
475 | - $criteria->add(new Criteria('article_category_id', '(' . implode(',', $categoryId) . ')', 'IN')); |
|
476 | - } elseif ($categoryId > 0) { |
|
477 | - $criteria->add(new Criteria('article_category_id', $categoryId, '=')); |
|
478 | - } |
|
479 | - $criteria->setStart($start); |
|
480 | - $criteria->setSort($sort); |
|
481 | - $criteria->setOrder($order); |
|
482 | - $criteria->setLimit($limit); |
|
483 | - |
|
484 | - return $this->getObjects($criteria); |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * Retourne le nombre total d'articles en ligne |
|
489 | - * |
|
490 | - * @return integer |
|
491 | - */ |
|
492 | - public function getOnlineArticlesCount() |
|
493 | - { |
|
494 | - return $this->getCount(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
495 | - } |
|
496 | - |
|
497 | - /** |
|
498 | - * Notification de la publication d'une nouvelle référence |
|
499 | - * |
|
500 | - * @param object|references_articles $article L'annonce pour laquelle on fait la notification |
|
501 | - * @return bool |
|
502 | - */ |
|
503 | - public function notifyNewArticle(references_articles $article) |
|
504 | - { |
|
505 | - $plugins = references_plugins::getInstance(); |
|
506 | - $plugins->fireAction(references_plugins::EVENT_ON_REFERENCE_CREATE, new references_parameters(array('reference' => $article))); |
|
507 | - |
|
508 | - return true; |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Effectue la suppression d'un article (et de ses images et fichier attaché) |
|
513 | - * |
|
514 | - * @param references_articles $article L'article à supprimer |
|
515 | - * @return boolean Le résultat de la suppression |
|
516 | - */ |
|
517 | - public function deleteArticle(references_articles $article) |
|
518 | - { |
|
519 | - $article->deletePicturesAndThumbs(); |
|
520 | - $article->deleteAttachment(); |
|
521 | - |
|
522 | - return $this->delete($article, true); |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * Retourne la liste des catégories uniques utilisées par les références |
|
527 | - * |
|
528 | - */ |
|
529 | - public function getDistinctCategoriesIds() |
|
530 | - { |
|
531 | - $ret = array(); |
|
532 | - $sql = 'SELECT distinct(article_category_id) FROM ' . $this->table; |
|
533 | - $sql .= ' ' . $this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
|
534 | - $sql .= ' GROUP BY article_category_id ORDER BY article_category_id'; |
|
535 | - $result = $this->db->query($sql); |
|
536 | - if (!$result) { |
|
537 | - return $ret; |
|
538 | - } |
|
539 | - while ($row = $this->db->fetchArray($result)) { |
|
540 | - $ret[$row['article_category_id']] = $row['article_category_id']; |
|
541 | - } |
|
542 | - |
|
543 | - return $ret; |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Passe un article en ligne |
|
548 | - * |
|
549 | - * @param references_articles $article |
|
550 | - * @return boolean |
|
551 | - */ |
|
552 | - public function onlineArticle(references_articles $article) |
|
553 | - { |
|
554 | - $article->setVar('article_online', REFERENCES_STATUS_ONLINE); |
|
555 | - |
|
556 | - return $this->insert($article, true); |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Passe un article hors ligne |
|
561 | - * |
|
562 | - * @param references_articles $article |
|
563 | - * @return boolean |
|
564 | - */ |
|
565 | - public function offlineArticle(references_articles $article) |
|
566 | - { |
|
567 | - $article->setVar('article_online', REFERENCES_STATUS_OFFLINE); |
|
568 | - |
|
569 | - return $this->insert($article, true); |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Indique si une référence est visible d'un utilisateur |
|
574 | - * |
|
575 | - * @param object|references_articles $article L'article à controler |
|
576 | - * @param integer $uid L'id de l'utilisateur à controler |
|
577 | - * @return bool |
|
578 | - */ |
|
579 | - public function userCanSeeReference(references_articles $article, $uid = 0) |
|
580 | - { |
|
581 | - global $xoopsUser; |
|
582 | - if ($uid == 0) { |
|
583 | - $uid = references_utils::getCurrentUserID(); |
|
584 | - } |
|
585 | - $currentModule = references_utils::getModule(); |
|
586 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
587 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
588 | - |
|
589 | - return $gperm_handler->checkRight(REFERENCES_PERM_READ, $article->article_category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Remonte un article d'un cran dans l'ordre global des articles |
|
594 | - * |
|
595 | - * @param integer $currentId L'ID de l'article courant dont on souhaite remonter l'ordre |
|
596 | - * @param integer $currentOrder L'ordre de l'élément courant à remonter |
|
597 | - * @return void |
|
598 | - */ |
|
599 | - public function moveUp($currentId, $currentOrder) |
|
600 | - { |
|
601 | - $sql_plus = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder - 1); |
|
602 | - $res_plus = $this->db->query($sql_plus); |
|
603 | - if ($this->db->getRowsNum($res_plus) == 0) { |
|
604 | - return; |
|
605 | - } |
|
606 | - $row_plus = $this->db->fetchArray($res_plus); |
|
607 | - |
|
608 | - $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight + 1) WHERE article_id = ' . $row_plus['article_id']; |
|
609 | - $this->db->queryF($upd1); |
|
610 | - |
|
611 | - $upd2 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . (int)$currentId; |
|
612 | - $this->db->queryF($upd2); |
|
613 | - $this->forceCacheClean(); |
|
614 | - } |
|
615 | - |
|
616 | - /** |
|
617 | - * Descend un article d'un cran dans l'ordre global des articles |
|
618 | - * |
|
619 | - * @param integer $currentId L'Id de l'article courant dont on souhaite descendre l'ordre |
|
620 | - * @param integer $currentOrder L'orde de l'élément courant à remonter |
|
621 | - * @return void |
|
622 | - */ |
|
623 | - public function moveDown($currentId, $currentOrder) |
|
624 | - { |
|
625 | - $sql_moins = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder + 1); |
|
626 | - $res_moins = $this->db->query($sql_moins); |
|
627 | - if ($this->db->getRowsNum($res_moins) == 0) { |
|
628 | - return; |
|
629 | - } |
|
630 | - |
|
631 | - $row_moins = $this->db->fetchArray($res_moins); |
|
632 | - $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . $row_moins['article_id']; |
|
633 | - $this->db->queryF($upd1); |
|
634 | - |
|
635 | - $upd2 = 'UPDATE ' . $this->table . ' SET article_weight =( article_weight + 1) WHERE article_id = ' . (int)$currentId; |
|
636 | - $this->db->queryF($upd2); |
|
637 | - $this->forceCacheClean(); |
|
638 | - } |
|
423 | + public function __construct($db) |
|
424 | + { // Table Classe Id Descr. |
|
425 | + parent::__construct($db, 'references_articles', 'references_articles', 'article_id', 'article_title'); |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Retourne le critère à utiliser pour voir les catégories en respectant les permissions |
|
430 | + * |
|
431 | + * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
432 | + * @return obejct de type Criteria |
|
433 | + */ |
|
434 | + public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
435 | + { |
|
436 | + global $xoopsUser; |
|
437 | + static $permissions = array(); |
|
438 | + if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
439 | + return $permissions[$permissionsType]; |
|
440 | + } |
|
441 | + $categories = array(); |
|
442 | + $currentModule = references_utils::getModule(); |
|
443 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
444 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
445 | + $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
446 | + if (is_array($categories) && count($categories) > 0) { |
|
447 | + $permissions[$permissionsType] = new Criteria('article_category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
448 | + } else { // Ne peut rien voir |
|
449 | + $permissions[$permissionsType] = new Criteria('article_category_id', '0', '='); |
|
450 | + } |
|
451 | + |
|
452 | + return $permissions[$permissionsType]; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Retourne les articles récents en tenant compte des permissions de consultation sur les catégories |
|
457 | + * |
|
458 | + * @param integer $start Indice de début |
|
459 | + * @param integer $limit Nombre d'objets à renvoyer |
|
460 | + * @param string $sort Zone de tri |
|
461 | + * @param string $order Sens du tri |
|
462 | + * @param boolean $onlyOnline Uniquement les articles en ligne ? |
|
463 | + * @param integer $categoryId Identifiant d'une catégorie à laquelle se limiter |
|
464 | + * @return array Objets de type references_articles |
|
465 | + */ |
|
466 | + public function getRecentArticles($start = 0, $limit = 0, $sort = 'article_timestamp', $order = 'DESC', $onlyOnline = true, $categoryId = 0) |
|
467 | + { |
|
468 | + $criteria = new CriteriaCompo(); |
|
469 | + $criteria->add(new Criteria('article_id', 0, '<>')); |
|
470 | + $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
471 | + if ($onlyOnline) { |
|
472 | + $criteria->add(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
473 | + } |
|
474 | + if (is_array($categoryId) && count($categoryId) > 0) { |
|
475 | + $criteria->add(new Criteria('article_category_id', '(' . implode(',', $categoryId) . ')', 'IN')); |
|
476 | + } elseif ($categoryId > 0) { |
|
477 | + $criteria->add(new Criteria('article_category_id', $categoryId, '=')); |
|
478 | + } |
|
479 | + $criteria->setStart($start); |
|
480 | + $criteria->setSort($sort); |
|
481 | + $criteria->setOrder($order); |
|
482 | + $criteria->setLimit($limit); |
|
483 | + |
|
484 | + return $this->getObjects($criteria); |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * Retourne le nombre total d'articles en ligne |
|
489 | + * |
|
490 | + * @return integer |
|
491 | + */ |
|
492 | + public function getOnlineArticlesCount() |
|
493 | + { |
|
494 | + return $this->getCount(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
|
495 | + } |
|
496 | + |
|
497 | + /** |
|
498 | + * Notification de la publication d'une nouvelle référence |
|
499 | + * |
|
500 | + * @param object|references_articles $article L'annonce pour laquelle on fait la notification |
|
501 | + * @return bool |
|
502 | + */ |
|
503 | + public function notifyNewArticle(references_articles $article) |
|
504 | + { |
|
505 | + $plugins = references_plugins::getInstance(); |
|
506 | + $plugins->fireAction(references_plugins::EVENT_ON_REFERENCE_CREATE, new references_parameters(array('reference' => $article))); |
|
507 | + |
|
508 | + return true; |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Effectue la suppression d'un article (et de ses images et fichier attaché) |
|
513 | + * |
|
514 | + * @param references_articles $article L'article à supprimer |
|
515 | + * @return boolean Le résultat de la suppression |
|
516 | + */ |
|
517 | + public function deleteArticle(references_articles $article) |
|
518 | + { |
|
519 | + $article->deletePicturesAndThumbs(); |
|
520 | + $article->deleteAttachment(); |
|
521 | + |
|
522 | + return $this->delete($article, true); |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * Retourne la liste des catégories uniques utilisées par les références |
|
527 | + * |
|
528 | + */ |
|
529 | + public function getDistinctCategoriesIds() |
|
530 | + { |
|
531 | + $ret = array(); |
|
532 | + $sql = 'SELECT distinct(article_category_id) FROM ' . $this->table; |
|
533 | + $sql .= ' ' . $this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
|
534 | + $sql .= ' GROUP BY article_category_id ORDER BY article_category_id'; |
|
535 | + $result = $this->db->query($sql); |
|
536 | + if (!$result) { |
|
537 | + return $ret; |
|
538 | + } |
|
539 | + while ($row = $this->db->fetchArray($result)) { |
|
540 | + $ret[$row['article_category_id']] = $row['article_category_id']; |
|
541 | + } |
|
542 | + |
|
543 | + return $ret; |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Passe un article en ligne |
|
548 | + * |
|
549 | + * @param references_articles $article |
|
550 | + * @return boolean |
|
551 | + */ |
|
552 | + public function onlineArticle(references_articles $article) |
|
553 | + { |
|
554 | + $article->setVar('article_online', REFERENCES_STATUS_ONLINE); |
|
555 | + |
|
556 | + return $this->insert($article, true); |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Passe un article hors ligne |
|
561 | + * |
|
562 | + * @param references_articles $article |
|
563 | + * @return boolean |
|
564 | + */ |
|
565 | + public function offlineArticle(references_articles $article) |
|
566 | + { |
|
567 | + $article->setVar('article_online', REFERENCES_STATUS_OFFLINE); |
|
568 | + |
|
569 | + return $this->insert($article, true); |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Indique si une référence est visible d'un utilisateur |
|
574 | + * |
|
575 | + * @param object|references_articles $article L'article à controler |
|
576 | + * @param integer $uid L'id de l'utilisateur à controler |
|
577 | + * @return bool |
|
578 | + */ |
|
579 | + public function userCanSeeReference(references_articles $article, $uid = 0) |
|
580 | + { |
|
581 | + global $xoopsUser; |
|
582 | + if ($uid == 0) { |
|
583 | + $uid = references_utils::getCurrentUserID(); |
|
584 | + } |
|
585 | + $currentModule = references_utils::getModule(); |
|
586 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
587 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
588 | + |
|
589 | + return $gperm_handler->checkRight(REFERENCES_PERM_READ, $article->article_category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Remonte un article d'un cran dans l'ordre global des articles |
|
594 | + * |
|
595 | + * @param integer $currentId L'ID de l'article courant dont on souhaite remonter l'ordre |
|
596 | + * @param integer $currentOrder L'ordre de l'élément courant à remonter |
|
597 | + * @return void |
|
598 | + */ |
|
599 | + public function moveUp($currentId, $currentOrder) |
|
600 | + { |
|
601 | + $sql_plus = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder - 1); |
|
602 | + $res_plus = $this->db->query($sql_plus); |
|
603 | + if ($this->db->getRowsNum($res_plus) == 0) { |
|
604 | + return; |
|
605 | + } |
|
606 | + $row_plus = $this->db->fetchArray($res_plus); |
|
607 | + |
|
608 | + $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight + 1) WHERE article_id = ' . $row_plus['article_id']; |
|
609 | + $this->db->queryF($upd1); |
|
610 | + |
|
611 | + $upd2 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . (int)$currentId; |
|
612 | + $this->db->queryF($upd2); |
|
613 | + $this->forceCacheClean(); |
|
614 | + } |
|
615 | + |
|
616 | + /** |
|
617 | + * Descend un article d'un cran dans l'ordre global des articles |
|
618 | + * |
|
619 | + * @param integer $currentId L'Id de l'article courant dont on souhaite descendre l'ordre |
|
620 | + * @param integer $currentOrder L'orde de l'élément courant à remonter |
|
621 | + * @return void |
|
622 | + */ |
|
623 | + public function moveDown($currentId, $currentOrder) |
|
624 | + { |
|
625 | + $sql_moins = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder + 1); |
|
626 | + $res_moins = $this->db->query($sql_moins); |
|
627 | + if ($this->db->getRowsNum($res_moins) == 0) { |
|
628 | + return; |
|
629 | + } |
|
630 | + |
|
631 | + $row_moins = $this->db->fetchArray($res_moins); |
|
632 | + $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . $row_moins['article_id']; |
|
633 | + $this->db->queryF($upd1); |
|
634 | + |
|
635 | + $upd2 = 'UPDATE ' . $this->table . ' SET article_weight =( article_weight + 1) WHERE article_id = ' . (int)$currentId; |
|
636 | + $this->db->queryF($upd2); |
|
637 | + $this->forceCacheClean(); |
|
638 | + } |
|
639 | 639 | } |
@@ -22,195 +22,195 @@ |
||
22 | 22 | |
23 | 23 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
24 | 24 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
25 | - require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
25 | + require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | class references_categories extends references_Object |
29 | 29 | { |
30 | - public function __construct() |
|
31 | - { |
|
32 | - $this->initVar('category_id', XOBJ_DTYPE_INT, null, false); |
|
33 | - $this->initVar('category_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
34 | - $this->initVar('category_weight', XOBJ_DTYPE_INT, null, false); |
|
35 | - $this->initVar('category_description', XOBJ_DTYPE_TXTAREA, null, false); |
|
36 | - // Pour autoriser le html |
|
37 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
42 | - * |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function getHrefTitle() |
|
46 | - { |
|
47 | - return references_utils::makeHrefTitle($this->getVar('category_title')); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Retourne l'url à utiliser pour atteindre la catégorie |
|
52 | - * |
|
53 | - * @param bool $shortVersion |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public function getUrl($shortVersion = false) |
|
57 | - { |
|
58 | - if (!$shortVersion) { |
|
59 | - return REFERENCES_URL . 'category.php?category_id=' . $this->getVar('category_id'); |
|
60 | - } else { |
|
61 | - return 'category.php?category_id=' . $this->getVar('category_id'); |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Retourne les éléments de l'annnonce formatés pour affichage |
|
67 | - * |
|
68 | - * @param string $format Format à utiliser |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function toArray($format = 's') |
|
72 | - { |
|
73 | - $ret = array(); |
|
74 | - $ret = parent::toArray($format); |
|
75 | - $ret['category_href_title'] = $this->getHrefTitle(); |
|
76 | - $ret['category_url_rewrited'] = $this->getUrl(); |
|
77 | - |
|
78 | - return $ret; |
|
79 | - } |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + $this->initVar('category_id', XOBJ_DTYPE_INT, null, false); |
|
33 | + $this->initVar('category_title', XOBJ_DTYPE_TXTBOX, null, false); |
|
34 | + $this->initVar('category_weight', XOBJ_DTYPE_INT, null, false); |
|
35 | + $this->initVar('category_description', XOBJ_DTYPE_TXTAREA, null, false); |
|
36 | + // Pour autoriser le html |
|
37 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
|
42 | + * |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function getHrefTitle() |
|
46 | + { |
|
47 | + return references_utils::makeHrefTitle($this->getVar('category_title')); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Retourne l'url à utiliser pour atteindre la catégorie |
|
52 | + * |
|
53 | + * @param bool $shortVersion |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public function getUrl($shortVersion = false) |
|
57 | + { |
|
58 | + if (!$shortVersion) { |
|
59 | + return REFERENCES_URL . 'category.php?category_id=' . $this->getVar('category_id'); |
|
60 | + } else { |
|
61 | + return 'category.php?category_id=' . $this->getVar('category_id'); |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Retourne les éléments de l'annnonce formatés pour affichage |
|
67 | + * |
|
68 | + * @param string $format Format à utiliser |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function toArray($format = 's') |
|
72 | + { |
|
73 | + $ret = array(); |
|
74 | + $ret = parent::toArray($format); |
|
75 | + $ret['category_href_title'] = $this->getHrefTitle(); |
|
76 | + $ret['category_url_rewrited'] = $this->getUrl(); |
|
77 | + |
|
78 | + return $ret; |
|
79 | + } |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | class ReferencesReferences_categoriesHandler extends references_XoopsPersistableObjectHandler |
83 | 83 | { |
84 | - public function __construct($db) |
|
85 | - { // Table Classe Id Descr. |
|
86 | - parent::__construct($db, 'references_categories', 'references_categories', 'category_id', 'category_title'); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Retourne le crit�re � utiliser pour voir les cat�gories en respectant les permissions |
|
91 | - * |
|
92 | - * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
93 | - * @return obejct de type Criteria |
|
94 | - */ |
|
95 | - public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
96 | - { |
|
97 | - global $xoopsUser; |
|
98 | - static $permissions = array(); |
|
99 | - if (references_utils::isAdmin()) { |
|
100 | - return new Criteria('category_id', '0', '>'); |
|
101 | - } |
|
102 | - if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
103 | - return $permissions[$permissionsType]; |
|
104 | - } |
|
105 | - $categories = array(); |
|
106 | - $currentModule = references_utils::getModule(); |
|
107 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
108 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
109 | - $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
110 | - if (is_array($categories) && count($categories) > 0) { |
|
111 | - $permissions[$permissionsType] = new Criteria('category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
112 | - } else { // Ne peut rien voir |
|
113 | - $permissions[$permissionsType] = new Criteria('category_id', '0', '='); |
|
114 | - } |
|
115 | - |
|
116 | - return $permissions[$permissionsType]; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Retourne les catégories |
|
121 | - * |
|
122 | - * @param integer $start Indice de début |
|
123 | - * @param integer $limit Nombre d'objets à renvoyer |
|
124 | - * @param string $sort Zone de tri |
|
125 | - * @param string $order Sens du tri |
|
126 | - * @return array Objets de type references_categories |
|
127 | - */ |
|
128 | - public function getCategories($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
129 | - { |
|
130 | - $criteria = new CriteriaCompo(); |
|
131 | - $criteria->add(new Criteria('category_id', 0, '<>')); |
|
132 | - $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
133 | - $criteria->setStart($start); |
|
134 | - $criteria->setSort($sort); |
|
135 | - $criteria->setOrder($order); |
|
136 | - $criteria->setLimit($limit); |
|
137 | - |
|
138 | - return $this->getObjects($criteria, true); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Retourne la liste des catégories en tant que tableau |
|
143 | - * @param integer $start Position de départ |
|
144 | - * @param integer $limit Nombre maximum d'objets à retourner |
|
145 | - * @param string $sort ordre de tri |
|
146 | - * @param string $order Sens du tri |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public function getListArray($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
150 | - { |
|
151 | - $criteria = new CriteriaCompo(); |
|
152 | - $criteria->add(new Criteria('category_id', 0, '<>')); |
|
153 | - $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
154 | - $criteria->setStart($start); |
|
155 | - $criteria->setSort($sort); |
|
156 | - $criteria->setOrder($order); |
|
157 | - $criteria->setLimit($limit); |
|
158 | - |
|
159 | - return $this->getList($criteria); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Retourne le sélecteur à utiliser pour voir la liste des catégies |
|
164 | - * |
|
165 | - * @param string $selectName Le nom du sélecteur |
|
166 | - * @param integer $selected L'élément sélectionné |
|
167 | - * @return string |
|
168 | - */ |
|
169 | - public function getCategoriesSelect($selectName = 'categoriesSelect', $selected = 0) |
|
170 | - { |
|
171 | - $categories = array(); |
|
172 | - $ret = ''; |
|
173 | - $categories = $this->getListArray(0, 0, 'category_weight ASC, category_title', 'ASC'); |
|
174 | - if (count($categories) == 0) { |
|
175 | - return $ret; |
|
176 | - } |
|
177 | - $jump = REFERENCES_URL . 'category.php?category_id='; |
|
178 | - $extra = " onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'"; |
|
179 | - |
|
180 | - return references_utils::htmlSelect($selectName, $categories, $selected, true, '', false, 1, $extra); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Notification de la création d'une nouvelle catégorie |
|
185 | - * |
|
186 | - * @param object|references_categories $category |
|
187 | - * @return bool |
|
188 | - */ |
|
189 | - public function notifyNewCategory(references_categories $category) |
|
190 | - { |
|
191 | - $plugins = references_plugins::getInstance(); |
|
192 | - $plugins->fireAction(references_plugins::EVENT_ON_CATEGORY_CREATE, new references_parameters(array('category' => $category))); |
|
193 | - |
|
194 | - return true; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Indique si une catégorie est visible d'un utilisateur |
|
199 | - * |
|
200 | - * @param object|references_categories $category La catégorie à controler |
|
201 | - * @param integer $uid L'id de l'utilisateur à controler |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function userCanSeeCategory(references_categories $category, $uid = 0) |
|
205 | - { |
|
206 | - global $xoopsUser; |
|
207 | - if ($uid == 0) { |
|
208 | - $uid = references_utils::getCurrentUserID(); |
|
209 | - } |
|
210 | - $currentModule = references_utils::getModule(); |
|
211 | - $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
212 | - $gperm_handler = xoops_getHandler('groupperm'); |
|
213 | - |
|
214 | - return $gperm_handler->checkRight(REFERENCES_PERM_READ, $category->category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
215 | - } |
|
84 | + public function __construct($db) |
|
85 | + { // Table Classe Id Descr. |
|
86 | + parent::__construct($db, 'references_categories', 'references_categories', 'category_id', 'category_title'); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Retourne le crit�re � utiliser pour voir les cat�gories en respectant les permissions |
|
91 | + * |
|
92 | + * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
|
93 | + * @return obejct de type Criteria |
|
94 | + */ |
|
95 | + public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
|
96 | + { |
|
97 | + global $xoopsUser; |
|
98 | + static $permissions = array(); |
|
99 | + if (references_utils::isAdmin()) { |
|
100 | + return new Criteria('category_id', '0', '>'); |
|
101 | + } |
|
102 | + if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
|
103 | + return $permissions[$permissionsType]; |
|
104 | + } |
|
105 | + $categories = array(); |
|
106 | + $currentModule = references_utils::getModule(); |
|
107 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
108 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
109 | + $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
|
110 | + if (is_array($categories) && count($categories) > 0) { |
|
111 | + $permissions[$permissionsType] = new Criteria('category_id', '(' . implode(',', $categories) . ')', 'IN'); |
|
112 | + } else { // Ne peut rien voir |
|
113 | + $permissions[$permissionsType] = new Criteria('category_id', '0', '='); |
|
114 | + } |
|
115 | + |
|
116 | + return $permissions[$permissionsType]; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Retourne les catégories |
|
121 | + * |
|
122 | + * @param integer $start Indice de début |
|
123 | + * @param integer $limit Nombre d'objets à renvoyer |
|
124 | + * @param string $sort Zone de tri |
|
125 | + * @param string $order Sens du tri |
|
126 | + * @return array Objets de type references_categories |
|
127 | + */ |
|
128 | + public function getCategories($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
129 | + { |
|
130 | + $criteria = new CriteriaCompo(); |
|
131 | + $criteria->add(new Criteria('category_id', 0, '<>')); |
|
132 | + $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
133 | + $criteria->setStart($start); |
|
134 | + $criteria->setSort($sort); |
|
135 | + $criteria->setOrder($order); |
|
136 | + $criteria->setLimit($limit); |
|
137 | + |
|
138 | + return $this->getObjects($criteria, true); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Retourne la liste des catégories en tant que tableau |
|
143 | + * @param integer $start Position de départ |
|
144 | + * @param integer $limit Nombre maximum d'objets à retourner |
|
145 | + * @param string $sort ordre de tri |
|
146 | + * @param string $order Sens du tri |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public function getListArray($start = 0, $limit = 0, $sort = 'category_weight', $order = 'ASC') |
|
150 | + { |
|
151 | + $criteria = new CriteriaCompo(); |
|
152 | + $criteria->add(new Criteria('category_id', 0, '<>')); |
|
153 | + $criteria->add($this->getPermissionsCategoriesCriteria()); |
|
154 | + $criteria->setStart($start); |
|
155 | + $criteria->setSort($sort); |
|
156 | + $criteria->setOrder($order); |
|
157 | + $criteria->setLimit($limit); |
|
158 | + |
|
159 | + return $this->getList($criteria); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Retourne le sélecteur à utiliser pour voir la liste des catégies |
|
164 | + * |
|
165 | + * @param string $selectName Le nom du sélecteur |
|
166 | + * @param integer $selected L'élément sélectionné |
|
167 | + * @return string |
|
168 | + */ |
|
169 | + public function getCategoriesSelect($selectName = 'categoriesSelect', $selected = 0) |
|
170 | + { |
|
171 | + $categories = array(); |
|
172 | + $ret = ''; |
|
173 | + $categories = $this->getListArray(0, 0, 'category_weight ASC, category_title', 'ASC'); |
|
174 | + if (count($categories) == 0) { |
|
175 | + return $ret; |
|
176 | + } |
|
177 | + $jump = REFERENCES_URL . 'category.php?category_id='; |
|
178 | + $extra = " onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'"; |
|
179 | + |
|
180 | + return references_utils::htmlSelect($selectName, $categories, $selected, true, '', false, 1, $extra); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Notification de la création d'une nouvelle catégorie |
|
185 | + * |
|
186 | + * @param object|references_categories $category |
|
187 | + * @return bool |
|
188 | + */ |
|
189 | + public function notifyNewCategory(references_categories $category) |
|
190 | + { |
|
191 | + $plugins = references_plugins::getInstance(); |
|
192 | + $plugins->fireAction(references_plugins::EVENT_ON_CATEGORY_CREATE, new references_parameters(array('category' => $category))); |
|
193 | + |
|
194 | + return true; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Indique si une catégorie est visible d'un utilisateur |
|
199 | + * |
|
200 | + * @param object|references_categories $category La catégorie à controler |
|
201 | + * @param integer $uid L'id de l'utilisateur à controler |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function userCanSeeCategory(references_categories $category, $uid = 0) |
|
205 | + { |
|
206 | + global $xoopsUser; |
|
207 | + if ($uid == 0) { |
|
208 | + $uid = references_utils::getCurrentUserID(); |
|
209 | + } |
|
210 | + $currentModule = references_utils::getModule(); |
|
211 | + $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
212 | + $gperm_handler = xoops_getHandler('groupperm'); |
|
213 | + |
|
214 | + return $gperm_handler->checkRight(REFERENCES_PERM_READ, $category->category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
|
215 | + } |
|
216 | 216 | } |
@@ -25,44 +25,44 @@ discard block |
||
25 | 25 | |
26 | 26 | class references_Object extends XoopsObject |
27 | 27 | { |
28 | - public function toArray($format = 's') |
|
29 | - { |
|
30 | - $ret = array(); |
|
31 | - foreach ($this->vars as $k => $v) { |
|
32 | - $ret[$k] = $this->getVar($k, $format); |
|
33 | - } |
|
34 | - |
|
35 | - return $ret; |
|
36 | - } |
|
37 | - |
|
38 | - // TODO: Rajouter une méthode intsert() et delete() |
|
39 | - |
|
40 | - /** |
|
41 | - * Permet de valoriser un champ de la table comme si c'était une propriété de la classe |
|
42 | - * |
|
43 | - * @example $enregistrement->nom_du_champ = 'ma chaine' |
|
44 | - * |
|
45 | - * @param string $key Le nom du champ à traiter |
|
46 | - * @param mixed $value La valeur à lui attribuer |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - public function __set($key, $value) |
|
50 | - { |
|
51 | - return $this->setVar($key, $value); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Permet d'accéder aux champs de la table comme à des propriétés de la classe |
|
56 | - * |
|
57 | - * @example echo $enregistrement->nom_du_champ; |
|
58 | - * |
|
59 | - * @param string $key Le nom du champ que l'on souhaite récupérer |
|
60 | - * @return mixed |
|
61 | - */ |
|
62 | - public function __get($key) |
|
63 | - { |
|
64 | - return $this->getVar($key); |
|
65 | - } |
|
28 | + public function toArray($format = 's') |
|
29 | + { |
|
30 | + $ret = array(); |
|
31 | + foreach ($this->vars as $k => $v) { |
|
32 | + $ret[$k] = $this->getVar($k, $format); |
|
33 | + } |
|
34 | + |
|
35 | + return $ret; |
|
36 | + } |
|
37 | + |
|
38 | + // TODO: Rajouter une méthode intsert() et delete() |
|
39 | + |
|
40 | + /** |
|
41 | + * Permet de valoriser un champ de la table comme si c'était une propriété de la classe |
|
42 | + * |
|
43 | + * @example $enregistrement->nom_du_champ = 'ma chaine' |
|
44 | + * |
|
45 | + * @param string $key Le nom du champ à traiter |
|
46 | + * @param mixed $value La valeur à lui attribuer |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + public function __set($key, $value) |
|
50 | + { |
|
51 | + return $this->setVar($key, $value); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Permet d'accéder aux champs de la table comme à des propriétés de la classe |
|
56 | + * |
|
57 | + * @example echo $enregistrement->nom_du_champ; |
|
58 | + * |
|
59 | + * @param string $key Le nom du champ que l'on souhaite récupérer |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | + public function __get($key) |
|
63 | + { |
|
64 | + return $this->getVar($key); |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -73,778 +73,778 @@ discard block |
||
73 | 73 | */ |
74 | 74 | class references_XoopsPersistableObjectHandler extends XoopsObjectHandler |
75 | 75 | { |
76 | - /**#@+ |
|
76 | + /**#@+ |
|
77 | 77 | * Information about the class, the handler is managing |
78 | 78 | * |
79 | 79 | * @var string |
80 | 80 | */ |
81 | - public $table; |
|
82 | - public $keyName; |
|
83 | - public $className; |
|
84 | - public $identifierName; |
|
85 | - protected $cacheOptions = array(); |
|
86 | - /**#@-*/ |
|
87 | - |
|
88 | - /** |
|
89 | - * Constructor - called from child classes |
|
90 | - * @param object $db {@link XoopsDatabase} object |
|
91 | - * @param string $tablename Name of database table |
|
92 | - * @param string $classname Name of Class, this handler is managing |
|
93 | - * @param string $keyname Name of the property, holding the key |
|
94 | - * @param string $idenfierName Name of the property, holding the label |
|
95 | - * @param array $cacheOptions Optional, options for the cache |
|
96 | - * |
|
97 | - */ |
|
98 | - public function __construct(&$db, $tablename, $classname, $keyname, $idenfierName = '', $cacheOptions = null) |
|
99 | - { |
|
100 | - parent::__construct($db); |
|
101 | - $this->table = $db->prefix($tablename); |
|
102 | - $this->keyName = $keyname; |
|
103 | - $this->className = $classname; |
|
104 | - if (trim($idenfierName) != '') { |
|
105 | - $this->identifierName = $idenfierName; |
|
106 | - } |
|
107 | - // To diable cache, add this line after the first one : 'caching' => false, |
|
108 | - if (is_null($cacheOptions)) { |
|
109 | - $this->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
110 | - } else { |
|
111 | - $this->setCachingOptions($cacheOptions); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - public function setCachingOptions($cacheOptions) |
|
116 | - { |
|
117 | - $this->cacheOptions = $cacheOptions; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Generates a unique ID for a Sql Query |
|
122 | - * |
|
123 | - * @param string $query The SQL query for which we want a unidque ID |
|
124 | - * @param integer $start Which record to start at |
|
125 | - * @param integer $limit Max number of objects to fetch |
|
126 | - * @return string An MD5 of the query |
|
127 | - */ |
|
128 | - protected function _getIdForCache($query, $start, $limit) |
|
129 | - { |
|
130 | - $id = md5($query . '-' . (string)$start . '-' . (string)$limit); |
|
131 | - |
|
132 | - return $id; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * create a new object |
|
137 | - * |
|
138 | - * @param bool $isNew Flag the new objects as "new"? |
|
139 | - * |
|
140 | - * @return object |
|
141 | - */ |
|
142 | - public function &create($isNew = true) |
|
143 | - { |
|
144 | - $obj = new $this->className(); |
|
145 | - if ($isNew === true) { |
|
146 | - $obj->setNew(); |
|
147 | - } |
|
148 | - |
|
149 | - return $obj; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * retrieve an object |
|
154 | - * |
|
155 | - * @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 |
|
156 | - * @param bool $as_object whether to return an object or an array |
|
157 | - * @return mixed reference to the object, FALSE if failed |
|
158 | - */ |
|
159 | - public function &get($id, $as_object = true) |
|
160 | - { |
|
161 | - if (is_array($this->keyName)) { |
|
162 | - $criteria = new CriteriaCompo(); |
|
163 | - $vnb = count($this->keyName); |
|
164 | - for ($i = 0; $i < $vnb; ++$i) { |
|
165 | - $criteria->add(new Criteria($this->keyName[$i], (int)$id[$i])); |
|
166 | - } |
|
167 | - } else { |
|
168 | - $criteria = new Criteria($this->keyName, (int)$id); |
|
169 | - } |
|
170 | - $criteria->setLimit(1); |
|
171 | - $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
172 | - if (count($obj_array) != 1) { |
|
173 | - $ret = null; |
|
174 | - } else { |
|
175 | - $ret =& $obj_array[0]; |
|
176 | - } |
|
177 | - |
|
178 | - return $ret; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * retrieve objects from the database |
|
183 | - * |
|
184 | - * @param null|CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
185 | - * @param bool $id_as_key use the ID as key for the array? |
|
186 | - * @param bool $as_object return an array of objects? |
|
187 | - * |
|
188 | - * @param string $fields |
|
189 | - * @param bool $autoSort |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $fields = '*', $autoSort = true) |
|
193 | - { |
|
194 | - require_once __DIR__ . '/lite.php'; |
|
195 | - $ret = array(); |
|
196 | - $limit = $start = 0; |
|
197 | - $sql = 'SELECT ' . $fields . ' FROM ' . $this->table; |
|
198 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
199 | - $sql .= ' ' . $criteria->renderWhere(); |
|
200 | - if ($criteria->groupby != '') { |
|
201 | - $sql .= $criteria->getGroupby(); |
|
202 | - } |
|
203 | - if ($criteria->getSort() != '') { |
|
204 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
205 | - } elseif ($this->identifierName != '' && $autoSort) { |
|
206 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
207 | - } |
|
208 | - $limit = $criteria->getLimit(); |
|
209 | - $start = $criteria->getStart(); |
|
210 | - } |
|
211 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
212 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
213 | - $cacheData = $Cache_Lite->get($id); |
|
214 | - if ($cacheData === false) { |
|
215 | - $result = $this->db->query($sql, $limit, $start); |
|
216 | - if (!$result) { |
|
217 | - return $ret; |
|
218 | - } |
|
219 | - $ret = $this->convertResultSet($result, $id_as_key, $as_object, $fields); |
|
220 | - $Cache_Lite->save($ret); |
|
221 | - |
|
222 | - return $ret; |
|
223 | - } else { |
|
224 | - return $cacheData; |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Convert a database resultset to a returnable array |
|
230 | - * |
|
231 | - * @param object $result database resultset |
|
232 | - * @param boolean $id_as_key - should NOT be used with joint keys |
|
233 | - * @param boolean $as_object |
|
234 | - * @param string $fields Requested fields from the query |
|
235 | - * |
|
236 | - * @return array |
|
237 | - */ |
|
238 | - protected function convertResultSet($result, $id_as_key = false, $as_object = true, $fields = '*') |
|
239 | - { |
|
240 | - $ret = array(); |
|
241 | - while ($myrow = $this->db->fetchArray($result)) { |
|
242 | - $obj =& $this->create(false); |
|
243 | - $obj->assignVars($myrow); |
|
244 | - if (!$id_as_key) { |
|
245 | - if ($as_object) { |
|
246 | - $ret[] =& $obj; |
|
247 | - } else { |
|
248 | - $row = array(); |
|
249 | - $vars = $obj->getVars(); |
|
250 | - $tbl_tmp = array_keys($vars); |
|
251 | - foreach ($tbl_tmp as $i) { |
|
252 | - $row[$i] = $obj->getVar($i); |
|
253 | - } |
|
254 | - $ret[] = $row; |
|
255 | - } |
|
256 | - } else { |
|
257 | - if ($as_object) { |
|
258 | - if ($fields === '*') { |
|
259 | - $ret[$myrow[$this->keyName]] =& $obj; |
|
260 | - } else { |
|
261 | - $ret[] =& $obj; |
|
262 | - } |
|
263 | - } else { |
|
264 | - $row = array(); |
|
265 | - $vars = $obj->getVars(); |
|
266 | - $tbl_tmp = array_keys($vars); |
|
267 | - foreach ($tbl_tmp as $i) { |
|
268 | - $row[$i] = $obj->getVar($i); |
|
269 | - } |
|
270 | - $ret[$myrow[$this->keyName]] = $row; |
|
271 | - } |
|
272 | - } |
|
273 | - unset($obj); |
|
274 | - } |
|
275 | - |
|
276 | - return $ret; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * get IDs of objects matching a condition |
|
281 | - * |
|
282 | - * @param object $criteria {@link CriteriaElement} to match |
|
283 | - * @return array of object IDs |
|
284 | - */ |
|
285 | - public function getIds($criteria = null) |
|
286 | - { |
|
287 | - require_once __DIR__ . '/lite.php'; |
|
288 | - $limit = $start = 0; |
|
289 | - |
|
290 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
291 | - $sql = 'SELECT ' . $this->keyName . ' FROM ' . $this->table; |
|
292 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
293 | - $sql .= ' ' . $criteria->renderWhere(); |
|
294 | - if ($criteria->groupby != '') { |
|
295 | - $sql .= $criteria->getGroupby(); |
|
296 | - } |
|
297 | - if ($criteria->getSort() != '') { |
|
298 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
299 | - } elseif ($this->identifierName != '') { |
|
300 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
301 | - } |
|
302 | - $limit = $criteria->getLimit(); |
|
303 | - $start = $criteria->getStart(); |
|
304 | - } |
|
305 | - |
|
306 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
307 | - $cacheData = $Cache_Lite->get($id); |
|
308 | - if ($cacheData === false) { |
|
309 | - $result = $this->db->query($sql, $limit, $start); |
|
310 | - $ret = array(); |
|
311 | - while ($myrow = $this->db->fetchArray($result)) { |
|
312 | - $ret[] = $myrow[$this->keyName]; |
|
313 | - } |
|
314 | - $Cache_Lite->save($ret); |
|
315 | - |
|
316 | - return $ret; |
|
317 | - } else { |
|
318 | - return $cacheData; |
|
319 | - } |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
324 | - * |
|
325 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
326 | - * @return array |
|
327 | - */ |
|
328 | - public function getList($criteria = null) |
|
329 | - { |
|
330 | - require_once __DIR__ . '/lite.php'; |
|
331 | - $limit = $start = 0; |
|
332 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
333 | - |
|
334 | - $ret = array(); |
|
335 | - |
|
336 | - $sql = 'SELECT ' . $this->keyName; |
|
337 | - if (!empty($this->identifierName)) { |
|
338 | - $sql .= ', ' . $this->identifierName; |
|
339 | - } |
|
340 | - $sql .= ' FROM ' . $this->table; |
|
341 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
342 | - $sql .= ' ' . $criteria->renderWhere(); |
|
343 | - if ($criteria->groupby != '') { |
|
344 | - $sql .= $criteria->getGroupby(); |
|
345 | - } |
|
346 | - if ($criteria->getSort() != '') { |
|
347 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
348 | - } elseif ($this->identifierName != '') { |
|
349 | - $sql .= ' ORDER BY ' . $this->identifierName; |
|
350 | - } |
|
351 | - $limit = $criteria->getLimit(); |
|
352 | - $start = $criteria->getStart(); |
|
353 | - } |
|
354 | - |
|
355 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
356 | - $cacheData = $Cache_Lite->get($id); |
|
357 | - if ($cacheData === false) { |
|
358 | - $result = $this->db->query($sql, $limit, $start); |
|
359 | - if (!$result) { |
|
360 | - $Cache_Lite->save($ret); |
|
361 | - |
|
362 | - return $ret; |
|
363 | - } |
|
364 | - |
|
365 | - $myts = MyTextSanitizer::getInstance(); |
|
366 | - while ($myrow = $this->db->fetchArray($result)) { |
|
367 | - //identifiers should be textboxes, so sanitize them like that |
|
368 | - $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->htmlSpecialChars($myrow[$this->identifierName]); |
|
369 | - } |
|
370 | - $Cache_Lite->save($ret); |
|
371 | - |
|
372 | - return $ret; |
|
373 | - } else { |
|
374 | - return $cacheData; |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Retourne des éléments selon leur ID |
|
380 | - * |
|
381 | - * @param array $ids Les ID des éléments à retrouver |
|
382 | - * @param null $additionnal |
|
383 | - * @return array Tableau d'objets |
|
384 | - */ |
|
385 | - public function getItemsFromIds($ids, $additionnal = null) |
|
386 | - { |
|
387 | - $ret = array(); |
|
388 | - if (is_array($ids) && count($ids) > 0) { |
|
389 | - $criteria = new CriteriaCompo(); |
|
390 | - $criteria->add(new Criteria($this->keyName, '(' . implode(',', $ids) . ')', 'IN')); |
|
391 | - if (!is_null($additionnal)) { |
|
392 | - $criteria->add($additionnal); |
|
393 | - } |
|
394 | - $ret =& $this->getObjects($criteria, true); |
|
395 | - } |
|
396 | - |
|
397 | - return $ret; |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * count objects matching a condition |
|
402 | - * |
|
403 | - * @param object $criteria {@link CriteriaElement} to match |
|
404 | - * @return int count of objects |
|
405 | - */ |
|
406 | - public function getCount($criteria = null) |
|
407 | - { |
|
408 | - $field = ''; |
|
409 | - $groupby = false; |
|
410 | - $limit = $start = 0; |
|
411 | - require_once __DIR__ . '/lite.php'; |
|
412 | - |
|
413 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
414 | - if ($criteria->groupby != '') { |
|
415 | - $groupby = true; |
|
416 | - $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
417 | - } |
|
418 | - } |
|
419 | - $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table; |
|
420 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
421 | - $sql .= ' ' . $criteria->renderWhere(); |
|
422 | - if ($criteria->groupby != '') { |
|
423 | - $sql .= $criteria->getGroupby(); |
|
424 | - } |
|
425 | - $limit = $criteria->getLimit(); |
|
426 | - $start = $criteria->getStart(); |
|
427 | - } |
|
428 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
429 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
430 | - $cacheData = $Cache_Lite->get($id); |
|
431 | - if ($cacheData === false) { |
|
432 | - $result = $this->db->query($sql, $limit, $start); |
|
433 | - if (!$result) { |
|
434 | - $ret = 0; |
|
435 | - $Cache_Lite->save($ret); |
|
436 | - |
|
437 | - return $ret; |
|
438 | - } |
|
439 | - if ($groupby == false) { |
|
440 | - list($count) = $this->db->fetchRow($result); |
|
441 | - $Cache_Lite->save($count); |
|
442 | - |
|
443 | - return $count; |
|
444 | - } else { |
|
445 | - $ret = array(); |
|
446 | - while (list($id, $count) = $this->db->fetchRow($result)) { |
|
447 | - $ret[$id] = $count; |
|
448 | - } |
|
449 | - $Cache_Lite->save($ret); |
|
450 | - |
|
451 | - return $ret; |
|
452 | - } |
|
453 | - } else { |
|
454 | - return $cacheData; |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Retourne le total d'un champ |
|
460 | - * |
|
461 | - * @param string $field Le champ dont on veut calculer le total |
|
462 | - * @param object $criteria {@link CriteriaElement} to match |
|
463 | - * @return integer le total |
|
464 | - */ |
|
465 | - public function getSum($field, $criteria = null) |
|
466 | - { |
|
467 | - $limit = $start = 0; |
|
468 | - require_once __DIR__ . '/lite.php'; |
|
469 | - |
|
470 | - $sql = 'SELECT Sum(' . $field . ') as cpt FROM ' . $this->table; |
|
471 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
472 | - $sql .= ' ' . $criteria->renderWhere(); |
|
473 | - if ($criteria->groupby != '') { |
|
474 | - $sql .= $criteria->getGroupby(); |
|
475 | - } |
|
476 | - $limit = $criteria->getLimit(); |
|
477 | - $start = $criteria->getStart(); |
|
478 | - } |
|
479 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
480 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
481 | - $cacheData = $Cache_Lite->get($id); |
|
482 | - if ($cacheData === false) { |
|
483 | - $result = $this->db->query($sql, $limit, $start); |
|
484 | - if (!$result) { |
|
485 | - $ret = 0; |
|
486 | - $Cache_Lite->save($ret); |
|
487 | - |
|
488 | - return $ret; |
|
489 | - } |
|
490 | - $row = $this->db->fetchArray($result); |
|
491 | - $count = $row['cpt']; |
|
492 | - $Cache_Lite->save($count); |
|
493 | - |
|
494 | - return $count; |
|
495 | - } else { |
|
496 | - return $cacheData; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * delete an object from the database |
|
502 | - * |
|
503 | - * @param XoopsObject $obj reference to the object to delete |
|
504 | - * @param bool $force |
|
505 | - * @return bool FALSE if failed. |
|
506 | - */ |
|
507 | - public function delete(XoopsObject $obj, $force = false) |
|
508 | - { |
|
509 | - if (is_array($this->keyName)) { |
|
510 | - $clause = array(); |
|
511 | - $vnb = count($this->keyName); |
|
512 | - for ($i = 0; $i < $vnb; ++$i) { |
|
513 | - $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
514 | - } |
|
515 | - $whereclause = implode(' AND ', $clause); |
|
516 | - } else { |
|
517 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
518 | - } |
|
519 | - $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
520 | - if (false != $force) { |
|
521 | - $result = $this->db->queryF($sql); |
|
522 | - } else { |
|
523 | - $result = $this->db->query($sql); |
|
524 | - } |
|
525 | - // Clear cache |
|
526 | - $this->forceCacheClean(); |
|
527 | - |
|
528 | - if (!$result) { |
|
529 | - return false; |
|
530 | - } |
|
531 | - |
|
532 | - return true; |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Quickly insert a record like this $myobject_handler->quickInsert('field1' => field1value, 'field2' => $field2value) |
|
537 | - * |
|
538 | - * @param array $vars Array containing the fields name and value |
|
539 | - * @param bool $force whether to force the query execution despite security settings |
|
540 | - * @return bool @link insert's value |
|
541 | - */ |
|
542 | - public function quickInsert($vars = null, $force = true) |
|
543 | - { |
|
544 | - $object = $this->create(true); |
|
545 | - $object->setVars($vars); |
|
546 | - $retval =& $this->insert($object, $force); |
|
547 | - unset($object); |
|
548 | - |
|
549 | - // Clear cache |
|
550 | - $this->forceCacheClean(); |
|
551 | - |
|
552 | - return $retval; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * insert a new object in the database |
|
557 | - * |
|
558 | - * @param XoopsObject $obj reference to the object |
|
559 | - * @param bool $force whether to force the query execution despite security settings |
|
560 | - * @param bool $checkObject check if the object is dirty and clean the attributes |
|
561 | - * @param bool $ignoreInsert |
|
562 | - * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
563 | - */ |
|
564 | - |
|
565 | - public function insert(XoopsObject $obj, $force = false, $checkObject = true, $ignoreInsert = false) |
|
566 | - { |
|
567 | - if ($checkObject != false) { |
|
568 | - if (!is_object($obj)) { |
|
569 | - trigger_error('Error, not object'); |
|
570 | - |
|
571 | - return false; |
|
572 | - } |
|
573 | - /** |
|
574 | - * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
575 | - */ |
|
576 | - if (!is_a($obj, $this->className)) { |
|
577 | - $obj->setErrors(get_class($obj) . ' Differs from ' . $this->className); |
|
578 | - |
|
579 | - return false; |
|
580 | - } |
|
581 | - if (!$obj->isDirty()) { |
|
582 | - $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 |
|
583 | - |
|
584 | - return true; |
|
585 | - } |
|
586 | - } |
|
587 | - if (!$obj->cleanVars()) { |
|
588 | - foreach ($obj->getErrors() as $oneerror) { |
|
589 | - trigger_error($oneerror); |
|
590 | - } |
|
591 | - |
|
592 | - return false; |
|
593 | - } |
|
594 | - foreach ($obj->cleanVars as $k => $v) { |
|
595 | - if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
596 | - $cleanvars[$k] = (int)$v; |
|
597 | - } elseif (is_array($v)) { |
|
598 | - $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
599 | - } else { |
|
600 | - $cleanvars[$k] = $this->db->quoteString($v); |
|
601 | - } |
|
602 | - } |
|
603 | - if (isset($cleanvars['dohtml'])) { // Modification Herv� to be able to use dohtml |
|
604 | - unset($cleanvars['dohtml']); |
|
605 | - } |
|
606 | - if ($obj->isNew()) { |
|
607 | - if (!is_array($this->keyName)) { |
|
608 | - if ($cleanvars[$this->keyName] < 1) { |
|
609 | - $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
610 | - } |
|
611 | - } |
|
612 | - $ignore = ''; |
|
613 | - if ($ignoreInsert) { |
|
614 | - $ignore = 'IGNORE'; |
|
615 | - } |
|
616 | - $sql = "INSERT $ignore INTO " . $this->table . ' (' . implode(',', array_keys($cleanvars)) . ') VALUES (' . implode(',', array_values($cleanvars)) . ')'; |
|
617 | - } else { |
|
618 | - $sql = 'UPDATE ' . $this->table . ' SET'; |
|
619 | - foreach ($cleanvars as $key => $value) { |
|
620 | - if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
621 | - continue; |
|
622 | - } |
|
623 | - if (isset($notfirst)) { |
|
624 | - $sql .= ','; |
|
625 | - } |
|
626 | - $sql .= ' ' . $key . ' = ' . $value; |
|
627 | - $notfirst = true; |
|
628 | - } |
|
629 | - if (is_array($this->keyName)) { |
|
630 | - $whereclause = ''; |
|
631 | - $vnb = count($this->keyName); |
|
632 | - for ($i = 0; $i < $vnb; ++$i) { |
|
633 | - if ($i > 0) { |
|
634 | - $whereclause .= ' AND '; |
|
635 | - } |
|
636 | - $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
637 | - } |
|
638 | - } else { |
|
639 | - $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
640 | - } |
|
641 | - $sql .= ' WHERE ' . $whereclause; |
|
642 | - } |
|
643 | - |
|
644 | - if (false != $force) { |
|
645 | - $result = $this->db->queryF($sql); |
|
646 | - } else { |
|
647 | - $result = $this->db->query($sql); |
|
648 | - } |
|
649 | - |
|
650 | - // Clear cache |
|
651 | - $this->forceCacheClean(); |
|
652 | - |
|
653 | - if (!$result) { |
|
654 | - return false; |
|
655 | - } |
|
656 | - if ($obj->isNew() && !is_array($this->keyName)) { |
|
657 | - $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
658 | - } |
|
659 | - |
|
660 | - return true; |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Change a value for objects with a certain criteria |
|
665 | - * |
|
666 | - * @param string $fieldname Name of the field |
|
667 | - * @param string $fieldvalue Value to write |
|
668 | - * @param object $criteria {@link CriteriaElement} |
|
669 | - * |
|
670 | - * @param bool $force |
|
671 | - * @return bool |
|
672 | - */ |
|
673 | - public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
|
674 | - { |
|
675 | - $set_clause = $fieldname . ' = '; |
|
676 | - if (is_numeric($fieldvalue)) { |
|
677 | - $set_clause .= $fieldvalue; |
|
678 | - } elseif (is_array($fieldvalue)) { |
|
679 | - $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
680 | - } else { |
|
681 | - $set_clause .= $this->db->quoteString($fieldvalue); |
|
682 | - } |
|
683 | - $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
684 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
685 | - $sql .= ' ' . $criteria->renderWhere(); |
|
686 | - } |
|
687 | - if ($force) { |
|
688 | - $result = $this->db->queryF($sql); |
|
689 | - } else { |
|
690 | - $result = $this->db->query($sql); |
|
691 | - } |
|
692 | - |
|
693 | - // Clear cache |
|
694 | - $this->forceCacheClean(); |
|
695 | - |
|
696 | - if (!$result) { |
|
697 | - return false; |
|
698 | - } |
|
699 | - |
|
700 | - return true; |
|
701 | - } |
|
702 | - |
|
703 | - // check if target object is attempting to use duplicated info |
|
704 | - public function isDuplicated(&$obj, $field = '', $error = '') |
|
705 | - { |
|
706 | - if (empty($field)) { |
|
707 | - return false; |
|
708 | - } |
|
709 | - $criteria = new CriteriaCompo(); |
|
710 | - $criteria->add(new Criteria($field, $obj->getVar($field))); |
|
711 | - // one more condition if target object exisits in database |
|
712 | - if (!$obj->isNew()) { |
|
713 | - $criteria->add(new Criteria($this->_key, $obj->getVar($this->_key), '!=')); |
|
714 | - } |
|
715 | - if ($this->getCount($criteria)) { |
|
716 | - $obj->setErrors($error); |
|
717 | - |
|
718 | - return true; |
|
719 | - } |
|
720 | - |
|
721 | - return false; |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * delete all objects meeting the conditions |
|
726 | - * |
|
727 | - * @param object $criteria {@link CriteriaElement} with conditions to meet |
|
728 | - * @return bool |
|
729 | - */ |
|
730 | - public function deleteAll($criteria = null) |
|
731 | - { |
|
732 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
733 | - $sql = 'DELETE FROM ' . $this->table; |
|
734 | - $sql .= ' ' . $criteria->renderWhere(); |
|
735 | - if (!$this->db->queryF($sql)) { |
|
736 | - return false; |
|
737 | - } |
|
738 | - $rows = $this->db->getAffectedRows(); |
|
739 | - |
|
740 | - // Clear cache |
|
741 | - $this->forceCacheClean(); |
|
742 | - |
|
743 | - return $rows > 0 ? $rows : true; |
|
744 | - } |
|
745 | - |
|
746 | - return false; |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Compare two objects and returns, in an array, the differences |
|
751 | - * |
|
752 | - * @param XoopsObject $old_object The first object to compare |
|
753 | - * @param XoopsObject $new_object The new object |
|
754 | - * @return array differences key = fieldname, value = array('old_value', 'new_value') |
|
755 | - */ |
|
756 | - public function compareObjects($old_object, $new_object) |
|
757 | - { |
|
758 | - $ret = array(); |
|
759 | - $vars_name = array_keys($old_object->getVars()); |
|
760 | - foreach ($vars_name as $one_var) { |
|
761 | - if ($old_object->getVar($one_var, 'f') == $new_object->getVar($one_var, 'f')) { |
|
762 | - } else { |
|
763 | - $ret[$one_var] = array($old_object->getVar($one_var), $new_object->getVar($one_var)); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - return $ret; |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * Get distincted values of a field in the table |
|
772 | - * |
|
773 | - * @param string $field Field's name |
|
774 | - * @param object $criteria {@link CriteriaElement} conditions to be met |
|
775 | - * @param string $format Format in wich we want the datas |
|
776 | - * @return array containing the distinct values |
|
777 | - */ |
|
778 | - public function getDistincts($field, $criteria = null, $format = 's') |
|
779 | - { |
|
780 | - require_once __DIR__ . '/lite.php'; |
|
781 | - $limit = $start = 0; |
|
782 | - $sql = 'SELECT ' . $this->keyName . ', ' . $field . ' FROM ' . $this->table; |
|
783 | - if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
784 | - $sql .= ' ' . $criteria->renderWhere(); |
|
785 | - $limit = $criteria->getLimit(); |
|
786 | - $start = $criteria->getStart(); |
|
787 | - } |
|
788 | - $sql .= ' GROUP BY ' . $field . ' ORDER BY ' . $field; |
|
789 | - |
|
790 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
791 | - $id = $this->_getIdForCache($sql, $start, $limit); |
|
792 | - $cacheData = $Cache_Lite->get($id); |
|
793 | - if ($cacheData === false) { |
|
794 | - $result = $this->db->query($sql, $limit, $start); |
|
795 | - $ret = array(); |
|
796 | - $obj = new $this->className(); |
|
797 | - while ($myrow = $this->db->fetchArray($result)) { |
|
798 | - $obj->setVar($field, $myrow[$field]); |
|
799 | - $ret[$myrow[$this->keyName]] = $obj->getVar($field, $format); |
|
800 | - } |
|
801 | - $Cache_Lite->save($ret); |
|
802 | - |
|
803 | - return $ret; |
|
804 | - } else { |
|
805 | - return $cacheData; |
|
806 | - } |
|
807 | - } |
|
808 | - |
|
809 | - /** |
|
810 | - * A generic shortcut to getObjects |
|
811 | - * |
|
812 | - * @author Herve Thouzard - Instant Zero |
|
813 | - * |
|
814 | - * @param integer $start Starting position |
|
815 | - * @param integer $limit Maximum count of elements to return |
|
816 | - * @param string $sort Field to use for the sort |
|
817 | - * @param string $order Sort order |
|
818 | - * @param boolean $idAsKey Do we have to return an array whoses keys are the record's ID ? |
|
819 | - * @return array Array of current objects |
|
820 | - */ |
|
821 | - public function getItems($start = 0, $limit = 0, $sort = '', $order = 'ASC', $idAsKey = true) |
|
822 | - { |
|
823 | - if (trim($order) == '') { |
|
824 | - if (isset($this->identifierName) && trim($this->identifierName) != '') { |
|
825 | - $order = $this->identifierName; |
|
826 | - } else { |
|
827 | - $order = $this->keyName; |
|
828 | - } |
|
829 | - } |
|
830 | - $items = array(); |
|
831 | - $critere = new Criteria($this->keyName, 0, '<>'); |
|
832 | - $critere->setLimit($limit); |
|
833 | - $critere->setStart($start); |
|
834 | - $critere->setSort($sort); |
|
835 | - $critere->setOrder($order); |
|
836 | - $items =& $this->getObjects($critere, $idAsKey); |
|
837 | - |
|
838 | - return $items; |
|
839 | - } |
|
840 | - |
|
841 | - /** |
|
842 | - * Forces the cache to be cleaned |
|
843 | - */ |
|
844 | - public function forceCacheClean() |
|
845 | - { |
|
846 | - require_once __DIR__ . '/lite.php'; |
|
847 | - $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
848 | - $Cache_Lite->clean(); |
|
849 | - } |
|
81 | + public $table; |
|
82 | + public $keyName; |
|
83 | + public $className; |
|
84 | + public $identifierName; |
|
85 | + protected $cacheOptions = array(); |
|
86 | + /**#@-*/ |
|
87 | + |
|
88 | + /** |
|
89 | + * Constructor - called from child classes |
|
90 | + * @param object $db {@link XoopsDatabase} object |
|
91 | + * @param string $tablename Name of database table |
|
92 | + * @param string $classname Name of Class, this handler is managing |
|
93 | + * @param string $keyname Name of the property, holding the key |
|
94 | + * @param string $idenfierName Name of the property, holding the label |
|
95 | + * @param array $cacheOptions Optional, options for the cache |
|
96 | + * |
|
97 | + */ |
|
98 | + public function __construct(&$db, $tablename, $classname, $keyname, $idenfierName = '', $cacheOptions = null) |
|
99 | + { |
|
100 | + parent::__construct($db); |
|
101 | + $this->table = $db->prefix($tablename); |
|
102 | + $this->keyName = $keyname; |
|
103 | + $this->className = $classname; |
|
104 | + if (trim($idenfierName) != '') { |
|
105 | + $this->identifierName = $idenfierName; |
|
106 | + } |
|
107 | + // To diable cache, add this line after the first one : 'caching' => false, |
|
108 | + if (is_null($cacheOptions)) { |
|
109 | + $this->setCachingOptions(array('cacheDir' => REFERENCES_CACHE_PATH, 'lifeTime' => null, 'automaticSerialization' => true, 'fileNameProtection' => false)); |
|
110 | + } else { |
|
111 | + $this->setCachingOptions($cacheOptions); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + public function setCachingOptions($cacheOptions) |
|
116 | + { |
|
117 | + $this->cacheOptions = $cacheOptions; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Generates a unique ID for a Sql Query |
|
122 | + * |
|
123 | + * @param string $query The SQL query for which we want a unidque ID |
|
124 | + * @param integer $start Which record to start at |
|
125 | + * @param integer $limit Max number of objects to fetch |
|
126 | + * @return string An MD5 of the query |
|
127 | + */ |
|
128 | + protected function _getIdForCache($query, $start, $limit) |
|
129 | + { |
|
130 | + $id = md5($query . '-' . (string)$start . '-' . (string)$limit); |
|
131 | + |
|
132 | + return $id; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * create a new object |
|
137 | + * |
|
138 | + * @param bool $isNew Flag the new objects as "new"? |
|
139 | + * |
|
140 | + * @return object |
|
141 | + */ |
|
142 | + public function &create($isNew = true) |
|
143 | + { |
|
144 | + $obj = new $this->className(); |
|
145 | + if ($isNew === true) { |
|
146 | + $obj->setNew(); |
|
147 | + } |
|
148 | + |
|
149 | + return $obj; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * retrieve an object |
|
154 | + * |
|
155 | + * @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 |
|
156 | + * @param bool $as_object whether to return an object or an array |
|
157 | + * @return mixed reference to the object, FALSE if failed |
|
158 | + */ |
|
159 | + public function &get($id, $as_object = true) |
|
160 | + { |
|
161 | + if (is_array($this->keyName)) { |
|
162 | + $criteria = new CriteriaCompo(); |
|
163 | + $vnb = count($this->keyName); |
|
164 | + for ($i = 0; $i < $vnb; ++$i) { |
|
165 | + $criteria->add(new Criteria($this->keyName[$i], (int)$id[$i])); |
|
166 | + } |
|
167 | + } else { |
|
168 | + $criteria = new Criteria($this->keyName, (int)$id); |
|
169 | + } |
|
170 | + $criteria->setLimit(1); |
|
171 | + $obj_array =& $this->getObjects($criteria, false, $as_object); |
|
172 | + if (count($obj_array) != 1) { |
|
173 | + $ret = null; |
|
174 | + } else { |
|
175 | + $ret =& $obj_array[0]; |
|
176 | + } |
|
177 | + |
|
178 | + return $ret; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * retrieve objects from the database |
|
183 | + * |
|
184 | + * @param null|CriteriaElement $criteria {@link CriteriaElement} conditions to be met |
|
185 | + * @param bool $id_as_key use the ID as key for the array? |
|
186 | + * @param bool $as_object return an array of objects? |
|
187 | + * |
|
188 | + * @param string $fields |
|
189 | + * @param bool $autoSort |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function &getObjects(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $fields = '*', $autoSort = true) |
|
193 | + { |
|
194 | + require_once __DIR__ . '/lite.php'; |
|
195 | + $ret = array(); |
|
196 | + $limit = $start = 0; |
|
197 | + $sql = 'SELECT ' . $fields . ' FROM ' . $this->table; |
|
198 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
199 | + $sql .= ' ' . $criteria->renderWhere(); |
|
200 | + if ($criteria->groupby != '') { |
|
201 | + $sql .= $criteria->getGroupby(); |
|
202 | + } |
|
203 | + if ($criteria->getSort() != '') { |
|
204 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
205 | + } elseif ($this->identifierName != '' && $autoSort) { |
|
206 | + $sql .= ' ORDER BY ' . $this->identifierName; |
|
207 | + } |
|
208 | + $limit = $criteria->getLimit(); |
|
209 | + $start = $criteria->getStart(); |
|
210 | + } |
|
211 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
212 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
213 | + $cacheData = $Cache_Lite->get($id); |
|
214 | + if ($cacheData === false) { |
|
215 | + $result = $this->db->query($sql, $limit, $start); |
|
216 | + if (!$result) { |
|
217 | + return $ret; |
|
218 | + } |
|
219 | + $ret = $this->convertResultSet($result, $id_as_key, $as_object, $fields); |
|
220 | + $Cache_Lite->save($ret); |
|
221 | + |
|
222 | + return $ret; |
|
223 | + } else { |
|
224 | + return $cacheData; |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Convert a database resultset to a returnable array |
|
230 | + * |
|
231 | + * @param object $result database resultset |
|
232 | + * @param boolean $id_as_key - should NOT be used with joint keys |
|
233 | + * @param boolean $as_object |
|
234 | + * @param string $fields Requested fields from the query |
|
235 | + * |
|
236 | + * @return array |
|
237 | + */ |
|
238 | + protected function convertResultSet($result, $id_as_key = false, $as_object = true, $fields = '*') |
|
239 | + { |
|
240 | + $ret = array(); |
|
241 | + while ($myrow = $this->db->fetchArray($result)) { |
|
242 | + $obj =& $this->create(false); |
|
243 | + $obj->assignVars($myrow); |
|
244 | + if (!$id_as_key) { |
|
245 | + if ($as_object) { |
|
246 | + $ret[] =& $obj; |
|
247 | + } else { |
|
248 | + $row = array(); |
|
249 | + $vars = $obj->getVars(); |
|
250 | + $tbl_tmp = array_keys($vars); |
|
251 | + foreach ($tbl_tmp as $i) { |
|
252 | + $row[$i] = $obj->getVar($i); |
|
253 | + } |
|
254 | + $ret[] = $row; |
|
255 | + } |
|
256 | + } else { |
|
257 | + if ($as_object) { |
|
258 | + if ($fields === '*') { |
|
259 | + $ret[$myrow[$this->keyName]] =& $obj; |
|
260 | + } else { |
|
261 | + $ret[] =& $obj; |
|
262 | + } |
|
263 | + } else { |
|
264 | + $row = array(); |
|
265 | + $vars = $obj->getVars(); |
|
266 | + $tbl_tmp = array_keys($vars); |
|
267 | + foreach ($tbl_tmp as $i) { |
|
268 | + $row[$i] = $obj->getVar($i); |
|
269 | + } |
|
270 | + $ret[$myrow[$this->keyName]] = $row; |
|
271 | + } |
|
272 | + } |
|
273 | + unset($obj); |
|
274 | + } |
|
275 | + |
|
276 | + return $ret; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * get IDs of objects matching a condition |
|
281 | + * |
|
282 | + * @param object $criteria {@link CriteriaElement} to match |
|
283 | + * @return array of object IDs |
|
284 | + */ |
|
285 | + public function getIds($criteria = null) |
|
286 | + { |
|
287 | + require_once __DIR__ . '/lite.php'; |
|
288 | + $limit = $start = 0; |
|
289 | + |
|
290 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
291 | + $sql = 'SELECT ' . $this->keyName . ' FROM ' . $this->table; |
|
292 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
293 | + $sql .= ' ' . $criteria->renderWhere(); |
|
294 | + if ($criteria->groupby != '') { |
|
295 | + $sql .= $criteria->getGroupby(); |
|
296 | + } |
|
297 | + if ($criteria->getSort() != '') { |
|
298 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
299 | + } elseif ($this->identifierName != '') { |
|
300 | + $sql .= ' ORDER BY ' . $this->identifierName; |
|
301 | + } |
|
302 | + $limit = $criteria->getLimit(); |
|
303 | + $start = $criteria->getStart(); |
|
304 | + } |
|
305 | + |
|
306 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
307 | + $cacheData = $Cache_Lite->get($id); |
|
308 | + if ($cacheData === false) { |
|
309 | + $result = $this->db->query($sql, $limit, $start); |
|
310 | + $ret = array(); |
|
311 | + while ($myrow = $this->db->fetchArray($result)) { |
|
312 | + $ret[] = $myrow[$this->keyName]; |
|
313 | + } |
|
314 | + $Cache_Lite->save($ret); |
|
315 | + |
|
316 | + return $ret; |
|
317 | + } else { |
|
318 | + return $cacheData; |
|
319 | + } |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS |
|
324 | + * |
|
325 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
326 | + * @return array |
|
327 | + */ |
|
328 | + public function getList($criteria = null) |
|
329 | + { |
|
330 | + require_once __DIR__ . '/lite.php'; |
|
331 | + $limit = $start = 0; |
|
332 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
333 | + |
|
334 | + $ret = array(); |
|
335 | + |
|
336 | + $sql = 'SELECT ' . $this->keyName; |
|
337 | + if (!empty($this->identifierName)) { |
|
338 | + $sql .= ', ' . $this->identifierName; |
|
339 | + } |
|
340 | + $sql .= ' FROM ' . $this->table; |
|
341 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
342 | + $sql .= ' ' . $criteria->renderWhere(); |
|
343 | + if ($criteria->groupby != '') { |
|
344 | + $sql .= $criteria->getGroupby(); |
|
345 | + } |
|
346 | + if ($criteria->getSort() != '') { |
|
347 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
348 | + } elseif ($this->identifierName != '') { |
|
349 | + $sql .= ' ORDER BY ' . $this->identifierName; |
|
350 | + } |
|
351 | + $limit = $criteria->getLimit(); |
|
352 | + $start = $criteria->getStart(); |
|
353 | + } |
|
354 | + |
|
355 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
356 | + $cacheData = $Cache_Lite->get($id); |
|
357 | + if ($cacheData === false) { |
|
358 | + $result = $this->db->query($sql, $limit, $start); |
|
359 | + if (!$result) { |
|
360 | + $Cache_Lite->save($ret); |
|
361 | + |
|
362 | + return $ret; |
|
363 | + } |
|
364 | + |
|
365 | + $myts = MyTextSanitizer::getInstance(); |
|
366 | + while ($myrow = $this->db->fetchArray($result)) { |
|
367 | + //identifiers should be textboxes, so sanitize them like that |
|
368 | + $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->htmlSpecialChars($myrow[$this->identifierName]); |
|
369 | + } |
|
370 | + $Cache_Lite->save($ret); |
|
371 | + |
|
372 | + return $ret; |
|
373 | + } else { |
|
374 | + return $cacheData; |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Retourne des éléments selon leur ID |
|
380 | + * |
|
381 | + * @param array $ids Les ID des éléments à retrouver |
|
382 | + * @param null $additionnal |
|
383 | + * @return array Tableau d'objets |
|
384 | + */ |
|
385 | + public function getItemsFromIds($ids, $additionnal = null) |
|
386 | + { |
|
387 | + $ret = array(); |
|
388 | + if (is_array($ids) && count($ids) > 0) { |
|
389 | + $criteria = new CriteriaCompo(); |
|
390 | + $criteria->add(new Criteria($this->keyName, '(' . implode(',', $ids) . ')', 'IN')); |
|
391 | + if (!is_null($additionnal)) { |
|
392 | + $criteria->add($additionnal); |
|
393 | + } |
|
394 | + $ret =& $this->getObjects($criteria, true); |
|
395 | + } |
|
396 | + |
|
397 | + return $ret; |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * count objects matching a condition |
|
402 | + * |
|
403 | + * @param object $criteria {@link CriteriaElement} to match |
|
404 | + * @return int count of objects |
|
405 | + */ |
|
406 | + public function getCount($criteria = null) |
|
407 | + { |
|
408 | + $field = ''; |
|
409 | + $groupby = false; |
|
410 | + $limit = $start = 0; |
|
411 | + require_once __DIR__ . '/lite.php'; |
|
412 | + |
|
413 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
414 | + if ($criteria->groupby != '') { |
|
415 | + $groupby = true; |
|
416 | + $field = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used |
|
417 | + } |
|
418 | + } |
|
419 | + $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table; |
|
420 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
421 | + $sql .= ' ' . $criteria->renderWhere(); |
|
422 | + if ($criteria->groupby != '') { |
|
423 | + $sql .= $criteria->getGroupby(); |
|
424 | + } |
|
425 | + $limit = $criteria->getLimit(); |
|
426 | + $start = $criteria->getStart(); |
|
427 | + } |
|
428 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
429 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
430 | + $cacheData = $Cache_Lite->get($id); |
|
431 | + if ($cacheData === false) { |
|
432 | + $result = $this->db->query($sql, $limit, $start); |
|
433 | + if (!$result) { |
|
434 | + $ret = 0; |
|
435 | + $Cache_Lite->save($ret); |
|
436 | + |
|
437 | + return $ret; |
|
438 | + } |
|
439 | + if ($groupby == false) { |
|
440 | + list($count) = $this->db->fetchRow($result); |
|
441 | + $Cache_Lite->save($count); |
|
442 | + |
|
443 | + return $count; |
|
444 | + } else { |
|
445 | + $ret = array(); |
|
446 | + while (list($id, $count) = $this->db->fetchRow($result)) { |
|
447 | + $ret[$id] = $count; |
|
448 | + } |
|
449 | + $Cache_Lite->save($ret); |
|
450 | + |
|
451 | + return $ret; |
|
452 | + } |
|
453 | + } else { |
|
454 | + return $cacheData; |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * Retourne le total d'un champ |
|
460 | + * |
|
461 | + * @param string $field Le champ dont on veut calculer le total |
|
462 | + * @param object $criteria {@link CriteriaElement} to match |
|
463 | + * @return integer le total |
|
464 | + */ |
|
465 | + public function getSum($field, $criteria = null) |
|
466 | + { |
|
467 | + $limit = $start = 0; |
|
468 | + require_once __DIR__ . '/lite.php'; |
|
469 | + |
|
470 | + $sql = 'SELECT Sum(' . $field . ') as cpt FROM ' . $this->table; |
|
471 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
472 | + $sql .= ' ' . $criteria->renderWhere(); |
|
473 | + if ($criteria->groupby != '') { |
|
474 | + $sql .= $criteria->getGroupby(); |
|
475 | + } |
|
476 | + $limit = $criteria->getLimit(); |
|
477 | + $start = $criteria->getStart(); |
|
478 | + } |
|
479 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
480 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
481 | + $cacheData = $Cache_Lite->get($id); |
|
482 | + if ($cacheData === false) { |
|
483 | + $result = $this->db->query($sql, $limit, $start); |
|
484 | + if (!$result) { |
|
485 | + $ret = 0; |
|
486 | + $Cache_Lite->save($ret); |
|
487 | + |
|
488 | + return $ret; |
|
489 | + } |
|
490 | + $row = $this->db->fetchArray($result); |
|
491 | + $count = $row['cpt']; |
|
492 | + $Cache_Lite->save($count); |
|
493 | + |
|
494 | + return $count; |
|
495 | + } else { |
|
496 | + return $cacheData; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * delete an object from the database |
|
502 | + * |
|
503 | + * @param XoopsObject $obj reference to the object to delete |
|
504 | + * @param bool $force |
|
505 | + * @return bool FALSE if failed. |
|
506 | + */ |
|
507 | + public function delete(XoopsObject $obj, $force = false) |
|
508 | + { |
|
509 | + if (is_array($this->keyName)) { |
|
510 | + $clause = array(); |
|
511 | + $vnb = count($this->keyName); |
|
512 | + for ($i = 0; $i < $vnb; ++$i) { |
|
513 | + $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
514 | + } |
|
515 | + $whereclause = implode(' AND ', $clause); |
|
516 | + } else { |
|
517 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
518 | + } |
|
519 | + $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause; |
|
520 | + if (false != $force) { |
|
521 | + $result = $this->db->queryF($sql); |
|
522 | + } else { |
|
523 | + $result = $this->db->query($sql); |
|
524 | + } |
|
525 | + // Clear cache |
|
526 | + $this->forceCacheClean(); |
|
527 | + |
|
528 | + if (!$result) { |
|
529 | + return false; |
|
530 | + } |
|
531 | + |
|
532 | + return true; |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Quickly insert a record like this $myobject_handler->quickInsert('field1' => field1value, 'field2' => $field2value) |
|
537 | + * |
|
538 | + * @param array $vars Array containing the fields name and value |
|
539 | + * @param bool $force whether to force the query execution despite security settings |
|
540 | + * @return bool @link insert's value |
|
541 | + */ |
|
542 | + public function quickInsert($vars = null, $force = true) |
|
543 | + { |
|
544 | + $object = $this->create(true); |
|
545 | + $object->setVars($vars); |
|
546 | + $retval =& $this->insert($object, $force); |
|
547 | + unset($object); |
|
548 | + |
|
549 | + // Clear cache |
|
550 | + $this->forceCacheClean(); |
|
551 | + |
|
552 | + return $retval; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * insert a new object in the database |
|
557 | + * |
|
558 | + * @param XoopsObject $obj reference to the object |
|
559 | + * @param bool $force whether to force the query execution despite security settings |
|
560 | + * @param bool $checkObject check if the object is dirty and clean the attributes |
|
561 | + * @param bool $ignoreInsert |
|
562 | + * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
563 | + */ |
|
564 | + |
|
565 | + public function insert(XoopsObject $obj, $force = false, $checkObject = true, $ignoreInsert = false) |
|
566 | + { |
|
567 | + if ($checkObject != false) { |
|
568 | + if (!is_object($obj)) { |
|
569 | + trigger_error('Error, not object'); |
|
570 | + |
|
571 | + return false; |
|
572 | + } |
|
573 | + /** |
|
574 | + * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5 |
|
575 | + */ |
|
576 | + if (!is_a($obj, $this->className)) { |
|
577 | + $obj->setErrors(get_class($obj) . ' Differs from ' . $this->className); |
|
578 | + |
|
579 | + return false; |
|
580 | + } |
|
581 | + if (!$obj->isDirty()) { |
|
582 | + $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 |
|
583 | + |
|
584 | + return true; |
|
585 | + } |
|
586 | + } |
|
587 | + if (!$obj->cleanVars()) { |
|
588 | + foreach ($obj->getErrors() as $oneerror) { |
|
589 | + trigger_error($oneerror); |
|
590 | + } |
|
591 | + |
|
592 | + return false; |
|
593 | + } |
|
594 | + foreach ($obj->cleanVars as $k => $v) { |
|
595 | + if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) { |
|
596 | + $cleanvars[$k] = (int)$v; |
|
597 | + } elseif (is_array($v)) { |
|
598 | + $cleanvars[$k] = $this->db->quoteString(implode(',', $v)); |
|
599 | + } else { |
|
600 | + $cleanvars[$k] = $this->db->quoteString($v); |
|
601 | + } |
|
602 | + } |
|
603 | + if (isset($cleanvars['dohtml'])) { // Modification Herv� to be able to use dohtml |
|
604 | + unset($cleanvars['dohtml']); |
|
605 | + } |
|
606 | + if ($obj->isNew()) { |
|
607 | + if (!is_array($this->keyName)) { |
|
608 | + if ($cleanvars[$this->keyName] < 1) { |
|
609 | + $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq'); |
|
610 | + } |
|
611 | + } |
|
612 | + $ignore = ''; |
|
613 | + if ($ignoreInsert) { |
|
614 | + $ignore = 'IGNORE'; |
|
615 | + } |
|
616 | + $sql = "INSERT $ignore INTO " . $this->table . ' (' . implode(',', array_keys($cleanvars)) . ') VALUES (' . implode(',', array_values($cleanvars)) . ')'; |
|
617 | + } else { |
|
618 | + $sql = 'UPDATE ' . $this->table . ' SET'; |
|
619 | + foreach ($cleanvars as $key => $value) { |
|
620 | + if ((!is_array($this->keyName) && $key == $this->keyName) || (is_array($this->keyName) && in_array($key, $this->keyName))) { |
|
621 | + continue; |
|
622 | + } |
|
623 | + if (isset($notfirst)) { |
|
624 | + $sql .= ','; |
|
625 | + } |
|
626 | + $sql .= ' ' . $key . ' = ' . $value; |
|
627 | + $notfirst = true; |
|
628 | + } |
|
629 | + if (is_array($this->keyName)) { |
|
630 | + $whereclause = ''; |
|
631 | + $vnb = count($this->keyName); |
|
632 | + for ($i = 0; $i < $vnb; ++$i) { |
|
633 | + if ($i > 0) { |
|
634 | + $whereclause .= ' AND '; |
|
635 | + } |
|
636 | + $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]); |
|
637 | + } |
|
638 | + } else { |
|
639 | + $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName); |
|
640 | + } |
|
641 | + $sql .= ' WHERE ' . $whereclause; |
|
642 | + } |
|
643 | + |
|
644 | + if (false != $force) { |
|
645 | + $result = $this->db->queryF($sql); |
|
646 | + } else { |
|
647 | + $result = $this->db->query($sql); |
|
648 | + } |
|
649 | + |
|
650 | + // Clear cache |
|
651 | + $this->forceCacheClean(); |
|
652 | + |
|
653 | + if (!$result) { |
|
654 | + return false; |
|
655 | + } |
|
656 | + if ($obj->isNew() && !is_array($this->keyName)) { |
|
657 | + $obj->assignVar($this->keyName, $this->db->getInsertId()); |
|
658 | + } |
|
659 | + |
|
660 | + return true; |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Change a value for objects with a certain criteria |
|
665 | + * |
|
666 | + * @param string $fieldname Name of the field |
|
667 | + * @param string $fieldvalue Value to write |
|
668 | + * @param object $criteria {@link CriteriaElement} |
|
669 | + * |
|
670 | + * @param bool $force |
|
671 | + * @return bool |
|
672 | + */ |
|
673 | + public function updateAll($fieldname, $fieldvalue, $criteria = null, $force = false) |
|
674 | + { |
|
675 | + $set_clause = $fieldname . ' = '; |
|
676 | + if (is_numeric($fieldvalue)) { |
|
677 | + $set_clause .= $fieldvalue; |
|
678 | + } elseif (is_array($fieldvalue)) { |
|
679 | + $set_clause .= $this->db->quoteString(implode(',', $fieldvalue)); |
|
680 | + } else { |
|
681 | + $set_clause .= $this->db->quoteString($fieldvalue); |
|
682 | + } |
|
683 | + $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause; |
|
684 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
685 | + $sql .= ' ' . $criteria->renderWhere(); |
|
686 | + } |
|
687 | + if ($force) { |
|
688 | + $result = $this->db->queryF($sql); |
|
689 | + } else { |
|
690 | + $result = $this->db->query($sql); |
|
691 | + } |
|
692 | + |
|
693 | + // Clear cache |
|
694 | + $this->forceCacheClean(); |
|
695 | + |
|
696 | + if (!$result) { |
|
697 | + return false; |
|
698 | + } |
|
699 | + |
|
700 | + return true; |
|
701 | + } |
|
702 | + |
|
703 | + // check if target object is attempting to use duplicated info |
|
704 | + public function isDuplicated(&$obj, $field = '', $error = '') |
|
705 | + { |
|
706 | + if (empty($field)) { |
|
707 | + return false; |
|
708 | + } |
|
709 | + $criteria = new CriteriaCompo(); |
|
710 | + $criteria->add(new Criteria($field, $obj->getVar($field))); |
|
711 | + // one more condition if target object exisits in database |
|
712 | + if (!$obj->isNew()) { |
|
713 | + $criteria->add(new Criteria($this->_key, $obj->getVar($this->_key), '!=')); |
|
714 | + } |
|
715 | + if ($this->getCount($criteria)) { |
|
716 | + $obj->setErrors($error); |
|
717 | + |
|
718 | + return true; |
|
719 | + } |
|
720 | + |
|
721 | + return false; |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * delete all objects meeting the conditions |
|
726 | + * |
|
727 | + * @param object $criteria {@link CriteriaElement} with conditions to meet |
|
728 | + * @return bool |
|
729 | + */ |
|
730 | + public function deleteAll($criteria = null) |
|
731 | + { |
|
732 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
733 | + $sql = 'DELETE FROM ' . $this->table; |
|
734 | + $sql .= ' ' . $criteria->renderWhere(); |
|
735 | + if (!$this->db->queryF($sql)) { |
|
736 | + return false; |
|
737 | + } |
|
738 | + $rows = $this->db->getAffectedRows(); |
|
739 | + |
|
740 | + // Clear cache |
|
741 | + $this->forceCacheClean(); |
|
742 | + |
|
743 | + return $rows > 0 ? $rows : true; |
|
744 | + } |
|
745 | + |
|
746 | + return false; |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Compare two objects and returns, in an array, the differences |
|
751 | + * |
|
752 | + * @param XoopsObject $old_object The first object to compare |
|
753 | + * @param XoopsObject $new_object The new object |
|
754 | + * @return array differences key = fieldname, value = array('old_value', 'new_value') |
|
755 | + */ |
|
756 | + public function compareObjects($old_object, $new_object) |
|
757 | + { |
|
758 | + $ret = array(); |
|
759 | + $vars_name = array_keys($old_object->getVars()); |
|
760 | + foreach ($vars_name as $one_var) { |
|
761 | + if ($old_object->getVar($one_var, 'f') == $new_object->getVar($one_var, 'f')) { |
|
762 | + } else { |
|
763 | + $ret[$one_var] = array($old_object->getVar($one_var), $new_object->getVar($one_var)); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + return $ret; |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * Get distincted values of a field in the table |
|
772 | + * |
|
773 | + * @param string $field Field's name |
|
774 | + * @param object $criteria {@link CriteriaElement} conditions to be met |
|
775 | + * @param string $format Format in wich we want the datas |
|
776 | + * @return array containing the distinct values |
|
777 | + */ |
|
778 | + public function getDistincts($field, $criteria = null, $format = 's') |
|
779 | + { |
|
780 | + require_once __DIR__ . '/lite.php'; |
|
781 | + $limit = $start = 0; |
|
782 | + $sql = 'SELECT ' . $this->keyName . ', ' . $field . ' FROM ' . $this->table; |
|
783 | + if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { |
|
784 | + $sql .= ' ' . $criteria->renderWhere(); |
|
785 | + $limit = $criteria->getLimit(); |
|
786 | + $start = $criteria->getStart(); |
|
787 | + } |
|
788 | + $sql .= ' GROUP BY ' . $field . ' ORDER BY ' . $field; |
|
789 | + |
|
790 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
791 | + $id = $this->_getIdForCache($sql, $start, $limit); |
|
792 | + $cacheData = $Cache_Lite->get($id); |
|
793 | + if ($cacheData === false) { |
|
794 | + $result = $this->db->query($sql, $limit, $start); |
|
795 | + $ret = array(); |
|
796 | + $obj = new $this->className(); |
|
797 | + while ($myrow = $this->db->fetchArray($result)) { |
|
798 | + $obj->setVar($field, $myrow[$field]); |
|
799 | + $ret[$myrow[$this->keyName]] = $obj->getVar($field, $format); |
|
800 | + } |
|
801 | + $Cache_Lite->save($ret); |
|
802 | + |
|
803 | + return $ret; |
|
804 | + } else { |
|
805 | + return $cacheData; |
|
806 | + } |
|
807 | + } |
|
808 | + |
|
809 | + /** |
|
810 | + * A generic shortcut to getObjects |
|
811 | + * |
|
812 | + * @author Herve Thouzard - Instant Zero |
|
813 | + * |
|
814 | + * @param integer $start Starting position |
|
815 | + * @param integer $limit Maximum count of elements to return |
|
816 | + * @param string $sort Field to use for the sort |
|
817 | + * @param string $order Sort order |
|
818 | + * @param boolean $idAsKey Do we have to return an array whoses keys are the record's ID ? |
|
819 | + * @return array Array of current objects |
|
820 | + */ |
|
821 | + public function getItems($start = 0, $limit = 0, $sort = '', $order = 'ASC', $idAsKey = true) |
|
822 | + { |
|
823 | + if (trim($order) == '') { |
|
824 | + if (isset($this->identifierName) && trim($this->identifierName) != '') { |
|
825 | + $order = $this->identifierName; |
|
826 | + } else { |
|
827 | + $order = $this->keyName; |
|
828 | + } |
|
829 | + } |
|
830 | + $items = array(); |
|
831 | + $critere = new Criteria($this->keyName, 0, '<>'); |
|
832 | + $critere->setLimit($limit); |
|
833 | + $critere->setStart($start); |
|
834 | + $critere->setSort($sort); |
|
835 | + $critere->setOrder($order); |
|
836 | + $items =& $this->getObjects($critere, $idAsKey); |
|
837 | + |
|
838 | + return $items; |
|
839 | + } |
|
840 | + |
|
841 | + /** |
|
842 | + * Forces the cache to be cleaned |
|
843 | + */ |
|
844 | + public function forceCacheClean() |
|
845 | + { |
|
846 | + require_once __DIR__ . '/lite.php'; |
|
847 | + $Cache_Lite = new references_Cache_Lite($this->cacheOptions); |
|
848 | + $Cache_Lite->clean(); |
|
849 | + } |
|
850 | 850 | } |