Hack Name: BBCode: MP3 Player v1.0

Author: GuldantheWarlock (GuldantheWarlock@xmbgarage.com)

Last Updated: May 15, 2008

Description: This hack will allow you to embed an mp3 file into your post via BBCode

Supported Version: XMB 1.9.5 Nexus Final

Notes:

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

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

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

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

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

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

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

// BBCode: MP3 Play 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:
=============

    $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.'include/swfobject.js"></script>';
    }

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

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

==================
Edit functions.php
==================

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

        $patterns[] = "#\[email=([^\"'<>]*?){1}([^\"]*?)\](.*?)\[/email\]#Smi";
        $replacements[] = '<a href="mailto:\1\2">\3</a>';
        
==========
Add Below:
==========

        $patterns[] = "#\[mp3\]([a-z]+?://){1}([^\"'<>]*?)\[/mp3\]#Smie";
        $replacements[] = 'bbcode_mp3(\'$1$2\')';
        
=====
Find:
=====

/**
* createAbsFSizeFromRel() - calculates the absolute font-size from a relative
*
* This functions takes a relative font-size modifier (eg. +3 or -1) and returns an
* adjusted absolute fontsize (eg. +3 with a base-font-size of 10pt becomes 13pt).
* This function is unit-aware
*
* @param	$rel	integer,	relative size provided
* @return			string,		the absolute size (with a unit)
*/
function createAbsFSizeFromRel($rel) {
    global $fontsize;
    static $cachedFs;

    if (!is_array($cachedFs) || count($cachedFs) != 2) {
        preg_match('#([0-9]+)([a-z]+)?#i', $fontsize, $res);
        $cachedFs[0] = $res[1];
        $cachedFs[1] = $res[2];

        if (empty($cachedFs[1])) {
            $cachedFs[1] = 'px';
        }
    }

    $o = ($rel+$cachedFs[0]).$cachedFs[1];
    //echo $o;
    return $o;
}

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

/**
 * bbcode_mp3() - Create embed code for an mp3
 *
 * This function creates the SWFObject JS code to embed
 * the mp3 flash player into the post. It generates a
 * unique id for each player to allow multiple MP3s per
 * post.
 *
 * @param    $path    string,    String path to the mp3
 * @return            string,    The compiled JS code.
 */
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));
}

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

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

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

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

function underline() {
      if (helpmode) {
        alert(bbcode_help_underline);
    }else if (advmode) {
        AddText('', '', "[u] [/u]", messageElement);

    }else {
        txt=prompt(bbcode_prompt_underline,"Text");
        if (txt!=null) {
            AddText('', '', "[u]"+txt+"[/u]", messageElement);
        }
    }
}

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

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);
        }
    }
}

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

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

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

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

function underline() {
    if(helpmode) {
        alert(bbcode_help_underline);

    } else if(advmode) {
        if(hasSelection(messageElement)) {
            wrapText('[u]', '[/u]', messageElement);
        } else {
            AddText('[u]', '[/u]', ' ', messageElement);
        }

    } else {
        if(hasSelection(messageElement)) {
            text = prompt(bbcode_prompt_underline, fetchSelection(messageElement));
            if(text == fetchSelection(messageElement)) {
                wrapText('[u]', '[/u]', messageElement);
            } else if(text == null) {
                return;
            } else {
                AddText('[u]', '[/u]', text, messageElement);
            }
        } else {
            text = prompt(bbcode_prompt_underline, 'Text');
            if(text == null) {
                return;
            } else {
                AddText('[u]', '[/u]', text, messageElement);
            }
        }
    }
}

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

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);
		}
	}
}

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

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

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

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

function underline() {
      if (helpmode) {
        alert(bbcode_help_underline);
    }else if (advmode) {
        AddText('', '', "[u] [/u]", messageElement);

    }else {
        txt=prompt(bbcode_prompt_underline,"Text");
        if (txt!=null) {
            AddText('', '', "[u]"+txt+"[/u]", messageElement);
        }
    }
}

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

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);
        }
    }
}

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

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

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

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

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

var bbcode_help_underline   = "$lang[bbcode_help_underline]";
var bbcode_prompt_underline = "$lang[bbcode_prompt_underline]";

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

var bbcode_help_mp3   = "$lang[bbcode_help_mp3]";
var bbcode_prompt_mp3 = "$lang[bbcode_prompt_mp3]";

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

=======
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="$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 include folder.
Upload the included 'bb_mp3.gif' from the Contents folder to your forum's theme directories.

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

Enjoy!