]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/microappplugin.php
Opps, don't miss this here ...
[quix0rs-gnu-social.git] / lib / microappplugin.php
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
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Superclass for microapp plugins
39  *
40  * This class lets you define micro-applications with different kinds of activities.
41  *
42  * The applications work more-or-less like other
43  *
44  * @category  Microapp
45  * @package   StatusNet
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/
50  */
51 abstract class MicroAppPlugin extends ActivityHandlerPlugin
52 {
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     /**
65      * When building the primary notice form, we'll fetch also some
66      * alternate forms for specialized types -- that's you!
67      *
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.
71      *
72      * All micro-app classes must override this method.
73      *
74      * @param HTMLOutputter $out
75      * @return Widget
76      */
77     abstract function entryForm(Action $out);
78
79     /**
80      *
81      */
82     public function newFormAction() {
83         // such as 'newbookmark' or 'newevent' route
84         return 'new'.$this->tag();
85     }
86
87     /**
88      * Output the HTML for this kind of object in a list
89      *
90      * @param NoticeListItem $nli The list item being shown.
91      *
92      * @return boolean hook value
93      */
94     function onStartShowNoticeItem(NoticeListItem $nli)
95     {
96         if (!$this->isMyNotice($nli->notice)) {
97             return true;
98         }
99
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;
104
105         $adapter->showNotice();
106         $adapter->showNoticeAttachments();
107         $adapter->showNoticeFooter();
108
109         return false;
110     }
111
112     /**
113      * Given a notice list item, returns an adapter specific
114      * to this plugin.
115      *
116      * @param NoticeListItem $nli item to adapt
117      *
118      * @return NoticeListItemAdapter adapter or null
119      */
120     function adaptNoticeListItem(NoticeListItem $nli)
121     {
122       return null;
123     }
124
125     function onStartShowEntryForms(array &$tabs)
126     {
127         $tabs[$this->tag()] = array('title' => $this->appTitle(),
128                                     'href'  => common_local_url($this->newFormAction()),
129                                    );
130         return true;
131     }
132
133     function onStartMakeEntryForm($tag, Action $out, Form &$form)
134     {
135         if ($tag == $this->tag()) {
136             $form = $this->entryForm($out);
137             return false;
138         }
139
140         return true;
141     }
142 }