Back to vBulletin 3.0 Add-Ons

[attachment]id[/attachment] BBcode
Mod Version: 1.00, by Benjy

This modification is in the archives.
vB Version: 3.0.3 Rating: (1 vote - 5.00 average) Installs: 8
Released: 19 Aug 2004 Last Update: Never Downloads: 11
Not Supported Template Edits Code Changes Additional Files Re-usable Code Translations  

What it does
This hack is a "clone" of the IPB [attachmentid=xxx] BBcode feature. It allows you to insert anywhere in your posts a link to an attachment, using its ID (therefore making it an inline attachment). It also detects the file type and shows either the thumbnail (with a link to the full image), the full image or a text link.
If the attachment doesn't exist or has been moderated, nothing will be shown.
By the way, maybe this should be a VB feature?


What is required
- 1 PHP file edit ("includes/functions_showthread.php")
- 1 CSS style edit
- 1 image upload ("images/misc/inlineattach.gif")


What can be done
- hide the [attachment] BBcode in the search results page
- handle (hide?) the [attachment] BBcode in the printable version
- handle (hide?) the [attachment] BBcode in the archive


Notes
- This hack will add 1 query per attachment BBcode, and the usual amount of queries for the "attachment.php" file call in case of a thumbnail or an inline image.
- The "howto.txt" is provided because it includes the indented code that VB loses with PHP and CODE tags.
- The PSD of the image is provided for personal editing.
- The french version of the image is provided (don't forget to rename it).
- This is my first released hack, so please be cool


Support
I may not be able to provide support for this hack.


Howto (also provided in "howto.txt")
1. Open "includes/functions_showthread.php".

2. Go to (around line 604):
PHP Code:
    $post['message'] = parse_bbcode($post['pagetext'], $forum['forumid'], $post['allowsmilie']);

Add below:
PHP Code:
 //ATTACHMENT BBCODE HACK BEGIN
$post['message'] = preg_replace_callback('#\[attachment\]\s*(\d+)\s*\[/attachment\]#siU''attachment_bbcode_callback'$post['message']);
//ATTACHMENT BBCODE HACK END 
3. Go to (at the end of the file):
PHP Code:
 return "$prepend$text";

Add below:
PHP Code:
//ATTACHMENT BBCODE HACK BEGIN
// ###################### Start attachment_bbcode_callback #######################
function attachment_bbcode_callback($matches)
{
global 
$DB_site$vboptions$bbuserinfo$session$stylevar;
 
$matches[1] = intval($matches[1]);
 
if (!
$vboptions['attachthumbs'] AND !$vboptions['viewattachedimages'])
{
return 
'';
}
else
{
$attachment $DB_site->query_first("
SELECT attachmentid, filename, filesize, IF(thumbnail = '', 0, 1) AS hasthumbnail, thumbnail_filesize, visible
FROM attachment
WHERE attachmentid = " 
$matches[1] . "
"
);
 
if (
$attachment['attachmentid'])
{
if(
$attachment['thumbnail_filesize'] == $attachment['filesize'])
{
    
$attachment['hasthumbnail'] = 0;
    
$attachment['forceimage'] = 1;
}
$attachment['filename'] = fetch_censored_text(htmlspecialchars_uni($attachment['filename']));
$attachment['attachmentextension'] = strtolower(file_extension($attachment['filename']));
$attachment['filesize'] = vb_number_format($attachment['filesize'], 1true);
if (
$attachment['visible'])
{
    switch(
$attachment['attachmentextension'])
    {
     case 
'gif':
     case 
'jpg':
     case 
'jpeg':
     case 
'jpe':
     case 
'png':
     case 
'bmp':
     if (!
$bbuserinfo['showimages'])
     {
     return 
'<img src="' $stylevar['imagesfolder'] . '/attach/' $attachment['attachmentextension'] . '.gif" alt="" title="" width="16" height="16" border="0" /> <a href="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '" target="_blank">' $attachment['filename'] . '</a> (' $attachment['filesize'] . ')';
     }
     else if (
$vboptions['attachthumbs'])
     {
     if (
$attachment['hasthumbnail'])
     {
        return 
'<a href="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '" target="_blank"><img src="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '&stc=1&thumb=1" border="0" alt="' $attachment['filename'] . '" title="' $attachment['filename'] . '" class="inlineattach" /></a>';
     }
     else if (
$attachment['forceimage'])
     {
        return 
'<img src="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '&stc=1" border="0" alt="' $attachment['filename'] . '" title="' $attachment['filename'] . '" class="attach" />';
     }
     else
     {
        return 
'<img src="' $stylevar['imagesfolder'] . '/attach/' $attachment['attachmentextension'] . '.gif" alt="" title="" width="16" height="16" border="0" /> <a href="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '" target="_blank">' $attachment['filename'] . '</a> (' $attachment['filesize'] . ')';
     }
     }
     else if (
$vboptions['viewattachedimages'] == OR ($vboptions['viewattachedimages'] == AND $attachcount == 1))
     {
     return 
'<img src="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '&stc=1" border="0" alt="' $attachment['filename'] . '" title="' $attachment['filename'] . '" class="attach" />';
     }
     else
     {
     return 
'<img src="' $stylevar['imagesfolder'] . '/attach/' $attachment['attachmentextension'] . '.gif" alt="" title="" width="16" height="16" border="0" /> <a href="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '" target="_blank">' $attachment['filename'] . '</a> (' $attachment['filesize'] . ')';
     }
     break;
     default:
     return 
'<img src="' $stylevar['imagesfolder'] . '/attach/' $attachment['attachmentextension'] . '.gif" alt="" title="" width="16" height="16" border="0" /> <a href="attachment.php?' $session['sessionurl'] . 'attachmentid=' $attachment['attachmentid'] . '" target="_blank">' $attachment['filename'] . '</a> (' $attachment['filesize'] . ')';
    }
}
else
{
    return 
'';
}
}
else
{
return 
'';
}
}
}
//ATTACHMENT BBCODE HACK END 
4. Save and upload "includes/functions_showthread.php".

5. Upload "inlineattach.gif" in "images/misc/".

6. Edit your style(s) Main CSS, and add this to your additional CSS (bottom of the page):
Code:
img.inlineattach {
background-color: #336699;
background-image: url('images/misc/inlineattach.gif');
background-position: bottom right;
background-repeat: no-repeat;
margin: 0px 2px 0px 0px 0px;
padding: 2px 2px 14px 2px;
}
(NB: #336699 is the background color of "inlineattach.gif")


Usage
[attachment]id[/attachment]


Demo
Have a look at the attached screenshots.

Download

This modification is archived and cannot be downloaded.

Screenshots

   


vblts.ru supports vBulletin®, 2022-2024