SlicedFavoritesPlugin.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, 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. /**
  20. * @package SlicedFavoritesPlugin
  21. * @maintainer Brion Vibber <brion@status.net>
  22. */
  23. if (!defined('STATUSNET')) { exit(1); }
  24. class SlicedFavoritesPlugin extends Plugin
  25. {
  26. const PLUGIN_VERSION = '2.0.0';
  27. /**
  28. * Example:
  29. *
  30. * addPlugin('SlicedFavorites', array(
  31. * 'slices' => array(
  32. * // show only pop's notices on /favorited
  33. * 'default' => array('include' => array('pop')),
  34. *
  35. * // show only son's notices on /favorited/blog
  36. * 'blog' => array('include' => array('son')),
  37. *
  38. * // show all favorited notices except pop's and son's on /favorited/submitted
  39. * 'submitted' => array('exclude' => array('pop', 'son')),
  40. *
  41. * // show all favorited notices on /favorited/everybody
  42. * 'everybody' => array(),
  43. * )
  44. * ));
  45. *
  46. * @var array
  47. */
  48. public $slices = array();
  49. /**
  50. * Hook for RouterInitialized event.
  51. *
  52. * @param URLMapper $m path-to-action mapper
  53. * @return boolean hook return
  54. */
  55. public function onRouterInitialized(URLMapper $m)
  56. {
  57. $m->connect('favorited/:slice',
  58. ['action' => 'favoritedslice'],
  59. ['slice' => '[a-zA-Z0-9]+']);
  60. return true;
  61. }
  62. // Take over the default... :D
  63. function onArgsInitialize($args)
  64. {
  65. if (array_key_exists('action', $args)) {
  66. $action = trim($args['action']);
  67. if ($action == 'favorited') {
  68. common_redirect(common_local_url('favoritedslice', array('slice' => 'default')));
  69. exit(0);
  70. }
  71. }
  72. return true;
  73. }
  74. function onSlicedFavoritesGetSettings($slice, &$data)
  75. {
  76. if (isset($this->slices[$slice])) {
  77. $data = $this->slices[$slice];
  78. return false;
  79. }
  80. return true;
  81. }
  82. /**
  83. * Provide plugin version information.
  84. *
  85. * This data is used when showing the version page.
  86. *
  87. * @param array &$versions array of version data arrays; see EVENTS.txt
  88. *
  89. * @return boolean hook value
  90. */
  91. public function onPluginVersion(array &$versions): bool
  92. {
  93. $url = GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/SlicedFavorites';
  94. $versions[] = array('name' => 'SlicedFavorites',
  95. 'version' => self::PLUGIN_VERSION,
  96. 'author' => 'Brion Vibber',
  97. 'homepage' => $url,
  98. 'rawdescription' =>
  99. // TRANS: Plugin description.
  100. _m('Shows timelines of popular notices for defined subsets of users.'));
  101. return true;
  102. }
  103. }