* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: newsletter_edit.php,v 1.1 2004-10-16 19:54:34 x2000habouzit Exp $
+ $Id: newsletter_edit.php,v 1.2 2004-10-16 21:14:15 x2000habouzit Exp $
***************************************************************************/
require("auto.prepend.inc.php");
header("Location: ?nid=$nid");
}
+if(isset($_POST['update'])) {
+ $nl->_title = $_POST['title'];
+ $nl->save();
+}
+
if(isset($_POST['save'])) {
$eaid = $_GET['edit_aid'];
$art = new NLArticle($_POST['title'], $_POST['body'], $_POST['append'], $eaid, $_POST['cid'], $_POST['pos']);
if(isset($_GET['edit_aid'])) {
$eaid = $_GET['edit_aid'];
- if($eaid<0) {
- if(!empty($_POST)) {
- $art = new NLArticle($_POST['title'], $_POST['body'], $_POST['append'],
- $eaid, $_POST['cid'], $_POST['pos']);
- } else {
- $art = new NLArticle();
- }
+ if(isset($_POST['aid'])) {
+ $art = new NLArticle($_POST['title'], $_POST['body'], $_POST['append'],
+ $eaid, $_POST['cid'], $_POST['pos']);
+ } elseif($eaid<0) {
+ $art = new NLArticle();
} else {
$art = $nl->getArt($_GET['edit_aid']);
}
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: newsletter.inc.php,v 1.8 2004-10-16 19:54:35 x2000habouzit Exp $
+ $Id: newsletter.inc.php,v 1.9 2004-10-16 21:14:15 x2000habouzit Exp $
***************************************************************************/
define('FEMME', 1);
define('HOMME', 0);
-function enriched_to_text($input,$html=false) {
+function justify($text,$n) {
+ $arr = split("\n",wordwrap($text,$n));
+ $arr = array_map(trim,$arr);
+ $res = '';
+ foreach($arr as $key => $line) {
+ $nxl = isset($arr[$key+1]) ? trim($arr[$key+1]) : '';
+ $nxl_split = preg_split('! +!',$nxl);
+ $nxw_len = count($nxl_split) ? strlen($nxl_split[0]) : 0;
+
+ if(strlen($line)+1+$nxw_len <= 68) {
+ $res .= "$line\n";
+ continue;
+ }
+
+ $tmp = preg_split('! +!',trim($line));
+ $words = count($tmp);
+ if($words <= 1) {
+ $res .= "$line\n";
+ continue;
+ }
+
+ $len = array_sum(array_map(strlen,$tmp));
+ $empty = $n - $len;
+ $sw = floatval($empty) / floatval($words-1);
+
+ $cur = 0;
+ $l = '';
+ foreach($tmp as $word) {
+ $l .= $word;
+ $cur += $sw + strlen($word);
+ $l = str_pad($l,intval($cur+0.5));
+ }
+ $res .= trim($l)."\n";
+ }
+ return trim($res);
+}
+
+
+function enriched_to_text($input,$html=false,$just=false) {
$text = stripslashes(trim($input));
if($html) {
$text = htmlspecialchars($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);
+ return $just ? justify($text,68) : wordwrap($text,68);
}
}
mysql_free_result($res);
}
+ function save() {
+ global $globals;
+ $globals->db->query("UPDATE newsletter
+ SET date='{$this->_date}',titre='{$this->_title}'
+ WHERE id='{$this->_id}'");
+ }
+
+ function title() { return stripslashes($this->_title); }
+
function getArt($aid) {
foreach($this->_arts as $key=>$artlist) {
if(isset($artlist["a$aid"])) return $artlist["a$aid"];
}
}
+ function toText() {
+ $res = "";
+ foreach($this->_arts as $cid=>$arts) {
+ $res .= "--------------------------------------------------------------------\n";
+ $res .= "*{$this->_cats[$cid]}*\n";
+ $res .= "--------------------------------------------------------------------\n\n";
+ foreach($arts as $art) {
+ $res .= $art->toText();
+ $res .= "\n\n";
+ }
+ }
+ return $res;
+ }
+
function toHtml() {
- return "foo";
+ $res = "";
+ foreach($this->_arts as $cid=>$arts) {
+ $res .= '<div style="margin: 2ex 0ex 2ex 0ex; padding: 2px 1ex 2px 1ex; width: 100%; border: 1px black solid; font-size: 125%;">';
+ $res .= $this->_cats[$cid].'</div>';
+ foreach($arts as $art) {
+ $res .= $art->toHtml();
+ }
+ }
+ return $res;
}
}
function toText() {
$title = '*'.stripslashes($this->_title).'*';
- $body = enriched_to_text($this->_body);
+ $body = enriched_to_text($this->_body,false,true);
$app = enriched_to_text($this->_append);
return trim("$title\n\n$body\n\n$app")."\n";
}
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: newsletter_edit.tpl,v 1.1 2004-10-16 19:54:35 x2000habouzit Exp $
+ $Id: newsletter_edit.tpl,v 1.2 2004-10-16 21:14:15 x2000habouzit Exp $
***************************************************************************}
{dynamic}
{if !$art}
+<p>[<a href="{"newsletter/show.php"|url}?nid={$nl->_id}">visualiser</a>]</p>
+
+<form action='{$smarty.server.PHP_SELF}?nid={$nl->_id}' method='post'>
+ <table class="bicol" cellpadding="3" cellspacing="0">
+ <tr>
+ <th colspan='2'>
+ Propriétés de la newsletter
+ </th>
+ </tr>
+ <tr>
+ <td class='titre'>
+ Titre
+ </td>
+ <td>
+ <input type='text' size='60' name='title' value="{$nl->title()}" />
+ </td>
+ </tr>
+ <tr class='center'>
+ <td colspan='2'>
+ <input type='submit' name='update' value='sauver' />
+ </td>
+ </tr>
+ </table>
+</form>
+
+<br />
+
<table class="bicol" cellpadding="3" cellspacing="0">
<tr>
- <th>
- {$nl->_title|default:"[no title]"}
- </th>
- <th></th>
- </tr>
- <tr>
<td>
Créer un nouvel article ...
</td>
{foreach from=$arts item=art}
<tr class="{cycle values="impair,pair"}">
<td>
- <div class='nl'>
- {$art->toHtml()|smarty:nodefaults}
- </div>
+ <pre>{$art->toText()|smarty:nodefaults}</pre>
</td>
<td style='vertical-align:middle; border-left: 1px gray solid'>
<strong>Pos: {$art->_pos}</strong><br />
<br />
-<form action="{$smarty.server.REQUEST_URI}" method="post">
+<form action="{$smarty.server.REQUEST_URI}#edit" method="post">
<table class='bicol'>
<tr>
<th colspan='2'>
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: show.tpl,v 1.1 2004-10-16 18:17:51 x2000habouzit Exp $
+ $Id: show.tpl,v 1.2 2004-10-16 21:14:16 x2000habouzit Exp $
***************************************************************************}
{dynamic}
Lettre de Polytechnique.org de {$nl->_date|date_format:"%B %Y"}
</div>
-<p>[<a href='index.php'>liste des lettres</a>]</p>
+<p>
+[<a href='index.php'>liste des lettres</a>]
+{if $smarty.get.text}
+[<a href='?nid={$nl->_id}'>version HTML</a>]
+{else}
+[<a href='?nid={$nl->_id}&text=1'>version Texte</a>]
+{/if}
+{perms level='admin'}
+[<a href='{"admin/newsletter_edit.php"|url}?nid={$nl->_id}'>Editer</a>]
+{/perms}
+</p>
<form method="post" action="{$smarty.server.PHP_SELF}">
<div class='center'>
<table class="bicol" cellpadding="3" cellspacing="0">
<tr>
+ <th>{$nl->title()}</th>
+ </tr>
+ <tr>
<td>
+ {if $smarty.get.text}
+ <pre>{$nl->toText()}</pre>
+ {else}
<div class='nl'>
- {$nl->toHtml()}
+ {$nl->toHtml()|smarty:nodefaults}
</div>
+ {/if}
</td>
</tr>
</table>