microappplugin.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 StatusNet
  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. /**
  52. * Returns a localized string which represents this micro-app,
  53. * to be shown to users selecting what type of post to make.
  54. * This is paired with the key string in $this->tag().
  55. *
  56. * All micro-app classes must override this method.
  57. *
  58. * @return string
  59. */
  60. abstract function appTitle();
  61. /**
  62. * When building the primary notice form, we'll fetch also some
  63. * alternate forms for specialized types -- that's you!
  64. *
  65. * Return a custom Widget or Form object for the given output
  66. * object, and it'll be included in the HTML output. Beware that
  67. * your form may be initially hidden.
  68. *
  69. * All micro-app classes must override this method.
  70. *
  71. * @param HTMLOutputter $out
  72. * @return Widget
  73. */
  74. abstract function entryForm($out);
  75. /**
  76. *
  77. */
  78. public function newFormAction() {
  79. // such as 'newbookmark' or 'newevent' route
  80. return 'new'.$this->tag();
  81. }
  82. /**
  83. * Output the HTML for this kind of object in a list
  84. *
  85. * @param NoticeListItem $nli The list item being shown.
  86. *
  87. * @return boolean hook value
  88. */
  89. function onStartShowNoticeItem(NoticeListItem $nli)
  90. {
  91. if (!$this->isMyNotice($nli->notice)) {
  92. return true;
  93. }
  94. // Legacy use was creating a "NoticeListItemAdapter", but
  95. // nowadays we solve that using event handling for microapps.
  96. // This section will remain until all plugins are fixed.
  97. $adapter = $this->adaptNoticeListItem($nli) ?: $nli;
  98. $adapter->showNotice();
  99. $adapter->showNoticeAttachments();
  100. $adapter->showNoticeFooter();
  101. return false;
  102. }
  103. /**
  104. * Given a notice list item, returns an adapter specific
  105. * to this plugin.
  106. *
  107. * @param NoticeListItem $nli item to adapt
  108. *
  109. * @return NoticeListItemAdapter adapter or null
  110. */
  111. function adaptNoticeListItem($nli)
  112. {
  113. return null;
  114. }
  115. function onStartShowEntryForms(&$tabs)
  116. {
  117. $tabs[$this->tag()] = array('title' => $this->appTitle(),
  118. 'href' => common_local_url($this->newFormAction()),
  119. );
  120. return true;
  121. }
  122. function onStartMakeEntryForm($tag, $out, &$form)
  123. {
  124. if ($tag == $this->tag()) {
  125. $form = $this->entryForm($out);
  126. return false;
  127. }
  128. return true;
  129. }
  130. }