class NewsLetter extends MassMailer
{
public $_date;
- public $_cats = Array();
- public $_arts = Array();
+ public $_cats = array();
+ public $_arts = array();
function __construct($id = null)
{
}
$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()) {
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;
}
}
}
// }}}
+ // {{{ 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(&$gethostbyname_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 ($gethostbyname_count < $globals->mail->blacklist_host_resolution_limit) {
+ break;
+ }
+
+ if ($host != $globals->mail->alias_dom && $host != $globals->mail->alias_dom2
+ && $host != $globals->mail->domain && $host != $globals->mail->domain2) {
+ $article_ips = array_merge($article_ips, array(gethostbyname($host) => $host));
+ ++$gethostbyname_count;
+ }
+ }
+ }
+
+ return $article_ips;
+ }
+
+ // }}}
}
// }}}
function handler_admin_nl_edit(&$page, $nid = 'last', $aid = null, $action = 'edit') {
$page->changeTpl('newsletter/edit.tpl');
$page->addCssLink('nl.css');
- $page->setTitle('Administration - Newsletter : Edition');
- require_once("newsletter.inc.php");
+ $page->setTitle('Administration - Newsletter : Édition');
+ require_once 'newsletter.inc.php';
- $nl = new NewsLetter($nid);
+ $nl = new NewsLetter($nid);
if($action == 'delete') {
$nl->delArticle($aid);
}
if($aid == 'update') {
- $nl->_title = Post::v('title');
- $nl->_title_mail= Post::v('title_mail');
- $nl->_date = Post::v('date');
- $nl->_head = Post::v('head');
- $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null;
+ $nl->_title = Post::v('title');
+ $nl->_title_mail = Post::v('title_mail');
+ $nl->_date = Post::v('date');
+ $nl->_head = Post::v('head');
+ $nl->_shortname = strlen(Post::v('shortname')) ? Post::v('shortname') : null;
if (preg_match('/^[-a-z0-9]*$/i', $nl->_shortname) && !is_numeric($nl->_shortname)) {
$nl->save();
} else {
- $page->trigError('Le nom de la NL n\'est pas valide');
+ $page->trigError("Le nom de la NL n'est pas valide.");
pl_redirect('admin/newsletter/edit/' . $nl->_id);
}
}
if(Post::v('save')) {
$art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'),
- $aid, Post::v('cid'), Post::v('pos'));
+ $aid, Post::v('cid'), Post::v('pos'));
$nl->saveArticle($art);
pl_redirect("admin/newsletter/edit/$nid");
}
- if($action == 'edit' && $aid != 'update') {
+ if ($action == 'edit' && $aid != 'update') {
$eaid = $aid;
if(Post::has('title')) {
$art = new NLArticle(Post::v('title'), Post::v('body'), Post::v('append'),
- $eaid, Post::v('cid'), Post::v('pos'));
+ $eaid, Post::v('cid'), Post::v('pos'));
} else {
- $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid);
+ $art = ($eaid == 'new') ? new NLArticle() : $nl->getArt($eaid);
}
$page->assign('art', $art);
}
- $page->assign_by_ref('nl',$nl);
+ if ($aid == 'blacklist_check') {
+ $ips_to_check = array();
+ $gethostbyname_count = 0;
+
+ foreach ($nl->_arts as $key => $articles) {
+ foreach ($articles as $article) {
+ $article_ips = $article->getLinkIps($gethostbyname_count);
+ if (!empty($article_ips)) {
+ $ips_to_check[$article->title()] = $article_ips;
+ }
+ }
+ }
+
+ $page->assign('ips_to_check', $ips_to_check);
+ if ($gethostbyname_count >= $globals->mail->blacklist_host_resolution_limit) {
+ $page-trigError("Toutes les url et adresses emails de la lettre"
+ . " n'ont pas été prises en compte car la"
+ . " limite du nombre de résolutions DNS"
+ . " autorisée a été atteinte.");
+ }
+ }
+
+ $page->assign_by_ref('nl', $nl);
}
function handler_admin_nl_cat(&$page, $action = 'list', $id = null) {