From 695650ecec5c6f554f8aeda49d9a5243311b1bbd Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Mon, 18 Oct 2004 07:06:48 +0000 Subject: [PATCH] newsletter is now send-able + html layout is really better --- htdocs/css/nl.css | 64 ++++++++++++++++++++++++++++++++++++ htdocs/listes/index.php | 4 +-- htdocs/newsletter/show.php | 8 ++++- include/newsletter.inc.php | 76 ++++++++++++++++++++++++++++++++----------- templates/listes/index.tpl | 37 ++++++++++++++++----- templates/newsletter/head.tpl | 13 ++------ 6 files changed, 160 insertions(+), 42 deletions(-) create mode 100644 htdocs/css/nl.css diff --git a/htdocs/css/nl.css b/htdocs/css/nl.css new file mode 100644 index 0000000..2fd0f0a --- /dev/null +++ b/htdocs/css/nl.css @@ -0,0 +1,64 @@ +/*************************************************************************** + * 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 * + ***************************************************************************/ + + +div.nl { + margin: auto; + font-family: "Georgia","times new roman",serif; + width: 56ex; + text-align: justify; +} + +div.nl div.title { + margin: 2ex 0ex 4ex 0ex; + padding: 1ex; + width: 100%; + border: 1px black solid; + font-size: 125%; + text-align: center; +} + +div.nl h1 { + margin: 3ex 0ex 2ex 0ex; + padding: 2px 1ex 2px 1ex; + width: 100%; + border: 1px black dotted; + font-size: 125%; +} + +div.nl h2 { + margin: 0ex 0ex 2ex 0ex; + width: 100%; + border-bottom: 1px #aaaaaa solid; + font-weight:bold; + font-style: italic; + font-size: 125% +} + +div.nl div.art { + padding-left: 1ex; + margin: 0ex 0ex 4ex 0ex; +} + +div.nl div.app { + padding-left: 4ex; + margin: 2ex 0ex 2ex 0ex; + text-align: left; +} diff --git a/htdocs/listes/index.php b/htdocs/listes/index.php index 7d55a4e..dc73847 100644 --- a/htdocs/listes/index.php +++ b/htdocs/listes/index.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.php,v 1.8 2004-10-14 22:16:01 x2000habouzit Exp $ + $Id: index.php,v 1.9 2004-10-18 07:06:49 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -46,7 +46,7 @@ if(isset($_POST['promo_add'])) { } } if(!empty($_GET['nl_unsub'])) unsubscribe_nl(); -if(!empty($_GET['nl_sub'])) subscribe_nl(); +if(!empty($_GET['nl_sub'])) subscribe_nl($_GET['nl_sub']=='html'); $listes = $client->get_lists('polytechnique.org'); $page->assign_by_ref('listes',$listes); diff --git a/htdocs/newsletter/show.php b/htdocs/newsletter/show.php index 4aec834..9b7ca0a 100644 --- a/htdocs/newsletter/show.php +++ b/htdocs/newsletter/show.php @@ -18,7 +18,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: show.php,v 1.1 2004-10-16 18:17:50 x2000habouzit Exp $ + $Id: show.php,v 1.2 2004-10-18 07:06:49 x2000habouzit Exp $ ***************************************************************************/ require("auto.prepend.inc.php"); @@ -29,5 +29,11 @@ $nid = empty($_GET['nid']) ? 'last' : $_GET['nid']; $nl = new NewsLetter($nid); $page->assign_by_ref('nl',$nl); +if(isset($_POST['send'])) { + $res = $globals->db->query("SELECT pref FROM newsletter_ins WHERE user_id='{$_SESSION['uid']}'"); + if(!(list($format) = mysql_fetch_row($res))) $format = 'html'; + $nl->sendTo($_SESSION['prenom'], $_SESSION['nom'], $_SESSION['forlife'], $_SESSION['femme'], $format=='html'); +} + $page->run(); ?> diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 8a1d115..2b24aaa 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.12 2004-10-16 23:02:44 x2000habouzit Exp $ + $Id: newsletter.inc.php,v 1.13 2004-10-18 07:06:50 x2000habouzit Exp $ ***************************************************************************/ @@ -139,10 +139,8 @@ class NewsLetter { return $res; } - function toHtml() { - $res = '
'; - $res .= $this->title(); - $res .= '
'; + function toHtml($body=false) { + $res = '
'.$this->title().'
'; $i = 1; foreach($this->_arts as $cid=>$arts) { @@ -155,14 +153,51 @@ class NewsLetter { } foreach($this->_arts as $cid=>$arts) { - $res .= '
'; - $res .= $this->_cats[$cid].'
'; + $res .= '

'.$this->_cats[$cid].'

'; foreach($arts as $art) { $res .= $art->toHtml(); } } + + if($body) { + $res = << + + + + +
+ $res +
+ + +EOF; + } return $res; } + + function sendTo($prenom,$nom,$forlife,$sex,$html) { + require_once('diogenes.mailer.inc.php'); + $mailer = new DiogenesMailer("Lettre Mensuelle Polytechnique.org ", + "$prenom $nom <$forlife@polytechnique.org>", + 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)); + } else { + $mailer->setBody($this->toText()); + } + $mailer->send(); + + } } class NLArticle { @@ -194,13 +229,14 @@ class NLArticle { } function toHtml() { - $title = '
' - .htmlentities($this->title()).'
'; + $title = '

'.htmlentities($this->title()).'

'; $body = enriched_to_text($this->_body,true); $app = enriched_to_text($this->_append,true); - $art = "$title\n$body
"; - if ($app) $art .= "
$app
"; + $art = "$title\n"; + $art .= "
\n$body\n"; + if ($app) $art .= "
$app
"; + $art .= "
\n"; return $art; } @@ -212,6 +248,7 @@ class NLArticle { foreach($arr as $line) if(trim($line)) $c++; return $c<9; } + } ///////////////////////// @@ -237,10 +274,10 @@ function get_nl_list() { function get_nl_state() { global $globals; - $res = $globals->db->query("SELECT COUNT(*)>0 FROM newsletter_ins WHERE user_id={$_SESSION['uid']}"); - list($b) = mysql_fetch_row($res); + $res = $globals->db->query("SELECT pref FROM newsletter_ins WHERE user_id={$_SESSION['uid']}"); + if(!(list($st) = mysql_fetch_row($res))) $st = false; mysql_free_result($res); - return $b; + return $st; } function unsubscribe_nl() { @@ -248,16 +285,17 @@ function unsubscribe_nl() { $globals->db->query("DELETE FROM newsletter_ins WHERE user_id={$_SESSION['uid']}"); } -function subscribe_nl() { +function subscribe_nl($html=true) { global $globals; - $globals->db->query("REPLACE INTO newsletter_ins (user_id,last) - SELECT {$_SESSION['uid']}, MAX(id) + $format = $html ? 'html' : 'text'; + $globals->db->query("REPLACE INTO newsletter_ins (user_id,last,pref) + SELECT {$_SESSION['uid']}, MAX(id), '$format' FROM newsletter WHERE bits!='new'"); } function justify($text,$n) { $arr = split("\n",wordwrap($text,$n)); - $arr = array_map(trim,$arr); + $arr = array_map('trim',$arr); $res = ''; foreach($arr as $key => $line) { $nxl = isset($arr[$key+1]) ? trim($arr[$key+1]) : ''; @@ -282,7 +320,7 @@ function justify($text,$n) { continue; } - $len = array_sum(array_map(strlen,$tmp)); + $len = array_sum(array_map('strlen',$tmp)); $empty = $n - $len; $sw = floatval($empty) / floatval($words-1); diff --git a/templates/listes/index.tpl b/templates/listes/index.tpl index 85cec45..d9a330f 100644 --- a/templates/listes/index.tpl +++ b/templates/listes/index.tpl @@ -17,7 +17,7 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: index.tpl,v 1.13 2004-10-14 18:32:58 x2000habouzit Exp $ + $Id: index.tpl,v 1.14 2004-10-18 07:06:50 x2000habouzit Exp $ ***************************************************************************}
@@ -84,25 +84,44 @@ Tu peux demander la cr Lettre mensuelle de Polytechnique.org
-{if $nl} +{if $nl eq html}

-Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org ! +Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format HTML !

+{elseif $nl eq text}

-Pour te désinscrire suis le lien : +Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format texte !

-
{else}

Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org.

+{/if} + +{if $nl neq "text"} +

+Pour recevoir la version texte suis le lien : +

+ +{/if} + +{if $nl neq "html"} +

+Pour recevoir la version HTML suis le lien : +

+ +{/if} + +{if $nl}

-Pour t'y abonner suis le lien : +Pour te désinscrire suis le lien :

{/if} diff --git a/templates/newsletter/head.tpl b/templates/newsletter/head.tpl index abd83f8..32f26b4 100644 --- a/templates/newsletter/head.tpl +++ b/templates/newsletter/head.tpl @@ -17,18 +17,9 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: head.tpl,v 1.1 2004-10-16 18:17:51 x2000habouzit Exp $ + $Id: head.tpl,v 1.2 2004-10-18 07:06:50 x2000habouzit Exp $ ***************************************************************************} -{literal} - -{/literal} + {* vim:set et sw=2 sts=2 sws=2: *} -- 2.1.4