XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
editor.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class editorController extends editor
9 {
13  function init()
14  {
15  }
16 
20  function procEditorSaveDoc()
21  {
22 
23  $this->deleteSavedDoc(false);
24 
25  $args = new stdClass;
26  $args->document_srl = Context::get('document_srl');
27  $args->content = Context::get('content');
28  $args->title = Context::get('title');
29  $output = $this->doSaveDoc($args);
30 
31  $this->setMessage('msg_auto_saved');
32  }
33 
38  {
39  $oEditorController = getController('editor');
40  $oEditorController->deleteSavedDoc(true);
41  }
42 
46  function procEditorCall()
47  {
48  $component = Context::get('component');
49  $method = Context::get('method');
50  if(!$component) return new BaseObject(-1, sprintf(Context::getLang('msg_component_is_not_founded'), $component));
51 
52  $oEditorModel = getModel('editor');
53  $oComponent = &$oEditorModel->getComponentObject($component);
54  if(!$oComponent->toBool()) return $oComponent;
55 
56  if(!method_exists($oComponent, $method)) return new BaseObject(-1, sprintf(Context::getLang('msg_component_is_not_founded'), $component));
57 
58  //$output = call_user_method($method, $oComponent);
59  //$output = call_user_func(array($oComponent, $method));
60  if(method_exists($oComponent, $method)) $output = $oComponent->{$method}();
61  else return new BaseObject(-1,sprintf('%s method is not exists', $method));
62 
63  if((is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject')) && !$output->toBool()) return $output;
64 
65  $this->setError($oComponent->getError());
66  $this->setMessage($oComponent->getMessage());
67 
68  $vars = $oComponent->getVariables();
69  if(count($vars))
70  {
71  foreach($vars as $key => $val)
72  {
73  $this->add($key, $val);
74  }
75  }
76  }
77 
82  {
83  $target_module_srl = Context::get('target_module_srl');
84  $target_module_srl = array_map('trim', explode(',', $target_module_srl));
85  $logged_info = Context::get('logged_info');
86  $module_srl = array();
87  $oModuleModel = getModel('module');
88 
89  foreach($target_module_srl as $srl)
90  {
91  if(!$srl) continue;
92 
93  $module_info = $oModuleModel->getModuleInfoByModuleSrl($srl);
94  if(!$module_info->module_srl)
95  {
96  return new BaseObject(-1, 'msg_invalid_request');
97  }
98 
99  $module_grant = $oModuleModel->getGrant($module_info, $logged_info);
100  if(!$module_grant->manager)
101  {
102  return new BaseObject(-1, 'msg_not_permitted');
103  }
104 
105  $module_srl[] = $srl;
106  }
107 
108  $editor_config = new stdClass;
109  $editor_config->editor_skin = Context::get('editor_skin');
110  $editor_config->comment_editor_skin = Context::get('comment_editor_skin');
111  $editor_config->content_style = Context::get('content_style');
112  $editor_config->comment_content_style = Context::get('comment_content_style');
113  $editor_config->content_font = Context::get('content_font');
114  if($editor_config->content_font)
115  {
116  $font_list = array();
117  $fonts = explode(',',$editor_config->content_font);
118  for($i=0,$c=count($fonts);$i<$c;$i++)
119  {
120  $font = trim(str_replace(array('"','\''),'',$fonts[$i]));
121  if(!$font) continue;
122  $font_list[] = $font;
123  }
124  if(count($font_list)) $editor_config->content_font = '"'.implode('","',$font_list).'"';
125  }
126  $editor_config->content_font_size = Context::get('content_font_size');
127  $editor_config->sel_editor_colorset = Context::get('sel_editor_colorset');
128  $editor_config->sel_comment_editor_colorset = Context::get('sel_comment_editor_colorset');
129 
130  $grants = array('enable_html_grant','enable_comment_html_grant','upload_file_grant','comment_upload_file_grant','enable_default_component_grant','enable_comment_default_component_grant','enable_component_grant','enable_comment_component_grant');
131 
132  foreach($grants as $key)
133  {
134  $grant = Context::get($key);
135  if(!$grant)
136  {
137  $editor_config->{$key} = array();
138  }
139  else if(is_array($grant))
140  {
141  $editor_config->{$key} = $grant;
142  }
143  else
144  {
145  $editor_config->{$key} = explode('|@|', $grant);
146  }
147  }
148 
149  $editor_config->editor_height = (int)Context::get('editor_height');
150  $editor_config->comment_editor_height = (int)Context::get('comment_editor_height');
151  $editor_config->enable_autosave = Context::get('enable_autosave');
152  if($editor_config->enable_autosave != 'Y') $editor_config->enable_autosave = 'N';
153 
154  $oModuleController = getController('module');
155  foreach($module_srl as $srl)
156  {
157  $oModuleController->insertModulePartConfig('editor', $srl, $editor_config);
158  }
159 
160  $this->setError(-1);
161  $this->setMessage('success_updated', 'info');
162 
163  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispBoardAdminContent');
164  $this->setRedirectUrl($returnUrl);
165  }
166 
170  function triggerEditorComponentCompile(&$content)
171  {
172  if(Context::getResponseMethod()!='HTML') return new BaseObject();
173 
174  $module_info = Context::get('module_info');
175  $module_srl = $module_info->module_srl;
176  if($module_srl)
177  {
178  $oEditorModel = getModel('editor');
179  $editor_config = $oEditorModel->getEditorConfig($module_srl);
180  $content_style = $editor_config->content_style;
181  if($content_style)
182  {
183  $path = _XE_PATH_ . 'modules/editor/styles/'.$content_style.'/';
184  if(is_dir($path) && file_exists($path . 'style.ini'))
185  {
186  $ini = file($path.'style.ini');
187  for($i = 0, $c = count($ini); $i < $c; $i++)
188  {
189  $file = trim($ini[$i]);
190  if(!$file) continue;
191 
192  if(substr_compare($file, '.css', -4) === 0)
193  {
194  Context::addCSSFile('./modules/editor/styles/'.$content_style.'/'.$file, false);
195  }
196  elseif(substr_compare($file, '.js', -3) === 0)
197  {
198  Context::addJsFile('./modules/editor/styles/'.$content_style.'/'.$file, false);
199  }
200  }
201  }
202  }
203  $content_font = $editor_config->content_font;
204  $content_font_size = $editor_config->content_font_size;
205  if($content_font || $content_font_size)
206  {
207  $buff = array();
208  $buff[] = '<style> .xe_content { ';
209  if($content_font) $buff[] = 'font-family:'.$content_font.';';
210  if($content_font_size) $buff[] = 'font-size:'.$content_font_size.';';
211  $buff[] = ' }</style>';
212  Context::addHtmlHeader(implode('', $buff));
213  }
214  }
215 
216  $content = $this->transComponent($content);
217  return new BaseObject();
218  }
219 
223  function transComponent($content)
224  {
225  $content = preg_replace_callback('!<(?:(div)|img)([^>]*)editor_component=([^>]*)>(?(1)(.*?)</div>)!is', array($this,'transEditorComponent'), $content);
226  return $content;
227  }
228 
232  function transEditorComponent($match)
233  {
234  $script = " {$match[2]} editor_component={$match[3]}";
235  $script = preg_replace('/([\w:-]+)\s*=(?:\s*(["\']))?((?(2).*?|[^ ]+))\2/i', '\1="\3"', $script);
236  preg_match_all('/([a-z0-9_-]+)="([^"]+)"/is', $script, $m);
237 
238  $xml_obj = new stdClass;
239  $xml_obj->attrs = new stdClass;
240  for($i=0,$c=count($m[0]);$i<$c;$i++)
241  {
242  if(!isset($xml_obj->attrs)) $xml_obj->attrs = new stdClass;
243  $xml_obj->attrs->{$m[1][$i]} = $m[2][$i];
244  }
245  $xml_obj->body = $match[4];
246 
247  if(!$xml_obj->attrs->editor_component) return $match[0];
248 
249  // Get converted codes by using component::transHTML()
250  $oEditorModel = getModel('editor');
251  $oComponent = &$oEditorModel->getComponentObject($xml_obj->attrs->editor_component, 0);
252  if(!is_object($oComponent)||!method_exists($oComponent, 'transHTML')) return $match[0];
253 
254  return $oComponent->transHTML($xml_obj);
255  }
256 
260  function doSaveDoc($args)
261  {
262  if(!$args->document_srl) $args->document_srl = $_SESSION['upload_info'][$editor_sequence]->upload_target_srl;
263 
264  // Get the current module if module_srl doesn't exist
265  if(!$args->module_srl) $args->module_srl = Context::get('module_srl');
266  if(!$args->module_srl)
267  {
268  $current_module_info = Context::get('current_module_info');
269  $args->module_srl = $current_module_info->module_srl;
270  }
271 
272  if(Context::get('is_logged'))
273  {
274  $logged_info = Context::get('logged_info');
275  $args->member_srl = $logged_info->member_srl;
276  }
277  else
278  {
279  $args->certify_key = $_COOKIE['autosave_certify_key_' . $args->module_srl];
280  if(!$args->certify_key) $args->certify_key = Password::createSecureSalt(40);
281  setcookie('autosave_certify_key_' . $args->module_srl, $args->certify_key, $_SERVER['REQUEST_TIME'] + 3600, '', '', false, true);
282  }
283 
284  return executeQuery('editor.insertSavedDoc', $args);
285  }
286 
291  {
292  $editor_sequence = Context::get('editor_sequence');
293  $primary_key = Context::get('primary_key');
294  $oEditorModel = getModel('editor');
295  $oFileController = getController('file');
296 
297  $saved_doc = $oEditorModel->getSavedDoc(null);
298 
299  $oFileController->setUploadInfo($editor_sequence, $saved_doc->document_srl);
300  $vars = $this->getVariables();
301  $this->add("editor_sequence", $editor_sequence);
302  $this->add("key", $primary_key);
303  $this->add("title", $saved_doc->title);
304  $this->add("content", $saved_doc->content);
305  $this->add("document_srl", $saved_doc->document_srl);
306  }
307 
312  {
313  $this->deleteSavedDoc(false);
314  return new BaseObject();
315  }
316 
321  function deleteSavedDoc($mode = false)
322  {
323  $args = new stdClass();
324  $args->module_srl = Context::get('module_srl');
325 
326  // Get the current module if module_srl doesn't exist
327  if(!$args->module_srl)
328  {
329  $current_module_info = Context::get('current_module_info');
330  $args->module_srl = $current_module_info->module_srl;
331  }
332  if(Context::get('is_logged'))
333  {
334  $logged_info = Context::get('logged_info');
335  $args->member_srl = $logged_info->member_srl;
336  }
337  else
338  {
339  $args->certify_key = $_COOKIE['autosave_certify_key_' . $args->module_srl];
340  // @see https://github.com/xpressengine/xe-core/issues/2208
341  // 변경 이전에 작성된 게시물 호환성 유지
342  if(!$args->certify_key) {
343  unset($args->certify_key);
344  $args->ipaddress = $_SERVER['REMOTE_ADDR'];
345  }
346  }
347  // Check if the auto-saved document already exists
348  $output = executeQuery('editor.getSavedDocument', $args);
349  $saved_doc = $output->data;
350  if(!$saved_doc) return;
351 
352  $oDocumentModel = getModel('document');
353  $oSaved = $oDocumentModel->getDocument($saved_doc->document_srl);
354  if(!$oSaved->isExists())
355  {
356  if($mode)
357  {
358  $output = executeQuery('editor.getSavedDocument', $args);
359  $output = ModuleHandler::triggerCall('editor.deleteSavedDoc', 'after', $saved_doc);
360  }
361  }
362 
363  $output = executeQuery('editor.deleteSavedDoc', $args);
364  return $output;
365  }
366 
370  function removeEditorConfig($site_srl)
371  {
372  $args->site_srl = $site_srl;
373  executeQuery('editor.deleteSiteComponent', $args);
374  }
375 
380  function makeCache($filter_enabled = true, $site_srl)
381  {
382  $oEditorModel = getModel('editor');
383  $args = new stdClass;
384 
385  if($filter_enabled) $args->enabled = "Y";
386 
387  if($site_srl)
388  {
389  $args->site_srl = $site_srl;
390  $output = executeQuery('editor.getSiteComponentList', $args);
391  }
392  else $output = executeQuery('editor.getComponentList', $args);
393  $db_list = $output->data;
394 
395  // Get a list of files
396  $downloaded_list = FileHandler::readDir(_XE_PATH_.'modules/editor/components');
397 
398  // Get information about log-in status and its group
399  $is_logged = Context::get('is_logged');
400  if($is_logged)
401  {
402  $logged_info = Context::get('logged_info');
403  if($logged_info->group_list && is_array($logged_info->group_list))
404  {
405  $group_list = array_keys($logged_info->group_list);
406  }
407  else $group_list = array();
408  }
409 
410  // Get xml information for looping DB list
411  if(!is_array($db_list)) $db_list = array($db_list);
412  $component_list = new stdClass();
413  foreach($db_list as $component)
414  {
415  if(in_array($component->component_name, array('colorpicker_text','colorpicker_bg'))) continue;
416 
417  $component_name = $component->component_name;
418  if(!$component_name) continue;
419 
420  if(!in_array($component_name, $downloaded_list)) continue;
421 
422  unset($xml_info);
423  $xml_info = $oEditorModel->getComponentXmlInfo($component_name);
424  $xml_info->enabled = $component->enabled;
425 
426  if($component->extra_vars)
427  {
428  $extra_vars = unserialize($component->extra_vars);
429  if($extra_vars->target_group)
430  {
431  $xml_info->target_group = $extra_vars->target_group;
432  }
433 
434  if($extra_vars->mid_list && count($extra_vars->mid_list))
435  {
436  $xml_info->mid_list = $extra_vars->mid_list;
437  }
438  /*
439  // Permisshin check if you are granted
440  if($extra_vars->target_group) {
441  // Stop using if not logged-in
442  if(!$is_logged) continue;
443  // Compare a target group with the current logged-in user group
444  $target_group = $extra_vars->target_group;
445  unset($extra_vars->target_group);
446 
447  $is_granted = false;
448  foreach($group_list as $group_srl) {
449  if(in_array($group_srl, $target_group)) {
450  $is_granted = true;
451  break;
452  }
453  }
454  if(!$is_granted) continue;
455  }
456  // Check if the target module exists
457  if($extra_vars->mid_list && count($extra_vars->mid_list) && Context::get('mid')) {
458  if(!in_array(Context::get('mid'), $extra_vars->mid_list)) continue;
459  }*/
460  // Check the configuration of the editor component
461  if($xml_info->extra_vars)
462  {
463  foreach($xml_info->extra_vars as $key => $val)
464  {
465  $xml_info->extra_vars->{$key}->value = $extra_vars->{$key};
466  }
467  }
468  }
469 
470  $component_list->{$component_name} = $xml_info;
471  // Get buttons, icons, images
472  $icon_file = _XE_PATH_.'modules/editor/components/'.$component_name.'/icon.gif';
473  $component_icon_file = _XE_PATH_.'modules/editor/components/'.$component_name.'/component_icon.gif';
474  if(file_exists($icon_file)) $component_list->{$component_name}->icon = true;
475  if(file_exists($component_icon_file)) $component_list->{$component_name}->component_icon = true;
476  }
477 
478  // Return if it checks enabled only
479  if(!$filter_enabled) {
480  // Get xml_info of downloaded list
481  foreach($downloaded_list as $component_name)
482  {
483  if(!is_dir(_XE_PATH_.'modules/editor/components/'.$component_name)) continue;
484  if(in_array($component_name, array('colorpicker_text','colorpicker_bg'))) continue;
485  // Pass if configured
486  if($component_list->{$component_name}) continue;
487  // Insert data into the DB
488  $oEditorController = getAdminController('editor');
489  $oEditorController->insertComponent($component_name, false, $site_srl);
490  // Add to component_list
491  unset($xml_info);
492  $xml_info = $oEditorModel->getComponentXmlInfo($component_name);
493  $xml_info->enabled = 'N';
494 
495  $component_list->{$component_name} = $xml_info;
496  }
497  }
498 
499  $oCacheHandler = CacheHandler::getInstance('object', null, true);
500  if($oCacheHandler->isSupport()) {
501  $cache_key = $oEditorModel->getComponentListCacheKey($filter_enabled, $site_srl);
502  $oCacheHandler->put($cache_key, $component_list);
503  }
504 
505  return $component_list;
506  }
507 
511  function removeCache($site_srl = 0)
512  {
513  $oEditorModel = getModel('editor');
514  FileHandler::removeFile($oEditorModel->getCacheFile(true, $site_srl));
515  FileHandler::removeFile($oEditorModel->getCacheFile(false, $site_srl));
516 
517  $oCacheHandler = CacheHandler::getInstance('object', null, true);
518  if($oCacheHandler->isSupport()) {
519  $cache_key = $oEditorModel->getComponentListCacheKey(true, $site_srl);
520  $oCacheHandler->delete($cache_key);
521  $cache_key = $oEditorModel->getComponentListCacheKey(false, $site_srl);
522  $oCacheHandler->delete($cache_key);
523  }
524  }
525 
527  {
528  $oModuleModel = getModel('module');
529  $editorConfig = $oModuleModel->getModulePartConfig('editor', $obj->originModuleSrl);
530 
531  $oModuleController = getController('module');
532  if(is_array($obj->moduleSrlList))
533  {
534  foreach($obj->moduleSrlList AS $key=>$moduleSrl)
535  {
536  $oModuleController->insertModulePartConfig('editor', $moduleSrl, $editorConfig);
537  }
538  }
539  }
540 }
541 /* End of file editor.controller.php */
542 /* Location: ./modules/editor/editor.controller.php */
$oModuleModel
Definition: ko.install.php:236
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
procEditorRemoveSavedDoc()
Delete autosaved documents.
procEditorSaveDoc()
AutoSave.
removeFile($filename)
init()
Initialization.
$obj
Definition: ko.install.php:262
removeCache($site_srl=0)
Delete cache files.
addHtmlHeader($header)
$output
Definition: ko.install.php:193
add($key, $val)
$module_info
Definition: ko.install.php:289
& getInstance($target= 'object', $info=null, $always_use_file=false)
transComponent($content)
Convert editor component codes to be returned.
makeCache($filter_enabled=true, $site_srl)
Caching a list of editor component (editorModel::getComponentList) For the editor component list...
foreach($sitemap as $id=> &$val) $extra_vars
Definition: ko.install.php:180
getNotEncodedUrl()
Definition: func.inc.php:316
deleteSavedDoc($mode=false)
Delete the auto-saved document Based on the current logged-in user.
procEditorCall()
Execute a method of the component when the component requests ajax.
triggerDeleteSavedDoc(&$obj)
A trigger to remove auto-saved document when inserting/updating the document.
transEditorComponent($match)
Convert editor component code of the contents.
setError($error=0)
triggerEditorComponentCompile(&$content)
convert editor component codes to be returned and specify content style.
$args
Definition: ko.install.php:185
addJsFile($file, $optimized=FALSE, $targetie= '', $index=0, $type= 'head', $isRuleset=FALSE, $autoPath=null)
addCSSFile($file, $optimized=FALSE, $media= 'all', $targetie= '', $index=0)
createSecureSalt($length, $format= 'hex')
Generate a cryptographically secure random string to use as a salt.
$oDocumentModel
Definition: ko.install.php:259
getLang($code)
const _XE_PATH_
Definition: config.inc.php:49
doSaveDoc($args)
AutoSave.
high class of the editor odule
Definition: editor.class.php:8
getModel($module_name)
Definition: func.inc.php:145
removeEditorConfig($site_srl)
ERemove editor component information used on the virtual site.
getAdminController($module_name)
Definition: func.inc.php:101
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
$module_srl
Definition: ko.install.php:254
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
procEditorLoadSavedDocument()
Load the srl of autosaved document - for those who uses XE older versions.
$oModuleController
Definition: ko.install.php:287
triggerCall($trigger_name, $called_position, &$obj)
procEditorInsertModuleConfig()
Save Editor&#39;s additional form for each module.