Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.55 KB | None | 0 0
  1. <?php
  2.  
  3. //////////////////////////////////////////////////////////////
  4. // Legal Notice //
  5. // //
  6. // The contents of this file are copyrighted and are the //
  7. // sole property of Ryan Schoen. Any unauthorized //
  8. // duplication, distribution, or reproduction will //
  9. // constitute an infringement of copyright. By editing this //
  10. // file, you agree that all contributions and modifications //
  11. // to its contents become the sole property of Ryan Schoen. //
  12. // //
  13. // (c) Copyright 2006 Ryan Schoen. All rights reserved. //
  14. //////////////////////////////////////////////////////////////
  15.  
  16. function deZero($string) //string
  17. {
  18. $string = preg_replace("/\.([^0]*)0+$/",".\\1",$string);
  19. $string = preg_replace("/\.$/","",$string);
  20. return $string;
  21. }
  22.  
  23. function format($text,$style) //string
  24. {
  25. if($style & FORMAT_REMOVE_HTML)
  26. {
  27. $text = htmlentities($text,ENT_QUOTES);
  28. }
  29. if($style & FORMAT_ADD_SLASHES)
  30. {
  31. $text = addslashes($text);
  32. }
  33. if($style & FORMAT_RXML_FORMATTING)
  34. {
  35.  
  36. $find = array (
  37. '/\[li\](.*)\n?/',
  38. '/\n/',
  39. '/ /',
  40. '/\[b\]/',
  41. '/\[i\]/',
  42. '/\[u\]/',
  43. '/\[s\]/',
  44. '/\[center\]/',
  45. '/\[\/b\]/',
  46. '/\[\/i\]/',
  47. '/\[\/u\]/',
  48. '/\[\/s\]/',
  49. '/\[\/center\]/',
  50. '/\[color=(.*?)\]/',
  51. '/\[\/color\]/',
  52. '/arsenal/');
  53. $replace = array (
  54. '<li class=forum>$1</li>',
  55. '<br>',
  56. ' &nbsp;',
  57. '<b>',
  58. '<i>',
  59. '<u>',
  60. '<s>',
  61. '<center>',
  62. '</b>',
  63. '</i>',
  64. '</u>',
  65. '</s>',
  66. '</center>',
  67. '<font color=\'\\1\'>',
  68. '</font>',
  69. '&#97;rsenal');
  70. $text = preg_replace($find,$replace,$text);
  71.  
  72. /*global $loggedid;
  73. if(!empty($loggedid))
  74. {
  75.  
  76. $find = array ('/\[id\]/', '/\[name\]/');
  77. $replace = array ($loggedid, getName($loggedid));
  78. $text = preg_replace($find,$replace,$text);
  79. }*/
  80.  
  81. $find = array( '/\[([^\]]+)\[([^\]]+)\]([^\]]+)\]/');//, '/\[([^\]]+)\]([^\]]+)\]/');
  82. $replace = array( '[\\1&#91;\\2&#93;\\3]');//, '[\\1&#93;\\2]');
  83. do {
  84. $text = preg_replace($find,$replace,$text,-1,$count);
  85. } while($count > 0);
  86.  
  87.  
  88. }
  89. if($style & FORMAT_SMILIES)
  90. {
  91. $find = array (
  92. '/(:-?\))/',
  93. '/(t\(\-_\-\(t)/',
  94. '/(:-?\|)/',
  95. '/(:-?\()/',
  96. '/(: -?(P|p))/',
  97. '/(;-?\))/',
  98. '/:-?(\\\|\/)([^\/])/',
  99. '/(:-?(D|d))/',
  100. "/(:\*\()/",
  101. '/(((o\.O)|(O\.o)))/',
  102. '/(\^_\^)/',
  103. '/(:-?X)/i' );
  104. $replace = array (
  105. smiley('happy'),
  106. smiley('tease'),
  107. smiley('blah'),
  108. smiley('sad'),
  109. smiley('tongue'),
  110. smiley('wink'),
  111. smiley('unsure')."\\2",
  112. smiley('laugh'),
  113. smiley('cry'),
  114. smiley('oO'),
  115. smiley('^_^'),
  116. smiley('mute') );
  117. $text = preg_replace($find,$replace,$text);
  118. }
  119. if($style & FORMAT_LINKS)
  120. {
  121. // Linking
  122. $find = array (
  123. '/\[(link|url)=(http:[^\s]*?)\](.*?)\[\/(link|url)\]/',
  124. '/\[(\d+)\]/e',
  125. '/\[(house|id)=(\d+)\]([^\[]+)\[\/(id|house)\]/e',
  126. '/\[pm=(\d+)\]([^\[]+)\[\/pm\]/e',
  127. '/\[post=(\d+)\]([^\[]+)\[\/post]/e',
  128. '/\[tos=([0-9IVX\.]+)\]/e',
  129. '/\[clan=(\d+)\]([^\[]+)\[\/clan\]/e' );
  130. $replace = array (
  131. '<a href="link.php?address=\\2" title="Link: \\2" target=_blank>\\3</a>',
  132. 'linkToID(\\1)',
  133. 'linkTo("house.php?id=\\2","\\3")',
  134. 'linkTo("pm.php?action=form&id=\\1","\\2")',
  135. 'linkTo("posts.php?postid=\\1","\\2")',
  136. 'linkTo("tos.php?section=\\1","ToS - Section \\1")',
  137. 'linkTo("lodge.php?action=details&clan=\\1","\\2")');
  138. $text = preg_replace($find,$replace,$text);
  139.  
  140. //$text = preg_replace('/\[out=([^\]]*?)\](.*?)\[\/out\]/','<a href="out.php?$1" target=_blank>$2</a>',$text);
  141.  
  142. }
  143. if($style & FORMAT_PICTURES)
  144. {
  145. $find = array (
  146. '/\[img=http:([^\s]*?\.(gif|jpg|jpeg|png|bmp|tif|tiff))\]/',
  147. '/(pwned\.)/i');
  148. $replace = array (
  149. '<img src="http:\\1">',
  150. '<img src=img/pwned.gif old=\\1>' );
  151. $text = preg_replace($find,$replace,$text);
  152. }
  153. if($style & FORMAT_DYNAMIC_LINKS)
  154. {
  155. $text = formatNews($text);
  156. }
  157. if($style & FORMAT_SPELLCHECK)
  158. {
  159. $text = spellcheck($text);
  160. }
  161. if($style & FORMAT_REMOVE_LISTS)
  162. {
  163. $text = preg_replace("/<\/li>/","<br>",$text);
  164. $text = preg_replace("/<li[^>]*>/"," - ",$text);
  165. $text = preg_replace("/<\/?b>/","",$text);
  166. }
  167.  
  168.  
  169. return $text;
  170.  
  171. }
  172.  
  173. function showBar($color1,$color2,$percent1) //string
  174. {
  175. $percent2 = round((100 - $percent1),0);
  176. $percent1 = round($percent1,0);
  177. return "<img src=img/$color1.jpg width=$percent1 height=7><img src=img/$color2.jpg width=$percent2 height=7>";
  178. }
  179.  
  180. function smiley($smiley) //string
  181. {
  182. global $loggedid;
  183. static $smileypreference;
  184. if(empty($smileypreference) && !empty($loggedid)) $smileypreference = getSetting($loggedid,SETTING_SMILEY_PREFERENCE);
  185. if(!empty($loggedid) AND $smileypreference == "x2") $string = "<img class=smileyold src=img/smileys/".$smiley."_old.gif old=\\1>";
  186. else $string = "<img class=smiley src=img/smileys/$smiley.gif old=\\1>";
  187. return $string;
  188. }
  189.  
  190. function roundDown($number,$precision=0) //float
  191. {
  192. if(!is_numeric($number)) error("Trying to round non-numeric number.");
  193. $number = preg_replace("/\.([0-9]{".$precision."}).*$/",".$1",$number);
  194. $number = deZero($number);
  195. return $number;
  196. }
  197.  
  198. function is_number($number,$allownegative=false,$allowdecimal=false) //bool
  199. {
  200. if($allowdecimal == true) return is_numeric($number);
  201. elseif($allownegative == true) return ereg("^-?[0-9]+$",$number);
  202. else return ereg("^[0-9]+$",$number);
  203. }
  204.  
  205.  
  206. function pages($url,$pages,$page,$separator=" ") //string
  207. {
  208. if(!is_number($pages)) error("Invalid number of pages!");
  209. if(!is_number($page)) error("Invalid current page!");
  210. if($pages <= 1) return;
  211. $return = "Page: ";
  212. for($i=1; $i<=$pages; $i++)
  213. {
  214. if($i == $page) $return .= "$i$separator";
  215. else
  216. {
  217. $newurl = $url;
  218. if(ereg("\?",$url)) $newurl = "$url&page=$i";
  219. else $newurl = "$url?page=$i";
  220. $return .= linkTo($newurl,"$i$separator");
  221. }
  222. }
  223. $return = preg_replace("/$separator$/","",$return);
  224. return $return;
  225.  
  226. }
  227.  
  228. function filter($text,$popup=true) //string
  229. {
  230. global $loggedid,$global,$curses,$notcurses;
  231. static $filter;
  232. if(!empty($loggedid))
  233. {
  234. if(!isset($filter[$loggedid])) $filter[$loggedid] = getSetting($loggedid,SETTING_FILTER);
  235. if(!$filter[$loggedid]) return $text;
  236. }
  237.  
  238. $replacedcurses = array();
  239. foreach($notcurses as $notcurse)
  240. {
  241. if(eregi($notcurse,$text))
  242. {
  243. $letters = preg_split("//",$notcurse,-1,PREG_SPLIT_NO_EMPTY);
  244. $find = $replace = '';
  245. $i = 0;
  246. foreach($letters as $letter)
  247. {
  248. $i++;
  249. $find .= "($letter)";
  250. $replace .= "\\$i.";
  251. }
  252. $replace = substr($replace,0,strlen($replace)-1);
  253. $text = preg_replace("/$find/",$replace,$text);
  254. $replacedcurses[$notcurse] = $letters;
  255. }
  256. }
  257.  
  258. global $curses;
  259. foreach($curses as $word) {
  260. $word = base64_decode($word);
  261. $replacement = str_repeat("*",strlen($word));
  262. 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>";
  263. $text = preg_replace("/$word/i",$replacement,$text);
  264. }
  265.  
  266. foreach($replacedcurses as $replacedcurse => $letters)
  267. {
  268. $find = $replace = '';
  269. foreach($letters as $letter)
  270. {
  271. $find .= "$letter\\.";
  272. $replace .= $letter;
  273. }
  274. $find = substr($find,0,strlen($find)-2);
  275. $text = preg_replace("/$find/",$replace,$text);
  276. }
  277.  
  278.  
  279. return $text;
  280. }
  281.  
  282. function button($text,$link) //string
  283. {
  284. return "<input type=button value=\"$text\" onClick=\"window.location='".encodeURL($link)."'\">";
  285. }
  286.  
  287.  
  288. function getNumberOfCurses($text) //int
  289. {
  290. global $curses;
  291. $numberOfCurses = 0;
  292. foreach($curses as $curse)
  293. {
  294. $curse = base64_decode($curse);
  295. $pos = -1;
  296. while(1)
  297. {
  298. $pos = strpos($text,$curse,$pos+1);
  299. if($pos === FALSE) break;
  300. $numberOfCurses++;
  301. }
  302. }
  303. return $numberOfCurses;
  304. }
  305.  
  306. function forumPopup($popup)
  307. {
  308. if(strlen($popup) > FORUM_PREVIEW_LENGTH) $popup = substr($popup,0,FORUM_PREVIEW_LENGTH-3)."...";
  309. $popup = filter(format($popup,FORMAT_POPUP),false);
  310. if(strpos($_SERVER['HTTP_USER_AGENT'],'ie') ==! 0) $popup = stri_replace("/<br>/","\n",$popup);
  311. return $popup;
  312. }
  313.  
  314. function spellcheck($text)
  315. {
  316. global $loggedid;
  317. if(empty($loggedid)) $dialect = DIALECT_AMERICAN;
  318. else $dialect = getSetting($loggedid,SETTING_SPELLCHECK_DIALECT);
  319.  
  320. $origtext = $text;
  321. $text = strip_tags($text);
  322.  
  323. $dictionary = pspell_new("en",$dialect,"","",PSPELL_FAST);
  324. $words = preg_split("/[^A-Za-z']/",$text);
  325. $words = array_unique($words);
  326.  
  327. foreach($words as $word)
  328. {
  329. if(ereg("[A-Za-z]",$word) AND pspell_check($dictionary,$word) === false)
  330. {
  331. $suggestions = pspell_suggest($dictionary,$word);
  332. $suggestionstring = '';
  333. foreach($suggestions as $suggestion) $suggestionstring .= "$suggestion<br>";
  334. $suggestionstring = preg_replace("/<br>$/","",$suggestionstring);
  335.  
  336. $origtext = preg_replace("/\\b$word\\b/",CSSPopup($word,$suggestionstring),$origtext);
  337. }
  338. }
  339. return $origtext;
  340. }
  341.  
  342. function simplifyQuantity($quant) //int
  343. {
  344. $quant = str_replace(",","",$quant);
  345. $quant = preg_replace("/\.[0-9]+/","",$quant);
  346. $quant = str_ireplace("k","000",$quant);
  347. $quant = str_ireplace("m","000",$quant);
  348. if(!ereg("^[0-9]+$",$quant)) $quant = 0;
  349. return $quant;
  350. }
  351.  
  352. function colorName2Hex($color) {
  353.  
  354. 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)){
  355.  
  356. $color = strtolower($color);
  357. $colors = array(
  358. "aliceblue" => "f0f8ff",
  359. "antiquewhite" => "faebd7",
  360. "aqua" => "00ffff",
  361. "aquamarine" => "7fffd4",
  362. "azure" => "f0ffff",
  363. "beige" => "f5f5dc",
  364. "bisque" => "ffe4c4",
  365. "black" => "000000",
  366. "blanchedalmond" => "ffebcd",
  367. "blue" => "0000ff",
  368. "blueviolet" => "8a2be2",
  369. "brown" => "a52a2a",
  370. "burlywood" => "deb887",
  371. "cadetblue" => "5f9ea0",
  372. "chartreuse" => "7fff00",
  373. "chocolate" => "d2691e",
  374. "coral" => "ff7f50",
  375. "cornflowerblue" => "6495ed",
  376. "cornsilk" => "fff8dc",
  377. "crimson" => "dc143c",
  378. "cyan" => "00ffff",
  379. "darkblue" => "00008b",
  380. "darkcyan" => "008b8b",
  381. "darkgoldenrod" => "b8860b",
  382. "darkgray" => "a9a9a9",
  383. "darkgreen" => "006400",
  384. "darkkhaki" => "bdb76b",
  385. "darkmagenta" => "8b008b",
  386. "darkolivegreen" => "556b2f",
  387. "darkorange" => "ff8c00",
  388. "darkorchid" => "9932cc",
  389. "darkred" => "8b0000",
  390. "darksalmon" => "e9967a",
  391. "darkseagreen" => "8fbc8f",
  392. "darkslateblue" => "483d8b",
  393. "darkslategray" => "2f4f4f",
  394. "darkturquoise" => "00ced1",
  395. "darkviolet" => "9400d3",
  396. "deeppink" => "ff1493",
  397. "deepskyblue" => "00bfff",
  398. "dimgray" => "696969",
  399. "dodgerblue" => "1e90ff",
  400. "feldspar" => "d19275",
  401. "firebrick" => "b22222",
  402. "floralwhite" => "fffaf0",
  403. "forestgreen" => "228b22",
  404. "fuchsia" => "ff00ff",
  405. "gainsboro" => "dcdcdc",
  406. "ghostwhite" => "f8f8ff",
  407. "gold" => "ffd700",
  408. "goldenrod" => "daa520",
  409. "gray" => "808080",
  410. "green" => "008000",
  411. "greenyellow" => "adff2f",
  412. "honeydew" => "f0fff0",
  413. "hotpink" => "ff69b4",
  414. "indianred " => "cd5c5c",
  415. "indigo " => "4b0082",
  416. "ivory" => "fffff0",
  417. "khaki" => "f0e68c",
  418. "lavender" => "e6e6fa",
  419. "lavenderblush" => "fff0f5",
  420. "lawngreen" => "7cfc00",
  421. "lemonchiffon" => "fffacd",
  422. "lightblue" => "add8e6",
  423. "lightcoral" => "f08080",
  424. "lightcyan" => "e0ffff",
  425. "lightgoldenrodyellow" => "fafad2",
  426. "lightgrey" => "d3d3d3",
  427. "lightgreen" => "90ee90",
  428. "lightpink" => "ffb6c1",
  429. "lightsalmon" => "ffa07a",
  430. "lightseagreen" => "20b2aa",
  431. "lightskyblue" => "87cefa",
  432. "lightslateblue" => "8470ff",
  433. "lightslategray" => "778899",
  434. "lightsteelblue" => "b0c4de",
  435. "lightyellow" => "ffffe0",
  436. "lime" => "00ff00",
  437. "limegreen" => "32cd32",
  438. "linen" => "faf0e6",
  439. "magenta" => "ff00ff",
  440. "maroon" => "800000",
  441. "mediumaquamarine" => "66cdaa",
  442. "mediumblue" => "0000cd",
  443. "mediumorchid" => "ba55d3",
  444. "mediumpurple" => "9370d8",
  445. "mediumseagreen" => "3cb371",
  446. "mediumslateblue" => "7b68ee",
  447. "mediumspringgreen" => "00fa9a",
  448. "mediumturquoise" => "48d1cc",
  449. "mediumvioletred" => "c71585",
  450. "midnightblue" => "191970",
  451. "mintcream" => "f5fffa",
  452. "mistyrose" => "ffe4e1",
  453. "moccasin" => "ffe4b5",
  454. "navajowhite" => "ffdead",
  455. "navy" => "000080",
  456. "oldlace" => "fdf5e6",
  457. "olive" => "808000",
  458. "olivedrab" => "6b8e23",
  459. "orange" => "ffa500",
  460. "orangered" => "ff4500",
  461. "orchid" => "da70d6",
  462. "palegoldenrod" => "eee8aa",
  463. "palegreen" => "98fb98",
  464. "paleturquoise" => "afeeee",
  465. "palevioletred" => "d87093",
  466. "papayawhip" => "ffefd5",
  467. "peachpuff" => "ffdab9",
  468. "peru" => "cd853f",
  469. "pink" => "ffc0cb",
  470. "plum" => "dda0dd",
  471. "powderblue" => "b0e0e6",
  472. "purple" => "800080",
  473. "red" => "ff0000",
  474. "rosybrown" => "bc8f8f",
  475. "royalblue" => "4169e1",
  476. "saddlebrown" => "8b4513",
  477. "salmon" => "fa8072",
  478. "sandybrown" => "f4a460",
  479. "seagreen" => "2e8b57",
  480. "seashell" => "fff5ee",
  481. "sienna" => "a0522d",
  482. "silver" => "c0c0c0",
  483. "skyblue" => "87ceeb",
  484. "slateblue" => "6a5acd",
  485. "slategray" => "708090",
  486. "snow" => "fffafa",
  487. "springgreen" => "00ff7f",
  488. "steelblue" => "4682b4",
  489. "tan" => "d2b48c",
  490. "teal" => "008080",
  491. "thistle" => "d8bfd8",
  492. "tomato" => "ff6347",
  493. "turquoise" => "40e0d0",
  494. "violet" => "ee82ee",
  495. "violetred" => "d02090",
  496. "wheat" => "f5deb3",
  497. "white" => "ffffff",
  498. "whitesmoke" => "f5f5f5",
  499. "yellow" => "ffff00",
  500. "yellowgreen" => "9acd32");
  501.  
  502. //$key = array_search($color, $colors);
  503.  
  504. if($colors[$color])
  505. return $colors[$color];
  506. else
  507. return "000000";
  508.  
  509. } else {
  510.  
  511. return substr($color, 1); // Remove the hash
  512.  
  513. }
  514. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement