ModPlusPlugin.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. if (!defined('STATUSNET')) {
  20. exit(1);
  21. }
  22. /**
  23. * Some UI extras for now...
  24. *
  25. * @package ModPlusPlugin
  26. * @maintainer Brion Vibber <brion@status.net>
  27. */
  28. class ModPlusPlugin extends Plugin
  29. {
  30. function onPluginVersion(&$versions)
  31. {
  32. $versions[] = array('name' => 'ModPlus',
  33. 'version' => GNUSOCIAL_VERSION,
  34. 'author' => 'Brion Vibber',
  35. 'homepage' => 'http://status.net/wiki/Plugin:ModPlus',
  36. 'rawdescription' =>
  37. // TRANS: Plugin description.
  38. _m('UI extension for profile moderation actions.'));
  39. return true;
  40. }
  41. /**
  42. * Load JS at runtime.
  43. *
  44. * @param Action $action
  45. * @return boolean hook result
  46. */
  47. function onEndShowScripts(Action $action)
  48. {
  49. $action->script($this->path('js/modplus.js'));
  50. return true;
  51. }
  52. public function onEndShowStylesheets(Action $action) {
  53. $action->cssLink($this->path('css/modplus.css'));
  54. return true;
  55. }
  56. /**
  57. * Add ModPlus-related paths to the router table
  58. *
  59. * Hook for RouterInitialized event.
  60. *
  61. * @param URLMapper $m URL mapper
  62. *
  63. * @return boolean hook return
  64. */
  65. public function onStartInitializeRouter(URLMapper $m)
  66. {
  67. $m->connect('user/remote/:id',
  68. array('action' => 'remoteprofile'),
  69. array('id' => '[\d]+'));
  70. return true;
  71. }
  72. /**
  73. * Add per-profile info popup menu for author on notice lists.
  74. *
  75. * @param NoticeListItem $item
  76. * @return boolean hook value
  77. */
  78. function onEndShowNoticeItemAuthor(Profile $profile, HTMLOutputter $out)
  79. {
  80. $this->showProfileOptions($out, $profile);
  81. return true;
  82. }
  83. /**
  84. * Add per-profile info popup menu on profile lists.
  85. *
  86. * @param ProfileListItem $item
  87. */
  88. function onStartProfileListItemProfile($item)
  89. {
  90. $this->showProfileOptions($item->out, $item->profile->getProfile());
  91. return true;
  92. }
  93. /**
  94. * Build common remote-profile options structure.
  95. * Currently only adds output for remote profiles, nothing for local users.
  96. *
  97. * @param HTMLOutputter $out
  98. * @param Profile $profile
  99. */
  100. protected function showProfileOptions(HTMLOutputter $out, Profile $profile)
  101. {
  102. if (!$profile->isGroup() && !$profile->isLocal()) {
  103. $target = common_local_url('remoteprofile', array('id' => $profile->id));
  104. // TRANS: Label for access to remote profile options.
  105. $label = _m('Remote profile options...');
  106. $out->elementStart('div', 'remote-profile-options');
  107. $out->element('a', array('href' => $target), $label);
  108. $out->elementEnd('div');
  109. }
  110. }
  111. }