forked from TwistedInteractive/ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.driver.php
120 lines (101 loc) · 3.63 KB
/
extension.driver.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
require_once(TOOLKIT . '/class.sectionmanager.php');
Class extension_ckeditor extends Extension
{
/**
* Extension information
*/
public function about() {
return array(
'name' => 'Text Formatter: CKEditor',
'version' => '1.1',
'release-date' => '2010-11-15',
'author' => array(
'name' => '<a href="http://thecocoabots.com">Tony Arnold</a>, <a href="http://gielberkers.com">Giel Berkers</a>'
),
'description' => 'Includes CKEditor, a web-based XHTML editor developed by Frederico Knabben. It also has an integrated file browser which uses Symphony sections to get it\'s files from.'
);
}
/**
* Add callback functions to backend delegates
*/
public function getSubscribedDelegates(){
return array(
array('page' => '/backend/',
'delegate' => 'ModifyTextareaFieldPublishWidget',
'callback' => 'applyCKEditor'),
array('page' => '/backend/',
'delegate' => 'ModifyTextBoxFullFieldPublishWidget',
'callback' => 'applyCKEditor'),
array('page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPresets'),
array('page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'savePresets')
);
}
/**
* Append presets
*/
public function appendPresets($context)
{
$wrapper = $context['wrapper'];
$fieldset = new XMLElement('fieldset', '', array('class'=>'settings'));
$fieldset->appendChild(new XMLElement('legend', __('CKEditor File Browser')));
$fieldset->appendChild(new XMLElement('p', __('Please select the sections that are permitted to use the CKEditor file browser:')));
$sectionManager = new SectionManager($this);
$sections = $sectionManager->fetch();
// Check which sections are allowed:
$data = @file_get_contents(MANIFEST.'/ckeditor_sections');
$checkedSections = $data != false ? explode(',', $data) : array();
foreach($sections as $section)
{
$label = new XMLElement('label');
$attributes = array('type'=>'checkbox', 'name'=>'ckeditor_sections[]', 'value'=>$section->get('id'));
if(in_array($section->get('id'), $checkedSections)) {
$attributes['checked'] = 'checked';
}
$label->appendChild(new XMLElement('input', $section->get('name'), $attributes));
$fieldset->appendChild($label);
}
$wrapper->appendChild($fieldset);
}
/**
* Save the presets
*/
public function savePresets($context)
{
if(isset($_POST['ckeditor_sections'])) {
$sectionStr = implode(',', $_POST['ckeditor_sections']);
file_put_contents(MANIFEST.'/ckeditor_sections', $sectionStr);
} else {
// If no sections are selected, delete the file:
$this->uninstall();
}
}
/**
* On uninstall, delete the ckeditor_sections-file
*/
public function uninstall()
{
if(file_exists(MANIFEST.'/ckeditor_sections'))
{
unlink(MANIFEST.'/ckeditor_sections');
}
}
/**
* Load and apply CKEditor
*/
protected $addedCKEditorHeaders = false;
public function applyCKEditor($context) {
if($context['field']->get('formatter') != 'ckeditor') return;
if(!$this->addedCKEditorHeaders){
Administration::instance()->Page->addScriptToHead(URL . '/extensions/ckeditor/lib/ckeditor/ckeditor.js', 200, false);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/ckeditor/assets/symphony.ckeditor.js', 210, false);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/ckeditor/assets/symphony.ckeditor.css', 'screen', 30);
$this->addedCKEditorHeaders = true;
}
}
}
?>