FavoritePlugin.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. <?php
  2. /*
  3. * GNU Social - a federating social network
  4. * Copyright (C) 2014, Free Software Foundation, Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('GNUSOCIAL')) {
  20. exit(1);
  21. }
  22. /**
  23. * @package Favorite
  24. * @author Mikael Nordfeldth <mmn@hethane.se>
  25. * @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
  26. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  27. */
  28. defined('GNUSOCIAL') || die();
  29. class FavoritePlugin extends ActivityVerbHandlerPlugin
  30. {
  31. const PLUGIN_VERSION = '2.0.0';
  32. protected $email_notify_fave = 1;
  33. public function tag()
  34. {
  35. return 'favorite';
  36. }
  37. public function types()
  38. {
  39. return array();
  40. }
  41. public function verbs()
  42. {
  43. return array(ActivityVerb::FAVORITE, ActivityVerb::LIKE,
  44. ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE);
  45. }
  46. public function onCheckSchema()
  47. {
  48. $schema = Schema::get();
  49. $schema->ensureTable('fave', Fave::schemaDef());
  50. return true;
  51. }
  52. public function initialize()
  53. {
  54. common_config_set('email', 'notify_fave', $this->email_notify_fave);
  55. }
  56. public function onStartUpgrade()
  57. {
  58. // This is a migration feature that will make sure we move
  59. // certain User preferences to the Profile_prefs table.
  60. // Introduced after commit b5fd2a048fc621ea05d756caba17275ab3dd0af4
  61. // on Sun Jul 13 16:30:37 2014 +0200
  62. $user = new User();
  63. $user->whereAdd('emailnotifyfav IS NOT NULL');
  64. if ($user->find()) {
  65. printfnq("Detected old User table (emailnotifyfav IS NOT NULL). Moving 'emailnotifyfav' property to Profile_prefs...");
  66. // First we'll make sure Profile_prefs exists
  67. $schema = Schema::get();
  68. $schema->ensureTable('profile_prefs', Profile_prefs::schemaDef());
  69. // Make sure we have our own tables setup properly
  70. while ($user->fetch()) {
  71. $user->setPref('email', 'notify_fave', $user->emailnotifyfav);
  72. $orig = clone($user);
  73. $user->emailnotifyfav = 'null'; // flag this preference as migrated
  74. $user->update($orig);
  75. }
  76. printfnq("DONE.\n");
  77. }
  78. }
  79. public function onEndUpgrade()
  80. {
  81. printfnq("Ensuring all faves have a URI...");
  82. $fave = new Fave();
  83. $fave->whereAdd('uri IS NULL');
  84. if ($fave->find()) {
  85. while ($fave->fetch()) {
  86. try {
  87. $fave->decache();
  88. $fave->query(sprintf(
  89. 'UPDATE fave '.
  90. 'SET uri = "%s", '.
  91. ' modified = "%s" '.
  92. 'WHERE user_id = %d '.
  93. 'AND notice_id = %d',
  94. Fave::newUri($fave->getActor(), $fave->getTarget(), $fave->modified),
  95. common_sql_date(strtotime($fave->modified)),
  96. $fave->user_id,
  97. $fave->notice_id
  98. ));
  99. } catch (Exception $e) {
  100. common_log(LOG_ERR, "Error updating fave URI: " . $e->getMessage());
  101. }
  102. }
  103. }
  104. printfnq("DONE.\n");
  105. }
  106. public function onRouterInitialized(URLMapper $m)
  107. {
  108. // Web UI actions
  109. $m->connect(
  110. 'main/favor',
  111. ['action' => 'favor']
  112. );
  113. $m->connect(
  114. 'main/disfavor',
  115. ['action' => 'disfavor']
  116. );
  117. if (common_config('singleuser', 'enabled')) {
  118. $nickname = User::singleUserNickname();
  119. $m->connect(
  120. 'favorites',
  121. ['action' => 'showfavorites',
  122. 'nickname' => $nickname]
  123. );
  124. $m->connect(
  125. 'favoritesrss',
  126. ['action' => 'favoritesrss',
  127. 'nickname' => $nickname]
  128. );
  129. } else {
  130. $m->connect(
  131. 'favoritedrss',
  132. ['action' => 'favoritedrss']
  133. );
  134. $m->connect(
  135. 'favorited/',
  136. ['action' => 'favorited']
  137. );
  138. $m->connect(
  139. 'favorited',
  140. ['action' => 'favorited']
  141. );
  142. $m->connect(
  143. ':nickname/favorites',
  144. ['action' => 'showfavorites'],
  145. ['nickname' => Nickname::DISPLAY_FMT]
  146. );
  147. $m->connect(
  148. ':nickname/favorites/rss',
  149. ['action' => 'favoritesrss'],
  150. ['nickname' => Nickname::DISPLAY_FMT]
  151. );
  152. }
  153. // Favorites for API
  154. $m->connect(
  155. 'api/favorites/create.:format',
  156. ['action' => 'ApiFavoriteCreate'],
  157. ['format' => '(xml|json)']
  158. );
  159. $m->connect(
  160. 'api/favorites/destroy.:format',
  161. ['action' => 'ApiFavoriteDestroy'],
  162. ['format' => '(xml|json)']
  163. );
  164. $m->connect(
  165. 'api/favorites/list.:format',
  166. ['action' => 'ApiTimelineFavorites'],
  167. ['format' => '(xml|json|rss|atom|as)']
  168. );
  169. $m->connect(
  170. 'api/favorites/:id.:format',
  171. ['action' => 'ApiTimelineFavorites'],
  172. ['id' => Nickname::INPUT_FMT,
  173. 'format' => '(xml|json|rss|atom|as)']
  174. );
  175. $m->connect(
  176. 'api/favorites.:format',
  177. ['action' => 'ApiTimelineFavorites'],
  178. ['format' => '(xml|json|rss|atom|as)']
  179. );
  180. $m->connect(
  181. 'api/favorites/create/:id.:format',
  182. ['action' => 'ApiFavoriteCreate'],
  183. ['id' => '[0-9]+',
  184. 'format' => '(xml|json)']
  185. );
  186. $m->connect(
  187. 'api/favorites/destroy/:id.:format',
  188. ['action' => 'ApiFavoriteDestroy'],
  189. ['id' => '[0-9]+',
  190. 'format' => '(xml|json)']
  191. );
  192. // AtomPub API
  193. $m->connect(
  194. 'api/statusnet/app/favorites/:profile/:notice.atom',
  195. ['action' => 'AtomPubShowFavorite'],
  196. ['profile' => '[0-9]+',
  197. 'notice' => '[0-9]+']
  198. );
  199. $m->connect(
  200. 'api/statusnet/app/favorites/:profile.atom',
  201. ['action' => 'AtomPubFavoriteFeed'],
  202. ['profile' => '[0-9]+']
  203. );
  204. // Required for qvitter API
  205. $m->connect(
  206. 'api/statuses/favs/:id.:format',
  207. ['action' => 'ApiStatusesFavs'],
  208. ['id' => '[0-9]+',
  209. 'format' => '(xml|json)']
  210. );
  211. }
  212. // FIXME: Set this to abstract public in lib/activityhandlerplugin.php ddwhen all plugins have migrated!
  213. protected function saveObjectFromActivity(Activity $act, Notice $stored, array $options=array())
  214. {
  215. assert($this->isMyActivity($act));
  216. // We must have an objects[0] here because in isMyActivity we require the count to be == 1
  217. $actobj = $act->objects[0];
  218. $object = Fave::saveActivityObject($actobj, $stored);
  219. return $object;
  220. }
  221. // FIXME: Put this in lib/activityhandlerplugin.php when we're ready
  222. // with the other microapps/activityhandlers as well.
  223. // Also it should be StartNoticeAsActivity (with a prepped Activity, including ->context etc.)
  224. public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped=null)
  225. {
  226. if (!$this->isMyNotice($stored)) {
  227. return true;
  228. }
  229. $this->extendActivity($stored, $act, $scoped);
  230. return false;
  231. }
  232. public function extendActivity(Notice $stored, Activity $act, Profile $scoped=null)
  233. {
  234. Fave::extendActivity($stored, $act, $scoped);
  235. }
  236. public function activityObjectFromNotice(Notice $notice)
  237. {
  238. $fave = Fave::fromStored($notice);
  239. return $fave->asActivityObject();
  240. }
  241. public function deleteRelated(Notice $notice)
  242. {
  243. try {
  244. $fave = Fave::fromStored($notice);
  245. $fave->delete();
  246. } catch (NoResultException $e) {
  247. // Cool, no problem. We wanted to get rid of it anyway.
  248. }
  249. }
  250. // API stuff
  251. /**
  252. * Typically just used to fill out Twitter-compatible API status data.
  253. *
  254. * FIXME: Make all the calls before this end up with a Notice instead of ArrayWrapper please...
  255. */
  256. public function onNoticeSimpleStatusArray($notice, array &$status, Profile $scoped=null, array $args=array())
  257. {
  258. if ($scoped instanceof Profile) {
  259. $status['favorited'] = Fave::existsForProfile($notice, $scoped);
  260. } else {
  261. $status['favorited'] = false;
  262. }
  263. return true;
  264. }
  265. public function onTwitterUserArray(Profile $profile, array &$userdata, Profile $scoped=null, array $args=array())
  266. {
  267. $userdata['favourites_count'] = Fave::countByProfile($profile);
  268. }
  269. /**
  270. * Typically just used to fill out StatusNet specific data in API calls in the referenced $info array.
  271. */
  272. public function onStatusNetApiNoticeInfo(Notice $notice, array &$info, Profile $scoped=null, array $args=array())
  273. {
  274. if ($scoped instanceof Profile) {
  275. $info['favorite'] = Fave::existsForProfile($notice, $scoped) ? 'true' : 'false';
  276. }
  277. return true;
  278. }
  279. public function onNoticeDeleteRelated(Notice $notice)
  280. {
  281. parent::onNoticeDeleteRelated($notice);
  282. // The below algorithm is because we want to delete fave
  283. // activities on any notice which _has_ faves, and not as
  284. // in the parent function only ones that _are_ faves.
  285. $fave = new Fave();
  286. $fave->notice_id = $notice->id;
  287. if ($fave->find()) {
  288. while ($fave->fetch()) {
  289. $fave->delete();
  290. }
  291. }
  292. $fave->free();
  293. }
  294. public function onProfileDeleteRelated(Profile $profile, array &$related)
  295. {
  296. $fave = new Fave();
  297. $fave->user_id = $profile->id;
  298. $fave->delete(); // Will perform a DELETE matching "user_id = {$user->id}"
  299. $fave->free();
  300. Fave::blowCacheForProfileId($profile->id);
  301. return true;
  302. }
  303. public function onStartNoticeListPrefill(array &$notices, array $notice_ids, Profile $scoped=null)
  304. {
  305. // prefill array of objects, before pluginfication it was Notice::fillFaves($notices)
  306. Fave::fillFaves($notice_ids);
  307. // DB caching
  308. if ($scoped instanceof Profile) {
  309. Fave::pivotGet('notice_id', $notice_ids, array('user_id' => $scoped->id));
  310. }
  311. }
  312. /**
  313. * show the "favorite" form in the notice options element
  314. * FIXME: Don't let a NoticeListItemAdapter slip in here (or extend that from NoticeListItem)
  315. *
  316. * @return void
  317. */
  318. public function onStartShowNoticeOptionItems($nli)
  319. {
  320. if (Event::handle('StartShowFaveForm', array($nli))) {
  321. $scoped = Profile::current();
  322. if ($scoped instanceof Profile) {
  323. if (Fave::existsForProfile($nli->notice, $scoped)) {
  324. $disfavor = new DisfavorForm($nli->out, $nli->notice);
  325. $disfavor->show();
  326. } else {
  327. $favor = new FavorForm($nli->out, $nli->notice);
  328. $favor->show();
  329. }
  330. }
  331. Event::handle('EndShowFaveForm', array($nli));
  332. }
  333. }
  334. protected function showNoticeListItem(NoticeListItem $nli)
  335. {
  336. // pass
  337. }
  338. public function openNoticeListItemElement(NoticeListItem $nli)
  339. {
  340. // pass
  341. }
  342. public function closeNoticeListItemElement(NoticeListItem $nli)
  343. {
  344. // pass
  345. }
  346. public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
  347. {
  348. $fave = new Fave();
  349. $fave->user_id = $uas->getUser()->id;
  350. if (!empty($uas->after)) {
  351. $fave->whereAdd("modified > '" . common_sql_date($uas->after) . "'");
  352. }
  353. if ($fave->find()) {
  354. while ($fave->fetch()) {
  355. $objs[] = clone($fave);
  356. }
  357. }
  358. return true;
  359. }
  360. public function onEndShowThreadedNoticeTailItems(NoticeListItem $nli, Notice $notice, &$threadActive)
  361. {
  362. if ($nli instanceof ThreadedNoticeListSubItem) {
  363. // The sub-items are replies to a conversation, thus we use different HTML elements etc.
  364. $item = new ThreadedNoticeListInlineFavesItem($notice, $nli->out);
  365. } else {
  366. $item = new ThreadedNoticeListFavesItem($notice, $nli->out);
  367. }
  368. $threadActive = $item->show() || $threadActive;
  369. return true;
  370. }
  371. public function onEndFavorNotice(Profile $actor, Notice $target)
  372. {
  373. try {
  374. $notice_author = $target->getProfile();
  375. // Don't notify ourselves of our own favorite on our own notice,
  376. // or if it's a remote user (since we don't know their email addresses etc.)
  377. if ($notice_author->id == $actor->id || !$notice_author->isLocal()) {
  378. return true;
  379. }
  380. $local_user = $notice_author->getUser();
  381. mail_notify_fave($local_user, $actor, $target);
  382. } catch (Exception $e) {
  383. // Mm'kay, probably not a local user. Let's skip this favor notification.
  384. }
  385. }
  386. /**
  387. * EndInterpretCommand for FavoritePlugin will handle the 'fav' command
  388. * using the class FavCommand.
  389. *
  390. * @param string $cmd Command being run
  391. * @param string $arg Rest of the message (including address)
  392. * @param User $user User sending the message
  393. * @param Command &$result The resulting command object to be run.
  394. *
  395. * @return boolean hook value
  396. */
  397. public function onStartInterpretCommand($cmd, $arg, $user, &$result)
  398. {
  399. if ($result === false && $cmd == 'fav') {
  400. if (empty($arg)) {
  401. $result = null;
  402. } else {
  403. list($other, $extra) = CommandInterpreter::split_arg($arg);
  404. if (!empty($extra)) {
  405. $result = null;
  406. } else {
  407. $result = new FavCommand($user, $other);
  408. }
  409. }
  410. return false;
  411. }
  412. return true;
  413. }
  414. public function onHelpCommandMessages(HelpCommand $help, array &$commands)
  415. {
  416. // TRANS: Help message for IM/SMS command "fav <nickname>".
  417. $commands['fav <nickname>'] = _m('COMMANDHELP', "add user's last notice as a 'fave'");
  418. // TRANS: Help message for IM/SMS command "fav #<notice_id>".
  419. $commands['fav #<notice_id>'] = _m('COMMANDHELP', "add notice with the given id as a 'fave'");
  420. }
  421. /**
  422. * Are we allowed to perform a certain command over the API?
  423. */
  424. public function onCommandSupportedAPI(Command $cmd, &$supported)
  425. {
  426. $supported = $supported || $cmd instanceof FavCommand;
  427. }
  428. // Form stuff (settings etc.)
  429. public function onEndEmailFormData(Action $action, Profile $scoped)
  430. {
  431. $emailfave = $scoped->getConfigPref('email', 'notify_fave') ? 1 : 0;
  432. $action->elementStart('li');
  433. $action->checkbox(
  434. 'email-notify_fave',
  435. // TRANS: Checkbox label in e-mail preferences form.
  436. _('Send me email when someone adds my notice as a favorite.'),
  437. $emailfave
  438. );
  439. $action->elementEnd('li');
  440. return true;
  441. }
  442. public function onStartEmailSaveForm(Action $action, Profile $scoped)
  443. {
  444. $emailfave = $action->boolean('email-notify_fave');
  445. try {
  446. if ($emailfave == (bool) $scoped->getPref('email', 'notify_fave')) {
  447. // No need to update setting
  448. return true;
  449. }
  450. } catch (NoResultException $e) {
  451. // Apparently there's no previously stored setting, then continue to save it as it is now.
  452. }
  453. $scoped->setPref('email', 'notify_fave', $emailfave);
  454. return true;
  455. }
  456. // Layout stuff
  457. public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
  458. {
  459. $menu->out->menuItem(
  460. common_local_url('showfavorites', array('nickname' => $target->getNickname())),
  461. // TRANS: Menu item in personal group navigation menu.
  462. _m('MENU', 'Favorites'),
  463. // @todo i18n FIXME: Need to make this two messages.
  464. // TRANS: Menu item title in personal group navigation menu.
  465. // TRANS: %s is a username.
  466. sprintf(_('%s\'s favorite notices'), $target->getBestName()),
  467. $scoped instanceof Profile && $target->id === $scoped->id && $menu->actionName =='showfavorites',
  468. 'nav_timeline_favorites'
  469. );
  470. }
  471. public function onEndPublicGroupNav(Menu $menu)
  472. {
  473. if (!common_config('singleuser', 'enabled')) {
  474. // TRANS: Menu item in search group navigation panel.
  475. $menu->out->menuItem(
  476. common_local_url('favorited'),
  477. _m('MENU', 'Popular'),
  478. // TRANS: Menu item title in search group navigation panel.
  479. _('Popular notices'),
  480. $menu->actionName == 'favorited',
  481. 'nav_timeline_favorited'
  482. );
  483. }
  484. }
  485. public function onEndShowSections(Action $action)
  486. {
  487. if (!$action->isAction(array('all', 'public'))) {
  488. return true;
  489. }
  490. if (!common_config('performance', 'high')) {
  491. $section = new PopularNoticeSection($action, $action->getScoped());
  492. $section->show();
  493. }
  494. }
  495. protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  496. {
  497. return Fave::existsForProfile($target, $scoped)
  498. // TRANS: Page/dialog box title when a notice is marked as favorite already
  499. ? _m('TITLE', 'Unmark notice as favorite')
  500. // TRANS: Page/dialog box title when a notice is not marked as favorite
  501. : _m('TITLE', 'Mark notice as favorite');
  502. }
  503. protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  504. {
  505. if ($action->isPost()) {
  506. // The below tests are only for presenting to the user. POSTs which inflict
  507. // duplicate favorite entries are handled with AlreadyFulfilledException.
  508. return false;
  509. }
  510. $exists = Fave::existsForProfile($target, $scoped);
  511. $expected_verb = $exists ? ActivityVerb::UNFAVORITE : ActivityVerb::FAVORITE;
  512. switch (true) {
  513. case $exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
  514. case !$exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
  515. common_redirect(common_local_url(
  516. 'activityverb',
  517. array('id' => $target->getID(),
  518. 'verb' => ActivityUtils::resolveUri($expected_verb, true))
  519. ));
  520. break;
  521. default:
  522. // No need to redirect as we are on the correct action already.
  523. }
  524. return false;
  525. }
  526. protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  527. {
  528. switch (true) {
  529. case ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
  530. Fave::addNew($scoped, $target);
  531. break;
  532. case ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
  533. Fave::removeEntry($scoped, $target);
  534. break;
  535. default:
  536. throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.');
  537. }
  538. return false;
  539. }
  540. protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  541. {
  542. return Fave::existsForProfile($target, $scoped)
  543. ? new DisfavorForm($action, $target)
  544. : new FavorForm($action, $target);
  545. }
  546. public function onPluginVersion(array &$versions)
  547. {
  548. $versions[] = array('name' => 'Favorite',
  549. 'version' => self::PLUGIN_VERSION,
  550. 'author' => 'Mikael Nordfeldth',
  551. 'homepage' => 'http://gnu.io/',
  552. 'rawdescription' =>
  553. // TRANS: Plugin description.
  554. _m('Favorites (likes) using ActivityStreams.'));
  555. return true;
  556. }
  557. }
  558. /**
  559. * Notify a user that one of their notices has been chosen as a 'fave'
  560. *
  561. * @param User $rcpt The user whose notice was faved
  562. * @param Profile $sender The user who faved the notice
  563. * @param Notice $notice The notice that was faved
  564. *
  565. * @return void
  566. */
  567. function mail_notify_fave(User $rcpt, Profile $sender, Notice $notice)
  568. {
  569. if (!$rcpt->receivesEmailNotifications() || !$rcpt->getConfigPref('email', 'notify_fave')) {
  570. return;
  571. }
  572. // This test is actually "if the sender is sandboxed"
  573. if (!$sender->hasRight(Right::EMAILONFAVE)) {
  574. return;
  575. }
  576. if ($rcpt->hasBlocked($sender)) {
  577. // If the author has blocked us, don't spam them with a notification.
  578. return;
  579. }
  580. // We need the global mail.php for various mail related functions below.
  581. require_once INSTALLDIR.'/lib/mail.php';
  582. $bestname = $sender->getBestName();
  583. common_switch_locale($rcpt->language);
  584. // TRANS: Subject for favorite notification e-mail.
  585. // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
  586. $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $sender->getNickname());
  587. // TRANS: Body for favorite notification e-mail.
  588. // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
  589. // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
  590. // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
  591. // TRANS: %7$s is the adding user's nickname.
  592. $body = sprintf(
  593. _("%1\$s (@%7\$s) just added your notice from %2\$s".
  594. " as one of their favorites.\n\n" .
  595. "The URL of your notice is:\n\n" .
  596. "%3\$s\n\n" .
  597. "The text of your notice is:\n\n" .
  598. "%4\$s\n\n" .
  599. "You can see the list of %1\$s's favorites here:\n\n" .
  600. "%5\$s"),
  601. $bestname,
  602. common_exact_date($notice->created),
  603. common_local_url(
  604. 'shownotice',
  605. array('notice' => $notice->id)
  606. ),
  607. $notice->content,
  608. common_local_url(
  609. 'showfavorites',
  610. array('nickname' => $sender->getNickname())
  611. ),
  612. common_config('site', 'name'),
  613. $sender->getNickname()
  614. ) .
  615. mail_footer_block();
  616. $headers = _mail_prepare_headers('fave', $rcpt->getNickname(), $sender->getNickname());
  617. common_switch_locale();
  618. mail_to_user($rcpt, $subject, $body, $headers);
  619. }