FavoriteModule.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. // Will perform a DELETE matching "user_id = {$user->id}"
  304. if ($fave->find()) {
  305. while ($fave->fetch()) {
  306. $fave->delete();
  307. }
  308. }
  309. $fave->free();
  310. Fave::blowCacheForProfileId($profile->id);
  311. return true;
  312. }
  313. public function onStartNoticeListPrefill(array &$notices, array $notice_ids, Profile $scoped=null)
  314. {
  315. // prefill array of objects, before pluginfication it was Notice::fillFaves($notices)
  316. Fave::fillFaves($notice_ids);
  317. // DB caching
  318. if ($scoped instanceof Profile) {
  319. Fave::pivotGet('notice_id', $notice_ids, array('user_id' => $scoped->id));
  320. }
  321. }
  322. /**
  323. * show the "favorite" form in the notice options element
  324. * FIXME: Don't let a NoticeListItemAdapter slip in here (or extend that from NoticeListItem)
  325. *
  326. * @return void
  327. */
  328. public function onStartShowNoticeOptionItems($nli)
  329. {
  330. if (Event::handle('StartShowFaveForm', array($nli))) {
  331. $scoped = Profile::current();
  332. if ($scoped instanceof Profile) {
  333. if (Fave::existsForProfile($nli->notice, $scoped)) {
  334. $disfavor = new DisfavorForm($nli->out, $nli->notice);
  335. $disfavor->show();
  336. } else {
  337. $favor = new FavorForm($nli->out, $nli->notice);
  338. $favor->show();
  339. }
  340. }
  341. Event::handle('EndShowFaveForm', array($nli));
  342. }
  343. }
  344. protected function showNoticeListItem(NoticeListItem $nli)
  345. {
  346. // pass
  347. }
  348. public function openNoticeListItemElement(NoticeListItem $nli)
  349. {
  350. // pass
  351. }
  352. public function closeNoticeListItemElement(NoticeListItem $nli)
  353. {
  354. // pass
  355. }
  356. public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
  357. {
  358. $fave = new Fave();
  359. $fave->user_id = $uas->getUser()->id;
  360. if (!empty($uas->after)) {
  361. $fave->whereAdd("modified > '" . common_sql_date($uas->after) . "'");
  362. }
  363. if ($fave->find()) {
  364. while ($fave->fetch()) {
  365. $objs[] = clone($fave);
  366. }
  367. }
  368. return true;
  369. }
  370. public function onEndShowThreadedNoticeTailItems(NoticeListItem $nli, Notice $notice, &$threadActive)
  371. {
  372. if ($nli instanceof ThreadedNoticeListSubItem) {
  373. // The sub-items are replies to a conversation, thus we use different HTML elements etc.
  374. $item = new ThreadedNoticeListInlineFavesItem($notice, $nli->out);
  375. } else {
  376. $item = new ThreadedNoticeListFavesItem($notice, $nli->out);
  377. }
  378. $threadActive = $item->show() || $threadActive;
  379. return true;
  380. }
  381. public function onEndFavorNotice(Profile $actor, Notice $target)
  382. {
  383. try {
  384. $notice_author = $target->getProfile();
  385. // Don't notify ourselves of our own favorite on our own notice,
  386. // or if it's a remote user (since we don't know their email addresses etc.)
  387. if ($notice_author->id == $actor->id || !$notice_author->isLocal()) {
  388. return true;
  389. }
  390. $local_user = $notice_author->getUser();
  391. mail_notify_fave($local_user, $actor, $target);
  392. } catch (Exception $e) {
  393. // Mm'kay, probably not a local user. Let's skip this favor notification.
  394. }
  395. }
  396. /**
  397. * EndInterpretCommand for FavoritePlugin will handle the 'fav' command
  398. * using the class FavCommand.
  399. *
  400. * @param string $cmd Command being run
  401. * @param string $arg Rest of the message (including address)
  402. * @param User $user User sending the message
  403. * @param Command &$result The resulting command object to be run.
  404. *
  405. * @return boolean hook value
  406. */
  407. public function onStartInterpretCommand($cmd, $arg, $user, &$result)
  408. {
  409. if ($result === false && $cmd == 'fav') {
  410. if (empty($arg)) {
  411. $result = null;
  412. } else {
  413. list($other, $extra) = CommandInterpreter::split_arg($arg);
  414. if (!empty($extra)) {
  415. $result = null;
  416. } else {
  417. $result = new FavCommand($user, $other);
  418. }
  419. }
  420. return false;
  421. }
  422. return true;
  423. }
  424. public function onHelpCommandMessages(HelpCommand $help, array &$commands)
  425. {
  426. // TRANS: Help message for IM/SMS command "fav <nickname>".
  427. $commands['fav <nickname>'] = _m('COMMANDHELP', "add user's last notice as a 'fave'");
  428. // TRANS: Help message for IM/SMS command "fav #<notice_id>".
  429. $commands['fav #<notice_id>'] = _m('COMMANDHELP', "add notice with the given id as a 'fave'");
  430. }
  431. /**
  432. * Are we allowed to perform a certain command over the API?
  433. */
  434. public function onCommandSupportedAPI(Command $cmd, &$supported)
  435. {
  436. $supported = $supported || $cmd instanceof FavCommand;
  437. }
  438. // Form stuff (settings etc.)
  439. public function onEndEmailFormData(Action $action, Profile $scoped)
  440. {
  441. $emailfave = $scoped->getConfigPref('email', 'notify_fave') ? 1 : 0;
  442. $action->elementStart('li');
  443. $action->checkbox(
  444. 'email-notify_fave',
  445. // TRANS: Checkbox label in e-mail preferences form.
  446. _('Send me email when someone adds my notice as a favorite.'),
  447. $emailfave
  448. );
  449. $action->elementEnd('li');
  450. return true;
  451. }
  452. public function onStartEmailSaveForm(Action $action, Profile $scoped)
  453. {
  454. $emailfave = $action->boolean('email-notify_fave');
  455. try {
  456. if ($emailfave == (bool) $scoped->getPref('email', 'notify_fave')) {
  457. // No need to update setting
  458. return true;
  459. }
  460. } catch (NoResultException $e) {
  461. // Apparently there's no previously stored setting, then continue to save it as it is now.
  462. }
  463. $scoped->setPref('email', 'notify_fave', $emailfave);
  464. return true;
  465. }
  466. // Layout stuff
  467. public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
  468. {
  469. $menu->out->menuItem(
  470. common_local_url('showfavorites', ['nickname' => $target->getNickname()]),
  471. // TRANS: Menu item in personal group navigation menu.
  472. _m('MENU', 'Favorites'),
  473. // @todo i18n FIXME: Need to make this two messages.
  474. // TRANS: Menu item title in personal group navigation menu.
  475. // TRANS: %s is a username.
  476. sprintf(_('%s\'s favorite notices'), $target->getBestName()),
  477. ($scoped instanceof Profile && $target->id === $scoped->id && $menu->actionName === 'showfavorites'),
  478. 'nav_timeline_favorites'
  479. );
  480. }
  481. public function onEndPublicGroupNav(Menu $menu)
  482. {
  483. if (!common_config('singleuser', 'enabled')) {
  484. // TRANS: Menu item in search group navigation panel.
  485. $menu->out->menuItem(
  486. common_local_url('favorited'),
  487. _m('MENU', 'Popular'),
  488. // TRANS: Menu item title in search group navigation panel.
  489. _('Popular notices'),
  490. ($menu->actionName === 'favorited'),
  491. 'nav_timeline_favorited'
  492. );
  493. }
  494. }
  495. public function onEndShowSections(Action $action)
  496. {
  497. if (!$action->isAction(array('all', 'public'))) {
  498. return true;
  499. }
  500. if (!common_config('performance', 'high')) {
  501. $section = new PopularNoticeSection($action, $action->getScoped());
  502. $section->show();
  503. }
  504. }
  505. protected function getActionTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  506. {
  507. return Fave::existsForProfile($target, $scoped)
  508. // TRANS: Page/dialog box title when a notice is marked as favorite already
  509. ? _m('TITLE', 'Unmark notice as favorite')
  510. // TRANS: Page/dialog box title when a notice is not marked as favorite
  511. : _m('TITLE', 'Mark notice as favorite');
  512. }
  513. protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  514. {
  515. if ($action->isPost()) {
  516. // The below tests are only for presenting to the user. POSTs which inflict
  517. // duplicate favorite entries are handled with AlreadyFulfilledException.
  518. return false;
  519. }
  520. $exists = Fave::existsForProfile($target, $scoped);
  521. $expected_verb = $exists ? ActivityVerb::UNFAVORITE : ActivityVerb::FAVORITE;
  522. switch (true) {
  523. case $exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
  524. case !$exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
  525. common_redirect(common_local_url(
  526. 'activityverb',
  527. [
  528. 'id' => $target->getID(),
  529. 'verb' => ActivityUtils::resolveUri($expected_verb, true),
  530. ]
  531. ));
  532. break;
  533. default:
  534. // No need to redirect as we are on the correct action already.
  535. }
  536. return false;
  537. }
  538. protected function doActionPost(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  539. {
  540. switch (true) {
  541. case ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
  542. Fave::addNew($scoped, $target);
  543. break;
  544. case ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
  545. Fave::removeEntry($scoped, $target);
  546. break;
  547. default:
  548. throw new ServerException('ActivityVerb POST not handled by plugin that was supposed to do it.');
  549. }
  550. return false;
  551. }
  552. protected function getActivityForm(ManagedAction $action, $verb, Notice $target, Profile $scoped)
  553. {
  554. return Fave::existsForProfile($target, $scoped)
  555. ? new DisfavorForm($action, $target)
  556. : new FavorForm($action, $target);
  557. }
  558. public function onModuleVersion(array &$versions): bool
  559. {
  560. $versions[] = array('name' => 'Favorite',
  561. 'version' => self::MODULE_VERSION,
  562. 'author' => 'Mikael Nordfeldth',
  563. 'homepage' => GNUSOCIAL_ENGINE_URL,
  564. 'rawdescription' =>
  565. // TRANS: Plugin description.
  566. _m('Favorites (likes) using ActivityStreams.'));
  567. return true;
  568. }
  569. }
  570. /**
  571. * Notify a user that one of their notices has been chosen as a 'fave'
  572. *
  573. * @param User $rcpt The user whose notice was faved
  574. * @param Profile $sender The user who faved the notice
  575. * @param Notice $notice The notice that was faved
  576. *
  577. * @return void
  578. */
  579. function mail_notify_fave(User $rcpt, Profile $sender, Notice $notice)
  580. {
  581. if (!$rcpt->receivesEmailNotifications() || !$rcpt->getConfigPref('email', 'notify_fave')) {
  582. return;
  583. }
  584. // This test is actually "if the sender is sandboxed"
  585. if (!$sender->hasRight(Right::EMAILONFAVE)) {
  586. return;
  587. }
  588. if ($rcpt->hasBlocked($sender)) {
  589. // If the author has blocked us, don't spam them with a notification.
  590. return;
  591. }
  592. // We need the global mail.php for various mail related functions below.
  593. require_once INSTALLDIR . '/lib/util/mail.php';
  594. $bestname = $sender->getBestName();
  595. common_switch_locale($rcpt->language);
  596. // TRANS: Subject for favorite notification e-mail.
  597. // TRANS: %1$s is the adding user's long name, %2$s is the adding user's nickname.
  598. $subject = sprintf(_('%1$s (@%2$s) added your notice as a favorite'), $bestname, $sender->getNickname());
  599. // TRANS: Body for favorite notification e-mail.
  600. // TRANS: %1$s is the adding user's long name, $2$s is the date the notice was created,
  601. // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
  602. // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
  603. // TRANS: %7$s is the adding user's nickname.
  604. $body = sprintf(
  605. _("%1\$s (@%7\$s) just added your notice from %2\$s".
  606. " as one of their favorites.\n\n" .
  607. "The URL of your notice is:\n\n" .
  608. "%3\$s\n\n" .
  609. "The text of your notice is:\n\n" .
  610. "%4\$s\n\n" .
  611. "You can see the list of %1\$s's favorites here:\n\n" .
  612. "%5\$s"),
  613. $bestname,
  614. common_exact_date($notice->created),
  615. common_local_url('shownotice', ['notice' => $notice->id]),
  616. $notice->content,
  617. common_local_url('showfavorites', ['nickname' => $sender->getNickname()]),
  618. common_config('site', 'name'),
  619. $sender->getNickname()
  620. ) .
  621. mail_footer_block();
  622. $headers = _mail_prepare_headers('fave', $rcpt->getNickname(), $sender->getNickname());
  623. common_switch_locale();
  624. mail_to_user($rcpt, $subject, $body, $headers);
  625. }