* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: newsletter.inc.php,v 1.9 2004-10-16 21:14:15 x2000habouzit Exp $
+ $Id: newsletter.inc.php,v 1.10 2004-10-16 22:06:33 x2000habouzit Exp $
***************************************************************************/
define('FEMME', 1);
define('HOMME', 0);
-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 = str_replace('[b]','<strong>', $text);
- $text = str_replace('[/b]','</strong>', $text);
- $text = str_replace('[i]','<em>', $text);
- $text = str_replace('[/i]','</em>', $text);
- $text = str_replace('[u]','<span style="text-decoration: underline">', $text);
- $text = str_replace('[/u]','</span>', $text);
- $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','<a href="\1">\1</a>', $text);
- $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','<a href="mailto:\1">\1</a>', $text);
- return nl2br($text);
- } else {
- $text = preg_replace('!\[\/?b\]!','*',$text);
- $text = preg_replace('!\[\/?u\]!','_',$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 $just ? justify($text,68) : wordwrap($text,68);
- }
-}
-
class NewsLetter {
var $_id;
FROM newsletter_art AS a
INNER JOIN newsletter AS n USING(id)
LEFT JOIN newsletter_cat AS c ON(a.cid=c.cid)
+ WHERE a.id=$id
ORDER BY c.pos,a.pos");
while(list($title,$body,$append,$aid,$cid,$pos) = mysql_fetch_row($res)) {
$this->_arts[$cid]["a$aid"] = new NLArticle($title,$body,$append,$aid,$cid,$pos);
$globals->db->query(
"INSERT INTO newsletter_art
SELECT {$this->_id},MAX(aid)+1,{$a->_cid},
- ". ($a->_pos ? $a->_pos : "IF(MAX(pos)<100,100,MAX(pos)+1),").",
+ ".($a->_pos ? $a->_pos : "MAX(pos)+1").",
'{$a->_title}','{$a->_body}','{$a->_append}'
FROM newsletter_art AS a
- WHERE a.id={$this->_id}");
+ WHERE a.id={$this->_id} AND cid='{$a->_cid}'");
$this->_arts['a'.$a->_aid] = $a;
}
}
}
function toText() {
- $res = "";
+ $res = "====================================================================\n";
+ $res .= ' '.$this->title()."\n";
+ $res .= "====================================================================\n\n";
+
+ $res .= "INTRO\n\n";
+
+ $res .= "--------------------------------------------------------------------\n";
+ $i = 1;
+ foreach($this->_arts as $cid=>$arts) {
+ $res .= "\n$i *{$this->_cats[$cid]}*\n";
+ foreach($arts as $art) {
+ $res .= '- '.$art->title()."\n";
+ }
+ $i ++;
+ }
+ $res .= "\n";
+
foreach($this->_arts as $cid=>$arts) {
$res .= "--------------------------------------------------------------------\n";
$res .= "*{$this->_cats[$cid]}*\n";
}
function toHtml() {
- $res = "";
+ $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>';
+
+ $i = 1;
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 .= "<strong>$i. {$this->_cats[$cid]}</strong><br />";
+ foreach($arts as $art) {
+ $res .= '- '.$art->title()."<br />\n";
+ }
+ $res .= '<br />';
+ $i ++;
+ }
+
+ 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>';
foreach($arts as $art) {
$res .= $art->toHtml();
$this->_pos = $pos;
}
+ function title() { return stripslashes(trim($this->_title)); }
function body() { return stripslashes(trim($this->_body)); }
function append() { return stripslashes(trim($this->_append)); }
function toText() {
- $title = '*'.stripslashes($this->_title).'*';
+ $title = '*'.$this->title().'*';
$body = enriched_to_text($this->_body,false,true);
$app = enriched_to_text($this->_append);
return trim("$title\n\n$body\n\n$app")."\n";
}
function toHtml() {
- $title = '<span style="font-weight:bold; font-style: italic; font-size: 125%">'
- .stripslashes($this->_title).'</span>';
+ $title = '<div style="margin: 2ex 0ex 2ex 0ex; font-weight:bold; font-style: italic; font-size: 125%">'
+ .$this->title().'</div>';
$body = enriched_to_text($this->_body,true);
$app = enriched_to_text($this->_append,true);
- $art = "$title<br /><br />$body<br />";
+ $art = "$title\n$body<br />";
if ($app) $art .= "<br />$app<br />";
return $art;
}
}
-class NLConstraint {
- var $_func;
- var $_arg;
-
- function NLConstraint($func, $arg) {
- $this->_func = $func;
- $this->_arg = $arg;
- }
-
- function check($user) { return false; }
-}
-
-class NLPromoConstraint {
- function check($user) {
- $promo = $user['promo'];
- switch($this->_func) {
- case 'eq': return ( $promo == $this->_arg );
- case 'neq': return ( $promo != $this->_arg );
- case 'geq': return ( $promo >= $this->_arg );
- case 'leq': return ( $promo <= $this->_arg );
- case 'odd': return ( $promo % 2 == 1 );
- case 'even': return ( $promo % 2 == 0 );
- default: return false;
- }
- }
-}
-
-class NLSexeConstraint {
- function check($user) { return $user['sexe'] == $_arg; }
-}
-
-
+/////////////////////////
+// functions ............
+//
function get_nl_slist() {
global $globals;
$res = $globals->db->query("SELECT id,date,titre FROM newsletter ORDER BY date DESC");
FROM newsletter WHERE bits!='new'");
}
+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;
+ $line = trim($line);
+
+ if(strlen($line)+1+$nxw_len < 68) {
+ $res .= "$line\n";
+ continue;
+ }
+
+ if(preg_match('![.:;]$!',$line)) {
+ $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 = str_replace('[b]','<strong>', $text);
+ $text = str_replace('[/b]','</strong>', $text);
+ $text = str_replace('[i]','<em>', $text);
+ $text = str_replace('[/i]','</em>', $text);
+ $text = str_replace('[u]','<span style="text-decoration: underline">', $text);
+ $text = str_replace('[/u]','</span>', $text);
+ $text = preg_replace('!((https?|ftp)://[^\r\n\t ]*)!','<a href="\1">\1</a>', $text);
+ $text = preg_replace('!([a-zA-Z0-9\-_+.]*@[a-zA-Z0-9\-_+.]*)!','<a href="mailto:\1">\1</a>', $text);
+ return nl2br($text);
+ } else {
+ $text = preg_replace('!\[\/?b\]!','*',$text);
+ $text = preg_replace('!\[\/?u\]!','_',$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 $just ? justify($text,68) : wordwrap($text,68);
+ }
+}
+
?>