]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EchoPlugin.php
Got photos displaying in the feed *the right way*
[quix0rs-gnu-social.git] / plugins / EchoPlugin.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Plugin to add Echo/JS-Kit commenting to notice pages
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Plugin
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Plugin to use Echo (formerly JS-Kit)
36  *
37  * This plugin adds an Echo commenting widget to each notice page on
38  * your site.  To get it to work, first you'll have to sign up for Echo
39  * (a commercial service) and register your site's URL.
40  *
41  *     http://aboutecho.com/
42  *
43  * Once you've done that it's pretty straight forward to turn the
44  * plugin on, just add:
45  *
46  *     addPlugin('Echo');
47  *
48  * to your config.php. The defaults should work OK with the default
49  * theme, but there are a lot of options to customize the look and
50  * feel of the comment widget. You can control both the CSS for the
51  * div that contains the widget, as well as the CSS for the widget
52  * itself via config parameters that can be passed into the plugin.
53  * See below for a more complex example:
54  *
55  * // Custom stylesheet for Echo commenting widget
56  * // See: http://wiki.js-kit.com/Skinning-Guide#UsingCSSnbsptocustomizefontsandcolors
57  * $stylesheet = <<<ENDOFCSS
58  * .js-CommentsArea { width: 400px; }
59  * .jsk-HeaderWrapper { display: none; }
60  * .jsk-ItemUserAvatar { display: none; }
61  * .jsk-ItemBody { margin-left: -48px; }
62  * .js-kit-avatars-wrapper { display: none; }
63  * .js-kit-nonLoggedUserInfo { margin-left: -75px; }
64  * .js-singleViaLinkWrapper { display: none; }
65  * .js-CommentsSkin-echo div.jsk-ThreadWrapper { padding: 0px; }
66  * .js-singleCommentAdminStar { display: none !important; }
67  * .js-singleCommentName { margin-right: 1em; }
68  * .js-kit-miniProfile { background-color:#FFFFFF; }
69  * .jskit-MenuContainer { background-color:#FFFFFF; }
70  * .jskit-MenuItemMO { background-color: #EDEDED; }
71  * .jsk-CommentFormButton { display: none; }
72  * .js-singleCommentReplyable { display: none; }
73  * .jsk-CommentFormSurface { display: none; }
74  * .js-kit-tab-follow { display: none; }
75  * ENDOFCSS;
76  *
77  * addPlugin(
78  *   'Echo',
79  *    array
80  *    (
81  *        // div_css is the css for the div containing the comment widget
82  *        'div_css' => 'width:675px; padding-top:10px; position:relative; float:left;',
83  *        // stylesheet is the CSS for the comment widget itself
84  *        'stylesheet' => $stylesheet
85  *    )
86  * );
87  *
88  * @category Plugin
89  * @package  StatusNet
90  * @author   Zach Copley <zach@status.net>
91  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
92  * @link     http://status.net/
93  *
94  * @see      Event
95  */
96
97 class EchoPlugin extends Plugin
98 {
99     // NOTE: The Echo documentation says that this script will change on
100     // a per site basis, but I think that's incorrect. It always seems to
101     // be the same.
102     public $script = 'http://cdn.js-kit.com/scripts/comments.js';
103
104     function onEndShowScripts($action)
105     {
106         if (get_class($action) == 'ShownoticeAction') {
107             $action->script($this->script);
108         }
109
110         return true;
111     }
112
113     function onEndShowContentBlock($action)
114     {
115         if (get_class($action) == 'ShownoticeAction') {
116
117             $attrs = array();
118             $attrs['class'] = 'js-kit-comments';
119             $attrs['permalink'] = $action->notice->uri;
120             $attrs['uniq'] = $action->notice->id;
121
122             // NOTE: there are some other attributes that could be useful
123             // http://wiki.js-kit.com/Echo-Behavior
124
125             if (empty($this->div_css)) {
126                 // This CSS seems to work OK with the default theme
127                 $attrs['style'] = 'width:675px; padding-top:10px; position:relative; float:left;';
128             } else {
129                 $attrs['style'] = $this->css;
130             }
131
132             $action->element('div', $attrs, null);
133         }
134     }
135
136     function onEndShowStyles($action)
137     {
138         if (get_class($action) == 'ShownoticeAction' && !empty($this->stylesheet)) {
139             $action->style($this->stylesheet);
140         }
141     }
142
143     function onPluginVersion(&$versions)
144     {
145         $versions[] = array('name' => 'Echo',
146                             'version' => STATUSNET_VERSION,
147                             'author' => 'Zach Copley',
148                             'homepage' => 'http://status.net/wiki/Plugin:Echo',
149                             'rawdescription' =>
150                             _m('Use <a href="http://aboutecho.com/">Echo</a>'.
151                                ' to add commenting to notice pages.'));
152         return true;
153     }
154 }