| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * StatusNet, the distributed open-source microblogging tool | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * An activity | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * PHP version 5 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * LICENCE: This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category  Feed | 
					
						
							|  |  |  |  * @package   StatusNet | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @author    Zach Copley <zach@status.net> | 
					
						
							|  |  |  |  * @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); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * A noun-ish thing in the activity universe | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The activity streams spec talks about activity objects, while also having | 
					
						
							|  |  |  |  * a tag activity:object, which is in fact an activity object. Aaaaaah! | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is just a thing in the activity universe. Can be the subject, object, | 
					
						
							|  |  |  |  * or indirect object (target!) of an activity verb. Rotten name, and I'm | 
					
						
							|  |  |  |  * propagating it. *sigh* | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @category  OStatus | 
					
						
							|  |  |  |  * @package   StatusNet | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @copyright 2010 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 | 
					
						
							|  |  |  |  * @link      http://status.net/ | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class ActivityObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const ARTICLE   = 'http://activitystrea.ms/schema/1.0/article'; | 
					
						
							|  |  |  |     const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry'; | 
					
						
							|  |  |  |     const NOTE      = 'http://activitystrea.ms/schema/1.0/note'; | 
					
						
							|  |  |  |     const STATUS    = 'http://activitystrea.ms/schema/1.0/status'; | 
					
						
							|  |  |  |     const FILE      = 'http://activitystrea.ms/schema/1.0/file'; | 
					
						
							|  |  |  |     const PHOTO     = 'http://activitystrea.ms/schema/1.0/photo'; | 
					
						
							|  |  |  |     const ALBUM     = 'http://activitystrea.ms/schema/1.0/photo-album'; | 
					
						
							|  |  |  |     const PLAYLIST  = 'http://activitystrea.ms/schema/1.0/playlist'; | 
					
						
							|  |  |  |     const VIDEO     = 'http://activitystrea.ms/schema/1.0/video'; | 
					
						
							|  |  |  |     const AUDIO     = 'http://activitystrea.ms/schema/1.0/audio'; | 
					
						
							|  |  |  |     const BOOKMARK  = 'http://activitystrea.ms/schema/1.0/bookmark'; | 
					
						
							|  |  |  |     const PERSON    = 'http://activitystrea.ms/schema/1.0/person'; | 
					
						
							|  |  |  |     const GROUP     = 'http://activitystrea.ms/schema/1.0/group'; | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  |     const _LIST     = 'http://activitystrea.ms/schema/1.0/list'; // LIST is reserved
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     const PLACE     = 'http://activitystrea.ms/schema/1.0/place'; | 
					
						
							|  |  |  |     const COMMENT   = 'http://activitystrea.ms/schema/1.0/comment'; | 
					
						
							|  |  |  |     // ^^^^^^^^^^ tea!
 | 
					
						
							| 
									
										
										
										
											2011-07-18 17:06:03 -04:00
										 |  |  |     const ACTIVITY = 'http://activitystrea.ms/schema/1.0/activity'; | 
					
						
							| 
									
										
										
										
											2013-06-04 16:29:47 -04:00
										 |  |  |     const SERVICE   = 'http://activitystrea.ms/schema/1.0/service'; | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |     const IMAGE     = 'http://activitystrea.ms/schema/1.0/image'; | 
					
						
							| 
									
										
										
										
											2013-06-07 03:11:23 -04:00
										 |  |  |     const COLLECTION = 'http://activitystrea.ms/schema/1.0/collection'; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:54 -04:00
										 |  |  |     const APPLICATION = 'http://activitystrea.ms/schema/1.0/application'; | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Atom elements we snarf
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const TITLE   = 'title'; | 
					
						
							|  |  |  |     const SUMMARY = 'summary'; | 
					
						
							|  |  |  |     const ID      = 'id'; | 
					
						
							|  |  |  |     const SOURCE  = 'source'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const NAME  = 'name'; | 
					
						
							|  |  |  |     const URI   = 'uri'; | 
					
						
							|  |  |  |     const EMAIL = 'email'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:53:30 -05:00
										 |  |  |     const POSTEROUS   = 'http://posterous.com/help/rss/1.0'; | 
					
						
							|  |  |  |     const AUTHOR      = 'author'; | 
					
						
							|  |  |  |     const USERIMAGE   = 'userImage'; | 
					
						
							|  |  |  |     const PROFILEURL  = 'profileUrl'; | 
					
						
							|  |  |  |     const NICKNAME    = 'nickName'; | 
					
						
							|  |  |  |     const DISPLAYNAME = 'displayName'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     public $element; | 
					
						
							|  |  |  |     public $type; | 
					
						
							|  |  |  |     public $id; | 
					
						
							|  |  |  |     public $title; | 
					
						
							|  |  |  |     public $summary; | 
					
						
							|  |  |  |     public $content; | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  |     public $owner; | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     public $link; | 
					
						
							|  |  |  |     public $source; | 
					
						
							|  |  |  |     public $avatarLinks = array(); | 
					
						
							|  |  |  |     public $geopoint; | 
					
						
							|  |  |  |     public $poco; | 
					
						
							|  |  |  |     public $displayName; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-22 18:53:09 -07:00
										 |  |  |     // @todo move this stuff to it's own PHOTO activity object
 | 
					
						
							|  |  |  |     const MEDIA_DESCRIPTION = 'description'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public $thumbnail; | 
					
						
							|  |  |  |     public $largerImage; | 
					
						
							|  |  |  |     public $description; | 
					
						
							| 
									
										
										
										
											2010-12-22 12:03:05 -08:00
										 |  |  |     public $extra = array(); | 
					
						
							| 
									
										
										
										
											2010-03-22 18:53:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |     public $stream; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Constructor | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * This probably needs to be refactored | 
					
						
							|  |  |  |      * to generate a local class (ActivityPerson, ActivityFile, ...) | 
					
						
							|  |  |  |      * based on the object type. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param DOMElement $element DOM thing to turn into an Activity thing | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     function __construct($element = null) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (empty($element)) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->element = $element; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->geopoint = $this->_childContent( | 
					
						
							|  |  |  |             $element, | 
					
						
							|  |  |  |             ActivityContext::POINT, | 
					
						
							|  |  |  |             ActivityContext::GEORSS | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($element->tagName == 'author') { | 
					
						
							|  |  |  |             $this->_fromAuthor($element); | 
					
						
							|  |  |  |         } else if ($element->tagName == 'item') { | 
					
						
							|  |  |  |             $this->_fromRssItem($element); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $this->_fromAtomEntry($element); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Some per-type attributes...
 | 
					
						
							|  |  |  |         if ($this->type == self::PERSON || $this->type == self::GROUP) { | 
					
						
							|  |  |  |             $this->displayName = $this->title; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $photos = ActivityUtils::getLinks($element, 'photo'); | 
					
						
							|  |  |  |             if (count($photos)) { | 
					
						
							|  |  |  |                 foreach ($photos as $link) { | 
					
						
							|  |  |  |                     $this->avatarLinks[] = new AvatarLink($link); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $avatars = ActivityUtils::getLinks($element, 'avatar'); | 
					
						
							|  |  |  |                 foreach ($avatars as $link) { | 
					
						
							|  |  |  |                     $this->avatarLinks[] = new AvatarLink($link); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->poco = new PoCo($element); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-22 18:53:09 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($this->type == self::PHOTO) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->thumbnail   = ActivityUtils::getLink($element, 'preview'); | 
					
						
							|  |  |  |             $this->largerImage = ActivityUtils::getLink($element, 'enclosure'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $this->description = ActivityUtils::childContent( | 
					
						
							|  |  |  |                 $element, | 
					
						
							|  |  |  |                 ActivityObject::MEDIA_DESCRIPTION, | 
					
						
							|  |  |  |                 Activity::MEDIA | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  |         if ($this->type == self::_LIST) { | 
					
						
							|  |  |  |             $owner = ActivityUtils::child($this->element, Activity::AUTHOR, Activity::SPEC); | 
					
						
							|  |  |  |             $this->owner = new ActivityObject($owner); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function _fromAuthor($element) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-12-27 10:19:51 -08:00
										 |  |  |         $this->type = $this->_childContent($element, | 
					
						
							|  |  |  |                                            Activity::OBJECTTYPE, | 
					
						
							|  |  |  |                                            Activity::SPEC); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->type)) { | 
					
						
							|  |  |  |             $this->type = self::PERSON; // XXX: is this fair?
 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-27 10:19:51 -08:00
										 |  |  |         // start with <atom:title>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $title = ActivityUtils::childHtmlContent($element, self::TITLE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($title)) { | 
					
						
							|  |  |  |             $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // fall back to <atom:name>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->title)) { | 
					
						
							|  |  |  |             $this->title = $this->_childContent($element, self::NAME); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-21 16:25:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-27 10:19:51 -08:00
										 |  |  |         // start with <atom:id>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->id = $this->_childContent($element, self::ID); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // fall back to <atom:uri>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->id)) { | 
					
						
							|  |  |  |             $this->id = $this->_childContent($element, self::URI); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // fall further back to <atom:email>
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->id)) { | 
					
						
							|  |  |  |             $email = $this->_childContent($element, self::EMAIL); | 
					
						
							|  |  |  |             if (!empty($email)) { | 
					
						
							|  |  |  |                 // XXX: acct: ?
 | 
					
						
							|  |  |  |                 $this->id = 'mailto:'.$email; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-12-27 10:19:51 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->link = ActivityUtils::getPermalink($element); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // fall finally back to <link rel=alternate>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
 | 
					
						
							|  |  |  |             $this->id = $this->link; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function _fromAtomEntry($element) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->type = $this->_childContent($element, Activity::OBJECTTYPE, | 
					
						
							|  |  |  |                                            Activity::SPEC); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->type)) { | 
					
						
							|  |  |  |             $this->type = ActivityObject::NOTE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->summary = ActivityUtils::childHtmlContent($element, self::SUMMARY); | 
					
						
							|  |  |  |         $this->content = ActivityUtils::getContent($element); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // We don't like HTML in our titles, although it's technically allowed
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $title = ActivityUtils::childHtmlContent($element, self::TITLE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:29:31 -07:00
										 |  |  |         $this->title = html_entity_decode(strip_tags($title), ENT_QUOTES, 'UTF-8'); | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->source  = $this->_getSource($element); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->link = ActivityUtils::getPermalink($element); | 
					
						
							| 
									
										
										
										
											2010-03-27 22:44:10 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $this->id = $this->_childContent($element, self::ID); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($this->id) && !empty($this->link)) { // fallback if there's no ID
 | 
					
						
							|  |  |  |             $this->id = $this->link; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-29 00:39:45 +02:00
										 |  |  |     // @todo FIXME: rationalize with Activity::_fromRssItem()
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     private function _fromRssItem($item) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->title = ActivityUtils::childContent($item, ActivityObject::TITLE, Activity::RSS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $contentEl = ActivityUtils::child($item, ActivityUtils::CONTENT, Activity::CONTENTNS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($contentEl)) { | 
					
						
							|  |  |  |             $this->content = htmlspecialchars_decode($contentEl->textContent, ENT_QUOTES); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $descriptionEl = ActivityUtils::child($item, Activity::DESCRIPTION, Activity::RSS); | 
					
						
							|  |  |  |             if (!empty($descriptionEl)) { | 
					
						
							|  |  |  |                 $this->content = htmlspecialchars_decode($descriptionEl->textContent, ENT_QUOTES); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->link = ActivityUtils::childContent($item, ActivityUtils::LINK, Activity::RSS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $guidEl = ActivityUtils::child($item, Activity::GUID, Activity::RSS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($guidEl)) { | 
					
						
							|  |  |  |             $this->id = $guidEl->textContent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($guidEl->hasAttribute('isPermaLink')) { | 
					
						
							|  |  |  |                 // overwrites <link>
 | 
					
						
							|  |  |  |                 $this->link = $this->id; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function fromRssAuthor($el) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $text = $el->textContent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (preg_match('/^(.*?) \((.*)\)$/', $text, $match)) { | 
					
						
							|  |  |  |             $email = $match[1]; | 
					
						
							|  |  |  |             $name = $match[2]; | 
					
						
							|  |  |  |         } else if (preg_match('/^(.*?) <(.*)>$/', $text, $match)) { | 
					
						
							|  |  |  |             $name = $match[1]; | 
					
						
							|  |  |  |             $email = $match[2]; | 
					
						
							|  |  |  |         } else if (preg_match('/.*@.*/', $text)) { | 
					
						
							|  |  |  |             $email = $text; | 
					
						
							|  |  |  |             $name = null; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $name = $text; | 
					
						
							|  |  |  |             $email = null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Not really enough info
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->element = $el; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->type  = ActivityObject::PERSON; | 
					
						
							|  |  |  |         $obj->title = $name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($email)) { | 
					
						
							|  |  |  |             $obj->id = 'mailto:'.$email; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $obj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function fromDcCreator($el) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // Not really enough info
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $text = $el->textContent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->element = $el; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->title = $text; | 
					
						
							|  |  |  |         $obj->type  = ActivityObject::PERSON; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $obj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public static function fromRssChannel($el) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $obj = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->element = $el; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->type = ActivityObject::PERSON; // @fixme guess better
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->title = ActivityUtils::childContent($el, ActivityObject::TITLE, Activity::RSS); | 
					
						
							|  |  |  |         $obj->link  = ActivityUtils::childContent($el, ActivityUtils::LINK, Activity::RSS); | 
					
						
							|  |  |  |         $obj->id    = ActivityUtils::getLink($el, Activity::SELF); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($obj->id)) { | 
					
						
							|  |  |  |             $obj->id = $obj->link; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $desc = ActivityUtils::childContent($el, Activity::DESCRIPTION, Activity::RSS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($desc)) { | 
					
						
							|  |  |  |             $obj->content = htmlspecialchars_decode($desc, ENT_QUOTES); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $imageEl = ActivityUtils::child($el, Activity::IMAGE, Activity::RSS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($imageEl)) { | 
					
						
							| 
									
										
										
										
											2010-03-20 17:18:24 -05:00
										 |  |  |             $url = ActivityUtils::childContent($imageEl, Activity::URL, Activity::RSS); | 
					
						
							|  |  |  |             $al = new AvatarLink(); | 
					
						
							|  |  |  |             $al->url = $url; | 
					
						
							|  |  |  |             $obj->avatarLinks[] = $al; | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $obj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:53:30 -05:00
										 |  |  |     public static function fromPosterousAuthor($el) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $obj = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->type = ActivityObject::PERSON; // @fixme any others...?
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $userImage = ActivityUtils::childContent($el, self::USERIMAGE, self::POSTEROUS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!empty($userImage)) { | 
					
						
							| 
									
										
										
										
											2010-03-20 17:18:24 -05:00
										 |  |  |             $al = new AvatarLink(); | 
					
						
							|  |  |  |             $al->url = $userImage; | 
					
						
							|  |  |  |             $obj->avatarLinks[] = $al; | 
					
						
							| 
									
										
										
										
											2010-03-20 16:53:30 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->link = ActivityUtils::childContent($el, self::PROFILEURL, self::POSTEROUS); | 
					
						
							|  |  |  |         $obj->id   = $obj->link; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->poco = new PoCo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->poco->preferredUsername = ActivityUtils::childContent($el, self::NICKNAME, self::POSTEROUS); | 
					
						
							|  |  |  |         $obj->poco->displayName       = ActivityUtils::childContent($el, self::DISPLAYNAME, self::POSTEROUS); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $obj->title = $obj->poco->displayName; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $obj; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     private function _childContent($element, $tag, $namespace=ActivityUtils::ATOM) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return ActivityUtils::childContent($element, $tag, $namespace); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Try to get a unique id for the source feed
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private function _getSource($element) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $sourceEl = ActivityUtils::child($element, 'source'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($sourceEl)) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $href = ActivityUtils::getLink($sourceEl, 'self'); | 
					
						
							|  |  |  |             if (!empty($href)) { | 
					
						
							|  |  |  |                 return $href; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return ActivityUtils::childContent($sourceEl, 'id'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static function fromNotice(Notice $notice) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |         if (Event::handle('StartActivityObjectFromNotice', array($notice, &$object))) { | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->type    = (empty($notice->object_type)) ? ActivityObject::NOTE : $notice->object_type; | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->id      = $notice->uri; | 
					
						
							| 
									
										
										
										
											2013-10-28 18:01:39 +01:00
										 |  |  |             $object->title = 'New ' . ActivityObject::canonicalType($object->type) . ' by '; | 
					
						
							|  |  |  |             try { | 
					
						
							|  |  |  |                 $object->title .= $notice->getProfile()->getAcctUri(); | 
					
						
							|  |  |  |             } catch (ProfileNoAcctUriException $e) { | 
					
						
							|  |  |  |                 $object->title .= $e->profile->nickname; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->content = $notice->rendered; | 
					
						
							| 
									
										
										
										
											2014-04-29 19:46:58 +02:00
										 |  |  |             $object->link    = $notice->getUrl(); | 
					
						
							| 
									
										
										
										
											2010-12-18 17:24:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 17:45:49 -04:00
										 |  |  |             $object->extra[] = array('status_net', array('notice_id' => $notice->id)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             Event::handle('EndActivityObjectFromNotice', array($notice, &$object)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static function fromProfile(Profile $profile) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |         if (Event::handle('StartActivityObjectFromProfile', array($profile, &$object))) { | 
					
						
							|  |  |  |             $object->type   = ActivityObject::PERSON; | 
					
						
							|  |  |  |             $object->id     = $profile->getUri(); | 
					
						
							|  |  |  |             $object->title  = $profile->getBestName(); | 
					
						
							|  |  |  |             $object->link   = $profile->profileurl; | 
					
						
							| 
									
										
										
										
											2010-12-18 17:24:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-30 22:13:37 +02:00
										 |  |  |             try { | 
					
						
							| 
									
										
										
										
											2013-10-06 15:54:06 +02:00
										 |  |  |                 $avatar = Avatar::getUploaded($profile); | 
					
						
							|  |  |  |                 $object->avatarLinks[] = AvatarLink::fromAvatar($avatar); | 
					
						
							|  |  |  |             } catch (NoAvatarException $e) { | 
					
						
							| 
									
										
										
										
											2013-09-30 22:13:37 +02:00
										 |  |  |                 // Could not find an original avatar to link
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-12-18 17:24:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $sizes = array( | 
					
						
							| 
									
										
										
										
											2010-12-20 13:26:57 -05:00
										 |  |  |                 AVATAR_PROFILE_SIZE, | 
					
						
							|  |  |  |                 AVATAR_STREAM_SIZE, | 
					
						
							|  |  |  |                 AVATAR_MINI_SIZE | 
					
						
							|  |  |  |             ); | 
					
						
							| 
									
										
										
										
											2010-12-18 17:24:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             foreach ($sizes as $size) { | 
					
						
							|  |  |  |                 $alink  = null; | 
					
						
							| 
									
										
										
										
											2013-10-01 11:37:59 +02:00
										 |  |  |                 try { | 
					
						
							| 
									
										
										
										
											2013-10-06 15:54:06 +02:00
										 |  |  |                     $avatar = Avatar::byProfile($profile, $size); | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |                     $alink = AvatarLink::fromAvatar($avatar); | 
					
						
							| 
									
										
										
										
											2013-10-06 15:54:06 +02:00
										 |  |  |                 } catch (NoAvatarException $e) { | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |                     $alink = new AvatarLink(); | 
					
						
							|  |  |  |                     $alink->type   = 'image/png'; | 
					
						
							|  |  |  |                     $alink->height = $size; | 
					
						
							|  |  |  |                     $alink->width  = $size; | 
					
						
							|  |  |  |                     $alink->url    = Avatar::defaultImage($size); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $object->avatarLinks[] = $alink; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (isset($profile->lat) && isset($profile->lon)) { | 
					
						
							|  |  |  |                 $object->geopoint = (float)$profile->lat | 
					
						
							|  |  |  |                     . ' ' . (float)$profile->lon; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $object->poco = PoCo::fromProfile($profile); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-09 21:35:16 +02:00
										 |  |  |             if ($profile->isLocal()) { | 
					
						
							| 
									
										
										
										
											2013-06-07 03:11:23 -04:00
										 |  |  |                 $object->extra[] = array('followers', array('url' => common_local_url('subscribers', array('nickname' => $profile->nickname)))); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             Event::handle('EndActivityObjectFromProfile', array($profile, &$object)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-06 03:48:41 +02:00
										 |  |  |     static function fromGroup(User_group $group) | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |         if (Event::handle('StartActivityObjectFromGroup', array($group, &$object))) { | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->type   = ActivityObject::GROUP; | 
					
						
							|  |  |  |             $object->id     = $group->getUri(); | 
					
						
							|  |  |  |             $object->title  = $group->getBestName(); | 
					
						
							|  |  |  |             $object->link   = $group->getUri(); | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->avatarLinks[] = AvatarLink::fromFilename($group->homepage_logo, | 
					
						
							|  |  |  |                                                               AVATAR_PROFILE_SIZE); | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->avatarLinks[] = AvatarLink::fromFilename($group->stream_logo, | 
					
						
							|  |  |  |                                                               AVATAR_STREAM_SIZE); | 
					
						
							| 
									
										
										
										
											2010-12-18 17:24:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->avatarLinks[] = AvatarLink::fromFilename($group->mini_logo, | 
					
						
							|  |  |  |                                                               AVATAR_MINI_SIZE); | 
					
						
							| 
									
										
										
										
											2010-12-18 17:24:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             $object->poco = PoCo::fromGroup($group); | 
					
						
							|  |  |  |             Event::handle('EndActivityObjectFromGroup', array($group, &$object)); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  |     static function fromPeopletag($ptag) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							|  |  |  |         if (Event::handle('StartActivityObjectFromPeopletag', array($ptag, &$object))) { | 
					
						
							|  |  |  |             $object->type    = ActivityObject::_LIST; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $object->id      = $ptag->getUri(); | 
					
						
							|  |  |  |             $object->title   = $ptag->tag; | 
					
						
							|  |  |  |             $object->summary = $ptag->description; | 
					
						
							|  |  |  |             $object->link    = $ptag->homeUrl(); | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |             $object->owner   = Profile::getKV('id', $ptag->tagger); | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  |             $object->poco    = PoCo::fromProfile($object->owner); | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |             Event::handle('EndActivityObjectFromPeopletag', array($ptag, &$object)); | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  |         } | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |     static function fromFile(File $file) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (Event::handle('StartActivityObjectFromFile', array($file, &$object))) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $object->type = self::mimeTypeToObjectType($file->mimetype); | 
					
						
							|  |  |  |             $object->id   = TagURI::mint(sprintf("file:%d", $file->id)); | 
					
						
							| 
									
										
										
										
											2013-06-05 16:12:54 -04:00
										 |  |  |             $object->link = common_local_url('attachment', array('attachment' => $file->id)); | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if ($file->title) { | 
					
						
							|  |  |  |                 $object->title = $file->title; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($file->date) { | 
					
						
							|  |  |  |                 $object->date = $file->date; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-28 12:12:06 +02:00
										 |  |  |             try { | 
					
						
							|  |  |  |                 $thumbnail = $file->getThumbnail(); | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |                 $object->thumbnail = $thumbnail; | 
					
						
							| 
									
										
										
										
											2014-04-28 12:12:06 +02:00
										 |  |  |             } catch (UnsupportedMediaException $e) { | 
					
						
							|  |  |  |                 $object->thumbnail = null; | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 16:51:35 -04:00
										 |  |  |             switch (ActivityObject::canonicalType($object->type)) { | 
					
						
							|  |  |  |             case 'image': | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |                 $object->largerImage = $file->url; | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2013-06-05 16:51:35 -04:00
										 |  |  |             case 'video': | 
					
						
							|  |  |  |             case 'audio': | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |                 $object->stream = $file->url; | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             Event::handle('EndActivityObjectFromFile', array($file, &$object)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:54 -04:00
										 |  |  |     static function fromNoticeSource(Notice_source $source) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							| 
									
										
										
										
											2013-06-07 11:49:34 -04:00
										 |  |  |         $wellKnown = array('web', 'xmpp', 'mail', 'omb', 'system', 'api', 'ostatus', | 
					
						
							|  |  |  |                            'activity', 'feed', 'mirror', 'twitter', 'facebook'); | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:54 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (Event::handle('StartActivityObjectFromNoticeSource', array($source, &$object))) { | 
					
						
							|  |  |  |             $object->type = ActivityObject::APPLICATION; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:49:34 -04:00
										 |  |  |             if (in_array($source->code, $wellKnown)) { | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:54 -04:00
										 |  |  |                 // We use one ID for all well-known StatusNet sources
 | 
					
						
							|  |  |  |                 $object->id = "tag:status.net,2009:notice-source:".$source->code; | 
					
						
							|  |  |  |             } else if ($source->url) { | 
					
						
							|  |  |  |                 // They registered with an URL
 | 
					
						
							|  |  |  |                 $object->id = $source->url; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 // Locally-registered, no URL
 | 
					
						
							|  |  |  |                 $object->id = TagURI::mint("notice-source:".$source->code); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($source->url) { | 
					
						
							|  |  |  |                 $object->link = $source->url; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($source->name) { | 
					
						
							|  |  |  |                 $object->title = $source->name; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $object->title = $source->code; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($source->created) { | 
					
						
							|  |  |  |                 $object->date = $source->created; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							| 
									
										
										
										
											2013-06-08 17:45:49 -04:00
										 |  |  |             $object->extra[] = array('status_net', array('source_code' => $source->code)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             Event::handle('EndActivityObjectFromNoticeSource', array($source, &$object)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static function fromMessage(Message $message) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = new ActivityObject(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (Event::handle('StartActivityObjectFromMessage', array($message, &$object))) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $object->type    = ActivityObject::NOTE; | 
					
						
							|  |  |  |             $object->id      = ($message->uri) ? $message->uri : (($message->url) ? $message->url : TagURI::mint(sprintf("message:%d", $message->id))); | 
					
						
							|  |  |  |             $object->content = $message->rendered; | 
					
						
							|  |  |  |             $object->date    = $message->created; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:54 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 17:45:49 -04:00
										 |  |  |             if ($message->url) { | 
					
						
							|  |  |  |                 $object->link = $message->url; | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $object->link = common_local_url('showmessage', array('message' => $message->id)); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $object->extra[] = array('status_net', array('message_id' => $message->id)); | 
					
						
							|  |  |  |              | 
					
						
							| 
									
										
										
										
											2013-06-08 21:05:09 -04:00
										 |  |  |             Event::handle('EndActivityObjectFromMessage', array($message, &$object)); | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:54 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $object; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |     function outputTo($xo, $tag='activity:object') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!empty($tag)) { | 
					
						
							|  |  |  |             $xo->elementStart($tag); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |         if (Event::handle('StartActivityObjectOutputAtom', array($this, $xo))) { | 
					
						
							|  |  |  |             $xo->element('activity:object-type', null, $this->type); | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             // <author> uses URI
 | 
					
						
							| 
									
										
										
										
											2010-12-27 09:25:26 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if ($tag == 'author') { | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 $xo->element(self::URI, null, $this->id); | 
					
						
							| 
									
										
										
										
											2010-12-27 09:25:26 -08:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 $xo->element(self::ID, null, $this->id); | 
					
						
							| 
									
										
										
										
											2010-12-27 09:25:26 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->title)) { | 
					
						
							|  |  |  |                 $name = common_xml_safe_str($this->title); | 
					
						
							|  |  |  |                 if ($tag == 'author') { | 
					
						
							|  |  |  |                     // XXX: Backward compatibility hack -- atom:name should contain
 | 
					
						
							|  |  |  |                     // full name here, instead of nickname, i.e.: $name. Change
 | 
					
						
							|  |  |  |                     // this in the next version.
 | 
					
						
							|  |  |  |                     $xo->element(self::NAME, null, $this->poco->preferredUsername); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $xo->element(self::TITLE, null, $name); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->summary)) { | 
					
						
							|  |  |  |                 $xo->element( | 
					
						
							|  |  |  |                     self::SUMMARY, | 
					
						
							|  |  |  |                     null, | 
					
						
							|  |  |  |                     common_xml_safe_str($this->summary) | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->content)) { | 
					
						
							|  |  |  |                 // XXX: assuming HTML content here
 | 
					
						
							| 
									
										
										
										
											2013-10-08 15:00:54 +02:00
										 |  |  |                 $xo->element( | 
					
						
							|  |  |  |                     ActivityUtils::CONTENT, | 
					
						
							| 
									
										
										
										
											2013-10-20 12:50:27 +02:00
										 |  |  |                     array('type' => 'html'), | 
					
						
							|  |  |  |                     common_xml_safe_str($this->content) | 
					
						
							| 
									
										
										
										
											2013-10-08 15:00:54 +02:00
										 |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->link)) { | 
					
						
							| 
									
										
										
										
											2010-12-20 13:26:57 -05:00
										 |  |  |                 $xo->element( | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                     'link', | 
					
						
							|  |  |  |                     array( | 
					
						
							|  |  |  |                         'rel' => 'alternate', | 
					
						
							|  |  |  |                         'type' => 'text/html', | 
					
						
							|  |  |  |                         'href' => $this->link | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |                     ), | 
					
						
							|  |  |  |                     null | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-22 07:56:25 +05:30
										 |  |  |             if(!empty($this->owner)) { | 
					
						
							|  |  |  |                 $owner = $this->owner->asActivityNoun(self::AUTHOR); | 
					
						
							|  |  |  |                 $xo->raw($owner); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-03-06 23:36:38 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if ($this->type == ActivityObject::PERSON | 
					
						
							|  |  |  |                 || $this->type == ActivityObject::GROUP) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-02 14:37:10 +02:00
										 |  |  |                 foreach ($this->avatarLinks as $alink) { | 
					
						
							|  |  |  |                     $xo->element('link', | 
					
						
							|  |  |  |                             array( | 
					
						
							|  |  |  |                                 'rel'          => 'avatar', | 
					
						
							|  |  |  |                                 'type'         => $alink->type, | 
					
						
							|  |  |  |                                 'media:width'  => $alink->width, | 
					
						
							|  |  |  |                                 'media:height' => $alink->height, | 
					
						
							|  |  |  |                                 'href'         => $alink->url, | 
					
						
							|  |  |  |                                 ), | 
					
						
							|  |  |  |                             null); | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->geopoint)) { | 
					
						
							|  |  |  |                 $xo->element( | 
					
						
							|  |  |  |                     'georss:point', | 
					
						
							|  |  |  |                     null, | 
					
						
							|  |  |  |                     $this->geopoint | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (!empty($this->poco)) { | 
					
						
							|  |  |  |                 $this->poco->outputTo($xo); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // @fixme there's no way here to make a tree; elements can only contain plaintext
 | 
					
						
							|  |  |  |             // @fixme these may collide with JSON extensions
 | 
					
						
							|  |  |  |             foreach ($this->extra as $el) { | 
					
						
							| 
									
										
										
										
											2013-09-24 00:12:30 +02:00
										 |  |  |                 list($extraTag, $attrs, $content) = array_pad($el, 3, null); | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 $xo->element($extraTag, $attrs, $content); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-12-20 13:26:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             Event::handle('EndActivityObjectOutputAtom', array($this, $xo)); | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |         if (!empty($tag)) { | 
					
						
							|  |  |  |             $xo->elementEnd($tag); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-12-20 13:26:57 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-12-20 13:26:57 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function asString($tag='activity:object') | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $xs = new XMLStringer(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-10 19:33:58 +02:00
										 |  |  |         $this->outputTo($xs, $tag); | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $xs->getString(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* | 
					
						
							|  |  |  |      * Returns an array based on this Activity Object suitable for | 
					
						
							|  |  |  |      * encoding as JSON. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return array $object the activity object array | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function asArray() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $object = array(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |         if (Event::handle('StartActivityObjectOutputJson', array($this, &$object))) { | 
					
						
							| 
									
										
										
										
											2011-08-25 10:00:20 -07:00
										 |  |  |             // XXX: attachments are added by Activity
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // author (Add object for author? Could be useful for repeats.)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // content (Add rendered version of the notice?)
 | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 10:00:20 -07:00
										 |  |  |             // downstreamDuplicates
 | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             // id
 | 
					
						
							| 
									
										
										
										
											2013-06-07 03:11:23 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if ($this->id) { | 
					
						
							|  |  |  |                 $object['id'] = $this->id; | 
					
						
							|  |  |  |             } else if ($this->link) { | 
					
						
							|  |  |  |                 $object['id'] = $this->link; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if ($this->type == ActivityObject::PERSON | 
					
						
							|  |  |  |                 || $this->type == ActivityObject::GROUP) { | 
					
						
							| 
									
										
										
										
											2011-02-16 16:21:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-08 15:00:54 +02:00
										 |  |  |                 // displayName
 | 
					
						
							|  |  |  |                 $object['displayName'] = $this->title; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 // XXX: Not sure what the best avatar is to use for the
 | 
					
						
							|  |  |  |                 // author's "image". For now, I'm using the large size.
 | 
					
						
							| 
									
										
										
										
											2011-02-16 18:55:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-25 11:37:15 -04:00
										 |  |  |                 $imgLink          = null; | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 $avatarMediaLinks = array(); | 
					
						
							| 
									
										
										
										
											2011-02-16 16:21:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 foreach ($this->avatarLinks as $a) { | 
					
						
							| 
									
										
										
										
											2011-02-16 18:55:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                     // Make a MediaLink for every other Avatar
 | 
					
						
							|  |  |  |                     $avatar = new ActivityStreamsMediaLink( | 
					
						
							|  |  |  |                         $a->url, | 
					
						
							|  |  |  |                         $a->width, | 
					
						
							|  |  |  |                         $a->height, | 
					
						
							|  |  |  |                         $a->type, | 
					
						
							|  |  |  |                         'avatar' | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2011-02-16 18:55:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                     // Find the big avatar to use as the "image"
 | 
					
						
							|  |  |  |                     if ($a->height == AVATAR_PROFILE_SIZE) { | 
					
						
							|  |  |  |                         $imgLink = $avatar; | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2011-02-16 18:55:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                     $avatarMediaLinks[] = $avatar->asArray(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-02-16 16:21:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 17:12:28 -04:00
										 |  |  |                 if (!array_key_exists('status_net', $object)) { | 
					
						
							|  |  |  |                     $object['status_net'] = array(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 $object['status_net']['avatarLinks'] = $avatarMediaLinks; // extension
 | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |                 // image
 | 
					
						
							| 
									
										
										
										
											2011-08-25 11:37:15 -04:00
										 |  |  |                 if (!empty($imgLink)) { | 
					
						
							|  |  |  |                     $object['image']  = $imgLink->asArray(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             // objectType
 | 
					
						
							|  |  |  |             //
 | 
					
						
							|  |  |  |             // We can probably use the whole schema URL here but probably the
 | 
					
						
							|  |  |  |             // relative simple name is easier to parse
 | 
					
						
							| 
									
										
										
										
											2013-06-04 17:12:28 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $object['objectType'] = ActivityObject::canonicalType($this->type); | 
					
						
							| 
									
										
										
										
											2011-08-25 10:00:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             // summary
 | 
					
						
							|  |  |  |             $object['summary'] = $this->summary; | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-08 15:00:54 +02:00
										 |  |  |             // content, usually rendered HTML
 | 
					
						
							| 
									
										
										
										
											2011-12-31 01:56:26 -08:00
										 |  |  |             $object['content'] = $this->content; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // published (probably don't need. Might be useful for repeats.)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // updated (probably don't need this)
 | 
					
						
							| 
									
										
										
										
											2011-08-25 10:00:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             // TODO: upstreamDuplicates
 | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 16:51:35 -04:00
										 |  |  |             if ($this->link) { | 
					
						
							|  |  |  |                 $object['url'] = $this->link; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-02-16 18:55:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             /* Extensions */ | 
					
						
							|  |  |  |             // @fixme these may collide with XML extensions
 | 
					
						
							|  |  |  |             // @fixme multiple tags of same name will overwrite each other
 | 
					
						
							|  |  |  |             // @fixme text content from XML extensions will be lost
 | 
					
						
							| 
									
										
										
										
											2013-06-04 17:12:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             foreach ($this->extra as $e) { | 
					
						
							| 
									
										
										
										
											2013-09-24 01:26:18 +02:00
										 |  |  |                 list($objectName, $props, $txt) = array_pad($e, 3, null); | 
					
						
							| 
									
										
										
										
											2013-06-04 17:12:28 -04:00
										 |  |  |                 if (!empty($objectName)) { | 
					
						
							|  |  |  |                     $parts = explode(":", $objectName); | 
					
						
							|  |  |  |                     if (count($parts) == 2 && $parts[0] == "statusnet") { | 
					
						
							|  |  |  |                         if (!array_key_exists('status_net', $object)) { | 
					
						
							|  |  |  |                             $object['status_net'] = array(); | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         $object['status_net'][$parts[1]] = $props; | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         $object[$objectName] = $props; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->geopoint)) { | 
					
						
							| 
									
										
										
										
											2011-02-17 20:12:28 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-04 17:22:51 -04:00
										 |  |  |                 list($lat, $lon) = explode(' ', $this->geopoint); | 
					
						
							| 
									
										
										
										
											2011-02-17 20:12:28 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 21:16:58 -04:00
										 |  |  |                 if (!empty($lat) && !empty($lon)) { | 
					
						
							|  |  |  |                     $object['location'] = array( | 
					
						
							|  |  |  |                         'objectType' => 'place', | 
					
						
							|  |  |  |                         'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon), | 
					
						
							|  |  |  |                         'lat' => $lat, | 
					
						
							|  |  |  |                         'lon' => $lon | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2013-06-04 17:22:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 21:16:58 -04:00
										 |  |  |                     $loc = Location::fromLatLon((float)$lat, (float)$lon); | 
					
						
							| 
									
										
										
										
											2013-06-04 17:22:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 21:16:58 -04:00
										 |  |  |                     if ($loc) { | 
					
						
							|  |  |  |                         $name = $loc->getName(); | 
					
						
							| 
									
										
										
										
											2013-06-04 17:22:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 21:16:58 -04:00
										 |  |  |                         if ($name) { | 
					
						
							|  |  |  |                             $object['location']['displayName'] = $name; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                         $url = $loc->getURL(); | 
					
						
							| 
									
										
										
										
											2013-06-04 17:22:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-08 21:16:58 -04:00
										 |  |  |                         if ($url) { | 
					
						
							|  |  |  |                             $object['location']['url'] = $url; | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2013-06-04 17:22:51 -04:00
										 |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-02-17 20:12:28 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             if (!empty($this->poco)) { | 
					
						
							| 
									
										
										
										
											2013-06-04 17:12:28 -04:00
										 |  |  |                 $object['portablecontacts_net'] = array_filter($this->poco->asArray()); | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2013-06-04 17:12:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |             if (!empty($this->thumbnail)) { | 
					
						
							|  |  |  |                 if (is_string($this->thumbnail)) { | 
					
						
							|  |  |  |                     $object['image'] = array('url' => $this->thumbnail); | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $object['image'] = array('url' => $this->thumbnail->url); | 
					
						
							|  |  |  |                     if ($this->thumbnail->width) { | 
					
						
							|  |  |  |                         $object['image']['width'] = $this->thumbnail->width; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     if ($this->thumbnail->height) { | 
					
						
							|  |  |  |                         $object['image']['height'] = $this->thumbnail->height; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 16:58:31 -04:00
										 |  |  |             switch (ActivityObject::canonicalType($this->type)) { | 
					
						
							| 
									
										
										
										
											2013-06-05 16:51:35 -04:00
										 |  |  |             case 'image': | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |                 if (!empty($this->largerImage)) { | 
					
						
							|  |  |  |                     $object['fullImage'] = array('url' => $this->largerImage); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							| 
									
										
										
										
											2013-06-05 16:51:35 -04:00
										 |  |  |             case 'audio': | 
					
						
							|  |  |  |             case 'video': | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |                 if (!empty($this->stream)) { | 
					
						
							|  |  |  |                     $object['stream'] = array('url' => $this->stream); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 break; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 11:54:23 -08:00
										 |  |  |             Event::handle('EndActivityObjectOutputJson', array($this, &$object)); | 
					
						
							| 
									
										
										
										
											2011-02-17 22:36:14 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-02-16 16:21:46 -08:00
										 |  |  |         return array_filter($object); | 
					
						
							| 
									
										
										
										
											2011-02-15 20:25:39 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-04 17:00:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static function canonicalType($type) { | 
					
						
							|  |  |  |         $ns = 'http://activitystrea.ms/schema/1.0/'; | 
					
						
							|  |  |  |         if (substr($type, 0, mb_strlen($ns)) == $ns) { | 
					
						
							|  |  |  |             return substr($type, mb_strlen($ns)); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $type; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     static function mimeTypeToObjectType($mimeType) { | 
					
						
							|  |  |  |         $ot = null; | 
					
						
							| 
									
										
										
										
											2013-06-05 16:11:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Default
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (empty($mimeType)) { | 
					
						
							|  |  |  |             return self::FILE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 09:39:13 -04:00
										 |  |  |         $parts = explode('/', $mimeType); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         switch ($parts[0]) { | 
					
						
							|  |  |  |         case 'image': | 
					
						
							|  |  |  |             $ot = self::IMAGE; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 'audio': | 
					
						
							|  |  |  |             $ot = self::AUDIO; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         case 'video': | 
					
						
							|  |  |  |             $ot = self::VIDEO; | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |             $ot = self::FILE; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return $ot; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-20 16:06:22 -05:00
										 |  |  | } |