Home
>
Outdated forums
>
Phorum 3 forums (READ ONLY)
>
Finished Mods and Plug-ins (READ ONLY)
>
Topic
Inline Attachments
Posted by Marc Line
Inline Attachments November 20, 2003 03:37AM |
I've benefitted greatly from reading and using contributions here, so I'd like to try to give something back. Here's a little hack to allow for the inline display of graphic attachments. There's no parsing to ensure that an attachment *is* a graphic 'cos I have it running in a forum which only allows jpg and gif, but adding that shouldn't be a problem.
What it does is modify the read.php script to have a sensitivity to a specific command embedded in a post. If someone uploads a graphic attachment and wants it to display at a certain point within their post, all they have to do is type ####attach=N#### in their post at the point at which they want the attachment to appear. (N is of course the number of the attachment in the list)
The first thing that the code does is to create an array of URLs as the attachment list is being parsed. Next, it counts the number found and for every one in that number, checks the body of the post for an ####attach=N#### command relating to it. If it finds one, it simply executes a string replacement of the command with the corresponding URL.
It's running in a heavily modified 3.4.2 but I've included it here as a code fragment of the read.php script from 3.4.3. All should be well! :)
The below is in two parts - original code and replacement code. I hope it's clear and I hope that someone will find it useful.
Many thanks
Marc
Phorum 3.4.3 read.php Line 462-
Original code here....
// exec read_header plugins
@reset($plugins['read_header']);
while(list($key,$val) = each($plugins['read_header'])) {
$val($rec_id);
}
$attachment_html='';
if ($AllowAttachments && $ForumAllowUploads == 'Y') {
$SQL="Select id, filename from $ForumTableName"."_attachments where message_id=$rec_id";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$filename="$AttachmentDir/$ForumTableName/$rec[id]".strtolower(strrchr($rec['filename'], '.'));
$size=filesize($filename);
if($size<1024) $size=1024;
$size=round($size/1024).'k';
$delim = (function_exists("apache_note")) ? "/" : "?";
if($ShowAttachments){
$attachment_html.="<a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"><img border=\"0\" src=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"></a><br />\n";
} else {
echo "$lFormAttachment: <a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\">$rec[filename]</a> ($size)<br />\n";
}
}
}
echo '<br />';
$qbody=$body;
$body=str_replace(PHORUM_SIG_MARKER, $sig, $body);
$body=format_body($body);
Replace the above with....
// exec read_header plugins
@reset($plugins['read_header']);
while(list($key,$val) = each($plugins['read_header'])) {
$val($rec_id);
}
$attachurl[]="";
$numattach=0;
$attachment_html='';
if ($AllowAttachments && $ForumAllowUploads == 'Y') {
$SQL="Select id, filename from $ForumTableName"."_attachments where message_id=$rec_id";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$filename="$AttachmentDir/$ForumTableName/$rec[id]".strtolower(strrchr($rec['filename'], '.'));
$size=filesize($filename);
if($size<1024) $size=1024;
$size=round($size/1024).'k';
$attachurl[]="<br><center><img src='$forum_url/download.$ext?finfo=$num,$rec_id,$rec[id]/$rec[filename]'></center><br>";
$delim = (function_exists("apache_note")) ? "/" : "?";
if($ShowAttachments){
$attachment_html.="<a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"><img border=\"0\" src=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"></a><br />\n";
} else {
echo "$lFormAttachment: <a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\">$rec[filename]</a> ($size)<br />\n";
}
}
$numattach = count($attachurl)-1;
}
echo '<br />';
$qbody=$body;
$body=str_replace(PHORUM_SIG_MARKER, $sig, $body);
//handle attachment directives (images only)
//<!--attach=N--->
$attachloop=0;
if($numattach > 0){
while ($attachloop < $numattach){
$attachcmd = "####attach=" . trim($attachloop+1) . "####";
if(strstr($body,$attachcmd)){
$thiscmd = $attachurl[$attachloop+1];
$body = str_replace($attachcmd,$thiscmd,$body);
}
$attachloop++;
}
}
$body=format_body($body);
What it does is modify the read.php script to have a sensitivity to a specific command embedded in a post. If someone uploads a graphic attachment and wants it to display at a certain point within their post, all they have to do is type ####attach=N#### in their post at the point at which they want the attachment to appear. (N is of course the number of the attachment in the list)
The first thing that the code does is to create an array of URLs as the attachment list is being parsed. Next, it counts the number found and for every one in that number, checks the body of the post for an ####attach=N#### command relating to it. If it finds one, it simply executes a string replacement of the command with the corresponding URL.
It's running in a heavily modified 3.4.2 but I've included it here as a code fragment of the read.php script from 3.4.3. All should be well! :)
The below is in two parts - original code and replacement code. I hope it's clear and I hope that someone will find it useful.
Many thanks
Marc
Phorum 3.4.3 read.php Line 462-
Original code here....
// exec read_header plugins
@reset($plugins['read_header']);
while(list($key,$val) = each($plugins['read_header'])) {
$val($rec_id);
}
$attachment_html='';
if ($AllowAttachments && $ForumAllowUploads == 'Y') {
$SQL="Select id, filename from $ForumTableName"."_attachments where message_id=$rec_id";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$filename="$AttachmentDir/$ForumTableName/$rec[id]".strtolower(strrchr($rec['filename'], '.'));
$size=filesize($filename);
if($size<1024) $size=1024;
$size=round($size/1024).'k';
$delim = (function_exists("apache_note")) ? "/" : "?";
if($ShowAttachments){
$attachment_html.="<a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"><img border=\"0\" src=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"></a><br />\n";
} else {
echo "$lFormAttachment: <a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\">$rec[filename]</a> ($size)<br />\n";
}
}
}
echo '<br />';
$qbody=$body;
$body=str_replace(PHORUM_SIG_MARKER, $sig, $body);
$body=format_body($body);
Replace the above with....
// exec read_header plugins
@reset($plugins['read_header']);
while(list($key,$val) = each($plugins['read_header'])) {
$val($rec_id);
}
$attachurl[]="";
$numattach=0;
$attachment_html='';
if ($AllowAttachments && $ForumAllowUploads == 'Y') {
$SQL="Select id, filename from $ForumTableName"."_attachments where message_id=$rec_id";
$q->query($DB, $SQL);
while($rec=$q->getrow()){
$filename="$AttachmentDir/$ForumTableName/$rec[id]".strtolower(strrchr($rec['filename'], '.'));
$size=filesize($filename);
if($size<1024) $size=1024;
$size=round($size/1024).'k';
$attachurl[]="<br><center><img src='$forum_url/download.$ext?finfo=$num,$rec_id,$rec[id]/$rec[filename]'></center><br>";
$delim = (function_exists("apache_note")) ? "/" : "?";
if($ShowAttachments){
$attachment_html.="<a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"><img border=\"0\" src=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\"></a><br />\n";
} else {
echo "$lFormAttachment: <a href=\"$forum_url/download.$ext$delim$num,$rec[id]/$rec[filename]\">$rec[filename]</a> ($size)<br />\n";
}
}
$numattach = count($attachurl)-1;
}
echo '<br />';
$qbody=$body;
$body=str_replace(PHORUM_SIG_MARKER, $sig, $body);
//handle attachment directives (images only)
//<!--attach=N--->
$attachloop=0;
if($numattach > 0){
while ($attachloop < $numattach){
$attachcmd = "####attach=" . trim($attachloop+1) . "####";
if(strstr($body,$attachcmd)){
$thiscmd = $attachurl[$attachloop+1];
$body = str_replace($attachcmd,$thiscmd,$body);
}
$attachloop++;
}
}
$body=format_body($body);
Sorry, you do not have permission to post/reply in this forum.