From 794feea76e0979eba4e125bb91b7ea43680f26e0 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 16 Sep 2007 19:12:44 +0200 Subject: [PATCH] Closes #677: Wiki syntax for announces even after validation, and wiki syntax for group description on xnet Signed-off-by: Florent Bruneau --- htdocs/css/xnet.css | 13 +++++++++++++ include/globals.inc.php.in | 2 +- include/validations/evts.inc.php | 9 ++------- modules/events.php | 17 ++++++----------- modules/profile.php | 2 -- modules/xnetgrp.php | 24 ++++++++++++------------ plugins/modifier.miniwiki.php | 30 ++++++++++++++++++++++++++++++ templates/events/form.tpl | 10 ++++++---- templates/events/index.tpl | 4 ++++ templates/events/preview.tpl | 4 ++-- templates/include/form.valid.evts.tpl | 2 +- templates/profile/profile.tpl | 4 ++-- templates/xnetgrp/announce-rss.tpl | 2 +- templates/xnetgrp/asso.tpl | 4 ++++ templates/xnetgrp/edit.tpl | 14 +++++++++++++- templates/xnetgrp/form.announce.tpl | 10 ++++------ upgrade/0.9.15/04_announces.sql | 6 ++++++ 17 files changed, 107 insertions(+), 50 deletions(-) create mode 100644 plugins/modifier.miniwiki.php create mode 100644 upgrade/0.9.15/04_announces.sql diff --git a/htdocs/css/xnet.css b/htdocs/css/xnet.css index 2513ab9..e181a5a 100644 --- a/htdocs/css/xnet.css +++ b/htdocs/css/xnet.css @@ -68,6 +68,19 @@ h2 { font-size: 115%; } font-style: italic; } +input.error, textarea.error { + background-color: #faa; +} + +input.valid, textarea.valid { + background-color: #afa; +} + +input.warning, textarea.warning { + background-color: #fda; +} + + /*************************************************************************** * DEBUG ***************************************************************************/ diff --git a/include/globals.inc.php.in b/include/globals.inc.php.in index e7f9f55..9bb1b54 100644 --- a/include/globals.inc.php.in +++ b/include/globals.inc.php.in @@ -107,7 +107,7 @@ class PlatalGlobals } if ($gp) { - $res = XDB::query('SELECT a.*, d.nom AS domnom + $res = XDB::query('SELECT a.*, d.nom AS domnom, FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc FROM groupex.asso AS a LEFT JOIN groupex.dom AS d ON d.id = a.dom WHERE diminutif = {?}', $gp); diff --git a/include/validations/evts.inc.php b/include/validations/evts.inc.php index 4a3a0ce..ed22c95 100644 --- a/include/validations/evts.inc.php +++ b/include/validations/evts.inc.php @@ -136,7 +136,7 @@ class EvtReq extends Validate { if (XDB::execute("INSERT INTO evenements SET user_id = {?}, creation_date=NOW(), titre={?}, texte={?}, - peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide')", + peremption={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')", $this->uid, $this->titre, $this->texte, $this->peremption, $this->pmin, $this->pmax)) { $eid = XDB::insertId(); @@ -151,14 +151,9 @@ class EvtReq extends Validate $forlife = get_user_forlife($this->uid); require_once 'banana/forum.inc.php'; $banana = new ForumsBanana($forlife); - $text = strip_tags($this->texte, '


      1. '); - $text = preg_replace(',(.*?),', '$1', $text); - $text = preg_replace('/
      2. /', '* ', $text); - $text = preg_replace(',,i', "\n", $text); - $text = preg_replace("/\n{2,}/", "\n\n", $text); $post = $banana->post($globals->banana->event_forum, $globals->banana->event_reply, - $this->titre, pl_entity_decode($text)); + $this->titre, MiniWiki::wikiToText($this->texte, false, 0, 80)); if ($post != -1) { XDB::execute("UPDATE evenements SET creation_date = creation_date, post_id = {?} diff --git a/modules/events.php b/modules/events.php index 67e6abd..a2f77ba 100644 --- a/modules/events.php +++ b/modules/events.php @@ -100,7 +100,7 @@ class EventsModule extends PLModule return false; } $sql = "SELECT e.id,e.titre,e.texte,e.post_id,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife, - p.x, p.y, p.attach IS NOT NULL AS img + p.x, p.y, p.attach IS NOT NULL AS img, FIND_IN_SET('wiki', e.flags) AS wiki FROM evenements AS e LEFT JOIN evenements_photo AS p ON (e.id = p.eid) INNER JOIN auth_user_md5 AS a ON e.user_id=a.user_id @@ -270,14 +270,11 @@ class EventsModule extends PLModule if (!is_utf8($texte)) { $texte = utf8_encode($texte); } - if (strpos($_SERVER['HTTP_REFERER'], 'admin') === false) { - $texte = MiniWiki::WikiToHTML($texte); - } $titre = Get::v('titre'); if (!is_utf8($titre)) { $titre = utf8_encode($titre); } - $page->assign('texte_html', $texte); + $page->assign('texte', $texte); $page->assign('titre', $titre); header('Content-Type: text/html; charset=utf-8'); } @@ -308,11 +305,8 @@ class EventsModule extends PLModule $action = null; } - $texte_catch_url = MiniWiki::WikiToHTML($texte); - $page->assign('titre', $titre); $page->assign('texte', $texte); - $page->assign('texte_html', $texte_catch_url); $page->assign('promo_min', $promo_min); $page->assign('promo_max', $promo_max); $page->assign('peremption', $peremption); @@ -326,7 +320,6 @@ class EventsModule extends PLModule } elseif ($action && (!trim($texte) || !trim($titre))) { $page->trig("L'article doit avoir un titre et un contenu"); } elseif ($action) { - $texte = $texte_catch_url; require_once 'validations.inc.php'; $evtreq = new EvtReq($titre, $texte, $promo_min, $promo_max, $peremption, $valid_mesg, S::v('uid'), $upload); @@ -397,11 +390,13 @@ class EventsModule extends PLModule } else { $res = XDB::query('SELECT flags FROM evenements WHERE id = {?}', $eid); $flags = new FlagSet($res->fetchOneCell()); + $flags->addFlag('wiki'); if (Post::v('important')) { $flags->addFlag('important'); } else { $flags->rmFlag('important'); } + XDB::execute('UPDATE evenements SET creation_date = creation_date, titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?}, @@ -428,7 +423,6 @@ class EventsModule extends PLModule list($titre, $texte, $peremption, $promo_min, $promo_max, $important, $img) = $res->fetchOneRow(); $page->assign('titre',$titre); $page->assign('texte',$texte); - $page->assign('texte_html', pl_entity_decode($texte)); $page->assign('promo_min',$promo_min); $page->assign('promo_max',$promo_max); $page->assign('peremption',$peremption); @@ -490,7 +484,8 @@ class EventsModule extends PLModule e.promo_min, e.promo_max, FIND_IN_SET('valide', e.flags) AS fvalide, FIND_IN_SET('archive', e.flags) AS farch, - u.promo, u.nom, u.prenom, a.alias AS forlife + u.promo, u.nom, u.prenom, a.alias AS forlife, + FIND_IN_SET('wiki', flags) AS wiki FROM evenements AS e INNER JOIN auth_user_md5 AS u ON(e.user_id = u.user_id) INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie') diff --git a/modules/profile.php b/modules/profile.php index b8237db..2a6f148 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -205,8 +205,6 @@ class ProfileModule extends PLModule $new = Env::v('modif') == 'new'; $user = get_user_details($login, S::v('uid'), $view); - $user['freetext'] = MiniWiki::WikiToHTML($user['freetext']); - $user['cv'] = MiniWiki::WikiToHTML($user['cv'], true); $title = $user['prenom'] . ' ' . ( empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'] ); $page->assign('xorg_title', $title); diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index acaf70e..6d34a54 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -171,10 +171,7 @@ class XnetGrpModule extends PLModule 'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml'); } - $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML')); $page->assign('articles', $arts); - - $page->assign('asso', $globals->asso()); } function handler_logo(&$page) @@ -233,7 +230,8 @@ class XnetGrpModule extends PLModule SET nom={?}, diminutif={?}, cat={?}, dom={?}, descr={?}, site={?}, mail={?}, resp={?}, forum={?}, mail_domain={?}, ax={?}, pub={?}, - sub_url={?}, inscriptible={?}, unsub_url={?} + sub_url={?}, inscriptible={?}, unsub_url={?}, + flags='wiki_desc' WHERE id={?}", Post::v('nom'), Post::v('diminutif'), Post::v('cat'), Post::i('dom'), @@ -252,7 +250,7 @@ class XnetGrpModule extends PLModule "UPDATE groupex.asso SET descr={?}, site={?}, mail={?}, resp={?}, forum={?}, ax={?}, pub= {?}, sub_url={?}, - unsub_url={?} + unsub_url={?},flags='wiki_desc' WHERE id={?}", Post::v('descr'), Post::v('site'), Post::v('mail'), Post::v('resp'), @@ -266,9 +264,9 @@ class XnetGrpModule extends PLModule $logo = file_get_contents($_FILES['logo']['tmp_name']); $mime = $_FILES['logo']['type']; XDB::execute('UPDATE groupex.asso - SET logo={?}, logo_mime={?} - WHERE id={?}', $logo, $mime, - $globals->asso('id')); + SET logo={?}, logo_mime={?} + WHERE id={?}', $logo, $mime, + $globals->asso('id')); } pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); @@ -279,6 +277,11 @@ class XnetGrpModule extends PLModule $page->assign('dom', $dom); $page->assign('super', true); } + if (!$globals->asso('wiki_desc') && $globals->asso('descr')) { + $page->trig("Attention, le format de la description a changé et utilise désormais la syntaxe wiki " + . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuelle pour " + . "qu'il s'affiche correctement avec cette nouvelle syntaxe."); + } } function handler_mail(&$page) @@ -1023,7 +1026,6 @@ class XnetGrpModule extends PLModule global $globals; require_once('rss.inc.php'); $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false); - $page->register_modifier('wiki_to_html', array('MiniWiki', 'WikiToHTML')); if ($uid) { $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date, @@ -1050,7 +1052,6 @@ class XnetGrpModule extends PLModule { global $globals, $platal; $page->changeTpl('xnetgrp/announce-edit.tpl'); - $page->register_modifier('wiki_to_html', array('MiniWiki','WikiToHTML')); $page->assign('new', is_null($aid)); $art = array(); @@ -1117,8 +1118,7 @@ class XnetGrpModule extends PLModule $aid = XDB::insertId(); if ($art['xorg']) { require_once('validations.inc.php'); - $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], - MiniWiki::WikiToHTML($fulltext), + $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, $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"); diff --git a/plugins/modifier.miniwiki.php b/plugins/modifier.miniwiki.php new file mode 100644 index 0000000..d437c3f --- /dev/null +++ b/plugins/modifier.miniwiki.php @@ -0,0 +1,30 @@ + diff --git a/templates/events/form.tpl b/templates/events/form.tpl index 5b078d0..13afdaa 100644 --- a/templates/events/form.tpl +++ b/templates/events/form.tpl @@ -20,10 +20,12 @@ {* *} {**************************************************************************} -{assign var=texte value=$smarty.request.texte|default:$texte} -{assign var=titre value=$smarty.request.titre|default:$titre} -{assign var=promo_min value=$smarty.request.promo_min|default:$promo_min} -{assign var=promo_max value=$smarty.request.promo_max|default:$promo_max} +{if $smarty.request.texte} +{assign var=texte value=$smarty.request.texte} +{/if} +{assign var=titre value=$smarty.request.titre|default:$titre} +{assign var=promo_min value=$smarty.request.promo_min|default:$promo_min} +{assign var=promo_max value=$smarty.request.promo_max|default:$promo_max} {assign var=peremption value=$smarty.request.peremption|default:$peremption} {assign var=important value=$smarty.request.important|default:$important} diff --git a/templates/events/index.tpl b/templates/events/index.tpl index f10936e..7b02de3 100644 --- a/templates/events/index.tpl +++ b/templates/events/index.tpl @@ -196,7 +196,11 @@ Bienvenue {$smarty.session.prenom}{if $birthday} {/if}
        + {if !$ev.wiki} {$ev.texte|smarty:nodefaults|nl2br} + {else} + {$ev.texte|miniwiki|smarty:nodefaults} + {/if}
        diff --git a/templates/events/preview.tpl b/templates/events/preview.tpl index 18058ed..1fa82b8 100644 --- a/templates/events/preview.tpl +++ b/templates/events/preview.tpl @@ -20,10 +20,10 @@ {* *} {**************************************************************************} -{if trim($titre) || trim($texte_html)} +{if trim($titre) || trim($texte)} - +
        Aperçu de : {$titre|nl2br}
        {$texte_html|nl2br|smarty:nodefaults}
        {$texte|miniwiki|smarty:nodefaults}
        {/if} diff --git a/templates/include/form.valid.evts.tpl b/templates/include/form.valid.evts.tpl index d626a9a..680c2e0 100644 --- a/templates/include/form.valid.evts.tpl +++ b/templates/include/form.valid.evts.tpl @@ -27,7 +27,7 @@ Texte - {tidy}{$valid->texte|nl2br|smarty:nodefaults}{/tidy} + {tidy}{$valid->texte|miniwiki|smarty:nodefaults}{/tidy} Péremption diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index 27ce51c..4b73b91 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -52,7 +52,7 @@ function chgMainWinLoc(strPage) {if $x.gpxs_join}
        Groupe(s) et institution(s) X :
        {$x.gpxs_join|smarty:nodefaults}
        {/if} {/if} {if $x.web}
        Site Web :
        {$x.web}
        {/if} - {if $x.freetext}
        Commentaires :
        {$x.freetext|smarty:nodefaults}
        {/if} + {if $x.freetext}
        Commentaires :
        {$x.freetext|miniwiki|smarty:nodefaults}
        {/if}
        @@ -179,7 +179,7 @@ function chgMainWinLoc(strPage) {if $logged && $x.cv}

        Curriculum Vitae :

        - {$x.cv|smarty:nodefaults} + {$x.cv|miniwiki:title|smarty:nodefaults}
        {/if} {if !$logged} diff --git a/templates/xnetgrp/announce-rss.tpl b/templates/xnetgrp/announce-rss.tpl index da0b8cb..4d1b517 100644 --- a/templates/xnetgrp/announce-rss.tpl +++ b/templates/xnetgrp/announce-rss.tpl @@ -37,7 +37,7 @@ {$line.titre|strip_tags} {$line.id} {#globals.baseurl#}/{$asso.diminutif}/#art{$line.id} -
        Contacts :
        {$line.contacts|wiki_to_html}{/if}]]>
        +
        Contacts :
        {$line.contacts|miniwiki}{/if}]]>
        {$line.prenom} {$line.nom} (X{$line.promo}) {$line.create_date|rss_date} diff --git a/templates/xnetgrp/asso.tpl b/templates/xnetgrp/asso.tpl index b616d7b..d1f72af 100644 --- a/templates/xnetgrp/asso.tpl +++ b/templates/xnetgrp/asso.tpl @@ -91,7 +91,11 @@
        + {if $asso.wiki_desc} + {$asso.descr|miniwiki:title|smarty:nodefaults} + {else} {$asso.descr|smarty:nodefaults} + {/if}

        diff --git a/templates/xnetgrp/edit.tpl b/templates/xnetgrp/edit.tpl index 886cdaf..bf0dfe0 100644 --- a/templates/xnetgrp/edit.tpl +++ b/templates/xnetgrp/edit.tpl @@ -180,8 +180,20 @@
        + +
        + + diff --git a/templates/xnetgrp/form.announce.tpl b/templates/xnetgrp/form.announce.tpl index ca3b565..fecbd7d 100644 --- a/templates/xnetgrp/form.announce.tpl +++ b/templates/xnetgrp/form.announce.tpl @@ -38,9 +38,7 @@ - {tidy} - {$art.texte|wiki_to_html|smarty:nodefaults} - {/tidy} + {$art.texte|miniwiki|smarty:nodefaults} {if ($is_logged || $admin) && $art.contacts} @@ -49,13 +47,13 @@ - {tidy} {if $art.contact_html} + {tidy} {$art.contact_html|nl2br|smarty:nodefaults} + {/tidy} {else} - {$art.contacts|wiki_to_html|nl2br|smarty:nodefaults} + {$art.contacts|miniwiki|smarty:nodefaults} {/if} - {/tidy} {/if} diff --git a/upgrade/0.9.15/04_announces.sql b/upgrade/0.9.15/04_announces.sql new file mode 100644 index 0000000..2f9eeaf --- /dev/null +++ b/upgrade/0.9.15/04_announces.sql @@ -0,0 +1,6 @@ +alter table evenements change flags flags set('valide','archive','important','wiki') not null; +use groupex +alter table asso add column flags set('wiki_desc') not null; +use x4dat + +# vim:set syntax=mysql: -- 2.1.4