SlicedFavoritesPlugin.php 3.3 KB

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