Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //////////////////////////////////////////////////////////////
- // Legal Notice //
- // //
- // The contents of this file are copyrighted and are the //
- // sole property of Ryan Schoen. Any unauthorized //
- // duplication, distribution, or reproduction will //
- // constitute an infringement of copyright. By editing this //
- // file, you agree that all contributions and modifications //
- // to its contents become the sole property of Ryan Schoen. //
- // //
- // (c) Copyright 2006 Ryan Schoen. All rights reserved. //
- //////////////////////////////////////////////////////////////
- function deZero($string) //string
- {
- $string = preg_replace("/\.([^0]*)0+$/",".\\1",$string);
- $string = preg_replace("/\.$/","",$string);
- return $string;
- }
- function format($text,$style) //string
- {
- if($style & FORMAT_REMOVE_HTML)
- {
- $text = htmlentities($text,ENT_QUOTES);
- }
- if($style & FORMAT_ADD_SLASHES)
- {
- $text = addslashes($text);
- }
- if($style & FORMAT_RXML_FORMATTING)
- {
- $find = array (
- '/\[li\](.*)\n?/',
- '/\n/',
- '/ /',
- '/\[b\]/',
- '/\[i\]/',
- '/\[u\]/',
- '/\[s\]/',
- '/\[center\]/',
- '/\[\/b\]/',
- '/\[\/i\]/',
- '/\[\/u\]/',
- '/\[\/s\]/',
- '/\[\/center\]/',
- '/\[color=(.*?)\]/',
- '/\[\/color\]/',
- '/arsenal/');
- $replace = array (
- '<li class=forum>$1</li>',
- '<br>',
- ' ',
- '<b>',
- '<i>',
- '<u>',
- '<s>',
- '<center>',
- '</b>',
- '</i>',
- '</u>',
- '</s>',
- '</center>',
- '<font color=\'\\1\'>',
- '</font>',
- 'arsenal');
- $text = preg_replace($find,$replace,$text);
- /*global $loggedid;
- if(!empty($loggedid))
- {
- $find = array ('/\[id\]/', '/\[name\]/');
- $replace = array ($loggedid, getName($loggedid));
- $text = preg_replace($find,$replace,$text);
- }*/
- $find = array( '/\[([^\]]+)\[([^\]]+)\]([^\]]+)\]/');//, '/\[([^\]]+)\]([^\]]+)\]/');
- $replace = array( '[\\1[\\2]\\3]');//, '[\\1]\\2]');
- do {
- $text = preg_replace($find,$replace,$text,-1,$count);
- } while($count > 0);
- }
- if($style & FORMAT_SMILIES)
- {
- $find = array (
- '/(:-?\))/',
- '/(t\(\-_\-\(t)/',
- '/(:-?\|)/',
- '/(:-?\()/',
- '/(: -?(P|p))/',
- '/(;-?\))/',
- '/:-?(\\\|\/)([^\/])/',
- '/(:-?(D|d))/',
- "/(:\*\()/",
- '/(((o\.O)|(O\.o)))/',
- '/(\^_\^)/',
- '/(:-?X)/i' );
- $replace = array (
- smiley('happy'),
- smiley('tease'),
- smiley('blah'),
- smiley('sad'),
- smiley('tongue'),
- smiley('wink'),
- smiley('unsure')."\\2",
- smiley('laugh'),
- smiley('cry'),
- smiley('oO'),
- smiley('^_^'),
- smiley('mute') );
- $text = preg_replace($find,$replace,$text);
- }
- if($style & FORMAT_LINKS)
- {
- // Linking
- $find = array (
- '/\[(link|url)=(http:[^\s]*?)\](.*?)\[\/(link|url)\]/',
- '/\[(\d+)\]/e',
- '/\[(house|id)=(\d+)\]([^\[]+)\[\/(id|house)\]/e',
- '/\[pm=(\d+)\]([^\[]+)\[\/pm\]/e',
- '/\[post=(\d+)\]([^\[]+)\[\/post]/e',
- '/\[tos=([0-9IVX\.]+)\]/e',
- '/\[clan=(\d+)\]([^\[]+)\[\/clan\]/e' );
- $replace = array (
- '<a href="link.php?address=\\2" title="Link: \\2" target=_blank>\\3</a>',
- 'linkToID(\\1)',
- 'linkTo("house.php?id=\\2","\\3")',
- 'linkTo("pm.php?action=form&id=\\1","\\2")',
- 'linkTo("posts.php?postid=\\1","\\2")',
- 'linkTo("tos.php?section=\\1","ToS - Section \\1")',
- 'linkTo("lodge.php?action=details&clan=\\1","\\2")');
- $text = preg_replace($find,$replace,$text);
- //$text = preg_replace('/\[out=([^\]]*?)\](.*?)\[\/out\]/','<a href="out.php?$1" target=_blank>$2</a>',$text);
- }
- if($style & FORMAT_PICTURES)
- {
- $find = array (
- '/\[img=http:([^\s]*?\.(gif|jpg|jpeg|png|bmp|tif|tiff))\]/',
- '/(pwned\.)/i');
- $replace = array (
- '<img src="http:\\1">',
- '<img src=img/pwned.gif old=\\1>' );
- $text = preg_replace($find,$replace,$text);
- }
- if($style & FORMAT_DYNAMIC_LINKS)
- {
- $text = formatNews($text);
- }
- if($style & FORMAT_SPELLCHECK)
- {
- $text = spellcheck($text);
- }
- if($style & FORMAT_REMOVE_LISTS)
- {
- $text = preg_replace("/<\/li>/","<br>",$text);
- $text = preg_replace("/<li[^>]*>/"," - ",$text);
- $text = preg_replace("/<\/?b>/","",$text);
- }
- return $text;
- }
- function showBar($color1,$color2,$percent1) //string
- {
- $percent2 = round((100 - $percent1),0);
- $percent1 = round($percent1,0);
- return "<img src=img/$color1.jpg width=$percent1 height=7><img src=img/$color2.jpg width=$percent2 height=7>";
- }
- function smiley($smiley) //string
- {
- global $loggedid;
- static $smileypreference;
- if(empty($smileypreference) && !empty($loggedid)) $smileypreference = getSetting($loggedid,SETTING_SMILEY_PREFERENCE);
- if(!empty($loggedid) AND $smileypreference == "x2") $string = "<img class=smileyold src=img/smileys/".$smiley."_old.gif old=\\1>";
- else $string = "<img class=smiley src=img/smileys/$smiley.gif old=\\1>";
- return $string;
- }
- function roundDown($number,$precision=0) //float
- {
- if(!is_numeric($number)) error("Trying to round non-numeric number.");
- $number = preg_replace("/\.([0-9]{".$precision."}).*$/",".$1",$number);
- $number = deZero($number);
- return $number;
- }
- function is_number($number,$allownegative=false,$allowdecimal=false) //bool
- {
- if($allowdecimal == true) return is_numeric($number);
- elseif($allownegative == true) return ereg("^-?[0-9]+$",$number);
- else return ereg("^[0-9]+$",$number);
- }
- function pages($url,$pages,$page,$separator=" ") //string
- {
- if(!is_number($pages)) error("Invalid number of pages!");
- if(!is_number($page)) error("Invalid current page!");
- if($pages <= 1) return;
- $return = "Page: ";
- for($i=1; $i<=$pages; $i++)
- {
- if($i == $page) $return .= "$i$separator";
- else
- {
- $newurl = $url;
- if(ereg("\?",$url)) $newurl = "$url&page=$i";
- else $newurl = "$url?page=$i";
- $return .= linkTo($newurl,"$i$separator");
- }
- }
- $return = preg_replace("/$separator$/","",$return);
- return $return;
- }
- function filter($text,$popup=true) //string
- {
- global $loggedid,$global,$curses,$notcurses;
- static $filter;
- if(!empty($loggedid))
- {
- if(!isset($filter[$loggedid])) $filter[$loggedid] = getSetting($loggedid,SETTING_FILTER);
- if(!$filter[$loggedid]) return $text;
- }
- $replacedcurses = array();
- foreach($notcurses as $notcurse)
- {
- if(eregi($notcurse,$text))
- {
- $letters = preg_split("//",$notcurse,-1,PREG_SPLIT_NO_EMPTY);
- $find = $replace = '';
- $i = 0;
- foreach($letters as $letter)
- {
- $i++;
- $find .= "($letter)";
- $replace .= "\\$i.";
- }
- $replace = substr($replace,0,strlen($replace)-1);
- $text = preg_replace("/$find/",$replace,$text);
- $replacedcurses[$notcurse] = $letters;
- }
- }
- global $curses;
- foreach($curses as $word) {
- $word = base64_decode($word);
- $replacement = str_repeat("*",strlen($word));
- if($popup) $replacement = "<a href='javascript:void(0)' style='text-decoration: none' title='$word' onMouseOver=\"window.status='Filtered'; return true\" onMouseOut=\"window.status=''; return true\"><font color=white>$replacement</font></a>";
- $text = preg_replace("/$word/i",$replacement,$text);
- }
- foreach($replacedcurses as $replacedcurse => $letters)
- {
- $find = $replace = '';
- foreach($letters as $letter)
- {
- $find .= "$letter\\.";
- $replace .= $letter;
- }
- $find = substr($find,0,strlen($find)-2);
- $text = preg_replace("/$find/",$replace,$text);
- }
- return $text;
- }
- function button($text,$link) //string
- {
- return "<input type=button value=\"$text\" onClick=\"window.location='".encodeURL($link)."'\">";
- }
- function getNumberOfCurses($text) //int
- {
- global $curses;
- $numberOfCurses = 0;
- foreach($curses as $curse)
- {
- $curse = base64_decode($curse);
- $pos = -1;
- while(1)
- {
- $pos = strpos($text,$curse,$pos+1);
- if($pos === FALSE) break;
- $numberOfCurses++;
- }
- }
- return $numberOfCurses;
- }
- function forumPopup($popup)
- {
- if(strlen($popup) > FORUM_PREVIEW_LENGTH) $popup = substr($popup,0,FORUM_PREVIEW_LENGTH-3)."...";
- $popup = filter(format($popup,FORMAT_POPUP),false);
- if(strpos($_SERVER['HTTP_USER_AGENT'],'ie') ==! 0) $popup = stri_replace("/<br>/","\n",$popup);
- return $popup;
- }
- function spellcheck($text)
- {
- global $loggedid;
- if(empty($loggedid)) $dialect = DIALECT_AMERICAN;
- else $dialect = getSetting($loggedid,SETTING_SPELLCHECK_DIALECT);
- $origtext = $text;
- $text = strip_tags($text);
- $dictionary = pspell_new("en",$dialect,"","",PSPELL_FAST);
- $words = preg_split("/[^A-Za-z']/",$text);
- $words = array_unique($words);
- foreach($words as $word)
- {
- if(ereg("[A-Za-z]",$word) AND pspell_check($dictionary,$word) === false)
- {
- $suggestions = pspell_suggest($dictionary,$word);
- $suggestionstring = '';
- foreach($suggestions as $suggestion) $suggestionstring .= "$suggestion<br>";
- $suggestionstring = preg_replace("/<br>$/","",$suggestionstring);
- $origtext = preg_replace("/\\b$word\\b/",CSSPopup($word,$suggestionstring),$origtext);
- }
- }
- return $origtext;
- }
- function simplifyQuantity($quant) //int
- {
- $quant = str_replace(",","",$quant);
- $quant = preg_replace("/\.[0-9]+/","",$quant);
- $quant = str_ireplace("k","000",$quant);
- $quant = str_ireplace("m","000",$quant);
- if(!ereg("^[0-9]+$",$quant)) $quant = 0;
- return $quant;
- }
- function colorName2Hex($color) {
- if(!preg_match("/\#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})/", $color) && !preg_match("/([a-fA-F0-9]{3}|[a-fA-F0-9]{6})/", $color)){
- $color = strtolower($color);
- $colors = array(
- "aliceblue" => "f0f8ff",
- "antiquewhite" => "faebd7",
- "aqua" => "00ffff",
- "aquamarine" => "7fffd4",
- "azure" => "f0ffff",
- "beige" => "f5f5dc",
- "bisque" => "ffe4c4",
- "black" => "000000",
- "blanchedalmond" => "ffebcd",
- "blue" => "0000ff",
- "blueviolet" => "8a2be2",
- "brown" => "a52a2a",
- "burlywood" => "deb887",
- "cadetblue" => "5f9ea0",
- "chartreuse" => "7fff00",
- "chocolate" => "d2691e",
- "coral" => "ff7f50",
- "cornflowerblue" => "6495ed",
- "cornsilk" => "fff8dc",
- "crimson" => "dc143c",
- "cyan" => "00ffff",
- "darkblue" => "00008b",
- "darkcyan" => "008b8b",
- "darkgoldenrod" => "b8860b",
- "darkgray" => "a9a9a9",
- "darkgreen" => "006400",
- "darkkhaki" => "bdb76b",
- "darkmagenta" => "8b008b",
- "darkolivegreen" => "556b2f",
- "darkorange" => "ff8c00",
- "darkorchid" => "9932cc",
- "darkred" => "8b0000",
- "darksalmon" => "e9967a",
- "darkseagreen" => "8fbc8f",
- "darkslateblue" => "483d8b",
- "darkslategray" => "2f4f4f",
- "darkturquoise" => "00ced1",
- "darkviolet" => "9400d3",
- "deeppink" => "ff1493",
- "deepskyblue" => "00bfff",
- "dimgray" => "696969",
- "dodgerblue" => "1e90ff",
- "feldspar" => "d19275",
- "firebrick" => "b22222",
- "floralwhite" => "fffaf0",
- "forestgreen" => "228b22",
- "fuchsia" => "ff00ff",
- "gainsboro" => "dcdcdc",
- "ghostwhite" => "f8f8ff",
- "gold" => "ffd700",
- "goldenrod" => "daa520",
- "gray" => "808080",
- "green" => "008000",
- "greenyellow" => "adff2f",
- "honeydew" => "f0fff0",
- "hotpink" => "ff69b4",
- "indianred " => "cd5c5c",
- "indigo " => "4b0082",
- "ivory" => "fffff0",
- "khaki" => "f0e68c",
- "lavender" => "e6e6fa",
- "lavenderblush" => "fff0f5",
- "lawngreen" => "7cfc00",
- "lemonchiffon" => "fffacd",
- "lightblue" => "add8e6",
- "lightcoral" => "f08080",
- "lightcyan" => "e0ffff",
- "lightgoldenrodyellow" => "fafad2",
- "lightgrey" => "d3d3d3",
- "lightgreen" => "90ee90",
- "lightpink" => "ffb6c1",
- "lightsalmon" => "ffa07a",
- "lightseagreen" => "20b2aa",
- "lightskyblue" => "87cefa",
- "lightslateblue" => "8470ff",
- "lightslategray" => "778899",
- "lightsteelblue" => "b0c4de",
- "lightyellow" => "ffffe0",
- "lime" => "00ff00",
- "limegreen" => "32cd32",
- "linen" => "faf0e6",
- "magenta" => "ff00ff",
- "maroon" => "800000",
- "mediumaquamarine" => "66cdaa",
- "mediumblue" => "0000cd",
- "mediumorchid" => "ba55d3",
- "mediumpurple" => "9370d8",
- "mediumseagreen" => "3cb371",
- "mediumslateblue" => "7b68ee",
- "mediumspringgreen" => "00fa9a",
- "mediumturquoise" => "48d1cc",
- "mediumvioletred" => "c71585",
- "midnightblue" => "191970",
- "mintcream" => "f5fffa",
- "mistyrose" => "ffe4e1",
- "moccasin" => "ffe4b5",
- "navajowhite" => "ffdead",
- "navy" => "000080",
- "oldlace" => "fdf5e6",
- "olive" => "808000",
- "olivedrab" => "6b8e23",
- "orange" => "ffa500",
- "orangered" => "ff4500",
- "orchid" => "da70d6",
- "palegoldenrod" => "eee8aa",
- "palegreen" => "98fb98",
- "paleturquoise" => "afeeee",
- "palevioletred" => "d87093",
- "papayawhip" => "ffefd5",
- "peachpuff" => "ffdab9",
- "peru" => "cd853f",
- "pink" => "ffc0cb",
- "plum" => "dda0dd",
- "powderblue" => "b0e0e6",
- "purple" => "800080",
- "red" => "ff0000",
- "rosybrown" => "bc8f8f",
- "royalblue" => "4169e1",
- "saddlebrown" => "8b4513",
- "salmon" => "fa8072",
- "sandybrown" => "f4a460",
- "seagreen" => "2e8b57",
- "seashell" => "fff5ee",
- "sienna" => "a0522d",
- "silver" => "c0c0c0",
- "skyblue" => "87ceeb",
- "slateblue" => "6a5acd",
- "slategray" => "708090",
- "snow" => "fffafa",
- "springgreen" => "00ff7f",
- "steelblue" => "4682b4",
- "tan" => "d2b48c",
- "teal" => "008080",
- "thistle" => "d8bfd8",
- "tomato" => "ff6347",
- "turquoise" => "40e0d0",
- "violet" => "ee82ee",
- "violetred" => "d02090",
- "wheat" => "f5deb3",
- "white" => "ffffff",
- "whitesmoke" => "f5f5f5",
- "yellow" => "ffff00",
- "yellowgreen" => "9acd32");
- //$key = array_search($color, $colors);
- if($colors[$color])
- return $colors[$color];
- else
- return "000000";
- } else {
- return substr($color, 1); // Remove the hash
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement