XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
main.php
Go to the documentation of this file.
1 <?php
2 // $Id: main.php 10882 2013-01-23 20:57:13Z beckmi $
3 // ------------------------------------------------------------------------ //
4 // XOOPS - PHP Content Management System //
5 // Copyright (c) 2000 XOOPS.org //
6 // <http://www.xoops.org/> //
7 // ------------------------------------------------------------------------ //
8 // This program is free software; you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation; either version 2 of the License, or //
11 // (at your option) any later version. //
12 // //
13 // You may not change or alter any portion of this comment or credits //
14 // of supporting developers from this source code or any supporting //
15 // source code which is considered copyrighted (c) material of the //
16 // original comment or credit authors. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details. //
22 // //
23 // You should have received a copy of the GNU General Public License //
24 // along with this program; if not, write to the Free Software //
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
26 // ------------------------------------------------------------------------ //
27 // Author: Kazumi Ono (AKA onokazu) //
28 // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29 // Project: The XOOPS Project //
30 // ------------------------------------------------------------------------- //
31 
32 
33 // Check users rights
34 if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->getVar('mid')) ) exit( _NOPERM );
35 
36 // Check is active
37 if ( !xoops_getModuleOption('active_comments', 'system') ) redirect_header( 'admin.php', 2, _AM_SYSTEM_NOTACTIVE );
38 
39 // Get Action type
40 $op = system_CleanVars ( $_REQUEST, 'op', 'default', 'string' );
41 // Define main template
42 $xoopsOption['template_main'] = 'system_comments.html';
44 // Define Stylesheet
45 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/admin.css');
46 $xoTheme->addStylesheet( XOOPS_URL . '/modules/system/css/ui/' . xoops_getModuleOption('jquery_theme', 'system') . '/ui.all.css');
47 // Define scripts
48 $xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
49 $xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.ui.js');
50 //$xoTheme->addScript('browse.php?Frameworks/jquery/plugins/jquery.tablesorter.js');
51 $xoTheme->addScript('modules/system/js/admin.js');
52 // Define Breadcrumb and tips
53 $xoBreadCrumb->addLink( _AM_SYSTEM_COMMENTS_NAV_MANAGER, system_adminVersion('comments', 'adminpath') );
54 
55 include_once $GLOBALS['xoops']->path('/include/comment_constants.php');
56 xoops_loadLanguage('comment');
57 
58 $limit_array = array(20, 50, 100);
60 $status_array2 = array(XOOPS_COMMENT_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #008000;">'._CM_PENDING.'</span>', XOOPS_COMMENT_ACTIVE => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">'._CM_ACTIVE.'</span>', XOOPS_COMMENT_HIDDEN => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">'._CM_HIDDEN.'</span>');
61 $start = 0;
63 
64 $comments = array();
65 $status = (!isset($_REQUEST['status']) || !in_array(intval($_REQUEST['status']), array_keys($status_array))) ? 0 : intval($_REQUEST['status']);
66 
67 $module = !isset($_REQUEST['module']) ? 0 : intval($_REQUEST['module']);
69 $module_array = $modules_Handler->getList(new Criteria('hascomments', 1));
71 
73 
74 switch ($op) {
75 
76  case 'comments_jump':
77  $com_id = system_CleanVars ( $_GET, 'com_id', 0, 'int' );
78  if ($com_id > 0) {
80  if (is_object($comment)) {
81  $module_handler =& xoops_gethandler('module');
82  $module =& $module_handler->get($comment->getVar('com_modid'));
83  $comment_config = $module->getInfo('comments');
84  header('Location: '.XOOPS_URL.'/modules/'.$module->getVar('dirname').'/'.$comment_config['pageName'].'?'.$comment_config['itemName'].'='.$comment->getVar('com_itemid').'&com_id='.$comment->getVar('com_id').'&com_rootid='.$comment->getVar('com_rootid').'&com_mode=thread&'.str_replace('&amp;', '&', $comment->getVar('com_exparams')).'#comment'.$comment->getVar('com_id'));
85  exit();
86  }
87  }
88  redirect_header('admin.php?fct=comments', 1, _AM_SYSTEM_COMMENTS_NO_COMMENTS);
89  break;
90 
91  case 'comments_form_purge':
92  //Affichage des coms
94  $xoBreadCrumb->addHelp( system_adminVersion('comments', 'help') . '#purge' );
96  $xoBreadCrumb->render();
97 
98  //Affichage du formulaire de purge
99  $form_purge = new XoopsThemeForm(_AM_SYSTEM_COMMENTS_FORM_PURGE, 'form', 'admin.php?fct=comments', 'post', true);
100 
101  $form_purge->addElement(new XoopsFormTextDateSelect(_AM_SYSTEM_COMMENTS_FORM_PURGE_DATE_AFTER, 'comments_after', '15'));
102  $form_purge->addElement(new XoopsFormTextDateSelect(_AM_SYSTEM_COMMENTS_FORM_PURGE_DATE_BEFORE, 'comments_before', '15'));
103 
104  //user
105  $form_purge->addElement(new XoopsFormSelectUser(_AM_SYSTEM_COMMENTS_FORM_PURGE_USER, "comments_userid", false, @$_REQUEST['comments_userid'], 5, true));
106 
107  //groups
108  $groupe_select = new XoopsFormSelectGroup(_AM_SYSTEM_COMMENTS_FORM_PURGE_GROUPS, "comments_groupe", false, '', 5, true);
109  $groupe_select->setExtra("style=\"width:170px;\" ");
110  $form_purge->addElement($groupe_select);
111 
112  //Status
113  $status = new XoopsFormSelect(_AM_SYSTEM_COMMENTS_FORM_PURGE_STATUS, "comments_status", '');
115  $status->addOptionArray($options);
116  $form_purge->addElement($status, true);
117 
118  //Modules
119  $modules = new XoopsFormSelect(_AM_SYSTEM_COMMENTS_FORM_PURGE_MODULES, "comments_modules", '');
121  $modules->addOptionArray($options);
122  $form_purge->addElement($modules, true);
123  $form_purge->addElement(new XoopsFormHidden("op", "comments_purge"));
124  $form_purge->addElement(new XoopsFormButton("", "submit", _SUBMIT, "submit"));
125  $xoopsTpl->assign('form', $form_purge->render());
126  break;
127 
128  case 'comments_purge':
129  $criteria = new CriteriaCompo();
130  $verif = false;
131  if (isset($_POST['comments_after']) && isset($_POST['comments_before'])) {
132  if ($_POST['comments_after'] != $_POST['comments_before']) {
133  $com_after = system_CleanVars($_POST, 'comments_after', time(), 'date');
134  $com_before = system_CleanVars($_POST, 'comments_before', time(), 'date');
135  if ($com_after) {
136  $criteria->add(new Criteria('com_created', $com_after, ">"));
137  }
138  if ($com_before) {
139  $criteria->add(new Criteria('com_created', $com_before, "<"));
140  }
141  $verif = true;
142  }
143  }
144  $com_modid = system_CleanVars($_POST, 'comments_modules', 0, 'int');
145  if ( $com_modid > 0 ) {
146  $criteria->add(new Criteria('com_modid', $com_modid));
147  $verif = true;
148  }
149  $comments_status = system_CleanVars($_POST, 'comments_status', 0, 'int');
150  if ( $comments_status > 0 ) {
151  $criteria->add(new Criteria('com_status', $_POST['comments_status']));
152  $verif = true;
153  }
154  $comments_userid = system_CleanVars($_POST, 'comments_userid', '', 'string');
155  if ( $comments_userid != '' ) {
156  foreach ($_REQUEST['comments_userid'] as $del)
157  {
158  $criteria->add(new Criteria('com_uid', $del), 'OR');
159  }
160  $verif = true;
161  }
162  $comments_groupe = system_CleanVars($_POST, 'comments_groupe', '', 'string');
163  if ( $comments_groupe != '' ) {
164  foreach ($_POST['comments_groupe'] as $del => $u_name)
165  {
166  $member_handler =& xoops_gethandler('member');
167  $members =& $member_handler->getUsersByGroup($u_name, true);
168  $mcount = count($members);
169  if ($mcount > 4000) {
170  redirect_header('admin.php?fct=comments', 2, _MP_DELETECOUNT);
171  }
172  for ($i = 0; $i < $mcount; $i++)
173  {
174  $criteria->add(new Criteria('com_uid', $members[$i]->getVar('uid')), 'OR');
175  }
176  }
177  $verif = true;
178  }
179  if(isset($_POST['commentslist_id'])) {
180  $commentslist_count = (!empty($_POST['commentslist_id']) && is_array($_POST['commentslist_id'])) ? count($_POST['commentslist_id']) : 0;
181  if ($commentslist_count > 0) {
182  for ( $i=0; $i < $commentslist_count; $i++ )
183  {
184  $criteria->add(new Criteria('com_id', $_REQUEST['commentslist_id'][$i]), 'OR');
185  }
186  }
187  $verif = true;
188  }
189  if ( $verif == true ){
190  if($comment_handler->deleteAll($criteria))
191  {
192  redirect_header("admin.php?fct=comments", 3, _AM_SYSTEM_DBUPDATED);
193  }
194  } else {
195  redirect_header("admin.php?fct=comments", 3, _AM_SYSTEM_DBUPDATED);
196  }
197  break;
198 
199  default:
200  // Display comments
202  $xoBreadCrumb->addHelp( system_adminVersion('comments', 'help') );
204  $xoBreadCrumb->render();
205 
207  $comments_Handler =& xoops_gethandler('comment');
208  $comments_module = '';
209  $comments_status = '';
210 
211  $criteria = new CriteriaCompo();
212  $comments_module = system_CleanVars($_REQUEST, 'comments_module', 0, 'int');
213  if ( $comments_module > 0 ) {
214  $criteria->add(new Criteria('com_modid', $comments_module));
215  $comments_module = $_REQUEST['comments_module'];
216  }
217  $comments_status = system_CleanVars($_REQUEST, 'comments_status', 0, 'int');
218  if ( $comments_status > 0 ) {
219  $criteria->add(new Criteria('com_status', $comments_status));
220  $comments_status = $_REQUEST['comments_status'];
221  }
222 
223  $criteria->setSort('com_created');
224  $criteria->setOrder('DESC');
225 
226  $comments_count = $comments_Handler->getCount($criteria);
227 
228  $xoopsTpl->assign( 'comments_count', $comments_count );
229 
230  if ($comments_count > 0) {
231  $comments_start = system_CleanVars($_REQUEST, 'comments_start', 0, 'int');
232  $comments_limit = system_CleanVars($_REQUEST, 'comments_limit', 0, 'int');
233  if (!in_array($comments_limit, $limit_array)) {
234  $comments_limit = xoops_getModuleOption('comments_pager', 'system');
235  }
236  $criteria->setLimit($comments_limit);
237  $criteria->setStart($comments_start);
238 
239  $comments_arr = $comments_Handler->getObjects($criteria, true);
240  }
241 
242  $form = '<form action="admin.php?fct=comments" method="post">
243  <select name="comments_module">';
244 
245  foreach ($module_array as $k => $v)
246  {
247  $sel = '';
248  if ($k == $module)
249  {
250  $sel = ' selected="selected"';
251  }
252  $form .= '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
253  }
254  $form .= '</select>&nbsp;<select name="comments_status">';
255 
256  foreach ($status_array as $k => $v) {
257  $sel = '';
258  if (isset($status) && $k == $status) {
259  $sel = ' selected="selected"';
260  }
261  $form .= '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
262  }
263 
264 
265  $form .= '</select>&nbsp;<select name="comments_limit">';
266  foreach ($limit_array as $k) {
267  $sel = '';
268  if (isset($limit) && $k == $limit) {
269  $sel = ' selected="selected"';
270  }
271  $form .= '<option value="'.$k.'"'.$sel.'>'.$k.'</option>';
272  }
273  $form .= '</select>&nbsp;<input type="hidden" name="fct" value="comments" /><input type="submit" value="'._GO.'" name="selsubmit" /></form>';
274 
275  $xoopsTpl->assign('form_sort', $form);
276  $xoopsTpl->assign('php_selft', $_SERVER['PHP_SELF'].'?fct=comments&op=comments_purge');
277 
278  if ($comments_count > 0) {
279  foreach (array_keys($comments_arr) as $i)
280  {
281  $com_id = $comments_arr[$i]->getVar('com_id');
282  $comments_poster_uname = $xoopsConfig['anonymous'];
283  // Start edit by voltan
284  if ($comments_arr[$i]->getVar('com_uid') > 0) {
285  $poster =& $member_handler->getUser($comments_arr[$i]->getVar('com_uid'));
286  if (is_object($poster)) {
287  $comments_poster_uname = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$comments_arr[$i]->getVar('com_uid').'">'.$poster->getVar('uname').'</a>';
288  }
289  } elseif($comments_arr[$i]->getVar('com_uid') == 0 && $comments_arr[$i]->getVar('com_user') != '') {
290  if($comments_arr[$i]->getVar('com_url') != '') {
291  $comments_poster_uname = '<div class="pad2 marg2"><a href="' . $comments_arr[$i]->getVar('com_url') . '">' . $comments_arr[$i]->getVar('com_user') . '</a> ( <a href="mailto:' . $comments_arr[$i]->getVar('com_email') . '">' . $comments_arr[$i]->getVar('com_email') . '</a> ) ' . '</div>';
292  } else {
293  $comments_poster_uname = '<div class="pad2 marg2">' . $comments_arr[$i]->getVar('com_user') . ' ( <a href="mailto:' . $comments_arr[$i]->getVar('com_email') . '">' . $comments_arr[$i]->getVar('com_email') . '</a> ) ' . '</div>';
294  }
295  }
296  // End edit by voltan
297  $comments_icon = ($comments_arr[$i]->getVar('com_icon') == '') ? '/images/icons/no_posticon.gif' : '/images/subject/' . htmlspecialchars( $comments_arr[$i]->getVar('com_icon'), ENT_QUOTES );
298  $comments_icon = '<img src="' . XOOPS_URL . $comments_icon . '" alt="" />';
299 
300  $comments['comments_id'] = $com_id;
301  $comments['comments_poster'] = $comments_poster_uname;
302  $comments['comments_icon'] = $comments_icon;
303  $comments['comments_title'] = '<a href="admin.php?fct=comments&amp;op=comments_jump&amp;com_id='.$comments_arr[$i]->getVar("com_id").'">'.$comments_arr[$i]->getVar("com_title");
304  $comments['comments_ip'] = $comments_arr[$i]->getVar('com_ip');
305  $comments['comments_date'] = formatTimeStamp($comments_arr[$i]->getVar('com_created'));
306  $comments['comments_text'] = $myts->undoHtmlSpecialChars($comments_arr[$i]->getVar('com_text'));
307  $comments['comments_status'] = @$status_array2[$comments_arr[$i]->getVar('com_status')];
308  $comments['comments_date_created'] = formatTimestamp($comments_arr[$i]->getVar('com_created'), 'm');
309  $comments['comments_modid'] = @$module_array[$comments_arr[$i]->getVar('com_modid')];
310  //$comments['comments_view_edit_delete'] = '<img class="cursorpointer" onclick="display_dialog('.$com_id.', true, true, \'slide\', \'slide\', 300, 500);" src="images/icons/view.png" alt="'._AM_SYSTEM_COMMENTS_VIEW.'" title="'._AM_SYSTEM_COMMENTS_VIEW.'" /><a href="admin/comments/comment_edit.php?com_id='.$com_id.'"><img src="./images/icons/edit.png" border="0" alt="'._EDIT.'" title="'._EDIT.'"></a><a href="admin/comments/comment_delete.php?com_id='.$com_id.'"><img src="./images/icons/delete.png" border="0" alt="'._DELETE.'" title="'._DELETE.'"></a>';
311 
312  $xoopsTpl->append_by_ref('comments', $comments);
313  $xoopsTpl->append_by_ref('comments_popup', $comments);
314  unset( $comments );
315  }
316 
317  if ( $comments_count > $comments_limit ) {
318  include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
319  $nav = new XoopsPageNav($comments_count, $comments_limit, $comments_start, 'comments_start', 'fct=comments&amp;comments_module='.$comments_module.'&amp;comments_status='.$comments_status);
320  $xoopsTpl->assign( 'nav', $nav->renderNav() );
321  }
322  }
323  break;
324 }
325 // Call Footer
327 
328 ?>