[SPIP Zone] r3529 - in /_plugins_/_contenu_editorial_/convertisseur: ./ exec/ exec/convertisseur.php img_pack/ img_pack/icon.png inc_convertisseur.php lang/ lang/convertisseur_fr.php plugin.xml

Author: erational@erational.org
Date: Thu Jun 8 19:31:43 2006
New Revision: 3529

Log:
un plug-in pour convertir des formats wiki, BBcode, ... et le format SPIP. Il est possible d'ajouter d'autres formats.(ce plug-in peut aider à faciliter les imports des notices venant de wiki du trac).

reste à caler et optimiser les regex.

Added:
    _plugins_/_contenu_editorial_/convertisseur/
    _plugins_/_contenu_editorial_/convertisseur/exec/
    _plugins_/_contenu_editorial_/convertisseur/exec/convertisseur.php
    _plugins_/_contenu_editorial_/convertisseur/img_pack/
    _plugins_/_contenu_editorial_/convertisseur/img_pack/icon.png (with props)
    _plugins_/_contenu_editorial_/convertisseur/inc_convertisseur.php
    _plugins_/_contenu_editorial_/convertisseur/lang/
    _plugins_/_contenu_editorial_/convertisseur/lang/convertisseur_fr.php
    _plugins_/_contenu_editorial_/convertisseur/plugin.xml

Added: _plugins_/_contenu_editorial_/convertisseur/exec/convertisseur.php

