XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
ModuleObject.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
3 
9 class ModuleObject extends BaseObject
10 {
11 
12  var $mid = NULL;
13  var $module = NULL;
14  var $module_srl = NULL;
15  var $module_info = NULL;
16  var $origin_module_info = NULL;
17  var $xml_info = NULL;
18  var $module_path = NULL;
19  var $act = NULL;
20  var $template_path = NULL;
21  var $template_file = NULL;
22  var $layout_path = '';
23  var $layout_file = '';
25  var $stop_proc = FALSE;
26  var $module_config = NULL;
27  var $ajaxRequestMethod = array('XMLRPC', 'JSON');
28  var $gzhandler_enable = TRUE;
29 
35  function setModule($module)
36  {
37  $this->module = $module;
38  }
39 
45  function setModulePath($path)
46  {
47  if(substr_compare($path, '/', -1) !== 0)
48  {
49  $path.='/';
50  }
51  $this->module_path = $path;
52  }
53 
60  function setRedirectUrl($url = './', $output = NULL)
61  {
62  $ajaxRequestMethod = array_flip($this->ajaxRequestMethod);
64  {
65  $this->add('redirect_url', $url);
66  }
67 
68  if($output !== NULL && is_object($output))
69  {
70  return $output;
71  }
72  }
73 
78  function getRedirectUrl()
79  {
80  return $this->get('redirect_url');
81  }
82 
89  function setMessage($message = 'success', $type = NULL)
90  {
91  parent::setMessage($message);
92  $this->setMessageType($type);
93  }
94 
100  function setMessageType($type)
101  {
102  $this->add('message_type', $type);
103  }
104 
109  function getMessageType()
110  {
111  $type = $this->get('message_type');
112  $typeList = array('error' => 1, 'info' => 1, 'update' => 1);
113  if(!isset($typeList[$type]))
114  {
115  $type = $this->getError() ? 'error' : 'info';
116  }
117  return $type;
118  }
119 
126  function setRefreshPage()
127  {
128  $this->setTemplatePath('./common/tpl');
129  $this->setTemplateFile('refresh');
130  }
131 
137  function setAct($act)
138  {
139  $this->act = $act;
140  }
141 
149  {
150  // The default variable settings
151  $this->mid = $module_info->mid;
152  $this->module_srl = $module_info->module_srl;
153  $this->module_info = $module_info;
154  $this->origin_module_info = $module_info;
155  $this->xml_info = $xml_info;
156  $this->skin_vars = $module_info->skin_vars;
157  // validate certificate info and permission settings necessary in Web-services
158  $is_logged = Context::get('is_logged');
159  $logged_info = Context::get('logged_info');
160  // module model create an object
161  $oModuleModel = getModel('module');
162  // permission settings. access, manager(== is_admin) are fixed and privilege name in XE
163  $module_srl = Context::get('module_srl');
164  if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl))
165  {
166  $request_module = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
167  if($request_module->module_srl == $module_srl)
168  {
169  $grant = $oModuleModel->getGrant($request_module, $logged_info);
170  }
171  }
172  else
173  {
174  $grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info);
175  // have at least access grant
176  if(substr_count($this->act, 'Member') || substr_count($this->act, 'Communication'))
177  {
178  $grant->access = 1;
179  }
180  }
181  // display no permission if the current module doesn't have an access privilege
182  //if(!$grant->access) return $this->stop("msg_not_permitted");
183  // checks permission and action if you don't have an admin privilege
184  if(!$grant->manager)
185  {
186  // get permission types(guest, member, manager, root) of the currently requested action
187  $permission_target = $xml_info->permission->{$this->act};
188  // check manager if a permission in module.xml otherwise action if no permission
189  if(!$permission_target && substr_count($this->act, 'Admin'))
190  {
191  $permission_target = 'manager';
192  }
193  // Check permissions
194  switch($permission_target)
195  {
196  case 'root' :
197  case 'manager' :
198  $this->stop('msg_is_not_administrator');
199  return;
200  case 'member' :
201  if(!$is_logged)
202  {
203  $this->stop('msg_not_permitted_act');
204  return;
205  }
206  break;
207  }
208  }
209  // permission variable settings
210  $this->grant = $grant;
211 
212  Context::set('grant', $grant);
213 
214  $this->module_config = $oModuleModel->getModuleConfig($this->module, $module_info->site_srl);
215 
216  if(method_exists($this, 'init'))
217  {
218  $this->init();
219  }
220  }
221 
227  function stop($msg_code)
228  {
229  // flag setting to stop the proc processing
230  $this->stop_proc = TRUE;
231  // Error handling
232  $this->setError(-1);
233  $this->setMessage($msg_code);
234  // Error message display by message module
235  $type = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
236  $oMessageObject = ModuleHandler::getModuleInstance('message', $type);
237  $oMessageObject->setError(-1);
238  $oMessageObject->setMessage($msg_code);
239  $oMessageObject->dispMessage();
240 
241  $this->setTemplatePath($oMessageObject->getTemplatePath());
242  $this->setTemplateFile($oMessageObject->getTemplateFile());
243 
244  return $this;
245  }
246 
252  function setTemplateFile($filename)
253  {
254  if(isset($filename) && substr_compare($filename, '.html', -5) !== 0)
255  {
256  $filename .= '.html';
257  }
258  $this->template_file = $filename;
259  }
260 
265  function getTemplateFile()
266  {
267  return $this->template_file;
268  }
269 
275  function setTemplatePath($path)
276  {
277  if(!$path) return;
278 
279  if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
280  {
281  $path = './' . $path;
282  }
283 
284  if(substr_compare($path, '/', -1) !== 0)
285  {
286  $path .= '/';
287  }
288  $this->template_path = $path;
289  }
290 
295  function getTemplatePath()
296  {
297  return $this->template_path;
298  }
299 
305  function setEditedLayoutFile($filename)
306  {
307  if(!$filename) return;
308 
309  if(substr_compare($filename, '.html', -5) !== 0)
310  {
311  $filename .= '.html';
312  }
313  $this->edited_layout_file = $filename;
314  }
315 
321  {
322  return $this->edited_layout_file;
323  }
324 
330  function setLayoutFile($filename)
331  {
332  if(!$filename) return;
333 
334  if(substr_compare($filename, '.html', -5) !== 0)
335  {
336  $filename .= '.html';
337  }
338  $this->layout_file = $filename;
339  }
340 
345  function getLayoutFile()
346  {
347  return $this->layout_file;
348  }
349 
354  function setLayoutPath($path)
355  {
356  if(!$path) return;
357 
358  if((strlen($path) >= 1 && substr_compare($path, '/', 0, 1) !== 0) && (strlen($path) >= 2 && substr_compare($path, './', 0, 2) !== 0))
359  {
360  $path = './' . $path;
361  }
362  if(substr_compare($path, '/', -1) !== 0)
363  {
364  $path .= '/';
365  }
366  $this->layout_path = $path;
367  }
368 
373  function getLayoutPath($layout_name = "", $layout_type = "P")
374  {
375  return $this->layout_path;
376  }
377 
382  function proc()
383  {
384  // pass if stop_proc is true
385  if($this->stop_proc)
386  {
387  debugPrint($this->message, 'ERROR');
388  return FALSE;
389  }
390 
391  // trigger call
392  $triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'before', $this);
393  if(!$triggerOutput->toBool())
394  {
395  $this->setError($triggerOutput->getError());
396  $this->setMessage($triggerOutput->getMessage());
397  return FALSE;
398  }
399 
400  // execute an addon(call called_position as before_module_proc)
401  $called_position = 'before_module_proc';
402  $oAddonController = getController('addon');
403  $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
404  if(FileHandler::exists($addon_file)) include($addon_file);
405 
406  if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act))
407  {
408  // Check permissions
409  if($this->module_srl && !$this->grant->access)
410  {
411  $this->stop("msg_not_permitted_act");
412  return FALSE;
413  }
414 
415  // integrate skin information of the module(change to sync skin info with the target module only by seperating its table)
416  $is_default_skin = ((!Mobile::isFromMobilePhone() && $this->module_info->is_skin_fix == 'N') || (Mobile::isFromMobilePhone() && $this->module_info->is_mskin_fix == 'N'));
417  $usedSkinModule = !($this->module == 'page' && ($this->module_info->page_type == 'OUTSIDE' || $this->module_info->page_type == 'WIDGET'));
418  if($usedSkinModule && $is_default_skin && $this->module != 'admin' && strpos($this->act, 'Admin') === false && $this->module == $this->module_info->module)
419  {
420  $dir = (Mobile::isFromMobilePhone()) ? 'm.skins' : 'skins';
421  $valueName = (Mobile::isFromMobilePhone()) ? 'mskin' : 'skin';
422  $oModuleModel = getModel('module');
423  $skinType = (Mobile::isFromMobilePhone()) ? 'M' : 'P';
424  $skinName = $oModuleModel->getModuleDefaultSkin($this->module, $skinType);
425  if($this->module == 'page')
426  {
427  $this->module_info->{$valueName} = $skinName;
428  }
429  else
430  {
431  $isTemplatPath = (strpos($this->getTemplatePath(), '/tpl/') !== FALSE);
432  if(!$isTemplatPath)
433  {
434  $this->setTemplatePath(sprintf('%s%s/%s/', $this->module_path, $dir, $skinName));
435  }
436  }
437  }
438 
439  $oModuleModel = getModel('module');
440  $oModuleModel->syncSkinInfoToModuleInfo($this->module_info);
441  Context::set('module_info', $this->module_info);
442  // Run
443  $output = $this->{$this->act}();
444  }
445  else
446  {
447  return FALSE;
448  }
449 
450  // trigger call
451  $triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'after', $this);
452  if(!$triggerOutput->toBool())
453  {
454  $this->setError($triggerOutput->getError());
455  $this->setMessage($triggerOutput->getMessage());
456  return FALSE;
457  }
458 
459  // execute an addon(call called_position as after_module_proc)
460  $called_position = 'after_module_proc';
461  $oAddonController = getController('addon');
462  $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
463  if(FileHandler::exists($addon_file)) include($addon_file);
464 
465  if(is_a($output, 'BaseObject') || is_subclass_of($output, 'BaseObject'))
466  {
467  $this->setError($output->getError());
468  $this->setMessage($output->getMessage());
469 
470  if(!$output->toBool())
471  {
472  return FALSE;
473  }
474  }
475  // execute api methods of the module if view action is and result is XMLRPC or JSON
476  if($this->module_info->module_type == 'view' || $this->module_info->module_type == 'mobile')
477  {
478  if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON')
479  {
480  $oAPI = getAPI($this->module_info->module, 'api');
481  if(method_exists($oAPI, $this->act))
482  {
483  $oAPI->{$this->act}($this);
484  }
485  }
486  }
487  return TRUE;
488  }
489 
490 }
491 /* End of file ModuleObject.class.php */
492 /* Location: ./classes/module/ModuleObject.class.php */
setTemplateFile($filename)
$oModuleModel
Definition: ko.install.php:236
setMessage($message= 'success', $type=NULL)
& getModuleInstance($module, $type= 'view', $kind= '')
getController($module_name)
Definition: func.inc.php:90
$template_path
a path of directory where template files reside
debugPrint($debug_output=NULL, $display_option=TRUE, $file= '_debug_message.php')
Definition: func.inc.php:805
$output
Definition: ko.install.php:193
add($key, $val)
$act
a string value to contain the action name
setLayoutFile($filename)
set($key, $val, $set_to_get_vars=0)
getLayoutPath($layout_name="", $layout_type="P")
high class of message module
$template_file
name of template file
$stop_proc
a flag to indicating whether to stop the execution of code.
$xml_info
an object containing the module description extracted from XML file
$module_path
a path to directory where module source code resides
$module_srl
integer value to represent a run-time instance of Module (XE Module)
$edited_layout_file
name of temporary layout files that is modified in an admin mode
setModuleInfo($module_info, $xml_info)
$module_info
an object containing the module information
$layout_path
a path of directory where layout files reside
$mid
string to represent run-time instance of Module (XE Module)
setRedirectUrl($url= './', $output=NULL)
isFromMobilePhone()
getAPI($module_name)
Definition: func.inc.php:167
$obj module_srl
Definition: ko.install.php:270
getModel($module_name)
Definition: func.inc.php:145
$module
Class name of Xe Module that is identified by mid.
setEditedLayoutFile($filename)
triggerCall($trigger_name, $called_position, &$obj)
$layout_file
name of layout file
high class of the module module
Definition: module.class.php:8