newsletter is now send-able + html layout is really better
authorx2000habouzit <x2000habouzit>
Mon, 18 Oct 2004 07:06:48 +0000 (07:06 +0000)
committerx2000habouzit <x2000habouzit>
Mon, 18 Oct 2004 07:06:48 +0000 (07:06 +0000)
htdocs/css/nl.css [new file with mode: 0644]
htdocs/listes/index.php
htdocs/newsletter/show.php
include/newsletter.inc.php
templates/listes/index.tpl
templates/newsletter/head.tpl

diff --git a/htdocs/css/nl.css b/htdocs/css/nl.css
new file mode 100644 (file)
index 0000000..2fd0f0a
--- /dev/null
@@ -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;
+}
index 7d55a4e..dc73847 100644 (file)
@@ -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);
index 4aec834..9b7ca0a 100644 (file)
@@ -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();
 ?>
index 8a1d115..2b24aaa 100644 (file)
@@ -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  = '<div style="margin: 2ex 0ex 2ex 0ex; padding: 1ex; width: 100%; border: 1px black solid; font-size: 125%; text-align: center">';
-       $res .= $this->title();
-       $res .= '</div>';
+    function toHtml($body=false) {
+       $res  = '<div class="title">'.$this->title().'</div>';
 
        $i = 1;
        foreach($this->_arts as $cid=>$arts) {
@@ -155,14 +153,51 @@ class NewsLetter {
        }
 
        foreach($this->_arts as $cid=>$arts) {
-           $res .= '<div style="margin: 2ex 0ex 2ex 0ex; padding: 2px 1ex 2px 1ex; width: 100%; border: 1px black dotted; font-size: 125%;">';
-           $res .= $this->_cats[$cid].'</div>';
+           $res .= '<h1>'.$this->_cats[$cid].'</h1>';
            foreach($arts as $art) {
                $res .= $art->toHtml();
            }
        }
+
+       if($body) {
+           $res = <<<EOF
+<html>
+  <head>
+    <style type="text/css">
+      div.nl    { margin: auto; font-family: "Georgia","times new roman",serif; width: 56ex; text-align: justify; }
+      div.title { margin: 2ex 0ex 4ex 0ex; padding: 1ex; width: 100%; border: 1px black solid; font-size: 125%; text-align: center; }
+      div.art   {      padding-left: 1ex; margin: 0ex 0ex 4ex 0ex; }
+      div.app   { padding-left: 4ex; margin: 2ex 0ex 2ex 0ex; text-align: left; }
+      h1 { margin: 3ex 0ex 2ex 0ex; padding: 2px 1ex 2px 1ex; width: 100%; border: 1px black dotted; font-size: 125%; }
+      h2 { margin: 0ex 0ex 2ex 0ex; width: 100%; border-bottom: 1px #aaaaaa solid; font-weight:bold; font-style: italic; font-size: 125% }
+    </style>
+  </head>
+  <body>
+    <div class='nl'>
+    $res
+    </div>
+  </body>
+</html>
+EOF;
+       }
        return $res;
     }
+    
+    function sendTo($prenom,$nom,$forlife,$sex,$html) {
+       require_once('diogenes.mailer.inc.php');
+       $mailer = new DiogenesMailer("Lettre Mensuelle Polytechnique.org <info+nlp@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 = '<div style="margin: 2ex 0ex 2ex 0ex; font-weight:bold; font-style: italic; font-size: 125%">'
-               .htmlentities($this->title()).'</div>';
+       $title = '<h2>'.htmlentities($this->title()).'</h2>';
        $body  = enriched_to_text($this->_body,true);
        $app   = enriched_to_text($this->_append,true);
        
-       $art = "$title\n$body<br />";
-       if ($app) $art .= "<div style='padding-left: 4ex; margin: 2ex 0ex 2ex 0ex;'>$app</div>";
+       $art  = "$title\n";
+       $art .= "<div class='art'>\n$body\n";
+       if ($app) $art .= "<div class='app'>$app</div>";
+       $art .= "</div>\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);
        
index 85cec45..d9a330f 100644 (file)
@@ -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 $
  ***************************************************************************}
 
 <div class="rubrique">
@@ -84,25 +84,44 @@ Tu peux demander <a href='create.php'>la cr
   Lettre mensuelle de Polytechnique.org
 </div>
 
-{if $nl}
+{if $nl eq html}
 <p>
-Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org !
+Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format HTML !
 </p>
+{elseif $nl eq text}
 <p>
-Pour te désinscrire suis le lien :
+Tu es actuellement inscrit à la lettre mensuelle de Polytechnique.org dans sont format texte !
 </p>
-<div class='center'>
-  [<a href='?nl_unsub=1'>me désinscrire</a>]
-</div>
 {else}
 <p>
 Tu n'es actuellement pas inscrit à la lettre mensuelle de Polytechnique.org.
 </p>
+{/if}
+
+{if $nl neq "text"}
+<p>
+Pour recevoir la version texte suis le lien :
+</p>
+<div class='center'>
+  [<a href='?nl_sub=text'>m'inscrire pour le format texte</a>]
+</div>
+{/if}
+
+{if $nl neq "html"}
+<p>
+Pour recevoir la version HTML suis le lien :
+</p>
+<div class='center'>
+  [<a href='?nl_sub=html'>m'inscrire pour le format HTML</a>]
+</div>
+{/if}
+
+{if $nl}
 <p>
-Pour t'y abonner suis le lien :
+Pour te désinscrire suis le lien :
 </p>
 <div class='center'>
-  [<a href='?nl_sub=1'>m'inscrire</a>]
+  [<a href='?nl_unsub=1'>me désinscrire</a>]
 </div>
 {/if}
 
index abd83f8..32f26b4 100644 (file)
  *  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}
-<style type="text/css">
-  div.nl {
-    margin: auto;
-    font-familly: georgia,"times new roman",serif;
-    width:56ex;
-    text-align: justify;
-  }
-</style>
-{/literal}
+<link rel="stylesheet" type="text/css" href="{"css/nl.css"|url}" media="screen,print" />
 
 {* vim:set et sw=2 sts=2 sws=2: *}