Skip to content

Instantly share code, notes, and snippets.

@bazooka07
Last active January 17, 2021 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bazooka07/72b8916fcba3a86eec64ef8488fe30cc to your computer and use it in GitHub Desktop.
Save bazooka07/72b8916fcba3a86eec64ef8488fe30cc to your computer and use it in GitHub Desktop.
Modification du template commentaires.php dans le thème "defaut" de PluXml pour afficher un avatar à chaque commentaire
<?php if(!defined('PLX_ROOT')) exit; ?>
<?php if($plxShow->plxMotor->plxRecord_coms): ?>
<?php
/*
* Rajouter la règle suivante dans theme.css :
.comment.avatar {
display: grid;
grid-template-columns: 4rem 1fr;
background: none;
padding-left: 0;
gap: 1rem;
}
* */
function getListing($path) {
$filename = $path . 'avatars.lst';
if(file_exists($filename)) {
return array_map('trim', file($filename));
} else {
# On récupère la liste des avatars dans le dossier des médias
$filesList = array_map(
function($item) use($path) {
return preg_replace('@^' . $path . '@', '', $item);
},
glob($path . 'art_*/armoiries_*.png')
);
# contrôle de l'unicité des blasons
$listing = array();
foreach($filesList as $f) {
$k = strtolower(preg_replace('@.*armoiries_?(.*)\.png$@', '$1', $f));
if(!array_key_exists($k, $listing)) {
$listing[$k] = $f;
}
}
ksort($listing);
file_put_contents($filename, implode(PHP_EOL, array_values($listing)));
return array_values($listing);
}
}
$avatars = getListing(PLX_ROOT . $plxShow->plxMotor->aConf['medias']);
function getAvatar($email, $name, $listing) {
if(empty($listing)) { return ''; }
$value = trim(!empty($email) ? $email : $name);
if(empty($value)) { return false; }
$index = abs(crc32(strtolower($value)));
$n = $index % count($listing);
return $listing[$n];
}
function avatarName($avatar) {
return strtr(
preg_replace('@^armoiries_?@i', '', basename($avatar, '.png')),
array(
'_d_' => ' d\'',
'_' => ' ',
)
);
}
?>
<h3 id="comments">
<?php echo $plxShow->artNbCom(); ?>
</h3>
<?php while($plxShow->plxMotor->plxRecord_coms->loop()): # On boucle sur les commentaires ?>
<div id="<?php $plxShow->comId(); ?>" class="comment <?php $plxShow->comLevel(); ?> avatar">
<div>
<?php
$avatar = getAvatar(
$plxShow->plxMotor->plxRecord_coms->f('mail'),
$plxShow->plxMotor->plxRecord_coms->f('author'),
$avatars
);
?>
<img src="<?php $plxShow->urlRewrite($plxShow->plxMotor->aConf['medias'] . $avatar) ?>" alt="avatar" title="<?= avatarName($avatar) ?>"/>
</div>
<div id="com-<?php $plxShow->comIndex(); ?>">
<small>
<a class="nbcom" href="<?php $plxShow->ComUrl(); ?>" title="#<?php echo $plxShow->plxMotor->plxRecord_coms->i+1 ?>">#<?php echo $plxShow->plxMotor->plxRecord_coms->i+1 ?></a>&nbsp;
<time datetime="<?php $plxShow->comDate('#num_year(4)-#num_month-#num_day #hour:#minute'); ?>"><?php $plxShow->comDate('#day #num_day #month #num_year(4) - #hour:#minute'); ?></time> -
<?php $plxShow->comAuthor('link'); ?>
<?php $plxShow->lang('SAID'); ?> :
</small>
<blockquote>
<p class="content_com type-<?php $plxShow->comType(); ?>"><?php $plxShow->comContent(); ?></p>
</blockquote>
</div>
<?php if($plxShow->plxMotor->plxRecord_arts->f('allow_com') AND $plxShow->plxMotor->aConf['allow_com']): ?>
<a rel="nofollow" href="<?php $plxShow->artUrl(); ?>#form" onclick="replyCom('<?php $plxShow->comIndex() ?>')"><?php $plxShow->lang('REPLY'); ?></a>
<?php endif; ?>
</div>
<?php endwhile; # Fin de la boucle sur les commentaires ?>
<?php endif; ?>
<?php if($plxShow->plxMotor->plxRecord_arts->f('allow_com') AND $plxShow->plxMotor->aConf['allow_com']): ?>
<h3>
<?php $plxShow->lang('WRITE_A_COMMENT') ?>
</h3>
<form id="form" action="<?php $plxShow->artUrl(); ?>#form" method="post">
<fieldset>
<div class="grid">
<div class="col sml-12">
<label for="id_name"><?php $plxShow->lang('NAME') ?>* :</label>
<input id="id_name" name="name" type="text" size="20" value="<?php $plxShow->comGet('name',''); ?>" maxlength="30" required="required" />
</div>
</div>
<div class="grid">
<div class="col sml-12 lrg-6">
<label for="id_mail"><?php $plxShow->lang('EMAIL') ?> :</label>
<input id="id_mail" name="mail" type="text" size="20" value="<?php $plxShow->comGet('mail',''); ?>" />
</div>
<div class="col sml-12 lrg-6">
<label for="id_site"><?php $plxShow->lang('WEBSITE') ?> :</label>
<input id="id_site" name="site" type="text" size="20" value="<?php $plxShow->comGet('site',''); ?>" />
</div>
</div>
<div class="grid">
<div class="col sml-12">
<div id="id_answer"></div>
<label for="id_content" class="lab_com"><?php $plxShow->lang('COMMENT') ?>* :</label>
<textarea id="id_content" name="content" cols="35" rows="6" required="required"><?php $plxShow->comGet('content',''); ?></textarea>
</div>
</div>
<?php $plxShow->comMessage('<p id="com_message" class="#com_class"><strong>#com_message</strong></p>'); ?>
<?php if($plxShow->plxMotor->aConf['capcha']): ?>
<div class="grid">
<div class="col sml-12">
<label for="id_rep"><strong><?php echo $plxShow->lang('ANTISPAM_WARNING') ?></strong>*</label>
<?php $plxShow->capchaQ(); ?>
<input id="id_rep" name="rep" type="text" size="2" maxlength="1" style="width: auto; display: inline;" required="required" />
</div>
</div>
<?php endif; ?>
<div class="grid">
<div class="col sml-12">
<input type="hidden" id="id_parent" name="parent" value="<?php $plxShow->comGet('parent',''); ?>" />
<input class="blue" type="submit" value="<?php $plxShow->lang('SEND') ?>" />
</div>
</div>
</fieldset>
</form>
<script>
function replyCom(idCom) {
document.getElementById('id_answer').innerHTML='<?php $plxShow->lang('REPLY_TO'); ?> :';
document.getElementById('id_answer').innerHTML+=document.getElementById('com-'+idCom).innerHTML;
document.getElementById('id_answer').innerHTML+='<a rel="nofollow" href="<?php $plxShow->artUrl(); ?>#form" onclick="cancelCom()"><?php $plxShow->lang('CANCEL'); ?></a>';
document.getElementById('id_answer').style.display='inline-block';
document.getElementById('id_parent').value=idCom;
document.getElementById('id_content').focus();
}
function cancelCom() {
document.getElementById('id_answer').style.display='none';
document.getElementById('id_parent').value='';
document.getElementById('com_message').innerHTML='';
}
var parent = document.getElementById('id_parent').value;
if(parent!='') { replyCom(parent) }
</script>
<script src="<?= PLX_ROOT.$plxMotor->aConf['racine_themes'] . $plxMotor->style ?>/smileys.js"></script>
<?php $plxShow->comFeed('rss',$plxShow->artId(), '<p><a href="#feedUrl" title="#feedTitle">#feedName</a></p>'); ?>
<?php else: ?>
<p>
<?php $plxShow->lang('COMMENTS_CLOSED') ?>.
</p>
<?php endif; # Fin du if sur l'autorisation des commentaires ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment