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

/lib/bennu/iCalendar_rfc2445.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 801 lines | 587 code | 135 blank | 79 comment | 235 complexity | ab4e010f080b97d77ed331ec13f6bd9b MD5 | raw file
  1. <?php
  2. /**
  3. * BENNU - PHP iCalendar library
  4. * (c) 2005-2006 Ioannis Papaioannou (pj@moodle.org). All rights reserved.
  5. *
  6. * Released under the LGPL.
  7. *
  8. * See http://bennu.sourceforge.net/ for more information and downloads.
  9. *
  10. * @author Ioannis Papaioannou
  11. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  12. */
  13. /*
  14. All names of properties, property parameters, enumerated property
  15. values and property parameter values are case-insensitive. However,
  16. all other property values are case-sensitive, unless otherwise
  17. stated.
  18. */
  19. define('RFC2445_CRLF', "\r\n");
  20. define('RFC2445_WSP', "\t ");
  21. define('RFC2445_WEEKDAYS', 'MO,TU,WE,TH,FR,SA,SU');
  22. define('RFC2445_FOLDED_LINE_LENGTH', 75);
  23. define('RFC2445_PARAMETER_SEPARATOR', ';');
  24. define('RFC2445_VALUE_SEPARATOR', ':');
  25. define('RFC2445_REQUIRED', 0x01);
  26. define('RFC2445_OPTIONAL', 0x02);
  27. define('RFC2445_ONCE', 0x04);
  28. define('RFC2445_PROP_FLAGS', 0);
  29. define('RFC2445_PROP_TYPE', 1);
  30. define('RFC2445_PROP_DEFAULT', 2);
  31. define('RFC2445_XNAME', 'X-');
  32. define('RFC2445_TYPE_BINARY', 0);
  33. define('RFC2445_TYPE_BOOLEAN', 1);
  34. define('RFC2445_TYPE_CAL_ADDRESS', 2);
  35. define('RFC2445_TYPE_DATE', 3);
  36. define('RFC2445_TYPE_DATE_TIME', 4);
  37. define('RFC2445_TYPE_DURATION', 5);
  38. define('RFC2445_TYPE_FLOAT', 6);
  39. define('RFC2445_TYPE_INTEGER', 7);
  40. define('RFC2445_TYPE_PERIOD', 8);
  41. define('RFC2445_TYPE_RECUR', 9);
  42. define('RFC2445_TYPE_TEXT', 10);
  43. define('RFC2445_TYPE_TIME', 11);
  44. define('RFC2445_TYPE_URI', 12); // CAL_ADDRESS === URI
  45. define('RFC2445_TYPE_UTC_OFFSET', 13);
  46. function rfc2445_fold($string) {
  47. if(textlib::strlen($string, 'utf-8') <= RFC2445_FOLDED_LINE_LENGTH) {
  48. return $string;
  49. }
  50. $retval = '';
  51. $i=0;
  52. $len_count=0;
  53. //multi-byte string, get the correct length
  54. $section_len = textlib::strlen($string, 'utf-8');
  55. while($len_count<$section_len) {
  56. //get the current portion of the line
  57. $section = textlib::substr($string, ($i * RFC2445_FOLDED_LINE_LENGTH), (RFC2445_FOLDED_LINE_LENGTH), 'utf-8');
  58. //increment the length we've processed by the length of the new portion
  59. $len_count += textlib::strlen($section, 'utf-8');
  60. /* Add the portion to the return value, terminating with CRLF.HTAB
  61. As per RFC 2445, CRLF.HTAB will be replaced by the processor of the
  62. data */
  63. $retval .= $section.RFC2445_CRLF.RFC2445_WSP;
  64. $i++;
  65. }
  66. return $retval;
  67. }
  68. function rfc2445_unfold($string) {
  69. for($i = 0; $i < strlen(RFC2445_WSP); ++$i) {
  70. $string = str_replace(RFC2445_CRLF.substr(RFC2445_WSP, $i, 1), '', $string);
  71. }
  72. return $string;
  73. }
  74. function rfc2445_is_xname($name) {
  75. // If it's less than 3 chars, it cannot be legal
  76. if(strlen($name) < 3) {
  77. return false;
  78. }
  79. // If it contains an illegal char anywhere, reject it
  80. if(strspn($name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-') != strlen($name)) {
  81. return false;
  82. }
  83. // To be legal, it must still start with "X-"
  84. return substr($name, 0, 2) === 'X-';
  85. }
  86. function rfc2445_is_valid_value($value, $type) {
  87. // This branch should only be taken with xname values
  88. if($type === NULL) {
  89. return true;
  90. }
  91. switch($type) {
  92. case RFC2445_TYPE_CAL_ADDRESS:
  93. case RFC2445_TYPE_URI:
  94. if(!is_string($value)) {
  95. return false;
  96. }
  97. $valid_schemes = array('ftp', 'http', 'ldap', 'gopher', 'mailto', 'news', 'nntp', 'telnet', 'wais', 'file', 'prospero');
  98. $pos = strpos($value, ':');
  99. if(!$pos) {
  100. return false;
  101. }
  102. $scheme = strtolower(substr($value, 0, $pos));
  103. $remain = substr($value, $pos + 1);
  104. if(!in_array($scheme, $valid_schemes)) {
  105. return false;
  106. }
  107. if($scheme === 'mailto') {
  108. $regexp = '#^[a-zA-Z0-9]+[_a-zA-Z0-9\-]*(\.[_a-z0-9\-]+)*@(([0-9a-zA-Z\-]+\.)+[a-zA-Z][0-9a-zA-Z\-]+|([0-9]{1,3}\.){3}[0-9]{1,3})$#';
  109. }
  110. else {
  111. $regexp = '#^//(.+(:.*)?@)?(([0-9a-zA-Z\-]+\.)+[a-zA-Z][0-9a-zA-Z\-]+|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]{1,5})?(/.*)?$#';
  112. }
  113. return preg_match($regexp, $remain);
  114. break;
  115. case RFC2445_TYPE_BINARY:
  116. if(!is_string($value)) {
  117. return false;
  118. }
  119. $len = strlen($value);
  120. if($len % 4 != 0) {
  121. return false;
  122. }
  123. for($i = 0; $i < $len; ++$i) {
  124. $ch = $value{$i};
  125. if(!($ch >= 'a' && $ch <= 'z' || $ch >= 'A' && $ch <= 'Z' || $ch >= '0' && $ch <= '9' || $ch == '-' || $ch == '+')) {
  126. if($ch == '=' && $len - $i <= 2) {
  127. continue;
  128. }
  129. return false;
  130. }
  131. }
  132. return true;
  133. break;
  134. case RFC2445_TYPE_BOOLEAN:
  135. if(is_bool($value)) {
  136. return true;
  137. }
  138. if(is_string($value)) {
  139. $value = strtoupper($value);
  140. return ($value == 'TRUE' || $value == 'FALSE');
  141. }
  142. return false;
  143. break;
  144. case RFC2445_TYPE_DATE:
  145. if(is_int($value)) {
  146. if($value < 0) {
  147. return false;
  148. }
  149. $value = "$value";
  150. }
  151. else if(!is_string($value)) {
  152. return false;
  153. }
  154. if(strlen($value) != 8) {
  155. return false;
  156. }
  157. $y = intval(substr($value, 0, 4));
  158. $m = intval(substr($value, 4, 2));
  159. $d = intval(substr($value, 6, 2));
  160. return checkdate($m, $d, $y);
  161. break;
  162. case RFC2445_TYPE_DATE_TIME:
  163. if(!is_string($value) || strlen($value) < 15) {
  164. return false;
  165. }
  166. return($value{8} == 'T' &&
  167. rfc2445_is_valid_value(substr($value, 0, 8), RFC2445_TYPE_DATE) &&
  168. rfc2445_is_valid_value(substr($value, 9), RFC2445_TYPE_TIME));
  169. break;
  170. case RFC2445_TYPE_DURATION:
  171. if(!is_string($value)) {
  172. return false;
  173. }
  174. $len = strlen($value);
  175. if($len < 3) {
  176. // Minimum conformant length: "P1W"
  177. return false;
  178. }
  179. if($value{0} == '+' || $value{0} == '-') {
  180. $value = substr($value, 1);
  181. --$len; // Don't forget to update this!
  182. }
  183. if($value{0} != 'P') {
  184. return false;
  185. }
  186. // OK, now break it up
  187. $num = '';
  188. $allowed = 'WDT';
  189. for($i = 1; $i < $len; ++$i) {
  190. $ch = $value{$i};
  191. if($ch >= '0' && $ch <= '9') {
  192. $num .= $ch;
  193. continue;
  194. }
  195. if(strpos($allowed, $ch) === false) {
  196. // Non-numeric character which shouldn't be here
  197. return false;
  198. }
  199. if($num === '' && $ch != 'T') {
  200. // Allowed non-numeric character, but no digits came before it
  201. return false;
  202. }
  203. // OK, $ch now holds a character which tells us what $num is
  204. switch($ch) {
  205. case 'W':
  206. // If duration in weeks is specified, this must end the string
  207. return ($i == $len - 1);
  208. break;
  209. case 'D':
  210. // Days specified, now if anything comes after it must be a 'T'
  211. $allowed = 'T';
  212. break;
  213. case 'T':
  214. // Starting to specify time, H M S are now valid delimiters
  215. $allowed = 'HMS';
  216. break;
  217. case 'H':
  218. $allowed = 'M';
  219. break;
  220. case 'M':
  221. $allowed = 'S';
  222. break;
  223. case 'S':
  224. return ($i == $len - 1);
  225. break;
  226. }
  227. // If we 're going to continue, reset $num
  228. $num = '';
  229. }
  230. // $num is kept for this reason: if we 're here, we ran out of chars
  231. // therefore $num must be empty for the period to be legal
  232. return ($num === '' && $ch != 'T');
  233. break;
  234. case RFC2445_TYPE_FLOAT:
  235. if(is_float($value)) {
  236. return true;
  237. }
  238. if(!is_string($value) || $value === '') {
  239. return false;
  240. }
  241. $dot = false;
  242. $int = false;
  243. $len = strlen($value);
  244. for($i = 0; $i < $len; ++$i) {
  245. switch($value{$i}) {
  246. case '-': case '+':
  247. // A sign can only be seen at position 0 and cannot be the only char
  248. if($i != 0 || $len == 1) {
  249. return false;
  250. }
  251. break;
  252. case '.':
  253. // A second dot is an error
  254. // Make sure we had at least one int before the dot
  255. if($dot || !$int) {
  256. return false;
  257. }
  258. $dot = true;
  259. // Make also sure that the float doesn't end with a dot
  260. if($i == $len - 1) {
  261. return false;
  262. }
  263. break;
  264. case '0': case '1': case '2': case '3': case '4':
  265. case '5': case '6': case '7': case '8': case '9':
  266. $int = true;
  267. break;
  268. default:
  269. // Any other char is a no-no
  270. return false;
  271. break;
  272. }
  273. }
  274. return true;
  275. break;
  276. case RFC2445_TYPE_INTEGER:
  277. if(is_int($value)) {
  278. return true;
  279. }
  280. if(!is_string($value) || $value === '') {
  281. return false;
  282. }
  283. if($value{0} == '+' || $value{0} == '-') {
  284. if(strlen($value) == 1) {
  285. return false;
  286. }
  287. $value = substr($value, 1);
  288. }
  289. if(strspn($value, '0123456789') != strlen($value)) {
  290. return false;
  291. }
  292. return ($value >= -2147483648 && $value <= 2147483647);
  293. break;
  294. case RFC2445_TYPE_PERIOD:
  295. if(!is_string($value) || empty($value)) {
  296. return false;
  297. }
  298. $parts = explode('/', $value);
  299. if(count($parts) != 2) {
  300. return false;
  301. }
  302. if(!rfc2445_is_valid_value($parts[0], RFC2445_TYPE_DATE_TIME)) {
  303. return false;
  304. }
  305. // Two legal cases for the second part:
  306. if(rfc2445_is_valid_value($parts[1], RFC2445_TYPE_DATE_TIME)) {
  307. // It has to be after the start time, so
  308. return ($parts[1] > $parts[0]);
  309. }
  310. else if(rfc2445_is_valid_value($parts[1], RFC2445_TYPE_DURATION)) {
  311. // The period MUST NOT be negative
  312. return ($parts[1]{0} != '-');
  313. }
  314. // It seems to be illegal
  315. return false;
  316. break;
  317. case RFC2445_TYPE_RECUR:
  318. if(!is_string($value)) {
  319. return false;
  320. }
  321. $parts = explode(';', strtoupper($value));
  322. // First of all, we need at least a FREQ and a UNTIL or COUNT part, so...
  323. if(count($parts) < 2) {
  324. return false;
  325. }
  326. // Let's get that into a more easily comprehensible format
  327. $vars = array();
  328. foreach($parts as $part) {
  329. $pieces = explode('=', $part);
  330. // There must be exactly 2 pieces, e.g. FREQ=WEEKLY
  331. if(count($pieces) != 2) {
  332. return false;
  333. }
  334. // It's illegal for a variable to appear twice
  335. if(isset($vars[$pieces[0]])) {
  336. return false;
  337. }
  338. // Sounds good
  339. $vars[$pieces[0]] = $pieces[1];
  340. }
  341. // OK... now to test everything else
  342. // FREQ must be the first thing appearing
  343. reset($vars);
  344. if(key($vars) != 'FREQ') {
  345. return false;
  346. }
  347. // It's illegal to have both UNTIL and COUNT appear
  348. if(isset($vars['UNTIL']) && isset($vars['COUNT'])) {
  349. return false;
  350. }
  351. // Special case: BYWEEKNO is only valid for FREQ=YEARLY
  352. if(isset($vars['BYWEEKNO']) && $vars['FREQ'] != 'YEARLY') {
  353. return false;
  354. }
  355. // Special case: BYSETPOS is only valid if another BY option is specified
  356. if(isset($vars['BYSETPOS'])) {
  357. $options = array('BYSECOND', 'BYMINUTE', 'BYHOUR', 'BYDAY', 'BYMONTHDAY', 'BYYEARDAY', 'BYWEEKNO', 'BYMONTH');
  358. $defined = array_keys($vars);
  359. $common = array_intersect($options, $defined);
  360. if(empty($common)) {
  361. return false;
  362. }
  363. }
  364. // OK, now simply check if each element has a valid value,
  365. // unsetting them on the way. If at the end the array still
  366. // has some elements, they are illegal.
  367. if($vars['FREQ'] != 'SECONDLY' && $vars['FREQ'] != 'MINUTELY' && $vars['FREQ'] != 'HOURLY' &&
  368. $vars['FREQ'] != 'DAILY' && $vars['FREQ'] != 'WEEKLY' &&
  369. $vars['FREQ'] != 'MONTHLY' && $vars['FREQ'] != 'YEARLY') {
  370. return false;
  371. }
  372. unset($vars['FREQ']);
  373. // Set this, we may need it later
  374. $weekdays = explode(',', RFC2445_WEEKDAYS);
  375. if(isset($vars['UNTIL'])) {
  376. if(rfc2445_is_valid_value($vars['UNTIL'], RFC2445_TYPE_DATE_TIME)) {
  377. // The time MUST be in UTC format
  378. if(!(substr($vars['UNTIL'], -1) == 'Z')) {
  379. return false;
  380. }
  381. }
  382. else if(!rfc2445_is_valid_value($vars['UNTIL'], RFC2445_TYPE_DATE_TIME)) {
  383. return false;
  384. }
  385. }
  386. unset($vars['UNTIL']);
  387. if(isset($vars['COUNT'])) {
  388. if(empty($vars['COUNT'])) {
  389. // This also catches the string '0', which makes no sense
  390. return false;
  391. }
  392. if(strspn($vars['COUNT'], '0123456789') != strlen($vars['COUNT'])) {
  393. return false;
  394. }
  395. }
  396. unset($vars['COUNT']);
  397. if(isset($vars['INTERVAL'])) {
  398. if(empty($vars['INTERVAL'])) {
  399. // This also catches the string '0', which makes no sense
  400. return false;
  401. }
  402. if(strspn($vars['INTERVAL'], '0123456789') != strlen($vars['INTERVAL'])) {
  403. return false;
  404. }
  405. }
  406. unset($vars['INTERVAL']);
  407. if(isset($vars['BYSECOND'])) {
  408. if($vars['BYSECOND'] == '') {
  409. return false;
  410. }
  411. // Comma also allowed
  412. if(strspn($vars['BYSECOND'], '0123456789,') != strlen($vars['BYSECOND'])) {
  413. return false;
  414. }
  415. $secs = explode(',', $vars['BYSECOND']);
  416. foreach($secs as $sec) {
  417. if($sec == '' || $sec < 0 || $sec > 59) {
  418. return false;
  419. }
  420. }
  421. }
  422. unset($vars['BYSECOND']);
  423. if(isset($vars['BYMINUTE'])) {
  424. if($vars['BYMINUTE'] == '') {
  425. return false;
  426. }
  427. // Comma also allowed
  428. if(strspn($vars['BYMINUTE'], '0123456789,') != strlen($vars['BYMINUTE'])) {
  429. return false;
  430. }
  431. $mins = explode(',', $vars['BYMINUTE']);
  432. foreach($mins as $min) {
  433. if($min == '' || $min < 0 || $min > 59) {
  434. return false;
  435. }
  436. }
  437. }
  438. unset($vars['BYMINUTE']);
  439. if(isset($vars['BYHOUR'])) {
  440. if($vars['BYHOUR'] == '') {
  441. return false;
  442. }
  443. // Comma also allowed
  444. if(strspn($vars['BYHOUR'], '0123456789,') != strlen($vars['BYHOUR'])) {
  445. return false;
  446. }
  447. $hours = explode(',', $vars['BYHOUR']);
  448. foreach($hours as $hour) {
  449. if($hour == '' || $hour < 0 || $hour > 23) {
  450. return false;
  451. }
  452. }
  453. }
  454. unset($vars['BYHOUR']);
  455. if(isset($vars['BYDAY'])) {
  456. if(empty($vars['BYDAY'])) {
  457. return false;
  458. }
  459. // First off, split up all values we may have
  460. $days = explode(',', $vars['BYDAY']);
  461. foreach($days as $day) {
  462. $daypart = substr($day, -2);
  463. if(!in_array($daypart, $weekdays)) {
  464. return false;
  465. }
  466. if(strlen($day) > 2) {
  467. $intpart = substr($day, 0, strlen($day) - 2);
  468. if(!rfc2445_is_valid_value($intpart, RFC2445_TYPE_INTEGER)) {
  469. return false;
  470. }
  471. if(intval($intpart) == 0) {
  472. return false;
  473. }
  474. }
  475. }
  476. }
  477. unset($vars['BYDAY']);
  478. if(isset($vars['BYMONTHDAY'])) {
  479. if(empty($vars['BYMONTHDAY'])) {
  480. return false;
  481. }
  482. $mdays = explode(',', $vars['BYMONTHDAY']);
  483. foreach($mdays as $mday) {
  484. if(!rfc2445_is_valid_value($mday, RFC2445_TYPE_INTEGER)) {
  485. return false;
  486. }
  487. $mday = abs(intval($mday));
  488. if($mday == 0 || $mday > 31) {
  489. return false;
  490. }
  491. }
  492. }
  493. unset($vars['BYMONTHDAY']);
  494. if(isset($vars['BYYEARDAY'])) {
  495. if(empty($vars['BYYEARDAY'])) {
  496. return false;
  497. }
  498. $ydays = explode(',', $vars['BYYEARDAY']);
  499. foreach($ydays as $yday) {
  500. if(!rfc2445_is_valid_value($yday, RFC2445_TYPE_INTEGER)) {
  501. return false;
  502. }
  503. $yday = abs(intval($yday));
  504. if($yday == 0 || $yday > 366) {
  505. return false;
  506. }
  507. }
  508. }
  509. unset($vars['BYYEARDAY']);
  510. if(isset($vars['BYWEEKNO'])) {
  511. if(empty($vars['BYWEEKNO'])) {
  512. return false;
  513. }
  514. $weeknos = explode(',', $vars['BYWEEKNO']);
  515. foreach($weeknos as $weekno) {
  516. if(!rfc2445_is_valid_value($weekno, RFC2445_TYPE_INTEGER)) {
  517. return false;
  518. }
  519. $weekno = abs(intval($weekno));
  520. if($weekno == 0 || $weekno > 53) {
  521. return false;
  522. }
  523. }
  524. }
  525. unset($vars['BYWEEKNO']);
  526. if(isset($vars['BYMONTH'])) {
  527. if(empty($vars['BYMONTH'])) {
  528. return false;
  529. }
  530. // Comma also allowed
  531. if(strspn($vars['BYMONTH'], '0123456789,') != strlen($vars['BYMONTH'])) {
  532. return false;
  533. }
  534. $months = explode(',', $vars['BYMONTH']);
  535. foreach($months as $month) {
  536. if($month == '' || $month < 1 || $month > 12) {
  537. return false;
  538. }
  539. }
  540. }
  541. unset($vars['BYMONTH']);
  542. if(isset($vars['BYSETPOS'])) {
  543. if(empty($vars['BYSETPOS'])) {
  544. return false;
  545. }
  546. $sets = explode(',', $vars['BYSETPOS']);
  547. foreach($sets as $set) {
  548. if(!rfc2445_is_valid_value($set, RFC2445_TYPE_INTEGER)) {
  549. return false;
  550. }
  551. $set = abs(intval($set));
  552. if($set == 0 || $set > 366) {
  553. return false;
  554. }
  555. }
  556. }
  557. unset($vars['BYSETPOS']);
  558. if(isset($vars['WKST'])) {
  559. if(!in_array($vars['WKST'], $weekdays)) {
  560. return false;
  561. }
  562. }
  563. unset($vars['WKST']);
  564. // Any remaining vars must be x-names
  565. if(empty($vars)) {
  566. return true;
  567. }
  568. foreach($vars as $name => $var) {
  569. if(!rfc2445_is_xname($name)) {
  570. return false;
  571. }
  572. }
  573. // At last, all is OK!
  574. return true;
  575. break;
  576. case RFC2445_TYPE_TEXT:
  577. return true;
  578. break;
  579. case RFC2445_TYPE_TIME:
  580. if(is_int($value)) {
  581. if($value < 0) {
  582. return false;
  583. }
  584. $value = "$value";
  585. }
  586. else if(!is_string($value)) {
  587. return false;
  588. }
  589. if(strlen($value) == 7) {
  590. if(strtoupper(substr($value, -1)) != 'Z') {
  591. return false;
  592. }
  593. $value = substr($value, 0, 6);
  594. }
  595. if(strlen($value) != 6) {
  596. return false;
  597. }
  598. $h = intval(substr($value, 0, 2));
  599. $m = intval(substr($value, 2, 2));
  600. $s = intval(substr($value, 4, 2));
  601. return ($h <= 23 && $m <= 59 && $s <= 60);
  602. break;
  603. case RFC2445_TYPE_UTC_OFFSET:
  604. if(is_int($value)) {
  605. if($value >= 0) {
  606. $value = "+$value";
  607. }
  608. else {
  609. $value = "$value";
  610. }
  611. }
  612. else if(!is_string($value)) {
  613. return false;
  614. }
  615. $s = 0;
  616. if(strlen($value) == 7) {
  617. $s = intval(substr($value, 5, 2));
  618. $value = substr($value, 0, 5);
  619. }
  620. if(strlen($value) != 5 || $value == "-0000") {
  621. return false;
  622. }
  623. if($value{0} != '+' && $value{0} != '-') {
  624. return false;
  625. }
  626. $h = intval(substr($value, 1, 2));
  627. $m = intval(substr($value, 3, 2));
  628. return ($h <= 23 && $m <= 59 && $s <= 59);
  629. break;
  630. }
  631. // TODO: remove this assertion
  632. trigger_error('bad code path', E_USER_WARNING);
  633. var_dump($type);
  634. return false;
  635. }
  636. function rfc2445_do_value_formatting($value, $type) {
  637. // Note: this does not only do formatting; it also does conversion to string!
  638. switch($type) {
  639. case RFC2445_TYPE_CAL_ADDRESS:
  640. case RFC2445_TYPE_URI:
  641. // Enclose in double quotes
  642. $value = '"'.$value.'"';
  643. break;
  644. case RFC2445_TYPE_TEXT:
  645. // Escape entities
  646. $value = strtr($value, array("\r\n" => '\\n', "\n" => '\\n', '\\' => '\\\\', ',' => '\\,', ';' => '\\;'));
  647. break;
  648. }
  649. return $value;
  650. }
  651. function rfc2445_undo_value_formatting($value, $type) {
  652. switch($type) {
  653. case RFC2445_TYPE_CAL_ADDRESS:
  654. case RFC2445_TYPE_URI:
  655. // Trim beginning and end double quote
  656. $value = substr($value, 1, strlen($value) - 2);
  657. break;
  658. case RFC2445_TYPE_TEXT:
  659. // Unescape entities
  660. $value = strtr($value, array('\\n' => "\n", '\\N' => "\n", '\\\\' => '\\', '\\,' => ',', '\\;' => ';'));
  661. break;
  662. }
  663. return $value;
  664. }