Exemple d'implémentation : Des nouvelles
Un article de ReaxiaWiki.
Sommaire |
Création du type Reaxia
Notre liste de nouvelles est un contenu structuré, qui s'appellera "Nouvelles". Elle peut être représentée par les champs du tableau suivant :
| Information | Type de champ |
|---|---|
| Titre | Texte sur une ligne |
| Date | Date |
| Texte | Texte de paragraphe |
Ajout d'un contenu
Après avoir créé le type, il faut ajouter au site un contenu dont le type est "Nouvelles". Dans la colonne "Contenu du site", à gauche, cliquez sur l'icône "Ajouter un contenu" puis choisissez le type "Nouvelles".
Mise en place du mot-clé
A présent, il faut ajouter le mot-clé [[NOUVELLES]] dans un champ paragraphe d'un contenu structuré :
Pour que le contributeur ait une description de ce mot-clé dans la liste des mots-clés, il faut ajouter une ligne dans le fichier reaxia_conf/Reaxia_Conf.php :
$GLOBALS['conf']['keywords']['NOUVELLES'] = "Affiche les dernières nouvelles";
Interprétation du mot-clé
Le code suivant est à ajouter dans la librairie traitant l'affichage des pages du site. Il remplace le mot-clé par le résultat de la libraire d'affichage show_news.
$textBefore = '';
$textAfter = '';
if (FindKeyword($Texte_de_la_page, '[[NOUVELLES]]', $textBefore, $textAfter))
{
$Texte_de_la_page = $textBefore;
$Texte_de_la_page .= display_thread('nouvelles', 'show_news', array('return' => true));
$Texte_de_la_page .= $textAfter;
}
Librairie d'affichage
Le code suivant doit être enregistré dans le fichier reaxia_lib/show_news/show_news.php :
<?php
class show_news extends thread_displayer
{
/**
* @param array $thread array with threadname, display_name, categories, PublishedTime
* @param array $options
*/
function show_news($threadname, &$options)
{
// Call the parent's constructor, initializes the class members
$this->thread_displayer($threadname, $options);
// Override any of thread_displayer's class members here:
}
/**
* Specify the SQL query who returns blocs
* @return string the SQL statement that fetches the data
*/
function GetSQLQuery()
{
if ($this->UsePreviewData)
$rxp = '_rxp';
else
$rxp = '';
$sql = 'SELECT * FROM `' . $this->threadRef . $rxp . '`';
$sql .= ' ORDER BY date_1 DESC';
$sql .= ' LIMIT 5';
return $sql;
}
/**
* Does whatever needs to be done with the selected blocs
* @return string usually an HTML fragment, but it can be nothing.
*/
function process_thread_content()
{
$html = '';
foreach ($this->Blocs as $aBloc)
{
$Titre = $aBloc['single_line_1'];
$Paragraphe = $aBloc['paragraph_1_text'];
// setlocale (LC_TIME, 'fr_FR', 'fr');
if ($aBloc['date_1'] != '')
$Date = trim(strftime("%e %B %y", SQLToTimeStamp($aBloc['date_1'])));
else
$Date = '';
// Output each bloc as HTML
$html .= '<div class="news_bloc">'."\n";
$html .= '<h1 class="news_title">'.$Date.' - '.$Titre.'</h1>'."\n";
$html .= '<p class="news_p">'.$Paragraphe.'</p>'."\n";
$html .= '</div>'."\n";
}
return $html;
}
}
?>
