404 Tech Support

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.

Implementing this mod is much easier if you have a basic understanding of PHP and Javascript. You can learn more about php and computers at the Computer Systems Institute. The Prosilver theme is much easier to work with than the Subsilver2 theme, 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 .= '' . utf8_basename($attachment['real_filename']) . '';

Replace with:

$s_inline_attachment_options .= '' . utf8_basename($attachment['real_filename']) .  ',' . $attachment['attach_id'] . '';

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.