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