Subversion Repositories Applications.papyrus

Compare Revisions

Problem with comparison.

Ignore whitespace Rev HEAD → Rev 842

/trunk/api/text/wiki_papyrus/Papyrus.class.php
New file
0,0 → 1,319
<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.3 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of Papyrus. |
// | |
// | Foobar is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | Foobar is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: Papyrus.class.php,v 1.8 2006-05-10 16:02:49 ddelon Exp $
/**
* Classe configurant le formatage pour Papyrus.
*
* Ce fichier contient une classe configurant les règles de formatage de Papyrus.
* Nécessite que l'application appelant ce fichier est précédement inclu le fichier de Pear:
* 'Text/Wiki.php';
*
*@package Text_Wiki
*@subpackage Papyrus
//Auteur original :
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author Aucun
*@copyright Tela-Botanica 2000-2004
*@version $Revision: 1.8 $ $Date: 2006-05-10 16:02:49 $
// +------------------------------------------------------------------------------------------------------+
*/
 
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
/**
*
* Parse structured wiki text and render into arbitrary formats such as XHTML.
*
* Cette classe fille permet de configurer les régles de formatage pour Papyrus.
* Généralement nous avons à faire à des actions.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
* @package Text_Wiki
* @version 0.23.1
* @license LGPL
*/
class Text_Papyrus extends Text_Wiki {
/**
*
* Liste de règles par défaut du format Papyrs dans leur ordre d'application au texte
* à transformer.
*
* @access public
*
* @var array
*
*/
var $rules = array(
'Inclure', // Action Inclure
'Motcles', // Action Motcles
'Categorie', // Action Categorie
'Nouveaute', // Action Nouveaute
'Plan', // Action Plan
'Lien', // Action Lien
'Syndication', // Action Syndication
'Redirection' // Action Redirection
);
/**
*
* The list of rules to not-apply to the source text.
*
* @access public
*
* @var array
*
*/
var $disable = array();
/**
*
* The delimiter for token numbers of parsed elements in source text.
*
* @access public
*
* @var string
*
*/
var $delim = 12;
function Text_Papyrus($rules = null)
{
//Text_Wiki::Text_Wiki();
if (is_array($rules)) {
$this->rules = $rules;
}
// Nous devons sortir les fichiers de Text_Wiki du dépot Pear car la fonction file_exists de PHP utilisée dans
// la méthode findfile de Text_Wiki renvoie false.
$this->addPath('parse', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Parse/');
$this->addPath('render', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Render/');
// Pour les règles spécifiques à Papyrus:
$this->addPath('parse', $this->fixPath(dirname(__FILE__)) . 'Parse/');
$this->addPath('render', $this->fixPath(dirname(__FILE__)) . 'Render/');
}
/**
*
* Renders tokens back into the source text, based on the requested format.
*
* @access public
*
* @param string $format The target output format, typically 'xhtml'.
* If a rule does not support a given format, the output from that
* rule is rule-specific.
*
* @return string The transformed wiki text.
*
*/
function render($format = 'Xhtml')
{
// the rendering method we're going to use from each rule
$format = ucwords(strtolower($format));
// the eventual output text
$output = '';
// when passing through the parsed source text, keep track of when
// we are in a delimited section
$in_delim = false;
// when in a delimited section, capture the token key number
$key = '';
// load the format object
$this->loadFormatObj($format);
// pre-rendering activity
if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
$output .= $this->formatObj[$format]->pre();
}
// load the render objects
foreach (array_keys($this->parseObj) as $rule) {
$this->loadRenderObj($format, $rule);
}
// pass through the parsed source text character by character
$k = strlen($this->source);
for ($i = 0; $i < $k; $i++) {
// the current character
$char = $this->source{$i};
// are alredy in a delimited section?
if ($in_delim) {
// yes; are we ending the section?
if ($char == chr($this->delim)) {
// yes, get the replacement text for the delimited
// token number and unset the flag.
$key = (int)$key;
$rule = null;
if (isset($this->tokens[$key][0])) {
$rule = $this->tokens[$key][0];
}
$opts = null;
if (isset($this->tokens[$key][1])) {
$opts = $this->tokens[$key][1];
}
if (isset($this->renderObj[$rule]) && is_object($this->renderObj[$rule])) {
$output .= $this->renderObj[$rule]->token($opts);
}
$in_delim = false;
} else {
// no, add to the dlimited token key number
$key .= $char;
}
} else {
// not currently in a delimited section.
// are we starting into a delimited section?
if ($char == chr($this->delim)) {
// yes, reset the previous key and
// set the flag.
$key = '';
$in_delim = true;
} else {
// no, add to the output as-is
$output .= $char;
}
}
}
// post-rendering activity
if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
$output .= $this->formatObj[$format]->post();
}
// return the rendered source text.
return $output;
}
/**
*
* Add a token to the Text_Wiki tokens array, and return a delimited
* token number.
*
* @access public
*
* @param array $options An associative array of options for the new
* token array element. The keys and values are specific to the
* rule, and may or may not be common to other rule options. Typical
* options keys are 'text' and 'type' but may include others.
*
* @param boolean $id_only If true, return only the token number, not
* a delimited token string.
*
* @return string|int By default, return the number of the
* newly-created token array element with a delimiter prefix and
* suffix; however, if $id_only is set to true, return only the token
* number (no delimiters).
*
*/
function addToken($rule, $options = array(), $id_only = false)
{
// increment the token ID number. note that if you parse
// multiple times with the same Text_Wiki object, the ID number
// will not reset to zero.
static $id;
if (! isset($id)) {
$id = 0;
} else {
$id ++;
}
// force the options to be an array
settype($options, 'array');
// add the token
$this->tokens[$id] = array(
0 => $rule,
1 => $options
);
// return a value
if ($id_only) {
// return the last token number
return $id;
} else {
// return the token number with delimiters
return chr($this->delim) . $id . chr($this->delim);
}
}
}
 
// +------------------------------------------------------------------------------------------------------+
// | PIED du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
 
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.7 2005/09/23 13:58:07 ddelon
* Php5, Projet et Redirection
*
* Revision 1.6 2005/04/18 16:41:53 jpm
* Ajout des actions Plan et Syndication.
*
* Revision 1.5 2005/04/14 16:35:42 jpm
* Ajout de nouvelles actions pour Papyrus XHTML.
*
* Revision 1.4 2005/01/20 19:39:39 jpm
* Correction bogue du à la fonction file_exists qui renvoie false pour les fichiers présent dans le dossier Pear /usr/local/lib/php/.
*
* Revision 1.3 2004/12/07 12:17:37 jpm
* Correction message d'erreur.
*
* Revision 1.2 2004/11/26 12:13:03 jpm
* Correction de résidu...
*
* Revision 1.1 2004/11/26 12:11:49 jpm
* Ajout des action Papyrus à Text_Wiki.
*
* Revision 1.2 2004/11/25 15:36:41 jpm
* Suppression régle Delimiter car problème avec les délimitations de fin de ligne.
*
* Revision 1.1 2004/11/23 17:25:38 jpm
* Début classe PEAR WIKI pour la syntaxe Wikini.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Syndication.php
New file
0,0 → 1,36
<?php
require_once GEN_CHEMIN_API.'syndication_rss/syndication_rss.php';
 
