From: x2000habouzit Date: Sat, 16 Oct 2004 17:49:37 +0000 (+0000) Subject: we can now submit articles, oh yeah ;p X-Git-Tag: xorg/old~1253 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=1bab534393100243cb1f2c5cc3cddfb478d582c9;p=platal.git we can now submit articles, oh yeah ;p --- diff --git a/htdocs/newsletter/submit.php b/htdocs/newsletter/submit.php new file mode 100644 index 0000000..9a5eb36 --- /dev/null +++ b/htdocs/newsletter/submit.php @@ -0,0 +1,48 @@ +assign('art', $art); +} elseif($_POST['valid']) { + $nl = new Newsletter(); + $art = new NLArticle($_POST['title'], $_POST['body'], $_POST['append']); + $nl->saveArticle($art); + + require("diogenes.mailer.inc.php"); + $to = 'Equipe Newsletter Polytechnique.org '; + $from = "{$_SESSION['prenom']} {$_SESSION['nom']} ({$_SESSION['promo']}) <{$_SESSION['forlife']}@polytechnique.org>"; + $mailer = new DiogenesMailer($from,$to,"proposition d'article dans la NL",false,$from); + $text = "l'article suivant a été proposé par:\n\n $from\n\n\n".$art->toText(); + $mailer->setBody($text); + $mailer->send(); + + $page->assign('submited', true); +} + +$page->run(); +?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 00e8ee9..8788081 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -18,20 +18,54 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: newsletter.inc.php,v 1.5 2004-10-15 22:31:13 x2000habouzit Exp $ + $Id: newsletter.inc.php,v 1.6 2004-10-16 17:49:38 x2000habouzit Exp $ ***************************************************************************/ define('FEMME', 1); define('HOMME', 0); +function enriched_to_text($input,$html=false) { + $text = stripslashes(trim($input)); + if($html) { + $text = htmlspecialchars($text); + $text = str_replace('[b]','', $text); + $text = str_replace('[/b]','', $text); + $text = str_replace('[i]','', $text); + $text = str_replace('[/i]','', $text); + $text = str_replace('[u]','', $text); + $text = str_replace('[/u]','', $text); + $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','\1', $text); + $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','\1', $text); + return nl2br($text); + } else { + $text = preg_replace('!\[\/?b\]!','*',$text); + $text = preg_replace('!\[\/?u\]!','_',$text); + $text = preg_replace('!\[\/?i\]!','/',$text); + $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','[\1]', $text); + $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','[mailto:\1]', $text); + return wordwrap($text, 68); + } +} + + class NewsLetter { + var $_id; var $_cats; - function NewsLetter() { + function NewsLetter($id=null) { global $globals; - $res = $globals->db->query("SELECT cid,title FROM newsletter_cat ORDER BY pos"); + if(isset($id)) { + $res = $globals->db->query("SELECT * FROM newsletter WHERE id='$id'"); + } else { + $res = $globals->db->query("SELECT * FROM newsletter WHERE bits='new'"); + } + $nl = mysql_fetch_assoc($res); + $this->_id = $nl['id']; + mysql_free_result($res); + + $res = $globals->db->query("SELECT cid,titre FROM newsletter_cat ORDER BY pos"); $this->_cats = Array(); while(list($cid,$title) = mysql_fetch_row($res)) { $this->_cats[$cid] = $title; @@ -39,10 +73,69 @@ class NewsLetter { mysql_free_result($res); } + + + function saveArticle(&$a) { + global $globals; + if($a->_aid) { + $globals->db->query("REPLACE INTO newsletter_art (id,aid,cid,pos,title,body.append) + VALUES({$this->_id},{$a->_aid},{$a->_cid},{$a->_pos}, + '{$a->_title}','{$a->_body}','{$a->_append}')"); + } else { + $globals->db->query( + "INSERT INTO newsletter_art + SELECT {$this->_id},MAX(aid)+1,0,100,'{$a->_title}','{$a->_body}','{$a->_append}' + FROM newsletter_art AS a + WHERE a.id={$this->_id}"); + } + } } class NLArticle { - function NLArticle() { } + var $_aid; + var $_cid; + var $_pos; + var $_title; + var $_body; + var $_append; + + function NLArticle($title,$body,$append,$aid=null,$cid=0,$pos=100) { + $this->_body = $body; + $this->_title = $title; + $this->_append = $append; + $this->_aid = $aid; + $this->_cid = $aid; + $this->_pos = $aid; + } + + function body() { return stripslashes(trim($this->_body)); } + function append() { return stripslashes(trim($this->_append)); } + + function toText() { + $title = '*'.stripslashes($this->_title).'*'; + $body = enriched_to_text($this->_body); + $app = enriched_to_text($this->_append); + return trim("$title\n\n$body\n\n$app")."\n"; + } + + function toHtml() { + $title = ''.stripslashes($this->_title).''; + $body = enriched_to_text($this->_body,true); + $app = enriched_to_text($this->_append,true); + + $art = "$title

$body
"; + if ($app) $art .= "
$app
"; + + return $art; + } + + function check() { + $text = enriched_to_text($this->_body); + $arr = explode("\n",wordwrap($text,68)); + $c = 0; + foreach($arr as $line) if(trim($line)) $c++; + return $c<9; + } } class NLConstraint { diff --git a/scripts/migration/0.9.1/newsleter.sql b/scripts/migration/0.9.1/newsleter.sql index 9cdddcb..0b140fd 100644 --- a/scripts/migration/0.9.1/newsleter.sql +++ b/scripts/migration/0.9.1/newsleter.sql @@ -1,7 +1,6 @@ -- ----------------------------------------------------------------------------- -- update old table -- -alter table newsletter change id id int not null; alter table newsletter change `date` `date` date not null; alter table newsletter add column bits enum('old','sent','new') default 'new' not null; update newsletter set bits='old'; @@ -32,19 +31,10 @@ create table newsletter_art ( aid smallint unsigned not null, cid smallint unsigned not null, pos tinyint unsigned not null, - texte mediumtext not null, + title mediumtext not null, + body mediumtext not null, + append mediumtext not null, PRIMARY KEY (id,aid) ); -- -- ----------------------------------------------------------------------------- --- newsletter appends --- -create table newsletter_contact ( - id int unsigned not null, - aid smallint unsigned not null, - titre varchar(128) not null, - content varchar(128) not null, - type enum('url','mail','text','none'), - PRIMARY KEY (id,aid) -); --- ----------------------------------------------------------------------------- diff --git a/templates/docs/contacts.tpl b/templates/docs/contacts.tpl index 3689077..b5c1626 100644 --- a/templates/docs/contacts.tpl +++ b/templates/docs/contacts.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: contacts.tpl,v 1.9 2004-08-31 20:19:30 x2000habouzit Exp $ + $Id: contacts.tpl,v 1.10 2004-10-16 17:49:39 x2000habouzit Exp $ ***************************************************************************} @@ -169,13 +169,17 @@ la newsletter : le texte du message doit faire au plus 8 lignes de 68 ca sus).

-Une fois que ton article est prêt et qu'il ne dépasse pas la taille indiquée, il te suffit -de nous le soumettre par email (éviter les pièces jointes) à cette adresse : +Un formulaire en ligne te permet de nous soumettre un article, et se chargera de vérifier +ces contraintes pour toi : soumission d'article. +

+

+Sinon, une fois que ton article est prêt et qu'il ne dépasse pas la taille indiquée, +tu peux aussi nous le soumettre par email (éviter les pièces jointes) à cette adresse : {mailto address='info_nlp@polytechnique.org' encode='hex'}.

Les anciennes newsletters de Polytechnique.org sont -archivées si tu veux t'en inspirer. +archivées si tu veux t'en inspirer.

{elseif $smarty.request.topic eq 6} diff --git a/templates/newsletter/index.tpl b/templates/newsletter/index.tpl index 806fdb7..93430e4 100644 --- a/templates/newsletter/index.tpl +++ b/templates/newsletter/index.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.tpl,v 1.1 2004-10-15 12:57:11 x2000habouzit Exp $ + $Id: index.tpl,v 1.2 2004-10-16 17:49:39 x2000habouzit Exp $ ***************************************************************************} @@ -30,7 +30,7 @@ cette lettre, il te suffit de te rendre sur la page de

Pour demander l'ajout d'une annonce dans la prochaine lettre mensuelle, -écris-nous ! +utilise le formulaire dédié !.

{dynamic} diff --git a/templates/newsletter/submit.tpl b/templates/newsletter/submit.tpl new file mode 100644 index 0000000..7c3f171 --- /dev/null +++ b/templates/newsletter/submit.tpl @@ -0,0 +1,128 @@ +{*************************************************************************** + * Copyright (C) 2003-2004 Polytechnique.org * + * http://opensource.polytechnique.org/ * + * * + * This program 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. * + * * + * This program 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 this program; if not, write to the Free Software * + * Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + *************************************************************************** + $Id: submit.tpl,v 1.1 2004-10-16 17:49:39 x2000habouzit Exp $ + ***************************************************************************} + + +
+ Proposer un article à sur la prochaine Lettre mensuelle +
+ +{dynamic} + +{if $submited} + +

+ton article a bien été pris en compte. +

+ +

+Nous te recontacterons éventuellement (certainement vers la fin du mois) si nous avons des +renseignements à te demander à son sujet ! +

+ +{else} + + +{if $art} + +{if !$art->check()} +

+article trop long !
+il faut te limiter à 8 lignes de 68 caractères. +

+{/if} + +
+ + + + + + {if $art->check()} + + + + + + + + + + + + + + {/if} +
Version texte
{$art->toText()}
Version html
+
+ {$art->toHtml()|smarty:nodefaults} +
+
Soumettre
+ Si tu es content de ton article, tu peux le soummetre. + Sinon, tu peux continuer à l'éditer en dessous +
+ + + + +
+
+ +
+ +{/if} + +
+ + + + + + + + + + + + + + + + + + + +
proposer un article
Sujet + +
Contenu + +
Ajouts (emails,contacts,tarifs,site web, ...) + +
+ +
+
+ +{/if} + +{/dynamic} + +{* vim:set et sw=2 sts=2 sws=2: *}