A tumblelog CMS built on AJAX, PHP and MySQL.

util.class.php 26KB

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