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')) {
40 public $attention = array();
43 const THR = 'http://purl.org/syndication/thread/1.0';
44 const GEORSS = 'http://www.georss.org/georss';
45 const OSTATUS = 'http://ostatus.org/schema/1.0';
47 const INREPLYTO = 'in-reply-to';
51 const POINT = 'point';
53 const ATTENTION = 'ostatus:attention';
54 const MENTIONED = 'mentioned';
55 const CONVERSATION = 'ostatus:conversation';
57 function __construct($element = null)
59 if (empty($element)) {
63 $replyToEl = ActivityUtils::child($element, self::INREPLYTO, self::THR);
65 if (!empty($replyToEl)) {
66 $this->replyToID = $replyToEl->getAttribute(self::REF);
67 $this->replyToUrl = $replyToEl->getAttribute(self::HREF);
70 $this->location = $this->getLocation($element);
72 $this->conversation = ActivityUtils::getLink($element, self::CONVERSATION);
74 // Multiple attention links allowed
76 $links = $element->getElementsByTagNameNS(ActivityUtils::ATOM, ActivityUtils::LINK);
79 for ($i = 0; $i < $links->length; $i++) {
80 $link = $links->item($i);
82 $linkRel = $link->getAttribute(ActivityUtils::REL);
84 // XXX: Deprecate this in favour of "mentioned" from Salmon spec
85 // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SALR
86 if ($linkRel == self::ATTENTION) {
87 $attention[] = $link->getAttribute(self::HREF);
88 } elseif ($linkRel == self::MENTIONED) {
89 $attention[] = $link->getAttribute(self::HREF);
92 $this->attention = array_unique($attention);
96 * Parse location given as a GeoRSS-simple point, if provided.
97 * http://www.georss.org/simple
99 * @param feed item $entry
100 * @return mixed Location or false
102 function getLocation($dom)
104 $points = $dom->getElementsByTagNameNS(self::GEORSS, self::POINT);
106 for ($i = 0; $i < $points->length; $i++) {
107 $point = $points->item($i)->textContent;
108 return self::locationFromPoint($point);
114 // XXX: Move to ActivityUtils or Location?
115 static function locationFromPoint($point)
117 $point = str_replace(',', ' ', $point); // per spec "treat commas as whitespace"
118 $point = preg_replace('/\s+/', ' ', $point);
119 $point = trim($point);
120 $coords = explode(' ', $point);
121 if (count($coords) == 2) {
122 list($lat, $lon) = $coords;
123 if (is_numeric($lat) && is_numeric($lon)) {
124 common_log(LOG_INFO, "Looking up location for $lat $lon from georss point");
125 return Location::fromLatLon($lat, $lon);
128 common_log(LOG_ERR, "Ignoring bogus georss:point value $point");