issue 2119. supporting php 5.4. module classes.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12691 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-05 02:17:43 +00:00
parent 9aa87c343f
commit 2383b8d711
2 changed files with 1475 additions and 1221 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,12 @@
<?php
/**
/**
* @class ModuleObject
* @author NHN (developers@xpressengine.com)
* base class of ModuleHandler
**/
class ModuleObject extends Object {
* */
class ModuleObject extends Object
{
var $mid = NULL; ///< string to represent run-time instance of Module (XE Module)
var $module = NULL; ///< Class name of Xe Module that is identified by mid
@ -13,31 +14,25 @@
var $module_info = NULL; ///< an object containing the module information
var $origin_module_info = NULL;
var $xml_info = NULL; ///< an object containing the module description extracted from XML file
var $module_path = NULL; ///< a path to directory where module source code resides
var $act = NULL; ///< a string value to contain the action name
var $template_path = NULL; ///< a path of directory where template files reside
var $template_file = NULL; ///< name of template file
var $layout_path = ''; ///< a path of directory where layout files reside
var $layout_file = ''; ///< name of layout file
var $edited_layout_file = ''; ///< name of temporary layout files that is modified in an admin mode
var $stop_proc = false; ///< a flag to indicating whether to stop the execution of code.
var $module_config = NULL;
var $ajaxRequestMethod = array('XMLRPC', 'JSON');
var $gzhandler_enable = TRUE;
/**
* setter to set the name of module
* @param string $module name of module
* @return void
**/
function setModule($module) {
* */
function setModule($module)
{
$this->module = $module;
}
@ -45,9 +40,13 @@
* setter to set the name of module path
* @param string $path the directory path to a module directory
* @return void
**/
function setModulePath($path) {
if(substr($path,-1)!='/') $path.='/';
* */
function setModulePath($path)
{
if(substr($path, -1) != '/')
{
$path.='/';
}
$this->module_path = $path;
}
@ -56,8 +55,9 @@
* @param string $url url for redirection
* @remark redirect_url is used only for ajax requests
* @return void
**/
function setRedirectUrl($url='./', $output = NULL) {
* */
function setRedirectUrl($url = './', $output = NULL)
{
$ajaxRequestMethod = array_flip($this->ajaxRequestMethod);
if(!isset($ajaxRequestMethod[Context::getRequestMethod()]))
{
@ -73,8 +73,9 @@
/**
* get url for redirection
* @return string redirect_url
**/
function getRedirectUrl(){
* */
function getRedirectUrl()
{
return $this->get('redirect_url');
}
@ -83,8 +84,9 @@
* @param string $message a message string
* @param string $type type of message (error, info, update)
* @return void
**/
function setMessage($message, $type = null){
* */
function setMessage($message, $type = NULL)
{
parent::setMessage($message);
$this->setMessageType($type);
}
@ -93,20 +95,23 @@
* set type of message
* @param string $type type of message (error, info, update)
* @return void
**/
function setMessageType($type){
* */
function setMessageType($type)
{
$this->add('message_type', $type);
}
/**
* get type of message
* @return string $type
**/
function getMessageType(){
* */
function getMessageType()
{
$type = $this->get('message_type');
$typeList = array('error'=>1, 'info'=>1, 'update'=>1);
if (!isset($typeList[$type])){
$type = $this->getError()?'error':'info';
$typeList = array('error' => 1, 'info' => 1, 'update' => 1);
if(!isset($typeList[$type]))
{
$type = $this->getError() ? 'error' : 'info';
}
return $type;
}
@ -116,19 +121,20 @@
* refresh.html is executed as a result of method execution
* Tpl as the common run of the refresh.html ..
* @return void
**/
function setRefreshPage() {
* */
function setRefreshPage()
{
$this->setTemplatePath('./common/tpl');
$this->setTemplateFile('refresh');
}
/**
* sett to set the action name
* @param string $act
* @return void
**/
function setAct($act) {
* */
function setAct($act)
{
$this->act = $act;
}
@ -137,8 +143,9 @@
* @param object $module_info object containing module information
* @param object $xml_info object containing module description
* @return void
**/
function setModuleInfo($module_info, $xml_info) {
* */
function setModuleInfo($module_info, $xml_info)
{
// The default variable settings
$this->mid = $module_info->mid;
$this->module_srl = $module_info->module_srl;
@ -150,30 +157,41 @@
$is_logged = Context::get('is_logged');
$logged_info = Context::get('logged_info');
// module model create an object
$oModuleModel = &getModel('module');
$oModuleModel = getModel('module');
// permission settings. access, manager(== is_admin) are fixed and privilege name in XE
$module_srl = Context::get('module_srl');
if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/',$module_srl)) {
if(!$module_info->mid && !is_array($module_srl) && preg_match('/^([0-9]+)$/', $module_srl))
{
$request_module = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
if($request_module->module_srl == $module_srl) {
if($request_module->module_srl == $module_srl)
{
$grant = $oModuleModel->getGrant($request_module, $logged_info);
}
} else {
}
else
{
$grant = $oModuleModel->getGrant($module_info, $logged_info, $xml_info);
// have at least access grant
if( substr_count($this->act, 'Member') || substr_count($this->act, 'Communication'))
if(substr_count($this->act, 'Member') || substr_count($this->act, 'Communication'))
{
$grant->access = 1;
}
}
// display no permission if the current module doesn't have an access privilege
//if(!$grant->access) return $this->stop("msg_not_permitted");
// checks permission and action if you don't have an admin privilege
if(!$grant->manager) {
if(!$grant->manager)
{
// get permission types(guest, member, manager, root) of the currently requested action
$permission_target = $xml_info->permission->{$this->act};
// check manager if a permission in module.xml otherwise action if no permission
if(!$permission_target && substr_count($this->act, 'Admin')) $permission_target = 'manager';
if(!$permission_target && substr_count($this->act, 'Admin'))
{
$permission_target = 'manager';
}
// Check permissions
switch($permission_target) {
switch($permission_target)
{
case 'root' :
case 'manager' :
$this->stop('msg_is_not_administrator');
@ -194,23 +212,27 @@
$this->module_config = $oModuleModel->getModuleConfig($this->module, $module_info->site_srl);
if(method_exists($this, 'init')) $this->init();
if(method_exists($this, 'init'))
{
$this->init();
}
}
/**
* set the stop_proc and approprate message for msg_code
* @param string $msg_code an error code
* @return ModuleObject $this
**/
function stop($msg_code) {
* */
function stop($msg_code)
{
// flag setting to stop the proc processing
$this->stop_proc = true;
$this->stop_proc = TRUE;
// Error handling
$this->setError(-1);
$this->setMessage($msg_code);
// Error message display by message module
$type = Mobile::isFromMobilePhone() ? 'mobile' : 'view';
$oMessageObject = &ModuleHandler::getModuleInstance('message',$type);
$oMessageObject = ModuleHandler::getModuleInstance('message', $type);
$oMessageObject->setError(-1);
$oMessageObject->setMessage($msg_code);
$oMessageObject->dispMessage();
@ -225,17 +247,22 @@
* set the file name of the template file
* @param string name of file
* @return void
**/
function setTemplateFile($filename) {
if(substr($filename,-5)!='.html') $filename .= '.html';
* */
function setTemplateFile($filename)
{
if(substr($filename, -5) != '.html')
{
$filename .= '.html';
}
$this->template_file = $filename;
}
/**
* retrieve the directory path of the template directory
* @return string
**/
function getTemplateFile() {
* */
function getTemplateFile()
{
return $this->template_file;
}
@ -243,18 +270,26 @@
* set the directory path of the template directory
* @param string path of template directory.
* @return void
**/
function setTemplatePath($path) {
if(substr($path,0,1)!='/' && substr($path,0,2)!='./') $path = './'.$path;
if(substr($path,-1)!='/') $path .= '/';
* */
function setTemplatePath($path)
{
if(substr($path, 0, 1) != '/' && substr($path, 0, 2) != './')
{
$path = './' . $path;
}
if(substr($path, -1) != '/')
{
$path .= '/';
}
$this->template_path = $path;
}
/**
* retrieve the directory path of the template directory
* @return string
**/
function getTemplatePath() {
* */
function getTemplatePath()
{
return $this->template_path;
}
@ -262,17 +297,22 @@
* set the file name of the temporarily modified by admin
* @param string name of file
* @return void
**/
function setEditedLayoutFile($filename) {
if(substr($filename,-5)!='.html') $filename .= '.html';
* */
function setEditedLayoutFile($filename)
{
if(substr($filename, -5) != '.html')
{
$filename .= '.html';
}
$this->edited_layout_file = $filename;
}
/**
* retreived the file name of edited_layout_file
* @return string
**/
function getEditedLayoutFile() {
* */
function getEditedLayoutFile()
{
return $this->edited_layout_file;
}
@ -280,49 +320,67 @@
* set the file name of the layout file
* @param string name of file
* @return void
**/
function setLayoutFile($filename) {
if(substr($filename,-5)!='.html') $filename .= '.html';
* */
function setLayoutFile($filename)
{
if(substr($filename, -5) != '.html')
{
$filename .= '.html';
}
$this->layout_file = $filename;
}
/**
* get the file name of the layout file
* @return string
**/
function getLayoutFile() {
* */
function getLayoutFile()
{
return $this->layout_file;
}
/**
* set the directory path of the layout directory
* @param string path of layout directory.
**/
function setLayoutPath($path) {
if(substr($path,0,1)!='/' && substr($path,0,2)!='./') $path = './'.$path;
if(substr($path,-1)!='/') $path .= '/';
* */
function setLayoutPath($path)
{
if(substr($path, 0, 1) != '/' && substr($path, 0, 2) != './')
{
$path = './' . $path;
}
if(substr($path, -1) != '/')
{
$path .= '/';
}
$this->layout_path = $path;
}
/**
* set the directory path of the layout directory
* @return string
**/
function getLayoutPath() {
* */
function getLayoutPath()
{
return $this->layout_path;
}
/**
* excute the member method specified by $act variable
* @return boolean true : success false : fail
**/
function proc() {
* */
function proc()
{
// pass if stop_proc is true
if($this->stop_proc) return false;
if($this->stop_proc)
{
return false;
}
// trigger call
$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'before', $this);
if(!$triggerOutput->toBool()) {
if(!$triggerOutput->toBool())
{
$this->setError($triggerOutput->getError());
$this->setMessage($triggerOutput->getMessage());
return false;
@ -330,13 +388,15 @@
// execute an addon(call called_position as before_module_proc)
$called_position = 'before_module_proc';
$oAddonController = &getController('addon');
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone()?"mobile":"pc");
$oAddonController = getController('addon');
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
@include($addon_file);
if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act)) {
if(isset($this->xml_info->action->{$this->act}) && method_exists($this, $this->act))
{
// Check permissions
if($this->module_srl && !$this->grant->access){
if($this->module_srl && !$this->grant->access)
{
$this->stop("msg_not_permitted_act");
return FALSE;
}
@ -364,19 +424,21 @@
}
}
$oModuleModel = &getModel('module');
$oModuleModel = getModel('module');
$oModuleModel->syncSkinInfoToModuleInfo($this->module_info);
Context::set('module_info', $this->module_info);
// Run
$output = $this->{$this->act}();
}
else {
else
{
return false;
}
// trigger call
$triggerOutput = ModuleHandler::triggerCall('moduleObject.proc', 'after', $this);
if(!$triggerOutput->toBool()) {
if(!$triggerOutput->toBool())
{
$this->setError($triggerOutput->getError());
$this->setMessage($triggerOutput->getMessage());
return false;
@ -384,26 +446,34 @@
// execute an addon(call called_position as after_module_proc)
$called_position = 'after_module_proc';
$oAddonController = &getController('addon');
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone()?"mobile":"pc");
$oAddonController = getController('addon');
$addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
@include($addon_file);
if(is_a($output, 'Object') || is_subclass_of($output, 'Object')) {
if(is_a($output, 'Object') || is_subclass_of($output, 'Object'))
{
$this->setError($output->getError());
$this->setMessage($output->getMessage());
if (!$output->toBool()) return false;
if(!$output->toBool())
{
return false;
}
}
// execute api methos of the module if view action is and result is XMLRPC or JSON
if($this->module_info->module_type == 'view'){
if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON') {
if($this->module_info->module_type == 'view')
{
if(Context::getResponseMethod() == 'XMLRPC' || Context::getResponseMethod() == 'JSON')
{
$oAPI = getAPI($this->module_info->module, 'api');
if(method_exists($oAPI, $this->act)) {
if(method_exists($oAPI, $this->act))
{
$oAPI->{$this->act}($this);
}
}
}
return true;
}
}
}
?>