utilisation du miniwiki partout #641
authorx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 13 Mar 2007 21:45:10 +0000 (21:45 +0000)
committerx2001corpet <x2001corpet@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 13 Mar 2007 21:45:10 +0000 (21:45 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1571 839d8a87-29fc-0310-9880-83ba4fa771e5

classes/miniwiki.php
include/massmailer.inc.php
include/newsletter.inc.php
modules/events.php
modules/xnetgrp.php
templates/xnetgrp/announce-rss.tpl
templates/xnetgrp/form.announce.tpl
upgrade/0.9.14/04_newsletter.sql [new file with mode: 0644]

index 7f0b76e..d17f097 100644 (file)
@@ -20,7 +20,7 @@ class MiniWiki
         MiniWiki::Markup(0, "/(\r\n|\r([^\n]))/", "\n$2", "\n$2");
                 
         // retours à la ligne avec \\
-        MiniWiki::Markup(1, "/\\\\(?".">(\\\\*))\n/e", "str_repeat('<br />\n',strlen('$1'))", "str_repeat('\\\\n',strlen('$1'))");
+        MiniWiki::Markup(1, "/\\\\(?".">(\\\\*))\n/e", "str_repeat('<br />\n',strlen('$1'))", "str_repeat('\n',strlen('$1'))");
         
         // bold, italic and others
         // ''' bold '''
@@ -38,12 +38,12 @@ class MiniWiki
         // {+ underline +}
         MiniWiki::Markup(8, "/{+(.*?)+}/",'<ins>$1</ins>','_$1_');
         // {- strikeout -}
-        MiniWiki::Markup(9, "/{-(.*?)-}/",'<del>$1</del>','_$1_');
+        MiniWiki::Markup(9, "/{-(.*?)-}/",'<del>$1</del>','-$1-');
         // [+ big +] [++ bigger ++] [+++ even bigger +++] ...
         MiniWiki::Markup(10, '/\\[(([-+])+)(.*?)\\1\\]/e',"'<span style=\'font-size:'.(round(pow(6/5,$2strlen('$1'))*100,0)).'%\'>$3</span>'", "'$3'");
         
         // ----- <hr/>
-        MiniWiki::Markup(11, '/(\n|^)----+/s', '$1<hr/>', '$1----');
+        MiniWiki::Markup(11, '/(\n|^)----+/s', '$1<hr/>', '$1----'."\n");
         // titles
         MiniWiki::Markup(12, '/(\n|^)(!+)([^\n]*)/se', "'$1<h'.strlen('$2').'>$3</h'.strlen('$2').'>'", "'$1$3'");
         
@@ -53,10 +53,10 @@ class MiniWiki
         MiniWiki::Markup(14, "/(^|\n)#(([^\n]*(\n|$))(#[^\n]*(\n|$))*)/se", "'<ol><li>'.str_replace(\"\\n#\",'</li><li>','$2').'</li></ol>'", "$0");
         
         // links
-        MiniWiki::Markup(15, '/((?:https?|ftp):\/\/(?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/ui', '<a href="\\0">\\0</a>', '\\0');
-        MiniWiki::Markup(16, '/(\s|^|\\[\\[)www\.((?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/iu', '\\1<a href="http://www.\\2">www.\\2</a>', 'http://www.\\2');
-        MiniWiki::Markup(17, '/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '<a href="mailto:\\0">\\0</a>', '\\0');
-        MiniWiki::Markup(18, '/\\[\\[\\s*<a href="([^>]*)">.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '<a href="\\1">\\2</a>', '\\2 (\\1)');
+        MiniWiki::Markup(15, '/((?:https?|ftp):\/\/(?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/ui', '<a href="\\0">\\0</a>', '[\\0]');
+        MiniWiki::Markup(16, '/(\s|^|\\[\\[)www\.((?:\.*,*[\w@~%$£µ&i#\-+=_\/\?;])*)/iu', '\\1<a href="http://www.\\2">www.\\2</a>', '[http://www.\\2]');
+        MiniWiki::Markup(17, '/(?:mailto:)?([a-z0-9.\-+_]+@([\-.+_]?[a-z0-9])+)/i', '<a href="mailto:\\0">\\0</a>', '[mailto:\\0]');
+        MiniWiki::Markup(18, '/\\[\\[\\s*<a href="([^>]*)">.*<\/a>\\s*\|([^\\]]+)\\]\\]/i', '<a href="\\1">\\2</a>', '\\2 [\\1]');
         
         // paragraphs and empty lines
         MiniWiki::Markup(19, "/\n\n/", '</p><p>', "\n\n");
@@ -64,17 +64,79 @@ class MiniWiki
         MiniWiki::Markup(21, "/^.*<\/p><p>.*$/s", "<p>$0</p>", "$0");
     }
 
-    public static function WikiToHTML($wiki, $notitle = false) {
-        if ($notitle) {
+    public static function WikiToHTML($wiki, $title = false) {
+        if (!$title) {
             $oldrule12 = MiniWiki::$replacementHTML[12];
             MiniWiki::$replacementHTML[12] = "'$0'";
         }
-        $html = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementHTML, htmlentities($wiki));
-        if ($notitle) {
+        $html = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementHTML, utf8_encode(htmlentities(utf8_decode(trim($wiki)))));
+        if (!$title) {
             MiniWiki::$replacementHTML[12] = $oldrule12;
         }
         return $html;
     }
+    
+    private function justify($text,$n)
+    {
+        $arr = explode("\n",wordwrap($text,$n));
+        $arr = array_map('trim',$arr);
+        $res = '';
+        foreach ($arr as $key => $line) {
+            $nxl       = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
+            $nxl_split = preg_split('! +!',$nxl);
+            $nxw_len   = count($nxl_split) ? strlen($nxl_split[0]) : 0;
+            $line      = trim($line);
+        
+            if (strlen($line)+1+$nxw_len < $n) {
+                $res .= "$line\n";
+                continue;
+            }
+            
+            if (preg_match('![.:;]$!',$line)) {
+                $res .= "$line\n";
+                continue;
+            }
+        
+            $tmp   = preg_split('! +!',trim($line));
+            $words = count($tmp);
+            if ($words <= 1) {
+                $res .= "$line\n";
+                continue;
+            }
+        
+            $len   = array_sum(array_map('strlen',$tmp));
+            $empty = $n - $len;
+            $sw    = floatval($empty) / floatval($words-1);
+            
+            $cur = 0;
+            $l   = '';
+            foreach ($tmp as $word) {
+                $l   .= $word;
+                $cur += $sw + strlen($word);
+                $l    = str_pad($l,intval($cur+0.5));
+            }
+            $res .= trim($l)."\n";
+        }
+        return trim($res);
+    }
+    
+
+    public static function WikiToText($wiki, $just=false, $indent=0, $width=68, $title=false) {
+        if (!$title) {
+            $oldrule12 = MiniWiki::$replacementHTML[12];
+            MiniWiki::$replacementHTML[12] = "'$0'";
+        }
+        $text = preg_replace(MiniWiki::$patternsWiki, MiniWiki::$replacementText, trim($wiki));
+        if (!$title) {
+            MiniWiki::$replacementHTML[12] = $oldrule12;
+        }
+        $text = $just ? MiniWiki::justify($text,$width-$indent) : wordwrap($text,$width-$indent);
+        if($indent) {
+            $ind = str_pad('',$indent);
+            $text = $ind.str_replace("\n","\n$ind",$text);
+        }
+        return $text;
+    }
 };
 
 MiniWiki::init();
index fce33ca..1ac9aea 100644 (file)
@@ -218,93 +218,15 @@ abstract class MassMailer
 // }}}
 // {{{ Functions
 
-function justify($text,$n)
-{
-    $arr = explode("\n",wordwrap($text,$n));
-    $arr = array_map('trim',$arr);
-    $res = '';
-    foreach ($arr as $key => $line) {
-    $nxl       = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
-    $nxl_split = preg_split('! +!',$nxl);
-    $nxw_len   = count($nxl_split) ? strlen($nxl_split[0]) : 0;
-    $line      = trim($line);
-
-    if (strlen($line)+1+$nxw_len < $n) {
-        $res .= "$line\n";
-        continue;
-    }
-    
-    if (preg_match('![.:;]$!',$line)) {
-        $res .= "$line\n";
-        continue;
-    }
-
-    $tmp   = preg_split('! +!',trim($line));
-    $words = count($tmp);
-    if ($words <= 1) {
-        $res .= "$line\n";
-        continue;
-    }
-
-    $len   = array_sum(array_map('strlen',$tmp));
-    $empty = $n - $len;
-    $sw    = floatval($empty) / floatval($words-1);
-    
-    $cur = 0;
-    $l   = '';
-    foreach ($tmp as $word) {
-        $l   .= $word;
-        $cur += $sw + strlen($word);
-        $l    = str_pad($l,intval($cur+0.5));
-    }
-    $res .= trim($l)."\n";
-    }
-    return trim($res);
-}
-
 function format_text($input, $format, $indent = 0, $width = 68)
 {
     if ($format == 'text') {
-        return enriched_to_text($input, false, true, $indent, $width);
+        return MiniWiki::WikiToText($input, true, $indent, $width, "title");
     }
-    return enriched_to_text($input, true);
+    return MiniWiki::WikiToHTML($input, "title");
 }
 
-function enriched_to_text($input,$html=false,$just=false,$indent=0,$width=68)
-{
-    $text = trim($input);
-    if ($html) {
-        $text = htmlspecialchars($text);
-        $text = str_replace('[b]','<strong>', $text);
-        $text = str_replace('[/b]','</strong>', $text);
-        $text = str_replace('[i]','<em>', $text);
-        $text = str_replace('[/i]','</em>', $text);
-        $text = str_replace('[u]','<span style="text-decoration: underline">', $text);
-        $text = str_replace('[/u]','</span>', $text);
-        $text = preg_replace("!(\\s*\n)*\[title\]!",'<h1>',$text);
-        $text = preg_replace("!\[\/title\](\\s*\n)*!", '</h1>',$text);
-        $text = preg_replace("!(\\s*\n)*\[subtitle\]!",'<h2>',$text);
-        $text = preg_replace("!\[\/subtitle\](\\s*\n)*!",'</h2>',$text);
-
-        require_once('url_catcher.inc.php');
-        $text = url_catcher($text);
-        return nl2br($text);
-    } else {
-        $text = preg_replace('!\[\/?b\]!','*',$text);
-        $text = preg_replace('!\[\/?u\]!','_',$text);
-        $text = preg_replace('!\[\/?i\]!','/',$text);
-        $text = preg_replace('!\[\/?title\]!','***', $text);
-        $text = preg_replace('!\[\/?subtitle\]!','**', $text);
-        $text = preg_replace('!(((https?|ftp)://|www\.)[^\r\n\t ]*)!','[\1]', $text);
-        $text = preg_replace('!(([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)(?:\?[^\r\n\t ]*)?)!','[mailto:\1]', $text);
-        $text = $just ? justify($text,$width-$indent) : wordwrap($text,$width-$indent);
-        if($indent) {
-            $ind = str_pad('',$indent);
-            $text = $ind.str_replace("\n","\n$ind",$text);
-        }
-        return $text;
-    }
-}
+// function enriched_to_text($input,$html=false,$just=false,$indent=0,$width=68)
 
 // }}}
 
index 386ef16..63025a3 100644 (file)
@@ -226,8 +226,8 @@ class NLArticle
     public function toText()
     {
         $title = '*'.$this->title().'*';
-        $body  = enriched_to_text($this->_body,false,true);
-        $app   = enriched_to_text($this->_append,false,false,4);
+        $body  = MiniWiki::WikiToText($this->_body,true);
+        $app   = MiniWiki::WikiToText($this->_append,false,4);
         return trim("$title\n\n$body\n\n$app")."\n";
     }
 
@@ -237,8 +237,8 @@ class NLArticle
     public function toHtml()
     {
         $title = "<h2 class='xorg_nl'><a id='art{$this->_aid}'></a>".pl_entities($this->title()).'</h2>';
-        $body  = enriched_to_text($this->_body,true);
-        $app   = enriched_to_text($this->_append,true);
+        $body  = MiniWiki::WikiToHTML($this->_body);
+        $app   = MiniWiki::WikiToHTML($this->_append);
     
         $art   = "$title\n";
         $art  .= "<div class='art'>\n$body\n";
@@ -255,7 +255,7 @@ class NLArticle
 
     public function check()
     {
-        $text = enriched_to_text($this->_body);
+        $text = MiniWiki::WikiToText($this->_body);
         $arr  = explode("\n",wordwrap($text,68));
         $c    = 0;
         foreach ($arr as $line) {
index 20a0f56..ff0ca57 100644 (file)
@@ -264,14 +264,13 @@ class EventsModule extends PLModule
 
     function handler_preview(&$page)
     {
-        require_once('url_catcher.inc.php');
         $page->changeTpl('events/preview.tpl', NO_SKIN);
         $texte = Get::v('texte');
         if (!is_utf8($texte)) {
             $texte = utf8_encode($texte);
         }
         if (strpos($_SERVER['HTTP_REFERER'], 'admin') === false) {
-            $texte = url_catcher(pl_entities($texte));
+            $texte = MiniWiki::WikiToHTML($texte);
         }
         $titre = Get::v('titre');
         if (!is_utf8($titre)) {
@@ -308,8 +307,7 @@ class EventsModule extends PLModule
             $action = null;
         }
 
-       require_once('url_catcher.inc.php');
-               $texte_catch_url = url_catcher($texte);
+               $texte_catch_url = MiniWiki::WikiToHTML($texte);
                
         $page->assign('titre', $titre);
         $page->assign('texte', $texte);
index 104a5f0..d4a9612 100644 (file)
@@ -170,9 +170,8 @@ class XnetGrpModule extends PLModule
             $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News",
                               'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml');
         }
-
-        require_once('url_catcher.inc.php');
-        $page->register_modifier('url_catcher', 'url_catcher');
+        
+        $page->register_modifier('url_catcher', array(MiniWiki,'WikiToHTML'));
         $page->assign('articles', $arts);
 
         $page->assign('asso', $globals->asso());
@@ -959,9 +958,8 @@ class XnetGrpModule extends PLModule
     {
         global $globals;
         require_once('rss.inc.php');
-        require_once('url_catcher.inc.php');
         $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false);
-        $page->register_modifier('url_catcher', 'url_catcher');
+        $page->register_modifier('url_catcher', array(MiniWiki,'WikiToHTML'));
 
         if ($uid) {
             $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
@@ -988,6 +986,7 @@ class XnetGrpModule extends PLModule
     {
         global $globals, $platal;
         new_groupadmin_page('xnetgrp/announce-edit.tpl');
+        $page->register_modifier('url_catcher', array(MiniWiki,'WikiToHTML'));
         $page->assign('new', is_null($aid));
         $art = array();
 
@@ -1043,9 +1042,8 @@ class XnetGrpModule extends PLModule
                 $aid = XDB::insertId();
                 if ($art['xorg']) {
                     require_once('validations.inc.php');
-                    require_once('url_catcher.inc.php');
                     $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'],
-                                    url_catcher($art['texte'] . (!empty($art['contact_html']) ? "\n\nContacts :\n" . $art['contact_html'] : "")),
+                                    MiniWiki::WikiToHTML($art['texte'] . (!empty($art['contact_html']) ? "\n\nContacts :\n" . $art['contact_html'] : "")),
                                     $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid'));
                     $article->submit();
                     $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation");
@@ -1113,8 +1111,7 @@ class XnetGrpModule extends PLModule
             }
         } 
 
-        require_once('url_catcher.inc.php');
-        $art['contact_html'] = url_catcher($art['contact_html']);
+        $art['contact_html'] = MiniWiki::WikiToHTML($art['contact_html']);
         $page->assign('art', $art);
     }
 
index b4ab621..5ece500 100644 (file)
@@ -37,7 +37,7 @@
       <title>{$line.titre|strip_tags}</title>
       <guid isPermaLink="false">{$line.id}</guid>
       <link>{#globals.baseurl#}/{$asso.diminutif}/#art{$line.id}</link>
-      <description><![CDATA[{$line.texte|nl2br}{if $line.contacts}<br/><br/><strong>Contacts :</strong><br/>{$line.contacts|url_catcher|nl2br}{/if}]]></description>
+      <description><![CDATA[{$line.texte|url_catcher}{if $line.contacts}<br/><br/><strong>Contacts :</strong><br/>{$line.contacts|url_catcher}{/if}]]></description>
       <author>{$line.prenom} {$line.nom} (X{$line.promo})</author>
       <pubDate>{$line.create_date|rss_date}</pubDate>
     </item>
index cf8f7e7..d1aa617 100644 (file)
@@ -39,7 +39,7 @@
   <tr>
     <td style="padding-bottom: 1em">
       {tidy}
-      {$art.texte|nl2br}
+      {$art.texte|url_catcher|smarty:nodefaults}
       {/tidy}
     </td>
   </tr>
diff --git a/upgrade/0.9.14/04_newsletter.sql b/upgrade/0.9.14/04_newsletter.sql
new file mode 100644 (file)
index 0000000..991e529
--- /dev/null
@@ -0,0 +1,12 @@
+UPDATE newsletter_art SET body =
+REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(body, 
+"[b]", "'''"),
+"[/b]", "'''"),
+"[i]", "''"),
+"[/i]", "''"),
+"[u]", "{+"),
+"[/u]", "+}"),
+"[title]", "\n!"),
+"[/title]", ""),
+"[subtitle]", "\n!!"),
+"[/subtitle]", "");