FavoriteModule.php 24 KB

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