X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=banana%2Fpost.inc.php;h=e699e7f9fe0109b690683677bd2f4983be4cf57f;hb=3c3d29bb4ab554f517223c35f1a042a2fc238a4c;hp=daea0896921ead7b61bf8287cd49e57c74287255;hpb=50cd076e53258dbf4e0f92a16ac3912c071c5461;p=banana.git
diff --git a/banana/post.inc.php b/banana/post.inc.php
index daea089..e699e7f 100644
--- a/banana/post.inc.php
+++ b/banana/post.inc.php
@@ -23,6 +23,8 @@ class BananaPost
var $pj;
/** poster name */
var $name;
+ /** test validity */
+ var $valid = true;
/** constructor
* @param $_id STRING MSGNUM or MSGID (a group should be selected in this case)
@@ -34,6 +36,7 @@ class BananaPost
$this->pj = array();
$this->messages = array();
if (!$this->_header()) {
+ $this->valid = false;
return null;
}
@@ -41,6 +44,7 @@ class BananaPost
if ($body = $banana->nntp->body($_id)) {
$this->body = join("\n", $body);
} else {
+ $this->valid = false;
return null;
}
@@ -57,11 +61,7 @@ class BananaPost
} else {
$this->_split_multipart($mpart_type[1], $mpart_boundary[1]);
$this->_find_uuencode();
- if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
- $this->body = iconv($matches[1], 'utf-8', $this->body);
- } else {
- $this->body = utf8_encode($this->body);
- }
+ $this->_fix_charset();
}
}
@@ -191,6 +191,23 @@ class BananaPost
return true;
}
+ /** Fix body charset (convert body to utf8)
+ * @return false if failed
+ */
+ function _fix_charset()
+ {
+ if (preg_match('!charset="?([^;"]*)"?\s*(;|$)?!', $this->headers['content-type'], $matches)) {
+ $body = iconv($matches[1], 'utf-8', $this->body);
+ if (strlen($body) == 0) {
+ return false;
+ }
+ $this->body = $body;
+ } else {
+ $this->body = utf8_encode($this->body);
+ }
+ return true;
+ }
+
/** return body in plain text (useful for messages without a text/plain part)
*/
function get_body()
@@ -253,11 +270,7 @@ class BananaPost
}
}
- if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
- $this->body = iconv($matches[1], 'utf-8', $this->body);
- } else {
- $this->body = utf8_encode($this->body);
- }
+ $this->_fix_charset();
return true;
}
@@ -369,7 +382,10 @@ class BananaPost
preg_match("@text/([^;]+);@", $this->messages[$i]['headers']['content-type'], $format);
$format = textFormat_translate($format[1]);
if ($i != $partid) {
- $res .= ''.$format.'';
+ $res .= makeHREF(Array('group' => $banana->state['group'],
+ 'artid' => $this->id,
+ 'part' => $i),
+ $format);
} else {
$res .= $format;
}
@@ -396,20 +412,33 @@ class BananaPost
$i = 0;
foreach ($this->pj as $file) {
$res .= $file['filename'].' ('.$file['MIME'].') : ';
- $res .= 'télécharger';
- $res .= ' . aperçu';
+ $res .= makeHREF(Array('group' => $banana->state['group'],
+ 'artid' => $this->id,
+ 'pj' => $i),
+ _b_('télécharger'));
+ $res .= ' . ';
+ $res .= makeHREF(Array('group' => $banana->state['group'],
+ 'artid' => $this->id,
+ 'pj' => $i,
+ 'action'=> 'view'),
+ _b_('aperçu'));
$res .= '
';
$i++;
}
$res .= '';
}
- $res .= '