You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

684 lines
22 KiB

  1. <?php
  2. /**
  3. * @file Utils.php
  4. * This file is part of PROJECT.
  5. *
  6. * @brief Description
  7. *
  8. * @author Etenil <etenil@etenilsrealm.nl>
  9. *
  10. * @version 1.0
  11. * @date 20 February 2011
  12. *
  13. * Copyright (C)2011 Etenil
  14. *
  15. * All rights reserved.
  16. */
  17. // Handy.
  18. function println($string)
  19. {
  20. $args = func_get_args();
  21. echo call_user_func_array('sprintf', $args) . PHP_EOL;
  22. }
  23. function sprintln($string)
  24. {
  25. $args = func_get_args();
  26. return call_user_func_array('sprintf', $args) . PHP_EOL;
  27. }
  28. /*
  29. * Return the current microtime
  30. */
  31. function getTime()
  32. {
  33. $a = explode (' ',microtime());
  34. return(double) $a[0] + $a[1];
  35. }
  36. /**
  37. * Replaces anchor tags with text
  38. * - Will search string and replace all anchor tags with text (case insensitive)
  39. *
  40. * How it works:
  41. * - Searches string for an anchor tag, checks to make sure it matches the criteria
  42. * Anchor search criteria:
  43. * - 1 - <a (must have the start of the anchor tag )
  44. * - 2 - Can have any number of spaces or other attributes before and after the href attribute
  45. * - 3 - Must close the anchor tag
  46. *
  47. * - Once the check has passed it will then replace the anchor tag with the string replacement
  48. * - The string replacement can be customized
  49. *
  50. * Know issue:
  51. * - This will not work for anchors that do not use a ' or " to contain the attributes.
  52. * (i.e.- <a href=http: //php.net>PHP.net</a> will not be replaced)
  53. */
  54. function replaceAnchorsWithText($data) {
  55. /**
  56. * Had to modify $regex so it could post to the site... so I broke it into 6 parts.
  57. */
  58. $regex = '/(<a\s*'; // Start of anchor tag
  59. $regex .= '(.*?)\s*'; // Any attributes or spaces that may or may not exist
  60. $regex .= 'href=[\'"]+?\s*(?P<link>\S+)\s*[\'"]+?'; // Grab the link
  61. $regex .= '\s*(.*?)\s*>\s*'; // Any attributes or spaces that may or may not exist before closing tag
  62. $regex .= '(?P<name>\S+)'; // Grab the name
  63. $regex .= '\s*<\/a>)/i'; // Any number of spaces between the closing anchor tag (case insensitive)
  64. if (is_array($data)) {
  65. // This is what will replace the link (modify to you liking)
  66. $data = "{$data['name']} {$data['link']} ";
  67. }
  68. return preg_replace_callback($regex, 'replaceAnchorsWithText', $data);
  69. }
  70. /**
  71. * Prepare the string (add the a to the links and show the smileys)
  72. *
  73. * @param string $string
  74. * @return string
  75. */
  76. function prepareString($string) {
  77. $smileys =
  78. array(
  79. ':okay:' => 'okay.gif',
  80. 'O:\)' => 'ange.gif',
  81. 'O:-\)' => 'ange.gif',
  82. ':\)' => 'smile.gif',
  83. ':-\)' => 'smile.gif',
  84. ':\(' => 'frown.gif',
  85. ':o' => 'redface.gif',
  86. ':love:' => 'love.gif',
  87. '<3' => 'love.gif',
  88. ':D' => 'biggrin.gif',
  89. ':d' => 'biggrin.gif',
  90. ':p' => 'tongue.gif',
  91. ':P' => 'tongue.gif',
  92. ':-P' => 'tongue.gif',
  93. ':\/' => 'bof.gif',
  94. ';\)' => 'wink.gif',
  95. 'B\)' => 'sol.gif',
  96. ":'\(" => 'cry.gif',
  97. ':trolldad:' => 'trolldad.png',
  98. ':epic:' => 'epic.png',
  99. ':aloneyeah:' => 'aloneyeah.png',
  100. ':fapfap:' => 'fapfap.png',
  101. ':megusta:' => 'gusta.png',
  102. ':trollface:' => 'trollface.png',
  103. ':troll:' => 'trollface.png',
  104. ':lol:' => 'trollol.png',
  105. );
  106. $fixer = new HtmlFixer();
  107. $string = $fixer->getFixedHtml($string);
  108. $string = str_replace('<a ', '<a target="_blank" ', $string);
  109. $string = preg_replace(
  110. array(
  111. '/(^|\s|>)(www.[^<> \n\r]+)/iex',
  112. '/(^|\s|>)([_A-Za-z0-9-]+(\\.[A-Za-z]{2,3})?\\.[A-Za-z]{2,4}\\/[^<> \n\r]+)/iex',
  113. '/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\'])((?:https?):\/\/([^<> \n\r]+)))/iex',
  114. '#<script[^>]*>.*?</script>#is'
  115. ),
  116. array(
  117. "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>&nbsp;\\2':'\\0'))",
  118. "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>&nbsp;\\4':'\\0'))",
  119. "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\" target=\"_blank\">\\2</a>&nbsp;':'\\0'))",
  120. ''
  121. ),
  122. ' '.$string
  123. );
  124. // We add some smileys...
  125. $conf = new Conf();
  126. $theme = $conf->getServerConfElement('theme');
  127. $path = BASE_URI . 'themes/' . $theme . '/img/smileys/';
  128. foreach($smileys as $key => $value) {
  129. $replace = ' <img class="smiley" src="'.$path.$value.'">';
  130. $string = preg_replace('/(^|[ ])('.$key.')/', $replace, $string);
  131. }
  132. return trim($string);
  133. }
  134. /**
  135. * Return a human-readable date
  136. *
  137. * @param timestamp $string
  138. * @return string
  139. */
  140. function prepareDate($time, $hours = true) {
  141. $dotw = array(
  142. 1 => t('Monday'),
  143. 2 => t('Tuesday'),
  144. 3 => t('Wednesday'),
  145. 4 => t('Thursday'),
  146. 5 => t('Friday'),
  147. 6 => t('Saturday'),
  148. 7 => t('Friday'));
  149. $moty = array(
  150. 1 => t('January'),
  151. 2 => t('February'),
  152. 3 => t('March'),
  153. 4 => t('April'),
  154. 5 => t('May'),
  155. 6 => t('June'),
  156. 7 => t('July'),
  157. 8 => t('August'),
  158. 9 => t('September'),
  159. 10 => t('October'),
  160. 11 => t('November'),
  161. 12 => t('December'));
  162. $today = strtotime(date('M j, Y'));
  163. $reldays = ($time - $today)/86400;
  164. if ($reldays >= 0 && $reldays < 1) {
  165. $date = t('Today');
  166. } else if ($reldays >= 1 && $reldays < 2) {
  167. $date = t('Tomorrow');
  168. } else if ($reldays >= -1 && $reldays < 0) {
  169. $date = t('Yesterday');
  170. } else {
  171. if (abs($reldays) < 7) {
  172. if ($reldays > 0) {
  173. $reldays = floor($reldays);
  174. $date = 'In ' . $reldays . ' '.t('day') . ($reldays != 1 ? 's' : '');
  175. } else {
  176. $reldays = abs(floor($reldays));
  177. $date = t(' %d days ago', $reldays);
  178. }
  179. } else {
  180. $date = $dotw[date('N',$time ? $time : time())] .', '.date('j',$time ? $time : time()).' '.$moty[date('n',$time ? $time : time())] ;
  181. if (abs($reldays) > 182)
  182. $date .= date(', Y',$time ? $time : time());
  183. }
  184. }
  185. if($hours)
  186. $date .= ' - '. date('H:i', $time);
  187. if($time)
  188. return $date;
  189. }
  190. /**
  191. * Generate a ramdom hash
  192. *
  193. * @return string
  194. */
  195. function generateHash(){
  196. $result = "";
  197. $charPool = '0123456789abcdefghijklmnopqrstuvwxyz';
  198. for($p = 0; $p<15; $p++)
  199. $result .= $charPool[mt_rand(0,strlen($charPool)-1)];
  200. return sha1($result);
  201. }
  202. /**
  203. * Return the list of gender
  204. */
  205. function getGender() {
  206. return array('N' => t('None'),
  207. 'M' => t('Male'),
  208. 'F' => t('Female'),
  209. 'O' => t('Other')
  210. );
  211. }
  212. /**
  213. * Return an array of informations from a XMPP uri
  214. */
  215. function explodeURI($uri) {
  216. $arr = parse_url(urldecode($uri));
  217. $result = array();
  218. if(isset($arr['query'])) {
  219. $query = explode(';', $arr['query']);
  220. foreach($query as $elt) {
  221. if($elt != '') {
  222. list($key, $val) = explode('=', $elt);
  223. $result[$key] = $val;
  224. }
  225. }
  226. $arr = array_merge($arr, $result);
  227. }
  228. return $arr;
  229. }
  230. /**
  231. * Return a list of all the country
  232. */
  233. function getCountries() {
  234. return array(
  235. "Afghanistan",
  236. "Albania",
  237. "Algeria",
  238. "Andorra",
  239. "Angola",
  240. "Antigua and Barbuda",
  241. "Argentina",
  242. "Armenia",
  243. "Australia",
  244. "Austria",
  245. "Azerbaijan",
  246. "Bahamas",
  247. "Bahrain",
  248. "Bangladesh",
  249. "Barbados",
  250. "Belarus",
  251. "Belgium",
  252. "Belize",
  253. "Benin",
  254. "Bhutan",
  255. "Bolivia",
  256. "Bosnia and Herzegovina",
  257. "Botswana",
  258. "Brazil",
  259. "Brunei",
  260. "Bulgaria",
  261. "Burkina Faso",
  262. "Burundi",
  263. "Cambodia",
  264. "Cameroon",
  265. "Canada",
  266. "Cape Verde",
  267. "Central African Republic",
  268. "Chad",
  269. "Chile",
  270. "China",
  271. "Colombi",
  272. "Comoros",
  273. "Congo (Brazzaville)",
  274. "Congo",
  275. "Costa Rica",
  276. "Cote d'Ivoire",
  277. "Croatia",
  278. "Cuba",
  279. "Cyprus",
  280. "Czech Republic",
  281. "Denmark",
  282. "Djibouti",
  283. "Dominica",
  284. "Dominican Republic",
  285. "East Timor (Timor Timur)",
  286. "Ecuador",
  287. "Egypt",
  288. "El Salvador",
  289. "Equatorial Guinea",
  290. "Eritrea",
  291. "Estonia",
  292. "Ethiopia",
  293. "Fiji",
  294. "Finland",
  295. "France",
  296. "Gabon",
  297. "Gambia, The",
  298. "Georgia",
  299. "Germany",
  300. "Ghana",
  301. "Greece",
  302. "Grenada",
  303. "Guatemala",
  304. "Guinea",
  305. "Guinea-Bissau",
  306. "Guyana",
  307. "Haiti",
  308. "Honduras",
  309. "Hungary",
  310. "Iceland",
  311. "India",
  312. "Indonesia",
  313. "Iran",
  314. "Iraq",
  315. "Ireland",
  316. "Israel",
  317. "Italy",
  318. "Jamaica",
  319. "Japan",
  320. "Jordan",
  321. "Kazakhstan",
  322. "Kenya",
  323. "Kiribati",
  324. "Korea, North",
  325. "Korea, South",
  326. "Kuwait",
  327. "Kyrgyzstan",
  328. "Laos",
  329. "Latvia",
  330. "Lebanon",
  331. "Lesotho",
  332. "Liberia",
  333. "Libya",
  334. "Liechtenstein",
  335. "Lithuania",
  336. "Luxembourg",
  337. "Macedonia",
  338. "Madagascar",
  339. "Malawi",
  340. "Malaysia",
  341. "Maldives",
  342. "Mali",
  343. "Malta",
  344. "Marshall Islands",
  345. "Mauritania",
  346. "Mauritius",
  347. "Mexico",
  348. "Micronesia",
  349. "Moldova",
  350. "Monaco",
  351. "Mongolia",
  352. "Morocco",
  353. "Mozambique",
  354. "Myanmar",
  355. "Namibia",
  356. "Nauru",
  357. "Nepa",
  358. "Netherlands",
  359. "New Zealand",
  360. "Nicaragua",
  361. "Niger",
  362. "Nigeria",
  363. "Norway",
  364. "Oman",
  365. "Pakistan",
  366. "Palau",
  367. "Panama",
  368. "Papua New Guinea",
  369. "Paraguay",
  370. "Peru",
  371. "Philippines",
  372. "Poland",
  373. "Portugal",
  374. "Qatar",
  375. "Romania",
  376. "Russia",
  377. "Rwanda",
  378. "Saint Kitts and Nevis",
  379. "Saint Lucia",
  380. "Saint Vincent",
  381. "Samoa",
  382. "San Marino",
  383. "Sao Tome and Principe",
  384. "Saudi Arabia",
  385. "Senegal",
  386. "Serbia and Montenegro",
  387. "Seychelles",
  388. "Sierra Leone",
  389. "Singapore",
  390. "Slovakia",
  391. "Slovenia",
  392. "Solomon Islands",
  393. "Somalia",
  394. "South Africa",
  395. "Spain",
  396. "Sri Lanka",
  397. "Sudan",
  398. "Suriname",
  399. "Swaziland",
  400. "Sweden",
  401. "Switzerland",
  402. "Syria",
  403. "Taiwan",
  404. "Tajikistan",
  405. "Tanzania",
  406. "Thailand",
  407. "Togo",
  408. "Tonga",
  409. "Trinidad and Tobago",
  410. "Tunisia",
  411. "Turkey",
  412. "Turkmenistan",
  413. "Tuvalu",
  414. "Uganda",
  415. "Ukraine",
  416. "United Arab Emirates",
  417. "United Kingdom",
  418. "United States",
  419. "Uruguay",
  420. "Uzbekistan",
  421. "Vanuatu",
  422. "Vatican City",
  423. "Venezuela",
  424. "Vietnam",
  425. "Yemen",
  426. "Zambia",
  427. "Zimbabwe"
  428. );
  429. }
  430. /**
  431. * Return the list of marital status
  432. */
  433. function getMarital() {
  434. return array('none' => t('None'),
  435. 'single' => t('Single'),
  436. 'relationship' => t('In a relationship'),
  437. 'married' => t('Married'),
  438. 'divorced' => t('Divorced'),
  439. 'widowed' => t('Widowed'),
  440. 'cohabiting' => t('Cohabiting'),
  441. 'union' => t('Civil Union')
  442. );
  443. }
  444. function getPresences() {
  445. return array(
  446. 1 => t('Online'),
  447. 2 => t('Away'),
  448. 3 => t('Do Not Disturb'),
  449. 4 => t('Extended Away'),
  450. 5 => t('Logout')
  451. );
  452. }
  453. function getPresencesTxt() {
  454. return array(
  455. 1 => 'online',
  456. 2 => 'away',
  457. 3 => 'dnd',
  458. 4 => 'xa',
  459. 5 => 'offline',
  460. 6 => 'server_error'
  461. );
  462. }
  463. function getMood() {
  464. return array(
  465. 'afraid' => t('afraid'), // Impressed with fear or apprehension; in fear; apprehensive.
  466. 'amazed' => t('amazed'), // Astonished; confounded with fear, surprise or wonder.
  467. 'amorous' => t('amorous'), // Inclined to love; having a propensity to love, or to sexual enjoyment; loving, fond, affectionate, passionate, lustful, sexual, etc.
  468. 'angry' => t('angry'), // Displaying or feeling anger, i.e., a strong feeling of displeasure, hostility or antagonism towards someone or something, usually combined with an urge to harm.
  469. 'annoyed' => t('annoyed'), // To be disturbed or irritated, especially by continued or repeated acts.
  470. 'anxious' => t('anxious'), // Full of anxiety or disquietude; greatly concerned or solicitous, esp. respecting something future or unknown; being in painful suspense.
  471. 'aroused' => t('aroused'), // To be stimulated in one's feelings, especially to be sexually stimulated.
  472. 'ashamed' => t('ashamed'), // Feeling shame or guilt.
  473. 'bored' => t('bored'), // Suffering from boredom; uninterested, without attention.
  474. 'brave' => t('brave'), // Strong in the face of fear; courageous.
  475. 'calm' => t('calm'), // Peaceful, quiet.
  476. 'cautious' => t('cautious'), // Taking care or caution; tentative.
  477. 'cold' => t('cold'), // Feeling the sensation of coldness, especially to the point of discomfort.
  478. 'confident' => t('confident'), // Feeling very sure of or positive about something, especially about one's own capabilities.
  479. 'condused' => t('confused'), // Chaotic, jumbled or muddled.
  480. 'contemplative' => t('contemplative'), // Feeling introspective or thoughtful.
  481. 'contented' => t('contented'), // Pleased at the satisfaction of a want or desire; satisfied.
  482. 'cranzy' => t('cranky'), // Grouchy, irritable; easily upset.
  483. 'crazy' => t('crazy'), // Feeling out of control; feeling overly excited or enthusiastic.
  484. 'creative' => t('creative'), // Feeling original, expressive, or imaginative.
  485. 'curious' => t('curious'), // Inquisitive; tending to ask questions, investigate, or explore.
  486. 'dejected' => t('dejected'), // Feeling sad and dispirited.
  487. 'depressed' => t('depressed'), // Severely despondent and unhappy.
  488. 'disappointed' => t('disappointed'), // Defeated of expectation or hope; let down.
  489. 'disgusted' => t('disgusted'), // Filled with disgust; irritated and out of patience.
  490. 'dismayed' => t('dismayed'), // Feeling a sudden or complete loss of courage in the face of trouble or danger.
  491. 'distracted' => t('distracted'), // Having one's attention diverted; preoccupied.
  492. 'embarrassed' => t('embarrassed'), // Having a feeling of shameful discomfort.
  493. 'envious' => t('envious'), // Feeling pain by the excellence or good fortune of another.
  494. 'excited' => t('excited'), // Having great enthusiasm.
  495. 'flirtatious' => t('flirtatious'), // In the mood for flirting.
  496. 'frustated' => t('frustrated'), // Suffering from frustration; dissatisfied, agitated, or discontented because one is unable to perform an action or fulfill a desire.
  497. 'grateful' => t('grateful'), // Feeling appreciation or thanks.
  498. 'grieving' => t('grieving'), // Feeling very sad about something, especially something lost; mournful; sorrowful.
  499. 'grumpy' => t('grumpy'), // Unhappy and irritable.
  500. 'guilty' => t('guilty'), // Feeling responsible for wrongdoing; feeling blameworthy.
  501. 'happy' => t('happy'), // Experiencing the effect of favourable fortune; having the feeling arising from the consciousness of well-being or of enjoyment; enjoying good of any kind, as peace, tranquillity, comfort; contented; joyous.
  502. 'hopeful' => t('hopeful'), // Having a positive feeling, belief, or expectation that something wished for can or will happen.
  503. 'hot' => t('hot'), // Feeling the sensation of heat, especially to the point of discomfort.
  504. 'humbled' => t('humbled'), // Having or showing a modest or low estimate of one's own importance; feeling lowered in dignity or importance.
  505. 'humiliated' => t('humiliated'), // Feeling deprived of dignity or self-respect.
  506. 'hungry' => t('hungry'), // Having a physical need for food.
  507. 'hurt' => t('hurt'), // Wounded, injured, or pained, whether physically or emotionally.
  508. 'impressed' => t('impressed'), // Favourably affected by something or someone.
  509. 'in_awe' => t('in awe'), // Feeling amazement at something or someone; or feeling a combination of fear and reverence.
  510. 'in_love' => t('in love'), // Feeling strong affection, care, liking, or attraction..
  511. 'indignant' => ('indignant'), // Showing anger or indignation, especially at something unjust or wrong.
  512. 'interested' => t('interested'), // Showing great attention to something or someone; having or showing interest.
  513. 'intoxicated' => t('intoxicated'), // Under the influence of alcohol; drunk.
  514. 'invincible' => t('invincible'), // Feeling as if one cannot be defeated, overcome or denied.
  515. 'jealous' => t('jealous'), // Fearful of being replaced in position or affection.
  516. 'lonely' => t('lonely'), // Feeling isolated, empty, or abandoned.
  517. 'lost' => t('lost'), // Unable to find one's way, either physically or emotionally.
  518. 'lucky' => t('lucky'), // Feeling as if one will be favored by luck.
  519. 'mean' => t('mean'), // Causing or intending to cause intentional harm; bearing ill will towards another; cruel; malicious.
  520. 'moody' => t('moody'), // Given to sudden or frequent changes of mind or feeling; temperamental.
  521. 'nervous' => t('nervous'), // Easily agitated or alarmed; apprehensive or anxious.
  522. 'neutral' => t('neutral'), // Not having a strong mood or emotional state.
  523. 'offended' => t('offended'), // Feeling emotionally hurt, displeased, or insulted.
  524. 'outraged' => t('outraged'), // Feeling resentful anger caused by an extremely violent or vicious attack, or by an offensive, immoral, or indecent act.
  525. 'playful' => t('playful'), // Interested in play; fun, recreational, unserious, lighthearted; joking, silly.
  526. 'proud' => t('proud'), // Feeling a sense of one's own worth or accomplishment.
  527. 'relaxed' => t('relaxed'), // Having an easy-going mood; not stressed; calm.
  528. 'relieved' => t('relieved'), // Feeling uplifted because of the removal of stress or discomfort.
  529. 'remorseful' => t('remorseful'), // Feeling regret or sadness for doing something wrong.
  530. 'restless' => t('restless'), // Without rest; unable to be still or quiet; uneasy; continually moving.
  531. 'sad' => t('sad'), // Feeling sorrow; sorrowful, mournful.
  532. 'sarcastic' => t('sarcastic'), // Mocking and ironical.
  533. 'satisfied' => t('satisfied'), // Pleased at the fulfillment of a need or desire.
  534. 'serious' => t('serious'), // Without humor or expression of happiness; grave in manner or disposition; earnest; thoughtful; solemn.
  535. 'shocked' => t('shocked'), // Surprised, startled, confused, or taken aback.
  536. 'shy' => t('shy'), // Feeling easily frightened or scared; timid; reserved or coy.
  537. 'sick' => t('sick'), // Feeling in poor health; ill.
  538. 'sleepy' => t('sleepy'), // Feeling the need for sleep.
  539. 'spontaneous' => t('spontaneous'), // Acting without planning; natural; impulsive.
  540. 'stressed' => t('stressed'), // Suffering emotional pressure.
  541. 'strong' => t('strong'), // Capable of producing great physical force; or, emotionally forceful, able, determined, unyielding.
  542. 'surprised' => t('surprised'), // Experiencing a feeling caused by something unexpected.
  543. 'thankful' => t('thankful'), // Showing appreciation or gratitude.
  544. 'thirsty' => t('thirsty'), // Feeling the need to drink.
  545. 'tired' => t('tired'), // In need of rest or sleep.
  546. 'undefined' => t('undefined'), // [Feeling any emotion not defined here.]
  547. 'weak' => t('weak'), // Lacking in force or ability, either physical or emotional.
  548. 'worried' => t('worried') // Thinking about unpleasant things that have happened or that might happen; feeling afraid and unhappy.
  549. );
  550. }
  551. /*
  552. * Get the user local timezone
  553. */
  554. function getLocalTimezone()
  555. {
  556. $iTime = time();
  557. $arr = localtime($iTime);
  558. $arr[5] += 1900;
  559. $arr[4]++;
  560. $iTztime = gmmktime($arr[2], $arr[1], $arr[0], $arr[4], $arr[3], $arr[5]);
  561. $offset = doubleval(($iTztime-$iTime)/(60*60));
  562. $zonelist =
  563. array
  564. (
  565. 'Kwajalein' => -12.00,
  566. 'Pacific/Midway' => -11.00,
  567. 'Pacific/Honolulu' => -10.00,
  568. 'America/Anchorage' => -9.00,
  569. 'America/Los_Angeles' => -8.00,
  570. 'America/Denver' => -7.00,
  571. 'America/Tegucigalpa' => -6.00,
  572. 'America/New_York' => -5.00,
  573. 'America/Caracas' => -4.30,
  574. 'America/Halifax' => -4.00,
  575. 'America/St_Johns' => -3.30,
  576. 'America/Argentina/Buenos_Aires' => -3.00,
  577. 'America/Sao_Paulo' => -3.00,
  578. 'Atlantic/South_Georgia' => -2.00,
  579. 'Atlantic/Azores' => -1.00,
  580. 'Europe/Dublin' => 0,
  581. 'Europe/Belgrade' => 1.00,
  582. 'Europe/Minsk' => 2.00,
  583. 'Asia/Kuwait' => 3.00,
  584. 'Asia/Tehran' => 3.30,
  585. 'Asia/Muscat' => 4.00,
  586. 'Asia/Yekaterinburg' => 5.00,
  587. 'Asia/Kolkata' => 5.30,
  588. 'Asia/Katmandu' => 5.45,
  589. 'Asia/Dhaka' => 6.00,
  590. 'Asia/Rangoon' => 6.30,
  591. 'Asia/Krasnoyarsk' => 7.00,
  592. 'Asia/Brunei' => 8.00,
  593. 'Asia/Seoul' => 9.00,
  594. 'Australia/Darwin' => 9.30,
  595. 'Australia/Canberra' => 10.00,
  596. 'Asia/Magadan' => 11.00,
  597. 'Pacific/Fiji' => 12.00,
  598. 'Pacific/Tongatapu' => 13.00
  599. );
  600. $index = array_keys($zonelist, $offset);
  601. if(sizeof($index)!=1)
  602. return false;
  603. return $index[0];
  604. }
  605. /*
  606. * Echap the JID
  607. */
  608. function echapJid($jid)
  609. {
  610. return str_replace(' ', '\40', $jid);
  611. }
  612. /**
  613. * Check the current Jid
  614. *
  615. * @param string $jid
  616. * @return bool
  617. */
  618. function checkJid($jid)
  619. {
  620. return filter_var($jid, FILTER_VALIDATE_EMAIL);
  621. }
  622. function stringToUri($url) {
  623. $url = utf8_decode($url);
  624. $url = strtolower(strtr($url, utf8_decode('ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ()[]\'"~$&%*@ç!?;,:/\^¨€{}<>|+.- '), 'aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn -- c --- e --'));
  625. $url = str_replace(' ', '', $url);
  626. $url = str_replace('---', '-', $url);
  627. $url = str_replace('--', '-', $url);
  628. $url = trim($url,'-');
  629. return $url;
  630. }
  631. function movim_log($log) {
  632. ob_start();
  633. // var_dump($log);
  634. print_r($log);
  635. $dump = ob_get_clean();
  636. $fh = fopen(BASE_PATH . 'log/movim.log', 'w');
  637. fwrite($fh, $dump);
  638. fclose($fh);
  639. }
  640. ?>