PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/iCalendar_v2/class.iCalBase.inc.php

http://flaimo-php.googlecode.com/
PHP | 699 lines | 194 code | 71 blank | 434 comment | 18 complexity | c37dbb4ba4735dc34d93c3c91bbd72d6 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //+----------------------------------------------------------------------+
  4. //| WAMP (XP-SP2/2.2/5.2/5.1.0) |
  5. //+----------------------------------------------------------------------+
  6. //| Copyright(c) 2001-2008 Michael Wimmer |
  7. //+----------------------------------------------------------------------+
  8. //| Licence: GNU General Public License v3 |
  9. //+----------------------------------------------------------------------+
  10. //| Authors: Michael Wimmer <flaimo@gmail.com> |
  11. //+----------------------------------------------------------------------+
  12. //
  13. // $Id$
  14. /**
  15. * @package iCalendar Everything to generate simple iCal files
  16. */
  17. /**
  18. * Base Class for the different Modules
  19. *
  20. * Tested with WAMP (XP-SP2/2.2/5.2/5.1.0)
  21. * Last Change: 2008-04-07
  22. *
  23. * @access protected
  24. * @author Michael Wimmer <flaimo@gmail.com>
  25. * @copyright Copyright Š 2002-2008, Michael Wimmer
  26. * @license GNU General Public License v3
  27. * @link http://code.google.com/p/flaimo-php/
  28. * @package iCalendar
  29. * @version 2.002
  30. */
  31. abstract class iCalBase {
  32. /*-------------------*/
  33. /* V A R I A B L E S */
  34. /*-------------------*/
  35. /**
  36. * FALSE = GMT time, TRUE = locale time
  37. */
  38. CONST USE_LOCALE_TIME = FALSE;
  39. /**#@+
  40. * @var string
  41. */
  42. /**
  43. * Detailed information for the module
  44. */
  45. private $description;
  46. /**
  47. * iso code language (en, de,&#x2026;)
  48. */
  49. private $lang;
  50. /**
  51. * If not empty, contains a Link for that module
  52. */
  53. private $url;
  54. /**
  55. * Headline for the module (mostly displayed in your cal programm)
  56. */
  57. private $summary;
  58. /**
  59. * String of days for the recurring module (example: &#x201C;SU,MO&#x201D;)
  60. */
  61. private $rec_days;
  62. /**
  63. * Location of the module
  64. */
  65. private $location;
  66. /**
  67. * String with the categories asigned to the module
  68. */
  69. private $categories;
  70. /**
  71. * last modification date in iCal format
  72. */
  73. private $last_mod;
  74. /**#@-*/
  75. /**#@+
  76. * @var array
  77. */
  78. /**
  79. * Organizer of the module; $organizer[0] = Name, $organizer[1] = e-mail
  80. */
  81. private $organizer = array('vCalEvent class', 'http://www.flaimo.com');
  82. /**
  83. * List of short strings symbolizing the weekdays
  84. */
  85. private $short_daynames = array('SU','MO','TU','WE','TH','FR','SA');
  86. /**
  87. * If the method is REQUEST, all attendees are listet in the file
  88. *
  89. * key = attendee name, value = e-mail, second value = role of the attendee
  90. * [0 = CHAIR | 1 = REQ | 2 = OPT | 3 =NON] (example: array('Michi' => 'flaimo@gmx.net,1'); )
  91. */
  92. private $attendees = array();
  93. /**
  94. * Array with the categories asigned to the module (example:
  95. * array('Freetime','Party'))
  96. */
  97. private $categories_array;
  98. /**
  99. * Exeptions dates for the recurring module (Array of timestamps)
  100. */
  101. private $exept_dates;
  102. /**#@-*/
  103. /**#@+
  104. * @var int
  105. */
  106. /**
  107. * set to 0
  108. */
  109. private $sequence;
  110. /**
  111. * 0 = once, 1-7 = secoundly - yearly
  112. */
  113. private $frequency;
  114. /**
  115. * If not empty, contains the status of the module
  116. * (0 = TENTATIVE, 1 = CONFIRMED, 2 = CANCELLED)
  117. */
  118. private $status;
  119. /**
  120. * Short string symbolizing the startday of the week
  121. */
  122. private $week_start = 1;
  123. /**
  124. * interval of the recurring date (example: every 2,3,4 weeks)
  125. */
  126. private $interval = 1;
  127. /**
  128. * PRIVATE (0) or PUBLIC (1) or CONFIDENTIAL (2)
  129. */
  130. private $class;
  131. /**
  132. * set to 5 (value between 0 and 9)
  133. */
  134. private $priority;
  135. /**
  136. * Timestamp of the last modification
  137. */
  138. private $last_mod_ts;
  139. /**#@-*/
  140. /*-----------------------*/
  141. /* C O N S T R U C T O R */
  142. /*-----------------------*/
  143. /**#@+
  144. * @return void
  145. */
  146. function __construct() {
  147. } // end constructor
  148. /*-------------------*/
  149. /* F U N C T I O N S */
  150. /*-------------------*/
  151. /**
  152. * Set $startdate variable
  153. *
  154. * @param string $isocode
  155. * @see getStartDate()
  156. * @see $startdate
  157. * @uses isValidLanguageCode()
  158. * @uses iCalBase::$lang
  159. */
  160. protected function setLanguage($isocode = '') {
  161. $this->lang = (string) (($this->isValidLanguageCode($isocode) == TRUE) ? ';LANGUAGE=' . $isocode : '');
  162. } // end function
  163. /**
  164. * Set $description variable
  165. *
  166. * @param string $description
  167. * @see getDescription()
  168. * @uses iCalBase::$description
  169. */
  170. protected function setDescription($description) {
  171. $this->description = (string) $description;
  172. } // end function
  173. /**
  174. * Set $organizer variable
  175. *
  176. * @param (array) $organizer
  177. * @see getOrganizerName()
  178. * @see getOrganizerMail()
  179. * @uses iCalBase::$organizer
  180. */
  181. protected function setOrganizer($organizer = '') {
  182. if (is_array($organizer)) {
  183. $this->organizer = (array) $organizer;
  184. } // end if
  185. } // end function
  186. /**
  187. * Set $url variable
  188. *
  189. * @param string $url
  190. * @see getURL()
  191. * @uses iCalBase::$url
  192. * @since 1.011 - 2002-12-22
  193. */
  194. protected function setURL($url = '') {
  195. $this->url = (string) $url;
  196. } // end function
  197. /**
  198. * Set $summary variable
  199. *
  200. * @param string $summary
  201. * @see getSummary()
  202. * @uses iCalBase::$summary
  203. */
  204. protected function setSummary($summary = '') {
  205. $this->summary = '';
  206. if (trim(strlen($summary)) > 0) { $this->summary = (string) $summary; }
  207. } // end function
  208. /**
  209. * Set $sequence variable
  210. *
  211. * @param int $int
  212. * @see getSequence()
  213. * @uses iCalBase::$sequence
  214. */
  215. protected function setSequence($int = 0) {
  216. $this->sequence = (int) $int;
  217. } // end function
  218. /**
  219. * Sets a string with weekdays of the recurring module
  220. *
  221. * @param (array) $recdays integers
  222. * @see getDays()
  223. * @uses iCalBase::$rec_days
  224. * @since 1.010 - 2002-10-26
  225. */
  226. protected function setDays($recdays = '') {
  227. $this->rec_days = (string) '';
  228. if (!is_array($recdays) || count($recdays) == 0) {
  229. $this->rec_days = (string) $this->short_daynames[1];
  230. } else {
  231. if (count($recdays) > 1) {
  232. $recdays = array_values(array_unique($recdays));
  233. } // end if
  234. foreach ($recdays as $day) {
  235. if (array_key_exists($day, $this->short_daynames)) {
  236. $this->rec_days .= (string) $this->short_daynames[$day] . ',';
  237. } // end if
  238. } // end foreach
  239. $this->rec_days = (string) substr($this->rec_days,0,strlen($this->rec_days)-1);
  240. } // end if
  241. } // end function
  242. /**
  243. * Sets the starting day for the week (0 = Sunday)
  244. *
  245. * @param int $weekstart 0&#x2013;6
  246. * @see getWeekStart()
  247. * @uses iCalBase::$week_start
  248. * @since 1.010 - 2002-10-26
  249. */
  250. protected function setWeekStart($weekstart = 1) {
  251. if (is_int($weekstart) && preg_match('(^([0-6]{1})$)', $weekstart)) {
  252. $this->week_start = (int) $weekstart;
  253. } // end if
  254. } // end function
  255. /**
  256. * Set $attendees variable
  257. *
  258. * @param (array) $attendees
  259. * @see getAttendees()
  260. * @uses iCalBase::$attendees
  261. * @since 1.001 - 2002-10-10
  262. */
  263. protected function setAttendees($attendees = '') {
  264. if (is_array($attendees)) {
  265. $this->attendees = (array) $attendees;
  266. } // end if
  267. } // end function
  268. /**
  269. * Set $location variable
  270. *
  271. * @param string $location
  272. * @see getLocation()
  273. * @uses iCalBase::$location
  274. */
  275. protected function setLocation($location = '') {
  276. if (strlen(trim($location)) > 0) {
  277. $this->location = (string) $location;
  278. } // end if
  279. } // end function
  280. /**
  281. * Set $categories_array variable
  282. *
  283. * @param string $categories
  284. * @see getCategoriesArray()
  285. * @uses iCalBase::$categories_array
  286. */
  287. protected function setCategoriesArray($categories = '') {
  288. $this->categories_array = (array) $categories;
  289. } // end function
  290. /**
  291. * Set $categories variable
  292. *
  293. * @param string $categories
  294. * @see getCategories()
  295. * @uses iCalBase::$categories
  296. */
  297. protected function setCategories($categories = '') {
  298. $this->setCategoriesArray($categories);
  299. $this->categories = (string) implode(',',$categories);
  300. } // end function
  301. /**
  302. * Sets the frequency of a recurring event
  303. *
  304. * @param int $int Integer 0&#x2013;7
  305. * @see getFrequency()
  306. * @uses iCalBase::$frequencies
  307. * @since 1.010 - 2002-10-26
  308. */
  309. protected function setFrequency($int = 0) {
  310. $this->frequency = (int) $int;
  311. } // end function
  312. /**
  313. * Set $status variable
  314. *
  315. * @param int $status
  316. * @see getStatus()
  317. * @uses iCalBase::$status
  318. * @since 1.011 - 2002-12-22
  319. */
  320. protected function setStatus($status = 1) {
  321. $this->status = (int) $status;
  322. } // end function
  323. /**
  324. * Sets the interval for a recurring event (2 = every 2 [days|weeks|years|&#x2026;])
  325. *
  326. * @param int $interval
  327. * @see getInterval()
  328. * @uses iCalBase::$interval
  329. * @since 1.010 - 2002-10-26
  330. */
  331. protected function setInterval($interval = 1) {
  332. $this->interval = (int) $interval;
  333. } // end function
  334. /**
  335. * returns a ical formated date depending on the locale constant at the beginning of the file
  336. *
  337. * @param int $timestamp
  338. * @uses USE_LOCALE_TIME
  339. * @since 2.001 - 2003-98-04
  340. */
  341. protected function formatDate($timestamp = 0) {
  342. return (string) ((self::USE_LOCALE_TIME === TRUE) ? date('Ymd\THi00',$timestamp) : gmdate('Ymd\THi00\Z',$timestamp));
  343. } // end function
  344. /**
  345. * Sets an array of formated exeptions dates based on an array with timestamps
  346. *
  347. * @param (array) $exeptdates
  348. * @see getExeptDates()
  349. * @uses iCalBase::$exept_dates
  350. * @since 1.010 - 2002-10-26
  351. */
  352. protected function setExeptDates($exeptdates = '') {
  353. if (!is_array($exeptdates)) {
  354. $this->exept_dates = (array) array();
  355. } else {
  356. foreach ($exeptdates as $timestamp) {
  357. $this->exept_dates[] = $this->formatDate($timestamp);
  358. } // end foreach
  359. } // end if
  360. } // end function
  361. /**
  362. * Set $class variable
  363. *
  364. * @param int $int
  365. * @see getClass()
  366. * @uses iCalBase::$class
  367. */
  368. protected function setClass($int = 0) {
  369. $this->class = (int) $int;
  370. } // end function
  371. /**
  372. * Set $priority variable
  373. *
  374. * @param int $int
  375. * @see getPriority()
  376. * @uses iCalBase::$priority
  377. */
  378. protected function setPriority($int = 5) {
  379. $this->priority = (int) ((is_int($int) && preg_match('(^([0-9]{1})$)', $int)) ? $int : 5);
  380. } // end function
  381. /**
  382. * Set $last_mod_ts variable
  383. *
  384. * @param int $timestamp
  385. * @see getLastModTS()
  386. * @uses iCalBase::$last_mod_ts
  387. * @since 1.020 - 2002-12-24
  388. */
  389. protected function setLastModTS($timestamp = 0) {
  390. if (is_int($timestamp) && $timestamp > 0) {
  391. $this->last_mod_ts = (int) $timestamp;
  392. } // end if
  393. } // end function
  394. /**
  395. * Set $last_mod variable
  396. *
  397. * @param int $last_mod
  398. * @see getLastMod()
  399. * @uses setLastModTS()
  400. * @uses iCalBase::$last_mod
  401. * @since 1.020 - 2002-12-24
  402. */
  403. protected function setLastMod($timestamp = 0) {
  404. $this->setLastModTS($timestamp);
  405. $this->last_mod = (string) $this->formatDate($this->last_mod_ts);
  406. } // end function
  407. /**#@-*/
  408. /**
  409. * Checks if a given string is a valid iso-language-code
  410. *
  411. * @param string $code String that should validated
  412. * @return boolean isvalid If string is valid or not
  413. * @since 1.001 - 2002/10/19
  414. */
  415. public static final function isValidLanguageCode($code = '') {
  416. return (boolean) ((preg_match('(^([a-zA-Z]{2})((_|-)[a-zA-Z]{2})?$)',trim($code)) > 0) ? TRUE : FALSE);
  417. } // end function
  418. /**
  419. * Get $startdate variable
  420. *
  421. * @return string $lang
  422. * @see setLanguage()
  423. */
  424. public function getLanguage() {
  425. return $this->lang;
  426. } // end function
  427. /**
  428. * Get $description variable
  429. *
  430. * @return string $description
  431. * @see setDescription()
  432. */
  433. public function getDescription() {
  434. return $this->description;
  435. } // end function
  436. /**
  437. * Get name from $organizer variable
  438. *
  439. * @return string $organizer
  440. * @see setOrganizer()
  441. * @see getOrganizerMail()
  442. * @since 1.011 - 2002-12-22
  443. */
  444. public function getOrganizerName() {
  445. return $this->organizer[0];
  446. } // end function
  447. /**
  448. * Get e-mail from $organizer variable
  449. *
  450. * @return string $organizer
  451. * @see setOrganizer()
  452. * @see getOrganizerName()
  453. * @since 1.011 - 2002-12-22
  454. */
  455. public function getOrganizerMail() {
  456. return $this->organizer[1];
  457. } // end function
  458. /**
  459. * Get $url variable
  460. *
  461. * @return string $url
  462. * @see setURL()
  463. * @since 1.011 - 2002-12-22
  464. */
  465. public function getURL() {
  466. return $this->url;
  467. } // end function
  468. /**
  469. * Get $summary variable
  470. *
  471. * @return string $summary
  472. * @see setSummary()
  473. */
  474. public function getSummary() {
  475. return $this->summary;
  476. } // end function
  477. /**
  478. * Get $sequence variable
  479. *
  480. * @return int $sequence
  481. * @see setSequence()
  482. */
  483. public function getSequence() {
  484. return $this->sequence;
  485. } // end function
  486. /**
  487. * Returns a string with recurring days
  488. *
  489. * @return string $rec_days
  490. * @see setDays()
  491. * @since 1.010 - 2002-10-26
  492. */
  493. public function getDays() {
  494. return $this->rec_days;
  495. } // end function
  496. /**
  497. * Get the string from the $week_start variable
  498. *
  499. * @return string $short_daynames
  500. * @see setWeekStart()
  501. * @uses iCalBase::$week_start
  502. * @since 1.010 - 2002-10-26
  503. */
  504. public function getWeekStart() {
  505. return ((array_key_exists($this->week_start, $this->short_daynames)) ? $this->short_daynames[$this->week_start] : $this->short_daynames[1]);
  506. } // end function
  507. /**
  508. * Get $attendees variable
  509. *
  510. * @return array $attendees
  511. * @see setAttendees()
  512. * @since 1.001 - 2002-10-10
  513. */
  514. public function getAttendees() {
  515. return $this->attendees;
  516. } // end function
  517. /**
  518. * Get $location variable
  519. *
  520. * @return string $location
  521. * @see setLocation()
  522. */
  523. public function getLocation() {
  524. return $this->location;
  525. } // end function
  526. /**
  527. * Get $categories_array variable
  528. *
  529. * @return array $categories_array
  530. * @see setCategoriesArray()
  531. */
  532. public function getCategoriesArray() {
  533. return $this->categories_array;
  534. } // end function
  535. /**
  536. * Get $categories variable
  537. *
  538. * @return string $categories
  539. * @see setCategories()
  540. */
  541. public function getCategories() {
  542. return $this->categories;
  543. } // end function
  544. /**
  545. * Get $frequency variable
  546. *
  547. * @return string $frequencies
  548. * @see setFrequency()
  549. * @since 1.010 - 2002-10-26
  550. */
  551. public function getFrequency() {
  552. return $this->frequency;
  553. } // end function
  554. /**
  555. * Get $status variable
  556. *
  557. * @return string $status
  558. * @see setStatus()
  559. * @since 1.011 - 2002-12-22
  560. */
  561. public function getStatus() {
  562. return $this->status;
  563. } // end function
  564. /**
  565. * Get $interval variable
  566. *
  567. * @return int $interval
  568. * @see setInterval()
  569. * @since 1.010 - 2002-10-26
  570. */
  571. public function getInterval() {
  572. return $this->interval;
  573. } // end function
  574. /**
  575. * Returns a string with exeptiondates
  576. *
  577. * @return string
  578. * @see setExeptDates()
  579. * @since 1.010 - 2002-10-26
  580. */
  581. public function getExeptDates() {
  582. $return = (string) '';
  583. foreach ($this->exept_dates as $date) {
  584. $return .= (string) $date . ',';
  585. } // end foreach
  586. $return = (string) substr($return,0,strlen($return)-1);
  587. return (string) $return;
  588. } // end function
  589. /**
  590. * Get $class variable
  591. *
  592. * @return string $class
  593. * @see setClass()
  594. */
  595. public function getClass() {
  596. return $this->class;
  597. } // end function
  598. /**
  599. * Get $priority variable
  600. *
  601. * @return string $priority
  602. * @see setPriority()
  603. */
  604. public function getPriority() {
  605. return $this->priority;
  606. } // end function
  607. /**
  608. * Get $last_mod_ts variable
  609. *
  610. * @return int $last_mod_ts
  611. * @see setLastModTS()
  612. * @since 1.020 - 2002-12-24
  613. */
  614. public function getLastModTS() {
  615. return $this->last_mod_ts;
  616. } // end function
  617. /**
  618. * Get $last_mod variable
  619. *
  620. * @return int $last_mod
  621. * @see setLastMod()
  622. * @since 1.020 - 2002-12-24
  623. */
  624. public function getLastMod() {
  625. return $this->last_mod;
  626. } // end function
  627. } // end class iCalBase
  628. ?>