本文整理汇总了PHP中Notice::getUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Notice::getUri方法的具体用法?PHP Notice::getUri怎么用?PHP Notice::getUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Notice
的用法示例。
在下文中一共展示了Notice::getUri方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: activityObjectFromNotice
public function activityObjectFromNotice(Notice $notice)
{
$object = new ActivityObject();
$object->type = $notice->object_type ?: ActivityObject::NOTE;
$object->id = $notice->getUri();
$object->title = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $notice->getProfile()->getNickname());
$object->content = $notice->getRendered();
$object->link = $notice->getUrl();
$object->extra[] = array('status_net', array('notice_id' => $notice->getID()));
return $object;
}
示例2: saveActivity
//.........这里部分代码省略.........
$conv = Conversation::create($act->context->conversation, $stored->created);
}
$stored->conversation = $conv->getID();
unset($conv);
}
}
// If it's not part of a conversation, it's the beginning of a new conversation.
if (empty($stored->conversation)) {
$conv = Conversation::create();
$stored->conversation = $conv->getID();
unset($conv);
}
$notloc = null;
if ($act->context instanceof ActivityContext) {
if ($act->context->location instanceof Location) {
$notloc = Notice_location::fromLocation($act->context->location);
}
} else {
$act->context = new ActivityContext();
}
$stored->scope = self::figureOutScope($actor, $groups, $scope);
foreach ($act->categories as $cat) {
if ($cat->term) {
$term = common_canonical_tag($cat->term);
if (!empty($term)) {
$tags[] = $term;
}
}
}
foreach ($act->enclosures as $href) {
// @todo FIXME: Save these locally or....?
$urls[] = $href;
}
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
if (empty($act->objects[0]->type)) {
// Default type for the post verb is 'note', but we know it's
// a 'comment' if it is in reply to something.
$stored->object_type = empty($stored->reply_to) ? ActivityObject::NOTE : ActivityObject::COMMENT;
} else {
//TODO: Is it safe to always return a relative URI? The
// JSON version of ActivityStreams always use it, so we
// should definitely be able to handle it...
$stored->object_type = ActivityUtils::resolveUri($act->objects[0]->type, true);
}
}
if (Event::handle('StartNoticeSave', array(&$stored))) {
// XXX: some of these functions write to the DB
try {
$result = $stored->insert();
// throws exception on error
if ($notloc instanceof Notice_location) {
$notloc->notice_id = $stored->getID();
$notloc->insert();
}
$orig = clone $stored;
// for updating later in this try clause
$object = null;
Event::handle('StoreActivityObject', array($act, $stored, $options, &$object));
if (empty($object)) {
throw new ServerException('Unsuccessful call to StoreActivityObject ' . $stored->getUri() . ': ' . $act->asString());
}
// If something changed in the Notice during StoreActivityObject
$stored->update($orig);
} catch (Exception $e) {
if (empty($stored->id)) {
common_debug('Failed to save stored object entry in database (' . $e->getMessage() . ')');
} else {
common_debug('Failed to store activity object in database (' . $e->getMessage() . '), deleting notice id ' . $stored->id);
$stored->delete();
}
throw $e;
}
}
if (!$stored instanceof Notice) {
throw new ServerException('StartNoticeSave did not give back a Notice');
}
// Only save 'attention' and metadata stuff (URLs, tags...) stuff if
// the activityverb is a POST (since stuff like repeat, favorite etc.
// reasonably handle notifications themselves.
if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
if (!empty($tags)) {
$stored->saveKnownTags($tags);
} else {
$stored->saveTags();
}
// Note: groups may save tags, so must be run after tags are saved
// to avoid errors on duplicates.
$stored->saveAttentions($act->context->attention);
if (!empty($urls)) {
$stored->saveKnownUrls($urls);
} else {
$stored->saveUrls();
}
}
if ($distribute) {
// Prepare inbox delivery, may be queued to background.
$stored->distribute();
}
return $stored;
}
示例3: onStartNoticeSave
/**
* This is run before ->insert, so our task in this function is just to
* delete if it is the delete verb.
*/
public function onStartNoticeSave(Notice $stored)
{
// DELETE is a bit special, we have to remove the existing entry and then
// add a new one with the same URI in order to trigger the distribution.
// (that's why we don't use $this->isMyNotice(...))
if (!ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::DELETE))) {
return true;
}
try {
$target = Notice::getByUri($stored->uri);
} catch (NoResultException $e) {
throw new AlreadyFulfilledException('Notice URI not found, so we have nothing to delete.');
}
$actor = $stored->getProfile();
$owner = $target->getProfile();
if ($owner->hasRole(Profile_role::DELETED)) {
// Don't bother with replacing notices if its author is being deleted.
// The later "StoreActivityObject" will pick this up and execute
// the deletion then.
// (the "delete verb notice" is too new to ever pass through Notice::saveNew
// which otherwise wouldn't execute the StoreActivityObject event)
return true;
}
// Since the user deleting may not be the same as the notice's owner,
// double-check this and also set the "re-stored" notice profile_id.
if (!$actor->sameAs($owner) && !$actor->hasRight(Right::DELETEOTHERSNOTICE)) {
throw new AuthorizationException(_('You are not allowed to delete another user\'s notice.'));
}
// We copy the identifying fields and replace the sensitive ones.
//$stored->id = $target->id; // We can't copy this since DB_DataObject won't inject it anyway
$props = array('uri', 'profile_id', 'conversation', 'reply_to', 'created', 'repeat_of', 'object_type', 'is_local', 'scope');
foreach ($props as $prop) {
$stored->{$prop} = $target->{$prop};
}
// Let's see if this has been deleted already.
try {
$deleted = Deleted_notice::getByKeys(['uri' => $stored->getUri()]);
return $deleted;
} catch (NoResultException $e) {
$deleted = new Deleted_notice();
$deleted->id = $target->getID();
$deleted->profile_id = $actor->getID();
$deleted->uri = $stored->getUri();
$deleted->act_created = $stored->created;
$deleted->created = common_sql_now();
// throws exception on error
$result = $deleted->insert();
}
// Now we delete the original notice, leaving the id and uri free.
$target->delete();
return true;
}
示例4: onEndNoticeAsActivity
public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped = null)
{
switch ($stored->verb) {
case ActivityVerb::UNFAVORITE:
// FIXME: do something here
break;
case ActivityVerb::JOIN:
$mem = Group_member::getKV('uri', $stored->getUri());
if ($mem instanceof Group_member) {
$group = $mem->getGroup();
$act->title = $stored->getTitle();
$act->objects = array(ActivityObject::fromGroup($group));
}
break;
case ActivityVerb::LEAVE:
// FIXME: ????
break;
case ActivityVerb::FOLLOW:
$sub = Subscription::getKV('uri', $stored->uri);
if ($sub instanceof Subscription) {
$profile = Profile::getKV('id', $sub->subscribed);
if ($profile instanceof Profile) {
$act->title = $stored->getTitle();
$act->objects = array($profile->asActivityObject());
}
}
break;
case ActivityVerb::UNFOLLOW:
// FIXME: ????
break;
}
return true;
}
示例5: extendActivity
public static function extendActivity(Notice $stored, Activity $act, Profile $scoped = null)
{
// the original notice id and type is still stored in the Notice table
// so we use that information to describe the delete activity
$act->target = new ActivityObject();
$act->target->id = $stored->getUri();
$act->target->type = $stored->getObjectType();
$act->objects = array(clone $act->target);
$act->title = ActivityUtils::verbToTitle($act->verb);
}
示例6: saveActivityObject
/**
* Store a Bookmark object
*
* @param Profile $profile To save the bookmark for
* @param string $title Title of the bookmark
* @param string $url URL of the bookmark
* @param string $description Description of the bookmark
*
* @return Bookmark the Bookmark object
*/
static function saveActivityObject(ActivityObject $actobj, Notice $stored)
{
$url = null;
// each extra element is array('tagname', array('attr'=>'val', ...), 'content')
foreach ($actobj->extra as $extra) {
if ($extra[1]['rel'] !== 'related') {
continue;
}
if ($url === null && strlen($extra[1]['href']) > 0) {
$url = $extra[1]['href'];
} elseif ($url !== null) {
// TRANS: Client exception thrown when a bookmark is formatted incorrectly.
throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
}
}
if (is_null($url)) {
// TRANS: Client exception thrown when a bookmark is formatted incorrectly.
throw new ClientException(sprintf(_m('Expected exactly 1 link rel=related in a Bookmark, got %1$d.'), count($relLinkEls)));
}
if (!strlen($actobj->title)) {
throw new ClientException(_m('You must provide a non-empty title.'));
}
if (!common_valid_http_url($url)) {
throw new ClientException(_m('Only web bookmarks can be posted (HTTP or HTTPS).'));
}
try {
$object = self::getByURL($stored->getProfile(), $url);
throw new ClientException(_m('You have already bookmarked this URL.'));
} catch (NoResultException $e) {
// Alright, so then we have to create it.
}
$nb = new Bookmark();
$nb->id = UUID::gen();
$nb->uri = $stored->getUri();
$nb->profile_id = $stored->getProfile()->getID();
$nb->title = $actobj->title;
$nb->url = $url;
$nb->description = $actobj->summary;
$nb->created = $stored->created;
$result = $nb->insert();
if ($result === false) {
throw new ServerException('Could not insert Bookmark into database!');
}
return $nb;
}