X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnewsletter.inc.php;h=a8c424ea3d6937702131c37324fd0eb0232c8815;hb=9e1816c7666767755abbc24f6a0df290efff81b6;hp=07aac94d71263ef535829677b5cf6d4893fea838;hpb=ebd515f95f03f8a87f9b846d65e179b39a535222;p=platal.git diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 07aac94..a8c424e 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -1,6 +1,6 @@ numRows()) { - Newsletter::create(); + NewsLetter::create(); } - $res = XDB::query("SELECT * FROM newsletter WHERE bits='new'"); + $res = XDB::query("SELECT * FROM newsletter WHERE bits='new' ORDER BY id DESC LIMIT 1"); + } + if ($res->numRows() != 1) { + throw new MailNotFound(); } $nl = $res->fetchOneAssoc(); - $this->_id = $nl['id']; - $this->_shortname = $nl['short_name']; - $this->_date = $nl['date']; - $this->_title = $nl['titre']; + $this->_id = $nl['id']; + $this->_shortname = $nl['short_name']; + $this->_date = $nl['date']; + $this->_title = $nl['titre']; $this->_title_mail = $nl['titre_mail']; - $this->_head = $nl['head']; + $this->_head = $nl['head']; $res = XDB::iterRow("SELECT cid,titre FROM newsletter_cat ORDER BY pos"); while (list($cid, $title) = $res->next()) { @@ -89,19 +92,21 @@ class NewsLetter extends MassMailer public function saveArticle(&$a) { - if ($a->_aid>=0) { - XDB::execute('REPLACE INTO newsletter_art (id,aid,cid,pos,title,body,append) - VALUES ({?},{?},{?},{?},{?},{?},{?})', + if ($a->_aid >= 0) { + XDB::execute('REPLACE INTO newsletter_art (id, aid, cid, pos, title, body, append) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?})', $this->_id, $a->_aid, $a->_cid, $a->_pos, $a->_title, $a->_body, $a->_append); - $this->_arts['a'.$a->_aid] = $a; + $this->_arts['a' . $a->_aid] = $a; } else { XDB::execute('INSERT INTO newsletter_art - SELECT {?},MAX(aid)+1,{?},'.($a->_pos ? intval($a->_pos) : 'MAX(pos)+1').',{?},{?},{?} + SELECT {?}, MAX(aid)+1, {?}, ' + . ($a->_pos ? intval($a->_pos) : 'MAX(pos)+1') + . ', {?}, {?}, {?} FROM newsletter_art AS a - WHERE a.id={?}', + WHERE a.id = {?}', $this->_id, $a->_cid, $a->_title, $a->_body, $a->_append, $this->_id); - $this->_arts['a'.$a->_aid] = $a; + $this->_arts['a' . $a->_aid] = $a; } } @@ -223,18 +228,24 @@ class NLArticle // }}} // {{{ function toText() - public function toText() + public function toText($hash = null, $login = null) { $title = '*'.$this->title().'*'; $body = MiniWiki::WikiToText($this->_body, true); $app = MiniWiki::WikiToText($this->_append,false,4); - return trim("$title\n\n$body\n\n$app")."\n"; + $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 = "

".pl_entities($this->title()).'

'; $body = MiniWiki::WikiToHTML($this->_body); @@ -246,6 +257,11 @@ class NLArticle $art .= "
$app
"; } $art .= "\n"; + if (!is_null($hash) && !is_null($login)) { + $art = str_replace('%HASH%', "$hash/$login", $art); + } else { + $art = str_replace('%HASH%', '', $art); + } return $art; } @@ -267,6 +283,60 @@ class NLArticle } // }}} + // {{{ function parseUrlsFromArticle() + + private function parseUrlsFromArticle() + { + $email_regex = '([a-z0-9.\-+_\$]+@([\-.+_]?[a-z0-9])+)'; + $url_regex = '((https?|ftp)://[a-zA-Z0-9._%#+/?=&~-]+)'; + $regex = '{' . $email_regex . '|' . $url_regex . '}i'; + + $matches = array(); + $body_matches = array(); + if (preg_match_all($regex, $this->body(), $body_matches)) { + $matches = array_merge($matches, $body_matches[0]); + } + + $append_matches = array(); + if (preg_match_all($regex, $this->append(), $append_matches)) { + $matches = array_merge($matches, $append_matches[0]); + } + + return $matches; + } + + // }}} + // {{{ function getLinkIps() + + public function getLinkIps(&$blacklist_host_resolution_count) + { + $matches = $this->parseUrlsFromArticle(); + $article_ips = array(); + + if (!empty($matches)) { + global $globals; + + foreach ($matches as $match) { + $host = parse_url($match, PHP_URL_HOST); + if ($host == '') { + list(, $host) = explode('@', $match); + } + + if ($blacklist_host_resolution_count >= $globals->mail->blacklist_host_resolution_limit) { + break; + } + + if (!preg_match('/^(' . str_replace(' ', '|', $globals->mail->domain_whitelist) . ')$/i', $host)) { + $article_ips = array_merge($article_ips, array(gethostbyname($host) => $host)); + ++$blacklist_host_resolution_count; + } + } + } + + return $article_ips; + } + + // }}} } // }}}