MicroAppPlugin.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2011, StatusNet, Inc.
  5. *
  6. * Superclass for microapp plugin
  7. *
  8. * PHP version 5
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * @category Microapp
  24. * @package StatusNet
  25. * @author Evan Prodromou <evan@status.net>
  26. * @copyright 2011 StatusNet, Inc.
  27. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  28. * @link http://status.net/
  29. */
  30. if (!defined('STATUSNET')) {
  31. // This check helps protect against security problems;
  32. // your code file can't be executed directly from the web.
  33. exit(1);
  34. }
  35. /**
  36. * Superclass for microapp plugins
  37. *
  38. * This class lets you define micro-applications with different kinds of activities.
  39. *
  40. * The applications work more-or-less like other
  41. *
  42. * @category Microapp
  43. * @package GNUsocial
  44. * @author Evan Prodromou <evan@status.net>
  45. * @copyright 2011 StatusNet, Inc.
  46. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  47. * @link http://status.net/
  48. */
  49. abstract class MicroAppPlugin extends ActivityHandlerPlugin
  50. {
  51. public $widgetOpts;
  52. public $scoped;
  53. /**
  54. * Returns a localized string which represents this micro-app,
  55. * to be shown to users selecting what type of post to make.
  56. * This is paired with the key string in $this->tag().
  57. *
  58. * All micro-app classes must override this method.
  59. *
  60. * @return string
  61. */
  62. abstract function appTitle();
  63. /**
  64. * When building the primary notice form, we'll fetch also some
  65. * alternate forms for specialized types -- that's you!
  66. *
  67. * Return a custom Widget or Form object for the given output
  68. * object, and it'll be included in the HTML output. Beware that
  69. * your form may be initially hidden.
  70. *
  71. * All micro-app classes must override this method.
  72. *
  73. * @param HTMLOutputter $out
  74. * @return Widget
  75. */
  76. abstract function entryForm($out);
  77. /**
  78. *
  79. */
  80. public function newFormAction() {
  81. // such as 'newbookmark' or 'newevent' route
  82. return 'new'.$this->tag();
  83. }
  84. /**
  85. * Output the HTML for this kind of object in a list
  86. *
  87. * @param NoticeListItem $nli The list item being shown.
  88. *
  89. * @return boolean hook value
  90. */
  91. function onStartShowNoticeItem(NoticeListItem $nli)
  92. {
  93. if (!$this->isMyNotice($nli->notice)) {
  94. return true;
  95. }
  96. // Legacy use was creating a "NoticeListItemAdapter", but
  97. // nowadays we solve that using event handling for microapps.
  98. // This section will remain until all plugins are fixed.
  99. $adapter = $this->adaptNoticeListItem($nli) ?: $nli;
  100. $adapter->showNotice();
  101. $adapter->showNoticeAttachments();
  102. $adapter->showNoticeFooter();
  103. return false;
  104. }
  105. /**
  106. * Given a notice list item, returns an adapter specific
  107. * to this plugin.
  108. *
  109. * @param NoticeListItem $nli item to adapt
  110. *
  111. * @return NoticeListItemAdapter adapter or null
  112. */
  113. function adaptNoticeListItem($nli)
  114. {
  115. return null;
  116. }
  117. function onStartShowEntryForms(&$tabs)
  118. {
  119. $tabs[$this->tag()] = array('title' => $this->appTitle(),
  120. 'href' => common_local_url($this->newFormAction()),
  121. );
  122. return true;
  123. }
  124. function onStartMakeEntryForm($tag, $out, &$form)
  125. {
  126. if ($tag == $this->tag()) {
  127. $form = $this->entryForm($out);
  128. return false;
  129. }
  130. return true;
  131. }
  132. }