Clean up non-static method calls in Widget module

This commit is contained in:
Kijin Sung 2025-05-26 22:49:29 +09:00
parent 810be0710b
commit 14dbac7890
4 changed files with 169 additions and 124 deletions

View file

@ -21,8 +21,7 @@ class WidgetAdminView extends Widget
function dispWidgetAdminDownloadedList()
{
// Set widget list
$oWidgetModel = getModel('widget');
$widget_list = $oWidgetModel->getDownloadedWidgetList();
$widget_list = WidgetModel::getDownloadedWidgetList();
$security = new Security($widget_list);
$widget_list = $security->encodeHTML('..', '..author..');
@ -59,20 +58,21 @@ class WidgetAdminView extends Widget
function dispWidgetAdminAddContent()
{
$module_srl = Context::get('module_srl');
if(!$module_srl) throw new Rhymix\Framework\Exceptions\InvalidRequest;
if (!$module_srl)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$document_srl = Context::get('document_srl');
$oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($document_srl);
$oDocument = DocumentModel::getDocument($document_srl);
Context::set('oDocument', $oDocument);
$oModuleModel = getModel('module');
$columnList = array('module_srl', 'mid');
$module_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
$module_info = ModuleModel::getModuleInfoByModuleSrl($module_srl, $columnList);
Context::set('module_info', $module_info);
// Editors settings of the module by calling getEditor
$oEditorModel = getModel('editor');
$editor = $oEditorModel->getModuleEditor('document',$module_srl, $module_srl,'module_srl','content');
$editor = EditorModel::getModuleEditor('document', $module_srl, $module_srl, 'module_srl', 'content');
Context::set('editor', $editor);
$security = new Security();

View file

@ -28,16 +28,18 @@ class WidgetController extends Widget
$skin = Context::get('skin');
$path = sprintf('./widgets/%s/', $widget);
$oModuleModel = getModel('module');
$skin_info = $oModuleModel->loadSkinInfo($path, $skin);
$skin_info = ModuleModel::loadSkinInfo($path, $skin);
$colorset_list = [];
foreach($skin_info->colorset ?: [] as $colorset)
foreach ($skin_info->colorset ?: [] as $colorset)
{
$colorset_list[] = sprintf('%s|@|%s', $colorset->name, $colorset->title);
}
if (count($colorset_list))
{
$colorsets = implode("\n", $colorset_list);
}
if(count($colorset_list)) $colorsets = implode("\n", $colorset_list);
$this->add('colorset_list', $colorsets);
}
@ -47,13 +49,18 @@ class WidgetController extends Widget
function procWidgetGenerateCode()
{
$widget = Context::get('selected_widget');
if(!$widget) throw new Rhymix\Framework\Exceptions\InvalidRequest;
if(!Context::get('skin')) throw new Rhymix\Framework\Exception('msg_widget_skin_is_null');
if (!$widget)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
if (!Context::get('skin'))
{
throw new Rhymix\Framework\Exception('msg_widget_skin_is_null');
}
$attribute = $this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars);
$widget_code = sprintf('<img class="zbxe_widget_output" widget="%s" %s />', $widget, implode(' ',$attribute));
// Code output
$this->add('widget_code', $widget_code);
}
@ -63,9 +70,14 @@ class WidgetController extends Widget
function procWidgetGenerateCodeInPage()
{
$widget = Context::get('selected_widget');
if(!$widget) throw new Rhymix\Framework\Exceptions\InvalidRequest;
if(!in_array($widget,array('widgetBox','widgetContent')) && !Context::get('skin')) throw new Rhymix\Framework\Exception('msg_widget_skin_is_null');
if (!$widget)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
if (!in_array($widget,array('widgetBox','widgetContent')) && !Context::get('skin'))
{
throw new Rhymix\Framework\Exception('msg_widget_skin_is_null');
}
$this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars);
@ -100,17 +112,23 @@ class WidgetController extends Widget
$editor_sequence = Context::get('editor_sequence');
$err = 0;
$oLayoutModel = getModel('layout');
$layout_info = $oLayoutModel->getLayout($module_srl);
if(!$layout_info || $layout_info->type != 'faceoff') $err++;
$layout_info = LayoutModel::getLayout($module_srl);
if (!$layout_info || $layout_info->type != 'faceoff')
{
$err++;
}
// Destination Information Wanted page module
$oModuleModel = getModel('module');
$columnList = array('module_srl', 'module');
$page_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
if(!$page_info->module_srl || $page_info->module != 'page') $err++;
if($err > 1) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$page_info = ModuleModel::getModuleInfoByModuleSrl($module_srl, $columnList);
if (!$page_info->module_srl || $page_info->module != 'page')
{
$err++;
}
if ($err > 1)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check permissions
$logged_info = Context::get('logged_info');
@ -118,23 +136,21 @@ class WidgetController extends Widget
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$module_grant = $oModuleModel->getGrant($page_info, $logged_info);
$module_grant = ModuleModel::getGrant($page_info, $logged_info);
if (!$module_grant->manager)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Enter post
$oDocumentModel = getModel('document');
$oDocumentController = getController('document');
$obj = new stdClass();
$obj->module_srl = $module_srl;
$obj->content = $content;
$obj->document_srl = $document_srl;
$obj->use_editor = 'Y';
$oDocument = $oDocumentModel->getDocument($obj->document_srl);
$oDocument = DocumentModel::getDocument($obj->document_srl);
$oDocumentController = DocumentController::getInstance();
if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
{
$output = $oDocumentController->updateDocument($oDocument, $obj);
@ -146,7 +162,10 @@ class WidgetController extends Widget
}
// Stop when an error occurs
if(!$output->toBool()) return $output;
if (!$output->toBool())
{
return $output;
}
// Return results
$this->add('document_srl', $obj->document_srl);
@ -160,18 +179,16 @@ class WidgetController extends Widget
// Variable Wanted
$document_srl = Context::get('document_srl');
$oDocumentModel = getModel('document');
$oDocumentController = getController('document');
$oDocumentAdminController = getAdminController('document');
$oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists()) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$oDocument = DocumentModel::getDocument($document_srl);
if (!$oDocument->isExists())
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$module_srl = $oDocument->get('module_srl');
// Destination Information Wanted page module
$oModuleModel = getModel('module');
$columnList = array('module_srl', 'module');
$page_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl, $columnList);
$page_info = ModuleModel::getModuleInfoByModuleSrl($module_srl, $columnList);
if(!$page_info->module_srl || $page_info->module != 'page') throw new Rhymix\Framework\Exceptions\InvalidRequest;
// Check permissions
@ -180,14 +197,18 @@ class WidgetController extends Widget
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$module_grant = $oModuleModel->getGrant($page_info, $logged_info);
$module_grant = ModuleModel::getGrant($page_info, $logged_info);
if (!$module_grant->manager)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$oDocumentAdminController = DocumentAdminController::getInstance();
$output = $oDocumentAdminController->copyDocumentModule(array($oDocument->get('document_srl')), $oDocument->get('module_srl'),0);
if(!$output->toBool()) return $output;
if (!$output->toBool())
{
return $output;
}
// Return results
$copied_srls = $output->get('copied_srls');
@ -201,18 +222,19 @@ class WidgetController extends Widget
{
// Variable Wanted
$document_srl = Context::get('document_srl');
$oDocumentModel = getModel('document');
$oDocumentController = getController('document');
$oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists()) return;
$oDocument = DocumentModel::getDocument($document_srl);
if (!$oDocument->isExists())
{
return;
}
$module_srl = $oDocument->get('module_srl');
// Destination Information Wanted page module
$oModuleModel = getModel('module');
$page_info = $oModuleModel->getModuleInfoByModuleSrl($module_srl);
if(!$page_info->module_srl || $page_info->module != 'page') throw new Rhymix\Framework\Exceptions\InvalidRequest;
$page_info = ModuleModel::getModuleInfoByModuleSrl($module_srl);
if (!$page_info->module_srl || $page_info->module != 'page')
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check permissions
$logged_info = Context::get('logged_info');
@ -220,14 +242,18 @@ class WidgetController extends Widget
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$module_grant = $oModuleModel->getGrant($page_info, $logged_info);
$module_grant = ModuleModel::getGrant($page_info, $logged_info);
if (!$module_grant->manager)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$oDocumentController = DocumentController::getInstance();
$output = $oDocumentController->deleteDocument($oDocument->get('document_srl'));
if(!$output->toBool()) return $output;
if (!$output->toBool())
{
return $output;
}
}
/**
@ -258,11 +284,14 @@ class WidgetController extends Widget
{
$content = Context::replaceUserLang($content);
}
// Check whether to include information about editing
$this->javascript_mode = $javascript_mode;
// Widget code box change
$content = preg_replace_callback('!<div([^>]*)widget=([^>]*?)><div><div>((<img.*?>)*)!is', array($this, 'transWidgetBox'), $content);
// Widget code information byeogyeong
// Widget code information change
$content = preg_replace_callback('!<img([^>]*)widget=([^>]*?)>!is', array($this, 'transWidget'), $content);
return $content;
@ -519,8 +548,7 @@ class WidgetController extends Widget
case 'widgetContent' :
if($args->document_srl)
{
$oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($args->document_srl, false, true);
$oDocument = DocumentModel::getDocument($args->document_srl, false, true);
$body = $oDocument->getContent(false, false, false, false);
}
else
@ -528,7 +556,7 @@ class WidgetController extends Widget
$body = base64_decode($args->body);
}
// Change the editor component
$oEditorController = getController('editor');
$oEditorController = EditorController::getInstance();
$body = $oEditorController->transComponent($body);
$widget_content_header = sprintf('<div class="rhymix_content xe_content xe-widget-wrapper ' . ($args->css_class ?? '') . '" %sstyle="%s"><div style="%s">', $args->id ?? '', $style, $inner_style);
@ -559,8 +587,7 @@ class WidgetController extends Widget
case 'widgetContent' :
if($args->document_srl)
{
$oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($args->document_srl, false, true);
$oDocument = DocumentModel::getDocument($args->document_srl, false, true);
$body = $oDocument->getContent(false, false, false, false);
}
else
@ -694,24 +721,33 @@ class WidgetController extends Widget
if(!isset($GLOBALS['_xe_loaded_widgets_'][$widget]))
{
// Finding the location of a widget
$oWidgetModel = getModel('widget');
$path = $oWidgetModel->getWidgetPath($widget);
$path = WidgetModel::getWidgetPath($widget);
// If you do not find the class file error output widget (html output)
$class_file = sprintf('%s%s.class.php', $path, $widget);
if(!file_exists($class_file)) return sprintf(lang('msg_widget_is_not_exists'), $widget);
if (!file_exists($class_file))
{
return sprintf(lang('msg_widget_is_not_exists'), $widget);
}
// Widget classes include
require_once($class_file);
// Creating Objects
if(!class_exists($widget, false))
if (!class_exists($widget, false))
{
return sprintf(lang('msg_widget_object_is_null'), $widget);
}
$oWidget = new $widget();
if(!is_object($oWidget)) return sprintf(lang('msg_widget_object_is_null'), $widget);
if(!method_exists($oWidget, 'proc')) return sprintf(lang('msg_widget_proc_is_null'), $widget);
if (!is_object($oWidget))
{
return sprintf(lang('msg_widget_object_is_null'), $widget);
}
if (!method_exists($oWidget, 'proc'))
{
return sprintf(lang('msg_widget_proc_is_null'), $widget);
}
$oWidget->widget_path = $path;
@ -722,12 +758,17 @@ class WidgetController extends Widget
function compileWidgetStyle($widgetStyle,$widget,$widget_content_body, $args, $javascript_mode)
{
if(!$widgetStyle) return $widget_content_body;
if (!$widgetStyle)
{
return $widget_content_body;
}
$oWidgetModel = getModel('widget');
// Bring extra_var widget style tie
$widgetstyle_info = $oWidgetModel->getWidgetStyleInfo($widgetStyle);
if(!$widgetstyle_info) return $widget_content_body;
$widgetstyle_info = WidgetModel::getWidgetStyleInfo($widgetStyle);
if (!$widgetstyle_info)
{
return $widget_content_body;
}
$widgetstyle_extra_var = new stdClass();
$widgetstyle_extra_var_key = get_object_vars($widgetstyle_info);
@ -742,7 +783,7 @@ class WidgetController extends Widget
// #18994272 오타를 수정했으나 하위 호환성을 위해 남겨둠 - deprecated
Context::set('widgetstyle_extar_var', $widgetstyle_extra_var);
if($javascript_mode && $widget=='widgetBox')
if ($javascript_mode && $widget == 'widgetBox')
{
Context::set('widget_content', '<div class="widget_inner">'.$widget_content_body.'</div>');
}
@ -750,8 +791,9 @@ class WidgetController extends Widget
{
Context::set('widget_content', $widget_content_body);
}
// Compilation
$widgetstyle_path = $oWidgetModel->getWidgetStylePath($widgetStyle);
$widgetstyle_path = WidgetModel::getWidgetStylePath($widgetStyle);
$oTemplate = Rhymix\Framework\Template::getInstance();
$tpl = $oTemplate->compile($widgetstyle_path, 'widgetstyle');
@ -763,8 +805,7 @@ class WidgetController extends Widget
*/
function arrangeWidgetVars($widget, $request_vars, &$vars)
{
$oWidgetModel = getModel('widget');
$widget_info = $oWidgetModel->getWidgetInfo($widget);
$widget_info = WidgetModel::getWidgetInfo($widget);
if(!$vars)
{
@ -800,7 +841,7 @@ class WidgetController extends Widget
// If the widget style
if($request_vars->widgetstyle)
{
$widgetStyle_info = $oWidgetModel->getWidgetStyleInfo($request_vars->widgetstyle);
$widgetStyle_info = WidgetModel::getWidgetStyleInfo($request_vars->widgetstyle);
if(countobj($widgetStyle_info->extra_var))
{
foreach($widgetStyle_info->extra_var as $key=>$val)

View file

@ -8,41 +8,32 @@
*/
class WidgetModel extends Widget
{
/**
* @brief Initialization
*/
function init()
{
}
/**
* @brief Wanted widget's path
*/
function getWidgetPath($widget_name)
public static function getWidgetPath($widget_name)
{
$path = sprintf('./widgets/%s/', $widget_name);
if(is_dir($path)) return $path;
return "";
}
/**
* @brief Wanted widget style path
*/
function getWidgetStylePath($widgetStyle_name)
public static function getWidgetStylePath($widgetStyle_name)
{
$path = sprintf('./widgetstyles/%s/', $widgetStyle_name);
if(is_dir($path)) return $path;
return "";
}
/**
* @brief Wanted widget style path
*/
function getWidgetStyleTpl($widgetStyle_name)
public static function getWidgetStyleTpl($widgetStyle_name)
{
$path = $this->getWidgetStylePath($widgetStyle_name);
$path = self::getWidgetStylePath($widgetStyle_name);
$tpl = sprintf('%swidgetstyle.html', $path);
return $tpl;
}
@ -51,7 +42,7 @@ class WidgetModel extends Widget
* @brief Wanted photos of the type and information
* Download a widget with type (generation and other means)
*/
function getDownloadedWidgetList()
public static function getDownloadedWidgetList()
{
$oAutoinstallModel = getModel('autoinstall');
@ -66,7 +57,7 @@ class WidgetModel extends Widget
// The name of the widget
$widget = $searched_list[$i];
// Wanted information on the Widget
$widget_info = $this->getWidgetInfo($widget);
$widget_info = self::getWidgetInfo($widget);
if(!$widget_info)
{
@ -96,7 +87,7 @@ class WidgetModel extends Widget
* @brief Wanted photos of the type and information
* Download a widget with type (generation and other means)
*/
function getDownloadedWidgetStyleList()
public static function getDownloadedWidgetStyleList()
{
// 've Downloaded the widget and the widget's list of installed Wanted
$searched_list = FileHandler::readDir('./widgetstyles');
@ -109,7 +100,7 @@ class WidgetModel extends Widget
// The name of the widget
$widgetStyle = $searched_list[$i];
// Wanted information on the Widget
$widgetStyle_info = $this->getWidgetStyleInfo($widgetStyle);
$widgetStyle_info = self::getWidgetStyleInfo($widgetStyle);
$list[] = $widgetStyle_info;
}
@ -120,11 +111,11 @@ class WidgetModel extends Widget
* @brief Modules conf/info.xml wanted to read the information
* It uses caching to reduce time for xml parsing ..
*/
function getWidgetInfo($widget)
public static function getWidgetInfo($widget)
{
// Check the widget path.
$widget = preg_replace('/[^a-zA-Z0-9-_]/', '', $widget);
$widget_path = $this->getWidgetPath($widget);
$widget_path = self::getWidgetPath($widget);
if (!$widget_path)
{
return;
@ -161,11 +152,11 @@ class WidgetModel extends Widget
* @brief Modules conf/info.xml wanted to read the information
* It uses caching to reduce time for xml parsing ..
*/
function getWidgetStyleInfo($widgetStyle)
public static function getWidgetStyleInfo($widgetStyle)
{
// Check the widget style path.
$widgetStyle = preg_replace('/[^a-zA-Z0-9-_]/', '', $widgetStyle);
$widgetStyle_path = $this->getWidgetStylePath($widgetStyle);
$widgetStyle_path = self::getWidgetStylePath($widgetStyle);
if (!$widgetStyle_path)
{
return;

View file

@ -21,13 +21,18 @@ class WidgetView extends Widget
function dispWidgetInfo()
{
// If people have skin widget widget output as a function of the skin More Details
if(Context::get('skin')) return $this->dispWidgetSkinInfo();
if (Context::get('skin'))
{
return $this->dispWidgetSkinInfo();
}
// Wanted widget is selected information
$oWidgetModel = getModel('widget');
$widget_info = $oWidgetModel->getWidgetInfo(Context::get('selected_widget'));
$widget_info = WidgetModel::getWidgetInfo(Context::get('selected_widget'));
Context::set('widget_info', $widget_info);
// Specifies the widget to pop up
$this->setLayoutFile('popup_layout');
// Set a template file
$this->setTemplateFile('widget_detail_info');
}
@ -40,14 +45,14 @@ class WidgetView extends Widget
$widget = Context::get('selected_widget');
$skin = preg_replace('/[^a-zA-Z0-9-_]/', '', Context::get('skin'));
$path = sprintf('./widgets/%s/', $widget);
// Wanted widget is selected information
$oModuleModel = getModel('module');
$skin_info = $oModuleModel->loadSkinInfo($path, $skin);
$path = sprintf('./widgets/%s/', $widget);
$skin_info = ModuleModel::loadSkinInfo($path, $skin);
Context::set('skin_info',$skin_info);
// Specifies the widget to pop up
$this->setLayoutFile('popup_layout');
// Set a template file
$this->setTemplateFile('skin_info');
}
@ -58,31 +63,32 @@ class WidgetView extends Widget
function dispWidgetGenerateCode()
{
// Wanted widget is selected information
$oWidgetModel = getModel('widget');
$widget_list = $oWidgetModel->getDownloadedWidgetList();
$widget_list = WidgetModel::getDownloadedWidgetList();
$selected_widget = Context::get('selected_widget');
if(!$selected_widget) $selected_widget = $widget_list[0]->widget;
if (!$selected_widget)
{
$selected_widget = $widget_list[0]->widget;
}
$widget_info = $oWidgetModel->getWidgetInfo($selected_widget);
$widget_info = WidgetModel::getWidgetInfo($selected_widget);
Context::set('widget_info', $widget_info);
Context::set('widget_list', $widget_list);
Context::set('selected_widget', $selected_widget);
$oModuleModel = getModel('module');
// Get a list of module categories
$module_categories = $oModuleModel->getModuleCategories();
$module_categories = ModuleModel::getModuleCategories();
// Get a mid list
$site_module_info = Context::get('site_module_info');
$args = new stdClass();
$args->site_srl = $site_module_info->site_srl;
$columnList = array('module_srl', 'module_category_srl', 'browser_title', 'mid');
$mid_list = $oModuleModel->getMidList($args, $columnList);
$mid_list = ModuleModel::getMidList($args, $columnList);
// Get a list of groups
$oMemberModel = getModel('member');
$group_list = $oMemberModel->getGroups($site_module_info->site_srl);
$group_list = MemberModel::getGroups($site_module_info->site_srl);
Context::set('group_list', $group_list);
// module_category and module combination
if($module_categories)
{
@ -102,14 +108,18 @@ class WidgetView extends Widget
}
Context::set('mid_list',$module_categories);
// Menu Get a list
$output = executeQueryArray('menu.getMenus');
Context::set('menu_list',$output->data);
// Wanted information on skin
$skin_list = $oModuleModel->getSkins($widget_info->path);
$skin_list = ModuleModel::getSkins($widget_info->path);
Context::set('skin_list', $skin_list);
// Specifies the widget to pop up
$this->setLayoutFile('popup_layout');
// Set a template file
$this->setTemplateFile('widget_generate_code');
}
@ -119,11 +129,14 @@ class WidgetView extends Widget
*/
function dispWidgetGenerateCodeInPage()
{
$oWidgetModel = getModel('widget');
$widget_list = $oWidgetModel->getDownloadedWidgetList();
Context::set('widget_list',$widget_list);
$widget_list = WidgetModel::getDownloadedWidgetList();
Context::set('widget_list', $widget_list);
// When there is no widget is selected in the first widget
if(!Context::get('selected_widget')) Context::set('selected_widget',$widget_list[0]->widget);
if (!Context::get('selected_widget'))
{
Context::set('selected_widget', $widget_list[0]->widget);
}
$this->dispWidgetGenerateCode();
$this->setLayoutFile('popup_layout');
@ -136,15 +149,15 @@ class WidgetView extends Widget
function dispWidgetStyleGenerateCodeInPage()
{
// Widget-style list
$oWidgetModel = getModel('widget');
$widgetStyle_list = $oWidgetModel->getDownloadedWidgetStyleList();
$widgetStyle_list = WidgetModel::getDownloadedWidgetStyleList();
Context::set('widgetStyle_list',$widgetStyle_list);
// Selected list of widget styles
$widgetstyle = Context::get('widgetstyle');
$widgetstyle_info = $oWidgetModel->getWidgetStyleInfo($widgetstyle);
if($widgetstyle && $widgetstyle_info)
$widgetstyle_info = WidgetModel::getWidgetStyleInfo($widgetstyle);
if ($widgetstyle && $widgetstyle_info)
{
Context::set('widgetstyle_info',$widgetstyle_info);
Context::set('widgetstyle_info', $widgetstyle_info);
}
$this->dispWidgetGenerateCode();