0 && ($content[$i+1]{0} == ' ' || $content[$i+1]{0} == "\t" )) { $line .= rtrim(substr($content[++$i],1)); } $data[] = $line; } return $data; } /** * Parses the feed found in content and calls storeSection to store * parsed data * @param string $content * @param SG_iCal $ical */ private static function _Parse( $content, SG_iCal $ical ) { $main_sections = array('vevent', 'vjournal', 'vtodo', 'vtimezone', 'vcalendar'); $array_idents = array('exdate','rdate'); $sections = array(); $section = ''; $current_data = array(); foreach( $content AS $line ) { $line = new SG_iCal_Line($line); if( $line->isBegin() ) { // New block of data, $section = new block $section = strtolower($line->getData()); $sections[] = strtolower($line->getData()); } elseif( $line->isEnd() ) { // End of block of data ($removed = just ended block, $section = new top-block) $removed = array_pop($sections); $section = end($sections); if( array_search($removed, $main_sections) !== false ) { self::StoreSection( $removed, $current_data[$removed], $ical); $current_data[$removed] = array(); } } else { // Data line foreach( $main_sections AS $s ) { // Loops though the main sections if( array_search($s, $sections) !== false ) { // This section is in the main section if( $section == $s ) { // It _is_ the main section else if (in_array($line->getIdent(), $array_idents)) //exdate could appears more that once $current_data[$s][$line->getIdent()][] = $line; else { $current_data[$s][$line->getIdent()] = $line; } } else { // Sub section $current_data[$s][$section][$line->getIdent()] = $line; } break; } } } } $current_data = array(); } /** * Stores the data in provided SG_iCal object * @param string $section eg 'vcalender', 'vevent' etc * @param string $data * @param SG_iCal $ical */ protected static function storeSection( $section, $data, SG_iCal $ical ) { $data = SG_iCal_Factory::Factory($ical, $section, $data); switch( $section ) { case 'vcalendar': return $ical->setCalendarInfo( $data ); case 'vevent': return $ical->addEvent( $data ); case 'vjournal': case 'vtodo': return true; // TODO: Implement case 'vtimezone': return $ical->addTimeZone( $data ); } } /** * This functions does some regexp checking to see if the value is * valid UTF-8. * * The function is from the book "Building Scalable Web Sites" by * Cal Henderson. * * @param string $data * @return bool */ private static function _ValidUtf8( $data ) { $rx = '[\xC0-\xDF]([^\x80-\xBF]|$)'; $rx .= '|[\xE0-\xEF].{0,1}([^\x80-\xBF]|$)'; $rx .= '|[\xF0-\xF7].{0,2}([^\x80-\xBF]|$)'; $rx .= '|[\xF8-\xFB].{0,3}([^\x80-\xBF]|$)'; $rx .= '|[\xFC-\xFD].{0,4}([^\x80-\xBF]|$)'; $rx .= '|[\xFE-\xFE].{0,5}([^\x80-\xBF]|$)'; $rx .= '|[\x00-\x7F][\x80-\xBF]'; $rx .= '|[\xC0-\xDF].[\x80-\xBF]'; $rx .= '|[\xE0-\xEF]..[\x80-\xBF]'; $rx .= '|[\xF0-\xF7]...[\x80-\xBF]'; $rx .= '|[\xF8-\xFB]....[\x80-\xBF]'; $rx .= '|[\xFC-\xFD].....[\x80-\xBF]'; $rx .= '|[\xFE-\xFE]......[\x80-\xBF]'; $rx .= '|^[\x80-\xBF]'; return ( ! (bool) preg_match('!'.$rx.'!', $data) ); } }