A tumblelog CMS built on AJAX, PHP and MySQL.

util.class.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <?php
  2. if (!defined('entry') || !entry) {
  3. die('Not a valid page');
  4. }
  5. /* ===========================
  6. Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS
  7. Sorbet CMS is a free software licensed under the GPL 3.0
  8. =========================== */
  9. class util
  10. {
  11. public function version()
  12. {
  13. return "1.0";
  14. }
  15. public function codeName()
  16. {
  17. return "Strawberry";
  18. }
  19. public function beginsWith($str, $sub)
  20. {
  21. return (strpos($str, $sub) === 0);
  22. }
  23. public function endsWith($str, $sub)
  24. {
  25. return (substr($str, strlen($str) - strlen($sub)) == $sub);
  26. }
  27. public function getFileName($fileUrl)
  28. {
  29. $path = explode('/', $fileUrl);
  30. return $path[count($path)-1];
  31. }
  32. public function isMP3($fileUrl)
  33. {
  34. $util_class = new util();
  35. if ($util_class->endsWith($fileUrl, ".mp3")) {
  36. return true;
  37. } else {
  38. return false;
  39. }
  40. }
  41. public function getMP3File($remoteFileName)
  42. {
  43. $util_class = new util();
  44. if ($util_class->isMP3($remoteFileName)) {
  45. if ($util_class->getFile($remoteFileName)) {
  46. return true;
  47. } else {
  48. return false;
  49. }
  50. } elseif ($util_class->isGoEar($remoteFileName)) {
  51. return true;
  52. } elseif ($util_class->isOdeo($remoteFileName)) {
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. }
  58. public function getGoEarCode($songUrl)
  59. {
  60. $pos = strpos($songUrl, "?v=");
  61. $lon = strlen($songUrl);
  62. $str = substr($songUrl, $pos + 3, $lon);
  63. return $str;
  64. }
  65. public function isGoEar($songUrl)
  66. {
  67. $util_class = new util();
  68. if ($util_class->beginsWith($songUrl, "http://www.goear.com/listen.php?v=") || $util_class->beginsWith($songUrl, "http://goear.com/listen.php?v=")) {
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. }
  74. public function isOdeo($songUrl)
  75. {
  76. $util_class = new util();
  77. if ($util_class->beginsWith($songUrl, "http://odeo.com/audio/") || $util_class->beginsWith($songUrl, "http://www.odeo.com/audio/")) {
  78. return true;
  79. } else {
  80. return false;
  81. }
  82. }
  83. public function getOdeoCode($songUrl)
  84. {
  85. $params = explode("audio/", $songUrl);
  86. $params2 = explode("/", $params[1]);
  87. return $params2[0];
  88. }
  89. public function isImageFile($photoUrl)
  90. {
  91. $util_class = new util();
  92. if ($util_class->endsWith($photoUrl, ".jpg")) {
  93. return true;
  94. } elseif ($util_class->endsWith($photoUrl, ".gif")) {
  95. return true;
  96. } elseif ($util_class->endsWith($photoUrl, ".png")) {
  97. return true;
  98. } else {
  99. return false;
  100. }
  101. }
  102. public function getPhotoFile($remoteFileName)
  103. {
  104. $util_class = new util();
  105. if ($util_class->isImageFile($remoteFileName)) {
  106. if ($util_class->getFile($remoteFileName)) {
  107. return true;
  108. } else {
  109. return false;
  110. }
  111. } else {
  112. return false;
  113. }
  114. }
  115. public function getFile($remoteFileName)
  116. {
  117. $util_class = new util();
  118. $fileName = "../uploads/".$util_class->sanitizeName($util_class->getFileName($remoteFileName));
  119. $str = $util_class->_file_get_contents($remoteFileName);
  120. if (!$handle = fopen($fileName, 'w')) {
  121. //die("no se abrio de escritura");
  122. return false;
  123. }
  124. if (fwrite($handle, $str) === false) {
  125. //die("no se escribio");
  126. return false;
  127. }
  128. fclose($handle);
  129. return true;
  130. }
  131. public function isVimeoVideo($videoUrl)
  132. {
  133. $util_class = new util();
  134. if ($util_class->beginsWith($videoUrl, "http://vimeo.com/") || $util_class->beginsWith($videoUrl, "http://www.vimeo.com/") || $util_class->beginsWith($videoUrl, "https://vimeo.com/")) {
  135. return true;
  136. } else {
  137. return false;
  138. }
  139. }
  140. public function getVimeoVideoUrl($videoUrl)
  141. {
  142. if (substr_count($videoUrl, "clip:")==1) {
  143. return array_pop(explode("clip:", $videoUrl));
  144. } else {
  145. $videoUrl = explode("/", $videoUrl);
  146. return array_pop($videoUrl);
  147. }
  148. }
  149. public function isYoutubeVideo($videoUrl)
  150. {
  151. $url = explode("?", $videoUrl);
  152. $util_class = new util();
  153. if (($util_class->beginsWith($url[0], "https://") && $util_class->endsWith($url[0], ".youtube.com/watch")) || $util_class->beginsWith($url[0], "https://youtube.com/watch")) {
  154. return true;
  155. } else {
  156. return false;
  157. }
  158. }
  159. public function getYoutubeVideoUrl($videoUrl)
  160. {
  161. $params = explode("?v=", $videoUrl);
  162. $params2 = explode("&", $params[1]);
  163. return $params2[0];
  164. }
  165. public function isYahooVideo($videoUrl)
  166. {
  167. $util_class = new util();
  168. if ($util_class->beginsWith($videoUrl, "http://video.yahoo.com/watch/") || $util_class->beginsWith($videoUrl, "http://www.video.yahoo.com/watch/")) {
  169. return true;
  170. } else {
  171. return false;
  172. }
  173. }
  174. public function getYahooVideoCode($videoUrl)
  175. {
  176. $params = explode("http://video.yahoo.com/watch/", $videoUrl);
  177. $params2 = explode("/", $params[1]);
  178. $values[0] = $params2[0];
  179. $values[1] = $params2[1];
  180. return $values;
  181. }
  182. public function isGoogleVideoUrl($videoUrl)
  183. {
  184. $util_class = new util();
  185. if ($util_class->beginsWith($videoUrl, "http://video.google.com/videoplay?")) {
  186. return true;
  187. } else {
  188. return false;
  189. }
  190. }
  191. public function getGoogleVideoCode($videoUrl)
  192. {
  193. $params = explode("?docid=", $videoUrl);
  194. $params2 = explode("&", $params[1]);
  195. return $params2[0];
  196. }
  197. public function isMTVVideoUrl($videoUrl)
  198. {
  199. $util_class = new util();
  200. if ($util_class->beginsWith($videoUrl, "http://www.mtvmusic.com/video/?id=") || $util_class->beginsWith($videoUrl, "http://mtvmusic.com/video/?id=")) {
  201. return true;
  202. } else {
  203. return false;
  204. }
  205. }
  206. public function getMTVVideoCode($videoUrl)
  207. {
  208. $params = explode("?id=", $videoUrl);
  209. $params2 = explode("&", $params[1]);
  210. return $params2[0];
  211. }
  212. public function isDailymotionVideo($videoUrl)
  213. {
  214. $util_class = new util();
  215. if ($util_class->beginsWith($videoUrl, "http://www.dailymotion.com/video/") || $util_class->beginsWith($videoUrl, "http://dailymotion.com/video/")) {
  216. return true;
  217. } else {
  218. return false;
  219. }
  220. }
  221. public function getDailymotionVideoUrl($videoUrl)
  222. {
  223. $params = explode("video/", $videoUrl);
  224. $params2 = explode("_", $params[1]);
  225. return $params2[0];
  226. }
  227. public function isSlideSharePresentation($videoUrl)
  228. {
  229. $util_class = new util();
  230. if ($util_class->beginsWith($videoUrl, "[slideshare id=")) {
  231. return true;
  232. } else {
  233. return false;
  234. }
  235. }
  236. public function getSlideSharePresentationCode($videoUrl)
  237. {
  238. $videoUrl = str_replace("[slideshare id=", "", $videoUrl);
  239. $videoUrl = str_replace("&doc=", " ", $videoUrl);
  240. $videoUrl = str_replace("&w=", " ", $videoUrl);
  241. return explode(" ", $videoUrl);
  242. }
  243. public function isVideo($url)
  244. {
  245. $util_class = new util();
  246. if ($util_class->isYoutubeVideo($url)) {
  247. return true;
  248. } elseif ($util_class->isVimeoVideo($url)) {
  249. return true;
  250. } elseif ($util_class->isDailymotionVideo($url)) {
  251. return true;
  252. } elseif ($util_class->isYahooVideo($url)) {
  253. return true;
  254. } elseif ($util_class->isSlideSharePresentation($url)) {
  255. return true;
  256. } elseif ($util_class->isGoogleVideoUrl($url)) {
  257. return true;
  258. } elseif ($util_class->isMTVVideoUrl($url)) {
  259. return true;
  260. } else {
  261. return false;
  262. }
  263. }
  264. public function sendMail($to, $title, $body, $from)
  265. {
  266. $rp = trim($from);
  267. $org = "Sorbet CMS";
  268. $mailer = "Sorbet CMS Mailer";
  269. $head = '';
  270. $head .= "Content-Type: text/html \r\n";
  271. $head .= "Date: ". date('r'). " \r\n";
  272. $head .= "Return-Path: $rp \r\n";
  273. $head .= "From: $from \r\n";
  274. $head .= "Sender: $from \r\n";
  275. $head .= "Reply-To: $from \r\n";
  276. $head .= "Organization: $org \r\n";
  277. $head .= "X-Sender: $from \r\n";
  278. $head .= "X-Priority: 3 \r\n";
  279. $head .= "X-Mailer: $mailer \r\n";
  280. $body = str_replace("\r\n", "\n", $body);
  281. $body = str_replace("\n", "\r\n", $body);
  282. return @mail($to, $title, $body, $head);
  283. }
  284. public function getThemes()
  285. {
  286. $themes_dir = "themes";
  287. $dirs = array();
  288. $path = getcwd();
  289. $dir = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$themes_dir : $path."/".$themes_dir;
  290. $dir = str_replace("admin\\", "", $dir);
  291. $dir = str_replace("admin/", "", $dir);
  292. $handle = opendir($dir);
  293. $i=0;
  294. while ($filename = readdir($handle)) {
  295. if ($filename != "." && $filename != ".." && $filename != ".svn") {
  296. $dirs[$i]=trim($filename);
  297. $i++;
  298. }
  299. }
  300. closedir($handle);
  301. return $dirs;
  302. }
  303. public function sanitizeName($name)
  304. {
  305. $name = preg_replace('/[\'"]/', '', $name);
  306. $name = preg_replace('/[^a-zA-Z0-9]+/', '-', $name);
  307. $name = trim($name, '-');
  308. $name = strtolower($name);
  309. //HACK: We need to rework the regular expression to allow the dot
  310. $ext = substr($name, strlen($name)-3, strlen($name));
  311. $body = substr($name, 0, strlen($name)-4);
  312. $name = $body.".".$ext;
  313. return $name;
  314. }
  315. public function _file_get_contents($path)
  316. {
  317. $util_class = new util();
  318. // Modified function from:
  319. // http://work.dokoku.net/Anieto2k/_file_get_contents.phps
  320. // http://www.anieto2k.com/2007/02/09/file_get_contents-y-dreamhost/
  321. if (!preg_match('/^http/i', $path)) {
  322. if ($fp = fopen($path, 'r')) {
  323. return fread($fp, 1024);
  324. } else {
  325. return false;
  326. }
  327. } else {
  328. if (extension_loaded('curl') && version_compare($util_class->get_curl_version(), '7.10.5', '>=')) {
  329. $ch = curl_init();
  330. $timeout = 5;
  331. curl_setopt($ch, CURLOPT_URL, $path);
  332. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  333. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  334. $file_contents = curl_exec($ch);
  335. curl_close($ch);
  336. if (is_string($file_contents)) {
  337. return $file_contents;
  338. } else {
  339. return false;
  340. }
  341. } else {
  342. $data = parse_url($path);
  343. if (!$data['host'] || $data['scheme'] != "http") {
  344. return false;
  345. }
  346. $f = @fsockopen($data['host'], ($data['port']) ? $data['port'] : 80, $e1, $e2, 3);
  347. if (!$f) {
  348. return false;
  349. }
  350. $q = "GET " . $data['path'] . (isset($data['query'])?'?'.$data['query']:'') . " HTTP/1.1\r\n";
  351. $q .= "Host: " . $data['host'] . "\r\n";
  352. $q .= "Connection: close\r\n";
  353. $q .= "Referer: //www.sorbetcms.net/\r\n\r\n";
  354. $recv = "";
  355. fwrite($f, $q);
  356. while (!feof($f)) {
  357. $recv .= fread($f, 1024);
  358. }
  359. $request = $q;
  360. $response = substr($recv, 0, strpos($recv, "\r\n\r\n"));
  361. $body = substr($recv, strpos($recv, "\r\n\r\n") + 4);
  362. if (preg_match('/http\/1\\.[0|1] ([0-9]{3})/i', $response, $res)) {
  363. if ($res[1][0] != "2") {
  364. return false;
  365. }
  366. } else {
  367. return false;
  368. }
  369. if (preg_match('/transfer-encoding:\s*chunked/i', $response)) {
  370. $tmp_body = $body;
  371. $new = "";
  372. $exit = false;
  373. while (!$exit) {
  374. if (preg_match('/^([0-9a-f]+).*?\r\n/i', $tmp_body, $res)) {
  375. $len = hexdec($res[1]);
  376. if ($len == "0") {
  377. $exit = true;
  378. break;
  379. }
  380. $new .= substr($tmp_body, strlen($res[0]), $len);
  381. $tmp_body = substr($tmp_body, strlen($res[0]) + $len + strlen("\r\n"));
  382. } else {
  383. $exit = true;
  384. }
  385. }
  386. $body = $new;
  387. }
  388. return $body;
  389. }
  390. }
  391. }
  392. public function get_curl_version()
  393. {
  394. $curl = 0;
  395. if (is_array(curl_version())) {
  396. $curl = curl_version();
  397. $curl = $curl['version'];
  398. } else {
  399. $curl = curl_version();
  400. $curl = explode(' ', $curl);
  401. $curl = explode('/', $curl[0]);
  402. $curl = $curl[1];
  403. }
  404. return $curl;
  405. }
  406. public function transform_offset($offset)
  407. {
  408. $sp = strpos($offset, ".")? explode(".", $offset) : false;
  409. if (is_array($sp)) {
  410. $minutes = strval($sp[1]);
  411. $off_h = $sp[0]*3600;
  412. $off_m = (($minutes*60)/100)*60;
  413. $off = $off_h+$off_m;
  414. } else {
  415. $off = ($offset*3600);
  416. }
  417. return $off;
  418. }
  419. public function getLangs()
  420. {
  421. $util_class = new util();
  422. $langs_dir = "languages";
  423. $dirs = array();
  424. $path = getcwd();
  425. $dir = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$langs_dir : $path."/".$langs_dir;
  426. $dir = str_replace("admin\\", "", $dir);
  427. $dir = str_replace("admin/", "", $dir);
  428. $i=0;
  429. $cls_lang_dir = @ dir($dir);
  430. while (($directory = $cls_lang_dir->read()) !== false) {
  431. if ($directory != "." && $directory != "..") {
  432. $dir2 = (substr(PHP_OS, 0, 3) == 'WIN') ? $path."\\".$langs_dir."\\".$directory : $path."/".$langs_dir."/".$directory;
  433. $dir2 = str_replace("admin\\", "", $dir2);
  434. $dir2 = str_replace("admin/", "", $dir2);
  435. if (is_dir($dir2)) {
  436. $cls_lang_dir2 = @ dir($dir2);
  437. while (($directory2 = $cls_lang_dir2->read()) !== false) {
  438. if ($directory2 != "." && $directory2 != "..") {
  439. if (preg_match('|^\.+$|', $directory2)) {
  440. continue;
  441. }
  442. if (preg_match('|\.mo$|', $directory2)) {
  443. if (!in_array($directory2, $dirs)) {
  444. $dirs[$directory]=$util_class->displayLanguage(trim($directory));
  445. $i++;
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. $dirs = array_unique($dirs);
  454. return $dirs;
  455. }
  456. public function removeBadTags($source, $secure=false)
  457. {
  458. $util_class = new util();
  459. if ($secure) {
  460. $validTags ='<blockquote><code><em><i><strong><b><a>';
  461. } else {
  462. $validTags ='<p><ol><ul><li><a><abbr><acronym><blockquote><code><pre><em><i><strong><b><del><br><span><div><img>';
  463. }
  464. $source = strip_tags($source, $validTags);
  465. return preg_replace_callback('/<(.*?)>/i',
  466. function ($m) {
  467. $util_class = new util();
  468. return"<{$util_class->removeBadAtributes($m[1])}>";
  469. },
  470. $source
  471. );
  472. }
  473. public function removeBadAtributes($sourceTag)
  474. {
  475. $badAtributes = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';
  476. $sourceTag = stripslashes($sourceTag);
  477. $sourceTag = preg_replace("/$badAtributes/i", "niceTry", $sourceTag);
  478. return $sourceTag;
  479. }
  480. public function type2Text($number)
  481. {
  482. $tmpStr = "";
  483. switch ($number) {
  484. case "1":
  485. $tmpStr = "post";
  486. break;
  487. case "2":
  488. $tmpStr = "photo";
  489. break;
  490. case "3":
  491. $tmpStr = "quote";
  492. break;
  493. case "4":
  494. $tmpStr = "url";
  495. break;
  496. case "5":
  497. $tmpStr = "conversation";
  498. break;
  499. case "6":
  500. $tmpStr = "video";
  501. break;
  502. case "7":
  503. $tmpStr = "mp3";
  504. break;
  505. }
  506. return $tmpStr;
  507. }
  508. public function type2Number($string)
  509. {
  510. $tmpStr = "";
  511. switch ($string) {
  512. case "post":
  513. $tmpStr = "1";
  514. break;
  515. case "photo":
  516. $tmpStr = "2";
  517. break;
  518. case "quote":
  519. $tmpStr = "3";
  520. break;
  521. case "url":
  522. $tmpStr = "4";
  523. break;
  524. case "conversation":
  525. $tmpStr = "5";
  526. break;
  527. case "video":
  528. $tmpStr = "6";
  529. break;
  530. case "mp3":
  531. $tmpStr = "7";
  532. break;
  533. }
  534. return $tmpStr;
  535. }
  536. public function trimString($string, $len=50)
  537. {
  538. if ($len>strlen(strip_tags($string)) or $len<1 or strlen(strip_tags($string))<1) {
  539. return strip_tags($string);
  540. }
  541. $string = strip_tags($string);
  542. return (strpos($string, " ", $len))?substr_replace($string, "...", $len):$string;
  543. }
  544. public function displayLanguage($lang)
  545. {
  546. $out = "";
  547. if (strpos($lang, '-')==2) {
  548. $lang = explode('-', $lang);
  549. }
  550. $language = is_array($lang)? $lang[0] : $lang;
  551. switch ($language) {
  552. case 'af': $out = __('Afrikaans'); break;
  553. case 'sq': $out = __('Albanian'); break;
  554. case 'ar': $out = __('Arabic'); break;
  555. case 'eu': $out = __('Basque'); break;
  556. case 'bg': $out = __('Bulgarian'); break;
  557. case 'be': $out = __('Belarusian'); break;
  558. case 'ca': $out = __('Catalan'); break;
  559. case 'zh': $out = __('Chinese'); break;
  560. case 'hr': $out = __('Croatian'); break;
  561. case 'cs': $out = __('Czech'); break;
  562. case 'da': $out = __('Danish'); break;
  563. case 'nl': $out = __('Dutch'); break;
  564. case 'en': $out = __('English'); break;
  565. case 'et': $out = __('Estonian'); break;
  566. case 'fo': $out = __('Faeroese'); break;
  567. case 'fa': $out = __('Farsi'); break;
  568. case 'fi': $out = __('Finnish'); break;
  569. case 'fr': $out = __('French'); break;
  570. case 'gd': $out = __('Gaelic'); break;
  571. case 'de': $out = __('German'); break;
  572. case 'el': $out = __('Greek'); break;
  573. case 'he': $out = __('Hebrew'); break;
  574. case 'hi': $out = __('Hindi'); break;
  575. case 'hu': $out = __('Hungarian'); break;
  576. case 'is': $out = __('Icelandic'); break;
  577. case 'id': $out = __('Indonesian'); break;
  578. case 'it': $out = __('Italian'); break;
  579. case 'ja': $out = __('Japanese'); break;
  580. case 'ko': $out = __('Korean'); break;
  581. case 'lv': $out = __('Latvian'); break;
  582. case 'lt': $out = __('Lithuanian'); break;
  583. case 'mk': $out = __('Macedonian'); break;
  584. case 'ms': $out = __('Malaysian'); break;
  585. case 'mt': $out = __('Maltese'); break;
  586. case 'no': $out = __('Norwegian'); break;
  587. case 'pl': $out = __('Polish'); break;
  588. case 'pt': $out = __('Portuguese'); break;
  589. case 'rm': $out = __('Rhaeto-Romanic'); break;
  590. case 'ro': $out = __('Romanian'); break;
  591. case 'ru': $out = __('Russian'); break;
  592. case 'sz': $out = __('Sami'); break;
  593. case 'sr': $out = __('Serbian'); break;
  594. case 'sk': $out = __('Slovak'); break;
  595. case 'sl': $out = __('Slovenian'); break;
  596. case 'sb': $out = __('Sorbian'); break;
  597. case 'es': $out = __('Spanish'); break;
  598. case 'sx': $out = __('Sutu'); break;
  599. case 'sv': $out = __('Swedish'); break;
  600. case 'th': $out = __('Thai'); break;
  601. case 'ts': $out = __('Tsonga'); break;
  602. case 'tn': $out = __('Tswana'); break;
  603. case 'tr': $out = __('Turkish'); break;
  604. case 'uk': $out = __('Ukrainian'); break;
  605. case 'ur': $out = __('Urdu'); break;
  606. case 've': $out = __('Venda'); break;
  607. case 'vi': $out = __('Vietnamese'); break;
  608. case 'xh': $out = __('Xhosa'); break;
  609. case 'ji': $out = __('Yiddish'); break;
  610. case 'zu': $out = __('Zulu'); break;
  611. default: $out = $language;
  612. }
  613. if (is_array($lang)) {
  614. $country = strtolower($lang[1]);
  615. switch ($country) {
  616. //Aca una lista con los paises. No se como tendr\EDa que hacer para hacer insensible a mayusculas o minusculas: es-MX o es-mx \BF?
  617. case 'sa': $out .= " (". __('Saudi Arabia'). ")"; break;
  618. case 'iq': $out .= " (". __('Iraq'). ")"; break;
  619. case 'eg': $out .= " (". __('Egypt'). ")"; break;
  620. case 'ly': $out .= " (". __('Libya'). ")"; break;
  621. case 'dz': $out .= " (". __('Algeria'). ")"; break;
  622. case 'ma': $out .= " (". __('Morocco'). ")"; break;
  623. case 'tn': $out .= " (". __('Tunisia'). ")"; break;
  624. case 'om': $out .= " (". __('Oman'). ")"; break;
  625. case 'ye': $out .= " (". __('Yemen'). ")"; break;
  626. case 'sy': $out .= " (". __('Syria'). ")"; break;
  627. case 'jo': $out .= " (". __('Jordan'). ")"; break;
  628. case 'lb': $out .= " (". __('Lebanon'). ")"; break;
  629. case 'kw': $out .= " (". __('Kuwait'). ")"; break;
  630. case 'ae': $out .= " (". __('U.A.E.'). ")"; break;
  631. case 'bh': $out .= " (". __('Bahrain'). ")"; break;
  632. case 'qa': $out .= " (". __('Qatar'). ")"; break;
  633. case 'tw': $out .= " (". __('Taiwan'). ")"; break;
  634. case 'cn': $out .= " (". __('PRC'). ")"; break;
  635. case 'hk': $out .= " (". __('Hong Kong SAR'). ")"; break;
  636. case 'sg': $out .= " (". __('Singapore'). ")"; break;
  637. case 'be': $out .= " (". __('Belgium'). ")"; break;
  638. case 'us': $out .= " (". __('United States'). ")"; break;
  639. case 'gb': $out .= " (". __('United Kingdom'). ")"; break;
  640. case 'au': $out .= " (". __('Australia'). ")"; break;
  641. case 'ca': $out .= " (". __('Canada'). ")"; break;
  642. case 'nz': $out .= " (". __('New Zealand'). ")"; break;
  643. case 'ie': $out .= " (". __('Ireland'). ")"; break;
  644. case 'za': $out .= " (". __('South Africa'). ")"; break;
  645. case 'jm': $out .= " (". __('Jamaica'). ")"; break;
  646. case 'bz': $out .= " (". __('Belize'). ")"; break;
  647. case 'tt': $out .= " (". __('Trinidad'). ")"; break;
  648. case 'ch': $out .= " (". __('Switzerland'). ")"; break;
  649. case 'lu': $out .= " (". __('Luxembourg'). ")"; break;
  650. case 'at': $out .= " (". __('Austria'). ")"; break;
  651. case 'li': $out .= " (". __('Liechtenstein'). ")"; break;
  652. case 'br': $out .= " (". __('Brazil'). ")"; break;
  653. case 'pt': $out .= " (". __('Portugal'). ")"; break;
  654. case 'mo': $out .= " (". __('Republic of Moldova'). ")"; break;
  655. case 'sz': $out .= " (". __('Lappish'). ")"; break;
  656. case 'mx': $out .= " (". __('Mexico'). ")"; break;
  657. case 'gt': $out .= " (". __('Guatemala'). ")"; break;
  658. case 'cr': $out .= " (". __('Costa Rica'). ")"; break;
  659. case 'pa': $out .= " (". __('Panama'). ")"; break;
  660. case 'do': $out .= " (". __('Dominican Republic'). ")"; break;
  661. case 've': $out .= " (". __('Venezuela'). ")"; break;
  662. case 'co': $out .= " (". __('Colombia'). ")"; break;
  663. case 'pe': $out .= " (". __('Peru'). ")"; break;
  664. case 'ar': $out .= " (". __('Argentina'). ")"; break;
  665. case 'ec': $out .= " (". __('Ecuador'). ")"; break;
  666. case 'cl': $out .= " (". __('Chile'). ")"; break;
  667. case 'uy': $out .= " (". __('Uruguay'). ")"; break;
  668. case 'py': $out .= " (". __('Paraguay'). ")"; break;
  669. case 'bo': $out .= " (". __('Bolivia'). ")"; break;
  670. case 'sv': $out .= " (". __('El Salvador'). ")"; break;
  671. case 'hn': $out .= " (". __('Honduras'). ")"; break;
  672. case 'ni': $out .= " (". __('Nicaragua'). ")"; break;
  673. case 'pr': $out .= " (". __('Puerto Rico'). ")"; break;
  674. case 'fi': $out .= " (". __('Finland'). ")"; break;
  675. default: $out .= "(".$country.")";
  676. }
  677. }
  678. return $out;
  679. }
  680. public function init_plugins()
  681. {
  682. global $conf;
  683. $actives = json_decode($conf->active_plugins, 1);
  684. $actives = $actives[1];
  685. foreach ((array)$actives as $index => $plugin) {
  686. if (!file_exists(Absolute_Path."plugins/".$plugin)) {
  687. unset($actives[$index]);
  688. continue;
  689. } else {
  690. require_once(Absolute_Path.'plugins/'.$plugin);
  691. }
  692. if (!class_exists($index)) {
  693. continue;
  694. }
  695. $GLOBALS['plugins::$instances'][$index] = new $index;
  696. }
  697. }
  698. }
  699. ?>