class Text_Wiki_Render_Xhtml_Syndication extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// Initialisation des variables
$sortie = '';
$titre = $options['titre'];
$urls = $options['url'];
$nblimite = $options['nb'];
$nouvellefenetre = $options['nouvellefenetre'];
$formatdate = $options['formatdate'];
$tab_url = array_map('trim', explode(',', $urls));
foreach ($tab_url as $cle => $url) {
$url = str_replace('&amp;', '&', $url) ;
$sortie .= voir_rss($titre, $url, $nblimite, $nouvellefenetre, $formatdate);
}
return $sortie;
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Motcles.php
New file
0,0 → 1,138
<?php
 
class Text_Wiki_Render_Xhtml_Motcles extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// Initialisation des variables
$sortie = '';
if (isset($options['mots'])) {
$mots = $options['mots'];
} else {
return '<p>'.' Aucun mot-clés passé en paramêtre! '.'</p>';
}
$condition = 'OR';
if (isset($options['condition'])) {
$condition = $options['condition'];
}
$condition2 = 'OR';
if (isset($options['condition2'])) {
$condition2 = $options['condition2'];
}
$ordre = 'ASC';
if (isset($options['ordre'])) {
$ordre = $options['ordre'];
}
if (isset($options['categorie'])) {
$categorie = $options['categorie'] ;
}
// Récupération des infos sur les mots
$tab_mots = explode(',', $mots);
for ($i = 0; $i < count($tab_mots); $i++) {
// Suppression des espaces, tabulations... en début et fin de chaine
$tab_mots[$i] = trim($tab_mots[$i]);
}
// Récupération des infos sur les catégories
$tab_cat = explode(',', $categorie) ;
for ($i = 0; $i < count($tab_cat); $i++) {
// Suppression des espaces, tabulations... en début et fin de chaine
$tab_cat[$i] = trim($tab_cat[$i]);
}
$aso_info_menu = GEN_lireInfoMenuMeta($GLOBALS['_GEN_commun']['pear_db'], $tab_mots, $tab_cat, $condition, $condition2, $ordre);
// Formatage des infos en XHTML
$sortie .= '<ul class="page_liste">'."\n";
foreach ($aso_info_menu as $id_menu => $un_menu) {
// Création de l'url
$une_url =& new Pap_URL();
$une_url->setId($id_menu);
$sortie .= '<li>'."\n";
// Affichage de l'auteur(s)
$sortie .= '<span class="page_auteur"> '.$un_menu->gm_auteur.'</span>'."\n";
$sortie .= '<span class="page_separateur_auteur"> - </span>'."\n";
// Affichage du titre
$sortie .= '<a href="'.$une_url->getURL().'">';
$sortie .= '<span class="page_titre"> '.$un_menu->gm_titre.'</span>';
$sortie .= '</a>'."\n";
$sortie .= '<span class="page_separateur_titre"> - </span>'."\n";
// Affichage de l'horaire de la création de la page
if (($heure = date('G', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_creation_heure">'.$heure.'</span>';
$sortie .= '<span class="page_separateur_heure">:</span>';
$minute = date('i', strtotime($un_menu->gm_date_creation));
$sortie .= '<span class="page_creation_minute">'.$minute.'</span>';
if (($seconde = date('s', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_separateur_heure">:</span>';
$sortie .= '<span class="page_creation_seconde">'.$seconde.'</span>';
}
}
$sortie .= "\n".'<span class="page_separateur_date_heure"> - </span>'."\n";
// Affichage de la date de la création de la page
if (($jour = date('d', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_creation_jour"> '.$jour.'</span>'."\n";
}
if (($mois = $this->_traduireMois(date('m', strtotime($un_menu->gm_date_creation))) ) != '' ) {
$sortie .= '<span class="page_creation_mois"> '.$mois.'</span>'."\n";
}
if (($annee = date('Y', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_creation_annee"> '.$annee.'</span>'."\n";
}
$sortie .= '</li>'."\n";
}
$sortie .= '</ul>'."\n";
return $sortie;
}
function _traduireMois($mois_numerique)
{
switch ($mois_numerique) {
case '01' :
return 'janvier';
case '02' :
return 'février';
case '03' :
return 'mars';
case '04' :
return 'avril';
case '05' :
return 'mai';
case '06' :
return 'juin';
case '07' :
return 'juillet';
case '08' :
return 'août';
case '09' :
return 'septembre';
case '10' :
return 'octobre';
case '11' :
return 'novembre';
case '12' :
return 'décembre';
default:
return '';
}
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Lien.php
New file
0,0 → 1,143
<?php
 
class Text_Wiki_Render_Xhtml_Lien extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
 
// Initialisation des variables
$sortie = '';
$niveau = $options['niveau'];
$identifiant = $options['identifiant'];
$titre = $options['titre'];
$bdd =& $GLOBALS['_GEN_commun']['pear_db'];
$id_langue = $GLOBALS['_GEN_commun']['i18n']; //identifiant de la langue choisie
if (isset($id_langue) && ($id_langue!='')) {
$langue_url=$id_langue;
} else {
$langue_url=GEN_I18N_ID_DEFAUT;
}
$une_url =& new Pap_URL('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
$nom='';
if ($niveau=="site") {
$requete = 'SELECT distinct * '.
'FROM gen_site ';
if (is_numeric($identifiant)) {
$requete .= 'WHERE gs_code_num = '.$identifiant.' ';
$une_url->addQueryString(GEN_URL_CLE_SITE, $identifiant);
}
$resultat = $bdd->query($requete);
(DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
$aso_site = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
$resultat->free();
$requete_traduction = 'SELECT * '.
'FROM gen_site_relation, gen_site '.
'WHERE gs_id_site = gsr_id_site_02 ' .
'AND '.$identifiant.' = gs_code_num '.
'AND gsr_id_valeur = 1 '.// 1 = "avoir traduction"
'AND gs_ce_i18n = "'.$langue_url.'" ';
$resultat_traduction = $bdd->query($requete_traduction);
(DB::isError($resultat_traduction)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_traduction->getMessage(), $requete_traduction))
: '';
if ( $resultat_traduction->numRows() > 0 ) {
$aso_site=$resultat_traduction->fetchRow(DB_FETCHMODE_ASSOC);
}
if ($titre=='') {
if (!empty($aso_site['gs_nom'])) {
$titre = $aso_site['gs_nom'];
} else {
$titre = $aso_site['gs_titre'];
}
}
}
// Menu
else {
$requete = 'SELECT distinct * '.
'FROM gen_menu ';
if (is_numeric($identifiant)) {
$requete .= 'WHERE gm_code_num = '.$identifiant.' ';
$une_url->addQueryString(GEN_URL_CLE_MENU, $identifiant);
}
$resultat = $bdd->query($requete);
(DB::isError($resultat)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
$aso_menu = $resultat->fetchRow(DB_FETCHMODE_ASSOC);
$resultat->free();
$requete_traduction = 'SELECT * '.
'FROM gen_menu_relation, gen_menu '.
'WHERE '.$identifiant.' = gm_code_num ' .
'AND gmr_id_menu_02 = gm_id_menu '.
'AND gmr_id_valeur = 2 '.// 2 = "avoir traduction"
'AND gm_ce_i18n = "'.$langue_url.'" ';
$resultat_traduction = $bdd->query($requete_traduction);
(DB::isError($resultat_traduction)) ? die(BOG_afficherErreurSql(__FILE__, __LINE__, $resultat_traduction->getMessage(), $requete_traduction))
: '';
if ($resultat_traduction->numRows() > 0) {
$aso_menu=$resultat_traduction->fetchRow(DB_FETCHMODE_ASSOC);
}
if ($titre=='') {
if (!empty($aso_menu['gm_nom'])) {
$titre = $aso_menu['gm_nom'];
}
elseif (!empty($menu_valeur['gm_titre'])) {
$titre = $aso_menu['gm_titre'];
}
}
}
if ($langue_url != GEN_I18N_ID_DEFAUT) {
$une_url->addQueryString(GEN_URL_CLE_I18N, $langue_url);
}
// Construction du lien
$sortie = '<a href="'.$une_url->getURL().'">'.htmlentities($titre).'</a>';
return $sortie;
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Redirection.php
New file
0,0 → 1,27
<?php
class Text_Wiki_Render_Xhtml_Redirection extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// Initialisation des variables
$sortie = '';
$url = $options['url'];
$url=ereg_replace('&amp;','&',$url);
header("Location: $url");
exit;
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Plan.php
New file
0,0 → 1,92
<?php
 
class Text_Wiki_Render_Xhtml_Plan extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// Initialisation des variables
$bdd =& $GLOBALS['_GEN_commun']['pear_db'];
$sortie = '';
$sites = $options['site'];
// Récupération de l'affichage ou pas des raccourcis
if (isset($options['permalien'])) {
$permalien = $options['permalien'];
}
$tab_site = array_map('trim', explode(',', $sites));
foreach ($tab_site as $cle => $site) {
if (count($tab_site) > 1) {
$aso_site = GEN_lireInfoSitePrincipalCodeAlpha($bdd, $site, DB_FETCHMODE_ASSOC);
if (!empty($aso_site['gs_titre'])) {
$titre = $aso_site['gs_titre'];
} else {
$titre = $aso_site['gs_nom'];
}
$sortie .= '<h2>'.htmlentities($titre).'</h2>'."\n";
}
$sortie .= '<ul class="plan_site_'.$site.'" >'."\n";
$aso_menus = GEN_retournerTableauMenusSiteCodeAlpha($bdd, $site);
$sortie .= $this->parserTableauMenus($aso_menus, $permalien);
$sortie .= '</ul>'."\n";
}
return $sortie;
}
function parserTableauMenus($aso_menus, $permalien)
{
$sortie = '';
// Création de l'url
foreach ($aso_menus as $menu_id => $menu_valeur) {
if ( $menu_valeur['gm_date_fin_validite'] == ''
|| $menu_valeur['gm_date_fin_validite'] == '0000-00-00 00:00:00'
|| strtotime($menu_valeur['gm_date_fin_validite']) > time()) {
$sortie .= '<li>';
// Création de l'url
$une_url =& new Pap_URL('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
$une_url->setId($menu_id);
// Construction de l'attribut title
$title = '';
if (!empty($menu_valeur['gm_titre'])) {
$title = ' title="'.htmlentities($menu_valeur['gm_titre']).'"';
} elseif (!empty($menu_valeur['gm_titre_alternatif'])) {
$title = ' title="'.htmlentities($menu_valeur['gm_titre_alternatif']).'"';
}
// Construction du lien
$sortie .= '<a href="'.$une_url->getURL().'"'.$title.'>'.htmlentities($menu_valeur['gm_nom']).'</a>';
// Nous affichons ou pas le permalien
if ($permalien) {
$une_url->setPermalien(true);
$sortie .= ' <span class="plan_permalien">'.'('.$une_url->getURL().')'.'</span>';
$une_url->setPermalien(false);
}
// Nous ajoutons les sous-menus s'il y en a.
$retour = $this->parserTableauMenus($menu_valeur['sous_menus'], $permalien);
if ($retour != '') {
$sortie .= "\n".'<ul>'."\n".$retour."\n".'</ul>'."\n";
}
$sortie .= '</li>'."\n";
}
}
return $sortie;
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Nouveaute.php
New file
0,0 → 1,164
<?php
 
class Text_Wiki_Render_Xhtml_Nouveaute extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// Initialisation des variables
$sortie = '';
$type = '';
$site = '';
$nombre = $options['nombre'];
// Récupération du type
if (isset($options['type'])) {
$type = $options['type'];
}
// Récupération du site
if (isset($options['site'])) {
$site = $options['site'];
}
// Récupération de la catégorie
if (isset($options['categorie'])) {
$categorie = $options['categorie'];
}
$aso_info_menu = GEN_lireInfoMenuContenuDate($GLOBALS['_GEN_commun']['pear_db'], $type, $site, $categorie);
// Formatage des infos en XHTML
$sortie .= '<ul class="page_liste">'."\n";
$i = 0;
foreach ($aso_info_menu as $menu_id => $un_menu) {
if ($i == $nombre) {
break;
}
// Création de l'url
$une_url =& new Pap_URL();
$une_url->setId($menu_id);
// Début affichage d'une entrée de la liste des pages modifiées
if ($un_menu->gmc_ce_type_modification = 1) {
$type_modif = 'mineure';
} elseif ($un_menu->gmc_ce_type_modification = 2) {
$type_modif = 'majeure';
}
$sortie .= '<li class="page_modification_'.$type_modif.'">'."\n";
// Affichage du titre
$sortie .= '<h2 class="page_titre"><a href="'.$une_url->getURL().'">';
if (!empty($un_menu->gm_titre)) {
$sortie .= $un_menu->gm_titre;
} elseif (!empty($un_menu->gm_titre_alternatif)) {
$sortie .= $un_menu->gm_titre_alternatif;
} else {
$sortie .= $un_menu->gm_nom;
}
$sortie .= '</a></h2>'."\n".'<dl>'."\n";
// Affichage de l'auteur(s)
if (!empty($un_menu->gm_auteur)) {
$sortie .= '<dt class="page_auteur"> Auteur(s)&nbsp;: '.'</dt>'."\n";
$sortie .= '<dd>'.$un_menu->gm_auteur.'</dd>'."\n";
}
// Affichage des contributeur(s)
if (!empty($un_menu->gm_contributeur)) {
$sortie .= '<dt class="page_contributeur"> Contributeur(s)&nbsp;: '.'</dt>'."\n";
$sortie .= '<dd>'.$un_menu->gm_contributeur.'</dd>'."\n";
}
// Affichage de la date de la modification de la page
$sortie .= '<dt class="page_modification_date"> '.'Modifié le&nbsp;: '.'</dt>'."\n";
$sortie .= '<dd>'."\n";
if (($jour = date('d', strtotime($un_menu->gmc_date_modification)) ) != 0 ) {
$sortie .= '<span class="page_modification_jour"> '.$jour.'</span>'."\n";
}
if (($mois = $this->_traduireMois(date('m', strtotime($un_menu->gmc_date_modification))) ) != '' ) {
$sortie .= '<span class="page_modification_mois"> '.$mois.'</span>'."\n";
}
if (($annee = date('Y', strtotime($un_menu->gmc_date_modification)) ) != 0 ) {
$sortie .= '<span class="page_modification_annee"> '.$annee.'</span>'."\n";
}
$sortie .= '<span class="page_separateur_date_heure"> - </span>'."\n";
// Affichage de l'horaire de la modification de la page
if (($heure = date('G', strtotime($un_menu->gmc_date_modification)) ) != 0 ) {
$sortie .= '<span class="page_modification_heure">'.$heure.'</span>';
$sortie .= '<span class="page_separateur_heure">:</span>';
$minute = date('i', strtotime($un_menu->gmc_date_modification));
$sortie .= '<span class="page_modification_minute">'.$minute.'</span>'."\n";
/*
if (($seconde = date('s', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_separateur_heure">:</span>';
$sortie .= '<span class="page_creation_seconde">'.$seconde.'</span>';
}
*/
}
$sortie .= '</dd>'."\n";
// Affichage de la description
if (!empty($un_menu->gm_description_libre)) {
$sortie .= '<dt class="page_description"> Description&nbsp;: '.'</dt>'."\n";
$sortie .= '<dd>'.$un_menu->gm_description_libre.'</dd>'."\n";
}
// Affichage du résumé de la modification
if (!empty($un_menu->gmc_resume_modification)) {
$sortie .= '<dt class="page_resumer_modification_'.$type_modif.'"> Résumer modification&nbsp;: '.'</dt>'."\n";
$sortie .= '<dd>'.$un_menu->gmc_resume_modification.'</dd>'."\n";
}
$sortie .= '</dl>'."\n";
$sortie .= '</li>'."\n";
$i++;
}
$sortie .= '</ul>'."\n";
return $sortie;
}
function _traduireMois($mois_numerique)
{
switch ($mois_numerique) {
case '01' :
return 'janvier';
case '02' :
return 'février';
case '03' :
return 'mars';
case '04' :
return 'avril';
case '05' :
return 'mai';
case '06' :
return 'juin';
case '07' :
return 'juillet';
case '08' :
return 'août';
case '09' :
return 'septembre';
case '10' :
return 'octobre';
case '11' :
return 'novembre';
case '12' :
return 'décembre';
default:
return '';
}
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Inclure.php
New file
0,0 → 1,69
<?php
 
class Text_Wiki_Render_Xhtml_Inclure extends Text_Wiki_Render {
var $conf = array(
'sites' => array(
'Wikipedia' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'),
'Wikipedia_fr' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://fr.wikipedia.org/wiki/%s'),
'Wikipedia_en' => array('preg' => '/<!-- start content -->(.*)<!-- end content -->/Umsi', 'url' => 'http://en.wikipedia.org/wiki/%s'),
'Wikini_eFlore' => array('preg' => '/<div class="page">(.*)<\/div>.*<div class="commentsheader">/Umsi', 'url' => 'http://wiki.tela-botanica.org/eflore/wakka.php?wiki=%s')
),
'css' => null,
'encodage' => 'iso-8859-15'
);
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
$site = $options['site'];
$page = $options['page'];
$text = $options['text'];
$css = $this->formatConf(' class="%s"', 'css');
if (isset($this->conf['sites'][$site])) {
$href = $this->conf['sites'][$site]['url'];
} else {
return $text;
}
// old form where page is at end,
// or new form with %s placeholder for sprintf()?
if (strpos($href, '%s') === false) {
// use the old form
$href = $href . $page;
} else {
// use the new form
$href = sprintf($href, $page);
}
$output = '';
$contenu = file_get_contents($href);
$tab_matches='';
preg_match($this->conf['sites'][$site]['preg'], $contenu, $tab_matches);
$tab_encodage='';
preg_match('/<meta +http-equiv="Content-Type" +content="text\/html; *charset=(.+)"\/>/Ui', $contenu, $tab_encodage);
if (preg_match('/^(?:iso-8859-1|iso-8859-15)$/i', $this->conf['encodage']) && preg_match('/utf-8/i', $tab_encodage[1])) {
$output = utf8_decode($tab_matches[1]);
} else {
$output = $tab_matches[1];
}
return $output;
}
}
?>
/trunk/api/text/wiki_papyrus/Render/Xhtml/Categorie.php
New file
0,0 → 1,116
<?php
 
class Text_Wiki_Render_Xhtml_Categorie extends Text_Wiki_Render {
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// Initialisation des variables
$sortie = '';
if (isset($options['mots'])) {
$mots = $options['mots'];
} else {
return '<p>'.' Aucune catégorie passé en paramêtre! '.'</p>';
}
// Récupération des infos
$tab_mots = explode(',', $mots);
for ($i = 0; $i < count($tab_mots); $i++) {
// Suppression des espaces, tabulations... en début et fin de chaine
$tab_mots[$i] = trim($tab_mots[$i]);
}
$aso_info_menu = GEN_lireInfoMenuCategorie($GLOBALS['_GEN_commun']['pear_db'], $tab_mots);
// Formatage des infos en XHTML
$sortie .= '<ul class="page_liste">'."\n";
foreach ($aso_info_menu as $id_menu => $un_menu) {
// Création de l'url
$une_url =& new Pap_URL();
$une_url->setId($id_menu);
$sortie .= '<li>'."\n";
// Affichage de l'auteur(s)
$sortie .= '<span class="page_auteur"> '.$un_menu->gm_auteur.'</span>';
$sortie .= '<span class="page_separateur_auteur"> - </span>';
// Affichage du titre
$sortie .= '<a href="'.$une_url->getURL().'">';
$sortie .= '<span class="page_titre"> '.$un_menu->gm_titre.'</span>';
$sortie .= '</a>';
$sortie .= '<span class="page_separateur_titre"> - </span>';
// Affichage de l'horaire de la création de la page
if (($heure = date('G', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_creation_heure">'.$heure.'</span>';
$sortie .= '<span class="page_separateur_heure">:</span>';
$minute = date('i', strtotime($un_menu->gm_date_creation));
$sortie .= '<span class="page_creation_minute">'.$minute.'</span>';
if (($seconde = date('s', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_separateur_heure">:</span>';
$sortie .= '<span class="page_creation_seconde">'.$seconde.'</span>';
}
}
$sortie .= '<span class="page_separateur_date_heure"> - </span>'."\n";
// Affichage de la date de la création de la page
if (($jour = date('d', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_creation_jour"> '.$jour.'</span>';
}
if (($mois = $this->_traduireMois(date('m', strtotime($un_menu->gm_date_creation))) ) != '' ) {
$sortie .= '<span class="page_creation_mois"> '.$mois.'</span>';
}
if (($annee = date('Y', strtotime($un_menu->gm_date_creation)) ) != 0 ) {
$sortie .= '<span class="page_creation_annee"> '.$annee.'</span>';
}
$sortie .= '</li>'."\n";
}
$sortie .= '</ul>'."\n";
return $sortie;
}
function _traduireMois($mois_numerique)
{
switch ($mois_numerique) {
case '01' :
return 'janvier';
case '02' :
return 'février';
case '03' :
return 'mars';
case '04' :
return 'avril';
case '05' :
return 'mai';
case '06' :
return 'juin';
case '07' :
return 'juillet';
case '08' :
return 'août';
case '09' :
return 'septembre';
case '10' :
return 'octobre';
case '11' :
return 'novembre';
case '12' :
return 'décembre';
default:
return '';
}
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Motcles.php
New file
0,0 → 1,65
<?php
// $Id: Motcles.php,v 1.4 2005-07-08 15:14:51 alexandre_tb Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Motcles extends Text_Wiki_Parse {
var $regex = '/\{\{MotCles mots="(.+?)"(?: condition="(ET|OU|et|ou)"|)(?: categorie="(.+?)"|)(?: condition="(ET|OU|et|ou)"|)(?: ordre="(ASC|DESC|asc|desc)"|)\}\}/';
/**
*
* Remplace l'action par une liste des pages contenant les mots clés choisis
* Les options sont:
*
* 'mots' => les mots clés séparés par des virgules
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'mots' => $matches[1],
'condition' => $matches[2],
'categorie' => $matches[3],
'condition2' => $matches[4],
'ordre' => $matches[5]
);
// Les conditions étant écrites en français, ce qui suit les traduit, "et" devient "AND" etc.
if (isset($options['condition'])) {
if ($options['condition'] == 'ET' || $options['condition'] == 'et') {
$options['condition'] = 'AND';
} elseif ($options['condition'] == 'OU' || $options['condition'] == 'ou') {
$options['condition'] = 'OR';
}
}
if (isset($options['condition2'])) {
if ($options['condition2'] == 'ET' || $options['condition2'] == 'et') {
$options['condition2'] = 'AND';
} elseif ($options['condition2'] == 'OU' || $options['condition2'] == 'ou') {
$options['condition2'] = 'OR';
}
}
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Lien.php
New file
0,0 → 1,48
<?php
// $Id: Lien.php,v 1.2 2006-05-10 19:21:47 ddelon Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Lien extends Text_Wiki_Parse {
var $regex = '/\{\{Lien ((?:menu)|(?:site))="((?:\w+)|(?:\d+))" (?:(?:titre)="(.*)")* *\}\}/';
/**
*
* Remplace l'action par une liste des dernières pages modifiées
* Les options sont:
*
* 'site' => le code alphanumérique du ou des sites que l'on veut afficher
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
if (!isset($matches[3])) $matches[3]='';
$options = array(
'niveau' => $matches[1],
'identifiant' => $matches[2],
'titre' => $matches[3]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Redirection.php
New file
0,0 → 1,46
<?php
// $Id: Redirection.php,v 1.1 2005-09-23 13:58:07 ddelon Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Redirection extends Text_Wiki_Parse {
var $regex = '/\{\{Redirection url="(.+?)"\}\}/';
/**
*
* Remplace l'action par une liste des pages contenant les mots clés choisis
* Les options sont:
*
* 'mots' => les mots clés séparés par des virgules
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'url' => $matches[1]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Plan.php
New file
0,0 → 1,51
<?php
// $Id: Plan.php,v 1.2 2005-05-25 14:05:31 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Plan extends Text_Wiki_Parse {
var $regex = '/\{\{Plan site="((?i:[,-]|\w|\s)+)"(?: permalien="(oui|non)"|)\}\}/';
/**
*
* Remplace l'action par une liste des dernières pages modifiées
* Les options sont:
*
* 'site' => le code alphanumérique du ou des sites que l'on veut afficher
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
if (isset($matches[2]) && $matches[2] == 'oui') {
$matches[2] = true;
} else {
$matches[2] = false;
}
$options = array(
'site' => $matches[1],
'permalien' => $matches[2]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Nouveaute.php
New file
0,0 → 1,48
<?php
// $Id: Nouveaute.php,v 1.2 2005-07-08 15:16:54 alexandre_tb Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Nouveaute extends Text_Wiki_Parse {
var $regex = '/\{\{Nouveaute nombre="([1-9][0-9]*)"(?: categorie="(.+?)"|)(?: type="(mineure|majeure)"|)(?: site="((?i:[,-]|\w|\s)+)"|)\}\}/';
/**
*
* Remplace l'action par une liste des dernières pages modifiées
* Les options sont:
*
* 'nombre' => le nombre de dernière page modifiée que l'on veut afficher
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'nombre' => $matches[1],
'categorie' => $matches[2],
'type' => $matches[3],
'site' => $matches[4]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Inclure.php
New file
0,0 → 1,52
<?php
// $Id: Inclure.php,v 1.1 2004-11-26 12:13:28 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Inclure extends Text_Wiki_Parse {
var $regex = '/\{\{inclure page="([A-Za-z0-9_]+)"(?: interwiki="([A-Za-z0-9_]+)"|)\}\}/';
/**
*
* Generates a replacement for the matched standalone interwiki text.
* Token options are:
*
* 'site' => The key name for the Text_Wiki interwiki array map,
* usually the name of the interwiki site.
*
* 'page' => The page on the target interwiki to link to.
*
* 'text' => The text to display as the link.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'page' => $matches[1],
'site' => $matches[2],
'text' => $matches[0]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Categorie.php
New file
0,0 → 1,45
<?php
// $Id: Categorie.php,v 1.2 2005-05-27 13:41:24 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Categorie extends Text_Wiki_Parse {
var $regex = '/\{\{Categorie mots="(.+?)"\}\}/';
/**
*
* Remplace l'action par une liste des pages contenant les mots clés choisis
* Les options sont:
*
* 'mots' => les mots clés séparés par des virgules
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'mots' => $matches[1]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_papyrus/Parse/Syndication.php
New file
0,0 → 1,44
<?php
// $Id: Syndication.php,v 1.4 2006-03-14 16:00:05 florian Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
class Text_Wiki_Parse_Syndication extends Text_Wiki_Parse {
var $regex = '/\{\{Syndication titre="(.+?)" url="(.+?)" nb=(.+?) nouvellefenetre=(.+?) formatdate="(.+?)"\}\}/';
/**
*
* Remplace l'action par une liste des dernières pages modifiées
* Les options sont:
*
* 'site' => le code alphanumérique du ou des sites que l'on veut afficher
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'titre' => $matches[1], 'url' => $matches[2], 'nb' => $matches[3], 'nouvellefenetre' => $matches[4], 'formatdate' => $matches[5],
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_wikini/Render/Xhtml/Table.php
New file
0,0 → 1,94
<?php
 
class Text_Wiki_Render_Xhtml_Table extends Text_Wiki_Render {
var $conf = array(
'css_table' => null,
'css_tr' => null,
'css_th' => null,
'css_td' => null
);
/**
*
* Renders a token into text matching the requested format.
*
* @access public
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*
*/
function token($options)
{
// make nice variable names (type, attr, span)
extract($options);
if (!isset($span)) $span=1;
if (!isset($type)) $type='';
if (!isset($attr)) $attr='';
 
$pad = ' ';
switch ($type) {
case 'table_start':
$css = $this->formatConf(' class="%s"', 'css_table');
return "\n\n".'<table'.$css.' '.trim($attr).'>'."\n";
case 'table_end':
return "</table>\n\n";
case 'row_start':
$css = $this->formatConf(' class="%s"', 'css_tr');
return "$pad<tr$css $attr>\n";
case 'row_end':
return "$pad</tr>\n";
case 'cell_start':
// base html
$html = $pad . $pad;
// is this a TH or TD cell?
if ($attr == 'header') {
// start a header cell
$css = $this->formatConf(' class="%s"', 'css_th');
$html .= "<th$css";
} else {
// start a normal cell
$css = $this->formatConf(' class="%s"', 'css_td');
$html .= "<td$css";
}
// add the column span
if ($span > 1) {
$html .= " colspan=\"$span\"";
}
// add alignment
if ($attr != 'header' && $attr != '') {
$html .= " $attr";
}
// done!
$html .= '>';
return $html;
case 'cell_end':
if ($attr == 'header') {
return "</th>\n";
} else {
return "</td>\n";
}
default:
return '';
}
}
}
?>
/trunk/api/text/wiki_wikini/Wikini.class.php
New file
0,0 → 1,300
<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.3 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of Papyrus. |
// | |
// | Foobar is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or |
// | (at your option) any later version. |
// | |
// | Foobar is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with Foobar; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: Wikini.class.php,v 1.6 2005-04-14 16:36:49 jpm Exp $
/**
* Classe configurant le formatage pour Wikini.
*
* Ce fichier contient une classe configurant les règles de formatage de Wikini.
* Nécessite que l'application appelant ce fichier est précédement inclu le fichier de Pear:
* 'Text/Wiki.php';
*
*@package Text_Wiki
*@subpackage Wikini
//Auteur original :
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author Aucun
*@copyright Tela-Botanica 2000-2004
*@version $Revision: 1.6 $ $Date: 2005-04-14 16:36:49 $
// +------------------------------------------------------------------------------------------------------+
*/
 
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
/**
*
* Parse structured wiki text and render into arbitrary formats such as XHTML.
*
* Cette classe fille permet de configurer les régles de formatage pour Wikini.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
* @package Text_Wiki
* @version 0.23.1
* @license LGPL
*/
class Text_Wikini extends Text_Wiki {
/**
*
* Liste de règles par défaut du format Wikini dans leur ordre d'application au texte
* à transformer.
*
* @access public
*
* @var array
*
*/
var $rules = array(
'Table', // Tableaux
'Code', // Inclusion de code avec coloration syntaxique
'Emphasis', // Italique
'Strong',// Gras
'Freelink', // Nom de Page qui ne sont pas au format Wiki
'Heading', // Titre
'Horiz', // Ligne horizontale
'Interwiki', // Affichage de page d'un autre Wiki. Modifié par rapport à l'original de Text_Wiki
'List', // Affichage de listes. Modifié par rapport à l'original de Text_Wiki
//'Newline', // Nouveau paragraphe.
'Paragraph', // Nouveau paragraphe avec une ligne vide.
'Tighten', // Réduit les lignes vide si on en a 3 ou plus consécutives
'Raw', // Inclusion de HTML et non traitement du contenu par les règles de formatage. Modifié par rapport à l'original de Text_Wiki
'Revise', // Suppression de texte. Modifié par rapport à l'original de Text_Wiki
'Tt', // Texte à espacement fixe
'Url' // Inclusion d'url dont les url d'images
);
/**
*
* The delimiter for token numbers of parsed elements in source text.
*
* @access public
*
* @var string
*
*/
var $delim = 12;
function Text_Wikini($rules = null)
{
//Text_Wiki::Text_Wiki();
if (is_array($rules)) {
$this->rules = $rules;
}
// Nous devons sortir les fichiers de Text_Wiki du dépot Pear car la fonction file_exists de PHP utilisée dans
// la méthode findfile de Text_Wiki renvoie false.
$this->addPath('parse', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Parse/');
$this->addPath('render', $this->fixPath(dirname(__FILE__)) .'../../pear/Text/Wiki/Render/');
// Pour les règles spécifiques à Wikini:
$this->addPath('parse', $this->fixPath(dirname(__FILE__)) . 'Parse/');
$this->addPath('render', $this->fixPath(dirname(__FILE__)) . 'Render/');
}
/**
*
* Renders tokens back into the source text, based on the requested format.
*
* @access public
*
* @param string $format The target output format, typically 'xhtml'.
* If a rule does not support a given format, the output from that
* rule is rule-specific.
*
* @return string The transformed wiki text.
*
*/
function render($format = 'Xhtml')
{
// the rendering method we're going to use from each rule
$format = ucwords(strtolower($format));
// the eventual output text
$output = '';
// when passing through the parsed source text, keep track of when
// we are in a delimited section
$in_delim = false;
// when in a delimited section, capture the token key number
$key = '';
// load the format object
$this->loadFormatObj($format);
// pre-rendering activity
if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
$output .= $this->formatObj[$format]->pre();
}
// load the render objects
foreach (array_keys($this->parseObj) as $rule) {
$this->loadRenderObj($format, $rule);
}
// pass through the parsed source text character by character
$k = strlen($this->source);
for ($i = 0; $i < $k; $i++) {
// the current character
$char = $this->source{$i};
// are alredy in a delimited section?
if ($in_delim) {
// yes; are we ending the section?
if ($char == chr($this->delim)) {
// yes, get the replacement text for the delimited
// token number and unset the flag.
$key = (int)$key;
$rule = null;
if (isset($this->tokens[$key][0])) {
$rule = $this->tokens[$key][0];
}
$opts = null;
if (isset($this->tokens[$key][1])) {
$opts = $this->tokens[$key][1];
}
if (isset($this->renderObj[$rule]) && is_object($this->renderObj[$rule])) {
$output .= $this->renderObj[$rule]->token($opts);
}
$in_delim = false;
} else {
// no, add to the dlimited token key number
$key .= $char;
}
} else {
// not currently in a delimited section.
// are we starting into a delimited section?
if ($char == chr($this->delim)) {
// yes, reset the previous key and
// set the flag.
$key = '';
$in_delim = true;
} else {
// no, add to the output as-is
$output .= $char;
}
}
}
// post-rendering activity
if (isset($this->formatObj[$format]) && is_object($this->formatObj[$format])) {
$output .= $this->formatObj[$format]->post();
}
// return the rendered source text.
return $output;
}
/**
*
* Add a token to the Text_Wiki tokens array, and return a delimited
* token number.
*
* @access public
*
* @param array $options An associative array of options for the new
* token array element. The keys and values are specific to the
* rule, and may or may not be common to other rule options. Typical
* options keys are 'text' and 'type' but may include others.
*
* @param boolean $id_only If true, return only the token number, not
* a delimited token string.
*
* @return string|int By default, return the number of the
* newly-created token array element with a delimiter prefix and
* suffix; however, if $id_only is set to true, return only the token
* number (no delimiters).
*
*/
function addToken($rule, $options = array(), $id_only = false)
{
// increment the token ID number. note that if you parse
// multiple times with the same Text_Wiki object, the ID number
// will not reset to zero.
static $id;
if (! isset($id)) {
$id = 0;
} else {
$id ++;
}
// force the options to be an array
settype($options, 'array');
// add the token
$this->tokens[$id] = array(
0 => $rule,
1 => $options
);
// return a value
if ($id_only) {
// return the last token number
return $id;
} else {
// return the token number with delimiters
return chr($this->delim) . $id . chr($this->delim);
}
}
}
 
// +------------------------------------------------------------------------------------------------------+
// | PIED du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
 
 
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.5 2005/01/20 19:39:43 jpm
* Correction bogue du à la fonction file_exists qui renvoie false pour les fichiers présent dans le dossier Pear /usr/local/lib/php/.
*
* Revision 1.4 2004/12/07 12:17:41 jpm
* Correction message d'erreur.
*
* Revision 1.3 2004/11/25 15:53:24 jpm
* Suppression action inclure, migrer dans Papyrus.
*
* Revision 1.2 2004/11/25 15:36:41 jpm
* Suppression régle Delimiter car problème avec les délimitations de fin de ligne.
*
* Revision 1.1 2004/11/23 17:25:38 jpm
* Début classe PEAR WIKI pour la syntaxe Wikini.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>
/trunk/api/text/wiki_wikini/Parse/Freelink.php
New file
0,0 → 1,106
<?php
// $Id: Freelink.php,v 1.2 2004-11-24 19:06:43 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as a
* wiki freelink, and automatically create a link to that page.
*
* A freelink is any page name not conforming to the standard
* StudlyCapsStyle for a wiki page name. For example, a page normally
* named MyHomePage can be renamed and referred to as ((My Home Page)) --
* note the spaces in the page name. You can also make a "nice-looking"
* link without renaming the target page; e.g., ((MyHomePage|My Home
* Page)). Finally, you can use named anchors on the target page:
* ((MyHomePage|My Home Page#Section1)).
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Freelink extends Text_Wiki_Parse {
/**
*
* Constructor. We override the Text_Wiki_Parse constructor so we can
* explicitly comment each part of the $regex property.
*
* @access public
*
* @param object &$obj The calling "parent" Text_Wiki object.
*
*/
function Text_Wiki_Parse_Freelink(&$obj)
{
parent::Text_Wiki_Parse($obj);
$this->regex =
'/' . // START regex
"\\[\\[" . // double crochet ouvrant
"(" . // START freelink page patter
"[-A-Za-z0-9_+\\/.,;!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character mmais pas les :
")" . // END freelink page pattern
"(" . // START display-name
" " . // un espace pour démarer l'affichage du texte
"[-A-Za-z0-9 _+\\/.,;!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character mmais pas les :
")?" . // END display-name pattern 0 or 1
"()\\]\\]" . // double close-parens
'/'; // END regex
}
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'page' => the wiki page name (e.g., HomePage).
*
* 'text' => alternative text to be displayed in place of the wiki
* page name.
*
* 'anchor' => a named anchor on the target wiki page
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
// use nice variable names
$page = $matches[1];
$text = $matches[2];
// get rid of the leading # from the anchor, if any
//$anchor = substr($matches[3], 1);
// is the page given a new text appearance?
if (trim($text) == '') {
// no
$text = $page;
} else {
// yes, strip the leading | character
$text = substr($text, 1);
}
// set the options
$options = array(
'page' => $page,
'text' => $text,
'anchor' => ''
);
// return a token placeholder
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Heading.php
New file
0,0 → 1,91
<?php
// $Id: Heading.php,v 1.1 2004-11-23 17:24:57 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked to
* be a heading element, as defined by text on a line by itself prefixed
* with a number of plus signs (+). The heading text itself is left in
* the source, but is prefixed and suffixed with delimited tokens marking
* the start and end of the heading.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Heading extends Text_Wiki_Parse {
/**
*
* The regular expression used to parse the source text and find
* matches conforming to this rule. Used by the parse() method.
*
* @access public
*
* @var string
*
* @see parse()
*
*/
var $regex = '/^(={1,6})(.*?)(={1,6})/m';
var $conf = array(
'id_prefix' => 'toc'
);
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* heading text. The text itself is left in the source.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A pair of delimited tokens to be used as a
* placeholder in the source text surrounding the heading text.
*
*/
function process(&$matches)
{
// Tableau permettant l'inversion du nombre de = par rapport au niveau du titre
$titre_niveau = array(6=>1, 5=>2, 4=>3, 3=>4, 2=>5, 1=>6);
// keep a running count for header IDs. we use this later
// when constructing TOC entries, etc.
static $id;
if (! isset($id)) {
$id = 0;
}
$prefix = htmlspecialchars($this->getConf('id_prefix'));
$start = $this->wiki->addToken(
$this->rule,
array(
'type' => 'start',
'level' => $titre_niveau[strlen($matches[1])],
'text' => $matches[2],
'id' => $prefix . $id ++
)
);
$end = $this->wiki->addToken(
$this->rule,
array(
'type' => 'end',
'level' =>$titre_niveau[strlen($matches[1])]
)
);
return $start . $matches[2] . $end . "\n";
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Interwiki.php
New file
0,0 → 1,116
<?php
// $Id: Interwiki.php,v 1.1 2004-11-24 18:34:35 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as
* an Interwiki link. See the regex for a detailed explanation of the
* text matching procedure; e.g., "InterWikiName:PageName".
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Interwiki extends Text_Wiki_Parse {
var $regex = '([A-Za-z0-9_]+):([\/=&~#A-Za-z0-9_]+)';
/**
*
* Parser. We override the standard parser so we can
* find both described interwiki links and standalone links.
*
* @access public
*
* @return void
*
*/
function parse()
{
// described interwiki links
$tmp_regex = '/\[\[' . $this->regex . ' (.+?)\]\]/';
$this->wiki->source = preg_replace_callback(
$tmp_regex,
array(&$this, 'processDescr'),
$this->wiki->source);
// standalone interwiki links
$tmp_regex = '/\[\[' . $this->regex . '\]\]/';
$this->wiki->source = preg_replace_callback(
$tmp_regex,
array(&$this, 'process'),
$this->wiki->source);
}
/**
*
* Generates a replacement for the matched standalone interwiki text.
* Token options are:
*
* 'site' => The key name for the Text_Wiki interwiki array map,
* usually the name of the interwiki site.
*
* 'page' => The page on the target interwiki to link to.
*
* 'text' => The text to display as the link.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function process(&$matches)
{
$options = array(
'site' => $matches[1],
'page' => $matches[2],
'text' => $matches[1].':'.$matches[2]
);
return $this->wiki->addToken($this->rule, $options);
}
/**
*
* Generates a replacement for described interwiki links. Token
* options are:
*
* 'site' => The key name for the Text_Wiki interwiki array map,
* usually the name of the interwiki site.
*
* 'page' => The page on the target interwiki to link to.
*
* 'text' => The text to display as the link.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token to be used as a placeholder in
* the source text, plus any text priot to the match.
*
*/
function processDescr(&$matches)
{
$options = array(
'site' => $matches[1],
'page' => $matches[2],
'text' => $matches[3]
);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Table.php
New file
0,0 → 1,210
<?php
// $Id: Table.php,v 1.3 2006-04-28 12:41:27 florian Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked as a
* set of table rows, where a line start and ends with double-pipes (||)
* and uses double-pipes to separate table cells. The rows must be on
* sequential lines (no blank lines between them) -- a blank line
* indicates the beginning of a new table.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Table extends Text_Wiki_Parse {
/**
*
* The regular expression used to parse the source text and find
* matches conforming to this rule. Used by the parse() method.
*
* @access public
*
* @var string
*
* @see parse()
*
*/
var $regex = '/\n(\[\|(.*)\n)(.+)(\n\|\])/Ums';
/**
*
* Generates a replacement for the matched text.
*
* Token options are:
*
* 'type' =>
* 'table_start' : the start of a bullet list
* 'table_end' : the end of a bullet list
* 'row_start' : the start of a number list
* 'row_end' : the end of a number list
* 'cell_start' : the start of item text (bullet or number)
* 'cell_end' : the end of item text (bullet or number)
*
* 'cols' => the number of columns in the table (for 'table_start')
*
* 'rows' => the number of rows in the table (for 'table_start')
*
* 'span' => column span (for 'cell_start')
*
* 'attr' => column attribute flag (for 'cell_start')
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A series of text and delimited tokens marking the different
* table elements and cell text.
*
*/
function process(&$matches)
{
// our eventual return value
$return = '';
// the number of columns in the table
$num_cols = 0;
// the number of rows in the table
$num_rows = 0;
// rows are separated by newlines in the matched text
$rows = explode("\n", $matches[3]);
// loop through each row
foreach ($rows as $row) {
// increase the row count
$num_rows ++;
// cells are separated by double-pipes
$cell = explode("|", $row);
// get the number of cells (columns) in this row
$last = count($cell) - 1;
// is this more than the current column count?
// (we decrease by 1 because we never use cell zero)
if ($last - 1 > $num_cols) {
// increase the column count
$num_cols = $last - 1;
}
// Les attributs de la ligne
$morceaux='';
if (preg_match('/^!(.*)!$/U', $cell[0], $morceaux)) {
$attr = $morceaux[1];
} else {
$attr = '';
}
// start a new row
$return .= $this->wiki->addToken(
$this->rule,
array( 'type' => 'row_start',
'attr' => $attr,
'span' => 1)
);
// ignore cell zero, and ignore the "last" cell; cell zero
// is before the first double-pipe, and the "last" cell is
// after the last double-pipe. both are always empty.
for ($i = 1; $i < $last; $i ++) {
// if there is no content at all, then it's an instance
// of two sets of || next to each other, indicating a
// span.
if ($cell[$i] == '') {
continue;
} else {
// this cell has content.
// find any special "attr"ibute cell markers
if (substr($cell[$i], 0, 1) == ' ' && substr($cell[$i], -1, 1) != ' ') {
// right-align
$attr = 'align="right"';
$cell[$i] = substr($cell[$i], 1);
} elseif (substr($cell[$i], 0, 1) == ' ' && substr($cell[$i], -1, 1) == ' ') {
// center-align
$attr = 'align="center"';
$cell[$i] = substr(substr($cell[$i], 1), 0, -1);
} elseif (substr($cell[$i], 0, 1) != ' ' && substr($cell[$i], -1, 1) == ' ') {
// left-align
$attr = 'align="left"';
$cell[$i] = substr($cell[$i], 0, -1);
} else {
$attr = null;
}
if (substr($cell[$i], 0, 1) == '!') {
// Les attributs de la cellule
preg_match('/^!(.*)!(.*)$/U', $cell[$i], $morceaux);
$attr .= ' '.$morceaux[1];
$cell[$i] = $morceaux[2];
}
// start a new cell...
$return .= $this->wiki->addToken(
$this->rule,
array (
'type' => 'cell_start',
'attr' => $attr,
'span' => 1
),
false
);
// ...add the content...
$return .= trim($cell[$i]);
// ...and end the cell.
$return .= $this->wiki->addToken(
$this->rule,
array (
'type' => 'cell_end',
'attr' => $attr
),
false
);
}
}
// end the row
$return .= $this->wiki->addToken(
$this->rule,
array('type' => 'row_end')
);
}
// wrap the return value in start and end tokens
$return =
$this->wiki->addToken(
$this->rule,
array(
'type' => 'table_start',
'rows' => $num_rows,
'cols' => $num_cols,
'attr' => $matches[2]
)
)
. $return .
$this->wiki->addToken(
$this->rule,
array(
'type' => 'table_end'
)
);
// we're done!
return "\n$return\n\n";
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Tt.php
New file
0,0 → 1,69
<?php
 
/**
*
* Find source text marked for teletype (monospace).
*
* Defined by text surrounded by two curly braces. On parsing, the text
* itself is left in place, but the starting and ending instances of
* curly braces are replaced with tokens.
*
* Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* teletype text. The text itself is left in the source.
*
*
* $Id: Tt.php,v 1.1 2004-11-23 17:24:57 jpm Exp $
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Tt extends Text_Wiki_Parse {
/**
*
* The regular expression used to parse the source text.
*
* @access public
*
* @var string
*
* @see parse()
*
*/
var $regex = "/##({*?.*}*?)##/U";
/**
*
* Generates a replacement for the matched text.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A pair of delimited tokens to be used as a
* placeholder in the source text surrounding the teletype text.
*
*/
function process(&$matches)
{
$start = $this->wiki->addToken(
$this->rule, array('type' => 'start')
);
$end = $this->wiki->addToken(
$this->rule, array('type' => 'end')
);
return $start . $matches[1] . $end;
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Raw.php
New file
0,0 → 1,55
<?php
// $Id: Raw.php,v 1.1 2004-11-23 17:24:57 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki rule to find sections of the source
* text that are not to be processed by Text_Wiki. These blocks of "raw"
* text will be rendered as they were found.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Raw extends Text_Wiki_Parse {
/**
*
* The regular expression used to find source text matching this
* rule.
*
* @access public
*
* @var string
*
*/
var $regex = '/""(.*)""/U';
/**
*
* Generates a token entry for the matched text. Token options are:
*
* 'text' => The full matched text.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token number to be used as a placeholder in
* the source text.
*
*/
function process(&$matches)
{
$options = array('text' => $matches[1]);
return $this->wiki->addToken($this->rule, $options);
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Code.php
New file
0,0 → 1,75
<?php
// $Id: Code.php,v 1.1 2004-11-24 19:43:09 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find sections marked as code
* examples. Blocks are marked as the string <code> on a line by itself,
* followed by the inline code example, and terminated with the string
* </code> on a line by itself. The code example is run through the
* native PHP highlight_string() function to colorize it, then surrounded
* with <pre>...</pre> tags when rendered as XHTML.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Code extends Text_Wiki_Parse {
/**
*
* The regular expression used to find source text matching this
* rule.
*
* @access public
*
* @var string
*
*/
var $regex = '/^(%%\((\w*?)\))(.+?)(%%)(\s|$)/Umsi';
/**
*
* Generates a token entry for the matched text. Token options are:
*
* 'text' => The full matched text, not including the <code></code> tags.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return A delimited token number to be used as a placeholder in
* the source text.
*
*/
function process(&$matches)
{
if ($matches[2] == '') {
$code = $this->wiki->addToken(
$this->rule,
array(
'text' => $matches[3],
'attr' => array('type' => '')
)
);
} else {
$code = $this->wiki->addToken(
$this->rule,
array(
'text' => $matches[3],
'attr' => array('type' => $matches[2])
)
);
}
return $code . $matches[5];
}
}
?>
/trunk/api/text/wiki_wikini/Parse/Revise.php
New file
0,0 → 1,84
<?php
// $Id: Revise.php,v 1.1 2004-11-23 17:24:57 jpm Exp $
 
 
/**
*
* This class implements a Text_Wiki_Parse to find source text marked for
* revision.
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @package Text_Wiki
*
*/
 
class Text_Wiki_Parse_Revise extends Text_Wiki_Parse {
/**
*
* The regular expression used to parse the source text and find
* matches conforming to this rule. Used by the parse() method.
*
* @access public
*
* @var string
*
* @see parse()
*
*/
var $regex = "/\@\@({*?.*}*?)\@\@/U";
/**
*
* Config options.
*
* @access public
*
* @var array
*
*/
var $conf = array(
'delmark' => '---',
'insmark' => '+++'
);
/**
*
* Generates a replacement for the matched text. Token options are:
*
* 'type' => ['start'|'end'] The starting or ending point of the
* inserted text. The text itself is left in the source.
*
* @access public
*
* @param array &$matches The array of matches from parse().
*
* @return string A pair of delimited tokens to be used as a
* placeholder in the source text surrounding the teletype text.
*
*/
function process(&$matches)
{
$output = '';
$output .= $this->wiki->addToken(
$this->rule, array('type' => 'del_start')
);
$output .= $matches[1];
$output .= $this->wiki->addToken(
$this->rule, array('type' => 'del_end')
);
return $output;
}
}
?>