PageRenderTime 67ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/helpers/string.php

https://github.com/MilkZoft/zan
PHP | 1018 lines | 967 code | 51 blank | 0 comment | 81 complexity | fcc830770f64cadeabf1c5c8b8563c14 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!defined("ACCESS")) {
  3. die("Error: You don't have permission to access here...");
  4. }
  5. if(!function_exists("getImageFromHTML")) {
  6. function getImageFromHTML($content)
  7. {
  8. preg_match_all('/< *img[^>]*src *= *["\']?([^"\']*).(jpg|png|gif)/i', $content, $matches);
  9. if (isset($matches[1][0]) and isset($matches[2][0])) {
  10. return replaceCDN($matches[1][0] .'.'. $matches[2][0]);
  11. } else {
  12. return replaceCDN("{{CDN_SERVER}}/www/lib/files/images/default.png");
  13. }
  14. }
  15. }
  16. if(!function_exists("spellChecker")) {
  17. function spellChecker($text)
  18. {
  19. global $Load;
  20. $language = whichLanguage();
  21. $RestClient = $Load->core("RESTClient");
  22. $RestClient->setURL("http://spellcheckerphp.com/api/");
  23. if (_get("verifySpelling") and $language == "Spanish") {
  24. return $RestClient->POST(array("text" => $text), true);
  25. }
  26. return $text;
  27. }
  28. }
  29. if (!function_exists("bbCode")) {
  30. function bbCode($text)
  31. {
  32. $text = trim($text);
  33. $text = preg_replace_callback('/\[code\](.*?)\[\/code\]/ms', "escape", $text);
  34. $in = array(
  35. '/\[b\](.*?)\[\/b\]/ms', '/\[i\](.*?)\[\/i\]/ms', '/\[u\](.*?)\[\/u\]/ms', '/\[img\](.*?)\[\/img\]/ms', '/\[video\](.*?)\[\/video\]/ms',
  36. '/\[email\](.*?)\[\/email\]/ms', '/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms', '/\[size\="?(.*?)"?\](.*?)\[\/size\]/ms',
  37. '/\[color\="?(.*?)"?\](.*?)\[\/color\]/ms', '/\[quote](.*?)\[\/quote\]/ms', '/\[list\=(.*?)\](.*?)\[\/list\]/ms',
  38. '/\[list\](.*?)\[\/list\]/ms', '/\[\*\]\s?(.*?)\n/ms'
  39. );
  40. $out = array(
  41. '<strong>\1</strong>', '<em>\1</em>', '<u>\1</u>', '<img src="\1" alt="\1" />',
  42. '<iframe width="560" height="315" src="$1" allowfullscreen></if rame>', '<a href="mailto:\1">\1</a>',
  43. '<a href="\1">\2</a>', '<span style="font-size:\1%">\2</span>', '<span style="color:\1">\2</span>',
  44. '<blockquote>\1</blockquote>', '<ol start="\1">\2</ol>', '<ul>\1</ul>', '<li>\1</li>'
  45. );
  46. $text = preg_replace($in, $out, $text);
  47. $text = str_replace("http://www.youtube.com/watch?v=", "http://www.youtube.com/embed/", $text);
  48. $text = str_replace("&amp;list=UUWDzmLpJP-z4qopWVA4qfTQ", "", $text);
  49. $text = str_replace("&amp;index=1", "", $text);
  50. $text = str_replace("&amp;index=2", "", $text);
  51. $text = str_replace("&amp;index=3", "", $text);
  52. $text = str_replace("&amp;index=4", "", $text);
  53. $text = str_replace("&amp;index=5", "", $text);
  54. $text = str_replace("&amp;index=6", "", $text);
  55. $text = str_replace("&amp;index=7", "", $text);
  56. $text = str_replace("&amp;index=8", "", $text);
  57. $text = str_replace("&amp;index=9", "", $text);
  58. $text = str_replace("&amp;feature=plcp", "", $text);
  59. $text = str_replace("&amp;feature=related", "", $text);
  60. $text = str_replace("&amp;feature=player_embedded", "", $text);
  61. $text = str_replace("&amp;feature=fvwrel", "", $text);
  62. $text = nl2br($text);
  63. $text = str_replace("</span><br />", "</span>", $text);
  64. $text = str_replace("</span>\r\n<br />", "</span>", $text);
  65. $text = str_replace("</blockquote>\r\n<br />", "</blockquote>", $text);
  66. $text = str_replace("<ul><br />", "<ul>", $text);
  67. $text = str_replace("</ul><br />", "</ul>", $text);
  68. $text = str_replace("</ol><br />", "</ol>", $text);
  69. $text = str_replace("<br />\n</li>", "</li>", $text);
  70. $text = str_replace("</blockquote><br />", "</blockquote>", $text);
  71. $text = str_replace("<span style=\"color: #000000\"><br />", "<span style=\"color: #000000\">", $text);
  72. $text = str_replace("</code><br />", "</code>", $text);
  73. $text = preg_replace_callback('/<pre class="code">(.*?)<\/pre>/ms', "removeBr", $text);
  74. $text = preg_replace('/<p><pre>(.*?)<\/pre><\/p>/ms', "<pre>\\1</pre>", $text);
  75. $text = preg_replace_callback('/<ul>(.*?)<\/ul>/ms', "removeBr", $text);
  76. $text = preg_replace('/<p><ul>(.*?)<\/ul><\/p>/ms', "<ul>\\1</ul>", $text);
  77. return $text;
  78. }
  79. }
  80. if (!function_exists("cleanHTML")) {
  81. function cleanHTML($HTML)
  82. {
  83. $search = array(
  84. '@<script[^>]*?>.*?</script>@si', '@<[\/\!]*?[^<>]*?>@si', '@([\r\n])[\s]+@', '@&(quot|#34);@i', '@&(amp|#38);@i',
  85. '@&(lt|#60);@i', '@&(gt|#62);@i', '@&(nbsp|#160);@i', '@&(iexcl|#161);@i', '@&(cent|#162);@i', '@&(pound|#163);@i',
  86. '@&(copy|#169);@i', '@&#(\d+);@e'
  87. );
  88. $replace = array('', '', '\1', '"', '&', '<', '>', ' ', chr(161), chr(162), chr(163), chr(169), 'chr(\1)');
  89. return preg_replace($search, $replace, $HTML);
  90. }
  91. }
  92. if (!function_exists("compress")) {
  93. function compress($string, $filetype = "php")
  94. {
  95. if ($filetype === "php") {
  96. $string = str_replace("<?php\r", "<?php ", $string);
  97. return str_replace(array("\r\n", "\r", "\n", "\t", " ", " ", " "), "", $string);
  98. } else {
  99. global $Load;
  100. if ($filetype === "css") {
  101. $Load->library("cssmin", null, null, "minify");
  102. return CSSMin::minify($string);
  103. } elseif ($filetype === 'js') {
  104. $Load->library("jsmin", null, null, "minify");
  105. return JSMin::minify($string);
  106. }
  107. }
  108. return null;
  109. }
  110. }
  111. if (!function_exists("cut")) {
  112. function cut($text, $length = 12, $type = "text", $slug = false, $file = false, $elipsis = false)
  113. {
  114. if ($type === "text") {
  115. $elipsis = "...";
  116. $words = explode(" ", $text);
  117. if (count($words) > $length) {
  118. return str_replace("\n", "", implode(" ", array_slice($words, 0, $length)) . $elipsis);
  119. }
  120. return $text;
  121. } elseif ($type === "word") {
  122. if ($file) {
  123. if (strlen($text) < $length) {
  124. $max = strlen($text);
  125. }
  126. if ($slug) {
  127. return substr(slug($text), 0, $length);
  128. } else {
  129. return substr($text, 0, $length);
  130. }
  131. } else {
  132. if (strlen($text) < 13) {
  133. return $text;
  134. }
  135. if (!$elipsis) {
  136. if ($slug) {
  137. return substr(slug($text), 0, $length);
  138. } else {
  139. return substr($text, 0, $length);
  140. }
  141. } else {
  142. if ($slug) {
  143. return substr(slug($text), 0, $length) . $elipsis;
  144. } else {
  145. return substr($text, 0, $length) . $elipsis;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. if (!function_exists("createURL")) {
  153. function createURL($text)
  154. {
  155. $result = ' '. $text;
  156. $result = preg_replace("#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="\2://\3" target="_blank">\2://\3</a>', $result);
  157. $result = preg_replace("#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="http://\2.\3" target="_blank">\2.\3</a>', $result);
  158. $result = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $result);
  159. return substr($result, 1);
  160. }
  161. }
  162. if (!function_exists("display")) {
  163. function display($content = null, $environment = true, $language = true)
  164. {
  165. if ($content and ($environment === true or _get("environment") <= $environment) and $language === true) {
  166. return $content;
  167. } elseif ($content and ($environment === true or _get("environment") <= $environment) and $language === whichLanguage()) {
  168. return $content;
  169. }
  170. return null;
  171. }
  172. }
  173. if (!function_exists("escape")) {
  174. function escape($string) {
  175. global $text;
  176. $code = $string[1];
  177. $code = str_replace("[", "&#91;", $code);
  178. $code = str_replace("]", "&#93;", $code);
  179. return getCode($code);
  180. }
  181. }
  182. if (!function_exists("exploding")) {
  183. function exploding($string, $URL = null, $separator = ",")
  184. {
  185. if (strlen($string) > 0) {
  186. $string = str_replace(", ", ",", $string);
  187. $parts = explode($separator, $string);
  188. $count = count($parts) - 1;
  189. $return = null;
  190. if ($count > 0) {
  191. for ($i = 0; $i <= $count; $i++) {
  192. if (!is_null($URL)) {
  193. if ($i == $count) {
  194. $return .= '<a href="'. path($URL . slug($parts[$i])) .'" title="'. $parts[$i] .'">'. $parts[$i] .'</a>';
  195. } elseif ($i == $count - 1) {
  196. $return .= '<a href="'. path($URL . slug($parts[$i])) .'" title="'. $parts[$i] .'">'. $parts[$i] .'</a> '. __("and") .' ';
  197. } else {
  198. $return .= '<a href="'. path($URL . slug($parts[$i])) .'" title="'. $parts[$i] .'">'. $parts[$i] .'</a>, ';
  199. }
  200. } else {
  201. if ($i == $count) {
  202. $return .= $parts[$i];
  203. } elseif ($i == $count - 1) {
  204. $return .= $parts[$i] .' '. __("and") .' ';
  205. } else {
  206. $return .= $parts[$i] .', ';
  207. }
  208. }
  209. }
  210. return $return;
  211. } else {
  212. return '<a href="'. path($URL . slug($string)) .'" title="'. $string .'">'. $string .'</a>';
  213. }
  214. }
  215. return false;
  216. }
  217. }
  218. if (!function_exists("like")) {
  219. function like($ID = 0, $application = null, $likes = false)
  220. {
  221. if ($ID > 0 and !is_null($application)) {
  222. return '<a title="'. __("I Like") .'" href="'. path("$application/like/$ID") .'"><img src="'. path("www/lib/images/like.png", true) .'" /> '. __("I Like") . ($likes ? " ($likes)" : null) .'</a>';
  223. }
  224. return false;
  225. }
  226. }
  227. if (!function_exists("dislike")) {
  228. function dislike($ID = 0, $application = null, $dislikes = false)
  229. {
  230. if ($ID > 0 and !is_null($application)) {
  231. return '<a title="'. __("I Dislike") .'" href="'. path("$application/dislike/$ID") .'">
  232. <img src="'. path("www/lib/images/dislike.png", true) .'" /> '. __("I Dislike") . ($dislikes ? " ($dislikes)" : null) .'
  233. </a>';
  234. }
  235. return false;
  236. }
  237. }
  238. if (!function_exists("report")) {
  239. function report($ID = 0, $application = null)
  240. {
  241. if ($ID > 0 and !is_null($application)) {
  242. return '<a title="'. __("Report Link") .'" href="'. path("$application/report/$ID") .'">
  243. <img src="'. path("www/lib/images/report.png", true) .'" /> '. __("Report link") .'
  244. </a>';
  245. }
  246. return false;
  247. }
  248. }
  249. if (!function_exists("decode")) {
  250. function decode($text, $URL = false)
  251. {
  252. if (is_string($text)) {
  253. return (!$URL) ? utf8_decode($text) : urldecode($text);
  254. }
  255. return $text;
  256. }
  257. }
  258. if (!function_exists("encode")) {
  259. function encode($text, $URL = false)
  260. {
  261. return (!$URL) ? utf8_encode($text) : urlencode($text);
  262. }
  263. }
  264. if (!function_exists("fbComments")) {
  265. function fbComments($URL, $count = false, $posts = 50, $width = 750)
  266. {
  267. if ($count) {
  268. return '<span class="fb-comments-count" data-href="'. $URL .'"></span> <span data-singular="'. __("comment") .'">'. __("comments") .'</span>';
  269. } else {
  270. return '<div class="fb-comments" data-href="'. $URL .'" data-num-posts="'. $posts .'" data-width="'. $width .'"></div>';
  271. }
  272. }
  273. }
  274. if (!function_exists("filter")) {
  275. function filter($text, $filter = false)
  276. {
  277. if (is_null($text)) {
  278. return false;
  279. }
  280. if ($text === true) {
  281. return true;
  282. } elseif ($filter === true) {
  283. $text = cleanHTML($text);
  284. } elseif ($filter === "remove") {
  285. $text = str_replace("\'", "", $text);
  286. $text = str_replace('\"', "", $text);
  287. $text = str_replace("'", "", $text);
  288. $text = str_replace('"', "", $text);
  289. }
  290. $text = str_replace("<", "", $text);
  291. $text = str_replace(">", "", $text);
  292. $text = str_replace("%27", "", $text);
  293. $text = str_replace("%22", "", $text);
  294. $text = str_replace("%20", "", $text);
  295. $text = str_replace("indexphp", "index.php", $text);
  296. return $text;
  297. }
  298. }
  299. if (!function_exists("quotes")) {
  300. function quotes($text)
  301. {
  302. $text = str_replace("&#39;", "\'", $text);
  303. $text = str_replace("&quot;", '\"', $text);
  304. return $text;
  305. }
  306. }
  307. if (!function_exists("getBetween")) {
  308. function getBetween($content, $start, $end)
  309. {
  310. $array = explode($start, $content);
  311. if (isset($array[1])) {
  312. $array = explode($end, $array[1]);
  313. return $array[0];
  314. }
  315. return null;
  316. }
  317. }
  318. if (!function_exists("getTotal")) {
  319. function getTotal($count, $singular, $plural)
  320. {
  321. return ((int) $count === 0 or (int) $count > 1) ? (int) $count ." ". __($plural) : (int) $count ." ". __($singular);
  322. }
  323. }
  324. if (!function_exists("gravatar")) {
  325. function gravatar($email)
  326. {
  327. return img("http://www.gravatar.com/avatar/". md5($email) ."");
  328. }
  329. }
  330. if (!function_exists("json")) {
  331. function json($json, $encode = true)
  332. {
  333. return ($encode) ? json_encode($json) : json_decode($json);
  334. }
  335. }
  336. if (!function_exists("parseCSV")) {
  337. function parseCSV($file)
  338. {
  339. $fh = fopen($file, "r");
  340. $lines = null;
  341. while ($line = fgetcsv($fh, 1000, ",")) {
  342. $lines .= $line[1];
  343. }
  344. return $lines;
  345. }
  346. }
  347. if (!function_exists("pathToImages")) {
  348. function pathToImages($HTML = null, $imagePath = null)
  349. {
  350. if ($HTML and $imagePath) {
  351. $newPath = ($imagePath === "lib") ? path("www/lib/images/", true) : path("www/lib/themes/$imagePath/", true);
  352. $patterns = array('<img.*src="([^http].*?)".*?>', '/<a(.*)href="([^http].*\.(jpg|gif |png))"(.*)>(.*?)<\/a>/', '/url\(\'?([^\'\)]+)\'?\)/m');
  353. $replacements = array('img src="'. $newPath .'\1" ', '<a$1href="'. $newPath .'$2"$4>$5</a> ', 'url('. $newPath .'\1) ');
  354. return preg_replace($patterns, $replacements, $HTML);
  355. }
  356. return false;
  357. }
  358. }
  359. if (!function_exists("getCode")) {
  360. function getCode($code)
  361. {
  362. if (!is_array($code)) {
  363. $code = explode("\n", $code);
  364. }
  365. $result = null;
  366. foreach ($code as $line => $codeLine) {
  367. if (preg_match("/<\?(php)?[^[:graph:]]/", $codeLine)) {
  368. $codeLine = str_replace('\"', '"', $codeLine);
  369. $codeLine = str_replace("\'", "'", $codeLine);
  370. $result .= htmlentities($codeLine) ."<br />";
  371. } else {
  372. $codeLine = str_replace('\"', '"', $codeLine);
  373. $codeLine = str_replace("\'", "'", $codeLine);
  374. $result .= preg_replace("/(&lt;\?php&nbsp;)+/", "", htmlentities(stripslashes($codeLine)) ."<br />");
  375. }
  376. }
  377. return '<pre class="prettyprint linenums">'. $result .'</pre>';
  378. }
  379. }
  380. if (!function_exists("getAd")) {
  381. function getAd($size = "block")
  382. {
  383. $size = strtolower($size);
  384. $slot = AD_SLOT_SKY;
  385. $width = AD_WIDTH_SKY;
  386. $height = AD_HEIGHT_SKY;
  387. if ($size === "block" or $size === "336px" or $size === "300px") {
  388. $slot = AD_SLOT_BLOCK;
  389. $width = AD_WIDTH_BLOCK;
  390. $height = AD_HEIGHT_BLOCK;
  391. } elseif ($size === "medium" or $size === "234px") {
  392. $slot = AD_SLOT_MEDIUM;
  393. $width = AD_WIDTH_MEDIUM;
  394. $height = AD_HEIGHT_MEDIUM;
  395. }
  396. if (isMobile()) {
  397. $slot = AD_SLOT_MEDIUM;
  398. $width = AD_WIDTH_MEDIUM;
  399. $height = AD_HEIGHT_MEDIUM;
  400. }
  401. if (_get("environment") === 4) {
  402. return '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><ins class="adsbygoogle" style="display:inline-block;width:'. $width .'px;height:'. $height .'px" data-ad-client="'. AD_CLIENT .'" data-ad-slot="'. $slot .'"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script>';
  403. }
  404. return null;
  405. }
  406. }
  407. if (!function_exists("removeRareChars")) {
  408. function removeRareChars($content)
  409. {
  410. $content = str_replace("%u200B", "", $content);
  411. return $content;
  412. }
  413. }
  414. if (!function_exists("showContent")) {
  415. function showContent($content)
  416. {
  417. $content = str_replace('<hr />', "", $content);
  418. $content = str_replace('<hr>', "", $content);
  419. $content = str_replace("------", "", $content);
  420. $content = str_replace('<pre class="prettyprint">', '<pre class="prettyprint linenums">', $content);
  421. $content = str_replace('<UIKit/UIKit.h>', '&lt;UIKit/UIKit.h&gt;', $content);
  422. $content = str_replace('<CoreLocation/CoreLocation.h>', '&lt;CoreLocation/CoreLocation.h&gt;', $content);
  423. $content = str_replace("[Ad:336px]", '<p>'. getAd() .'</p>', $content);
  424. $content = str_replace("[Ad:728px]", '<p>'. getAd("728px") .'</p>', $content);
  425. $content = str_replace("[Ad:Block]", '<p>'. getAd("336px") .'</p>', $content);
  426. $sizes = array("728px", "336px");
  427. $rand = rand(0, 1);
  428. $content = str_replace("[Ad:Sky]", '<p>'. getAd($sizes[$rand]) .'</p>', $content);
  429. $content = str_replace("[ad:336px]", '<p>'. getAd() .'</p>', $content);
  430. $content = str_replace("[ad:728px]", '<p>'. getAd("728px") .'</p>', $content);
  431. $content = str_replace("[Ad:block]", '<p>'. getAd() .'</p>', $content);
  432. $content = str_replace('\"', '"', $content);
  433. $content = str_replace("\'", "'", $content);
  434. $content = str_replace("<a ", '<a rel="nofollow" ', $content);
  435. $content = removeRareChars($content);
  436. $content = str_replace("{{CDN_SERVER}}", getCDN(), $content);
  437. $content = str_replace("<p>&nbsp;</p>", "", $content);
  438. return setCode($content);
  439. }
  440. }
  441. if (!function_exists("replaceCDN")) {
  442. function replaceCDN($content)
  443. {
  444. return str_replace("{{CDN_SERVER}}", getCDN(), $content);
  445. }
  446. }
  447. if (!function_exists("setCode")) {
  448. function setCode($HTML, $return = false)
  449. {
  450. $HTML = str_replace("[Code]", '<pre class="prettyprint linenums">', $HTML);
  451. $HTML = str_replace("[/Code]", '</pre>', $HTML);
  452. $HTML = str_replace("[code]", '<pre class="prettyprint linenums">', $HTML);
  453. $HTML = str_replace("[/code]", '</pre>', $HTML);
  454. $codes = explode('<pre class="prettyprint linenums">', $HTML);
  455. if (count($codes) > 1) {
  456. for ($i = 1; $i <= count($codes) - 1; $i++) {
  457. if (isset($codes[$i])) {
  458. $code = explode("</pre>", $codes[$i]);
  459. if (isset($code[0])) {
  460. $code[0] = ($return) ? htmlspecialchars(getCode($code[0])) : htmlspecialchars($code[0]);
  461. $code[0] = str_replace("&amp;", "&", $code[0]);
  462. $code[0] = str_replace("&nbsp;", " ", $code[0]);
  463. }
  464. $codes[$i] = ($return) ? implode("", $code) : implode("</pre>", $code);
  465. }
  466. }
  467. }
  468. return ($return) ? implode("", $codes) : implode('<pre class="prettyprint linenums">', $codes);
  469. }
  470. }
  471. if (!function_exists("randomString")) {
  472. function randomString($length = 6)
  473. {
  474. $consonant = array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z");
  475. $vocal = array("a", "e", "i", "o", "u");
  476. $string = null;
  477. srand((double) microtime() * 1000000);
  478. $max = $length / 2;
  479. for ($i = 1; $i <= $max; $i++) {
  480. $string .= $consonant[rand(0, 19)];
  481. $string .= $vocal[rand(0, 4)];
  482. }
  483. return $string;
  484. }
  485. }
  486. if (!function_exists("repeat")) {
  487. function repeat($string, $times = 2)
  488. {
  489. $HTML = null;
  490. for ($i = 0; $i <= $times; $i++) {
  491. $HTML .= $string;
  492. }
  493. return $HTML;
  494. }
  495. }
  496. if (!function_exists("slug")) {
  497. function slug($string)
  498. {
  499. $specialWords = array(
  500. "C++" => "cpp",
  501. "C/C++" => "c-cpp",
  502. "Node.js" => "nodejs",
  503. "Backbone.js" => "backbonejs",
  504. "Angular.js" => "angularjs"
  505. );
  506. if (array_key_exists($string, $specialWords)) {
  507. return $specialWords[$string];
  508. }
  509. $characters = array(
  510. "Á" => "A", "Ç" => "c", "É" => "e", "Í" => "i", "Ñ" => "n", "Ó" => "o", "Ú" => "u", "á" => "a", "ç" => "c",
  511. "é" => "e", "í" => "i", "ñ" => "n", "ó" => "o", "ú" => "u", "à" => "a", "è" => "e", "ì" => "i", "ò" => "o",
  512. "ù" => "u", "ã" => "a", "¿" => "", "?" => "", "¡" => "", "!" => "", ": " => "-"
  513. );
  514. $string = strtr($string, $characters);
  515. $string = strtolower(trim($string));
  516. $string = preg_replace("/[^a-z0-9-]/", "-", $string);
  517. $string = preg_replace("/-+/", "-", $string);
  518. return (substr($string, strlen($string) - 1, strlen($string)) === "-") ? substr($string, 0, strlen($string) - 1) : $string;
  519. }
  520. }
  521. if (!function_exists("pageBreak")) {
  522. function pageBreak($content, $URL = null, $label = null)
  523. {
  524. $content = str_replace("<p><!-- pagebreak --></p>", "<!---->", $content);
  525. $content = str_replace('<p style="text-align: center;"><!-- pagebreak --></p>', "<!---->", $content);
  526. $content = str_replace('<p style="text-align: left;"><!-- pagebreak --></p>', "<!---->", $content);
  527. $content = str_replace('<p style="text-align: right;"><!-- pagebreak --></p>', "<!---->", $content);
  528. $content = str_replace('<p style="text-align: justif y;"><!-- pagebreak --></p>', "<!---->", $content);
  529. $content = str_replace('<p style="text-align: center;"><span style="color: #ff0000;"><!----></span></p>', "<!---->", $content);
  530. $content = str_replace('<p style="text-align: center;"><em><!-- pagebreak --></em></p>', "<!---->", $content);
  531. $content = str_replace('<p style="text-align: center;"><strong><!-- pagebreak --></strong></p>', "<!---->", $content);
  532. $content = str_replace('<p style="text-align: center;"><span style="text-decoration: underline;"><!-- pagebreak --></span></p>', "<!---->", $content);
  533. $content = str_replace('<p style="text-align: justif y;"><!-- pagebreak --></p>', "<!---->", $content);
  534. $content = str_replace('<p><!-- pagebreak -->', "<p><!-- pagebreak --></p>\n<p>", $content);
  535. $content = str_replace("<p><!-- pagebreak --></p>", "<!---->", $content);
  536. $content = str_replace('<!-- pagebreak -->', "<!---->", $content);
  537. $content = str_replace('<!-- Pagebreak -->', "<!---->", $content);
  538. $content = str_replace('<!--Pagebreak-->', "<!---->", $content);
  539. $content = str_replace('------', "<!---->", $content);
  540. $content = str_replace('<div style="page-break-after: always;"><span style="display: none;">&nbsp;</span></div>', "<!---->", $content);
  541. $content = str_replace('<hr />', "<!---->", $content);
  542. $content = str_replace('<hr>', "<!---->", $content);
  543. $parts = explode("<!---->", $content);
  544. if (count($parts) > 1) {
  545. if (is_null($URL)) {
  546. return $parts[0];
  547. } else {
  548. return $parts[0] . (is_null($label) ? '<p><a href="'. $URL .'" title="'. __("Read more") .'">&raquo; '. __("Read more") .'...</a></p>' : $label);
  549. }
  550. }
  551. return $content;
  552. }
  553. }
  554. if (!function_exists("POST")) {
  555. function POST($position = false, $coding = "decode", $filter = "escape")
  556. {
  557. global $Load;
  558. if ($position !== true and $position !== false) {
  559. if (isset($_POST[$position])) {
  560. $_POST[$position] = str_replace("'", "\'", $_POST[$position]);
  561. $_POST[$position] = str_replace("\\\'", "\'", $_POST[$position]);
  562. $_POST[$position] = str_replace("“", '"', $_POST[$position]);
  563. $_POST[$position] = str_replace("”", '"', $_POST[$position]);
  564. }
  565. }
  566. if ($coding === "clenHTML") {
  567. return isset($_POST[$position]) ? cleanHTML($_POST[$position]) : false;
  568. } elseif ($coding === "clean") {
  569. return isset($_POST[$position]) ? $_POST[$position] : false;
  570. } elseif ($position === true) {
  571. return $_POST;
  572. } elseif (!$position) {
  573. $Load->helper("debugging");
  574. ____($_POST);
  575. } elseif (isset($_POST[$position]) and is_array($_POST[$position])) {
  576. $POST = $_POST[$position];
  577. } elseif (isset($_POST[$position]) and $_POST[$position] === "") {
  578. return null;
  579. } elseif (isset($_POST[$position])) {
  580. if ($coding === "b64") {
  581. $POST = base64_decode($_POST[$position]);
  582. } elseif ($coding === "unserialize") {
  583. $POST = unserialize(base64_decode($_POST[$position]));
  584. } elseif ($coding === "encrypt") {
  585. if ($filter === true) {
  586. $POST = encrypt(encode($_POST[$position]));
  587. } elseif ($filter === "escape") {
  588. $POST = encrypt(filter(encode($_POST[$position]), "escape"));
  589. } else {
  590. $POST = encrypt(filter(encode($_POST[$position]), true));
  591. }
  592. } elseif ($coding === "encode") {
  593. if ($filter === true) {
  594. $POST = encode($_POST[$position]);
  595. } elseif ($filter === "escape") {
  596. $POST = filter(encode($_POST[$position]), "escape");
  597. } else {
  598. $POST = filter(encode($_POST[$position]), true);
  599. }
  600. } elseif ($coding === "decode-encrypt") {
  601. if ($filter === true) {
  602. $POST = encrypt(filter($_POST[$position], true));
  603. } elseif ($filter === "escape") {
  604. $POST = encrypt(filter($_POST[$position], "escape"));
  605. } else {
  606. $POST = encrypt($_POST[$position]);
  607. }
  608. } elseif ($coding === "decode") {
  609. if ($filter === true) {
  610. $POST = filter(decode($_POST[$position]), true);
  611. } elseif ($filter === "escape") {
  612. $POST = filter(decode($_POST[$position]), "escape");
  613. } elseif ($filter === null) {
  614. $POST = decode($_POST[$position]);
  615. } else {
  616. $data = decode($_POST[$position]);
  617. $POST = $data;
  618. }
  619. } else {
  620. if ($filter === true) {
  621. $POST = filter($_POST[$position], true);
  622. } elseif ($filter === "escape") {
  623. $POST = filter($_POST[$position], "escape");
  624. } else {
  625. $POST = $_POST[$position];
  626. }
  627. }
  628. } elseif (isset($_POST[$position]) and $_POST[$position] === 0) {
  629. return 0;
  630. } else {
  631. return false;
  632. }
  633. return $POST;
  634. }
  635. }
  636. if (!function_exists("GET")) {
  637. function GET($position = false, $coding = "decode", $filter = "escape")
  638. {
  639. global $Load;
  640. if ($coding === "clean") {
  641. return $_GET[$position];
  642. } elseif ($position === true) {
  643. return $_GET;
  644. } elseif (!$position) {
  645. $Load->helper("debugging");
  646. ____($_GET);
  647. } elseif (isset($_GET[$position]) and is_array($_GET[$position])) {
  648. $GET = $_GET[$position];
  649. } elseif (isset($_GET[$position]) and $_GET[$position] === "") {
  650. return null;
  651. } elseif (isset($_GET[$position])) {
  652. if ($coding === "b64") {
  653. $GET = base64_decode($_GET[$position]);
  654. } elseif ($coding === "unserialize") {
  655. $GET = unserialize(base64_decode($_GET[$position]));
  656. } elseif ($coding === "encrypt") {
  657. if ($filter === true) {
  658. $GET = encrypt(encode($_GET[$position]));
  659. } elseif ($filter === "escape") {
  660. $GET = encrypt(filter(encode($_GET[$position]), "escape"));
  661. } else {
  662. $GET = encrypt(filter(encode($_GET[$position]), true));
  663. }
  664. } elseif ($coding === "encode") {
  665. if ($filter === true) {
  666. $GET = encode($_GET[$position]);
  667. } elseif ($filter === "escape") {
  668. $GET = filter(encode($_GET[$position]), "escape");
  669. } else {
  670. $GET = filter(encode($_GET[$position]), true);
  671. }
  672. } elseif ($coding === "decode-encrypt") {
  673. if ($filter === true) {
  674. $GET = encrypt(filter($_GET[$position], true));
  675. } elseif ($filter === "escape") {
  676. $GET = encrypt(filter($_GET[$position], "escape"));
  677. } else {
  678. $GET = encrypt($_GET[$position]);
  679. }
  680. } elseif ($coding === "decode") {
  681. if ($filter === true) {
  682. $GET = filter(decode($_GET[$position]), true);
  683. } elseif ($filter === "escape") {
  684. $GET = filter(decode($_GET[$position]), "escape");
  685. } elseif ($filter === null) {
  686. $GET = decode($_GET[$position]);
  687. } else {
  688. $data = decode($_GET[$position]);
  689. $data = str_replace("'", "\'", $data);
  690. $GET = $data;
  691. }
  692. } else {
  693. if ($filter === true) {
  694. $GET = filter($_GET[$position], true);
  695. } elseif ($filter === "escape") {
  696. $GET = filter($_GET[$position], "escape");
  697. } else {
  698. $GET = $_GET[$position];
  699. }
  700. }
  701. } elseif (isset($_GET[$position]) and $_GET[$position] === 0) {
  702. return 0;
  703. } else {
  704. return false;
  705. }
  706. return $GET;
  707. }
  708. }
  709. if (!function_exists("REQUEST")) {
  710. function REQUEST($position = false, $coding = "decode", $filter = "escape")
  711. {
  712. global $Load;
  713. if ($coding === "clean") {
  714. return $_REQUEST[$position];
  715. } elseif ($position === true) {
  716. return $_REQUEST;
  717. } elseif (!$position) {
  718. $Load->helper("debugging");
  719. ____($_REQUEST);
  720. } elseif (isset($_REQUEST[$position]) and is_array($_REQUEST[$position])) {
  721. $REQUEST = $_REQUEST[$position];
  722. } elseif (isset($_REQUEST[$position]) and $_REQUEST[$position] === "") {
  723. return null;
  724. } elseif (isset($_REQUEST[$position])) {
  725. if ($coding === "b64") {
  726. $REQUEST = base64_decode($_REQUEST[$position]);
  727. } elseif ($coding === "unserialize") {
  728. $REQUEST = unserialize(base64_decode($_REQUEST[$position]));
  729. } elseif ($coding === "encrypt") {
  730. if ($filter === true) {
  731. $REQUEST = encrypt(encode($_REQUEST[$position]));
  732. } elseif ($filter === "escape") {
  733. $REQUEST = encrypt(filter(encode($_REQUEST[$position]), "escape"));
  734. } else {
  735. $REQUEST = encrypt(filter(encode($_REQUEST[$position]), true));
  736. }
  737. } elseif ($coding === "encode") {
  738. if ($filter === true) {
  739. $REQUEST = encode($_REQUEST[$position]);
  740. } elseif ($filter === "escape") {
  741. $REQUEST = filter(encode($_REQUEST[$position]), "escape");
  742. } else {
  743. $REQUEST = filter(encode($_REQUEST[$position]), true);
  744. }
  745. } elseif ($coding === "decode-encrypt") {
  746. if ($filter === true) {
  747. $REQUEST = encrypt(filter($_REQUEST[$position], true));
  748. } elseif ($filter === "escape") {
  749. $REQUEST = encrypt(filter($_REQUEST[$position], "escape"));
  750. } else {
  751. $REQUEST = encrypt($_REQUEST[$position]);
  752. }
  753. } elseif ($coding === "decode") {
  754. if ($filter === true) {
  755. $REQUEST = filter(decode($_REQUEST[$position]), true);
  756. } elseif ($filter === "escape") {
  757. $REQUEST = filter(decode($_REQUEST[$position]), "escape");
  758. } elseif ($filter === null) {
  759. $REQUEST = decode($_REQUEST[$position]);
  760. } else {
  761. $data = decode($_REQUEST[$position]);
  762. $data = str_replace("'", "\'", $data);
  763. $data = str_replace("“", '"', $data);
  764. $data = str_replace("”", '"', $data);
  765. $REQUEST = $data;
  766. }
  767. } else {
  768. if ($filter === true) {
  769. $REQUEST = filter($_REQUEST[$position], true);
  770. } elseif ($filter === "escape") {
  771. $REQUEST = filter($_REQUEST[$position], "escape");
  772. } else {
  773. $REQUEST = $_REQUEST[$position];
  774. }
  775. }
  776. } elseif (isset($_REQUEST[$position]) and $_REQUEST[$position] === 0) {
  777. return 0;
  778. } else {
  779. return false;
  780. }
  781. return $REQUEST;
  782. }
  783. }
  784. if (!function_exists("recoverPOST")) {
  785. function recoverPOST($position, $value = null)
  786. {
  787. if (is_null($value)) {
  788. if (is_array(POST($position))) {
  789. return POST($position);
  790. } elseif (POST($position)) {
  791. return _get("isOnline") ? htmlentities(decode(POST($position))) : htmlentities(POST($position));
  792. }
  793. } else {
  794. if (is_array($value)) {
  795. foreach ($value as $val) {
  796. if (!is_array($val)) {
  797. $data[] = htmlentities($val);
  798. } else {
  799. array_walk_recursive($val, create_function('&$val', '$val = htmlentities($val);'));
  800. $data[] = $val;
  801. }
  802. }
  803. return $data;
  804. } else {
  805. if ($position == "content") {
  806. return (POST($position)) ? POST($position, "decode", false) : decode($value);
  807. }
  808. if (POST($position)) {
  809. return _get("isOnline") ? htmlentities(decode(POST($position))) : htmlentities(POST($position));
  810. } else {
  811. return _get("isOnline") ? htmlentities(decode($value)) : htmlentities($value);
  812. }
  813. }
  814. }
  815. }
  816. }
  817. if (!function_exists('removeBr')) {
  818. function removeBr($string) {
  819. return str_replace("<br />", "", $e[0]);
  820. }
  821. }
  822. if (!function_exists("removeSpaces")) {
  823. function removeSpaces($text, $trim = false)
  824. {
  825. $text = preg_replace("/\s+/", " ", $text);
  826. return ($trim) ? trim($text) : $text;
  827. }
  828. }
  829. if (!function_exists("social")) {
  830. function social($type = "horizontal", $title, $URL)
  831. {
  832. $display = 'st_title="'. $title .'" st_url="'. $URL .'"';
  833. if ($type == "horizontal") {
  834. return '<span '. $display .' st_via="codejobs" class="st_facebook_hcount" displayText="Facebook"></span>
  835. <span '. $display .' st_via="codejobs" class="st_twitter_hcount" displayText="Tweet"></span>
  836. <span '. $display .' st_via="codejobs" class="st_linkedin_hcount" displayText="LinkedIn"></span>
  837. <span '. $display .' st_via="codejobs" class="st_plusone_hcount" displayText="Google +1"></span>';
  838. } else {
  839. return '<span '. $display .' st_via="codejobs" class="st_facebook_vcount" displayText="Facebook"></span>
  840. <span '. $display .' st_via="codejobs" class="st_twitter_vcount" displayText="Tweet"></span>
  841. <span '. $display .' st_via="codejobs" class="st_linkedin_vcount" displayText="LinkedIn"></span>
  842. <span '. $display .' st_via="codejobs" class="st_delicious_vcount" displayText="Delicious"></span>
  843. <span '. $display .' st_via="codejobs" class="st_tumblr_vcount" displayText="Tumblr"></span>
  844. <span '. $display .' st_via="codejobs" class="st_plusone_vcount" displayText="Google +1"></span>';
  845. }
  846. }
  847. }
  848. if (!function_exists("showLinks")) {
  849. function showLinks($content)
  850. {
  851. return preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $content);
  852. }
  853. }
  854. if (!function_exists("num2str")) {
  855. function num2str($number, $translate = FALSE, $function = FALSE)
  856. {
  857. switch($number) {
  858. case 1:
  859. $string = "one";
  860. break;
  861. case 2:
  862. $string = "two";
  863. break;
  864. case 3:
  865. $string = "three";
  866. break;
  867. case 4:
  868. $string = "four";
  869. break;
  870. case 5:
  871. $string = "five";
  872. break;
  873. case 6:
  874. $string = "six";
  875. break;
  876. case 7:
  877. $string = "seven";
  878. break;
  879. case 8:
  880. $string = "eight";
  881. break;
  882. case 9:
  883. $string = "nine";
  884. break;
  885. default:
  886. $string = "zero";
  887. }
  888. if($translate) {
  889. $string = __($string);
  890. }
  891. if($function) {
  892. $string = $funciont($string);
  893. }
  894. return $string;
  895. }
  896. }