--- _plugins_/_contenu_editorial_/convertisseur/exec/convertisseur.php (added)
+++ _plugins_/_contenu_editorial_/convertisseur/exec/convertisseur.php Thu Jun 8 19:31:43 2006
@@ -0,0 +1,174 @@
+<?php
+
+// -------------------------------
+// Main
+// ------------------------------
+function exec_convertisseur(){
+ include_spip("inc/presentation");
+ global $spip_lang_right;
+
+ $conv_in = "";
+ $conv_out = "";
+ $log = "";
+ $format = "";
+
+ // check rights (utile ?)
+ global $connect_statut;
+ global $connect_toutes_rubriques;
+ if ($connect_statut != '0minirezo') {
+ debut_page(_T("convertisseur:convertir_titre"), "naviguer", "plugin");
+ echo _T('avis_non_acces_page');
+ fin_page();
+ exit;
+ }
+
+ // ---------------------------------------------------------------------------
+ // Definition des regex pour les convertions
+ // ---------------------------------------------------------------------------
+ $conv_formats = array();
+
+ // Convertion MoinWiki -> SPIP
+ // ref. syntaxe: http://zone.spip.org/trac/spip-zone/wiki/WikiFormatting
+ // ref. syntaxe: http://moinmoin.wikiwikiweb.de/HelpOnFormatting?highlight=(formatting)
+ $conv_formats['MoinWiki_SPIP'] = array(
+ "pattern" => array(
+ 'code' => "{{{([^}}}]*)}}}", // FIXME si } dans {{{ }}}
+ 'list' => "\*([^\*]*)",
+ 'bold' => "'''([^'']*)'''",
+ 'i' => "''([^'']*)''",
+ 'under' => "__([^\_]*)__",
+ 'del' => "~~([^\~]*)~~",
+ 'h4' => "==== ([^\====]*) ====",
+ 'h3' => "=== ([^\===]*) ===",
+ 'h2' => "== ([^\==]*) ==",
+ 'h' => "= ([^\=]*) =",
+ 'link2' => "\\[([^\\[]*) ([^(\\[| )]*)\\]", // FIXME si plusieurs espaces blanc
+ 'cell' => "\|\|([^\|]*)\|\|",
+ ),
+ "replacement" => array(
+ 'code' => "<code>\\1</code>",
+ 'list' => "-\\1",
+ 'bold' => "{{\\1}}",
+ 'i' => "{\\1}",
+ 'under' => "<span class='underline'>\\1</span",
+ 'del' => '<del>\\1</del>',
+ 'h4' => "{{{\\1}}}",
+ 'h3' => "{{{\\1}}}",
+ 'h2' => "{{{\\1}}}",
+ 'h' => "{{{\\1}}}",
+ 'link2' => "[\\2->\\1]",
+ 'cell' => "|\\1|",
+ )
+ );
+
+ // Convertion BBcode -> SPIP
+ // ref. syntaxe: http://en.wikipedia.org/wiki/BBCode
+ // voir aussi la version filtre: http://www.spip-contrib.net/Du-BBcode-dans-SPIP
+ // question: detecter si barre enrichie pour adopter la syntaxte etendue ?
+ $conv_formats['BBcode_SPIP'] = array(
+ "pattern" => array(
+ 'url' => "\\[url]([^\\[]*)\\[/url\\]",
+ 'url2' => "\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]",
+ 'email' => "\\[email\\]([^\\[]*)\\[/email\\]",
+ 'email2'=> "\\[email=([^\\[]*)\\]([^\\[]*)\\[/email\\]",
+ 'color' => "\\[color=([^\\[]*)\\]([^\\[]*)\\[/color\\]",
+ 'size' => "\\[size=([^\\[]*)\\]([^\\[]*)\\[/size\\]",
+ //'list' => "!\[list\](.+)\[/list\]!Umi",
+ //'list2' => "!\[\*\](.+)(?=(\[\*\]|</ul>))!Umi",
+ 'code' => "\\[code]([^\\[]*)\\[/code\\]",
+ 'quote' => "\\[quote]([^\\[]*)\\[/quote\\]",
+ 'b' => "\\[b]([^\\[]*)\\[/b\\]",
+ 'i' => "\\[i]([^\\[]*)\\[/i\\]",
+ 'center'=> "\\[center]([^\\[]*)\\[/center\\]",
+ 'img' => "\\[img]([^\\[]*)\\[/img\\]",
+ ),
+ "replacement" => array(
+ 'url' => "[\\1->\\1]",
+ 'url2' => "[\\2->\\1]",
+ 'email' => "[\\1->mailto:\\1]",
+ 'email2'=> "[\\2->mailto:\\1]",
+ 'color' => "<span style=\"color:\\1\">\\2</span>",
+ 'size' => "<span style=\"font-size:\\1px\">\\2</span>",
+ //'list' => "<ul> $1 </ul>",
+ //'list2' => "<li>$1</li>",
+ 'code' => "<code>\\1</code>",
+ 'quote' => "<quote>\\1</quote>",
+ 'b' => "{{\\1}}",
+ 'i' => "{\\1}",
+ 'center' => "<div style=\"text-align:center:\\1\">\\2</div>",
+ 'img' => "<img src=\"\\1\" alt='' />",
+ )
+ );
+
+ // Convertion SPIP -> txt
+ $conv_formats['SPIP_txt'] = array(
+ "pattern" => array(
+ 'h' => "{{{([^}}}]*)}}}",
+ 'b' => "{{([^}}]*)}}",
+ 'i' => "{([^}]*)}",
+ 'url' => "\\[([^\\[]*)->([^(\\[| )]*)\\]",
+ ),
+ "replacement" => array(
+ 'h' => "\\1\n",
+ 'b' => "* \\1 *",
+ 'i' => "\\1",
+ 'url' => "\\1 (\\2)",
+ )
+ );
+
+ // ---------------------------------------------------------------------------
+ // Action ?
+ // ---------------------------------------------------------------------------
+ if (isset($_POST['conv_in'])) {
+ $conv_in = $_POST['conv_in'];
+ if (isset($_POST['format'])) {
+ $conv_out = $_POST['conv_in'];
+ $format = trim(strip_tags($_POST['format']));
+ if (isset($conv_formats[$format])) {
+ // on convertit (en avant les regex!)
+ foreach($conv_formats[$format]['pattern'] as $key=>$pattern) {
+ $replacement = $conv_formats[$format]['replacement'][$key];
+ $conv_out = eregi_replace($pattern, $replacement, $conv_out);
+ }
+ } else {
+ $log = "<span style='color:red'>"._T("convertisseur:unknown_format")."</span>";
+ }
+ }
+ }
+
+ // ---------------------------------------------------------------------------
+ // HTML output
+ // ---------------------------------------------------------------------------
+ debut_page(_T("convertisseur:convertir_titre"), "naviguer", "plugin");
+ debut_gauche();
+ debut_boite_info();
+ echo _T("convertisseur:convertir_desc");
+ fin_boite_info();
+
+ debut_droite();
+ echo $log;
+ echo "<form method='post'>\n";
+ if ($conv_out!="") {
+ $conv_out = str_replace("</textarea>",'&lt;/textarea&gt;',$conv_out);
+ echo "<div style='background-color:#E6ECF9;padding:8px 3px;margin-bottom:5px'>"._T("convertisseur:convertir_en");
+ if (isset($conv_formats[$format])) echo "<strong>"._T("convertisseur:$format")."</strong>\n";
+ echo "<textarea name='conv_out' cols='55' rows='12'>$conv_out</textarea><br />\n";
+ echo "</div>\n";
+ }
+ $conv_in = str_replace("</textarea>",'&lt;/textarea&gt;',$conv_in);
+ echo "<textarea name='conv_in' cols='55' rows='12'>$conv_in</textarea><br />\n";
+ echo _T("convertisseur:from");
+ echo "<select name='format'>\n";
+ foreach ($conv_formats as $k=>$val) {
+ if ($format==$k) $selected = " selected='selected'";
+ else $selected = "";
+ echo "<option value='$k'$selected>"._T("convertisseur:$k")."</option>\n";
+ }
+ echo "</select>\n";
+ echo "<input type='submit' value='". _T("convertisseur:convertir")."'>\n";
+ echo "</form>\n";
+
+
+ fin_page();
+}
+?>

