*/ /** * @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; // Where the cache files are created widget var $cache_path = './files/cache/widget_cache/'; /** * @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); $oModuleModel = getModel('module'); $skin_info = $oModuleModel->loadSkinInfo($path, $skin); for($i=0;$icolorset);$i++) { $colorset = sprintf('%s|@|%s', $skin_info->colorset[$i]->name, $skin_info->colorset[$i]->title); $colorset_list[] = $colorset; } 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) return new Object(-1,'msg_invalid_request'); if(!Context::get('skin')) return new Object(-1,Context::getLang('msg_widget_skin_is_null')); $attribute = $this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars); $widget_code = sprintf('', $widget, implode(' ',$attribute)); // Code output $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) return new Object(-1,'msg_invalid_request'); if(!in_array($widget,array('widgetBox','widgetContent')) && !Context::get('skin')) return new Object(-1,Context::getLang('msg_widget_skin_is_null')); $attribute = $this->arrangeWidgetVars($widget, Context::getRequestVars(), $vars); // Wanted results $widget_code = $this->execute($widget, $vars, true, false); $oModuleController = getController('module'); $oModuleController->replaceDefinedLangCode($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; $oLayoutModel = getModel('layout'); $layout_info = $oLayoutModel->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) return new Object(-1,'msg_invalid_request'); // Check permissions $is_logged = Context::get('is_logged'); $logged_info = Context::get('logged_info'); $user_group = $logged_info->group_list; $is_admin = false; if(count($user_group)&&count($page_info->grants['manager'])) { $manager_group = $page_info->grants['manager']; foreach($user_group as $group_srl => $group_info) { if(in_array($group_srl, $manager_group)) $is_admin = true; } } if(!$is_admin && !$is_logged && $logged_info->is_admin != 'Y' && !$oModuleModel->isSiteAdmin($logged_info) && !(is_array($page_info->admin_id) && in_array($logged_info->user_id, $page_info->admin_id))) return new Object(-1,'msg_not_permitted'); // Enter post $oDocumentModel = getModel('document'); $oDocumentController = getController('document'); $obj = new stdClass(); $obj->module_srl = $module_srl; $obj->content = $content; $obj->document_srl = $document_srl; $oDocument = $oDocumentModel->getDocument($obj->document_srl, true); 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'); $oDocumentModel = getModel('document'); $oDocumentController = getController('document'); $oDocumentAdminController = getAdminController('document'); $oDocument = $oDocumentModel->getDocument($document_srl, true); if(!$oDocument->isExists()) return new Object(-1,'msg_invalid_request'); $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); if(!$page_info->module_srl || $page_info->module != 'page') return new Object(-1,'msg_invalid_request'); // Check permissions $is_logged = Context::get('is_logged'); $logged_info = Context::get('logged_info'); $user_group = $logged_info->group_list; $is_admin = false; if(count($user_group)&&count($page_info->grants['manager'])) { $manager_group = $page_info->grants['manager']; foreach($user_group as $group_srl => $group_info) { if(in_array($group_srl, $manager_group)) $is_admin = true; } } if(!$is_admin && !$is_logged && $logged_info->is_admin != 'Y' && !$oModuleModel->isSiteAdmin($logged_info) && !(is_array($page_info->admin_id) && in_array($logged_info->user_id, $page_info->admin_id))) return new Object(-1,'msg_not_permitted'); $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'); $oDocumentModel = getModel('document'); $oDocumentController = getController('document'); $oDocument = $oDocumentModel->getDocument($document_srl, true); if(!$oDocument->isExists()) return new Object(); $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') return new Object(-1,'msg_invalid_request'); // Check permissions $is_logged = Context::get('is_logged'); $logged_info = Context::get('logged_info'); $user_group = $logged_info->group_list; $is_admin = false; if(count($user_group)&&count($page_info->grants['manager'])) { $manager_group = $page_info->grants['manager']; foreach($user_group as $group_srl => $group_info) { if(in_array($group_srl, $manager_group)) $is_admin = true; } } if(!$is_admin && !$is_logged && $logged_info->is_admin != 'Y' && !$oModuleModel->isSiteAdmin($logged_info) && !(is_array($page_info->admin_id) && in_array($logged_info->user_id, $page_info->admin_id))) return new Object(-1,'msg_not_permitted'); $output = $oDocumentController->deleteDocument($oDocument->get('document_srl'), true); 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 new Object(); $content = $this->transWidgetCode($content, $this->layout_javascript_mode); return new Object(); } /** * @breif By converting the specific content of the widget tag return */ function transWidgetCode($content, $javascript_mode = false, $isReplaceLangCode = true) { // Changing user-defined language $oModuleController = getController('module'); $oModuleController->replaceDefinedLangCode($content, $isReplaceLangCode); // Check whether to include information about editing $this->javascript_mode = $javascript_mode; // Widget code box change $content = preg_replace_callback('!]*)widget=([^\>]*?)\>
(()*)!is', array($this,'transWidgetBox'), $content); // Widget code information byeogyeong $content = preg_replace_callback('!]*)widget=([^\>]*?)\>!is', array($this,'transWidget'), $content); return $content; } /** * @brief Widget code with the actual code changes */ function transWidget($matches) { $buff = trim($matches[0]); $oXmlParser = new XmlParser(); $xml_doc = $oXmlParser->parse(trim($buff)); if($xml_doc->img) $vars = $xml_doc->img->attrs; else $vars = $xml_doc->attrs; $widget = $vars->widget; if(!$widget) return $matches[0]; unset($vars->widget); return $this->execute($widget, $vars, $this->javascript_mode); } /** * @brief Widget box with the actual code changes */ function transWidgetBox($matches) { $buff = preg_replace('/
(.*)$/i','
',$matches[0]); $oXmlParser = new XmlParser(); $xml_doc = $oXmlParser->parse($buff); $vars = $xml_doc->div->attrs; $widget = $vars->widget; if(!$widget) return $matches[0]; unset($vars->widget); $vars->widgetbox_content = $matches[3]; return $this->execute($widget, $vars, $this->javascript_mode); } /** * @brief Re-create specific content within a widget * Widget on the page and create cache file in the module using */ function recompileWidget($content) { // Language in bringing $lang_list = Context::get('lang_supported'); // Bringing widget cache sequence preg_match_all('!]*)widget=([^\>]*?)\>!is', $content, $matches); $oXmlParser = new XmlParser(); $cnt = count($matches[1]); for($i=0;$i<$cnt;$i++) { $buff = $matches[0][$i]; $xml_doc = $oXmlParser->parse(trim($buff)); $args = $xml_doc->img->attrs; if(!$args) continue; // If you are not caching path $widget = $args->widget; $sequence = $args->widget_sequence; $cache = $args->widget_cache; if(!$sequence || !$cache) continue; if(count($args)) { foreach($args as $k => $v) $args->{$k} = urldecode($v); } // If the cache file for each language widget regeneration foreach($lang_list as $lang_type => $val) { $cache_file = sprintf('%s%d.%s.cache', $this->cache_path, $sequence, $lang_type); if(!file_exists($cache_file)) continue; $this->getCache($widget, $args, $lang_type, true); } } } /** * @brief Widget cache handling */ function getCache($widget, $args, $lang_type = null, $ignore_cache = false) { // If the specified language specifies the current language if(!$lang_type) $lang_type = Context::getLangType(); // widget, the cache number and cache values are set $widget_sequence = $args->widget_sequence; $widget_cache = $args->widget_cache; /** * Even if the cache number and value of the cache and return it to extract data */ if(!$ignore_cache && (!$widget_cache || !$widget_sequence)) { $oWidget = $this->getWidgetObject($widget); if(!$oWidget || !method_exists($oWidget, 'proc')) return; $widget_content = $oWidget->proc($args); $oModuleController = getController('module'); $oModuleController->replaceDefinedLangCode($widget_content); return $widget_content; } $oCacheHandler = CacheHandler::getInstance('object'); if($oCacheHandler->isSupport()) { $key = 'widget_cache:' . $widget_sequence; $cache_body = $oCacheHandler->get($key); $cache_body = preg_replace('@<\!--#Meta:@', '