Hack Name: BB Code: MP3 Player v1.0

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Last Updated: May 1, 2009

Description: This modification will allow you to embed an mp3 file into your post via BB Code

Supported Version: XMB 1.9.8 SP3

Updated for 1.9.8 by: WormHole @ XMB Garage

Notes:

This modification makes use of the JW FLV Media Player found at http://www.jeroenwijering.com/

This modification is released under the GPL. You should have recieved a copy of it with this software package.

Please backup your files before installing this modification. Neither XMBGarage nor the author can be held responsible if your board stops functioning properly due to you installing this modification.

=======================================================================================================

=======
Step 1:
=======

====================
Edit lang/English.lang.php:
====================

==============
Add to end of file:
==============

// BBCode: MP3 Player Mod Begin
$lang['bbcode_help_mp3'] = "MP3 tag\\nEmbeds an mp3 file.\\nUsage: [mp3]url of file[/mp3]";
$lang['bbcode_prompt_mp3'] = "Please enter the URL of the MP3 file you would like to link to.";
$lang['cb_insert_mp3'] = "Embed MP3 file";
// BBCode: MP3 Player Mod End

=======================================================================================================

=======
Step 2:
=======

=============
Edit header.php
=============

======
Find:
======

// additional CSS to load?
if (file_exists($imgdir.'/theme.css')) {
    $cssInclude = '<style type="text/css">'."\n"."@import url('".$imgdir."/theme.css');"."\n".'</style>';
} else {
    $cssInclude = '';
}
    
============
Replace With:
============

// additional CSS to load?
$cssInclude = '';
if (file_exists($imgdir.'/theme.css')) {
    $cssInclude = '<style type="text/css">'."\n"."@import url('".$imgdir."/theme.css');"."\n".'</style>';
}
if (isset($tid) && is_numeric($tid) && (int) $tid > 0) {
    $cssInclude .= "\n".'<script type="text/javascript" src="'.ROOT.'js/swfobject.js"></script>';
}

=======================================================================================================

=======
Step 3:
=======

====================
Edit include/functions.php
====================

======
Find:
======

        $replacements[] = '<a href="mailto:\1\2">\3</a>';
        
==========
Add Below:
==========

        // BB Code: MP3 Player Mod Begin
        $patterns[] = "#\[mp3\]([a-z]+?://){1}([^\"'<>]*?)\[/mp3\]#Smie";
        $replacements[] = 'bbcode_mp3(\'$1$2\')';
        // BB Code: MP3 Player Mod End

======
Find:
======

