Exemplo n.º 1
0
 /**
  * sort iCal compoments
  *
  * ascending sort on properties (if exist) x-current-dtstart, dtstart,
  * x-current-dtend, dtend, x-current-due, due, duration, created, dtstamp, uid
  * if no arguments, otherwise sorting on argument CATEGORIES, LOCATION, SUMMARY or RESOURCES
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.8.4 - 2011-06-02
  * @param string $sortArg, optional
  * @return void
  *
  */
 function sort($sortArg = FALSE)
 {
     if (is_array($this->components)) {
         if ($sortArg) {
             $sortArg = strtoupper($sortArg);
             if (!in_array($sortArg, array('ATTENDEE', 'CATEGORIES', 'DTSTAMP', 'LOCATION', 'ORGANIZER', 'RESOURCES', 'PRIORITY', 'STATUS', 'SUMMARY'))) {
                 $sortArg = FALSE;
             }
         }
         /* set sort parameters for each component */
         foreach ($this->components as $cix => &$c) {
             $c->srtk = array('0', '0', '0', '0');
             if ('vtimezone' == $c->objName) {
                 if (FALSE === ($c->srtk[0] = $c->getProperty('tzid'))) {
                     $c->srtk[0] = 0;
                 }
                 continue;
             } elseif ($sortArg) {
                 if ('ATTENDEE' == $sortArg || 'CATEGORIES' == $sortArg || 'RESOURCES' == $sortArg) {
                     $propValues = array();
                     $c->_getProperties($sortArg, $propValues);
                     $c->srtk[0] = reset(array_keys($propValues));
                 } elseif (FALSE !== ($d = $c->getProperty($sortArg))) {
                     $c->srtk[0] = $d;
                 }
                 continue;
             }
             if (FALSE !== ($d = $c->getProperty('X-CURRENT-DTSTART'))) {
                 $c->srtk[0] = iCal_UtilityFunctions::_date_time_string($d[1]);
             } elseif (FALSE === ($c->srtk[0] = $c->getProperty('dtstart'))) {
                 $c->srtk[1] = 0;
             }
             // sortkey 0 : dtstart
             if (FALSE !== ($d = $c->getProperty('X-CURRENT-DTEND'))) {
                 $c->srtk[1] = iCal_UtilityFunctions::_date_time_string($d[1]);
             } elseif (FALSE === ($c->srtk[1] = $c->getProperty('dtend'))) {
                 if (FALSE !== ($d = $c->getProperty('X-CURRENT-DUE'))) {
                     $c->srtk[1] = iCal_UtilityFunctions::_date_time_string($d[1]);
                 } elseif (FALSE === ($c->srtk[1] = $c->getProperty('due'))) {
                     if (FALSE === ($c->srtk[1] = $c->getProperty('duration', FALSE, FALSE, TRUE))) {
                         $c->srtk[1] = 0;
                     }
                 }
             }
             if (FALSE === ($c->srtk[2] = $c->getProperty('created'))) {
                 // sortkey 2 : created/dtstamp
                 if (FALSE === ($c->srtk[2] = $c->getProperty('dtstamp'))) {
                     $c->srtk[2] = 0;
                 }
             }
             if (FALSE === ($c->srtk[3] = $c->getProperty('uid'))) {
                 // sortkey 3 : uid
                 $c->srtk[3] = 0;
             }
         }
         // end foreach( $this->components as & $c
         /* sort */
         usort($this->components, array($this, '_cmpfcn'));
     }
 }
Exemplo n.º 2
0
 /**
  * step date, return updated date, array and timpstamp
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.4.16 - 2008-10-18
  * @param array $date, date to step
  * @param int $timestamp
  * @param array $step, default array( 'day' => 1 )
  * @return void
  */
 public static function _stepdate(&$date, &$timestamp, $step = array('day' => 1))
 {
     foreach ($step as $stepix => $stepvalue) {
         $date[$stepix] += $stepvalue;
     }
     $timestamp = iCal_UtilityFunctions::_date2timestamp($date);
     $date = iCal_UtilityFunctions::_timestamp2date($timestamp, 6);
     foreach ($date as $k => $v) {
         if (ctype_digit($v)) {
             $date[$k] = (int) $v;
         }
     }
 }
