. * * @category Feed * @package StatusNet * @author Evan Prodromou * @author Zach Copley * @copyright 2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 * @link http://status.net/ */ if (!defined('STATUSNET')) { exit(1); } class PoCo { const NS = 'http://portablecontacts.net/spec/1.0'; const USERNAME = 'preferredUsername'; const DISPLAYNAME = 'displayName'; const NOTE = 'note'; public $preferredUsername; public $displayName; public $note; public $address; public $urls = array(); function __construct($element = null) { if (empty($element)) { return; } $this->preferredUsername = ActivityUtils::childContent( $element, self::USERNAME, self::NS ); $this->displayName = ActivityUtils::childContent( $element, self::DISPLAYNAME, self::NS ); $this->note = ActivityUtils::childContent( $element, self::NOTE, self::NS ); $this->address = $this->_getAddress($element); $this->urls = $this->_getURLs($element); } private function _getURLs($element) { $urlEls = $element->getElementsByTagnameNS(self::NS, PoCoURL::URLS); $urls = array(); foreach ($urlEls as $urlEl) { $type = ActivityUtils::childContent( $urlEl, PoCoURL::TYPE, PoCo::NS ); $value = ActivityUtils::childContent( $urlEl, PoCoURL::VALUE, PoCo::NS ); $primary = ActivityUtils::childContent( $urlEl, PoCoURL::PRIMARY, PoCo::NS ); $isPrimary = false; if (isset($primary) && $primary == 'true') { $isPrimary = true; } // @todo check to make sure a primary hasn't already been added array_push($urls, new PoCoURL($type, $value, $isPrimary)); } return $urls; } private function _getAddress($element) { $addressEl = ActivityUtils::child( $element, PoCoAddress::ADDRESS, PoCo::NS ); if (!empty($addressEl)) { $formatted = ActivityUtils::childContent( $addressEl, PoCoAddress::FORMATTED, self::NS ); if (!empty($formatted)) { $address = new PoCoAddress(); $address->formatted = $formatted; return $address; } } return null; } function fromProfile($profile) { if (empty($profile)) { return null; } $poco = new PoCo(); $poco->preferredUsername = $profile->nickname; $poco->displayName = $profile->getBestName(); $poco->note = $profile->bio; $paddy = new PoCoAddress(); $paddy->formatted = $profile->location; $poco->address = $paddy; if (!empty($profile->homepage)) { array_push( $poco->urls, new PoCoURL( 'homepage', $profile->homepage, true ) ); } return $poco; } function fromGroup($group) { if (empty($group)) { return null; } $poco = new PoCo(); $poco->preferredUsername = $group->nickname; $poco->displayName = $group->getBestName(); $poco->note = $group->description; $paddy = new PoCoAddress(); $paddy->formatted = $group->location; $poco->address = $paddy; if (!empty($group->homepage)) { array_push( $poco->urls, new PoCoURL( 'homepage', $group->homepage, true ) ); } return $poco; } function getPrimaryURL() { foreach ($this->urls as $url) { if ($url->primary) { return $url; } } } function asString() { $xs = new XMLStringer(true); $xs->element( 'poco:preferredUsername', null, $this->preferredUsername ); $xs->element( 'poco:displayName', null, $this->displayName ); if (!empty($this->note)) { $xs->element('poco:note', null, common_xml_safe_str($this->note)); } if (!empty($this->address)) { $xs->raw($this->address->asString()); } foreach ($this->urls as $url) { $xs->raw($url->asString()); } return $xs->getString(); } }