-
Notifications
You must be signed in to change notification settings - Fork 2
/
ext.tinymce_communicate.php
81 lines (70 loc) · 2.27 KB
/
ext.tinymce_communicate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
if (!defined('EXT')) exit('Invalid file request');
class TinyMCE_Communicate
{
var $name = 'TinyMCE Communicate';
var $description = 'Adds TinyMCE WYSIWYG editing to ExpressionEngine\'s \'Communicate\' tab. (Requires LG TinyMce)';
var $version = '0.1';
var $docs_url = 'http://github.com/aaronrussell/ee-tinymce-communicate';
function __construct()
{
$this->settings = $this->_get_lg_settings();
}
function _get_lg_settings( $force_refresh = FALSE, $return_all = FALSE )
{
global $DB, $REGX, $PREFS;
$query = $DB->query("SELECT settings FROM exp_extensions WHERE enabled = 'y' AND class = 'Lg_tinymce' LIMIT 1");
$settings = $REGX->array_stripslashes(unserialize($query->row['settings']));
return $settings[$PREFS->ini('site_id')];
}
function activate_extension()
{
global $DB;
$settings = array();
$hooks[] = array(
'extension_id' => '',
'class' => __CLASS__,
'method' => 'show_full_control_panel_end',
'hook' => 'show_full_control_panel_end',
'settings' => serialize($settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y'
);
foreach($hooks as $hook)
{
$DB->query($DB->insert_string('exp_extensions', $hook));
}
}
function disable_extension()
{
global $DB;
$DB->query("DELETE FROM exp_extensions WHERE class = '" . __CLASS__ . "'");
}
function show_full_control_panel_end($html)
{
global $EXT;
$html = ($EXT->last_call !== FALSE) ? $EXT->last_call : $html;
if(isset($_GET['C']) && $_GET['C'] == 'communicate')
{
$replace = '<script type="text/javascript" src="' . trim($this->settings['script_path']) . '"></script>' . NL;
$settings_parts = implode("\n\t\t", preg_split("/(\r\n|\n|\r)/", trim($this->settings['script_config'])));
$replace .= '
<script type="text/javascript">
//<![CDATA[
tinyMCE.init({'.$settings_parts.'});
//]]>
</script>';
$html = str_replace('</head>', $replace.'</head>', $html);
$html = $this->str_replace_once("class='textarea'", "class='textarea lg_mceEditor'", $html);
}
return $html;
}
function str_replace_once($needle , $replace , $haystack)
{
$pos = strpos($haystack, $needle);
if ($pos === false) {return $haystack;}
return substr_replace($haystack, $replace, $pos, strlen($needle));
}
}
?>