XOOPS  2.6.0
main.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
22 include __DIR__ . '/header.php';
23 
24 // Get main instance
28 
29 // Get Action type
30 $op = $system->cleanVars($_REQUEST, 'op', 'default', 'string');
31 // Call Header
32 $xoops->header('admin:comments/comments.tpl');
33 
34 $admin_page = new \Xoops\Module\Admin();
35 $admin_page->renderNavigation('main.php');
36 
37 $limit_array = array(20, 50, 100);
39  array(COMMENTS_PENDING => _MD_COMMENTS_PENDING, COMMENTS_ACTIVE => _MD_COMMENTS_ACTIVE, COMMENTS_HIDDEN => _MD_COMMENTS_HIDDEN);
41  COMMENTS_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #008000;">' . _MD_COMMENTS_PENDING . '</span>',
42  COMMENTS_ACTIVE => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">' . _MD_COMMENTS_ACTIVE . '</span>',
43  COMMENTS_HIDDEN => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">' . _MD_COMMENTS_HIDDEN . '</span>'
44 );
45 $start = 0;
47 
48 $comments = array();
49 $status = (!isset($_REQUEST['status']) || !in_array(intval($_REQUEST['status']), array_keys($status_array))) ? 0
50  : intval($_REQUEST['status']);
51 
52 $module = !isset($_REQUEST['module']) ? 0 : intval($_REQUEST['module']);
53 
54 $modules_array = array();
55 $module_handler = $xoops->getHandlerModule();
56 $available_plugins = \Xoops\Module\Plugin::getPlugins('comments');
57 if (!empty($available_plugins)) {
58  $criteria = new Criteria('dirname', "('" . implode("','", array_keys($available_plugins)). "')", 'IN');
59  $module_array = $module_handler->getNameList($criteria);
60 }
61 
63 
64 $comment_handler = $helper->getHandlerComment();
65 
66 switch ($op) {
67 
68  case 'comments_jump':
69  $id = $system->cleanVars($_GET, 'item_id', 0, 'int');
70  if ($id > 0) {
71  $comment = $comment_handler->get($id);
72  if (is_object($comment)) {
73  /* @var $plugin CommentsPluginInterface */
74  $module = $xoops->getModuleById($comment->getVar('modid'));
75  $plugin = Xoops\Module\Plugin::getPlugin($module->getVar('dirname'), 'comments');
76  header('Location: ' . \XoopsBaseConfig::get('url') . '/modules/' . $module->getVar('dirname') . '/' . $plugin->pageName() . '?' . $plugin->itemName() . '=' . $comment->getVar('itemid') . '&id=' . $comment->getVar('id') . '&rootid=' . $comment->getVar('rootid') . '&mode=thread&' . str_replace('&amp;', '&', $comment->getVar('exparams')) . '#comment' . $comment->getVar('id'));
77  exit();
78  }
79  }
80  $helper->redirect('admin/main.php', 1, _AM_COMMENTS_NO_COMMENTS);
81  break;
82 
83  case 'comments_form_purge':
84  //Affichage du formulaire de purge
85  $form_purge = new Xoops\Form\ThemeForm(_AM_COMMENTS_FORM_PURGE, 'form', $helper->url('admin/main.php'), 'post', true);
86 
87  $form_purge->addElement(new Xoops\Form\DateSelect(_AM_COMMENTS_FORM_PURGE_DATE_AFTER, 'comments_after', '15'));
88  $form_purge->addElement(new Xoops\Form\DateSelect(_AM_COMMENTS_FORM_PURGE_DATE_BEFORE, 'comments_before', '15'));
89 
90  //user
91  $form_purge->addElement(new Xoops\Form\SelectUser(_AM_COMMENTS_FORM_PURGE_USER, "comments_userid", false, @$_REQUEST['comments_userid'], 5, true));
92 
93  //groups
94  $groupe_select = new Xoops\Form\SelectGroup(_AM_COMMENTS_FORM_PURGE_GROUPS, "comments_groupe", false, '', 5, true);
95  $groupe_select->setExtra("style=\"width:170px;\" ");
96  $form_purge->addElement($groupe_select);
97 
98  //Status
99  $status = new Xoops\Form\Select(_AM_COMMENTS_FORM_PURGE_STATUS, "comments_status", '');
101  $status->addOptionArray($options);
102  $form_purge->addElement($status, true);
103 
104  //Modules
105  $modules = new Xoops\Form\Select(_AM_COMMENTS_FORM_PURGE_MODULES, "comments_modules", '');
107  $modules->addOptionArray($options);
108  $form_purge->addElement($modules, true);
109  $form_purge->addElement(new Xoops\Form\Hidden("op", "comments_purge"));
110  $form_purge->addElement(new Xoops\Form\Button("", "submit", XoopsLocale::A_SUBMIT, "submit"));
111  $xoops->tpl()->assign('form', $form_purge->render());
112  break;
113 
114  case 'comments_purge':
115  $criteria = new CriteriaCompo();
116  $verif = false;
117  if (isset($_POST['comments_after']) && isset($_POST['comments_before'])) {
118  if ($_POST['comments_after'] != $_POST['comments_before']) {
119  $after = $system->cleanVars($_POST, 'comments_after', time(), 'date');
120  $before = $system->cleanVars($_POST, 'comments_before', time(), 'date');
121  if ($after) {
122  $criteria->add(new Criteria('created', $after, ">"));
123  }
124  if ($before) {
125  $criteria->add(new Criteria('created', $before, "<"));
126  }
127  $verif = true;
128  }
129  }
130  $modid = $system->cleanVars($_POST, 'comments_modules', 0, 'int');
131  if ($modid > 0) {
132  $criteria->add(new Criteria('modid', $modid));
133  $verif = true;
134  }
135  $comments_status = $system->cleanVars($_POST, 'comments_status', 0, 'int');
136  if ($comments_status > 0) {
137  $criteria->add(new Criteria('status', $_POST['comments_status']));
138  $verif = true;
139  }
140  $comments_userid = $system->cleanVars($_POST, 'comments_userid', '', 'string');
141  if ($comments_userid != '') {
142  foreach ($_REQUEST['comments_userid'] as $del) {
143  $criteria->add(new Criteria('uid', $del), 'OR');
144  }
145  $verif = true;
146  }
147  $comments_groupe = $system->cleanVars($_POST, 'comments_groupe', '', 'string');
148  if ($comments_groupe != '') {
149  foreach ($_POST['comments_groupe'] as $del => $u_name) {
150  $member_handler = $xoops->getHandlerMember();
151  $members = $member_handler->getUsersByGroup($u_name, true);
152  $mcount = count($members);
153  if ($mcount > 4000) {
154  $helper->redirect('admin/main.php', 2, _AM_COMMENTS_DELETE_LIMIT);
155  }
156  for ($i = 0; $i < $mcount; ++$i) {
157  $criteria->add(new Criteria('uid', $members[$i]->getVar('uid')), 'OR');
158  }
159  }
160  $verif = true;
161  }
162  if (isset($_POST['commentslist_id'])) {
163  $commentslist_count = (!empty($_POST['commentslist_id']) && is_array($_POST['commentslist_id']))
164  ? count($_POST['commentslist_id']) : 0;
165  if ($commentslist_count > 0) {
166  for ($i = 0; $i < $commentslist_count; ++$i) {
167  $criteria->add(new Criteria('id', $_REQUEST['commentslist_id'][$i]), 'OR');
168  }
169  }
170  $verif = true;
171  }
172  if ($verif == true) {
173  if ($comment_handler->deleteAll($criteria)) {
174  $helper->redirect("admin/main.php", 3, XoopsLocale::S_DATABASE_UPDATED);
175  }
176  } else {
177  $helper->redirect("admin/main.php", 3, XoopsLocale::S_DATABASE_UPDATED);
178  }
179  break;
180 
181  default:
183  $admin_page->renderTips();
184  // Display comments
186  $comments_Handler = $helper->getHandlerComment();
187  $comments_module = '';
188  $comments_status = '';
189 
190  $criteria = new CriteriaCompo();
191  $comments_module = $system->cleanVars($_REQUEST, 'comments_module', 0, 'int');
192  if ($comments_module > 0) {
193  $criteria->add(new Criteria('modid', $comments_module));
194  $comments_module = $_REQUEST['comments_module'];
195  }
196  $comments_status = $system->cleanVars($_REQUEST, 'comments_status', 0, 'int');
197  if ($comments_status > 0) {
198  $criteria->add(new Criteria('status', $comments_status));
199  $comments_status = $_REQUEST['comments_status'];
200  }
201 
202  $criteria->setSort('created');
203  $criteria->setOrder('DESC');
204 
205  $comments_count = $comments_Handler->getCount($criteria);
206 
207  $xoops->tpl()->assign('comments_count', $comments_count);
208 
209  $comments_arr = array();
210  $comments_start = 0;
211  $comments_limit = 0;
212  if ($comments_count > 0) {
213  $comments_start = $system->cleanVars($_REQUEST, 'comments_start', 0, 'int');
214  $comments_limit = $system->cleanVars($_REQUEST, 'comments_limit', 0, 'int');
215  if (!in_array($comments_limit, $limit_array)) {
216  $comments_limit = $helper->getConfig('com_pager');
217  }
218  $criteria->setLimit($comments_limit);
219  $criteria->setStart($comments_start);
220 
221  $comments_arr = $comments_Handler->getObjects($criteria, true);
222  }
223 
224  $url = $helper->url('admin/main.php');
225  $form = '<form class="form-inline" action="' . $url . '" method="post">
226  <select class="span2" name="comments_module">';
227 
228  foreach ($module_array as $k => $v) {
229  $sel = '';
230  if ($k == $module) {
231  $sel = ' selected="selected"';
232  }
233  $form .= '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
234  }
235  $form .= '</select>&nbsp;<select class="span2" name="comments_status">';
236 
237  foreach ($status_array as $k => $v) {
238  $sel = '';
239  if (isset($status) && $k == $status) {
240  $sel = ' selected="selected"';
241  }
242  $form .= '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
243  }
244 
245 
246  $form .= '</select>&nbsp;<select class="span2" name="comments_limit">';
247  foreach ($limit_array as $k) {
248  $sel = '';
249  if (isset($limit) && $k == $limit) {
250  $sel = ' selected="selected"';
251  }
252  $form .= '<option value="' . $k . '"' . $sel . '>' . $k . '</option>';
253  }
254  $form .= '</select>&nbsp;<input class ="btn" type="submit" value="' . XoopsLocale::A_GO . '" name="selsubmit" /></form>';
255 
256  $xoops->tpl()->assign('form_sort', $form);
257  $xoops->tpl()->assign('php_selft', $_SERVER['PHP_SELF'] . '?op=comments_purge');
258 
259  if ($comments_count > 0) {
260  foreach (array_keys($comments_arr) as $i) {
261  $id = $comments_arr[$i]->getVar('id');
262  $comments_poster_uname = $xoops->getConfig('anonymous');
263  if ($comments_arr[$i]->getVar('uid') > 0) {
264  $poster = $member_handler->getUser($comments_arr[$i]->getVar('uid'));
265  if (is_object($poster)) {
266  $comments_poster_uname = '<a href="' . \XoopsBaseConfig::get('url') . '/userinfo.php?uid=' . $comments_arr[$i]->getVar('uid') . '">' . $poster->getVar('uname') . '</a>';
267  }
268  }
269 
270  $comments_icon = ($comments_arr[$i]->getVar('icon') == '') ? '/images/icons/no_posticon.gif'
271  : '/images/subject/' . htmlspecialchars($comments_arr[$i]->getVar('icon'), ENT_QUOTES);
272  $comments_icon = '<img src="' . \XoopsBaseConfig::get('url') . $comments_icon . '" alt="" />';
273 
274  $comments['comments_id'] = $id;
275  $comments['comments_poster'] = $comments_poster_uname;
276  $comments['comments_icon'] = $comments_icon;
277  $comments['comments_title'] = '<a href="main.php?op=comments_jump&amp;item_id=' . $comments_arr[$i]->getVar("id") . '">' . $comments_arr[$i]->getVar("title") . '</a>';
278  $comments['comments_ip'] = $comments_arr[$i]->getVar('ip');
279  $comments['comments_date'] = XoopsLocale::formatTimeStamp($comments_arr[$i]->getVar('created'));
280  $comments['comments_text'] = $myts->undoHtmlSpecialChars($comments_arr[$i]->getVar('text'));
281  $comments['comments_status'] = @$status_array2[$comments_arr[$i]->getVar('status')];
282  $comments['comments_date_created'] = XoopsLocale::formatTimestamp($comments_arr[$i]->getVar('created'), 'm');
283  $comments['comments_modid'] = @$module_array[$comments_arr[$i]->getVar('modid')];
284  //$comments['comments_view_edit_delete'] = '<img class="cursorpointer" onclick="display_dialog('.$id.', true, true, \'slide\', \'slide\', 300, 500);" src="images/icons/view.png" alt="'._AM_COMMENTS_VIEW.'" title="'._AM_COMMENTS_VIEW.'" /><a href="admin/comments/comment_edit.php?id='.$id.'"><img src="./images/icons/edit.png" border="0" alt="'._EDIT.'" title="'._EDIT.'"></a><a href="admin/comments/comment_delete.php?id='.$id.'"><img src="./images/icons/delete.png" border="0" alt="'._DELETE.'" title="'._DELETE.'"></a>';
285 
286  $xoops->tpl()->appendByRef('comments', $comments);
287  $xoops->tpl()->appendByRef('comments_popup', $comments);
288  unset($comments);
289  }
290 
291  if ($comments_count > $comments_limit) {
292  $nav = new XoopsPageNav($comments_count, $comments_limit, $comments_start, 'comments_start', 'comments_module=' . $comments_module . '&amp;comments_status=' . $comments_status);
293  $xoops->tpl()->assign('nav', $nav->renderNav());
294  }
295  }
296  break;
297 }
298 // Call Footer
299 $xoops->footer();
if(!empty($available_plugins)) $module_array[0]
Definition: main.php:62
const _AM_COMMENTS_FORM_ALL_MODS
Definition: admin.php:36
const A_SUBMIT
Definition: en_US.php:128
static formatTimestamp($time, $format= 'l', $timeoffset=null)
Definition: Abstract.php:289
const _AM_COMMENTS_DELETE_LIMIT
Definition: admin.php:60
const A_GO
Definition: en_US.php:98
$member_handler
Definition: main.php:41
$i
Definition: dialog.php:68
$system
Definition: main.php:26
static getInstance()
Definition: system.php:46
static getInstance()
Definition: Xoops.php:160
if(in_array($op, array('install', 'update', 'uninstall'))) $myts
Definition: main.php:46
addElement(Element $formElement, $required=false)
Definition: Form.php:206
static getInstance()
Definition: helper.php:46
const _AM_COMMENTS_FORM_PURGE_STATUS
Definition: admin.php:44
$options['editor']
const _MD_COMMENTS_ACTIVE
Definition: main.php:28
$sel
Definition: main.php:48
$_SERVER['REQUEST_URI']
$admin_page
Definition: main.php:34
static getPlugin($dirname, $pluginName= 'system', $force=false)
Definition: Plugin.php:30
const _AM_COMMENTS_FORM_PURGE_DATE_AFTER
Definition: admin.php:40
$helper
Definition: main.php:27
$comment_handler
Definition: main.php:64
const _MD_COMMENTS_PENDING
Definition: main.php:26
$modid
Definition: groupperm.php:27
$form
Definition: xoops_code.php:21
$status
Definition: main.php:49
exit
Definition: browse.php:104
const _AM_COMMENTS_FORM_ALL_STATUS
Definition: admin.php:37
$limit_array
Definition: main.php:37
$id
Definition: admin_menu.php:36
const _AM_COMMENTS_NO_COMMENTS
Definition: admin.php:56
const _MD_COMMENTS_HIDDEN
Definition: main.php:27
$status_array2
Definition: main.php:40
$op
Definition: main.php:30
static get($name)
$module
Definition: main.php:52
$start
Definition: main.php:45
$comments
Definition: main.php:48
$status_array
Definition: main.php:38
$limit
Definition: findusers.php:202
$available_plugins
Definition: main.php:56
$modules
Definition: userinfo.php:185
const _AM_COMMENTS_FORM_PURGE_GROUPS
Definition: admin.php:42
$url
Definition: register.php:72
$modules_array
Definition: main.php:54
$criteria
$module_handler
Definition: main.php:55
$xoops
Definition: main.php:25
const _AM_COMMENTS_FORM_PURGE
Definition: admin.php:39
const S_DATABASE_UPDATED
Definition: en_US.php:1024
const _AM_COMMENTS_FORM_PURGE_MODULES
Definition: admin.php:45
const _AM_COMMENTS_NAV_TIPS
Definition: admin.php:28
const _AM_COMMENTS_FORM_PURGE_USER
Definition: admin.php:43
const _AM_COMMENTS_FORM_PURGE_DATE_BEFORE
Definition: admin.php:41