/** * Create an HCalendar * * @param array $event * @example * $myEvent = array( 'name' => 'Release party of Chisimba', 'begin' => time(), 'end' => time()+2*60*60, // duration: 2 hours 'location' => array ( 'street' => '15z Main street', 'town' => 'Jonestown', 'zip' => '22912', 'state' => 'Western Cape', 'country' => 'South Africa' ), 'url' => 'http://chisimba.uwc.ac.za' ); */ public function showHcalendar($event) { return phpMicroformats::createHCalendar($event); }
function createHCard($data) { $result = ''; // prepare data $data['fn'] = $data['name']; // TODO parse name, apply vcard scheme (?) // encode vcard $result .= '<div class="vcard">' . "\n"; // name $result .= '<span class="fn">' . $data['fn'] . '</span>' . "\n"; // email if (isset($data['email'])) { $result .= '<span>Email: <a class="fn email" href="mailto:' . $data['email'] . '">' . $data['email'] . '</a></span>' . "\n"; } // company / organization if (isset($data['org'])) { if (isset($data['org']['name']) && strlen($data['org']['name']) > 0) { $result .= '<span class="org">' . $data['org']['name'] . '</span>' . "\n"; } if (isset($data['org']['title']) && strlen($data['org']['title']) > 0) { $result .= '<span class="title">' . $data['org']['title'] . '</span>' . "\n"; } } // location if (isset($data['location'])) { // TODO handle type of location: dom, intl, postal, parcel, home, work, pref $result .= phpMicroformats::formatLocation($data['location']); } // phone if (isset($data['phone'])) { // TODO parse phone number! if (is_string($data['phone'])) { $result .= '<div class="tel">' . "\n"; $result .= '<span>' . $data['phone'] . '</span>' . "\n"; $result .= '</div>' . "\n"; } // handle phone types: msg, home, work, pref, voice, fax, cell, video, pager, bbs, car, isdn, pcs $phoneTypes = array('msg', 'home', 'work', 'pref', 'voice', 'fax', 'cell', 'video', 'pager', 'bbs', 'car', 'isdn', 'pcs'); if (is_array($data['phone'])) { foreach ($data['phone'] as $type => $number) { if (in_array($type, $phoneTypes)) { $result .= '<div class="tel">' . "\n"; $result .= '<span class="type">' . $type . '</span>' . "\n"; $result .= '<span class="value">' . $number . '</span>' . "\n"; $result .= '</div>' . "\n"; } // else: not valid type, ignore it } } } // photo if (isset($data['photo']) && strlen($data['photo']) > 0) { // local files can be encoded and added directly to the returned data if (is_file($data['photo']) && file_exists($data['photo'])) { // extract image type $imageTypes = array('png' => array('png', 'PNG'), 'jpeg' => array('jpg', 'jpeg', 'JPG', 'JPEG'), 'gif' => array('gif', 'GIF')); $imageType = ''; foreach ($imageTypes as $type => $extensions) { foreach ($extensions as $tmpId => $imageExtension) { // check filename extension - if ok, use this image type for the encoding if (substr($data['photo'], -strlen('.' . $imageExtension)) == '.' . $imageExtension) { $imageType = $type; break; } } if ($imageType != '') { break; } } // TODO maybe check size of image, do not encode large images $result .= '<img class="photo" src="data:image/' . $imageType . ';base64,' . base64_encode(implode('', file($data['photo']))) . '" alt="' . $data['fn'] . '" />' . "\n"; } else { // TODO check if valid url with existing file at the end! // use url of image $result .= '<img class="photo" src="' . $data['photo'] . '" alt="' . $data['fn'] . '" />' . "\n"; } } // IM support: AIM, MSN, Skype, Yahooo if (isset($data['im'])) { $result .= '<div class="im">' . "\n"; // class "im" is not supported by microformats.org, but might be useful if (isset($data['im']['aim'])) { $result .= '<a class="url" href="aim:goim?screenname=' . $data['im']['aim'] . '">AIM chat with ' . $data['fn'] . '</a>' . "\n"; } if (isset($data['im']['msn'])) { $result .= '<a class="url" href="msnim:chat?contact=' . $data['im']['msn'] . '@hotmail.com">MSN chat with ' . $data['fn'] . '</a>' . "\n"; } if (isset($data['im']['skype'])) { $result .= '<a class="url" href="skype:' . $data['im']['skype'] . '?call">Skype call to ' . $data['fn'] . '</a>' . "\n"; $result .= '<a class="url" href="skype:' . $data['im']['skype'] . '?chat">Skype chat with ' . $data['fn'] . '</a>' . "\n"; } if (isset($data['im']['xmpp'])) { $result .= '<a class="url" href="xmpp:' . $data['im']['xmpp'] . '">XMPP chat with ' . $data['fn'] . '</a>' . "\n"; } if (isset($data['im']['yahoo'])) { $result .= '<a class="url" href="ymsgr:sendIM?' . $data['im']['yahoo'] . '">Yahoo chat with ' . $data['fn'] . '</a>' . "\n"; } $result .= '</div>' . "\n"; } $result .= '</div>' . "\n"; return $result; }