function _fromAtomEntry($entry, $feed) { $pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM); if (!empty($pubEl)) { $this->time = strtotime($pubEl->textContent); } else { // XXX technically an error; being liberal. Good idea...? $updateEl = $this->_child($entry, self::UPDATED, self::ATOM); if (!empty($updateEl)) { $this->time = strtotime($updateEl->textContent); } else { $this->time = null; } } $this->link = ActivityUtils::getPermalink($entry); $verbEl = $this->_child($entry, self::VERB); if (!empty($verbEl)) { $this->verb = trim($verbEl->textContent); } else { $this->verb = ActivityVerb::POST; // XXX: do other implied stuff here } // get immediate object children $objectEls = ActivityUtils::children($entry, self::OBJECT, self::SPEC); if (count($objectEls) > 0) { foreach ($objectEls as $objectEl) { // Special case for embedded activities $objectType = ActivityUtils::childContent($objectEl, self::OBJECTTYPE, self::SPEC); if (!empty($objectType) && $objectType == ActivityObject::ACTIVITY) { $this->objects[] = new Activity($objectEl); } else { $this->objects[] = new ActivityObject($objectEl); } } } else { // XXX: really? $this->objects[] = new ActivityObject($entry); } $actorEl = $this->_child($entry, self::ACTOR); if (!empty($actorEl)) { // Standalone <activity:actor> elements are a holdover from older // versions of ActivityStreams. Newer feeds should have this data // integrated straight into <atom:author>. $this->actor = new ActivityObject($actorEl); // Cliqset has bad actor IDs (just nickname of user). We // work around it by getting the author data and using its // id instead if (!preg_match('/^\\w+:/', $this->actor->id)) { $authorEl = ActivityUtils::child($entry, 'author'); if (!empty($authorEl)) { $authorObj = new ActivityObject($authorEl); $this->actor->id = $authorObj->id; } } } else { if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) { // An <atom:author> in the entry overrides any author info on // the surrounding feed. $this->actor = new ActivityObject($authorEl); } else { if (!empty($feed) && ($subjectEl = $this->_child($feed, self::SUBJECT))) { // Feed subject is used for things like groups. // Should actually possibly not be interpreted as an actor...? $this->actor = new ActivityObject($subjectEl); } else { if (!empty($feed) && ($authorEl = $this->_child($feed, self::AUTHOR, self::ATOM))) { // If there's no <atom:author> on the entry, it's safe to assume // the containing feed's authorship info applies. $this->actor = new ActivityObject($authorEl); } } } } $contextEl = $this->_child($entry, self::CONTEXT); if (!empty($contextEl)) { $this->context = new ActivityContext($contextEl); } else { $this->context = new ActivityContext($entry); } $targetEl = $this->_child($entry, self::TARGET); if (!empty($targetEl)) { $this->target = new ActivityObject($targetEl); } elseif (ActivityUtils::compareTypes($this->verb, array(ActivityVerb::FAVORITE))) { // StatusNet didn't send a 'target' for their Favorite atom entries $this->target = clone $this->objects[0]; } $this->summary = ActivityUtils::childContent($entry, 'summary'); $this->id = ActivityUtils::childContent($entry, 'id'); $this->content = ActivityUtils::getContent($entry); $catEls = $entry->getElementsByTagNameNS(self::ATOM, 'category'); if ($catEls) { for ($i = 0; $i < $catEls->length; $i++) { $catEl = $catEls->item($i); $this->categories[] = new AtomCategory($catEl); } } foreach (ActivityUtils::getLinks($entry, 'enclosure') as $link) { $this->enclosures[] = $link->getAttribute('href'); } // From APP. Might be useful. $this->selfLink = ActivityUtils::getLink($entry, 'self', 'application/atom+xml'); $this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml'); }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // for older verions of gnu social: include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share')); $twitter_status['repeated_id'] = $repeated->id; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // add id to all attachments $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; // add data about thumbnails $thumb = $attachment->getThumbnail(); $large_thumb = $attachment->getThumbnail(1000, 3000, false); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($thumb->filename); $large_thumb_url = File_thumbnail::url($large_thumb->filename); } else { $thumb_url = $thumb->getUrl(); $large_thumb_url = $large_thumb->getUrl(); } $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } // this applies to older versions of gnu social, i think } catch (ServerException $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $thumb_url = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add the extra meta data to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]); } } } // quoted notices if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { $quoted_notice = false; // if this attachment has an url this might be a notice url if (isset($attachment['url'])) { $noticeurl = common_path('notice/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); // remove protocol for the comparison below $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl); $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl); $attachment_url_wo_protocol = preg_replace('(^https?://)', '', $attachment['url']); // local notice urls if (strpos($attachment_url_wo_protocol, $noticeurl_wo_protocol) === 0) { $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $attachment_url_wo_protocol); if (ctype_digit($possible_notice_id)) { $quoted_notice = Notice::getKV('id', $possible_notice_id); } } elseif (strpos($attachment_url_wo_protocol, $instanceurl_wo_protocol) !== 0 && stristr($attachment_url_wo_protocol, '/notice/')) { $quoted_notice = Notice::getKV('url', $attachment['url']); // try with http<->https if no match. applies to quitter.se notices mostly if (!$quoted_notice instanceof Notice) { if (strpos($attachment['url'], 'https://') === 0) { $quoted_notice = Notice::getKV('url', str_replace('https://', 'http://', $attachment['url'])); } else { $quoted_notice = Notice::getKV('url', str_replace('http://', 'https://', $attachment['url'])); } } } // include the quoted notice in the attachment if ($quoted_notice instanceof Notice) { $quoted_notice_author = Profile::getKV('id', $quoted_notice->profile_id); if ($quoted_notice_author instanceof Profile) { $attachment['quoted_notice']['id'] = $quoted_notice->id; $attachment['quoted_notice']['content'] = $quoted_notice->content; $attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname; $attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname; $quoted_notice_attachments = $quoted_notice->attachments(); foreach ($quoted_notice_attachments as $q_attach) { if (is_object($q_attach)) { try { $qthumb = $q_attach->getThumbnail(); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($qthumb->filename); } else { $thumb_url = $qthumb->getUrl(); } $attachment['quoted_notice']['attachments'][] = array('thumb_url' => $thumb_url, 'attachment_id' => $q_attach->id); } catch (Exception $e) { common_debug('Qvitter: could not get thumbnail for attachment id=' . $q_attach->id . ' in quoted notice id=' . $quoted_notice->id); } } } } } } } } try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { if ($repeats->verb == ActivityVerb::SHARE) { // i.e. not deleted repeats $repeatnum++; } } $twitter_status['repeat_num'] = $repeatnum; // is this a post? (previously is_activity) if (method_exists('ActivityUtils', 'compareVerbs')) { $twitter_status['is_post_verb'] = ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)); } else { $twitter_status['is_post_verb'] = $notice->verb == ActivityVerb::POST ? true : false; } // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($twitter_status['is_post_verb'] === true) { try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } } } if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) { $twitter_status['qvitter_delete_notice'] = true; } return true; }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // for older verions of gnu social: include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share')); $twitter_status['repeated_id'] = $repeated->id; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // add id to all attachments $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; // add data about thumbnails $thumb = $attachment->getThumbnail(); $large_thumb = $attachment->getThumbnail(1000, 3000, false); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($thumb->filename); $large_thumb_url = File_thumbnail::url($large_thumb->filename); } else { $thumb_url = $thumb->getUrl(); $large_thumb_url = $large_thumb->getUrl(); } $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } // this applies to older versions of gnu social, i think } catch (ServerException $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $thumb_url = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add the extra meta data to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]); } } } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { if ($repeats->verb == ActivityVerb::SHARE) { // i.e. not deleted repeats $repeatnum++; } } $twitter_status['repeat_num'] = $repeatnum; // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($notice->object_type != 'activity') { try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } } } if ($notice->source == 'activity' || $notice->object_type == 'activity' || $notice->object_type == 'http://activitystrea.ms/schema/1.0/activity' || $notice->verb == 'delete') { $twitter_status['is_activity'] = true; } else { $twitter_status['is_activity'] = false; } if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) { $twitter_status['qvitter_delete_notice'] = true; } return true; }
/** * Add stuff to notices in API responses * * @param Action $action action being executed * * @return boolean hook return */ function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped) { // groups $notice_groups = $notice->getGroups(); $group_addressees = false; foreach ($notice_groups as $g) { $group_addressees[] = array('nickname' => $g->nickname, 'url' => $g->mainpage); } $twitter_status['statusnet_in_groups'] = $group_addressees; // for older verions of gnu social: include the repeat-id, which we need when unrepeating later if (array_key_exists('repeated', $twitter_status) && $twitter_status['repeated'] === true) { $repeated = Notice::pkeyGet(array('profile_id' => $scoped->id, 'repeat_of' => $notice->id, 'verb' => 'http://activitystrea.ms/schema/1.0/share')); $twitter_status['repeated_id'] = $repeated->id; } // more metadata about attachments // get all attachments first, and put all the extra meta data in an array $attachments = $notice->attachments(); $attachment_url_to_id = array(); if (!empty($attachments)) { foreach ($attachments as $attachment) { if (is_object($attachment)) { try { $enclosure_o = $attachment->getEnclosure(); // Oembed if (array_key_exists('Oembed', StatusNet::getActivePlugins())) { $oembed = File_oembed::getKV('file_id', $attachment->id); if ($oembed instanceof File_oembed) { $oembed_html = str_replace('<!--//-->', '', $oembed->html); // trash left of wordpress' javascript after htmLawed removed the tags if ($oembed->provider == 'Twitter' && strstr($oembed_html, '>— ' . $oembed->author_name)) { $oembed_html = substr($oembed_html, 0, strpos($oembed_html, '>— ' . $oembed->author_name) + 1); // remove user data from twitter oembed html (we have it in ) $twitter_username = substr($oembed->html, strpos($oembed->html, '>— ' . $oembed->author_name) + strlen('>— ' . $oembed->author_name)); $twitter_username = substr($twitter_username, strpos($twitter_username, '(@') + 1); $twitter_username = substr($twitter_username, 0, strpos($twitter_username, ')')); $oembed->title = $twitter_username; } $oembed_html = str_replace('…', '...', $oembed_html); // ellipsis is sometimes stored as html in db, for some reason $oembed_html = mb_substr(trim(strip_tags(html_entity_decode($oembed_html, ENT_QUOTES))), 0, 250); // sometimes we have html charachters that we want to decode and then strip $oembed_title = trim(strip_tags(html_entity_decode($oembed->title, ENT_QUOTES))); $oembed_provider = trim(strip_tags(html_entity_decode($oembed->provider, ENT_QUOTES))); $oembed_author_name = trim(strip_tags(html_entity_decode($oembed->author_name, ENT_QUOTES))); $attachment_url_to_id[$enclosure_o->url]['oembed'] = array('type' => $oembed->type, 'provider' => $oembed_provider, 'provider_url' => $oembed->provider_url, 'oembedHTML' => $oembed_html, 'title' => $oembed_title, 'author_name' => $oembed_author_name, 'author_url' => $oembed->author_url); } else { $attachment_url_to_id[$enclosure_o->url]['oembed'] = false; } } // add id to all attachments $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; // add an attachment version to all attachments // this means we can force all cached attachments to update, if we change this $attachment_url_to_id[$enclosure_o->url]['version'] = '1.2'; // add data about thumbnails $thumb = $attachment->getThumbnail(); $large_thumb = $attachment->getThumbnail(1000, 3000, false); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($thumb->filename); $large_thumb_url = File_thumbnail::url($large_thumb->filename); } else { $thumb_url = $thumb->getUrl(); $large_thumb_url = $large_thumb->getUrl(); } $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $large_thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } // this applies to older versions of gnu social, i think } catch (Exception $e) { $thumb = File_thumbnail::getKV('file_id', $attachment->id); if ($thumb instanceof File_thumbnail) { $thumb_url = $thumb->getUrl(); $attachment_url_to_id[$enclosure_o->url]['id'] = $attachment->id; $attachment_url_to_id[$enclosure_o->url]['thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['large_thumb_url'] = $thumb_url; $attachment_url_to_id[$enclosure_o->url]['width'] = $attachment->width; $attachment_url_to_id[$enclosure_o->url]['height'] = $attachment->height; // animated gif? if ($attachment->mimetype == 'image/gif') { $image = ImageFile::fromFileObject($attachment); if ($image->animated == 1) { $attachment_url_to_id[$enclosure_o->url]['animated'] = true; } else { $attachment_url_to_id[$enclosure_o->url]['animated'] = false; } } } } } } } // add the extra meta data to $twitter_status if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { if (!empty($attachment_url_to_id[$attachment['url']])) { $attachment = array_merge($attachment, $attachment_url_to_id[$attachment['url']]); } } } // quoted notices if (!empty($twitter_status['attachments'])) { foreach ($twitter_status['attachments'] as &$attachment) { $quoted_notice = false; // if this attachment has an url this might be a notice url if (isset($attachment['url'])) { $noticeurl = common_path('notice/', StatusNet::isHTTPS()); $instanceurl = common_path('', StatusNet::isHTTPS()); // remove protocol for the comparison below $noticeurl_wo_protocol = preg_replace('(^https?://)', '', $noticeurl); $instanceurl_wo_protocol = preg_replace('(^https?://)', '', $instanceurl); $attachment_url_wo_protocol = preg_replace('(^https?://)', '', $attachment['url']); // local notice urls if (strpos($attachment_url_wo_protocol, $noticeurl_wo_protocol) === 0) { $possible_notice_id = str_replace($noticeurl_wo_protocol, '', $attachment_url_wo_protocol); if (ctype_digit($possible_notice_id)) { $quoted_notice = Notice::getKV('id', $possible_notice_id); } } elseif (strpos($attachment_url_wo_protocol, $instanceurl_wo_protocol) !== 0 && stristr($attachment_url_wo_protocol, '/notice/')) { $quoted_notice = Notice::getKV('url', $attachment['url']); // try with http<->https if no match. applies to quitter.se notices mostly if (!$quoted_notice instanceof Notice) { if (strpos($attachment['url'], 'https://') === 0) { $quoted_notice = Notice::getKV('url', str_replace('https://', 'http://', $attachment['url'])); } else { $quoted_notice = Notice::getKV('url', str_replace('http://', 'https://', $attachment['url'])); } } } // include the quoted notice in the attachment if ($quoted_notice instanceof Notice) { $quoted_notice_author = Profile::getKV('id', $quoted_notice->profile_id); if ($quoted_notice_author instanceof Profile) { $attachment['quoted_notice']['id'] = $quoted_notice->id; $attachment['quoted_notice']['content'] = $quoted_notice->content; $attachment['quoted_notice']['nickname'] = $quoted_notice_author->nickname; $attachment['quoted_notice']['fullname'] = $quoted_notice_author->fullname; $attachment['quoted_notice']['is_local'] = $quoted_notice_author->isLocal(); $quoted_notice_attachments = $quoted_notice->attachments(); foreach ($quoted_notice_attachments as $q_attach) { if (is_object($q_attach)) { try { $qthumb = $q_attach->getThumbnail(); if (method_exists('File_thumbnail', 'url')) { $thumb_url = File_thumbnail::url($qthumb->filename); } else { $thumb_url = $qthumb->getUrl(); } $attachment['quoted_notice']['attachments'][] = array('thumb_url' => $thumb_url, 'attachment_id' => $q_attach->id); } catch (Exception $e) { common_debug('Qvitter: could not get thumbnail for attachment id=' . $q_attach->id . ' in quoted notice id=' . $quoted_notice->id); } } } } } } } } try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } // reply-to profile url try { $reply = $notice->getParent(); $twitter_status['in_reply_to_profileurl'] = $reply->getProfile()->getUrl(); } catch (ServerException $e) { $twitter_status['in_reply_to_profileurl'] = null; } // fave number $faves = Fave::byNotice($notice); $favenum = count($faves); $twitter_status['fave_num'] = $favenum; // repeat number $repeats = $notice->repeatStream(); $repeatnum = 0; while ($repeats->fetch()) { if ($repeats->verb == ActivityVerb::SHARE) { // i.e. not deleted repeats $repeatnum++; } } $twitter_status['repeat_num'] = $repeatnum; // is this a post? (previously is_activity) if (method_exists('ActivityUtils', 'compareVerbs')) { $twitter_status['is_post_verb'] = ActivityUtils::compareVerbs($notice->verb, array(ActivityVerb::POST)); } else { $twitter_status['is_post_verb'] = $notice->verb == ActivityVerb::POST ? true : false; } // some more metadata about notice if ($notice->is_local == '1') { $twitter_status['is_local'] = true; } else { $twitter_status['is_local'] = false; if ($twitter_status['is_post_verb'] === true) { try { $twitter_status['external_url'] = $notice->getUrl(true); } catch (InvalidUrlException $e) { common_debug('Qvitter: No URL available for external notice: id=' . $notice->id); } } } if (ActivityUtils::compareTypes($notice->verb, array('qvitter-delete-notice', 'delete'))) { $twitter_status['qvitter_delete_notice'] = true; } return true; }
/** * Handle a posted object from Salmon * * @param Activity $activity activity to handle * @param mixed $target user or group targeted * * @return boolean hook value */ function onStartHandleSalmonTarget(Activity $activity, $target) { if (!$this->isMyActivity($activity)) { return true; } $this->log(LOG_INFO, "Checking {$activity->id} as a valid Salmon slap."); if ($target instanceof User_group || $target->isGroup()) { $uri = $target->getUri(); if (!array_key_exists($uri, $activity->context->attention)) { // @todo FIXME: please document (i18n). // TRANS: Client exception thrown when ... throw new ClientException(_('Object not posted to this group.')); } } elseif ($target instanceof Profile && $target->isLocal()) { $original = null; // FIXME: Shouldn't favorites show up with a 'target' activityobject? if (!ActivityUtils::compareTypes($activity->verb, array(ActivityVerb::POST)) && isset($activity->objects[0])) { // If this is not a post, it's a verb targeted at something (such as a Favorite attached to a note) if (!empty($activity->objects[0]->id)) { $activity->context->replyToID = $activity->objects[0]->id; } } if (!empty($activity->context->replyToID)) { $original = Notice::getKV('uri', $activity->context->replyToID); } if ((!$original instanceof Notice || $original->profile_id != $target->id) && !array_key_exists($target->getUri(), $activity->context->attention)) { // @todo FIXME: Please document (i18n). // TRANS: Client exception when ... throw new ClientException(_('Object not posted to this user.')); } } else { // TRANS: Server exception thrown when a micro app plugin uses a target that cannot be handled. throw new ServerException(_('Do not know how to handle this kind of target.')); } $oactor = Ostatus_profile::ensureActivityObjectProfile($activity->actor); $actor = $oactor->localProfile(); // FIXME: will this work in all cases? I made it work for Favorite... if (ActivityUtils::compareTypes($activity->verb, array(ActivityVerb::POST))) { $object = $activity->objects[0]; } else { $object = $activity; } $options = array('uri' => $object->id, 'url' => $object->link, 'is_local' => Notice::REMOTE, 'source' => 'ostatus'); if (!isset($this->oldSaveNew)) { $notice = Notice::saveActivity($activity, $actor, $options); } else { $notice = $this->saveNoticeFromActivity($activity, $actor, $options); } return false; }
function isMyType($type) { return count($this->types()) === 0 || ActivityUtils::compareTypes($type, $this->types()); }
protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped) { switch (true) { case ActivityUtils::compareTypes($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)): Fave::addNew($scoped, $target); break; case ActivityUtils::compareTypes($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)): Fave::removeEntry($scoped, $target); break; default: throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.'); } return false; }
public static function extendActivity(Notice $stored, Activity $act, Profile $scoped = null) { $target = self::getTargetFromStored($stored); // The following logic was copied from StatusNet's Activity plugin if (ActivityUtils::compareTypes($target->verb, array(ActivityVerb::POST))) { // "I like the thing you posted" $act->objects = $target->asActivity()->objects; } else { // "I like that you did whatever you did" $act->target = $target->asActivityObject(); $act->objects = array(clone $act->target); } $act->context->replyToID = $target->getUri(); $act->context->replyToUrl = $target->getUrl(); $act->title = ActivityUtils::verbToTitle($act->verb); }