XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
admin.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
12 {
13 
18  function init()
19  {
20  // forbit access if the user is not an administrator
21  $oMemberModel = getModel('member');
22  $logged_info = $oMemberModel->getLoggedInfo();
23  if($logged_info->is_admin != 'Y')
24  {
25  return $this->stop("msg_is_not_administrator");
26  }
27  }
28 
33  function procAdminMenuReset()
34  {
35  $menuSrl = Context::get('menu_srl');
36  if(!$menuSrl)
37  {
38  return $this->stop('msg_invalid_request');
39  }
40 
42  $oCacheHandler = CacheHandler::getInstance('object', null, true);
43  if($oCacheHandler->isSupport())
44  {
45  $cache_key = 'admin_menu_langs:' . Context::getLangType();
46  $oCacheHandler->delete($cache_key);
47  }
48  $output = $oMenuAdminController->deleteMenu($menuSrl);
49  if(!$output->toBool())
50  {
51  return $output;
52  }
53 
54  FileHandler::removeDir('./files/cache/menu/admin_lang/');
55 
56  $this->setRedirectUrl(Context::get('error_return_url'));
57  }
58 
64  {
65  // rename cache dir
66  $temp_cache_dir = './files/cache_' . $_SERVER['REQUEST_TIME'];
67  FileHandler::rename('./files/cache', $temp_cache_dir);
68  FileHandler::makeDir('./files/cache');
69 
70  // remove module extend cache
71  FileHandler::removeFile(_XE_PATH_ . 'files/config/module_extend.php');
72 
73  // remove debug files
74  FileHandler::removeFile(_XE_PATH_ . 'files/_debug_message.php');
75  FileHandler::removeFile(_XE_PATH_ . 'files/_debug_db_query.php');
76  FileHandler::removeFile(_XE_PATH_ . 'files/_slowlog_query.php');
77  FileHandler::removeFile(_XE_PATH_ . 'files/_slowlog_trigger.php');
78  FileHandler::removeFile(_XE_PATH_ . 'files/_slowlog_addon.php');
79  FileHandler::removeFile(_XE_PATH_ . 'files/_slowlog_widget.php');
80 
81  $oModuleModel = getModel('module');
82  $module_list = $oModuleModel->getModuleList();
83 
84  // call recompileCache for each module
85  foreach($module_list as $module)
86  {
87  $oModule = NULL;
88  $oModule = getClass($module->module);
89  if(method_exists($oModule, 'recompileCache'))
90  {
91  $oModule->recompileCache();
92  }
93  }
94 
95  // remove cache
96  $truncated = array();
97  $oObjectCacheHandler = CacheHandler::getInstance('object');
98  $oTemplateCacheHandler = CacheHandler::getInstance('template');
99 
100  if($oObjectCacheHandler->isSupport())
101  {
102  $truncated[] = $oObjectCacheHandler->truncate();
103  }
104 
105  if($oTemplateCacheHandler->isSupport())
106  {
107  $truncated[] = $oTemplateCacheHandler->truncate();
108  }
109 
110  if(count($truncated) && in_array(FALSE, $truncated))
111  {
112  return new BaseObject(-1, 'msg_self_restart_cache_engine');
113  }
114 
115  // remove cache dir
116  $tmp_cache_list = FileHandler::readDir('./files', '/(^cache_[0-9]+)/');
117  if($tmp_cache_list)
118  {
119  foreach($tmp_cache_list as $tmp_dir)
120  {
121  if($tmp_dir)
122  {
123  FileHandler::removeDir('./files/' . $tmp_dir);
124  }
125  }
126  }
127 
128  // remove duplicate indexes (only for CUBRID)
129  $db_type = Context::getDBType();
130  if($db_type == 'cubrid')
131  {
132  $db = DB::getInstance();
133  $db->deleteDuplicateIndexes();
134  }
135 
136  // check autoinstall packages
137  $oAutoinstallAdminController = getAdminController('autoinstall');
138  $oAutoinstallAdminController->checkInstalled();
139 
140  $this->setMessage('success_updated');
141  }
142 
147  function procAdminLogout()
148  {
149  $oMemberController = getController('member');
150  $oMemberController->procMemberLogout();
151 
152  header('Location: ' . getNotEncodedUrl('', 'module', 'admin'));
153  }
154 
156  {
157  $vars = Context::getRequestVars();
158  if(!$vars->site_srl)
159  {
160  $vars->site_srl = 0;
161  }
162 
163  // create a DesignInfo file
164  $output = $this->updateDefaultDesignInfo($vars);
165  return $this->setRedirectUrl(Context::get('error_return_url'), $output);
166  }
167 
168  public function updateDefaultDesignInfo($vars)
169  {
170  $siteDesignPath = _XE_PATH_ . 'files/site_design/';
171 
172  $vars->module_skin = json_decode($vars->module_skin);
173 
174  if(!is_dir($siteDesignPath))
175  {
177  }
178 
179  $siteDesignFile = _XE_PATH_ . 'files/site_design/design_' . $vars->site_srl . '.php';
180 
181  $layoutTarget = 'layout_srl';
182  $skinTarget = 'skin';
183 
184  if($vars->target_type == 'M')
185  {
186  $layoutTarget = 'mlayout_srl';
187  $skinTarget = 'mskin';
188  }
189 
190  if(is_readable($siteDesignFile))
191  {
192  include($siteDesignFile);
193  }
194  else
195  {
196  $designInfo = new stdClass();
197  }
198 
199  $layoutSrl = (!$vars->layout_srl) ? 0 : $vars->layout_srl;
200 
201  $designInfo->{$layoutTarget} = $layoutSrl;
202 
203  foreach($vars->module_skin as $moduleName => $skinName)
204  {
205  if($moduleName == 'ARTICLE')
206  {
207  $moduleName = 'page';
208  }
209 
210  if(!isset($designInfo->module->{$moduleName})) $designInfo->module->{$moduleName} = new stdClass();
211  $designInfo->module->{$moduleName}->{$skinTarget} = $skinName;
212  }
213 
214  $this->makeDefaultDesignFile($designInfo, $vars->site_srl);
215 
216  return new BaseObject();
217  }
218 
219  function makeDefaultDesignFile($designInfo, $site_srl = 0)
220  {
221  $buff = array();
222  $buff[] = '<?php if(!defined("__XE__")) exit();';
223  $buff[] = '$designInfo = new stdClass;';
224 
225  if($designInfo->layout_srl)
226  {
227  $buff[] = sprintf('$designInfo->layout_srl = %s; ', $designInfo->layout_srl);
228  }
229 
230  if($designInfo->mlayout_srl)
231  {
232  $buff[] = sprintf('$designInfo->mlayout_srl = %s;', $designInfo->mlayout_srl);
233  }
234 
235  $buff[] = '$designInfo->module = new stdClass;';
236 
237  foreach($designInfo->module as $moduleName => $skinInfo)
238  {
239  $buff[] = sprintf('$designInfo->module->%s = new stdClass;', $moduleName);
240  foreach($skinInfo as $target => $skinName)
241  {
242  $buff[] = sprintf('$designInfo->module->%s->%s = \'%s\';', $moduleName, $target, $skinName);
243  }
244  }
245 
246  $siteDesignFile = _XE_PATH_ . 'files/site_design/design_' . $site_srl . '.php';
247  FileHandler::writeFile($siteDesignFile, implode(PHP_EOL, $buff));
248  }
249 
255  {
256  $siteSrl = Context::get('site_srl');
257  $moduleName = Context::get('module_name');
258 
259  // check favorite exists
260  $oModel = getAdminModel('admin');
261  $output = $oModel->isExistsFavorite($siteSrl, $moduleName);
262  if(!$output->toBool())
263  {
264  return $output;
265  }
266 
267  // if exists, delete favorite
268  if($output->get('result'))
269  {
270  $favoriteSrl = $output->get('favoriteSrl');
271  $output = $this->_deleteFavorite($favoriteSrl);
272  $result = 'off';
273  }
274  // if not exists, insert favorite
275  else
276  {
277  $output = $this->_insertFavorite($siteSrl, $moduleName);
278  $result = 'on';
279  }
280 
281  if(!$output->toBool())
282  {
283  return $output;
284  }
285 
286  $this->add('result', $result);
287 
288  return $this->setRedirectUrl(Context::get('error_return_url'), $output);
289  }
290 
295  function cleanFavorite()
296  {
297  $oModel = getAdminModel('admin');
298  $output = $oModel->getFavoriteList();
299  if(!$output->toBool())
300  {
301  return $output;
302  }
303 
304  $favoriteList = $output->get('favoriteList');
305  if(!$favoriteList)
306  {
307  return new BaseObject();
308  }
309 
310  $deleteTargets = array();
311  foreach($favoriteList as $favorite)
312  {
313  if($favorite->type == 'module')
314  {
315  $modulePath = _XE_PATH_ . 'modules/' . $favorite->module;
316  if(!is_dir($modulePath))
317  {
318  $deleteTargets[] = $favorite->admin_favorite_srl;
319  }
320  }
321  }
322 
323  if(!count($deleteTargets))
324  {
325  return new BaseObject();
326  }
327 
328  $args = new stdClass();
329  $args->admin_favorite_srls = $deleteTargets;
330  $output = executeQuery('admin.deleteFavorites', $args);
331  if(!$output->toBool())
332  {
333  return $output;
334  }
335 
336  return new BaseObject();
337  }
338 
344  {
345  $isAgree = Context::get('is_agree');
346  if($isAgree == 'true')
347  {
348  $_SESSION['enviroment_gather'] = 'Y';
349  }
350  else
351  {
352  $_SESSION['enviroment_gather'] = 'N';
353  }
354 
355  $redirectUrl = getNotEncodedUrl('', 'module', 'admin');
356  $this->setRedirectUrl($redirectUrl);
357  }
358 
364  {
365  $adminTitle = Context::get('adminTitle');
366  $file = Context::get('adminLogo');
367 
368  $oModuleModel = getModel('module');
369  $oAdminConfig = $oModuleModel->getModuleConfig('admin');
370 
371  if(!is_object($oAdminConfig))
372  {
373  $oAdminConfig = new stdClass();
374  }
375 
376  if($file['tmp_name'])
377  {
378  $target_path = 'files/attach/images/admin/';
379  FileHandler::makeDir($target_path);
380 
381  // Get file information
382  list($width, $height, $type, $attrs) = @getimagesize($file['tmp_name']);
383  if($type == 3)
384  {
385  $ext = 'png';
386  }
387  elseif($type == 2)
388  {
389  $ext = 'jpg';
390  }
391  else
392  {
393  $ext = 'gif';
394  }
395 
396  $target_filename = sprintf('%s%s.%s.%s', $target_path, 'adminLogo', date('YmdHis'), $ext);
397  @move_uploaded_file($file['tmp_name'], $target_filename);
398 
399  $oAdminConfig->adminLogo = $target_filename;
400  }
401  if($adminTitle)
402  {
403  $oAdminConfig->adminTitle = strip_tags($adminTitle);
404  }
405  else
406  {
407  unset($oAdminConfig->adminTitle);
408  }
409 
410  if($oAdminConfig)
411  {
412  $oModuleController = getController('module');
413  $oModuleController->insertModuleConfig('admin', $oAdminConfig);
414  }
415 
416  $this->setMessage('success_updated', 'info');
417 
418  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdminSetup');
419  $this->setRedirectUrl($returnUrl);
420  }
421 
427  {
428  $oModuleModel = getModel('module');
429  $oAdminConfig = $oModuleModel->getModuleConfig('admin');
430 
431  FileHandler::removeFile(_XE_PATH_ . $oAdminConfig->adminLogo);
432  unset($oAdminConfig->adminLogo);
433 
434  $oModuleController = getController('module');
435  $oModuleController->insertModuleConfig('admin', $oAdminConfig);
436 
437  $this->setMessage('success_deleted', 'info');
438 
439  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdminSetup');
440  $this->setRedirectUrl($returnUrl);
441  }
442 
447  function _insertFavorite($siteSrl, $module, $type = 'module')
448  {
449  $args = new stdClass();
450  $args->adminFavoriteSrl = getNextSequence();
451  $args->site_srl = $siteSrl;
452  $args->module = $module;
453  $args->type = $type;
454  $output = executeQuery('admin.insertFavorite', $args);
455  return $output;
456  }
457 
462  function _deleteFavorite($favoriteSrl)
463  {
464  $args = new stdClass();
465  $args->admin_favorite_srl = $favoriteSrl;
466  $output = executeQuery('admin.deleteFavorite', $args);
467  return $output;
468  }
469 
475  {
476  $args = new stdClass;
477  $output = executeQuery('admin.deleteAllFavorite', $args);
478  return $output;
479  }
480 
486  {
487 
488  $site_info = Context::get('site_module_info');
489  $virtual_site = '';
490  if($site_info->site_srl)
491  {
492  $virtual_site = $site_info->site_srl . '/';
493  }
494 
495  $iconname = Context::get('iconname');
496  $file_exist = FileHandler::readFile(_XE_PATH_ . 'files/attach/xeicon/' . $virtual_site . $iconname);
497  if($file_exist)
498  {
499  @FileHandler::removeFile(_XE_PATH_ . 'files/attach/xeicon/' . $virtual_site . $iconname);
500  }
501  else
502  {
503  return new BaseObject(-1, 'fail_to_delete');
504  }
505  $this->setMessage('success_deleted');
506  }
507 
509  {
510  $vars = Context::getRequestVars();
511  $oInstallController = getController('install');
512 
513  $db_info = Context::getDBInfo();
514 
515  $db_info->use_sitelock = ($vars->use_sitelock) ? $vars->use_sitelock : 'N';
516  $db_info->sitelock_title = $vars->sitelock_title;
517  $db_info->sitelock_message = $vars->sitelock_message;
518 
519  $whitelist = $vars->sitelock_whitelist;
520  $whitelist = preg_replace("/[\r|\n|\r\n]+/",",",$whitelist);
521  $whitelist = preg_replace("/\s+/","",$whitelist);
522  if(preg_match('/(<\?|<\?php|\?>)/xsm', $whitelist))
523  {
524  $whitelist = '';
525  }
526  $whitelist .= ',127.0.0.1,' . $_SERVER['REMOTE_ADDR'];
527  $whitelist = explode(',',trim($whitelist, ','));
528  $whitelist = array_unique($whitelist);
529 
530  if(!IpFilter::validate($whitelist)) {
531  return new BaseObject(-1, 'msg_invalid_ip');
532  }
533 
534  $db_info->sitelock_whitelist = $whitelist;
535 
536  $oInstallController = getController('install');
537  if(!$oInstallController->makeConfigFile())
538  {
539  return new BaseObject(-1, 'msg_invalid_request');
540  }
541 
542  if(!in_array(Context::getRequestMethod(), array('XMLRPC','JSON')))
543  {
544  $returnUrl = Context::get('success_return_url');
545  if(!$returnUrl) $returnUrl = getNotEncodedUrl('', 'act', 'dispAdminConfigGeneral');
546  header('location:' . $returnUrl);
547  return;
548  }
549  }
550 
552  {
553  $vars = Context::getRequestVars();
554 
555  $db_info = Context::getDBInfo();
556 
557  $white_object = $vars->embed_white_object;
558  $white_object = preg_replace("/[\r\n|\r|\n]+/", '|@|', $white_object);
559  $white_object = preg_replace("/[\s\'\"]+/", '', $white_object);
560  $white_object = explode('|@|', $white_object);
561  $white_object = array_unique($white_object);
562 
563  $white_iframe = $vars->embed_white_iframe;
564  $white_iframe = preg_replace("/[\r\n|\r|\n]+/", '|@|', $white_iframe);
565  $white_iframe = preg_replace("/[\s\'\"]+/", '', $white_iframe);
566  $white_iframe = explode('|@|', $white_iframe);
567  $white_iframe = array_unique($white_iframe);
568 
569  $whitelist = new stdClass;
570  $whitelist->object = $white_object;
571  $whitelist->iframe = $white_iframe;
572 
573  $db_info->embed_white_object = $white_object;
574  $db_info->embed_white_iframe = $white_iframe;
575 
576  $oInstallController = getController('install');
577  if(!$oInstallController->makeConfigFile())
578  {
579  return new BaseObject(-1, 'msg_invalid_request');
580  }
581 
582  require_once(_XE_PATH_ . 'classes/security/EmbedFilter.class.php');
583  $oEmbedFilter = EmbedFilter::getInstance();
584  $oEmbedFilter->_makeWhiteDomainList($whitelist);
585 
586  if(!in_array(Context::getRequestMethod(), array('XMLRPC','JSON')))
587  {
588  $returnUrl = Context::get('success_return_url');
589  if(!$returnUrl) $returnUrl = getNotEncodedUrl('', 'act', 'dispAdminConfigGeneral');
590  header('location:' . $returnUrl);
591  return;
592  }
593  }
594 
595 }
596 /* End of file admin.admin.controller.php */
597 /* Location: ./modules/admin/admin.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
$designInfo
Definition: ko.install.php:221
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
$oMenuAdminController
Definition: ko.install.php:7
removeFile($filename)
$output
Definition: ko.install.php:193
& getInstance($target= 'object', $info=null, $always_use_file=false)
validate($ip_list=array())
getNotEncodedUrl()
Definition: func.inc.php:316
writeFile($filename, $buff, $mode="w")
rename($source, $target)
$args
Definition: ko.install.php:185
_insertFavorite($siteSrl, $module, $type= 'module')
setRedirectUrl($url= './', $output=NULL)
$siteDesignPath
Definition: ko.install.php:217
getAdminModel($module_name)
Definition: func.inc.php:156
getInstance($db_type=NULL)
Definition: DB.class.php:142
makeDir($path_string)
makeDefaultDesignFile($designInfo, $site_srl=0)
const _XE_PATH_
Definition: config.inc.php:49
readFile($filename)
getNextSequence()
Definition: func.inc.php:236
getModel($module_name)
Definition: func.inc.php:145
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
$module
Class name of Xe Module that is identified by mid.
$oModuleController
Definition: ko.install.php:287
getClass($module_name)
Definition: func.inc.php:189