<?php
/***************************************************************************
- * Copyright (C) 2003-2007 Polytechnique.org *
+ * Copyright (C) 2003-2009 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
function __construct($id = null)
{
- parent::__construct('newsletter/nl.tpl', 'nl.css', 'nl/show');
+ parent::__construct('newsletter/nl.mail.tpl', 'nl.css', 'nl/show', 'newsletter', 'newsletter_ins');
if (isset($id)) {
if ($id == 'last') {
$res = XDB::query("SELECT MAX(id) FROM newsletter WHERE bits!='new'");
}
$res = XDB::query("SELECT * FROM newsletter WHERE bits='new'");
}
+ if ($res->numRows() != 1) {
+ throw new MailNotFound();
+ }
$nl = $res->fetchOneAssoc();
$this->_id = $nl['id'];
while (list($cid, $title) = $res->next()) {
$this->_cats[$cid] = $title;
}
-
+
$res = XDB::iterRow(
"SELECT a.title,a.body,a.append,a.aid,a.cid,a.pos
FROM newsletter_art AS a
XDB::execute('UPDATE newsletter SET date={?},titre={?},titre_mail={?},head={?},short_name={?} WHERE id={?}',
$this->_date, $this->_title, $this->_title_mail, $this->_head, $this->_shortname,$this->_id);
}
-
+
public function getArt($aid)
{
foreach ($this->_arts as $key=>$artlist) {
$this->_arts['a'.$a->_aid] = $a;
}
}
-
+
public function delArticle($aid)
{
XDB::execute('DELETE FROM newsletter_art WHERE id={?} AND aid={?}', $this->_id, $aid);
protected function setSent()
{
XDB::execute("UPDATE newsletter SET bits='sent' WHERE id={?}", $this->_id);
- }
+ }
static public function subscriptionState($uid = null)
{
FROM newsletter_ins
WHERE user_id={?}", $user);
return $res->fetchOneCell();
- }
-
+ }
+
static public function unsubscribe($uid = null)
{
$user = is_null($uid) ? S::v('uid') : $uid;
VALUES ({?}, 0)", $user);
}
- protected function subscriptionTable()
- {
- return 'newsletter_ins';
- }
-
protected function subscriptionWhere()
{
return '1';
class NLArticle
{
// {{{ properties
-
+
var $_aid;
var $_cid;
var $_pos;
// }}}
// {{{ constructor
-
+
function __construct($title='', $body='', $append='', $aid=-1, $cid=0, $pos=0)
{
$this->_body = $body;
// }}}
// {{{ function body()
-
+
public function body()
{ return trim($this->_body); }
-
+
// }}}
// {{{ function append()
-
+
public function append()
{ return trim($this->_append); }
// }}}
// {{{ function toText()
- public function toText()
+ public function toText($hash = null, $login = null)
{
$title = '*'.$this->title().'*';
- $body = enriched_to_text($this->_body,false,true);
- $app = enriched_to_text($this->_append,false,false,4);
- return trim("$title\n\n$body\n\n$app")."\n";
+ $body = MiniWiki::WikiToText($this->_body, true);
+ $app = MiniWiki::WikiToText($this->_append,false,4);
+ $text = trim("$title\n\n$body\n\n$app")."\n";
+ if (!is_null($hash) && !is_null($login)) {
+ $text = str_replace('%HASH%', "$hash/$login", $text);
+ } else {
+ $text = str_replace('%HASH%', '', $text);
+ }
+ return $text;
}
// }}}
// {{{ function toHtml()
- public function toHtml()
+ public function toHtml($hash = null, $login = null)
{
$title = "<h2 class='xorg_nl'><a id='art{$this->_aid}'></a>".pl_entities($this->title()).'</h2>';
- $body = enriched_to_text($this->_body,true);
- $app = enriched_to_text($this->_append,true);
-
+ $body = MiniWiki::WikiToHTML($this->_body);
+ $app = MiniWiki::WikiToHTML($this->_append);
+
$art = "$title\n";
$art .= "<div class='art'>\n$body\n";
if ($app) {
$art .= "<div class='app'>$app</div>";
}
$art .= "</div>\n";
-
+ if (!is_null($hash) && !is_null($login)) {
+ $art = str_replace('%HASH%', "$hash/$login", $art);
+ } else {
+ $art = str_replace('%HASH%', '', $art);
+ }
+
return $art;
}
public function check()
{
- $text = enriched_to_text($this->_body);
+ $text = MiniWiki::WikiToText($this->_body);
$arr = explode("\n",wordwrap($text,68));
$c = 0;
foreach ($arr as $line) {