Added: _plugins_/_contenu_editorial_/convertisseur/img_pack/icon.png

Binary file - no diff available.

Propchange: _plugins_/_contenu_editorial_/convertisseur/img_pack/icon.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: _plugins_/_contenu_editorial_/convertisseur/inc_convertisseur.php

--- _plugins_/_contenu_editorial_/convertisseur/inc_convertisseur.php (added)
+++ _plugins_/_contenu_editorial_/convertisseur/inc_convertisseur.php Thu Jun 8 19:31:43 2006
@@ -0,0 +1,18 @@
+<?php
+
+$p=explode(basename(_DIR_PLUGINS)."/",str_replace('\\','/',realpath(dirname(__FILE__))));
+define('_DIR_PLUGIN_CONVERTISSEUR',(_DIR_PLUGINS.end($p)));
+
+// ajout bouton ds interface admin
+function Convertisseur_ajouterBoutons($boutons_admin) {
+ // si on est admin
+ if ($GLOBALS['connect_statut'] == "0minirezo") { // rendre aussi accessible aux redacteurs ??
+ $boutons_admin['naviguer']->sousmenu['convertisseur']= new Bouton(
+ '../'._DIR_PLUGIN_CONVERTISSEUR.'/img_pack/icon.png', // icone
+ _L("convertisseur:convertir_titre") // titre
+ );
+ }
+ return $boutons_admin;
+}
+
+?>

Added: _plugins_/_contenu_editorial_/convertisseur/lang/convertisseur_fr.php

--- _plugins_/_contenu_editorial_/convertisseur/lang/convertisseur_fr.php (added)
+++ _plugins_/_contenu_editorial_/convertisseur/lang/convertisseur_fr.php Thu Jun 8 19:31:43 2006
@@ -0,0 +1,23 @@
+<?php
+

[... 64 lines stripped ...]