Exemplo n.º 3
0
 /**
  * get component property value/params
  *
  * if property has multiply values, consequtive function calls are needed
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.10.1 - 2011-07-16
  * @param string $propName, optional
  * @param int @propix, optional, if specific property is wanted in case of multiply occurences
  * @param bool $inclParam=FALSE
  * @param bool $specform=FALSE
  * @return mixed
  */
 function getProperty($propName = FALSE, $propix = FALSE, $inclParam = FALSE, $specform = FALSE)
 {
     if ($this->_notExistProp($propName)) {
         return FALSE;
     }
     $propName = $propName ? strtoupper($propName) : 'X-PROP';
     if (in_array($propName, array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'EXDATE', 'EXRULE', 'FREEBUSY', 'RDATE', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'TZNAME', 'X-PROP'))) {
         if (!$propix) {
             $propix = isset($this->propix[$propName]) ? $this->propix[$propName] + 2 : 1;
         }
         $this->propix[$propName] = --$propix;
     }
     switch ($propName) {
         case 'ACTION':
             if (!empty($this->action['value'])) {
                 return $inclParam ? $this->action : $this->action['value'];
             }
             break;
         case 'ATTACH':
             $ak = is_array($this->attach) ? array_keys($this->attach) : array();
             while (is_array($this->attach) && !isset($this->attach[$propix]) && 0 < count($this->attach) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->attach[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->attach[$propix] : $this->attach[$propix]['value'];
             break;
         case 'ATTENDEE':
             $ak = is_array($this->attendee) ? array_keys($this->attendee) : array();
             while (is_array($this->attendee) && !isset($this->attendee[$propix]) && 0 < count($this->attendee) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->attendee[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->attendee[$propix] : $this->attendee[$propix]['value'];
             break;
         case 'CATEGORIES':
             $ak = is_array($this->categories) ? array_keys($this->categories) : array();
             while (is_array($this->categories) && !isset($this->categories[$propix]) && 0 < count($this->categories) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->categories[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->categories[$propix] : $this->categories[$propix]['value'];
             break;
         case 'CLASS':
             if (!empty($this->class['value'])) {
                 return $inclParam ? $this->class : $this->class['value'];
             }
             break;
         case 'COMMENT':
             $ak = is_array($this->comment) ? array_keys($this->comment) : array();
             while (is_array($this->comment) && !isset($this->comment[$propix]) && 0 < count($this->comment) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->comment[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->comment[$propix] : $this->comment[$propix]['value'];
             break;
         case 'COMPLETED':
             if (!empty($this->completed['value'])) {
                 return $inclParam ? $this->completed : $this->completed['value'];
             }
             break;
         case 'CONTACT':
             $ak = is_array($this->contact) ? array_keys($this->contact) : array();
             while (is_array($this->contact) && !isset($this->contact[$propix]) && 0 < count($this->contact) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->contact[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->contact[$propix] : $this->contact[$propix]['value'];
             break;
         case 'CREATED':
             if (!empty($this->created['value'])) {
                 return $inclParam ? $this->created : $this->created['value'];
             }
             break;
         case 'DESCRIPTION':
             $ak = is_array($this->description) ? array_keys($this->description) : array();
             while (is_array($this->description) && !isset($this->description[$propix]) && 0 < count($this->description) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->description[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->description[$propix] : $this->description[$propix]['value'];
             break;
         case 'DTEND':
             if (!empty($this->dtend['value'])) {
                 return $inclParam ? $this->dtend : $this->dtend['value'];
             }
             break;
         case 'DTSTAMP':
             if (in_array($this->objName, array('valarm', 'vtimezone', 'standard', 'daylight'))) {
                 return;
             }
             if (!isset($this->dtstamp['value'])) {
                 $this->_makeDtstamp();
             }
             return $inclParam ? $this->dtstamp : $this->dtstamp['value'];
             break;
         case 'DTSTART':
             if (!empty($this->dtstart['value'])) {
                 return $inclParam ? $this->dtstart : $this->dtstart['value'];
             }
             break;
         case 'DUE':
             if (!empty($this->due['value'])) {
                 return $inclParam ? $this->due : $this->due['value'];
             }
             break;
         case 'DURATION':
             if (!isset($this->duration['value'])) {
                 return FALSE;
             }
             $value = $specform && isset($this->dtstart['value']) && isset($this->duration['value']) ? iCal_UtilityFunctions::_duration2date($this->dtstart['value'], $this->duration['value']) : $this->duration['value'];
             return $inclParam ? array('value' => $value, 'params' => $this->duration['params']) : $value;
             break;
         case 'EXDATE':
             $ak = is_array($this->exdate) ? array_keys($this->exdate) : array();
             while (is_array($this->exdate) && !isset($this->exdate[$propix]) && 0 < count($this->exdate) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->exdate[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->exdate[$propix] : $this->exdate[$propix]['value'];
             break;
         case 'EXRULE':
             $ak = is_array($this->exrule) ? array_keys($this->exrule) : array();
             while (is_array($this->exrule) && !isset($this->exrule[$propix]) && 0 < count($this->exrule) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->exrule[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->exrule[$propix] : $this->exrule[$propix]['value'];
             break;
         case 'FREEBUSY':
             $ak = is_array($this->freebusy) ? array_keys($this->freebusy) : array();
             while (is_array($this->freebusy) && !isset($this->freebusy[$propix]) && 0 < count($this->freebusy) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->freebusy[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->freebusy[$propix] : $this->freebusy[$propix]['value'];
             break;
         case 'GEO':
             if (!empty($this->geo['value'])) {
                 return $inclParam ? $this->geo : $this->geo['value'];
             }
             break;
         case 'LAST-MODIFIED':
             if (!empty($this->lastmodified['value'])) {
                 return $inclParam ? $this->lastmodified : $this->lastmodified['value'];
             }
             break;
         case 'LOCATION':
             if (!empty($this->location['value'])) {
                 return $inclParam ? $this->location : $this->location['value'];
             }
             break;
         case 'ORGANIZER':
             if (!empty($this->organizer['value'])) {
                 return $inclParam ? $this->organizer : $this->organizer['value'];
             }
             break;
         case 'PERCENT-COMPLETE':
             if (!empty($this->percentcomplete['value']) || isset($this->percentcomplete['value']) && '0' == $this->percentcomplete['value']) {
                 return $inclParam ? $this->percentcomplete : $this->percentcomplete['value'];
             }
             break;
         case 'PRIORITY':
             if (!empty($this->priority['value']) || isset($this->priority['value']) && '0' == $this->priority['value']) {
                 return $inclParam ? $this->priority : $this->priority['value'];
             }
             break;
         case 'RDATE':
             $ak = is_array($this->rdate) ? array_keys($this->rdate) : array();
             while (is_array($this->rdate) && !isset($this->rdate[$propix]) && 0 < count($this->rdate) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->rdate[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->rdate[$propix] : $this->rdate[$propix]['value'];
             break;
         case 'RECURRENCE-ID':
             if (!empty($this->recurrenceid['value'])) {
                 return $inclParam ? $this->recurrenceid : $this->recurrenceid['value'];
             }
             break;
         case 'RELATED-TO':
             $ak = is_array($this->relatedto) ? array_keys($this->relatedto) : array();
             while (is_array($this->relatedto) && !isset($this->relatedto[$propix]) && 0 < count($this->relatedto) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->relatedto[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->relatedto[$propix] : $this->relatedto[$propix]['value'];
             break;
         case 'REPEAT':
             if (!empty($this->repeat['value']) || isset($this->repeat['value']) && '0' == $this->repeat['value']) {
                 return $inclParam ? $this->repeat : $this->repeat['value'];
             }
             break;
         case 'REQUEST-STATUS':
             $ak = is_array($this->requeststatus) ? array_keys($this->requeststatus) : array();
             while (is_array($this->requeststatus) && !isset($this->requeststatus[$propix]) && 0 < count($this->requeststatus) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->requeststatus[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->requeststatus[$propix] : $this->requeststatus[$propix]['value'];
             break;
         case 'RESOURCES':
             $ak = is_array($this->resources) ? array_keys($this->resources) : array();
             while (is_array($this->resources) && !isset($this->resources[$propix]) && 0 < count($this->resources) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->resources[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->resources[$propix] : $this->resources[$propix]['value'];
             break;
         case 'RRULE':
             $ak = is_array($this->rrule) ? array_keys($this->rrule) : array();
             while (is_array($this->rrule) && !isset($this->rrule[$propix]) && 0 < count($this->rrule) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->rrule[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->rrule[$propix] : $this->rrule[$propix]['value'];
             break;
         case 'SEQUENCE':
             if (isset($this->sequence['value']) && (isset($this->sequence['value']) && '0' <= $this->sequence['value'])) {
                 return $inclParam ? $this->sequence : $this->sequence['value'];
             }
             break;
         case 'STATUS':
             if (!empty($this->status['value'])) {
                 return $inclParam ? $this->status : $this->status['value'];
             }
             break;
         case 'SUMMARY':
             if (!empty($this->summary['value'])) {
                 return $inclParam ? $this->summary : $this->summary['value'];
             }
             break;
         case 'TRANSP':
             if (!empty($this->transp['value'])) {
                 return $inclParam ? $this->transp : $this->transp['value'];
             }
             break;
         case 'TRIGGER':
             if (!empty($this->trigger['value'])) {
                 return $inclParam ? $this->trigger : $this->trigger['value'];
             }
             break;
         case 'TZID':
             if (!empty($this->tzid['value'])) {
                 return $inclParam ? $this->tzid : $this->tzid['value'];
             }
             break;
         case 'TZNAME':
             $ak = is_array($this->tzname) ? array_keys($this->tzname) : array();
             while (is_array($this->tzname) && !isset($this->tzname[$propix]) && 0 < count($this->tzname) && $propix < end($ak)) {
                 $propix++;
             }
             if (!isset($this->tzname[$propix])) {
                 unset($this->propix[$propName]);
                 return FALSE;
             }
             return $inclParam ? $this->tzname[$propix] : $this->tzname[$propix]['value'];
             break;
         case 'TZOFFSETFROM':
             if (!empty($this->tzoffsetfrom['value'])) {
                 return $inclParam ? $this->tzoffsetfrom : $this->tzoffsetfrom['value'];
             }
             break;
         case 'TZOFFSETTO':
             if (!empty($this->tzoffsetto['value'])) {
                 return $inclParam ? $this->tzoffsetto : $this->tzoffsetto['value'];
             }
             break;
         case 'TZURL':
             if (!empty($this->tzurl['value'])) {
                 return $inclParam ? $this->tzurl : $this->tzurl['value'];
             }
             break;
         case 'UID':
             if (in_array($this->objName, array('valarm', 'vtimezone', 'standard', 'daylight'))) {
                 return FALSE;
             }
             if (empty($this->uid['value'])) {
                 $this->_makeuid();
             }
             return $inclParam ? $this->uid : $this->uid['value'];
             break;
         case 'URL':
             if (!empty($this->url['value'])) {
                 return $inclParam ? $this->url : $this->url['value'];
             }
             break;
         default:
             if ($propName != 'X-PROP') {
                 if (!isset($this->xprop[$propName])) {
                     return FALSE;
                 }
                 return $inclParam ? array($propName, $this->xprop[$propName]) : array($propName, $this->xprop[$propName]['value']);
             } else {
                 if (empty($this->xprop)) {
                     return FALSE;
                 }
                 $xpropno = 0;
                 foreach ($this->xprop as $xpropkey => $xpropvalue) {
                     if ($propix == $xpropno) {
                         return $inclParam ? array($xpropkey, $this->xprop[$xpropkey]) : array($xpropkey, $this->xprop[$xpropkey]['value']);
                     } else {
                         $xpropno++;
                     }
                 }
                 return FALSE;
                 // not found ??
             }
     }
     return FALSE;
 }