*/
/**
* @class widgetController
* @author NAVER (developers@xpressengine.com)
* @brief Controller class for widget modules
*/
class WidgetController extends Widget
{
// The results are not widget modify/delete and where to use the flag for
// layout_javascript_mode include all the results into the javascript mode Sikkim
var $javascript_mode = false;
var $layout_javascript_mode = false;
/**
* @brief Initialization
*/
function init()
{
}
/**
* @brief Selected photos - the return of the skin-color three
*/
function procWidgetGetColorsetList()
{
$widget = Context::get('selected_widget');
$skin = Context::get('skin');
$path = sprintf('./widgets/%s/', $widget);
$skin_info = ModuleModel::loadSkinInfo($path, $skin);
$colorset_list = [];
foreach ($skin_info->colorset ?: [] as $colorset)
{
$colorset_list[] = sprintf('%s|@|%s', $colorset->name, $colorset->title);
}
if (count($colorset_list))
{
$colorsets = implode("\n", $colorset_list);
}
$this->add('colorset_list', $colorsets);
}
/**
* @brief Return the generated code of the 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');
}
$attribute = $this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars);
$widget_code = sprintf('', $widget, implode(' ',$attribute));
$this->add('widget_code', $widget_code);
}
/**
* @brief Edit page request for the creation of the widget code
*/
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');
}
$this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars);
// Wanted results
$widget_code = $this->execute($widget, $vars, true, false);
$widget_code = Context::replaceUserLang($widget_code);
$this->add('widget_code', $widget_code);
}
/**
* @brief Upload widget styles
*/
function procWidgetStyleExtraImageUpload()
{
$attribute = $this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars);
$this->setLayoutPath('./common/tpl');
$this->setLayoutFile('default_layout.html');
$this->setTemplatePath($this->module_path.'tpl');
$this->setTemplateFile("top_refresh.html");
}
/**
* @brief Add content widget
*/
function procWidgetInsertDocument()
{
// Variable Wanted
$module_srl = Context::get('module_srl');
$document_srl = Context::get('document_srl');
$content = Context::get('content');
$editor_sequence = Context::get('editor_sequence');
$err = 0;
$layout_info = LayoutModel::getLayout($module_srl);
if (!$layout_info || $layout_info->type != 'faceoff')
{
$err++;
}
// Destination Information Wanted page module
$columnList = array('module_srl', 'module');
$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');
if (!$logged_info->member_srl)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$module_grant = ModuleModel::getGrant($page_info, $logged_info);
if (!$module_grant->manager)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
// Enter post
$obj = new stdClass();
$obj->module_srl = $module_srl;
$obj->content = $content;
$obj->document_srl = $document_srl;
$obj->use_editor = 'Y';
$oDocument = DocumentModel::getDocument($obj->document_srl);
$oDocumentController = DocumentController::getInstance();
if($oDocument->isExists() && $oDocument->document_srl == $obj->document_srl)
{
$output = $oDocumentController->updateDocument($oDocument, $obj);
}
else
{
$output = $oDocumentController->insertDocument($obj);
$obj->document_srl = $output->get('document_srl');
}
// Stop when an error occurs
if (!$output->toBool())
{
return $output;
}
// Return results
$this->add('document_srl', $obj->document_srl);
}
/**
* @brief Copy the content widget
*/
function procWidgetCopyDocument()
{
// Variable Wanted
$document_srl = Context::get('document_srl');
$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
$columnList = array('module_srl', 'module');
$page_info = ModuleModel::getModuleInfoByModuleSrl($module_srl, $columnList);
if(!$page_info->module_srl || $page_info->module != 'page') throw new Rhymix\Framework\Exceptions\InvalidRequest;
// Check permissions
$logged_info = Context::get('logged_info');
if (!$logged_info->member_srl)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$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;
}
// Return results
$copied_srls = $output->get('copied_srls');
$this->add('document_srl', $copied_srls[$oDocument->get('document_srl')]);
}
/**
* @brief Deleting widgets
*/
function procWidgetDeleteDocument()
{
// Variable Wanted
$document_srl = Context::get('document_srl');
$oDocument = DocumentModel::getDocument($document_srl);
if (!$oDocument->isExists())
{
return;
}
$module_srl = $oDocument->get('module_srl');
// Destination Information Wanted page module
$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');
if (!$logged_info->member_srl)
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$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;
}
}
/**
* @brief Modify the code in Javascript widget/Javascript edit mode for dragging and converted to
*/
function setWidgetCodeInJavascriptMode()
{
$this->layout_javascript_mode = true;
}
/**
* @brief Widget code compiles and prints the information to trigger
* display:: before invoked in
*/
function triggerWidgetCompile(&$content)
{
if(Context::getResponseMethod()!='HTML') return;
$content = $this->transWidgetCode($content, $this->layout_javascript_mode);
}
/**
* @breif By converting the specific content of the widget tag return
*/
function transWidgetCode($content, $javascript_mode = false, $isReplaceLangCode = true)
{
// Changing user-defined language
if($isReplaceLangCode)
{
$content = Context::replaceUserLang($content);
}
// Check whether to include information about editing
$this->javascript_mode = $javascript_mode;
// Widget code box change
$content = preg_replace_callback('!