Fork me on GitHub

Rapport de message :*
 

Re: Bloquer l'édition des commentaires dans xoops 2.5

Titre du sujet : Re: Bloquer l'édition des commentaires dans xoops 2.5
par aquaportail sur 25/11/2010 19:49:48

Je t'indique un hack compliqué pour obtenir une fonction de blocage de l'édition des commentaires des membres dans tout Xoops!

Attention : (très) bon niveau de programmation recommandé pour effectuer les modifications. De plus, attendre la validation par un développeur de l'équipe Xoops actuelle avant de faire cela sur un site en production. Je tourne sur une plateforme Xoops 2.0.1x, donc je n'ai pas vérifié si cela fonctionne sous une Xoops 2.4 ou 2.5.

Il faut modifier manuellement 2 fichiers : root/class/commentrenderer.php et root/modules/system/templates/system_comment.html

Le plus difficile est d'appliquer le hack dans commentrenderer.php, la modification dans le fichier template est simplissime ensuite.

L'objectif est de créer une variable booléenne, nommée 'canedit', qui va déterminer, ou non, l'affichage du bouton 'edit'. Le délai, dans la variable $the_delay est exprimé en minutes; dans mon exemple, le délai est fixé à 1 jour (24x60=1440 minutes).

Dans le fichier commentrenderer.php, il faut ajouter ce code (3 fois, dont 1 différent...) :

1- Dans la function renderFlatView (environ ligne 100 dans mon fichier), juste vers la fin de la fonction (vers ligne 120), il faut remplacer :
$this->_tpl->append('comments', array('id' => $this->_comments[$i]->getVar('com_id'), 'title' => $title'text' => $text'date_posted' => formatTimestamp($this->_comments[$i]->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($this->_comments[$i]->getVar('com_modified'), 'm'), 'poster' => $poster));


par

//hack date edit - JF Fortier - www.aquaportail.com - 25 nov, 2010
$created_date $this->_comments[$i]->getVar('com_created');
$the_delay 1440// 24 hours = 1440 minutes -set this value to your own
$canEdit = (time()-$created_date) < ($the_delay*60);
$this->_tpl->append('comments', array('id' => $this->_comments[$i]->getVar('com_id'), 'title' => $title'text' => $text'date_posted' => formatTimestamp($this->_comments[$i]->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($this->_comments[$i]->getVar('com_modified'), 'm'), 'poster' => $poster'canedit' => $canEdit));


2- Dans la function renderThreadView (environ ligne 140 dans mon fichier), juste vers la fin de la fonction (vers ligne 180), il faut remplacer :
$this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid'), 'id' => $tree[$comment_id]['obj']->getVar('com_id'), 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid'), 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid'), 'title' => $title'text' => $text'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid')), 'replies' => $replies'show_replies' => $show_replies));


par

//hack date edit - JF Fortier - www.aquaportail.com - 25 nov, 2010
$created_date $tree[$comment_id]['obj']->getVar('com_created');
$the_delay 1440// 24 hours = 1440 minutes -set this value to your own
$canEdit = (time()-$created_date) < ($the_delay*60);
$this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid'), 'id' => $tree[$comment_id]['obj']->getVar('com_id'), 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid'), 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid'), 'title' => $title'text' => $text'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid')), 'replies' => $replies'show_replies' => $show_replies'canedit' => $canEdit));


3- Dans la function renderNestView (environ ligne 235 dans mon fichier), juste vers la fin de la fonction (vers ligne 265), il faut remplacer :
$this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid'), 'id' => $tree[$comment_id]['obj']->getVar('com_id'), 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid'), 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid'), 'title' => $title'text' => $text'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid')), 'replies' => $replies));


par

//hack date edit - JF Fortier - www.aquaportail.com - 25 nov, 2010
$created_date $tree[$comment_id]['obj']->getVar('com_created');
$the_delay 1440// 24 hours = 1440 minutes -set this value to your own
$canEdit = (time()-$created_date) < ($the_delay*60);
$this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid'), 'id' => $tree[$comment_id]['obj']->getVar('com_id'), 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid'), 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid'), 'title' => $title'text' => $text'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid')), 'replies' => $replies'canedit' => $canEdit));


Ca, c'est fait, c'était le plus gros morceau.

Maintenant, il faut modifier le template modules/system/templates/system_comment.html en insérant un test de validité du booléen créé précédemment comme ceci :

<{if $comment.canedit}>le lien pour editer un commentaire<{/if}>


Evidemment, il faut laisser à l'admin/modo la possibilité d'éditer tous les messages et cela va ressembler à ceci pour la modification du template (il faut repérer où est afficher la variable $lang_edit).
Attention : ne pas recopier ce bout de html stricto-sensu! Il tient compte de votre template... c'est le test smarty qui entoure le lien d'édition qui est important.
<{elseif $xoops_isuser == true && $xoops_userid == $comment.poster.id}>
 <
td class="even right">
  <{if 
$comment.canedit}><class=btSearch href="<{$editcomment_link}>&amp;com_id=<{$comment.id}>"><{$lang_edit}></a> <{/if}>


SVP : attendez la validation d'un développeur confirmé de l'équipe Xoops... Ce genre de modif peut facilement planter un site...

Note : évidemment, dans les options admins de Xoops, il faudra forcer la mise à jour des templates pour que les modifications soient visibles.

Ce hack est à réserver aux experts : il est aussi dangereux qu'une pieuvre en colère!
Propulsé avec XOOPS | Graphisme adapté par Tatane, Grosdunord, Montuy337513

73 Personne(s) en ligne (56 Personne(s) connectée(s) sur Forum) | Utilisateur(s): 0 | Invité(s): 73 | Plus ...