FavoritePlugin.php 24 KB

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