3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Superclass for microapp plugin
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.
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.
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/>.
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/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * Superclass for microapp plugins
40 * This class lets you define micro-applications with different kinds of activities.
42 * The applications work more-or-less like other
46 * @author Evan Prodromou <evan@status.net>
47 * @copyright 2011 StatusNet, Inc.
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
49 * @link http://status.net/
51 abstract class MicroAppPlugin extends ActivityHandlerPlugin
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().
58 * All micro-app classes must override this method.
62 abstract function appTitle();
65 * When building the primary notice form, we'll fetch also some
66 * alternate forms for specialized types -- that's you!
68 * Return a custom Widget or Form object for the given output
69 * object, and it'll be included in the HTML output. Beware that
70 * your form may be initially hidden.
72 * All micro-app classes must override this method.
74 * @param HTMLOutputter $out
77 abstract function entryForm($out);
82 public function newFormAction() {
83 // such as 'newbookmark' or 'newevent' route
84 return 'new'.$this->tag();
88 * Output the HTML for this kind of object in a list
90 * @param NoticeListItem $nli The list item being shown.
92 * @return boolean hook value
94 function onStartShowNoticeItem(NoticeListItem $nli)
96 if (!$this->isMyNotice($nli->notice)) {
100 // Legacy use was creating a "NoticeListItemAdapter", but
101 // nowadays we solve that using event handling for microapps.
102 // This section will remain until all plugins are fixed.
103 $adapter = $this->adaptNoticeListItem($nli) ?: $nli;
105 $adapter->showNotice();
106 $adapter->showNoticeAttachments();
107 $adapter->showNoticeFooter();
113 * Given a notice list item, returns an adapter specific
116 * @param NoticeListItem $nli item to adapt
118 * @return NoticeListItemAdapter adapter or null
120 function adaptNoticeListItem($nli)
125 function onStartShowEntryForms(&$tabs)
127 $tabs[$this->tag()] = array('title' => $this->appTitle(),
128 'href' => common_local_url($this->newFormAction()),
133 function onStartMakeEntryForm($tag, $out, &$form)
135 if ($tag == $this->tag()) {
136 $form = $this->entryForm($out);