XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
layout.admin.view.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class layoutAdminView extends layout
9 {
14  function init()
15  {
16  $this->setTemplatePath($this->module_path.'tpl');
17  }
18 
24  {
25  $type = Context::get('type');
26  $type = ($type != 'M') ? 'P' : 'M';
27 
28  // Set a layout list
29  $oLayoutModel = getModel('layout');
30  $layout_list = $oLayoutModel->getDownloadedLayoutList($type, true);
31  if(!is_array($layout_list))
32  {
33  $layout_list = array();
34  }
35 
36  if($type == 'P')
37  {
38  // get Theme layout
39  $oAdminModel = getAdminModel('admin');
40  $themeList = $oAdminModel->getThemeList();
41  $themeLayoutList = array();
42  foreach($themeList as $themeInfo)
43  {
44  if(strpos($themeInfo->layout_info->name, '.') === false) continue;
45  $themeLayoutList[] = $oLayoutModel->getLayoutInfo($themeInfo->layout_info->name, null, 'P');
46  }
47  $layout_list = array_merge($layout_list, $themeLayoutList);
48  $layout_list[] = $oLayoutModel->getLayoutInfo('faceoff', null, 'P');
49  }
50 
51  $pcLayoutCount = $oLayoutModel->getInstalledLayoutCount('P');
52  $mobileLayoutCount = $oLayoutModel->getInstalledLayoutCount('M');
53  Context::set('pcLayoutCount', $pcLayoutCount);
54  Context::set('mobileLayoutCount', $mobileLayoutCount);
55  $this->setTemplateFile('installed_layout_list');
56 
57  $security = new Security($layout_list);
58  $layout_list = $security->encodeHTML('..', '..author..');
59 
60  //Security
61  $security = new Security();
62  $security->encodeHTML('layout_list..layout','layout_list..title');
63 
64  foreach($layout_list as $no => $layout_info)
65  {
66  $layout_list[$no]->description = nl2br(trim($layout_info->description));
67  }
68  Context::set('layout_list', $layout_list);
69  }
70 
76  {
77  $type = Context::get('type');
78 
79  if(!in_array($type, array('P', 'M'))) $type = 'P';
80 
81  $oLayoutModel = getModel('layout');
82 
83  $pcLayoutCount = $oLayoutModel->getInstalledLayoutCount('P');
84  $mobileLayoutCount = $oLayoutModel->getInstalledLayoutCount('M');
85  Context::set('pcLayoutCount', $pcLayoutCount);
86  Context::set('mobileLayoutCount', $mobileLayoutCount);
87 
88  $columnList = array('layout_srl', 'layout', 'module_srl', 'title', 'regdate');
89  $_layout_list = $oLayoutModel->getLayoutInstanceList(0, $type, null, $columnList);
90 
91  $layout_list = array();
92  foreach($_layout_list as $item)
93  {
94  if(!$layout_list[$item->layout])
95  {
96  $layout_list[$item->layout] = array();
97  $layout_info = $oLayoutModel->getLayoutInfo($item->layout, null, $type);
98  if ($layout_info)
99  {
100  $layout_list[$item->layout]['title'] = $layout_info->title;
101  }
102  }
103 
104  $layout_list[$item->layout][] = $item;
105  }
106 
107  usort($layout_list, array($this, 'sortLayoutInstance'));
108 
109  Context::set('layout_list', $layout_list);
110 
111  $this->setTemplateFile('layout_all_instance_list');
112 
113  $security = new Security();
114  $security->encodeHTML('layout_list..');
115  }
116 
120  function sortLayoutInstance($a, $b)
121  {
122  $aTitle = strtolower($a['title']);
123  $bTitle = strtolower($b['title']);
124 
125  if($aTitle == $bTitle)
126  {
127  return 0;
128  }
129 
130  return ($aTitle < $bTitle) ? -1 : 1;
131  }
132 
138  {
139  $type = Context::get('type');
140  $layout = Context::get('layout');
141 
142  if(!in_array($type, array('P', 'M'))) $type = 'P';
143  if(!$layout) return $this->stop('msg_invalid_request');
144 
145  $oLayoutModel = getModel('layout');
146  $layout_info = $oLayoutModel->getLayoutInfo($layout, null, $type);
147  if(!$layout_info) return $this->stop('msg_invalid_request');
148 
149  Context::set('layout_info', $layout_info);
150 
151  $columnList = array('layout_srl', 'layout', 'module_srl', 'title', 'regdate');
152  $layout_list = $oLayoutModel->getLayoutInstanceList(0, $type, $layout, $columnList);
153  Context::set('layout_list', $layout_list);
154 
155  $this->setTemplateFile('layout_instance_list');
156 
157  $security = new Security();
158  $security->encodeHTML('layout_list..');
159  }
160 
167  {
168  $oModel = getModel('layout');
169  $type = Context::get('type');
170  if(!in_array($type, array('P', 'M'))) $type = 'P';
171 
172  //Security
173  $security = new Security();
174  $security->encodeHTML('layout_list..layout','layout_list..title');
175 
176  // Get layout info
177  $layout = Context::get('layout');
178  if($layout == 'faceoff') return $this->stop('not supported');
179 
180  $layout_info = $oModel->getLayoutInfo($layout, null, $type);
181  if(!$layout_info) return $this->stop('msg_invalid_request');
182 
183  // get Menu list
184  $oMenuAdminModel = getAdminModel('menu');
185  $menu_list = $oMenuAdminModel->getMenus();
186  Context::set('menu_list', $menu_list);
187 
188  $security = new Security();
189  $security->encodeHTML('menu_list..');
190 
191  $security = new Security($layout_info);
192  $layout_info = $security->encodeHTML('.', 'author..', 'extra_var..', 'extra_var....');
193 
194  $layout_info->description = nl2br(trim($layout_info->description));
195  if(!is_object($layout_info->extra_var)) $layout_info->extra_var = new StdClass();
196  foreach($layout_info->extra_var as $var_name => $val)
197  {
198  if(isset($layout_info->{$var_name}->description))
199  $layout_info->{$var_name}->description = nl2br(trim($val->description));
200  }
201  Context::set('selected_layout', $layout_info);
202 
203  $this->setTemplateFile('layout_modify');
204  }
205 
211  {
212  $oLayoutAdminModel = getAdminModel('layout');
213  $oLayoutAdminModel->setLayoutAdminSetInfoView();
214 
215  Context::set('is_sitemap', '0');
216  $script = '<script src="./modules/layout/tpl/js/layout_modify.js"></script>';
217  $oTemplate = &TemplateHandler::getInstance();
218  $content = $oTemplate->compile($this->module_path.'tpl/', 'layout_info_view');
219 
220  Context::set('content', $content);
221 
222  $this->setTemplateFile('layout_modify');
223  }
224 
230  {
231  // Set the layout with its information
232  $layout_srl = Context::get('layout_srl');
233  // Get layout information
234  $oLayoutModel = getModel('layout');
235  $layout_info = $oLayoutModel->getLayout($layout_srl);
236  // Error appears if there is no layout information is registered
237  if(!$layout_info) return $this->dispLayoutAdminInstalledList();
238 
239  // Get Layout Code
240  if($oLayoutModel->useDefaultLayout($layout_info->layout_srl))
241  {
242  $layout_file = $oLayoutModel->getDefaultLayoutHtml($layout_info->layout);
243  $layout_css_file = $oLayoutModel->getDefaultLayoutCss($layout_info->layout);
244  }
245  else
246  {
247  $layout_file = $oLayoutModel->getUserLayoutHtml($layout_info->layout_srl);
248  $layout_css_file = $oLayoutModel->getUserLayoutCss($layout_info->layout_srl);
249 
250  if(!file_exists($layout_file)) $layout_file = $layout_info->path . 'layout.html';
251  if(!file_exists($layout_css_file)) $layout_css_file = $layout_info->path . 'layout.css';
252  }
253 
254  if(file_exists($layout_css_file))
255  {
256  $layout_code_css = FileHandler::readFile($layout_css_file);
257  Context::set('layout_code_css', $layout_code_css);
258  }
259 
260  $layout_code = FileHandler::readFile($layout_file);
261  Context::set('layout_code', $layout_code);
262 
263  // set User Images
264  $layout_image_list = $oLayoutModel->getUserLayoutImageList($layout_info->layout_srl);
265  Context::set('layout_image_list', $layout_image_list);
266 
267  $layout_image_path = $oLayoutModel->getUserLayoutImagePath($layout_info->layout_srl);
268  Context::set('layout_image_path', $layout_image_path);
269  // Set widget list
270  $oWidgetModel = getModel('widget');
271  $widget_list = $oWidgetModel->getDownloadedWidgetList();
272  Context::set('widget_list', $widget_list);
273 
274  $this->setTemplateFile('layout_edit');
275 
276  $security = new Security($layout_info);
277  $layout_info = $security->encodeHTML('.', '.author..');
278  Context::set('selected_layout', $layout_info);
279 
280  //Security
281  $security = new Security();
282  $security->encodeHTML('layout_list..');
283  $security->encodeHTML('layout_list..author..');
284 
285  $security = new Security();
286  $security->encodeHTML('layout_code_css', 'layout_code', 'widget_list..title');
287  }
288 
294  {
295  $layout_srl = Context::get('layout_srl');
296  $code = Context::get('code');
297  $code_css = Context::get('code_css');
298  if(!$layout_srl || !$code) return new BaseObject(-1, 'msg_invalid_request');
299  // Get the layout information
300  $oLayoutModel = getModel('layout');
301  $layout_info = $oLayoutModel->getLayout($layout_srl);
302  if(!$layout_info) return new BaseObject(-1, 'msg_invalid_request');
303  // Separately handle the layout if its type is faceoff
304  if($layout_info && $layout_info->type == 'faceoff') $oLayoutModel->doActivateFaceOff($layout_info);
305  // Apply CSS directly
306  Context::addHtmlHeader("<style type=\"text/css\" charset=\"UTF-8\">".$code_css."</style>");
307  // Set names and values of extra_vars to $layout_info
308  if($layout_info->extra_var_count)
309  {
310  foreach($layout_info->extra_var as $var_id => $val)
311  {
312  $layout_info->{$var_id} = $val->value;
313  }
314  }
315  // menu in layout information becomes an argument for Context:: set
316  if($layout_info->menu_count)
317  {
318  foreach($layout_info->menu as $menu_id => $menu)
319  {
320  $menu->php_file = FileHandler::getRealPath($menu->php_file);
321  if(FileHandler::exists($menu->php_file)) include($menu->php_file);
322  Context::set($menu_id, $menu);
323  }
324  }
325 
326  Context::set('layout_info', $layout_info);
327  Context::set('content', Context::getLang('layout_preview_content'));
328  // Temporary save the codes
329  $edited_layout_file = sprintf('./files/cache/layout/tmp.tpl');
330  FileHandler::writeFile($edited_layout_file, $code);
331 
332  // Compile
333  $oTemplate = &TemplateHandler::getInstance();
334 
335  $layout_path = $layout_info->path;
336  $layout_file = 'layout';
337 
338  $layout_tpl = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file);
339  Context::set('layout','none');
340  // Convert widgets and others
342  Context::set('layout_tpl', $layout_tpl);
343  // Delete Temporary Files
344  FileHandler::removeFile($edited_layout_file);
345  $this->setTemplateFile('layout_preview');
346 
347  }
348 
355  {
356  // Get layout_srl
357  $current_module_info = Context::get('current_module_info');
358  $layout_srl = $current_module_info->layout_srl;
359  // Remove the remaining tmp files because of temporarily saving
360  // This part needs to be modified
361  $delete_tmp = Context::get('delete_tmp');
362  if($delete_tmp =='Y')
363  {
365  $oLayoutAdminController->deleteUserLayoutTempFile($layout_srl);
366  }
367 
368  $oLayoutModel = getModel('layout');
369  // layout file is used as a temp.
370  $oLayoutModel->setUseUserLayoutTemp();
371  // Apply CSS in inline style
372  $faceoffcss = $oLayoutModel->_getUserLayoutFaceOffCss($current_module_info->layout_srl);
373 
374  $css = FileHandler::readFile($faceoffcss);
375  $match = null;
376  preg_match_all('/([^\{]+)\{([^\}]*)\}/is',$css,$match);
377  for($i=0,$c=count($match[1]);$i<$c;$i++)
378  {
379  $name = trim($match[1][$i]);
380  $css = trim($match[2][$i]);
381  if(!$css) continue;
382  $css = str_replace('./images/',Context::getRequestUri().$oLayoutModel->getUserLayoutImagePath($layout_srl),$css);
383  $style[] .= sprintf('"%s":"%s"',$name,$css);
384  }
385 
386  if(count($style))
387  {
388  $script = '<script type="text/javascript"> var faceOffStyle = {'.implode(',',$style).'}; </script>';
389  Context::addHtmlHeader($script);
390  }
391 
392  $oTemplate = &TemplateHandler::getInstance();
393  Context::set('content', $oTemplate->compile($this->module_path.'tpl','about_faceoff'));
394  // Change widget codes in Javascript mode
395  $oWidgetController = getController('widget');
396  $oWidgetController->setWidgetCodeInJavascriptMode();
397  // Set a template file
398  $this->setTemplateFile('faceoff_layout_edit');
399  }
400 
406  {
407  $layoutSrl = Context::get('layout_srl');
408 
409  $oLayoutModel = getModel('layout');
410  $layout = $oLayoutModel->getLayout($layoutSrl);
411 
412  Context::set('layout', $layout);
413  $this->setTemplateFile('copy_layout');
414  }
415 }
416 /* End of file layout.admin.view.php */
417 /* Location: ./modules/layout/layout.admin.view.php */
setTemplateFile($filename)
getController($module_name)
Definition: func.inc.php:90
removeFile($filename)
addHtmlHeader($header)
$layout_srl
Definition: ko.install.php:186
set($key, $val, $set_to_get_vars=0)
writeFile($filename, $buff, $mode="w")
$oLayoutAdminController
Definition: ko.install.php:192
$oContext
Include the necessary configuration files.
Definition: index.php:45
getAdminModel($module_name)
Definition: func.inc.php:156
getRealPath($source)
getLang($code)
readFile($filename)
getRequestUri($ssl_mode=FOLLOW_REQUEST_SSL, $domain=null)
& getInstance()
getModel($module_name)
Definition: func.inc.php:145
getAdminController($module_name)
Definition: func.inc.php:101