1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: 17: 18: 19: 20: 21:
22: abstract class cWYSIWYGEditor {
23: 24: 25: 26:
27: protected static $_configPrefix = '[\'wysiwyg\']';
28:
29: 30: 31: 32:
33: protected $_sPath;
34:
35: 36: 37: 38:
39: protected $_sEditor;
40:
41: 42: 43: 44:
45: protected $_sEditorName;
46:
47: 48: 49: 50:
51: protected $_sEditorContent;
52:
53: 54: 55: 56:
57: protected $_aSettings;
58:
59: 60: 61: 62: 63: 64:
65: public function __construct($editorName, $editorContent) {
66: $cfg = cRegistry::getConfig();
67:
68: $this->_sPath = $cfg['path']['all_wysiwyg_html'];
69: $this->_setEditorName($editorName);
70: $this->_setEditorContent($editorContent);
71: }
72:
73: 74: 75: 76:
77: protected function _setEditorContent($sEditorContent) {
78: $this->_sEditorContent = $sEditorContent;
79: }
80:
81: 82: 83: 84:
85: protected function _setEditor($sEditor) {
86: global $cfg;
87:
88: if (is_dir($cfg['path']['all_wysiwyg'] . $sEditor)) {
89: if (cString::getPartOfString($sEditor, cString::getStringLength($sEditor) - 1, 1) != "/") {
90: $sEditor = $sEditor . "/";
91: }
92:
93: $this->_sEditor = $sEditor;
94: }
95: }
96:
97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
109: public function setSetting($type = null, $key, $value, $forceSetting = false) {
110: if ($forceSetting || !array_key_exists($key, $this->_aSettings)) {
111: $this->_aSettings[$key] = $value;
112: }
113: }
114:
115: 116: 117: 118:
119: protected function _unsetSetting($key) {
120: unset($this->_aSettings[$key]);
121: }
122:
123: 124: 125: 126:
127: protected function _getEditorPath() {
128: return $this->_sPath . $this->_sEditor;
129: }
130:
131: 132: 133: 134:
135: protected function _setEditorName($sEditorName) {
136: $this->_sEditorName = $sEditorName;
137: }
138:
139: 140: 141: 142: 143:
144: protected function getScripts() {
145: throw new cBadMethodCallException('You need to override the method _getScripts');
146: }
147:
148: 149: 150: 151: 152:
153: protected function getEditor() {
154: throw new cBadMethodCallException('You need to override the method _getEditor');
155: }
156:
157: 158: 159: 160: 161:
162: public static function getCurrentWysiwygEditorName() {
163:
164: define('DEFAULT_WYSIWYG_EDITOR', cRegistry::getConfigValue('wysiwyg', 'editor', 'tinymce3'));
165:
166: $curWysiwygEditor = getEffectiveSetting('wysiwyg', 'editor', constant('DEFAULT_WYSIWYG_EDITOR'));
167:
168:
169:
170: if (0 === cString::getStringLength($curWysiwygEditor)
171: || false === cFileHandler::exists(cRegistry::getConfigValue('path', 'all_wysiwyg') . $curWysiwygEditor)
172: || false !== cString::findFirstPos($curWysiwygEditor, '.')
173: || false !== cString::findFirstPos($curWysiwygEditor, '/')
174: || false !== cString::findFirstPos($curWysiwygEditor, '\\')) {
175: $curWysiwygEditor = constant('DEFAULT_WYSIWYG_EDITOR');
176: }
177:
178: return $curWysiwygEditor;
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193:
194: public static function saveConfig($config) {
195:
196:
197:
198: $configFile = 'config.wysiwyg_' . static::getCurrentWysiwygEditorName() . '.php';
199:
200:
201: $configPath = cRegistry::getConfigValue('path', 'contenido_config');
202:
203:
204: $filePrefix = '<?php ' . PHP_EOL;
205: $filePrefix .= "defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');\n";
206: $filePrefix .= 'global $cfg;' . PHP_EOL . PHP_EOL;
207:
208: $content = $filePrefix . '$cfg' . static::$_configPrefix . ' = ' . var_export($config, true) . ';' . PHP_EOL;
209:
210:
211: if (true !== cFileHandler::write($configPath . $configFile, $content)) {
212: $erroneousSettings = array();
213:
214:
215: $erroneusSettings['saving'] = array('config_file' => 'wysiwyg config file could not be written');
216:
217: error_log('Error writing ' . $configPath . $configFile);
218: return $erroneusSettings;
219: }
220:
221:
222: global $cfg;
223: $cfg['wysiwyg'][static::getCurrentWysiwygEditorName()] = $config;
224:
225: return array();
226: }
227: }
228: