PageRenderTime 48ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/core/admin/comments.php

https://bitbucket.org/bontiv/insomnia
PHP | 233 lines | 183 code | 22 blank | 28 comment | 26 complexity | 74a4c2f63a537619943fbd5607aaf74a MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, LGPL-2.1, GPL-3.0, BSD-3-Clause, GPL-2.0
  1. <?php
  2. /**
  3. * Listing des commentaires en attente de validation
  4. *
  5. * @package PLX
  6. * @author Stephane F
  7. **/
  8. include(dirname(__FILE__).'/prepend.php');
  9. # Control du token du formulaire
  10. plxToken::validateFormToken($_POST);
  11. # Hook Plugins
  12. eval($plxAdmin->plxPlugins->callHook('AdminCommentsPrepend'));
  13. # Control de l'accès à la page en fonction du profil de l'utilisateur connecté
  14. $plxAdmin->checkProfil(PROFIL_ADMIN, PROFIL_MANAGER, PROFIL_MODERATOR);
  15. # validation de l'id de l'article si passé en parametre
  16. if(isset($_GET['a']) AND !preg_match('/^_?[0-9]{4}$/',$_GET['a'])) {
  17. plxMsg::Error(L_ERR_UNKNOWN_ARTICLE); # Article inexistant
  18. header('Location: index.php');
  19. exit;
  20. }
  21. # Suppression des commentaires selectionnes
  22. if(isset($_POST['selection']) AND ($_POST['selection'][0] == 'delete' OR $_POST['selection'][1] == 'delete') AND isset($_POST['idCom'])) {
  23. foreach ($_POST['idCom'] as $k => $v) $plxAdmin->delCommentaire($v);
  24. header('Location: comments.php'.(!empty($_GET['a'])?'?a='.$_GET['a']:''));
  25. exit;
  26. }
  27. # Validation des commentaires selectionnes
  28. elseif(isset($_POST['selection']) AND ($_POST['selection'][0] == 'online' OR $_POST['selection'][1] == 'online') AND isset($_POST['idCom'])) {
  29. foreach ($_POST['idCom'] as $k => $v) $plxAdmin->modCommentaire($v, 'online');
  30. header('Location: comments.php'.(!empty($_GET['a'])?'?a='.$_GET['a']:''));
  31. exit;
  32. }
  33. # Mise hors-ligne des commentaires selectionnes
  34. elseif (isset($_POST['selection']) AND ($_POST['selection'][0] == 'offline' OR $_POST['selection'][1] == 'offline') AND isset($_POST['idCom'])) {
  35. foreach ($_POST['idCom'] as $k => $v) $plxAdmin->modCommentaire($v, 'offline');
  36. header('Location: comments.php'.(!empty($_GET['a'])?'?a='.$_GET['a']:''));
  37. exit;
  38. }
  39. # Récuperation des infos sur l'article attaché au commentaire si passé en paramètre
  40. if(!empty($_GET['a'])) {
  41. # Infos sur notre article
  42. if(!$globArt = $plxAdmin->plxGlob_arts->query('/^'.$_GET['a'].'.(.*).xml$/','','sort',0,1)) {
  43. plxMsg::Error(L_ERR_UNKNOWN_ARTICLE); # Article inexistant
  44. header('Location: index.php');
  45. exit;
  46. }
  47. # Infos sur l'article
  48. $aArt = $plxAdmin->parseArticle(PLX_ROOT.$plxAdmin->aConf['racine_articles'].$globArt['0']);
  49. $portee = L_COMMENTS_ARTICLE_SCOPE.' &laquo;'.$aArt['title'].'&raquo;';
  50. } else { # Commentaires globaux
  51. $portee = '';
  52. }
  53. # On inclut le header
  54. include(dirname(__FILE__).'/top.php');
  55. # Récuperation du type de commentaire à afficher
  56. $_GET['sel'] = !empty($_GET['sel']) ? $_GET['sel'] : 'all';
  57. if(in_array($_GET['sel'], array('online', 'offline', 'all')))
  58. $comSel = plxUtils::nullbyteRemove($_GET['sel']);
  59. else
  60. $comSel = ((isset($_SESSION['selCom']) AND !empty($_SESSION['selCom'])) ? $_SESSION['selCom'] : 'all');
  61. if(!empty($_GET['a'])) {
  62. $comSelMotif = '/^[[:punct:]]?'.str_replace('_','',$_GET['a']).'.(.*).xml$/';
  63. $_SESSION['selCom'] = 'all';
  64. $nbComPagination=$plxAdmin->nbComments($comSelMotif);
  65. echo '<h2>'.L_COMMENTS_ALL_LIST.'</h2>';
  66. }
  67. elseif($comSel=='online') {
  68. $comSelMotif = '/^[0-9]{4}.(.*).xml$/';
  69. $_SESSION['selCom'] = 'online';
  70. $nbComPagination=$plxAdmin->nbComments('online');
  71. echo '<h2>'.L_COMMENTS_ONLINE_LIST.'</h2>';
  72. }
  73. elseif($comSel=='offline') {
  74. $comSelMotif = '/^_[0-9]{4}.(.*).xml$/';
  75. $_SESSION['selCom'] = 'offline';
  76. $nbComPagination=$plxAdmin->nbComments('offline');
  77. echo '<h2>'.L_COMMENTS_OFFLINE_LIST.'</h2>';
  78. }
  79. elseif($comSel=='all') { // all
  80. $comSelMotif = '/^[[:punct:]]?[0-9]{4}.(.*).xml$/';
  81. $_SESSION['selCom'] = 'all';
  82. $nbComPagination=$plxAdmin->nbComments('all');
  83. echo '<h2>'.L_COMMENTS_ALL_LIST.'</h2>';
  84. }
  85. if($portee!='') {
  86. echo '<h3>'.$portee.'</h3>';
  87. }
  88. $breadcrumbs = array();
  89. $breadcrumbs[] = '<a '.($_SESSION['selCom']=='all'?'class="selected" ':'').'href="comments.php?sel=all&amp;page=1">'.L_ALL.'</a>&nbsp;('.$plxAdmin->nbComments('all').')';
  90. $breadcrumbs[] = '<a '.($_SESSION['selCom']=='online'?'class="selected" ':'').'href="comments.php?sel=online&amp;page=1">'.L_COMMENT_ONLINE.'</a>&nbsp;('.$plxAdmin->nbComments('online').')';
  91. $breadcrumbs[] = '<a '.($_SESSION['selCom']=='offline'?'class="selected" ':'').'href="comments.php?sel=offline&amp;page=1">'.L_COMMENT_OFFLINE.'</a>&nbsp;('.$plxAdmin->nbComments('offline').')';
  92. if(!empty($_GET['a'])) {
  93. $breadcrumbs[] = '<a href="comment_new.php?a='.$_GET['a'].'" title="'.L_COMMENT_NEW_COMMENT_TITLE.'">'.L_COMMENT_NEW_COMMENT.'</a>';
  94. }
  95. ob_start();
  96. if($comSel=='online')
  97. plxUtils::printSelect('selection[]', array(''=> L_FOR_SELECTION, 'offline' => L_COMMENT_SET_OFFLINE, '-'=>'-----', 'delete' => L_COMMENT_DELETE), '', false,'',false);
  98. elseif($comSel=='offline')
  99. plxUtils::printSelect('selection[]', array(''=> L_FOR_SELECTION, 'online' => L_COMMENT_SET_ONLINE, '-'=>'-----', 'delete' => L_COMMENT_DELETE), '', false,'',false);
  100. elseif($comSel=='all')
  101. plxUtils::printSelect('selection[]', array(''=> L_FOR_SELECTION, 'online' => L_COMMENT_SET_ONLINE, 'offline' => L_COMMENT_SET_OFFLINE, '-'=>'-----','delete' => L_COMMENT_DELETE), '', false,'',false);
  102. $selector=ob_get_clean();
  103. ?>
  104. <?php eval($plxAdmin->plxPlugins->callHook('AdminCommentsTop')) # Hook Plugins ?>
  105. <form action="comments.php<?php echo !empty($_GET['a'])?'?a='.$_GET['a']:'' ?>" method="post" id="form_comments">
  106. <p class="breadcrumbs">
  107. <?php echo implode('&nbsp;|&nbsp;', $breadcrumbs); ?>
  108. </p>
  109. <p>
  110. <?php echo $selector ?><input class="button submit" type="submit" name="submit" value="Ok" />
  111. </p>
  112. <table class="table">
  113. <thead>
  114. <tr>
  115. <th class="checkbox"><input type="checkbox" onclick="checkAll(this.form, 'idCom[]')" /></th>
  116. <th class="datetime"><?php echo L_COMMENTS_LIST_DATE ?></th>
  117. <th class="message"><?php echo L_COMMENTS_LIST_MESSAGE ?></th>
  118. <th class="author"><?php echo L_COMMENTS_LIST_AUTHOR ?></th>
  119. <th class="action"><?php echo L_COMMENTS_LIST_ACTION ?></th>
  120. </tr>
  121. </thead>
  122. <tbody>
  123. <?php
  124. # On va récupérer les commentaires
  125. $plxAdmin->getPage();
  126. $start = $plxAdmin->aConf['bypage_admin_coms']*($plxAdmin->page-1);
  127. $coms = $plxAdmin->getCommentaires($comSelMotif,'rsort',$start,$plxAdmin->aConf['bypage_admin_coms'],'all');
  128. if($coms) {
  129. $num=0;
  130. while($plxAdmin->plxRecord_coms->loop()) { # On boucle
  131. $year = substr($plxAdmin->plxRecord_coms->f('date'),0,4);
  132. $month = substr($plxAdmin->plxRecord_coms->f('date'),5,2);
  133. $day = substr($plxAdmin->plxRecord_coms->f('date'),8,2);
  134. $time = substr($plxAdmin->plxRecord_coms->f('date'),11,8);
  135. $artId = $plxAdmin->plxRecord_coms->f('article');
  136. $status = $plxAdmin->plxRecord_coms->f('status');
  137. $id = $status.$artId.'.'.$plxAdmin->plxRecord_coms->f('numero');
  138. $content = nl2br($plxAdmin->plxRecord_coms->f('content'));
  139. if($_SESSION['selCom']=='all') {
  140. $content = $content.' - <strong>'.($status==''?L_COMMENT_ONLINE:L_COMMENT_OFFLINE).'</strong><br />';
  141. }
  142. # On génère notre ligne
  143. echo '<tr class="line-'.(++$num%2).' top type-'.$plxAdmin->plxRecord_coms->f('type').'">';
  144. echo '<td><input type="checkbox" name="idCom[]" value="'.$id.'" /></td>';
  145. echo '<td class="datetime">'.$day.'/'.$month.'/'.$year.' '.$time.'&nbsp;</td>';
  146. echo '<td>'.$content.'&nbsp;</td>';
  147. echo '<td>'.plxUtils::strCut($plxAdmin->plxRecord_coms->f('author'),30).'&nbsp;</td>';
  148. echo '<td class="action"> ';
  149. echo '<a href="comment_new.php?c='.$id.(!empty($_GET['a'])?'&amp;a='.$_GET['a']:'').'" title="'.L_COMMENT_ANSWER.'">'.L_COMMENT_ANSWER.'</a> | ';
  150. echo '<a href="comment.php?c='.$id.(!empty($_GET['a'])?'&amp;a='.$_GET['a']:'').'" title="'.L_COMMENT_EDIT_TITLE.'">'.L_COMMENT_EDIT.'</a> | ';
  151. echo '<a href="article.php?a='.$artId.'" title="'.L_COMMENT_ARTICLE_LINKED_TITLE.'">'.L_COMMENT_ARTICLE_LINKED.'</a>';
  152. echo '</td></tr>';
  153. }
  154. } else { # Pas de commentaires
  155. echo '<tr><td colspan="5" class="center">'.L_NO_COMMENT.'</td></tr>';
  156. }
  157. ?>
  158. </tbody>
  159. </table>
  160. <p>
  161. <?php echo plxToken::getTokenPostMethod() ?>
  162. <?php echo $selector ?><input class="button submit" type="submit" name="submit" value="Ok" />
  163. </p>
  164. </form>
  165. <div id="pagination">
  166. <?php
  167. # Hook Plugins
  168. eval($plxAdmin->plxPlugins->callHook('AdminCommentsPagination'));
  169. # Affichage de la pagination
  170. if($coms) { # Si on a des commentaires (hors page)
  171. # Calcul des pages
  172. $last_page = ceil($nbComPagination/$plxAdmin->aConf['bypage_admin_coms']);
  173. if($plxAdmin->page > $last_page) $plxAdmin->page = $last_page;
  174. $prev_page = $plxAdmin->page - 1;
  175. $next_page = $plxAdmin->page + 1;
  176. # Generation des URLs
  177. $p_url = 'comments.php?page='.$prev_page.'&amp;sel='.$_SESSION['selCom'].(!empty($_GET['a'])?'&amp;a='.$_GET['a']:''); # Page precedente
  178. $n_url = 'comments.php?page='.$next_page.'&amp;sel='.$_SESSION['selCom'].(!empty($_GET['a'])?'&amp;a='.$_GET['a']:''); # Page suivante
  179. $l_url = 'comments.php?page='.$last_page.'&amp;sel='.$_SESSION['selCom'].(!empty($_GET['a'])?'&amp;a='.$_GET['a']:''); # Derniere page
  180. $f_url = 'comments.php?page=1'.'&amp;sel='.$_SESSION['selCom'].(!empty($_GET['a'])?'&amp;a='.$_GET['a']:''); # Premiere page
  181. # On effectue l'affichage
  182. if($plxAdmin->page > 2) # Si la page active > 2 on affiche un lien 1ere page
  183. echo '<span class="p_first"><a href="'.$f_url.'" title="'.L_PAGINATION_FIRST_TITLE.'">'.L_PAGINATION_FIRST.'</a></span>';
  184. if($plxAdmin->page > 1) # Si la page active > 1 on affiche un lien page precedente
  185. echo '<span class="p_prev"><a href="'.$p_url.'" title="'.L_PAGINATION_PREVIOUS_TITLE.'">'.L_PAGINATION_PREVIOUS.'</a></span>';
  186. # Affichage de la page courante
  187. printf('<span class="p_page">'.L_PAGINATION.'</span>',$plxAdmin->page,$last_page);
  188. if($plxAdmin->page < $last_page) # Si la page active < derniere page on affiche un lien page suivante
  189. echo '<span class="p_next"><a href="'.$n_url.'" title="'.L_PAGINATION_NEXT_TITLE.'">'.L_PAGINATION_NEXT.'</a></span>';
  190. if(($plxAdmin->page + 1) < $last_page) # Si la page active++ < derniere page on affiche un lien derniere page
  191. echo '<span class="p_last"><a href="'.$l_url.'" title="'.L_PAGINATION_LAST_TITLE.'">'.L_PAGINATION_LAST.'</a></span>';
  192. }
  193. ?>
  194. </div>
  195. <?php if(!empty($plxAdmin->aConf['clef'])) : ?>
  196. <div class="feeds">
  197. <p><?php echo L_COMMENTS_PRIVATE_FEEDS ?> :</p>
  198. <ul class="feed">
  199. <?php $urlp_hl = $plxAdmin->racine.'feed.php?admin'.$plxAdmin->aConf['clef'].'/commentaires/hors-ligne'; ?>
  200. <li><a href="<?php echo $urlp_hl ?>" title="<?php echo L_COMMENT_OFFLINE_FEEDS_TITLE ?>"><?php echo L_COMMENT_OFFLINE_FEEDS ?></a></li>
  201. <?php $urlp_el = $plxAdmin->racine.'feed.php?admin'.$plxAdmin->aConf['clef'].'/commentaires/en-ligne'; ?>
  202. <li><a href="<?php echo $urlp_el ?>" title="<?php echo L_COMMENT_ONLINE_FEEDS_TITLE ?>"><?php echo L_COMMENT_ONLINE_FEEDS ?></a></li>
  203. </ul>
  204. </div>
  205. <?php endif; ?>
  206. <?php
  207. # Hook Plugins
  208. eval($plxAdmin->plxPlugins->callHook('AdminCommentsFoot'));
  209. # On inclut le footer
  210. include(dirname(__FILE__).'/foot.php');
  211. ?>