XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
layout.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
9 {
14  function init()
15  {
16  }
17 
25  {
26  if(Context::get('layout') == 'faceoff') return $this->stop('not supported');
27 
28  // Get information to create a layout
29  $site_module_info = Context::get('site_module_info');
30  $args->site_srl = (int)$site_module_info->site_srl;
31  $args->layout_srl = getNextSequence();
32  $args->layout = Context::get('layout');
33  $args->title = Context::get('title');
34  $args->layout_type = Context::get('_layout_type');
35  if(!$args->layout_type) $args->layout_type = "P";
36 
37  // Insert into the DB
38  $output = $this->insertLayout($args);
39  if(!$output->toBool()) return $output;
40 
41  // initiate if it is faceoff layout
42  $this->initLayout($args->layout_srl, $args->layout);
43 
44  // update layout info
45  Context::set('layout_srl', $args->layout_srl);
46  $output = $this->procLayoutAdminUpdate();
47  if (!$output->toBool()) return $output;
48 
49  return $this->setRedirectUrl(Context::get('success_return_url'), $output);
50  }
51 
57  function insertLayout($args)
58  {
59  $output = executeQuery("layout.insertLayout", $args);
60  return $output;
61  }
62 
69  function initLayout($layout_srl, $layout_name)
70  {
71  $oLayoutModel = getModel('layout');
72  // Import a sample layout if it is faceoff
73  if($oLayoutModel->useDefaultLayout($layout_name))
74  {
75  $this->importLayout($layout_srl, $this->module_path.'tpl/faceOff_sample.tar');
76  // Remove a directory
77  }
78  else
79  {
80  FileHandler::removeDir($oLayoutModel->getUserLayoutPath($layout_srl));
81  }
82  }
83 
90  {
91  // Consider the rest of items as extra vars, except module, act, layout_srl, layout, and title .. Some gurida ..
93  unset($extra_vars->module);
94  unset($extra_vars->act);
95  unset($extra_vars->layout_srl);
96  unset($extra_vars->layout);
97  unset($extra_vars->title);
98  unset($extra_vars->apply_layout);
99  unset($extra_vars->apply_mobile_view);
100 
101  $is_sitemap = $extra_vars->is_sitemap;
102  unset($extra_vars->is_sitemap);
103 
104  $args = Context::gets('layout_srl','title');
105  // Get layout information
106  $oLayoutModel = getModel('layout');
107  $oMenuAdminModel = getAdminModel('menu');
108  $layout_info = $oLayoutModel->getLayout($args->layout_srl);
109 
110  if($layout_info->menu)
111  {
112  $menus = get_object_vars($layout_info->menu);
113  }
114  if(count($menus))
115  {
116  foreach($menus as $menu_id => $val)
117  {
118  $menu_srl = Context::get($menu_id);
119  if(!$menu_srl) continue;
120 
121  // if menu is -1, get default menu in site
122  if($menu_srl == -1)
123  {
124  $oModuleModel = getModel('module');
125  $start_module = $oModuleModel->getSiteInfo(0, $columnList);
126  $tmpArgs = new stdClass;
127  $tmpArgs->url = $start_module->mid;
128  $tmpArgs->site_srl = 0;
129  $output = executeQuery('menu.getMenuItemByUrl', $tmpArgs);
130  if(!$output->toBool())
131  {
132  return new BaseObject(-1, 'fail_to_update');
133  }
134 
135  $menu_srl = $output->data->menu_srl;
136  }
137 
138  $output = $oMenuAdminModel->getMenu($menu_srl);
139 
140  $menu_srl_list[] = $menu_srl;
141  $menu_name_list[$menu_srl] = $output->title;
142 
143  $apply_layout = Context::get('apply_layout');
144  $apply_mobile_view = Context::get('apply_mobile_view');
145 
146  if($apply_layout=='Y' || $apply_mobile_view=='Y')
147  {
148  $menu_args = new stdClass();
149  $menu_args->menu_srl = $menu_srl;
150  $menu_args->site_srl = $layout_info->site_srl;
151  $output = executeQueryArray('layout.getLayoutModules', $menu_args);
152  if($output->data)
153  {
154  $modules = array();
155  for($i=0;$i<count($output->data);$i++)
156  {
157  $modules[] = $output->data[$i]->module_srl;
158  }
159 
160  if(count($modules))
161  {
162  $update_args = new stdClass();
163  $update_args->module_srls = implode(',',$modules);
164  if($apply_layout == "Y")
165  {
166  $update_args->layout_srl = $args->layout_srl;
167  }
168  if($layout_info->layout_type == "M")
169  {
170  if(Context::get('apply_mobile_view') == "Y")
171  {
172  $update_args->use_mobile = "Y";
173  }
174  $output = executeQuery('layout.updateModuleMLayout', $update_args);
175  }
176  else
177  {
178  $output = executeQuery('layout.updateModuleLayout', $update_args);
179  }
180 
181  $oCacheHandler = CacheHandler::getInstance('object', null, true);
182  if($oCacheHandler->isSupport())
183  {
184  $oCacheHandler->invalidateGroupKey('site_and_module');
185  }
186  }
187  }
188  }
189  }
190  }
191 
192  $tmpDir = sprintf('./files/attach/images/%s/tmp', $args->layout_srl);
193  // Separately handle if a type of extra_vars is an image
194  if($layout_info->extra_var)
195  {
196  foreach($layout_info->extra_var as $name => $vars)
197  {
198  if($vars->type!='image') continue;
199 
200  $fileName = $extra_vars->{$name};
201  if($vars->value == $fileName)
202  {
203  continue;
204  }
205 
206  FileHandler::removeFile($vars->value);
207 
208  if(!$fileName)
209  {
210  continue;
211  }
212 
213  $pathInfo = pathinfo($fileName);
214  $tmpFileName = sprintf('%s/tmp/%s', $pathInfo['dirname'], $pathInfo['basename']);
215 
216  if(!FileHandler::moveFile($tmpFileName, $fileName))
217  {
218  unset($extra_vars->{$name});
219  }
220  }
221  }
222 
223  // Save header script into "config" of layout module
224  $oModuleModel = getModel('module');
225  $oModuleController = getController('module');
226  $layout_config = new stdClass();
227  $layout_config->header_script = Context::get('header_script');
228  $oModuleController->insertModulePartConfig('layout',$args->layout_srl,$layout_config);
229  // Save a title of the menu
230  $extra_vars->menu_name_list = $menu_name_list;
231  // Variable setting for DB insert
232  $args->extra_vars = serialize($extra_vars);
233 
234  $output = $this->updateLayout($args);
235  if(!$output->toBool())
236  {
237  return $output;
238  }
239 
240  FileHandler::removeDir($tmpDir);
241 
242  if(!$is_sitemap)
243  {
244  return $this->setRedirectUrl(Context::get('error_return_url'), $output);
245  }
246  else
247  {
248  $context = Context::getInstance();
249  $context->setRequestMethod('JSON');
250  $this->setMessage('success');
251  }
252  }
253 
259  function updateLayout($args) {
260  $output = executeQuery('layout.updateLayout', $args);
261  if($output->toBool())
262  {
263  $oLayoutModel = getModel('layout');
264  $cache_file = $oLayoutModel->getUserLayoutCache($args->layout_srl, Context::getLangType());
265  FileHandler::removeFile($cache_file);
266  }
267 
268  return $output;
269  }
270 
277  {
278  $layout_srl = Context::get('layout_srl');
279  $this->setRedirectUrl(Context::get('error_return_url'));
280  return $this->deleteLayout($layout_srl);
281  }
282 
288  function deleteLayout($layout_srl, $force = FALSE)
289  {
290  $oLayoutModel = getModel('layout');
291 
292  if($force)
293  {
294  $layoutInfo = $oLayoutModel->getLayout($layout_srl);
295  if($layoutInfo)
296  {
297  $layoutList = $oLayoutModel->getLayoutInstanceList($layoutInfo->site_srl, $layoutInfo->layout_type, $layoutInfo->layout, array('layout_srl', 'layout'));
298  if(count($layoutList) <= 1)
299  {
300  // uninstall package
301  $path = $layoutInfo->path;
302 
303  $oAutoinstallModel = getModel('autoinstall');
304  $packageSrl = $oAutoinstallModel->getPackageSrlByPath($path);
305  $oAutoinstallAdminController = getAdminController('autoinstall');
306 
307  if($packageSrl)
308  {
309  $output = $oAutoinstallAdminController->uninstallPackageByPackageSrl($packageSrl);
310  }
311  else
312  {
313  $output = $oAutoinstallAdminController->uninstallPackageByPath($path);
314  }
315 
316  if(!$output->toBool())
317  {
318  return new BaseObject(-1, $output->message);
319  }
320  }
321  }
322  }
323 
324  $path = $oLayoutModel->getUserLayoutPath($layout_srl);
325  FileHandler::removeDir($path);
326 
327  $layout_file = $oLayoutModel->getUserLayoutHtml($layout_srl);
328  FileHandler::removeFile($layout_file);
329  // Delete Layout
330  $args = new stdClass();
331  $args->layout_srl = $layout_srl;
332  $output = executeQuery("layout.deleteLayout", $args);
333 
334  if(!$output->toBool()) return $output;
335 
336  return new BaseObject(0,'success_deleted');
337  }
338 
344  {
345  $mode = Context::get('mode');
346  if ($mode == 'reset')
347  {
348  return $this->procLayoutAdminCodeReset();
349  }
350 
351  $layout_srl = Context::get('layout_srl');
352  $code = Context::get('code');
353  $code_css = Context::get('code_css');
354  $is_post = ($_SERVER['REQUEST_METHOD'] == 'POST');
355 
356  if(!$layout_srl || !$code || !$is_post)
357  {
358  return new BaseObject(-1, 'msg_invalid_request');
359  }
360 
361  $oLayoutModel = getModel('layout');
362  $layout_file = $oLayoutModel->getUserLayoutHtml($layout_srl);
363  FileHandler::writeFile($layout_file, $code);
364 
365  $layout_css_file = $oLayoutModel->getUserLayoutCss($layout_srl);
366  FileHandler::writeFile($layout_css_file, $code_css);
367 
368  $this->setRedirectUrl(Context::get('error_return_url'));
369  $this->setMessage('success_updated');
370  }
371 
377  {
378  $layout_srl = Context::get('layout_srl');
379  if(!$layout_srl) return new BaseObject(-1, 'msg_invalid_request');
380 
381  // delete user layout file
382  $oLayoutModel = getModel('layout');
383  $layout_file = $oLayoutModel->getUserLayoutHtml($layout_srl);
384  FileHandler::removeFile($layout_file);
385 
386  $info = $oLayoutModel->getLayout($layout_srl);
387 
388  // if face off delete, tmp file
389  if($oLayoutModel->useDefaultLayout($info->layout))
390  {
391  $this->deleteUserLayoutTempFile($layout_srl);
392  $faceoff_css = $oLayoutModel->getUserLayoutFaceOffCss($layout_srl);
393  FileHandler::removeFile($faceoff_css);
394  }
395 
396  $this->initLayout($layout_srl, $info->layout);
397  $this->setMessage('success_reset');
398  $this->setRedirectUrl(Context::get('error_return_url'));
399  }
400 
406  {
407  if(!Context::isUploaded()) exit();
408 
409  $image = Context::get('user_layout_image');
410  $layout_srl = Context::get('layout_srl');
411  if(!is_uploaded_file($image['tmp_name'])) exit();
412 
413  $this->insertUserLayoutImage($layout_srl, $image);
414  $this->setTemplatePath($this->module_path.'tpl');
415  $this->setTemplateFile("top_refresh.html");
416 
417  $this->setRedirectUrl(Context::get('error_return_url'));
418  }
419 
427  {
428  $oLayoutModel = getModel('layout');
429  $path = $oLayoutModel->getUserLayoutImagePath($layout_srl);
430  if(!is_dir($path)) FileHandler::makeDir($path);
431 
432  $filename = strtolower($source['name']);
433  if($filename != urlencode($filename))
434  {
435  $ext = substr(strrchr($filename,'.'),1);
436  $filename = sprintf('%s.%s', md5($filename), $ext);
437  }
438 
439  // Check uploaded file
440  if(!checkUploadedFile($source['tmp_name'])) return false;
441 
442  if(file_exists($path .'/'. $filename)) @unlink($path . $filename);
443  if(!move_uploaded_file($source['tmp_name'], $path . $filename )) return false;
444  return true;
445  }
446 
452  {
453  $filename = Context::get('filename');
454  $layout_srl = Context::get('layout_srl');
455  $this->removeUserLayoutImage($layout_srl,$filename);
456  $this->setMessage('success_deleted');
457  $this->setRedirectUrl(Context::get('error_return_url'));
458  }
459 
466  function removeUserLayoutImage($layout_srl,$filename)
467  {
468  $oLayoutModel = getModel('layout');
469  $path = $oLayoutModel->getUserLayoutImagePath($layout_srl);
470  @unlink($path . $filename);
471  }
472 
473  // deprecated
481  {
482  $oModuleModel = getModel('module');
483 
484  $mid = Context::get('mid');
485  if(!$mid) return new BaseObject(-1, 'msg_invalid_request');
486 
487  $site_module_info = Context::get('site_module_info');
488  $columnList = array('layout_srl');
489  $module_info = $oModuleModel->getModuleInfoByMid($mid, $site_module_info->site_srl, $columnList);
490  $layout_srl = $module_info->layout_srl;
491  if(!$layout_srl) return new BaseObject(-1, 'msg_invalid_request');
492 
493  $oLayoutModel = getModel('layout');
494 
495  // save tmp?
496  $temp = Context::get('saveTemp');
497  if($temp =='Y')
498  {
499  $oLayoutModel->setUseUserLayoutTemp();
500  }
501  else
502  {
503  // delete temp files
504  $this->deleteUserLayoutTempFile($layout_srl);
505  }
506 
507  $this->add('saveTemp',$temp);
508 
509  // write user layout
510  $extension_obj = Context::gets('e1','e2','neck','knee');
511 
512  $file = $oLayoutModel->getUserLayoutHtml($layout_srl);
513  $content = FileHandler::readFile($file);
514  $content = $this->addExtension($layout_srl,$extension_obj,$content);
515  FileHandler::writeFile($file,$content);
516 
517  // write faceoff.css
518  $css = stripslashes(Context::get('css'));
519 
520  $css_file = $oLayoutModel->getUserLayoutFaceOffCss($layout_srl);
521  FileHandler::writeFile($css_file,$css);
522 
523  // write ini
524  $obj = Context::gets('type','align','column');
525  $obj = (array)$obj;
526  $src = $oLayoutModel->getUserLayoutIniConfig($layout_srl);
527  foreach($obj as $key => $val) $src[$key] = $val;
528  $this->insertUserLayoutValue($layout_srl,$src);
529  }
530 
538  {
539  $oLayoutModel = getModel('layout');
540  $file = $oLayoutModel->getUserLayoutIni($layout_srl);
541  FileHandler::writeIniFile($file, $arr);
542  }
543 
551  function addExtension($layout_srl,$arg,$content)
552  {
553  $oLayoutModel = getModel('layout');
554  $reg = '/(<\!\-\- start\-e1 \-\->)(.*)(<\!\-\- end\-e1 \-\->)/i';
555  $extension_content = '\1' .stripslashes($arg->e1) . '\3';
556  $content = preg_replace($reg,$extension_content,$content);
557 
558  $reg = '/(<\!\-\- start\-e2 \-\->)(.*)(<\!\-\- end\-e2 \-\->)/i';
559  $extension_content = '\1' .stripslashes($arg->e2) . '\3';
560  $content = preg_replace($reg,$extension_content,$content);
561 
562  $reg = '/(<\!\-\- start\-neck \-\->)(.*)(<\!\-\- end\-neck \-\->)/i';
563  $extension_content = '\1' .stripslashes($arg->neck) . '\3';
564  $content = preg_replace($reg,$extension_content,$content);
565 
566  $reg = '/(<\!\-\- start\-knee \-\->)(.*)(<\!\-\- end\-knee \-\->)/i';
567  $extension_content = '\1' .stripslashes($arg->knee) . '\3';
568  $content = preg_replace($reg,$extension_content,$content);
569  return $content;
570  }
571 
578  {
579  $oLayoutModel = getModel('layout');
580  $file_list = $oLayoutModel->getUserLayoutTempFileList($layout_srl);
581  foreach($file_list as $key => $file)
582  {
584  }
585  }
586 
592  {
593  $layout_srl = Context::get('layout_srl');
594  if(!$layout_srl) return new BaseObject('-1','msg_invalid_request');
595 
596  require_once(_XE_PATH_.'libs/tar.class.php');
597  $oLayoutModel = getModel('layout');
598 
599  // Copy files to temp path
600  $file_path = $oLayoutModel->getUserLayoutPath($layout_srl);
601  $target_path = $oLayoutModel->getUserLayoutPath(0);
602  FileHandler::copyDir($file_path, $target_path);
603 
604  // replace path and ini config
605  $ini_config = $oLayoutModel->getUserLayoutIniConfig(0);
606  $file_list = $oLayoutModel->getUserLayoutFileList($layout_srl);
607  unset($file_list[2]);
608 
609  foreach($file_list as $file)
610  {
611  if(strncasecmp('images', $file, 6) === 0) continue;
612 
613  // replace path
614  $file = $target_path . $file;
615  $content = FileHandler::readFile($file);
616  $pattern = '/(http:\/\/[^ ]+)?(\.\/)?' . str_replace('/', '\/', (str_replace('./', '', $file_path))) . '/';
617  if(basename($file) == 'faceoff.css' || basename($file) == 'layout.css')
618  $content = preg_replace($pattern, '../', $content);
619  else
620  $content = preg_replace($pattern, './', $content);
621 
622  // replace ini config
623  foreach($ini_config as $key => $value)
624  {
625  $content = str_replace('{$layout_info->faceoff_ini_config[\'' . $key . '\']}', $value, $content);
626  }
627 
628  FileHandler::writeFile($file, $content);
629  }
630 
631  // make info.xml
632  $info_file = $target_path . 'conf/info.xml';
633  FileHandler::copyFile('./modules/layout/faceoff/conf/info.xml', $info_file);
634  $content = FileHandler::readFile($info_file);
635  $content = str_replace('type="faceoff"', '', $content);
636  FileHandler::writeFile($info_file, $content);
637  $file_list[] = 'conf/info.xml';
638 
639  // make css file
640  $css_file = $target_path . 'css/layout.css';
641  FileHandler::copyFile('./modules/layout/faceoff/css/layout.css', $css_file);
642  $content = FileHandler::readFile('./modules/layout/tpl/css/widget.css');
643  FileHandler::writeFile($css_file, "\n" . $content, 'a');
644  $content = FileHandler::readFile($target_path . 'faceoff.css');
645  FileHandler::writeFile($css_file, "\n" . $content, 'a');
646  $content = FileHandler::readFile($target_path . 'layout.css');
647  FileHandler::writeFile($css_file, "\n" . $content, 'a');
648 
649  // css load
650  $content = FileHandler::readFile($target_path . 'layout.html');
651  $content = "<load target=\"css/layout.css\" />\n" . $content;
652  FileHandler::writeFile($target_path . 'layout.html', $content);
653  unset($file_list[3]);
654  unset($file_list[1]);
655  $file_list[] = 'css/layout.css';
656 
657  // Compress the files
658  $tar = new tar();
659  $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath(0));
660  chdir($user_layout_path);
661  foreach($file_list as $key => $file) $tar->addFile($file);
662 
663  $stream = $tar->toTarStream();
664  $filename = 'faceoff_' . date('YmdHis') . '.tar';
665  header("Cache-Control: ");
666  header("Pragma: ");
667  header("Content-Type: application/x-compressed");
668  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
669  // header("Content-Length: " .strlen($stream)); ?? why??
670  header('Content-Disposition: attachment; filename="'. $filename .'"');
671  header("Content-Transfer-Encoding: binary\n");
672  echo $stream;
673  // Close Context and then exit
674  Context::close();
675 
676  // delete temp path
677  FileHandler::removeDir($target_path);
678 
679  exit();
680  }
681 
687  function procLayoutAdminUserLayoutImport()
688  {
689  return $this->stop('not supported');
690 
691  // check upload
692  if(!Context::isUploaded()) exit();
693  $file = Context::get('file');
694  if(!is_uploaded_file($file['tmp_name']) || !checkUploadedFile($file['tmp_name'])) exit();
695 
696  if(substr_compare($file['name'], '.tar', -4) !== 0) exit();
697 
698  $layout_srl = Context::get('layout_srl');
699  if(!$layout_srl) exit();
700 
701  $oLayoutModel = getModel('layout');
702  $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($layout_srl));
703  if(!move_uploaded_file($file['tmp_name'], $user_layout_path . 'faceoff.tar')) exit();
704 
705  $this->importLayout($layout_srl, $user_layout_path.'faceoff.tar');
706 
707  $this->setRedirectUrl(Context::get('error_return_url'));
708  }
709 
714  function procLayoutAdminCopyLayout()
715  {
716  $sourceArgs = Context::getRequestVars();
717  if($sourceArgs->layout == 'faceoff')
718  {
719  return $this->stop('not supported');
720  }
721 
722  if(!$sourceArgs->layout_srl)
723  {
724  return $this->stop('msg_empty_origin_layout');
725  }
726 
727  $oLayoutModel = getModel('layout');
728  $layout = $oLayoutModel->getLayout($sourceArgs->layout_srl);
729 
730  if(!$sourceArgs->title)
731  {
732  $sourceArgs->title = array($layout->title.'_'.$this->_makeRandomMid());
733  }
734 
735  if(!is_array($sourceArgs->title) || count($sourceArgs->title) == 0)
736  {
737  return $this->stop('msg_empty_target_layout');
738  }
739 
740  $output = $oLayoutModel->getLayoutRawData($sourceArgs->layout_srl, array('extra_vars'));
741  $args = new stdClass();
742  $args->extra_vars = $output->extra_vars;
743  $extra_vars = unserialize($args->extra_vars);
744 
745  if($layout->extra_var_count) {
746  $reg = "/^.\/files\/attach\/images\/([0-9]+)\/(.*)/";
747  if($extra_vars) foreach($extra_vars as $key => $val) {
748  if($layout->extra_var->{$key}->type == 'image') {
749  if(!preg_match($reg,$val,$matches)) continue;
750  $image_list[$key]->filename = $matches[2];
751  $image_list[$key]->old_file = $val;
752  }
753  }
754  }
755 
756  $oModuleController = getController('module');
757  $layout_config = new stdClass();
758  $layout_config->header_script = $extra_vars->header_script;
759 
760  // Get information to create a layout
761  $args->site_srl = (int)$layout->site_srl;
762  $args->layout = $layout->layout;
763  $args->layout_type = $layout->layout_type;
764  if(!$args->layout_type) $args->layout_type = "P";
765 
766  $oDB = &DB::getInstance();
767  $oDB->begin();
768 
769  if(is_array($sourceArgs->title))
770  {
771  foreach($sourceArgs->title AS $key=>$value)
772  {
773  if(!trim($value))
774  {
775  continue;
776  }
777 
778  $args->layout_srl = getNextSequence();
779  $args->title = $value;
780 
781  if(is_array($image_list)) {
782  foreach($image_list as $key=>$val) {
783  $new_file = sprintf("./files/attach/images/%s/%s", $args->layout_srl,$val->filename);
784  FileHandler::copyFile($val->old_file, $new_file);
785  $extra_vars->{$key} = $new_file;
786  }
787  $args->extra_vars = serialize($extra_vars);
788  }
789 
790  // for header script
791  $oModuleController->insertModulePartConfig('layout', $args->layout_srl, $layout_config);
792 
793  // Insert into the DB
794  $output = $this->insertLayout($args);
795  if(!$output->toBool())
796  {
797  $oDB->rollback();
798  return $output;
799  }
800 
801  // initiate if it is faceoff layout
802  $this->initLayout($args->layout_srl, $args->layout);
803 
804  // update layout info
805  $output = $this->updateLayout($args);
806  if (!$output->toBool())
807  {
808  $oDB->rollback();
809  return $output;
810  }
811 
812  $this->_copyLayoutFile($layout->layout_srl, $args->layout_srl);
813  }
814  }
815  $oDB->commit();
816 
817  $this->setMessage('success_registed');
818  if(!in_array(Context::getRequestMethod(),array('XMLRPC','JSON'))) {
819  global $lang;
820  htmlHeader();
821  alertScript($lang->success_registed);
822  reload(true);
823  closePopupScript();
824  htmlFooter();
825  Context::close();
826  exit;
827  }
828  }
829 
830  private function _makeRandomMid()
831  {
832  $time = $_SERVER['REQUEST_TIME'];
833  $randomString = "";
834  for($i=0;$i<4;$i++)
835  {
836  $doc = rand()%26+65;
837  $randomString .= chr($doc);
838  }
839 
840  return $randomString.substr($time, -4);
841  }
842 
849  function _copyLayoutFile($sourceLayoutSrl, $targetLayoutSrl)
850  {
851  $oLayoutModel = getModel('layout');
852  $sourceLayoutPath = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($sourceLayoutSrl));
853  $targetLayoutPath = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($targetLayoutSrl));
854 
855  $sourceImagePath = $oLayoutModel->getUserLayoutImagePath($sourceLayoutSrl);
856  $targetImagePath = $oLayoutModel->getUserLayoutImagePath($targetLayoutSrl);
857  FileHandler::makeDir($targetImagePath);
858 
859  $sourceFileList = $oLayoutModel->getUserLayoutFileList($sourceLayoutSrl);
860  foreach($sourceFileList as $key => $file)
861  {
862  if(is_readable($sourceLayoutPath.$file))
863  {
864  FileHandler::copyFile($sourceLayoutPath.$file, $targetLayoutPath.$file);
865  if($file == 'layout.html' || $file == 'layout.css')
866  {
867  $this->_changeFilepathInSource($targetLayoutPath.$file, $sourceImagePath, $targetImagePath);
868  }
869  }
870  }
871  }
872 
878  function _changeFilepathInSource($file, $source, $target)
879  {
880  $content = FileHandler::readFile($file);
881  $content = str_replace($source, $target, $content);
882  FileHandler::writeFile($file, $content);
883  }
884 
891  function importLayout($layout_srl, $source_file)
892  {
893  $oLayoutModel = getModel('layout');
894  $user_layout_path = FileHandler::getRealPath($oLayoutModel->getUserLayoutPath($layout_srl));
895  $file_list = $oLayoutModel->getUserLayoutFileList($layout_srl);
896  foreach($file_list as $key => $file)
897  {
898  FileHandler::removeFile($user_layout_path . $file);
899  }
900 
901  require_once(_XE_PATH_.'libs/tar.class.php');
902  $image_path = $oLayoutModel->getUserLayoutImagePath($layout_srl);
903  FileHandler::makeDir($image_path);
904  $tar = new tar();
905  $tar->openTAR($source_file);
906  // If layout.ini file does not exist
907  if(!$tar->getFile('layout.ini')) return;
908 
909  $replace_path = getNumberingPath($layout_srl,3);
910  foreach($tar->files as $key => $info)
911  {
912  FileHandler::writeFile($user_layout_path . $info['name'],str_replace('__LAYOUT_PATH__',$replace_path,$info['file']));
913  }
914  // Remove uploaded file
915  FileHandler::removeFile($source_file);
916  }
917 
921  function procLayoutAdminConfigImageUpload()
922  {
923  $layoutSrl = Context::get('layout_srl');
924  $name = Context::get('name');
925  $img = Context::get('img');
926 
927  $this->setTemplatePath($this->module_path.'tpl');
928  $this->setTemplateFile("after_upload_config_image.html");
929 
930  if(!$img['tmp_name'] || !is_uploaded_file($img['tmp_name']) || !checkUploadedFile($img['tmp_name']))
931  {
932  Context::set('msg', Context::getLang('upload failed'));
933  return;
934  }
935 
936  if(!preg_match('/\.(jpg|jpeg|gif|png)$/i', $img['name']))
937  {
938  Context::set('msg', Context::getLang('msg_layout_image_target'));
939  return;
940  }
941 
942  $path = sprintf('./files/attach/images/%s/', $layoutSrl);
943  $tmpPath = $path . 'tmp/';
944  if(!FileHandler::makeDir($tmpPath))
945  {
946  Context::set('msg', Context::getLang('make directory failed'));
947  return;
948  }
949 
950  $ext = substr(strrchr($img['name'],'.'),1);
951  $_fileName = md5(crypt(rand(1000000,900000), rand(0,100))).'.'.$ext;
952  $fileName = $path . $_fileName;
953  $tmpFileName = $tmpPath . $_fileName;
954 
955  if(!move_uploaded_file($img['tmp_name'], $tmpFileName))
956  {
957  Context::set('msg', Context::getLang('move file failed'));
958  return;
959  }
960 
961  Context::set('name', $name);
962  Context::set('fileName', $fileName);
963  Context::set('tmpFileName', $tmpFileName);
964  }
965 
969  function procLayoutAdminConfigImageDelete()
970  {
971  $layoutSrl = Context::get('layout_srl');
972  $name = Context::get('name');
973 
974  $this->setTemplatePath($this->module_path.'tpl');
975  $this->setTemplateFile("after_delete_config_image.html");
976 
977  $oModel = getModel('layout');
978  $layoutInfo = $oModel->getLayout($layoutSrl);
979 
980  if($layoutInfo->extra_var_count)
981  {
982  foreach($layoutInfo->extra_var as $varId => $val)
983  {
984  $newLayoutInfo->{$varId} = $val->value;
985  }
986  }
987 
988  unset($newLayoutInfo->{$name});
989 
990  $args->layout_srl = $layoutSrl;
991  $args->extra_vars = serialize($newLayoutInfo);
992  $output = $this->updateLayout($args);
993  if(!$output->toBool())
994  {
995  Context::set('msg', Context::getLang($output->getMessage()));
996  return $output;
997  }
998 
999  FileHandler::removeFile($layoutInfo->extra_var->{$name}->value);
1000  Context::set('name', $name);
1001  }
1002 }
1003 /* End of file layout.admin.controller.php */
1004 /* Location: ./modules/layout/layout.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
getController($module_name)
Definition: func.inc.php:90
removeFile($filename)
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
$module_info
Definition: ko.install.php:289
& getInstance($target= 'object', $info=null, $always_use_file=false)
addExtension($layout_srl, $arg, $content)
importLayout($layout_srl, $source_file)
foreach($sitemap as $id=> &$val) $extra_vars
Definition: ko.install.php:180
$layout_srl
Definition: ko.install.php:186
set($key, $val, $set_to_get_vars=0)
writeFile($filename, $buff, $mode="w")
widget module&#39;s high class
Definition: widget.class.php:8
moveFile($source, $target)
insertUserLayoutValue($layout_srl, $arr)
$args
Definition: ko.install.php:185
$args extra_vars
Definition: ko.install.php:197
setRedirectUrl($url= './', $output=NULL)
getAdminModel($module_name)
Definition: func.inc.php:156
writeIniFile($filename, $arr)
makeDir($path_string)
removeUserLayoutImage($layout_srl, $filename)
copyDir($source_dir, $target_dir, $filter=null, $type=null)
const _XE_PATH_
Definition: config.inc.php:49
deleteLayout($layout_srl, $force=FALSE)
readFile($filename)
getNextSequence()
Definition: func.inc.php:236
& getInstance()
getModel($module_name)
Definition: func.inc.php:145
insertUserLayoutImage($layout_srl, $source)
executeQueryArray($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:219
getAdminController($module_name)
Definition: func.inc.php:101
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
$oModuleController
Definition: ko.install.php:287
initLayout($layout_srl, $layout_name)
$designInfo layout_srl
Definition: ko.install.php:222
high class of the module module
Definition: module.class.php:8
checkUploadedFile($file)
Definition: func.inc.php:1165