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 * Returns a key string which represents this micro-app in HTML
66 * ids etc, as when offering selection of what type of post to make.
67 * This is paired with the user-visible localizable $this->appTitle().
69 * All micro-app classes must override this method.
71 abstract function tag();
74 * When building the primary notice form, we'll fetch also some
75 * alternate forms for specialized types -- that's you!
77 * Return a custom Widget or Form object for the given output
78 * object, and it'll be included in the HTML output. Beware that
79 * your form may be initially hidden.
81 * All micro-app classes must override this method.
83 * @param HTMLOutputter $out
86 abstract function entryForm($out);
91 public function newFormAction() {
92 // such as 'newbookmark' or 'newevent' route
93 return 'new'.$this->tag();
97 * Output the HTML for this kind of object in a list
99 * @param NoticeListItem $nli The list item being shown.
101 * @return boolean hook value
103 * @fixme WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation
105 function onStartShowNoticeItem($nli)
107 if (!$this->isMyNotice($nli->notice)) {
111 $adapter = $this->adaptNoticeListItem($nli);
113 if (!empty($adapter)) {
114 $adapter->showNotice();
115 $adapter->showNoticeAttachments();
116 $adapter->showNoticeInfo();
117 $adapter->showNoticeOptions();
119 $this->oldShowNotice($nli);
126 * Given a notice list item, returns an adapter specific
129 * @param NoticeListItem $nli item to adapt
131 * @return NoticeListItemAdapter adapter or null
133 function adaptNoticeListItem($nli)
138 function oldShowNotice($nli)
141 $notice = $nli->notice;
144 $this->showNotice($notice, $out);
145 } catch (Exception $e) {
146 common_log(LOG_ERR, $e->getMessage());
148 $out->elementStart('div');
153 $nli->showNoticeLink();
154 $nli->showNoticeSource();
155 $nli->showNoticeLocation();
159 $out->elementEnd('div');
161 $nli->showNoticeOptions();
164 function onStartShowEntryForms(&$tabs)
166 $tabs[$this->tag()] = array('title' => $this->appTitle(),
167 'href' => common_local_url($this->newFormAction()),
172 function onStartMakeEntryForm($tag, $out, &$form)
174 if ($tag == $this->tag()) {
175 $form = $this->entryForm($out);
182 function showNotice($notice, $out)
184 // TRANS: Server exception thrown when a micro app plugin developer has not done his job too well.
185 throw new ServerException(_('You must implement either adaptNoticeListItem() or showNotice().'));