Ask 404TS: How do I expand your phpBB mods to work for the Subsilver2 theme?
I’ve written two unofficial mods for phpBB3 forums previously that worked very well for those using the Prosilver theme, the MP3 inline attachment mod and the FLV inline attachment mod. Recently, I was asked in the forums how to make them work for the Subsilver2 theme, the other popular theme that many styled themes are based on. After puzzling on it for a long time and decoding the makeup of the Subsilver2 theme, I figured out a way to make it reliably work. Installing this mod will allow you to place inline .flv or .mp3 files to be played streaming with a simple Flash player.
The Prosilver theme is much easier to work with, particularly with the part I am modifying, because it builds the command it directly wants to call from an array of variables. For example, this button is built with the Javascript variables Value1 and Value2:
<input type="button" value="{L_PLACE_INLINE}" onclick="attach_inline({Value1}, '{Value2}');" />
and I’m able to just add a third comma-separated value in there with the info I need.
Whereas with the Subsilver 2 theme, it seems to cheat a bit. It uses the information to build a drop-down box and the ‘Place Inline’ button then derives the information from the drop-down box for the attachment index. To get by this, we’re going to have to pass along the attachment ID in with the Filename and then split it apart later in the process.
Just like the Prosilver version of these mods, we only have two files to edit, although they are different files. To append the attachment ID onto the filename, we’ll need to open:
phpBBroot/includes/functions_posting.php
Find:
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>'; |
Replace with:
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . ',' . $attachment['attach_id'] . '</option>'; |
The attachment ID and a comma are being appended to the usual drop-down option box code. This means, your end users will see the attachment ID in the drop-down and we’ll split the values apart later along the comma.
To do that, we need to open:
phpBBroot/styles/subsilver2/template/editor.js
Find:
/** * Add inline attachment at position */ function attach_inline(index, filename) { insert_text('[attachment=' + index + ']' + filename + '[/attachment]'); document.forms[form_name].elements[text_name].focus(); } |
Replace with:
/** * Add inline attachment at position */ function attach_inline(index, filenameID) { var splitresults = filenameID.split(","); var filename = splitresults[0]; var attach_id = splitresults[1]; if (filename.match(".mp3")) { insert_text('[mp3]' +'http://yourforumURL.com/download/file.php?id=' + attach_id +'[/mp3]'+' ' + filename); document.forms[form_name].elements[text_name].focus(); } else if (filename.match(".flv")) { insert_text('[flv]' +'http://yourforumURL.com/download/file.php?id=' + attach_id +'.flv[/flv]'); document.forms[form_name].elements[text_name].focus(); } else { insert_text('[attachment=' + index + ']' + filename + '[/attachment]'); document.forms[form_name].elements[text_name].focus(); } } |
In the above code, don’t forget to update the yourforumURL.com path to be your domain name.
As long as you have the MP3 and FLV BBCodes and the players on your server, which you can find in the previous articles, you should be all set.
If you’re running a board where Prosilver and Subsilver2 themes might be in mixed company, you’ll need to use the top eight lines in the editor.js file under the prosilver template directory.
Because of complications like this when running a phpBB board with multiple styles, I don’t have a demo to show. You can see it working in Prosilver in the comments.
Comment on this post in our forums
Related posts:



February 23rd, 2010 at 7:01 PM
Hi thanks for your awesome mod! It is exactly what i was looking for. I am also using a Subsilver2 based theme, but for some strange reason when i upload a file now i get this error:
Fatal error: Call to undefined function utf8_basename() in /home2/dubstepr/public_html/glitchhopforum/includes/functions_posting.php on line 755
This references the line which we modified in Functions Posting in your instructions. I googled and found out that utf8_basename() is defined in includes/utf/utf_tools.php. Would it be possible that because my theme is a modification of Subsilver, that somehow this utf_tools file is not being included? Is there a way to manually include it? Is this even the root of the problem?
Please help!
Thanks,
dewey
February 23rd, 2010 at 9:26 PM
Hey dewey,
Since the utf8_basename() function is used in the line before the edits, I’m inclined to look elsewhere. The most likely culprit in my opinion is that a quote or double-quote or parentheses is missing from the edit. I’d recommend trying it again and see if that changes things. Can you copy in line 755 before and after the edit here to the forum? I’ll check it out and I’m curious to see the code since you said it’s a variant of subsilver2.
phpBBroot/includes/functions_posting.php
Before:
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . '</option>';After:
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . ',' . $attachment['attach_id'] . '</option>';February 25th, 2010 at 7:23 PM
Hey thanks for the quick reply, here is the the whole function. My theme is Melankolia, and i’m using phpbb 3.0.4
(edited, cause i posted the code wrong the first time)
/*** Assign Inline attachments (build option fields)
*/
function posting_gen_inline_attachments(&$attachment_data)
{
global $template;
if (sizeof($attachment_data))
{
$s_inline_attachment_options = '';
foreach ($attachment_data as $i => $attachment)
{
$s_inline_attachment_options .= '<option value="' . $i . '">' . utf8_basename($attachment['real_filename']) . ',' . $attachment['attach_id'] . '</option>';
}
$template->assign_var('S_INLINE_ATTACHMENT_OPTIONS', $s_inline_attachment_options);
return true;
}
return false;
}
Don’t know if it is any help, but i don’t actually see a "embed inline" button, or dropdown box at all. here is a screen shot from my forum:

And once that file upload reaches 100% it reloads to this page:
http://glitchhopforum.com/posting.php?m … 360782459a
and i get the same error:
Fatal error: Call to undefined function utf8_basename() in /home2/dubstepr/public_html/glitchhopforum/includes/functions_posting.php on line 755cheers,
dewey
February 27th, 2010 at 7:00 AM
Not seeing the Place Inline button is normal. You won’t see that until you have a file uploaded.
The next steps I would recommend are:
Enable subsilver2
Switch that to be your personal theme (doesn’t have to be your boards theme)
Implement the mod in Subsilver2 and get that to work
That will give you a better understanding of the mod and the themes. Once you have that done, you might be able to see what’s missing for the Melankolia theme.
March 2nd, 2010 at 1:24 AM
Success! I’ve discovered the root of the problem was with an outdated version of files in the UTF folder. (i’m still using an older version of phpbb3)
After reading: http://www.phpbb.com/community/viewtopi … 95&start=0
I replaced my UTF folder with all the files from PHPBB 3.0.7
Instantly my utf8 error went away
Thanks for your help & your mod!
March 2nd, 2010 at 5:44 AM
Cool! Thanks for coming back and sharing how you made it work.