3 * StatusNet, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Zach Copley <zach@status.net>
26 * @copyright 2010 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
37 const NS = 'http://portablecontacts.net/spec/1.0';
39 const USERNAME = 'preferredUsername';
40 const DISPLAYNAME = 'displayName';
43 public $preferredUsername;
47 public $urls = array();
49 function __construct($element = null)
51 if (empty($element)) {
55 $this->preferredUsername = ActivityUtils::childContent(
61 $this->displayName = ActivityUtils::childContent(
67 $this->note = ActivityUtils::childContent(
73 $this->address = $this->_getAddress($element);
74 $this->urls = $this->_getURLs($element);
77 private function _getURLs($element)
79 $urlEls = $element->getElementsByTagnameNS(self::NS, PoCoURL::URLS);
82 foreach ($urlEls as $urlEl) {
84 $type = ActivityUtils::childContent(
90 $value = ActivityUtils::childContent(
96 $primary = ActivityUtils::childContent(
104 if (isset($primary) && $primary == 'true') {
108 // @todo check to make sure a primary hasn't already been added
110 array_push($urls, new PoCoURL($type, $value, $isPrimary));
115 private function _getAddress($element)
117 $addressEl = ActivityUtils::child(
119 PoCoAddress::ADDRESS,
123 if (!empty($addressEl)) {
124 $formatted = ActivityUtils::childContent(
126 PoCoAddress::FORMATTED,
130 if (!empty($formatted)) {
131 $address = new PoCoAddress();
132 $address->formatted = $formatted;
140 function fromProfile($profile)
142 if (empty($profile)) {
148 $poco->preferredUsername = $profile->nickname;
149 $poco->displayName = $profile->getBestName();
151 $poco->note = $profile->bio;
153 $paddy = new PoCoAddress();
154 $paddy->formatted = $profile->location;
155 $poco->address = $paddy;
157 if (!empty($profile->homepage)) {
171 function fromGroup($group)
179 $poco->preferredUsername = $group->nickname;
180 $poco->displayName = $group->getBestName();
182 $poco->note = $group->description;
184 $paddy = new PoCoAddress();
185 $paddy->formatted = $group->location;
186 $poco->address = $paddy;
188 if (!empty($group->homepage)) {
202 function getPrimaryURL()
204 foreach ($this->urls as $url) {
213 $xs = new XMLStringer(true);
215 'poco:preferredUsername',
217 $this->preferredUsername
226 if (!empty($this->note)) {
227 $xs->element('poco:note', null, common_xml_safe_str($this->note));
230 if (!empty($this->address)) {
231 $xs->raw($this->address->asString());
234 foreach ($this->urls as $url) {
235 $xs->raw($url->asString());
238 return $xs->getString();