FavoriteModule.php 24 KB

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