]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TinyMCE/TinyMCEPlugin.php
f8d85c1ba03c78ee0cc08e93937a159e7b7dee3a
[quix0rs-gnu-social.git] / plugins / TinyMCE / TinyMCEPlugin.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
6  * Use TinyMCE library to allow rich text editing in the browser
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  WYSIWYG
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2010 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  * Use TinyMCE library to allow rich text editing in the browser
39  *
40  * Converts the notice form in browser to a rich-text editor.
41  *
42  * @category  WYSIWYG
43  * @package   StatusNet
44  * @author    Evan Prodromou <evan@status.net>
45  * @copyright 2010 StatusNet, Inc.
46  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
47  * @link      http://status.net/
48  */
49
50 class TinyMCEPlugin extends Plugin
51 {
52     var $html;
53
54     function onEndShowScripts($action)
55     {
56         if (common_logged_in()) {
57             $action->script(common_path('plugins/TinyMCE/js/jquery.tinymce.js'));
58             $action->inlineScript($this->_inlineScript());
59         }
60
61         return true;
62     }
63
64     function onEndShowStyles($action)
65     {
66         $action->style('span#notice_data-text_container { float: left }');
67         return true;
68     }
69
70     function onPluginVersion(&$versions)
71     {
72         $versions[] = array('name' => 'TinyMCE',
73                             'version' => STATUSNET_VERSION,
74                             'author' => 'Evan Prodromou',
75                             'homepage' => 'http://status.net/wiki/Plugin:TinyMCE',
76                             'rawdescription' =>
77                             _m('Use TinyMCE library to allow rich text editing in the browser'));
78         return true;
79     }
80
81     function onArgsInitialize(&$args)
82     {
83         if (!array_key_exists('action', $args) ||
84             $args['action'] != 'newnotice') {
85             return true;
86         }
87
88         $raw = $this->_scrub($args['status_textarea']);
89
90         require_once INSTALLDIR.'/extlib/htmLawed/htmLawed.php';
91
92         $config = array('safe' => 1,
93                         'deny_attribute' => 'id,style,on*');
94
95         $this->html = htmLawed($raw, $config);
96
97         $text = html_entity_decode(strip_tags($this->html));
98
99         $args['status_textarea'] = $text;
100
101         return true;
102     }
103
104     function onStartNoticeSave($notice)
105     {
106         if (!empty($this->html)) {
107             // Stomp on any rendering
108             $notice->rendered = $this->html;
109         }
110
111         return true;
112     }
113
114     function _inlineScript()
115     {
116         $path = common_path('plugins/TinyMCE/js/tiny_mce.js');
117
118         $scr = <<<END_OF_SCRIPT
119         $().ready(function() {
120             $('textarea#notice_data-text').tinymce({
121                 script_url : '{$path}',
122                 // General options
123                 theme : "simple",
124             });
125         });
126 END_OF_SCRIPT;
127
128         return $scr;
129     }
130
131     function _scrub($txt)
132     {
133         $strip = get_magic_quotes_gpc();
134         if ($strip) {
135             return stripslashes($txt);
136         } else {
137             return $txt;
138         }
139     }
140 }
141