PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/iCalendar_v2/class.iCalJournal.inc.php

http://flaimo-php.googlecode.com/
PHP | 325 lines | 92 code | 24 blank | 209 comment | 12 complexity | 3bb8579d2d69180c5b2786ce9f98eecc MD5 | raw file
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. //+----------------------------------------------------------------------+
  4. //| WAMP (XP-SP1/1.3.27/4.0.12/5.0.0b2-dev) |
  5. //+----------------------------------------------------------------------+
  6. //| Copyright (c) 1992-2003 Michael Wimmer |
  7. //+----------------------------------------------------------------------+
  8. //| I don't have the time to read through all the licences to find out |
  9. //| what the exactly say. But it's simple. It's free for non commercial |
  10. //| projects, but as soon as you make money with it, i want my share :-) |
  11. //| (License : Free for non-commercial use) |
  12. //+----------------------------------------------------------------------+
  13. //| Authors: Michael Wimmer <flaimo@gmx.net> |
  14. //+----------------------------------------------------------------------+
  15. //
  16. // $Id$
  17. /**
  18. * @package iCalendar Everything to generate simple iCal files
  19. */
  20. /**
  21. * We need the base class
  22. */
  23. include_once 'class.iCalBase.inc.php';
  24. /**
  25. * Container for a single Journal
  26. *
  27. * Tested with WAMP (XP-SP2/2.2/5.2/5.1.0)
  28. * Last Change: 2008-04-07
  29. *
  30. * @access public
  31. * @author Michael Wimmer <flaimo@gmail.com>
  32. * @copyright Copyright Š 2002-2008, Michael Wimmer
  33. * @license GNU General Public License v3
  34. * @link http://code.google.com/p/flaimo-php/
  35. * @package iCalendar
  36. * @version 2.002
  37. */
  38. class iCalJournal extends iCalBase {
  39. /*-------------------*/
  40. /* V A R I A B L E S */
  41. /*-------------------*/
  42. /**
  43. * Timestamp of the start date
  44. *
  45. * @var int
  46. */
  47. private $startdate_ts;
  48. /**
  49. * start date in iCal format
  50. *
  51. * @var string
  52. */
  53. private $startdate;
  54. /**
  55. * Timestamp of the creation date
  56. *
  57. * @var int
  58. */
  59. private $created_ts;
  60. /**
  61. * creation date in iCal format
  62. *
  63. * @var string
  64. */
  65. private $created;
  66. /**
  67. * Automaticaly created: md5 value of the start date + end date
  68. *
  69. * @var string
  70. */
  71. private $uid;
  72. /**
  73. * '' = never, integer < 4 numbers = number of times, integer >= 4 = timestamp
  74. *
  75. * @var mixed
  76. */
  77. private $rec_end;
  78. /*-----------------------*/
  79. /* C O N S T R U C T O R */
  80. /*-----------------------*/
  81. /**#@+
  82. * @return void
  83. */
  84. /**
  85. * Constructor
  86. *
  87. * Only job is to set all the variablesnames
  88. *
  89. * @param string $summary Title for the event
  90. * @param string $description Description
  91. * @param int $start Start time for the event (timestamp)
  92. * @param int $created Creation date for the event (timestamp)
  93. * @param int $last_mod Last modification date for the event (timestamp)
  94. * @param int $status Status of the event (0 = TENTATIVE, 1 = CONFIRMED, 2 = CANCELLED)
  95. * @param int $class (0 = PRIVATE | 1 = PUBLIC | 2 = CONFIDENTIAL)
  96. * @param array $organizer The organizer &#x2013; use array('Name', 'name@domain.com')
  97. * @param array $attendees key = attendee name, value = e-mail, second value = role of the attendee [0 = CHAIR | 1 = REQ | 2 = OPT | 3 =NON] (example: array('Michi' => 'flaimo@gmx.net,1'); )
  98. * @param array $categories Array with Strings (example: array('Freetime','Party'))
  99. * @param int $frequency frequency: 0 = once, secoundly &#x2013; yearly = 1&#x2013;7
  100. * @param mixed $rec_end recurrency end: ('' = forever | integer = number of times | timestring = explicit date)
  101. * @param int $interval Interval for frequency (every 2,3,4 weeks&#x2026;)
  102. * @param string $days Array with the number of the days the event accures (example: array(0,1,5) = Sunday, Monday, Friday
  103. * @param string $weekstart Startday of the Week ( 0 = Sunday &#x2013; 6 = Saturday)
  104. * @param string $exept_dates exeption dates: Array with timestamps of dates that should not be includes in the recurring event
  105. * @param string $url optional URL for that event
  106. * @param string $lang Language of the strings used in the event (iso code)
  107. * @param string $uid Optional UID for the Journal
  108. * @uses setSummary()
  109. * @uses iCalBase::setDescription()
  110. * @uses setStartDate()
  111. * @uses setCreated()
  112. * @uses iCalBase::setLastMod()
  113. * @uses iCalBase::setStatus()
  114. * @uses iCalBase::setClass()
  115. * @uses iCalBase::setOrganizer()
  116. * @uses iCalBase::setAttendees()
  117. * @uses iCalBase::setCategories()
  118. * @uses iCalBase::setURL()
  119. * @uses iCalBase::setLanguage()
  120. * @uses iCalBase::setFrequency()
  121. * @uses setRecEnd()
  122. * @uses iCalBase::setInterval()
  123. * @uses iCalBase::setDays()
  124. * @uses iCalBase::setWeekStart()
  125. * @uses iCalBase::setExeptDates()
  126. * @uses iCalBase::setSequence()
  127. * @uses setUID()
  128. */
  129. function __construct($summary, $description, $start, $created, $last_mod,
  130. $status, $class, $organizer, $attendees, $categories,
  131. $frequency, $rec_end, $interval, $days, $weekstart,
  132. $exept_dates, $url, $lang, $uid) {
  133. parent::__construct();
  134. parent::setSummary($summary);
  135. parent::setDescription($description);
  136. $this->setStartDate($start);
  137. $this->setCreated($created);
  138. parent::setLastMod($last_mod);
  139. parent::setStatus($status);
  140. parent::setClass($class);
  141. parent::setOrganizer($organizer);
  142. parent::setAttendees($attendees);
  143. parent::setCategories($categories);
  144. parent::setURL($url);
  145. parent::setLanguage($lang);
  146. parent::setFrequency($frequency);
  147. $this->setRecEnd($rec_end);
  148. parent::setInterval($interval);
  149. parent::setDays($days);
  150. parent::setWeekStart($weekstart);
  151. parent::setExeptDates($exept_dates);
  152. parent::setSequence(0);
  153. $this->setUID($uid);
  154. } // end constructor
  155. /*-------------------*/
  156. /* F U N C T I O N S */
  157. /*-------------------*/
  158. /**
  159. * Sets the end for a recurring event (0 = never ending,
  160. * integer < 4 numbers = number of times, integer >= 4 enddate)
  161. *
  162. * @param int $freq
  163. * @see getRecEnd()
  164. * @uses iCalJournal::$rec_end
  165. * @since 1.010 - 2002-10-26
  166. */
  167. private function setRecEnd($freq = '') {
  168. if (strlen(trim($freq)) < 1) {
  169. $this->rec_end = 0;
  170. } elseif (is_int($freq) && strlen(trim($freq)) < 4) {
  171. $this->rec_end = $freq;
  172. } else {
  173. $this->rec_end = (string) parent::formatDate($freq);
  174. } // end if
  175. } // end function
  176. /**
  177. * Set $startdate_ts variable
  178. *
  179. * @param int $timestamp
  180. * @see getStartDateTS()
  181. * @uses iCalJournal::$startdate_ts
  182. * @uses iCalJournal::$enddate_ts
  183. */
  184. private function setStartDateTS($timestamp = 0) {
  185. if (is_int($timestamp) && $timestamp > 0) {
  186. $this->startdate_ts = (int) $timestamp;
  187. } else {
  188. $this->startdate_ts = (int) ((isset($this->enddate_ts) && is_numeric($this->enddate_ts) && $this->enddate_ts > 0) ? ($this->enddate_ts - 3600) : time());
  189. } // end if
  190. } // end function
  191. /**
  192. * Set $created_ts variable
  193. *
  194. * @param int $timestamp
  195. * @see getCreatedTS()
  196. * @uses iCalJournal::$created_ts
  197. */
  198. private function setCreatedTS($timestamp = 0) {
  199. if (is_int($timestamp) && $timestamp > 0) {
  200. $this->created_ts = (int) $timestamp;
  201. } // end if
  202. } // end function
  203. /**
  204. * Set $startdate variable
  205. *
  206. * @param int $timestamp
  207. * @see getStartDate()
  208. * @uses iCalJournal::$startdate
  209. * @uses iCalJournal::$startdate_ts
  210. * @uses setStartDateTS()
  211. */
  212. private function setStartDate($timestamp = 0) {
  213. $this->setStartDateTS($timestamp);
  214. $this->startdate = (string) parent::formatDate($this->startdate_ts);
  215. } // end function
  216. /**
  217. * Set $created variable
  218. *
  219. * @param int $timestamp
  220. * @see getCreated()
  221. * @uses iCalJournal::$created
  222. * @uses iCalJournal::$created_ts
  223. * @uses setCreatedTS()
  224. */
  225. private function setCreated($timestamp = 0) {
  226. $this->setCreatedTS($timestamp);
  227. $this->created = (string) parent::formatDate($this->created_ts);
  228. } // end function
  229. /**
  230. * Set $uid variable
  231. *
  232. * @param int $uid
  233. * @see getUID()
  234. * @uses iCalJournal::$uid
  235. */
  236. private function setUID($uid = 0) {
  237. if (strlen(trim($uid)) > 0) {
  238. $this->uid = (string) $uid;
  239. } else {
  240. $rawid = (string) $this->startdate . 'plus' . parent::getSummary();
  241. $this->uid = (string) md5($rawid);
  242. } // end if
  243. } // end function
  244. /**#@-*/
  245. /**
  246. * Get $rec_end variable
  247. *
  248. * @return mixed $rec_end
  249. * @see setRecEnd()
  250. * @since 1.010 - 2002-10-26
  251. */
  252. public function getRecEnd() {
  253. return $this->rec_end;
  254. } // end function
  255. /**
  256. * Get $startdate_ts variable
  257. *
  258. * @return int $startdate_ts
  259. * @see setStartDateTS()
  260. */
  261. public function getStartDateTS() {
  262. return (int) $this->startdate_ts;
  263. } // end function
  264. /**
  265. * Get $created_ts variable
  266. *
  267. * @return int $created_ts
  268. * @see setCreatedTS()
  269. */
  270. public function getCreatedTS() {
  271. return (int) $this->created_ts;
  272. } // end function
  273. /**
  274. * Get $startdate variable
  275. *
  276. * @return int $startdate
  277. * @see setStartDate()
  278. */
  279. public function getStartDate() {
  280. return (string) $this->startdate;
  281. } // end function
  282. /**
  283. * Get $created variable
  284. *
  285. * @return string $created
  286. * @see setCreated()
  287. */
  288. public function getCreated() {
  289. return (string) $this->created;
  290. } // end function
  291. /**
  292. * Get $uid variable
  293. *
  294. * @return string $uid
  295. * @see setUID()
  296. */
  297. public function getUID() {
  298. return (string) $this->uid;
  299. } // end function
  300. } // end class iCalJournal
  301. ?>