From: x2000habouzit Date: Wed, 20 Oct 2004 15:09:57 +0000 (+0000) Subject: adds custom NL + custom header on a per NL basis X-Git-Tag: xorg/old~1219 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=2435a4c67031dc1606c00517212a11e9e25f52ca;p=platal.git adds custom NL + custom header on a per NL basis --- diff --git a/htdocs/admin/newsletter_edit.php b/htdocs/admin/newsletter_edit.php index 0090ad12..84c9766 100644 --- a/htdocs/admin/newsletter_edit.php +++ b/htdocs/admin/newsletter_edit.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: newsletter_edit.php,v 1.4 2004-10-16 22:34:09 x2000habouzit Exp $ + $Id: newsletter_edit.php,v 1.5 2004-10-20 15:09:57 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -35,6 +35,7 @@ if(isset($_GET['del_aid'])) { if(isset($_POST['update'])) { $nl->_title = $_POST['title']; $nl->_date = $_POST['date']; + $nl->_head = $_POST['head']; $nl->save(); } diff --git a/htdocs/css/nl.css b/htdocs/css/nl.css index 4245782..87f718a 100644 --- a/htdocs/css/nl.css +++ b/htdocs/css/nl.css @@ -28,6 +28,7 @@ div.nl { } div.nl a { text-decoration: none; } +div.nl a:hover { text-decoration: underline; } div.nl div.title { margin: 2ex 0ex 2ex 0ex; @@ -41,7 +42,10 @@ div.nl div.title { border: 1px #ff4040 solid; } -div.nl div.lnk { margin: 2ex 0ex 2ex 0ex; } +div.nl div.lnk { + padding: 0ex 2ex 0ex 2ex; + margin: 2ex 0ex 2ex 0ex; +} div.nl div.lnk a { display: block; } @@ -94,6 +98,10 @@ div.nl div.app { font-size: 95%; } +div.nl div.intro { + padding: 2ex; +} + div.nl div.foot { border-top: 1px #808080 dashed; font-size: 95%; diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 784771c..ca7afd2 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: newsletter.inc.php,v 1.18 2004-10-20 13:57:56 x2000habouzit Exp $ + $Id: newsletter.inc.php,v 1.19 2004-10-20 15:09:58 x2000habouzit Exp $ ***************************************************************************/ @@ -30,6 +30,7 @@ class NewsLetter { var $_id; var $_date; var $_title; + var $_head; var $_cats = Array(); var $_arts = Array(); @@ -49,6 +50,7 @@ class NewsLetter { $this->_id = $nl['id']; $this->_date = $nl['date']; $this->_title = $nl['titre']; + $this->_head = $nl['head']; mysql_free_result($res); $res = $globals->db->query("SELECT cid,titre FROM newsletter_cat ORDER BY pos"); @@ -72,11 +74,12 @@ class NewsLetter { function save() { global $globals; $globals->db->query("UPDATE newsletter - SET date='{$this->_date}',titre='{$this->_title}' + SET date='{$this->_date}',titre='{$this->_title}',head='{$this->_head}' WHERE id='{$this->_id}'"); } function title() { return stripslashes($this->_title); } + function head() { return stripslashes($this->_head); } function getArt($aid) { foreach($this->_arts as $key=>$artlist) { @@ -133,11 +136,19 @@ class NewsLetter { } } - function toText() { + function toText($prenom,$nom,$sexe) { $res = "====================================================================\n"; $res .= ' '.$this->title()."\n"; $res .= "====================================================================\n\n"; + $head = $this->head(); + $head = str_replace('', $sexe ? 'Chère' : 'Cher', $head); + $head = str_replace('', $prenom, $head); + $head = str_replace('', $nom, $head); + $head = enriched_to_text($head,false,true,2,64); + + if($head) $res .= "\n$head\n\n\n"; + $i = 1; foreach($this->_arts as $cid=>$arts) { $res .= "\n$i *{$this->_cats[$cid]}*\n"; @@ -163,8 +174,17 @@ class NewsLetter { return $res; } - function toHtml($body=false) { + function toHtml($prenom,$nom,$sexe,$body=false) { $res = '
'.$this->title().'
'; + + $head = $this->head(); + $head = str_replace('', $sexe ? 'Chère' : 'Cher', $head); + $head = str_replace('', $prenom, $head); + $head = str_replace('', $nom, $head); + $head = enriched_to_text($head,true); + + if($head) $res .= "
$head
"; + $i = 1; foreach($this->_arts as $cid=>$arts) { @@ -193,18 +213,22 @@ class NewsLetter { div.nl { margin: auto; font-family: "Georgia","times new roman",serif; width: 60ex; text-align: justify; font-size: 10pt; } div.title { margin: 2ex 0ex 2ex 0ex; padding: 1ex; width: 100%; border: 1px black solid; font-size: 140%; text-align: center; color: black; background: #ffffb0; border: 1px #ff4040 solid; } - div.lnk { margin: 2ex 0ex 2ex 0ex; } + + a { text-decoration: none; } + a:hover { text-decoration: underline; } + + div.lnk { margin: 2ex 0ex 2ex 0ex; padding: 0ex 2ex 0ex 2ex; } div.lnk a { display: block; } - a { text-decoration: none; } h1 { margin: 6ex 0ex 4ex 0ex; padding: 2px 4ex 2px 0ex; width: 60ex; font-size: 100%; border-bottom: 1px #ff4040 solid; } h2 { width: 100%; margin: 0ex 1ex 0ex 1ex; padding: 2px 0px 2px 0px; font-weight: bold; font-style: italic; font-size: 95%; } h1 a, h1 a:hover { color: black; background: #ffffb0; text-decoration: none; font-size: 140%; padding: 2px 1ex 2px 1ex; border: 1px #ff4040 solid; } h2 a, h2 a:hover { color: blue; background: #eeeeee; text-decoration: none; padding: 2px 4px 2px 4px; border: 1px #cccccc solid; } - div.art { padding: 2ex; margin: 0ex 1ex 2ex 1ex; width: 58ex; border-top: 1px #cccccc solid; } - div.app { padding: 2ex 3ex 0ex 3ex; width: 100%; margin: 0ex; text-align: left; font-size: 95%; } - div.foot { border-top: 1px #808080 dashed; font-size: 95%; padding: 1ex; color: #808080; background: inherit; text-align: center; } + div.art { padding: 2ex; margin: 0ex 1ex 2ex 1ex; width: 58ex; border-top: 1px #cccccc solid; } + div.app { padding: 2ex 3ex 0ex 3ex; width: 100%; margin: 0ex; text-align: left; font-size: 95%; } + div.intro { padding: 2ex; } + div.foot { border-top: 1px #808080 dashed; font-size: 95%; padding: 1ex; color: #808080; background: inherit; text-align: center; } @@ -225,10 +249,10 @@ EOF; replace_accent($this->title()), $html); if($html) { - $mailer->addPart('text/plain; charset=iso-8859-1', 'iso-8859-1', $this->toText()); - $mailer->addPart('text/html; charset=iso-8859-1', 'iso-8859-1', $this->toHtml(true)); + $mailer->addPart('text/plain; charset=iso-8859-1', 'iso-8859-1', $this->toText($prenom,$nom,$sex)); + $mailer->addPart('text/html; charset=iso-8859-1', 'iso-8859-1', $this->toHtml($prenom,$nom,$sex,true)); } else { - $mailer->setBody($this->toText()); + $mailer->setBody($this->toText($prenom,$nom,$sex)); } $mailer->send(); @@ -343,7 +367,7 @@ function justify($text,$n) { $nxw_len = count($nxl_split) ? strlen($nxl_split[0]) : 0; $line = trim($line); - if(strlen($line)+1+$nxw_len < 68) { + if(strlen($line)+1+$nxw_len < $n) { $res .= "$line\n"; continue; } @@ -377,7 +401,7 @@ function justify($text,$n) { } -function enriched_to_text($input,$html=false,$just=false,$indent=0) { +function enriched_to_text($input,$html=false,$just=false,$indent=0,$width=68) { $text = stripslashes(trim($input)); if($html) { $text = htmlspecialchars($text); @@ -396,7 +420,7 @@ function enriched_to_text($input,$html=false,$just=false,$indent=0) { $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); - $text = $just ? justify($text,68-$indent) : wordwrap($text,68-$indent); + $text = $just ? justify($text,$width-$indent) : wordwrap($text,$width-$indent); if($indent) { $ind = str_pad('',$indent); $text = $ind.str_replace("\n","\n$ind",$text); diff --git a/scripts/migration/0.9.1/newsleter.sql b/scripts/migration/0.9.1/newsleter.sql index 0b140fd..81fd142 100644 --- a/scripts/migration/0.9.1/newsleter.sql +++ b/scripts/migration/0.9.1/newsleter.sql @@ -2,6 +2,7 @@ -- update old table -- alter table newsletter change `date` `date` date not null; +alter table newsletter add column head mediumtext default '' not null; alter table newsletter add column bits enum('old','sent','new') default 'new' not null; update newsletter set bits='old'; diff --git a/templates/admin/newsletter_edit.tpl b/templates/admin/newsletter_edit.tpl index 493278e..8717cda 100644 --- a/templates/admin/newsletter_edit.tpl +++ b/templates/admin/newsletter_edit.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: newsletter_edit.tpl,v 1.5 2004-10-16 22:39:35 x2000habouzit Exp $ + $Id: newsletter_edit.tpl,v 1.6 2004-10-20 15:09:59 x2000habouzit Exp $ ***************************************************************************} {dynamic} @@ -55,6 +55,14 @@ + + + Intro de la lettre + + + + + @@ -84,7 +92,7 @@ {foreach from=$arts item=art} -
{$art->toText()|smarty:nodefaults}
+
{$art->toText($smarty.session.prenom,$smarty.session.nom,$smarty.session.femme)|smarty:nodefaults}
Pos: {$art->_pos}
diff --git a/templates/newsletter/show.tpl b/templates/newsletter/show.tpl index f994cb4..7613c33 100644 --- a/templates/newsletter/show.tpl +++ b/templates/newsletter/show.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: show.tpl,v 1.4 2004-10-20 13:57:56 x2000habouzit Exp $ + $Id: show.tpl,v 1.5 2004-10-20 15:09:59 x2000habouzit Exp $ ***************************************************************************} {dynamic} @@ -50,10 +50,10 @@ {if $smarty.get.text} -
{$nl->toText()}
+
{$nl->toText($smarty.session.prenom,$smarty.session.nom,$smarty.session.femme)}
{else}
- {$nl->toHtml()|smarty:nodefaults} + {$nl->toHtml($smarty.session.prenom,$smarty.session.nom,$smarty.session.femme)|smarty:nodefaults}
{/if}