XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
page.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class pageAdminController extends page
9 {
13  function init()
14  {
15  }
16 
21  {
22  // Create model/controller object of the module module
24  $oModuleModel = getModel('module');
25  // Set board module
27  $args->module = 'page';
28  $args->mid = $args->page_name; //because if mid is empty in context, set start page mid
29  $args->path = (!$args->path) ? '' : $args->path;
30  $args->mpath = (!$args->mpath) ? '' : $args->mpath;
31  unset($args->page_name);
32 
33  if($args->use_mobile != 'Y') $args->use_mobile = '';
34  // Check if an original module exists by using module_srl
35  if($args->module_srl)
36  {
37  $columnList = array('module_srl');
38  $module_info = $oModuleModel->getModuleInfoByModuleSrl($args->module_srl, $columnList);
39  if($module_info->module_srl != $args->module_srl)
40  {
41  unset($args->module_srl);
42  }
43  else
44  {
45  foreach($args as $key=>$val)
46  {
47  $module_info->{$key} = $val;
48  }
50  }
51  }
52 
53  switch ($args->page_type)
54  {
55  case 'WIDGET' :
56  {
57  unset($args->skin);
58  unset($args->mskin);
59  unset($args->path);
60  unset($args->mpath);
61  break;
62  }
63  case 'ARTICLE' :
64  {
65  unset($args->page_caching_interval);
66  unset($args->path);
67  unset($args->mpath);
68  break;
69  }
70  case 'OUTSIDE' :
71  {
72  unset($args->skin);
73  unset($args->mskin);
74  break;
75  }
76  }
77  // Insert/update depending on module_srl
78  if(!$args->module_srl)
79  {
80  $output = $oModuleController->insertModule($args);
81  $msg_code = 'success_registed';
82  }
83  else
84  {
85  $output = $oModuleController->updateModule($args);
86  $msg_code = 'success_updated';
87  }
88 
89  if(!$output->toBool()) return $output;
90 
91  $this->add("page", Context::get('page'));
92  $this->add('module_srl',$output->get('module_srl'));
93  $this->setMessage($msg_code);
94 
95  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'module_srl', $output->get('module_srl'), 'act', 'dispPageAdminInfo');
96  $this->setRedirectUrl($returnUrl);
97  }
98 
103  {
104  $this->procPageAdminInsert();
105  }
106 
107  function putDocumentsInPageToArray($target, &$array)
108  {
109  if(!$target) return;
110  preg_match_all('!<img hasContent="true" ([^>]+)!is', $target, $matches);
111  $pattern = '!document_srl="(\d+)"!';
112  foreach($matches[1] as $match)
113  {
114  $match2 = null;
115  preg_match($pattern, $match, $match2);
116  if(count($match2))
117  {
118  $array[(int)$match2[1]] = 1;
119  }
120  }
121  }
122 
127  {
128  $module_srl = Context::get('module_srl');
129  $content = Context::get('content');
130  if(!$module_srl) return new BaseObject(-1,'msg_invalid_request');
131  $mcontent = Context::get('mcontent');
132  $type = Context::get('type');
133  // Guhaeom won information page
134  $oModuleModel = getModel('module');
135  $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
136  if($type == "mobile")
137  {
138  if(!$mcontent) $mcontent = '';
139  $module_info->mcontent = $mcontent;
140  }
141  else
142  {
143  if(!isset($content)) $content ='';
144  $module_info->content = $content;
145  }
146 
147  $document_srls = array();
148  $this->putDocumentsInPageToArray($module_info->content, $document_srls);
149  $this->putDocumentsInPageToArray($module_info->mcontent, $document_srls);
150 
151  $oDocumentModel = getModel('document');
152  $oDocumentController = getController('document');
153  $obj = new stdClass();
154  $obj->module_srl = $module_srl;
155  $obj->list_count = 99999999;
156  $output = $oDocumentModel->getDocumentList($obj);
157  if(count($output->data))
158  {
159  foreach($output->data as $document)
160  {
161  if($document_srls[$document->document_srl]) continue;
162  $oDocumentController->deleteDocument($document->document_srl, true);
163  }
164  }
165  // Creates an object of the controller module module
166  $oModuleController = getController('module');
167  // Save
168  $output = $oModuleController->updateModule($module_info);
169  if(!$output->toBool()) return $output;
170  // On the page, change the validity status of the attached file
171  $oFileController = getController('file');
172  $oFileController->setFilesValid($module_info->module_srl);
173 
174  $this->add("module_srl", $module_info->module_srl);
175  $this->add("page", Context::get('page'));
176  $this->add("mid", $module_info->mid);
177  $this->setMessage($msg_code);
178 
179  // Create cache file
180  $this->procPageAdminRemoveWidgetCache();
181  }
182 
187  {
188  $module_srl = Context::get('module_srl');
189  // Get an original
190  $oModuleController = getController('module');
191  $output = $oModuleController->deleteModule($module_srl);
192  if(!$output->toBool()) return $output;
193 
194  $this->add('module','page');
195  $this->add('page',Context::get('page'));
196  $this->setMessage('success_deleted');
197 
198  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispPageAdminContent');
199  $this->setRedirectUrl($returnUrl);
200  }
201 
206  {
207  // Get the basic information
209  // Insert by creating the module Controller object
210  $oModuleController = getController('module');
211  $output = $oModuleController->insertModuleConfig('page',$args);
212  return $output;
213  }
214 
218  function procUploadFile()
219  {
220  // Basic variables setting
221  $upload_target_srl = Context::get('upload_target_srl');
222  $module_srl = Context::get('module_srl');
223  // Create the controller object file class
224  $oFileController = getController('file');
225  $output = $oFileController->insertFile($module_srl, $upload_target_srl);
226  // Attachment to the output of the list, java script
227  $oFileController->printUploadedFileList($upload_target_srl);
228  }
229 
234  function procDeleteFile()
235  {
236  // Basic variable setting(upload_target_srl and module_srl set)
237  $upload_target_srl = Context::get('upload_target_srl');
238  $module_srl = Context::get('module_srl');
239  $file_srl = Context::get('file_srl');
240  // Create the controller object file class
241  $oFileController = getController('file');
242  if($file_srl) $output = $oFileController->deleteFile($file_srl, $this->grant->manager);
243  // Attachment to the output of the list, java script
244  $oFileController->printUploadedFileList($upload_target_srl);
245  }
246 
251  {
252  $module_srl = Context::get('module_srl');
253 
254  if(!$module_srl) return;
255 
256  $oModuleModel = getModel('module');
257  $columnList = array('module_srl', 'content');
258  $module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
259 
260  $content = $module_info->content;
261 
262  // widget controller re-run of the cache files
263  $oWidgetController = getController('widget');
264  $oWidgetController->recompileWidget($content);
265 
266  if($module_info->page_type == 'WIDGET')
267  {
268  $path = _XE_PATH_ . 'files/cache/page/';
269  $cache_files = FileHandler::readDir($path, '/^' . $module_info->module_srl . '\./');
270  foreach($cache_files as $file_name)
271  {
272  FileHandler::removeFile($path . $module_info->module_srl . '.' . $file_name);
273  }
274  }
275  else if($module_info->page_type == 'OUTSIDE')
276  {
277  $path = _XE_PATH_ . 'files/cache/page/';
278  $cache_files = FileHandler::readDir($path, '/^' . $module_info->module_srl . './');
279  foreach($cache_files as $file_name)
280  {
281  FileHandler::removeFile($path . $module_info->module_srl . '.' . $file_name);
282  }
283  }
284 
285  $oCacheHandler = CacheHandler::getInstance('object', null, true);
286  if($oCacheHandler->isSupport())
287  {
288  $object_key = 'mid_info:' . $module_info->module_srl;
289  $cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
290  $oCacheHandler->delete($cache_key);
291  }
292  }
293 
295  {
296  $oDocumentModel = getModel('document');
297  $oDocumentController = getController('document');
298 
299  $logged_info = Context::get('logged_info');
300 
301  $oModuleModel = getModel('module');
302  $grant = $oModuleModel->getGrant($this->module_info, $logged_info);
303 
304  if(!$grant->manager)
305  {
306  return new BaseObject(-1, 'msg_not_permitted');
307  }
308 
310  $obj->module_srl = $this->module_info->module_srl;
311  $obj->is_notice = 'N';
312 
313  settype($obj->title, "string");
314  if($obj->title == '') $obj->title = cut_str(strip_tags($obj->content),20,'...');
315  //그래도 없으면 Untitled
316  if($obj->title == '') $obj->title = 'Untitled';
317 
318  $document_srl = $obj->document_srl;
319 
320  // 이미 존재하는 글인지 체크
321  $oDocument = $oDocumentModel->getDocument($obj->document_srl, true);
322 
323  $bAnonymous = false;
324  $target = ($obj->ismobile == 'Y') ? 'mdocument_srl' : 'document_srl';
325 
326  // 이미 존재하는 경우 수정
327  if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
328  {
329  $output = $oDocumentController->updateDocument($oDocument, $obj);
330  $msg_code = 'success_updated';
331  }
332  else
333  {
334  // 그렇지 않으면 신규 등록
335  $output = $oDocumentController->insertDocument($obj, $bAnonymous);
336  $msg_code = 'success_registed';
337  $document_srl = $output->get('document_srl');
338  }
339 
340  if(!isset($this->module_info->{$target}) || (isset($this->module_info->{$target}) && $this->module_info->{$target} !== $document_srl))
341  {
342  $oModuleController = getController('module');
343  $this->module_info->{$target} = $document_srl;
344  $oModuleController->updateModule($this->module_info);
345  }
346 
347  // 오류 발생시 멈춤
348  if(!$output->toBool()) return $output;
349 
350  // 결과를 리턴
351  $this->add('mid', Context::get('mid'));
352  $this->add('document_srl', $output->get('document_srl'));
353  $this->add('is_mobile', $obj->ismobile);
354 
355  // 성공 메세지 등록
356  $this->setMessage($msg_code);
357  }
358 }
359 /* End of file page.admin.controller.php */
360 /* Location: ./modules/page/page.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
procPageAdminRemoveWidgetCache()
Clear widget cache files of the specified page.
procPageAdminInsertConfig()
Additional pages of basic information.
removeFile($filename)
procPageAdminInsertContent()
Save page edits.
$obj
Definition: ko.install.php:262
$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)
high class of the module page
Definition: page.class.php:8
getNotEncodedUrl()
Definition: func.inc.php:316
procPageAdminDelete()
Delete page.
$args
Definition: ko.install.php:185
$module_info
an object containing the module information
setRedirectUrl($url= './', $output=NULL)
page of the module admin controller class
$document_srl
Definition: ko.install.php:279
$oDocumentModel
Definition: ko.install.php:259
const _XE_PATH_
Definition: config.inc.php:49
$oDocumentController
Definition: ko.install.php:260
getModel($module_name)
Definition: func.inc.php:145
readDir($path, $filter= '', $to_lower=FALSE, $concat_prefix=FALSE)
$module_srl
Definition: ko.install.php:254
cut_str($string, $cut_size=0, $tail= '...')
Definition: func.inc.php:508
putDocumentsInPageToArray($target, &$array)
$oModuleController
Definition: ko.install.php:287
procPageAdminInsert()
Add a Page.
procPageAdminUpdate()
Page Modify.
procDeleteFile()
Delete the attachment Delete individual files in the editor using.
procUploadFile()
Upload attachments.