function createAbsFSizeFromRel($rel) {

===========
Add Above:
===========

// BB Code: MP3 Player Mod Begin
function bbcode_mp3($path) {
    global $thisbg, $THEME;
    
    $rand = md5(uniqid(mt_rand()));
    
    $mp3embed   = array();
    $mp3embed[] = '<div id="mp3player'.$rand.'"></div>';
    $mp3embed[] = '<script language="JavaScript" type="text/javascript">';
    $mp3embed[] = "var so = new SWFObject('".ROOT."include/mediaplayer.swf', 'mpl', '470', '20', '8');";
    $mp3embed[] = "so.addParam('allowscriptaccess', 'always');";
    $mp3embed[] = "so.addParam('allowfullscreen', 'true');";
    $mp3embed[] = "so.addVariable('height', '20');";
    $mp3embed[] = "so.addVariable('width', '470');";
    $mp3embed[] = "so.addVariable('file', '$path');";
    $mp3embed[] = "so.addVariable('backcolor',   '0x".(($thisbg == $THEME['altbg2']) ? $THEME['altbg1'] : $THEME['altbg2'])."');";
    $mp3embed[] = "so.addVariable('frontcolor',  '0x".$THEME['tabletext']."');";
    $mp3embed[] = "so.addVariable('lightcolor',  '0x".$THEME['link']."');";
    $mp3embed[] = "so.addVariable('screencolor', '0xFFFFFF');";
    $mp3embed[] = "so.write('mp3player".$rand."');";
    $mp3embed[] = '</script>';
    $mp3embed[] = '<br />';
    $mp3embed[] = '<span><a href="'.$path.'">Click here to download</a></span>';
    
    return str_replace('0x#', '0x', implode('', $mp3embed));
}
// BB Code: MP3 Player Mod End

=======================================================================================================

=======
Step 4:
=======

=================
Edit js/bbcodefns-ie.js
=================

======
Find:
======

function storeCaret(textEl) {

===========
Add Above:
===========

// BB Code: MP3 Player Mod Begin
function mp3() {
    if (helpmode) {
        alert(bbcode_help_mp3);
    } else if (advmode) {
        AddText('', '', "[mp3] [/mp3]", messageElement);
    } else {
        var txt = prompt(bbcode_prompt_mp3, "myfile.mp3");
        if (txt != null) {
            AddText('', '', "[mp3]"+txt+"[/mp3]", messageElement);
        }
    }
}
// BB Code: MP3 Player Mod End

=======================================================================================================

=======
Step 5:
=======

=====================
Edit js/bbcodefns-mozilla.js
=====================

=====
Find:
=====

function storeCaret() {

===========
Add Above:
===========

// BB Code: MP3 Player Mod Begin
function mp3() {
    if (helpmode) {
        alert(bbcode_help_mp3);
    } else if (advmode) {
        if (hasSelection(messageElement)) {
            wrapText('[mp3]', '[/mp3]', messageElement);
        } else {
            AddText('[mp3]', '[/mp3]', ' ', messageElement);
        }

    } else {
        if (hasSelection(messageElement)) {
            var text = prompt(bbcode_prompt_mp3, fetchSelection(messageElement));
            if (text == fetchSelection(messageElement)) {
                wrapText('[mp3]', '[/mp3]', messageElement);
            } else {
                AddText('[mp3]', '[/mp3]', text, messageElement);
            }
        } else {
            var text = prompt(bbcode_prompt_mp3, 'myfile.mp3');
            AddText('[mp3]', '[/mp3]', text, messageElement);
        }
    }
}
// BB Code: MP3 Player Mod End

=======================================================================================================

=======
Step 6:
=======

========================
Edit include/bbcodefns-opera.js
========================

======
Find:
======

function storeCaret(textEl) {

==========
Add Below:
==========

// BB Code: MP3 Player Mod Begin
function mp3() {
    if (helpmode) {
        alert(bbcode_help_mp3);
    } else if (advmode) {
        AddText('', '', "[mp3] [/mp3]", messageElement);

    } else {
        var txt = prompt(bbcode_prompt_mp3, "myfile.mp3");
        if (txt != null) {
            AddText('', '', "[mp3]"+txt+"[/mp3]", messageElement);
        }
    }
}
// BB Code: MP3 Player Mod End

=======================================================================================================

=======
Step 7:
=======

=========================
Go to Admin Panel -> Templates
=========================

========================
Edit template: functions_bbcode
========================

=====
Find:
=====

var bbcode_prompt_underline = "$lang[bbcode_prompt_underline]";

==========
Add Below:
==========

// BB Code: MP3 Player Mod Begin
var bbcode_help_mp3 = "$lang[bbcode_help_mp3]";
var bbcode_prompt_mp3 = "$lang[bbcode_prompt_mp3]";
// BB Code: MP3 Player Mod End

=======================================================================================================

=======
Step 8:
=======

=========================
Go to Admin Panel -> Templates
=========================

===========================
Edit template: functions_bbcodeinsert
===========================

======
Find:
======

<a href="javascript:list()"><img src="$imgdir/bb_list.gif" border="0" width="23" height="22" alt="$lang[cb_insert_list]" /></a></td>

============
Replace With:
============

<a href="javascript:list()"><img src="$imgdir/bb_list.gif" border="0" width="23" height="22" alt="$lang[cb_insert_list]" /></a>
<a href="javascript:mp3();"><img src="$THEME[imgdir]/bb_mp3.gif" border="0" width="22" height="22" alt="$lang[cb_insert_mp3]" /></a></td>

=======================================================================================================

=======
Step 9:
=======

Upload the included 'mediaplayer.swf' and 'swfobject.js' from the Contents folder to your forum's js folder.
Upload the included 'bb_mp3.gif' from the Contents folder to your forum's theme directories.

=======================================================================================================
Enjoy!