|
From: FlorinCB <ory...@us...> - 2008-09-09 10:39:14
|
Update of /cvsroot/mxbb/mx_music/music_box/includes In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6810/music_box/includes Modified Files: music_functions.php Log Message: emoticons added in comments Index: music_functions.php =================================================================== RCS file: /cvsroot/mxbb/mx_music/music_box/includes/music_functions.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** music_functions.php 9 Sep 2008 06:54:12 -0000 1.4 --- music_functions.php 9 Sep 2008 10:38:32 -0000 1.5 *************** *** 353,356 **** --- 353,478 ---- } + /** + * Rewritten by Nathan Codding - Feb 6, 2001. + * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking + * to that URL + * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking + * to http://www.xxxx.yyyy[/zzzz] + * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking + * to that email address + * - Only matches these 2 patterns either after a space, or at the beginning of a line + * + * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe + * have it require something like xx...@yy... or such. We'll see. + * We can add here more phpBB3 stuff in time - Ory + */ + function music_make_clickable($text) + { + $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text); + + // pad it with a space so we can match things at the start of the 1st line. + $ret = ' ' . $text; + + // matches an "xxxx://yyyy" URL at the start of a line, or after a space. + // xxxx can only be alpha characters. + // yyyy is anything up to the first space, newline, comma, double quote or < + $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret); + + // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing + // Must contain at least 2 dots. xxxx contains either alphanum, or "-" + // zzzz is optional.. will contain everything up to the first space, newline, + // comma, double quote or <. + $ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret); + + // matches an email@domain type address at the start of a line, or after a space. + // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". + $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); + + // Remove our padding.. + $ret = substr($ret, 1); + + return($ret); + } + + /** + * phpBB Smilies pass. + * + * Hacking smilies_pass from phpbb/includes/bbcode.php + * + * @param string $message + * @return string + * + */ + function music_smilies_pass($message) + { + static $orig, $repl; + global $board_config, $mx_root_path, $phpbb_root_path, $phpEx; + + switch (PORTAL_BACKEND) + { + case 'internal': + $smiley_path_url = PHPBB_URL; //change this to PORTAL_URL when shared folder will be removed + $smiley_root_path = $phpbb_root_path; //same here + $smiley_url = 'smile_url'; + $smiley_id = 'smilies_id'; + $emotion = 'emoticon'; + break; + case 'phpbb2': + $smiley_path_url = PHPBB_URL; + $smiley_root_path = $phpbb_root_path; + $smiley_url = 'smile_url'; + $smiley_id = 'smilies_id'; + $emotion = 'emoticon'; + break; + case 'phpbb3': + $smiley_path_url = PHPBB_URL; + $smiley_root_path = $phpbb_root_path; + $smiley_url = 'smiley_url'; + $smiley_id = 'smiley_id'; + $emotion = 'emotion'; + $board_config['smilies_path'] = str_replace("smiles", "smilies", $board_config['smilies_path']); + break; + } + + //$smilies_path = $board_config['smilies_path']; + //$board_config['smilies_path'] = $smiley_path_url . $board_config['smilies_path']; + + if (!isset($orig)) + { + global $db; + $orig = $repl = array(); + + $sql = 'SELECT * FROM ' . SMILIES_TABLE; + if( !$result = $db->sql_query($sql) ) + { + mx_message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql); + } + + $smilies = $db->sql_fetchrowset($result); + + if (count($smilies)) + { + @usort($smilies, 'smiley_sort'); + } + + for ($i = 0; $i < count($smilies); $i++) + { + $orig[] = "/(?<=.\W|\W.|^\W)" . preg_quote($smilies[$i]['code'], "/") . "(?=.\W|\W.|\W$)/"; + $repl[] = '<img src="' . $smiley_path_url . $board_config['smilies_path'] . '/' . $smilies[$i][$smiley_url] . '" alt="' . $smilies[$i][$emotion] . '" border="0" />'; + } + } + + if (count($orig)) + { + $message = preg_replace($orig, $repl, ' ' . $message . ' '); + $message = substr($message, 1, -1); + } + + //$board_config['smilies_path'] = $smilies_path; + + return $message; + } + + // ---------------------------------------------------------------------------- |