当前位置: 首页>>代码示例>>PHP>>正文


PHP Fave::addNew方法代码示例

本文整理汇总了PHP中Fave::addNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Fave::addNew方法的具体用法?PHP Fave::addNew怎么用?PHP Fave::addNew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Fave的用法示例。


在下文中一共展示了Fave::addNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $profile = AnonymousFavePlugin::getAnonProfile();
     if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
         // TRANS: Client error.
         $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.'));
     }
     $id = $this->trimmed('notice');
     $notice = Notice::getKV($id);
     $token = $this->checkSessionToken();
     // Throws exception
     $stored = Fave::addNew($profile, $notice);
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title.
         $this->element('title', null, _m('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new AnonDisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         $this->returnToPrevious();
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:35,代码来源:anonfavor.php

示例2: handle

 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     try {
         $fave = Fave::addNew($this->user->getProfile(), $notice);
     } catch (Exception $e) {
         $channel->error($this->user, $e->getMessage());
         return;
     }
     // TRANS: Text shown when a notice has been marked as favourite successfully.
     $channel->output($this->user, _('Notice marked as fave.'));
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:12,代码来源:favcommand.php

示例3: handle

 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     if ($user->hasFave($notice)) {
         // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
         $this->clientError(_('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($user->getProfile(), $notice);
     if (!$fave) {
         // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($notice, $user);
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Page title for page on which favorite notices can be unfavourited.
         $this->element('title', null, _('Disfavor favorite.'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new DisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)), 303);
     }
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:56,代码来源:favor.php

示例4: handle

 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $profile = AnonymousFavePlugin::getAnonProfile();
     if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
         // TRANS: Client error.
         $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.'));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (empty($token) || $token != common_session_token()) {
         // TRANS: Client error.
         $this->clientError(_m('There was a problem with your session token. Try again, please.'));
         return;
     }
     if ($profile->hasFave($notice)) {
         // TRANS: Client error.
         $this->clientError(_m('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($profile, $notice);
     if (!$fave) {
         // TRANS: Server error.
         $this->serverError(_m('Could not create favorite.'));
         return;
     }
     $profile->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title.
         $this->element('title', null, _m('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new AnonDisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         $this->returnToPrevious();
     }
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:51,代码来源:anonfavor.php

示例5: handle

 /**
  * Class handler.
  * 
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         $this->clientError(_("There was a problem with your session token. Try again, please."));
         return;
     }
     if ($user->hasFave($notice)) {
         $this->clientError(_('This notice is already a favorite!'));
         return;
     }
     $fave = Fave::addNew($user, $notice);
     if (!$fave) {
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($notice, $user);
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Disfavor favorite'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $disfavor = new DisFavorForm($this, $notice);
         $disfavor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:51,代码来源:favor.php

示例6: handle

 protected function handle()
 {
     parent::handle();
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
     }
     if (empty($this->notice)) {
         $this->clientError(_('No status found with that ID.'), 404, $this->format);
     }
     try {
         $stored = Fave::addNew($this->scoped, $this->notice);
     } catch (AlreadyFulfilledException $e) {
         // Note: Twitter lets you fave things repeatedly via API.
         $this->clientError($e->getMessage(), 403);
     }
     if ($this->format == 'xml') {
         $this->showSingleXmlStatus($this->notice);
     } elseif ($this->format == 'json') {
         $this->show_single_json_status($this->notice);
     }
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:21,代码来源:apifavoritecreate.php

示例7: execute

 function execute($channel)
 {
     $recipient = common_relative_profile($this->user, common_canonical_nickname($this->other));
     if (!$recipient) {
         $channel->error($this->user, _('No such user.'));
         return;
     }
     $notice = $recipient->getCurrentNotice();
     if (!$notice) {
         $channel->error($this->user, _('User has no last notice'));
         return;
     }
     $fave = Fave::addNew($this->user, $notice);
     if (!$fave) {
         $channel->error($this->user, _('Could not create favorite.'));
         return;
     }
     $other = User::staticGet('id', $recipient->id);
     if ($other && $other->id != $user->id) {
         if ($other->email && $other->emailnotifyfav) {
             mail_notify_fave($other, $this->user, $notice);
         }
     }
     $this->user->blowFavesCache();
     $channel->output($this->user, _('Notice marked as fave.'));
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:26,代码来源:command.php

示例8: doActionPost

 protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
 {
     switch (true) {
         case ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
             Fave::addNew($scoped, $target);
             break;
         case ActivityUtils::compareVerbs($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;
 }
开发者ID:bashrc,项目名称:gnusocial-debian,代码行数:14,代码来源:FavoritePlugin.php

示例9: handle

 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     $fave = Fave::addNew($this->user->getProfile(), $notice);
     if (!$fave) {
         $channel->error($this->user, _('Could not create favorite.'));
         return;
     }
     // @fixme favorite notification should be triggered
     // at a lower level
     $other = User::staticGet('id', $notice->profile_id);
     if ($other && $other->id != $user->id) {
         if ($other->email && $other->emailnotifyfav) {
             mail_notify_fave($other, $this->user, $notice);
         }
     }
     $this->user->blowFavesCache();
     $channel->output($this->user, _('Notice marked as fave.'));
 }
开发者ID:sukhjindersingh,项目名称:PHInest-Solutions,代码行数:19,代码来源:command.php

示例10: importNotice

 /**
  * Load or create an imported notice from Yammer data.
  *
  * @param object $item loaded JSON data for Yammer importer
  * @return Notice
  */
 function importNotice($item)
 {
     $data = $this->prepNotice($item);
     $noticeId = $this->findImportedNotice($data['orig_id']);
     if ($noticeId) {
         return Notice::staticGet('id', $noticeId);
     } else {
         $notice = Notice::staticGet('uri', $data['options']['uri']);
         $content = $data['content'];
         $user = User::staticGet($data['profile']);
         // Fetch file attachments and add the URLs...
         $uploads = array();
         foreach ($data['attachments'] as $url) {
             try {
                 $upload = $this->saveAttachment($url, $user);
                 $content .= ' ' . $upload->shortUrl();
                 $uploads[] = $upload;
             } catch (Exception $e) {
                 common_log(LOG_ERR, "Error importing Yammer attachment: " . $e->getMessage());
             }
         }
         // Here's the meat! Actually save the dang ol' notice.
         $notice = Notice::saveNew($user->id, $content, $data['source'], $data['options']);
         // Save "likes" as favorites...
         foreach ($data['faves'] as $nickname) {
             $user = User::staticGet('nickname', $nickname);
             if ($user) {
                 Fave::addNew($user->getProfile(), $notice);
             }
         }
         // And finally attach the upload records...
         foreach ($uploads as $upload) {
             $upload->attachToNotice($notice);
         }
         $this->recordImportedNotice($data['orig_id'], $notice->id);
         return $notice;
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:44,代码来源:yammerimporter.php

示例11: addFavorite

 /**
  * add a new favorite
  *
  * @return void
  */
 function addFavorite()
 {
     // XXX: Refactor this; all the same for atompub
     if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) {
         // TRANS: Client exception thrown when trying to set a favorite for another user.
         throw new ClientException(_("Cannot add someone else's" . " subscription."), 403);
     }
     $xml = file_get_contents('php://input');
     $dom = DOMDocument::loadXML($xml);
     if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') {
         // TRANS: Client error displayed when not using an Atom entry.
         throw new ClientException(_('Atom post must be an Atom entry.'));
         return;
     }
     $activity = new Activity($dom->documentElement);
     $fave = null;
     if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
         if ($activity->verb != ActivityVerb::FAVORITE) {
             // TRANS: Client exception thrown when trying use an incorrect activity verb for the Atom pub method.
             throw new ClientException(_('Can only handle favorite activities.'));
             return;
         }
         $note = $activity->objects[0];
         if (!in_array($note->type, array(ActivityObject::NOTE, ActivityObject::BLOGENTRY, ActivityObject::STATUS))) {
             // TRANS: Client exception thrown when trying favorite an object that is not a notice.
             throw new ClientException(_('Can only fave notices.'));
             return;
         }
         $notice = Notice::staticGet('uri', $note->id);
         if (empty($notice)) {
             // XXX: import from listed URL or something
             // TRANS: Client exception thrown when trying favorite a notice without content.
             throw new ClientException(_('Unknown note.'));
         }
         $old = Fave::pkeyGet(array('user_id' => $this->auth_user->id, 'notice_id' => $notice->id));
         if (!empty($old)) {
             // TRANS: Client exception thrown when trying favorite an already favorited notice.
             throw new ClientException(_('Already a favorite.'));
         }
         $profile = $this->auth_user->getProfile();
         $fave = Fave::addNew($profile, $notice);
         if (!empty($fave)) {
             $this->_profile->blowFavesCache();
             $this->notify($fave, $notice, $this->auth_user);
         }
         Event::handle('EndAtomPubNewActivity', array($activity, $fave));
     }
     if (!empty($fave)) {
         $act = $fave->asActivity();
         header('Content-Type: application/atom+xml; charset=utf-8');
         header('Content-Location: ' . $act->selfLink);
         $this->startXML();
         $this->raw($act->asString(true, true, true));
         $this->endXML();
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:61,代码来源:atompubfavoritefeed.php

示例12: handle

 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $this->format);
         return;
     }
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
         return;
     }
     if (empty($this->notice)) {
         $this->clientError(_('No status found with that ID.'), 404, $this->format);
         return;
     }
     // Note: Twitter lets you fave things repeatedly via API.
     if ($this->user->hasFave($this->notice)) {
         $this->clientError(_('This status is already a favorite.'), 403, $this->format);
         return;
     }
     $fave = Fave::addNew($this->user->getProfile(), $this->notice);
     if (empty($fave)) {
         $this->clientError(_('Could not create favorite.'), 403, $this->format);
         return;
     }
     $this->notify($fave, $this->notice, $this->user);
     $this->user->blowFavesCache();
     if ($this->format == 'xml') {
         $this->showSingleXmlStatus($this->notice);
     } elseif ($this->format == 'json') {
         $this->show_single_json_status($this->notice);
     }
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:42,代码来源:apifavoritecreate.php

示例13: handleFavorite

 /**
  * Remote user likes one of our posts.
  * Confirm the post is ours, and save a local favorite event.
  */
 function handleFavorite()
 {
     $notice = $this->getNotice($this->act->objects[0]);
     $profile = $this->ensureProfile()->localProfile();
     $old = Fave::pkeyGet(array('user_id' => $profile->id, 'notice_id' => $notice->id));
     if (!empty($old)) {
         throw new ClientException("We already know that's a fave!");
     }
     if (!Fave::addNew($profile, $notice)) {
         throw new ClientException("Could not save new favorite.");
     }
 }
开发者ID:himmelex,项目名称:NTW,代码行数:16,代码来源:usersalmon.php

示例14: create

 function create($args, $apidata)
 {
     parent::handle($args);
     // Check for RESTfulness
     if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
         // XXX: Twitter just prints the err msg, no XML / JSON.
         $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
         return;
     }
     if (!in_array($apidata['content-type'], array('xml', 'json'))) {
         $this->clientError(_('API method not found!'), $code = 404);
         return;
     }
     $this->auth_user = $apidata['user'];
     $user = $this->auth_user;
     $notice_id = $apidata['api_arg'];
     $notice = Notice::staticGet($notice_id);
     if (!$notice) {
         $this->clientError(_('No status found with that ID.'), 404, $apidata['content-type']);
         return;
     }
     // XXX: Twitter lets you fave things repeatedly via api.
     if ($user->hasFave($notice)) {
         $this->clientError(_('This notice is already a favorite!'), 403, $apidata['content-type']);
         return;
     }
     $fave = Fave::addNew($user, $notice);
     if (!$fave) {
         $this->serverError(_('Could not create favorite.'));
         return;
     }
     $this->notify($fave, $notice, $user);
     $user->blowFavesCache();
     if ($apidata['content-type'] == 'xml') {
         $this->show_single_xml_status($notice);
     } elseif ($apidata['content-type'] == 'json') {
         $this->show_single_json_status($notice);
     }
 }
开发者ID:Br3nda,项目名称:laconica,代码行数:39,代码来源:twitapifavorites.php

示例15: testNoticeInfoFave

 public function testNoticeInfoFave()
 {
     $notice = $this->_fakeNotice();
     $fave = Fave::addNew($this->author2->getProfile(), $notice);
     // Should be set if user has faved
     $entry = $notice->asAtomEntry(false, false, false, $this->author2);
     $element = $this->_entryToElement($entry, true);
     $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
     $this->assertEquals('true', $noticeInfo->getAttribute('favorite'));
     // Shouldn't be set if user has not faved
     $entry = $notice->asAtomEntry(false, false, false, $this->targetUser1);
     $element = $this->_entryToElement($entry, true);
     $noticeInfo = ActivityUtils::child($element, 'notice_info', "http://status.net/schema/api/1/");
     $this->assertEquals('false', $noticeInfo->getAttribute('favorite'));
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:15,代码来源:ActivityGenerationTests.php


注:本文中的Fave::addNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。