XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
layout.model.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 class layoutModel extends layout
10 {
15  var $useUserLayoutTemp = null;
16 
21  function init()
22  {
23  }
24 
34  function getLayoutList($site_srl = 0, $layout_type="P", $columnList = array())
35  {
36  if(!$site_srl)
37  {
38  $site_module_info = Context::get('site_module_info');
39  $site_srl = (int)$site_module_info->site_srl;
40  }
41  $args = new stdClass();
42  $args->site_srl = $site_srl;
43  $args->layout_type = $layout_type;
44  $output = executeQueryArray('layout.getLayoutList', $args, $columnList);
45 
46  foreach($output->data as $no => &$val)
47  {
48  if(!$this->isExistsLayoutFile($val->layout, $layout_type))
49  {
50  unset($output->data[$no]);
51  }
52  }
53 
54  $oLayoutAdminModel = getAdminModel('layout');
55  $siteDefaultLayoutSrl = $oLayoutAdminModel->getSiteDefaultLayout($layout_type, $site_srl);
56  if($siteDefaultLayoutSrl)
57  {
58  $siteDefaultLayoutInfo = $this->getlayout($siteDefaultLayoutSrl);
59  $newLayout = sprintf('%s, %s', $siteDefaultLayoutInfo->title, $siteDefaultLayoutInfo->layout);
60  $siteDefaultLayoutInfo->layout_srl = -1;
61  $siteDefaultLayoutInfo->title = Context::getLang('use_site_default_layout');
62  $siteDefaultLayoutInfo->layout = $newLayout;
63 
64  array_unshift($output->data, $siteDefaultLayoutInfo);
65  }
66 
67  return $output->data;
68  }
69 
76  {
77  $siteSrl = Context::get('site_srl');
78  $layoutType = Context::get('layout_type');
79 
80  $layoutList = $this->getLayoutInstanceList($siteSrl, $layoutType);
81  $thumbs = array();
82 
83  foreach($layoutList as $key => $val)
84  {
85  if($thumbs[$val->layouts])
86  {
87  $val->thumbnail = $thumbs[$val->layouts];
88  continue;
89  }
90 
91  $token = explode('|@|', $val->layout);
92  if(count($token) == 2)
93  {
94  $thumbnailPath = sprintf('./themes/%s/layouts/%s/thumbnail.png' , $token[0], $token[1]);
95  }
96  else
97  {
98  $thumbnailPath = sprintf('./layouts/%s/thumbnail.png' , $val->layout);
99  }
100  if(is_readable($thumbnailPath))
101  {
102  $val->thumbnail = $thumbnailPath;
103  }
104  else
105  {
106  $val->thumbnail = sprintf('./modules/layout/tpl/img/noThumbnail.png');
107  }
108  $thumbs[$val->layout] = $val->thumbnail;
109  }
110  $this->add('layout_list', $layoutList);
111  }
112 
121  function getLayoutInstanceList($siteSrl = 0, $layoutType = 'P', $layout = null, $columnList = array())
122  {
123  if (!$siteSrl)
124  {
125  $siteModuleInfo = Context::get('site_module_info');
126  $siteSrl = (int)$siteModuleInfo->site_srl;
127  }
128  $args = new stdClass();
129  $args->site_srl = $siteSrl;
130  $args->layout_type = $layoutType;
131  $args->layout = $layout;
132  $output = executeQueryArray('layout.getLayoutList', $args, $columnList);
133 
134  // Create instance name list
135  $instanceList = array();
136  if(is_array($output->data))
137  {
138  foreach($output->data as $no => $iInfo)
139  {
140  if($this->isExistsLayoutFile($iInfo->layout, $layoutType))
141  {
142  $instanceList[] = $iInfo->layout;
143  }
144  else
145  {
146  unset($output->data[$no]);
147  }
148  }
149  }
150 
151  // Create downloaded name list
152  $downloadedList = array();
153  $titleList = array();
154  $_downloadedList = $this->getDownloadedLayoutList($layoutType);
155  if(is_array($_downloadedList))
156  {
157  foreach($_downloadedList as $dLayoutInfo)
158  {
159  $downloadedList[$dLayoutInfo->layout] = $dLayoutInfo->layout;
160  $titleList[$dLayoutInfo->layout] = $dLayoutInfo->title;
161  }
162  }
163 
164  if($layout)
165  {
166  if(count($instanceList) < 1 && $downloadedList[$layout])
167  {
168  $insertArgs = new stdClass();
169  $insertArgs->site_srl = $siteSrl;
170  $insertArgs->layout_srl = getNextSequence();
171  $insertArgs->layout = $layout;
172  $insertArgs->title = $titleList[$layout];
173  $insertArgs->layout_type = $layoutType;
174 
176  $oLayoutAdminController->insertLayout($insertArgs);
177  $isCreateInstance = TRUE;
178  }
179  }
180  else
181  {
182  // Get downloaded name list have no instance
183  $noInstanceList = array_diff($downloadedList, $instanceList);
184  foreach($noInstanceList as $layoutName)
185  {
186  $insertArgs = new stdClass();
187  $insertArgs->site_srl = $siteSrl;
188  $insertArgs->layout_srl = getNextSequence();
189  $insertArgs->layout = $layoutName;
190  $insertArgs->title = $titleList[$layoutName];
191  $insertArgs->layout_type = $layoutType;
192 
194  $oLayoutAdminController->insertLayout($insertArgs);
195  $isCreateInstance = TRUE;
196  }
197  }
198 
199  // If create layout instance, reload instance list
200  if($isCreateInstance)
201  {
202  $output = executeQueryArray('layout.getLayoutList', $args, $columnList);
203 
204  if(is_array($output->data))
205  {
206  foreach($output->data as $no => $iInfo)
207  {
208  if(!$this->isExistsLayoutFile($iInfo->layout, $layoutType))
209  {
210  unset($output->data[$no]);
211  }
212  }
213  }
214  }
215 
216  return $output->data;
217  }
218 
226  function isExistsLayoutFile($layout, $layoutType)
227  {
228  //TODO If remove a support themes, remove this codes also.
229  if($layoutType == 'P')
230  {
231  $pathPrefix = _XE_PATH_ . 'layouts/';
232  $themePathFormat = _XE_PATH_ . 'themes/%s/layouts/%s';
233  }
234  else
235  {
236  $pathPrefix = _XE_PATH_ . 'm.layouts/';
237  $themePathFormat = _XE_PATH_ . 'themes/%s/m.layouts/%s';
238  }
239 
240  if(strpos($layout, '|@|') !== FALSE)
241  {
242  list($themeName, $layoutName) = explode('|@|', $layout);
243  $path = sprintf($themePathFormat, $themeName, $layoutName);
244  }
245  else
246  {
247  $path = $pathPrefix . $layout;
248  }
249 
250  return is_readable($path . '/layout.html');
251  }
252 
260  {
261  // Get information from the DB
262  $args = new stdClass();
263  $args->layout_srl = $layout_srl;
264  $output = executeQuery('layout.getLayout', $args);
265  if(!$output->data) return;
266 
267  // Return xml file informaton after listing up the layout and extra_vars
268  $layout_info = $this->getLayoutInfo($layout, $output->data, $output->data->layout_type);
269 
270  return $layout_info;
271  }
272 
273  function getLayoutRawData($layout_srl, $columnList = array())
274  {
275  $args = new stdClass();
276  $args->layout_srl = $layout_srl;
277  $output = executeQuery('layout.getLayout', $args, $columnList);
278  if(!$output->toBool())
279  {
280  return;
281  }
282 
283  return $output->data;
284  }
285 
292  function getLayoutPath($layout_name = "", $layout_type = "P")
293  {
294  $layout_parse = explode('|@|', $layout_name);
295  if(count($layout_parse) > 1)
296  {
297  $class_path = './themes/'.$layout_parse[0].'/layouts/'.$layout_parse[1].'/';
298  }
299  else if($layout_name == 'faceoff')
300  {
301  $class_path = './modules/layout/faceoff/';
302  }
303  else if($layout_type == "M")
304  {
305  $class_path = sprintf("./m.layouts/%s/", $layout_name);
306  }
307  else
308  {
309  $class_path = sprintf('./layouts/%s/', $layout_name);
310  }
311  if(is_dir($class_path)) return $class_path;
312  return "";
313  }
314 
322  function getDownloadedLayoutList($layout_type = "P", $withAutoinstallInfo = false)
323  {
324  if ($withAutoinstallInfo) $oAutoinstallModel = getModel('autoinstall');
325 
326  // Get a list of downloaded layout and installed layout
327  $searched_list = $this->_getInstalledLayoutDirectories($layout_type);
328  $searched_count = count($searched_list);
329  if(!$searched_count) return;
330 
331  // natcasesort($searched_list);
332  // Return information for looping searched list of layouts
333  $list = array();
334  for($i=0;$i<$searched_count;$i++)
335  {
336  // Name of the layout
337  $layout = $searched_list[$i];
338  // Get information of the layout
339  $layout_info = $this->getLayoutInfo($layout, null, $layout_type);
340 
341  if(!$layout_info)
342  {
343  continue;
344  }
345 
346  if($withAutoinstallInfo)
347  {
348  // get easyinstall remove url
349  $packageSrl = $oAutoinstallModel->getPackageSrlByPath($layout_info->path);
350  $layout_info->remove_url = $oAutoinstallModel->getRemoveUrlByPackageSrl($packageSrl);
351 
352  // get easyinstall need update
353  $package = $oAutoinstallModel->getInstalledPackages($packageSrl);
354  $layout_info->need_update = $package[$packageSrl]->need_update;
355 
356  // get easyinstall update url
357  if($layout_info->need_update)
358  {
359  $layout_info->update_url = $oAutoinstallModel->getUpdateUrlByPackageSrl($packageSrl);
360  }
361  }
362  $list[] = $layout_info;
363  }
364 
365  usort($list, array($this, 'sortLayoutByTitle'));
366  return $list;
367  }
368 
372  function sortLayoutByTitle($a, $b)
373  {
374  if(!$a->title)
375  {
376  $a->title = $a->layout;
377  }
378 
379  if(!$b->title)
380  {
381  $b->title = $b->layout;
382  }
383 
384  $aTitle = strtolower($a->title);
385  $bTitle = strtolower($b->title);
386 
387  if($aTitle == $bTitle)
388  {
389  return 0;
390  }
391 
392  return ($aTitle < $bTitle) ? -1 : 1;
393  }
394 
400  function getInstalledLayoutCount($layoutType = 'P')
401  {
402  $searchedList = $this->_getInstalledLayoutDirectories($layoutType);
403  return count($searchedList);
404  }
405 
411  function _getInstalledLayoutDirectories($layoutType = 'P')
412  {
413  if($layoutType == 'M')
414  {
415  $directory = './m.layouts';
416  $globalValueKey = 'MOBILE_LAYOUT_DIRECTOIES';
417  }
418  else
419  {
420  $directory = './layouts';
421  $globalValueKey = 'PC_LAYOUT_DIRECTORIES';
422  }
423 
424  if($GLOBALS[$globalValueKey]) return $GLOBALS[$globalValueKey];
425 
426  $searchedList = FileHandler::readDir($directory);
427  if (!$searchedList) $searchedList = array();
428  $GLOBALS[$globalValueKey] = $searchedList;
429 
430  return $searchedList;
431  }
432 
441  function getLayoutInfo($layout, $info = null, $layout_type = "P")
442  {
443  if($info)
444  {
445  $layout_title = $info->title;
446  $layout = $info->layout;
447  $layout_srl = $info->layout_srl;
448  $site_srl = $info->site_srl;
449  $vars = unserialize($info->extra_vars);
450 
451  if($info->module_srl)
452  {
453  $layout_path = preg_replace('/([a-zA-Z0-9\_\.]+)(\.html)$/','',$info->layout_path);
454  $xml_file = sprintf('%sskin.xml', $layout_path);
455  }
456  }
457 
458  // Get a path of the requested module. Return if not exists.
459  if(!$layout_path) $layout_path = $this->getLayoutPath($layout, $layout_type);
460  if(!is_dir($layout_path)) return;
461 
462  // Read the xml file for module skin information
463  if(!$xml_file) $xml_file = sprintf("%sconf/info.xml", $layout_path);
464  if(!file_exists($xml_file))
465  {
466  $layout_info = new stdClass;
467  $layout_info->title = $layout;
468  $layout_info->layout = $layout;
469  $layout_info->path = $layout_path;
470  $layout_info->layout_title = $layout_title;
471  if(!$layout_info->layout_type)
472  {
473  $layout_info->layout_type = $layout_type;
474  }
475  return $layout_info;
476  }
477 
478  // Include the cache file if it is valid and then return $layout_info variable
479  if(!$layout_srl)
480  {
481  $cache_file = $this->getLayoutCache($layout, Context::getLangType(), $layout_type);
482  }
483  else
484  {
485  $cache_file = $this->getUserLayoutCache($layout_srl, Context::getLangType());
486  }
487 
488  if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
489  {
490  include($cache_file);
491 
492  if($layout_info->extra_var && $vars)
493  {
494  foreach($vars as $key => $value)
495  {
496  if(!$layout_info->extra_var->{$key} && !$layout_info->{$key})
497  {
498  $layout_info->{$key} = $value;
499  }
500  }
501  }
502 
503  if(!$layout_info->title)
504  {
505  $layout_info->title = $layout;
506  }
507 
508  return $layout_info;
509  }
510  // If no cache file exists, parse the xml and then return the variable.
511  $oXmlParser = new XmlParser();
512  $tmp_xml_obj = $oXmlParser->loadXmlFile($xml_file);
513 
514  if($tmp_xml_obj->layout) $xml_obj = $tmp_xml_obj->layout;
515  elseif($tmp_xml_obj->skin) $xml_obj = $tmp_xml_obj->skin;
516 
517  if(!$xml_obj) return;
518 
519  $buff = array();
520  $buff[] = '$layout_info = new stdClass;';
521  $buff[] = sprintf('$layout_info->site_srl = "%s";', $site_srl);
522 
523  if($xml_obj->version && $xml_obj->attrs->version == '0.2')
524  {
525  // Layout title, version and other information
526  sscanf($xml_obj->date->body, '%d-%d-%d', $date_obj->y, $date_obj->m, $date_obj->d);
527  $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
528  $buff[] = sprintf('$layout_info->layout = "%s";', $layout);
529  $buff[] = sprintf('$layout_info->type = "%s";', $xml_obj->attrs->type);
530  $buff[] = sprintf('$layout_info->path = "%s";', $layout_path);
531  $buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body);
532  $buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->description->body);
533  $buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->version->body);
534  $buff[] = sprintf('$layout_info->date = "%s";', $date);
535  $buff[] = sprintf('$layout_info->homepage = "%s";', $xml_obj->link->body);
536  $buff[] = sprintf('$layout_info->layout_srl = $layout_srl;');
537  $buff[] = sprintf('$layout_info->layout_title = $layout_title;');
538  $buff[] = sprintf('$layout_info->license = "%s";', $xml_obj->license->body);
539  $buff[] = sprintf('$layout_info->license_link = "%s";', $xml_obj->license->attrs->link);
540  $buff[] = sprintf('$layout_info->layout_type = "%s";', $layout_type);
541 
542  // Author information
543  if(!is_array($xml_obj->author)) $author_list[] = $xml_obj->author;
544  else $author_list = $xml_obj->author;
545 
546  $buff[] = '$layout_info->author = array();';
547  for($i=0, $c=count($author_list); $i<$c; $i++)
548  {
549  $buff[] = sprintf('$layout_info->author[%d] = new stdClass;', $i);
550  $buff[] = sprintf('$layout_info->author[%d]->name = "%s";', $i, $author_list[$i]->name->body);
551  $buff[] = sprintf('$layout_info->author[%d]->email_address = "%s";', $i, $author_list[$i]->attrs->email_address);
552  $buff[] = sprintf('$layout_info->author[%d]->homepage = "%s";', $i, $author_list[$i]->attrs->link);
553  }
554 
555  // Extra vars (user defined variables to use in a template)
556  $extra_var_groups = $xml_obj->extra_vars->group;
557  if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
558  if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
559 
560  $buff[] = '$layout_info->extra_var = new stdClass;';
561  $extra_var_count = 0;
562  foreach($extra_var_groups as $group)
563  {
564  $extra_vars = $group->var;
565  if($extra_vars)
566  {
567  if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
568 
569  $count = count($extra_vars);
570  $extra_var_count += $count;
571 
572  for($i=0;$i<$count;$i++)
573  {
574  unset($var, $options);
575  $var = $extra_vars[$i];
576  $name = $var->attrs->name;
577 
578  $buff[] = sprintf('$layout_info->extra_var->%s = new stdClass;', $name);
579  $buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body);
580  $buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body);
581  $buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type);
582  $buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name);
583  $buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"','\"',$var->description->body));
584 
585  $options = $var->options;
586  if(!$options) continue;
587  if(!is_array($options)) $options = array($options);
588 
589  $buff[] = sprintf('$layout_info->extra_var->%s->options = array();', $var->attrs->name);
590  $options_count = count($options);
591  $thumbnail_exist = false;
592  for($j=0; $j < $options_count; $j++)
593  {
594  $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"] = new stdClass;', $var->attrs->name, $options[$j]->attrs->value);
595  $thumbnail = $options[$j]->attrs->src;
596  if($thumbnail)
597  {
598  $thumbnail = $layout_path.$thumbnail;
599  if(file_exists($thumbnail))
600  {
601  $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->thumbnail = "%s";', $var->attrs->name, $options[$j]->attrs->value, $thumbnail);
602  if(!$thumbnail_exist)
603  {
604  $buff[] = sprintf('$layout_info->extra_var->%s->thumbnail_exist = true;', $var->attrs->name);
605  $thumbnail_exist = true;
606  }
607  }
608  }
609  $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->attrs->value, $options[$j]->title->body);
610  }
611  }
612  }
613  }
614  $buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count);
615  // Menu
616  if($xml_obj->menus->menu)
617  {
618  $menus = $xml_obj->menus->menu;
619  if(!is_array($menus)) $menus = array($menus);
620 
621  $menu_count = count($menus);
622  $buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count);
623  $buff[] = '$layout_info->menu = new stdClass;';
624  for($i=0;$i<$menu_count;$i++)
625  {
626  $name = $menus[$i]->attrs->name;
627  if($menus[$i]->attrs->default == "true") $buff[] = sprintf('$layout_info->default_menu = "%s";', $name);
628  $buff[] = sprintf('$layout_info->menu->%s = new stdClass;', $name);
629  $buff[] = sprintf('$layout_info->menu->%s->name = "%s";',$name, $menus[$i]->attrs->name);
630  $buff[] = sprintf('$layout_info->menu->%s->title = "%s";',$name, $menus[$i]->title->body);
631  $buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";',$name, $menus[$i]->attrs->maxdepth);
632 
633  $buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name);
634  $buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";',$name, $name);
635  $buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";',$name, $name);
636  }
637  }
638  }
639  else
640  {
641  // Layout title, version and other information
642  sscanf($xml_obj->author->attrs->date, '%d. %d. %d', $date_obj->y, $date_obj->m, $date_obj->d);
643  $date = sprintf('%04d%02d%02d', $date_obj->y, $date_obj->m, $date_obj->d);
644  $buff[] = sprintf('$layout_info->layout = "%s";', $layout);
645  $buff[] = sprintf('$layout_info->path = "%s";', $layout_path);
646  $buff[] = sprintf('$layout_info->title = "%s";', $xml_obj->title->body);
647  $buff[] = sprintf('$layout_info->description = "%s";', $xml_obj->author->description->body);
648  $buff[] = sprintf('$layout_info->version = "%s";', $xml_obj->attrs->version);
649  $buff[] = sprintf('$layout_info->date = "%s";', $date);
650  $buff[] = sprintf('$layout_info->layout_srl = $layout_srl;');
651  $buff[] = sprintf('$layout_info->layout_title = $layout_title;');
652  // Author information
653  $buff[] = sprintf('$layout_info->author[0]->name = "%s";', $xml_obj->author->name->body);
654  $buff[] = sprintf('$layout_info->author[0]->email_address = "%s";', $xml_obj->author->attrs->email_address);
655  $buff[] = sprintf('$layout_info->author[0]->homepage = "%s";', $xml_obj->author->attrs->link);
656  // Extra vars (user defined variables to use in a template)
657  $extra_var_groups = $xml_obj->extra_vars->group;
658  if(!$extra_var_groups) $extra_var_groups = $xml_obj->extra_vars;
659  if(!is_array($extra_var_groups)) $extra_var_groups = array($extra_var_groups);
660  foreach($extra_var_groups as $group)
661  {
662  $extra_vars = $group->var;
663  if($extra_vars)
664  {
665  if(!is_array($extra_vars)) $extra_vars = array($extra_vars);
666 
667  $extra_var_count = count($extra_vars);
668 
669  $buff[] = sprintf('$layout_info->extra_var_count = "%s";', $extra_var_count);
670  for($i=0;$i<$extra_var_count;$i++)
671  {
672  unset($var, $options);
673  $var = $extra_vars[$i];
674  $name = $var->attrs->name;
675 
676  $buff[] = sprintf('$layout_info->extra_var->%s->group = "%s";', $name, $group->title->body);
677  $buff[] = sprintf('$layout_info->extra_var->%s->title = "%s";', $name, $var->title->body);
678  $buff[] = sprintf('$layout_info->extra_var->%s->type = "%s";', $name, $var->attrs->type);
679  $buff[] = sprintf('$layout_info->extra_var->%s->value = $vars->%s;', $name, $name);
680  $buff[] = sprintf('$layout_info->extra_var->%s->description = "%s";', $name, str_replace('"','\"',$var->description->body));
681 
682  $options = $var->options;
683  if(!$options) continue;
684 
685  if(!is_array($options)) $options = array($options);
686  $options_count = count($options);
687  for($j=0;$j<$options_count;$j++)
688  {
689  $buff[] = sprintf('$layout_info->extra_var->%s->options["%s"]->val = "%s";', $var->attrs->name, $options[$j]->value->body, $options[$j]->title->body);
690  }
691  }
692  }
693  }
694  // Menu
695  if($xml_obj->menus->menu)
696  {
697  $menus = $xml_obj->menus->menu;
698  if(!is_array($menus)) $menus = array($menus);
699 
700  $menu_count = count($menus);
701  $buff[] = sprintf('$layout_info->menu_count = "%s";', $menu_count);
702  for($i=0;$i<$menu_count;$i++)
703  {
704  $name = $menus[$i]->attrs->name;
705  if($menus[$i]->attrs->default == "true") $buff[] = sprintf('$layout_info->default_menu = "%s";', $name);
706  $buff[] = sprintf('$layout_info->menu->%s->name = "%s";',$name, $name);
707  $buff[] = sprintf('$layout_info->menu->%s->title = "%s";',$name, $menus[$i]->title->body);
708  $buff[] = sprintf('$layout_info->menu->%s->maxdepth = "%s";',$name, $menus[$i]->maxdepth->body);
709  $buff[] = sprintf('$layout_info->menu->%s->menu_srl = $vars->%s;', $name, $name);
710  $buff[] = sprintf('$layout_info->menu->%s->xml_file = "./files/cache/menu/".$vars->%s.".xml.php";',$name, $name);
711  $buff[] = sprintf('$layout_info->menu->%s->php_file = "./files/cache/menu/".$vars->%s.".php";',$name, $name);
712  }
713  }
714  }
715 
716  // header_script
717  $oModuleModel = getModel('module');
718  $layout_config = $oModuleModel->getModulePartConfig('layout', $layout_srl);
719  $header_script = trim($layout_config->header_script);
720 
721  if($header_script)
722  {
723  $buff[] = sprintf(' $layout_info->header_script = %s; ', var_export($header_script, true));
724  }
725 
726  FileHandler::writeFile($cache_file, '<?php if(!defined("__XE__")) exit(); ' . join(PHP_EOL, $buff));
727  if(FileHandler::exists($cache_file)) include($cache_file);
728 
729  if(!$layout_info->title)
730  {
731  $layout_info->title = $layout;
732  }
733 
734  return $layout_info;
735  }
736 
743  {
744  return FileHandler::readDir($this->getUserLayoutImagePath($layout_srl));
745  }
746 
753  function getUserLayoutIniConfig($layout_srl, $layout_name=null)
754  {
755  $file = $this->getUserLayoutIni($layout_srl);
756  if($layout_name && FileHandler::exists($file) === FALSE)
757  {
758  FileHandler::copyFile($this->getDefaultLayoutIni($layout_name),$this->getUserLayoutIni($layout_srl));
759  }
760 
761  return FileHandler::readIniFile($file);
762  }
763 
770  {
771  return sprintf("./files/faceOff/%s", getNumberingPath($layout_srl,3));
772  }
773 
780  {
781  return $this->getUserLayoutPath($layout_srl). 'images/';
782  }
783 
790  {
791  return $this->getUserLayoutPath($layout_srl). 'layout.css';
792  }
793 
800  {
801  if($this->useUserLayoutTemp == 'temp') return;
802  return $this->_getUserLayoutFaceOffCss($layout_srl);
803  }
804 
811  {
812  return $this->getUserLayoutPath($layout_srl). 'faceoff.css';
813  }
814 
821  {
822  return $this->getUserLayoutPath($layout_srl). 'tmp.faceoff.css';
823  }
824 
831  {
832  $src = $this->getUserLayoutPath($layout_srl). 'layout.html';
833  if($this->useUserLayoutTemp == 'temp')
834  {
835  $temp = $this->getUserLayoutTempHtml($layout_srl);
836  if(FileHandler::exists($temp) === FALSE) FileHandler::copyFile($src,$temp);
837  return $temp;
838  }
839 
840  return $src;
841  }
842 
849  {
850  return $this->getUserLayoutPath($layout_srl). 'tmp.layout.html';
851  }
852 
859  {
860  $src = $this->getUserLayoutPath($layout_srl). 'layout.ini';
861  if($this->useUserLayoutTemp == 'temp')
862  {
863  $temp = $this->getUserLayoutTempIni($layout_srl);
864  if(!file_exists(FileHandler::getRealPath($temp))) FileHandler::copyFile($src,$temp);
865  return $temp;
866  }
867 
868  return $src;
869  }
870 
877  {
878  return $this->getUserLayoutPath($layout_srl). 'tmp.layout.ini';
879  }
880 
888  function getUserLayoutCache($layout_srl,$lang_type)
889  {
890  return $this->getUserLayoutPath($layout_srl). "{$lang_type}.cache.php";
891  }
892 
899  function getLayoutCache($layout_name,$lang_type,$layout_type='P')
900  {
901  if($layout_type=='P')
902  {
903  return sprintf("%sfiles/cache/layout/%s.%s.cache.php", _XE_PATH_, $layout_name,$lang_type);
904  }
905  else
906  {
907  return sprintf("%sfiles/cache/layout/m.%s.%s.cache.php", _XE_PATH_, $layout_name,$lang_type);
908  }
909  }
910 
916  function getDefaultLayoutIni($layout_name)
917  {
918  return $this->getDefaultLayoutPath($layout_name). 'layout.ini';
919  }
920 
926  function getDefaultLayoutHtml($layout_name)
927  {
928  return $this->getDefaultLayoutPath($layout_name). 'layout.html';
929  }
930 
936  function getDefaultLayoutCss($layout_name)
937  {
938  return $this->getDefaultLayoutPath($layout_name). 'css/layout.css';
939  }
940 
947  {
948  return "./modules/layout/faceoff/";
949  }
950 
956  function useDefaultLayout($layout_name)
957  {
958  $info = $this->getLayoutInfo($layout_name);
959  return ($info->type == 'faceoff');
960  }
961 
967  function setUseUserLayoutTemp($flag='temp')
968  {
969  $this->useUserLayoutTemp = $flag;
970  }
971 
978  {
979  return array(
980  $this->getUserLayoutTempHtml($layout_srl),
981  $this->getUserLayoutTempFaceOffCss($layout_srl),
982  $this->getUserLayoutTempIni($layout_srl)
983  );
984  }
985 
992  {
993  $file_list = array(
994  basename($this->getUserLayoutHtml($layout_srl)),
995  basename($this->getUserLayoutFaceOffCss($layout_srl)),
996  basename($this->getUserLayoutIni($layout_srl)),
997  basename($this->getUserLayoutCss($layout_srl))
998  );
999 
1000  $image_path = $this->getUserLayoutImagePath($layout_srl);
1001  $image_list = FileHandler::readDir($image_path,'/(.*(?:jpg|jpeg|gif|bmp|png)$)/i');
1002 
1003  foreach($image_list as $image)
1004  {
1005  $file_list[] = 'images/' . $image;
1006  }
1007  return $file_list;
1008  }
1009 
1016  function doActivateFaceOff(&$layout_info)
1017  {
1018  $layout_info->faceoff_ini_config = $this->getUserLayoutIniConfig($layout_info->layout_srl, $layout_info->layout);
1019  // faceoff layout CSS
1020  Context::addCSSFile($this->getDefaultLayoutCss($layout_info->layout));
1021  // CSS generated in the layout manager
1022  $faceoff_layout_css = $this->getUserLayoutFaceOffCss($layout_info->layout_srl);
1023  if($faceoff_layout_css) Context::addCSSFile($faceoff_layout_css);
1024  // CSS output for the widget
1025  Context::loadFile($this->module_path.'/tpl/css/widget.css', true);
1026  if($layout_info->extra_var->colorset->value == 'black') Context::loadFile($this->module_path.'/tpl/css/widget@black.css', true);
1027  else Context::loadFile($this->module_path.'/tpl/css/widget@white.css', true);
1028  // Different page displayed upon user's permission
1029  $logged_info = Context::get('logged_info');
1030  // Display edit button for faceoff layout
1031  if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin')===false && ($logged_info->is_admin == 'Y' || $logged_info->is_site_admin))
1032  {
1033  Context::addHtmlFooter('<div class="faceOffManager" style="height: 23px; position: fixed; right: 3px; top: 3px;"><a href="'.getUrl('','mid',Context::get('mid'),'act','dispLayoutAdminLayoutModify','delete_tmp','Y').'">'.Context::getLang('cmd_layout_edit').'</a></div>');
1034  }
1035  // Display menu when editing the faceOff page
1036  if(Context::get('act')=='dispLayoutAdminLayoutModify' && ($logged_info->is_admin == 'Y' || $logged_info->is_site_admin))
1037  {
1038  $oTemplate = &TemplateHandler::getInstance();
1039  Context::addBodyHeader($oTemplate->compile($this->module_path.'/tpl', 'faceoff_layout_menu'));
1040  }
1041  }
1042 }
1043 /* End of file layout.model.php */
1044 /* Location: ./modules/layout/layout.model.php */
getDefaultLayoutIni($layout_name)
getUserLayoutCss($layout_srl)
$oModuleModel
Definition: ko.install.php:236
getDefaultLayoutCss($layout_name)
getUserLayoutImagePath($layout_srl)
getNumberingPath($no, $size=3)
Definition: func.inc.php:1081
$args site_srl
Definition: ko.install.php:187
loadFile($args)
useDefaultLayout($layout_name)
getUserLayoutImageList($layout_srl)
$args title
Definition: ko.install.php:189
doActivateFaceOff(&$layout_info)
if(file_exists(_XE_PATH_. 'config/config.user.inc.php')) if(!defined('__DEBUG__')) if(!defined('__DEBUG_OUTPUT__')) if(!defined('__DEBUG_PROTECT__')) if(!defined('__DEBUG_PROTECT_IP__')) if(!defined('__DEBUG_DB_OUTPUT__')) if(!defined('__LOG_SLOW_QUERY__')) if(!defined('__LOG_SLOW_TRIGGER__')) if(!defined('__LOG_SLOW_ADDON__')) if(!defined('__LOG_SLOW_WIDGET__')) if(!defined('__DEBUG_QUERY__')) if(!defined('__OB_GZHANDLER_ENABLE__')) if(!defined('__ENABLE_PHPUNIT_TEST__')) if(!defined('__PROXY_SERVER__')) if(!defined('__ERROR_LOG__')) if(!defined('__DISABLE_DEFAULT_CSS__')) if(!defined('__AUTO_OPCACHE_INVALIDATE__')) if((__DEBUG_OUTPUT__==2)&&version_compare(PHP_VERSION, '6.0.0')===-1) if(version_compare(PHP_VERSION, '5.3.0') >=0) $GLOBALS['__xe_autoload_file_map']
Definition: config.inc.php:324
getLayoutInstanceListForJSONP()
$output
Definition: ko.install.php:193
add($key, $val)
readIniFile($filename)
getUserLayoutTempFaceOffCss($layout_srl)
if($called_position!="before_display_content"||Context::get('act')== 'dispPageAdminContentModify'||Context::getResponseMethod()!= 'HTML'||isCrawler())
foreach($sitemap as $id=> &$val) $extra_vars
Definition: ko.install.php:180
$layout_srl
Definition: ko.install.php:186
getUserLayoutTempFileList($layout_srl)
writeFile($filename, $buff, $mode="w")
getUserLayoutIni($layout_srl)
getLayout($layout_srl)
_getInstalledLayoutDirectories($layoutType= 'P')
$oLayoutAdminController
Definition: ko.install.php:192
getLayoutPath($layout_name="", $layout_type="P")
getUserLayoutCache($layout_srl, $lang_type)
getUserLayoutPath($layout_srl)
getLayoutInstanceList($siteSrl=0, $layoutType= 'P', $layout=null, $columnList=array())
getDownloadedLayoutList($layout_type="P", $withAutoinstallInfo=false)
getLayoutList($site_srl=0, $layout_type="P", $columnList=array())
addBodyHeader($header)
getUserLayoutIniConfig($layout_srl, $layout_name=null)
$args
Definition: ko.install.php:185
setUseUserLayoutTemp($flag='temp')
$layout_path
a path of directory where layout files reside
addCSSFile($file, $optimized=FALSE, $media= 'all', $targetie= '', $index=0)
getUserLayoutTempIni($layout_srl)
getAdminModel($module_name)
Definition: func.inc.php:156
getRealPath($source)
getLayoutCache($layout_name, $lang_type, $layout_type='P')
copyFile($source, $target, $force= 'Y')
getLang($code)
const _XE_PATH_
Definition: config.inc.php:49
_getUserLayoutFaceOffCss($layout_srl)
foreach($skinTypes as $key=> $dir) $designInfo module board skin
Definition: ko.install.php:246
getUserLayoutFileList($layout_srl)
getLayoutRawData($layout_srl, $columnList=array())
getNextSequence()
Definition: func.inc.php:236
getDefaultLayoutHtml($layout_name)
getModel($module_name)
Definition: func.inc.php:145
getUserLayoutHtml($layout_srl)
isExistsLayoutFile($layout, $layoutType)
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219
getUserLayoutTempHtml($layout_srl)
getInstalledLayoutCount($layoutType= 'P')
getAdminController($module_name)
Definition: func.inc.php:101
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
getLayoutInfo($layout, $info=null, $layout_type="P")
getUrl()
Definition: func.inc.php:297
addHtmlFooter($footer)
getUserLayoutFaceOffCss($layout_srl)
sortLayoutByTitle($a, $b)