From: <du...@us...> - 2013-01-29 16:25:10
|
Revision: 10944 http://sourceforge.net/p/xoops/svn/10944 Author: dugris Date: 2013-01-29 16:25:04 +0000 (Tue, 29 Jan 2013) Log Message: ----------- Refactoring page module : use : - Xoops_Module_Helper - Xoops_Request - Xoops_Locale Add plugins for : - Waiting blocks - backend Modified Paths: -------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/content.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/header.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/index.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/menu.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/permissions.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/related.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/blocks/page_blocks.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/form/page_content.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/form/page_related.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_content.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_rating.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_related.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/plugin/comments.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/plugin/notifications.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/plugin/search.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/plugin/system.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/css/rating.css XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/css/styles.css XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/docs/credits.txt XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/header.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/include/install.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/index.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/pdf.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/print.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/sql/mysql.sql XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/admin/page_admin_content.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/admin/page_admin_permissions.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/admin/page_admin_related.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_id.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/page_index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/page_navigation.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/page_pdf.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/page_print.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/page_viewpage.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/viewpage.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/xoops_version.php Added Paths: ----------- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/groupperm.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/helper.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page_related_link.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/icons/16/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/icons/16/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/icons/16/star_d.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/icons/16/star_o.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/icons/16/star_u.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/jquery_rating.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/en_US.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/locale.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/templates/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/templates/help.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/en_US/templates/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/locale/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select-init.js XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/css/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/css/application.css XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/css/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/css/multi-select.css XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/arrow.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/check.gif XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/delete.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/download.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/minus.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/plus.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/img/switch.png XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/js/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/js/application.js XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/js/index.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/js/jquery.js XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/js/jquery.multi-select.js XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/media/jquery/multi-select.0.3-7/js/jquery.quicksearch.js XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/preloads/core.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_content.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_list.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/page_rating.html Removed Paths: ------------- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/class/page.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/images/rating/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/js/ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/language/english/admin.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/language/english/blocks.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/language/english/main.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/language/english/modinfo.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/rating.php XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_hits.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_random.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_rating.html XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/templates/blocks/page_blocks_recent.html Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/content.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/content.php 2013-01-29 13:28:01 UTC (rev 10943) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/content.php 2013-01-29 16:25:04 UTC (rev 10944) @@ -20,21 +20,9 @@ * @version $Id$ */ include dirname(__FILE__) . '/header.php'; -// Get main instance -$system = System::getInstance(); -$xoops = Xoops::getInstance(); -// Parameters -$nb_content = $xoops->getModuleConfig('page_adminpager'); -// Get Action type -$op = $system->cleanVars($_REQUEST, 'op', 'default', 'string'); -// Get handler -$content_Handler = $xoops->getModuleHandler('page_content'); -$related_Handler = $xoops->getModuleHandler('page_related'); -$gperm_handler = $xoops->getHandler('groupperm'); + // Call header $xoops->header('page_admin_content.html'); -// Get start pager -$start = $system->cleanVars($_REQUEST, 'start', 0, 'int'); $admin_page = new XoopsModuleAdmin(); $admin_page->renderNavigation('content.php'); @@ -43,257 +31,175 @@ case 'list': default: - // Add Scripts - $xoops->theme()->addScript('media/xoops/xoops.js'); - $admin_page->addTips(_AM_PAGE_CONTENT_TIPS); - $admin_page->addItemButton(_AM_PAGE_CONTENT_ADD, 'content.php?op=new', 'add'); + $admin_page->addTips(PageLocale::CONTENT_TIPS); + $admin_page->addItemButton(PageLocale::A_ADD_CONTENT, 'content.php?op=new', 'add'); $admin_page->renderTips(); $admin_page->renderButton(); - // Criteria - $criteria = new CriteriaCompo(); - $criteria->setSort('content_weight ASC, content_title'); - $criteria->setOrder('ASC'); - $criteria->setStart($start); - $criteria->setLimit($nb_content); - $content_count = $content_Handler->getCount($criteria); - $content_arr = $content_Handler->getAll($criteria); + // Content + $content_count = $content_Handler->countPage(); + $content_arr = $content_Handler->getPage($start, $nb_limit); + // Assign Template variables $xoops->tpl()->assign('content_count', $content_count); if ($content_count > 0) { foreach (array_keys($content_arr) as $i) { - $content_id = $content_arr[$i]->getVar('content_id'); - $content['id'] = $content_id; - $content['title'] = $content_arr[$i]->getVar('content_title'); - $content['maindisplay'] = $content_arr[$i]->getVar('content_maindisplay'); - $content['weight'] = $content_arr[$i]->getVar('content_weight'); - $content['status'] = $content_arr[$i]->getVar('content_status'); - $content['hits'] = $content_arr[$i]->getVar('content_hits'); - $content['rating'] = number_format($content_arr[$i]->getVar('content_rating'), 1); + $content = $content_arr[$i]->getValues(); $xoops->tpl()->append_by_ref('content', $content); unset($content); } // Display Page Navigation - if ($content_count > $nb_content) { - $nav = new XoopsPageNav($content_count, $nb_content, $start, 'start'); + if ($content_count > $nb_limit) { + $nav = new XoopsPageNav($content_count, $nb_limit, $start, 'start'); $xoops->tpl()->assign('nav_menu', $nav->renderNav(4, 'small')); } } else { - $xoops->tpl()->assign('error_message', _AM_PAGE_CONTENT_ERROR_NOCONTENT); + $xoops->tpl()->assign('error_message', PageLocale::E_NO_CONTENT); } break; case 'new': - $admin_page->addItemButton(_AM_PAGE_CONTENT_LIST, 'content.php', 'application-view-detail'); + $admin_page->addItemButton(PageLocale::A_LIST_CONTENT, 'content.php', 'application-view-detail'); $admin_page->renderButton(); $obj = $content_Handler->create(); - $form = $xoops->getModuleForm($obj, 'page_content'); + $form = $helper->getForm($obj, 'page_content'); $xoops->tpl()->assign('form', $form->render()); break; case 'edit': - $admin_page->addItemButton(_AM_PAGE_CONTENT_LIST, 'content.php', 'application-view-detail'); - $admin_page->addItemButton(_AM_PAGE_CONTENT_ADD, 'content.php?op=new', 'add'); + $admin_page->addItemButton(PageLocale::A_LIST_CONTENT, 'content.php', 'application-view-detail'); + $admin_page->addItemButton(PageLocale::A_ADD_CONTENT, 'content.php?op=new', 'add'); $admin_page->renderButton(); // Create form - $obj = $content_Handler->get($system->cleanVars($_REQUEST, 'id', 0, 'int')); - $form = $xoops->getModuleForm($obj, 'page_content'); + $content_id = $request->asInt('content_id', 0); + $obj = $content_Handler->get($content_id); + $form = $helper->getForm($obj, 'page_content'); $xoops->tpl()->assign('form', $form->render()); break; case 'save': if (!$xoops->security()->check()) { - $xoops->redirect("content.php", 3, implode(",", $xoops->security()->getErrors())); + $xoops->redirect('content.php', 3, implode(',', $xoops->security()->getErrors())); } - $content_id = $system->cleanVars($_REQUEST, 'content_id', 0, 'int'); + + $content_id = $request->asInt('content_id', 0); if ($content_id > 0) { $obj = $content_Handler->get($content_id); - if ($_POST["date_update"] == 'Y'){ - $obj->setVar("content_create", strtotime($_POST["content_create"])); - } } else { $obj = $content_Handler->create(); - $obj->setVar("content_create", time()); } + $error_message = ''; $error = false; - $obj->setVar("content_title", $_POST["content_title"]); - $obj->setVar("content_shorttext", $_POST["content_shorttext"]); - $obj->setVar("content_text", $_POST["content_text"]); - $obj->setVar("content_mkeyword", $_POST["content_mkeyword"]); - $obj->setVar("content_mdescription", $_POST["content_mdescription"]); - $obj->setVar("content_author", $_POST["content_author"]); - $obj->setVar("content_status", $_POST["content_status"]); - $obj->setVar("content_maindisplay", $_POST["content_maindisplay"]); - $obj->setVar("content_dopdf", 0); - $obj->setVar("content_doprint", 0); - $obj->setVar("content_domail", 0); - $obj->setVar("content_doauthor", 0); - $obj->setVar("content_dodate", 0); - $obj->setVar("content_dohits", 0); - $obj->setVar("content_dorating", 0); - $obj->setVar("content_doncoms", 0); - $obj->setVar("content_docoms", 0); - $obj->setVar("content_dosocial", 0); - $obj->setVar("content_dotitle", 0); - $obj->setVar("content_donotifications", 0); - if (isset($_POST["content_option"])) { - $content_option = $_POST["content_option"]; - foreach (array_keys($content_option) as $i) { - switch ($content_option[$i]) { - case 'pdf': - $obj->setVar("content_dopdf", 1); - break; - case 'print': - $obj->setVar("content_doprint", 1); - break; - case 'mail': - $obj->setVar("content_domail", 1); - break; - case 'author': - $obj->setVar("content_doauthor", 1); - break; - case 'date': - $obj->setVar("content_dodate", 1); - break; - case 'hits': - $obj->setVar("content_dohits", 1); - break; - case 'rating': - $obj->setVar("content_dorating", 1); - break; - case 'coms': - $obj->setVar("content_docoms", 1); - break; - case 'ncoms': - $obj->setVar("content_doncoms", 1); - break; - case 'social': - $obj->setVar("content_dosocial", 1); - break; - case 'title': - $obj->setVar("content_dotitle", 1); - break; - case 'notifications': - $obj->setVar("content_donotifications", 1); - break; - } - } + $obj->setVar('content_title', $request->asStr('content_title', '')); + $obj->setVar('content_shorttext', $request->asStr('content_shorttext', '')); + $obj->setVar('content_text', $request->asStr('content_text', '')); + $obj->setVar('content_mkeyword', $request->asStr('content_mkeyword', '')); + $obj->setVar('content_mdescription', $request->asStr('content_mdescription', '')); + + $date_create = $request->asArray('content_create', array()); + if (count($date_create) == 1) { + $content_create = strtotime($date_create['date']); + } elseif (count($date_create) == 2) { + $content_create = strtotime($date_create['date']) + $date_create['time']; + } else { + $content_create = time(); } - if (preg_match('/^\d+$/', $_POST["content_weight"]) == false){ + $obj->setVar('content_create', $content_create); + + $obj->setVar('content_author', $request->asInt('content_author', $helper->xoops()->user->getVar('uid'))); + $obj->setVar('content_status', $request->asInt('content_status', 1)); + $obj->setVar('content_maindisplay', $request->asInt('content_maindisplay', 1)); + + $content_option = $request->asArray('content_option', array()); + $obj->setVar('content_dopdf', in_array('pdf', $content_option)); + $obj->setVar('content_doprint', in_array('print', $content_option)); + $obj->setVar('content_domail', in_array('mail', $content_option)); + $obj->setVar('content_doauthor', in_array('author', $content_option)); + $obj->setVar('content_dodate', in_array('date', $content_option)); + $obj->setVar('content_dohits', in_array('hits', $content_option)); + $obj->setVar('content_dorating', in_array('rating', $content_option)); + $obj->setVar('content_doncoms', in_array('ncoms', $content_option)); + $obj->setVar('content_docoms', in_array('coms', $content_option)); + $obj->setVar('content_dosocial', in_array('social', $content_option)); + $obj->setVar('content_dotitle', in_array('title', $content_option)); + $obj->setVar('content_donotifications', in_array('notifications', $content_option)); + + if (preg_match('/^\d+$/', $request->asInt('content_weight', 0)) == false){ $error = true; - $error_message .= _AM_PAGE_CONTENT_ERROR_WEIGHT . '<br />'; - $obj->setVar("content_weight", ''); + $error_message .= PageLocale::E_WEIGHT . '<br />'; + $obj->setVar('content_weight', 0); } else { - $obj->setVar("content_weight", $_POST["content_weight"]); + $obj->setVar('content_weight', $request->asInt('content_weight', 0)); } if ($error == true){ $xoops->tpl()->assign('error_message', $error_message); } else { - if ($content_Handler->insert($obj)) { - $newcontent_id = $obj->get_new_id(); - $perm_id = isset($_REQUEST['content_id']) ? $content_id : $newcontent_id; - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('gperm_itemid', $perm_id, '=')); - $criteria->add(new Criteria('gperm_modid', $xoops->module->getVar('mid'),'=')); - $criteria->add(new Criteria('gperm_name', 'page_view_item', '=')); - $gperm_handler->deleteAll($criteria); - //permissions view - if(isset($_POST['groups_view_item'])) { - foreach($_POST['groups_view_item'] as $onegroup_id) { - $gperm_handler->addRight('page_view_item', $perm_id, $onegroup_id, $xoops->module->getVar('mid')); - } - } + if ($newcontent_id = $content_Handler->insert($obj)) { + // update permissions + $perm_id = $content_id > 0 ? $content_id : $newcontent_id; + $groups_view_item = $request->asArray('groups_view_item', array()); + $gperm_Handler->updatePerms($perm_id, $groups_view_item); + //notifications - if ($content_id == 0) { - if ($xoops->isActiveModule('notifications')) { - $notification_handler = Notifications::getInstance()->getHandlerNotification(); - $tags = array(); - $tags['MODULE_NAME'] = 'page'; - $tags['ITEM_NAME'] = $_POST["content_title"]; - $tags['ITEM_URL'] = XOOPS_URL . '/modules/page/viewpage.php?id=' . $newcontent_id; - $notification_handler->triggerEvent('global', 0, 'newcontent', $tags); - $notification_handler->triggerEvent('item', $newcontent_id, 'newcontent', $tags); - } + if ($content_id == 0 && $xoops->isActiveModule('notifications')) { + $notification_handler = Notifications::getInstance()->getHandlerNotification(); + $tags = array(); + $tags['MODULE_NAME'] = 'page'; + $tags['ITEM_NAME'] = $request->asStr('content_title', ''); + $tags['ITEM_URL'] = XOOPS_URL . '/modules/page/viewpage.php?id=' . $newcontent_id; + $notification_handler->triggerEvent('global', 0, 'newcontent', $tags); + $notification_handler->triggerEvent('item', $newcontent_id, 'newcontent', $tags); } - $xoops->redirect("content.php", 2, _AM_PAGE_DBUPDATED); + $xoops->redirect('content.php', 2, XoopsLocale::S_DATABASE_UPDATED); } echo $xoops->alert('error', $obj->getHtmlErrors()); } - $form = $xoops->getModuleForm($obj, 'page_content'); + $form = $helper->getForm($obj, 'page_content'); $xoops->tpl()->assign('form', $form->render()); break; case 'delete': - $admin_page->addItemButton(_AM_PAGE_CONTENT_LIST, 'content.php', 'application-view-detail'); - $admin_page->addItemButton(_AM_PAGE_CONTENT_ADD, 'content.php?op=new', 'add'); + $admin_page->addItemButton(PageLocale::A_LIST_CONTENT, 'content.php', 'application-view-detail'); + $admin_page->addItemButton(PageLocale::A_ADD_CONTENT, 'content.php?op=new', 'add'); $admin_page->renderButton(); - // Define Stylesheet - $xoops->theme()->addStylesheet('modules/system/css/admin.css'); - $content_id = $system->cleanVars($_REQUEST, 'id', 0, 'int'); + + $content_id = $request->asInt('content_id', 0); + $ok = $request->asInt('ok', 0); + $obj = $content_Handler->get($content_id); - if (isset($_POST["ok"]) && $_POST["ok"] == 1) { + if ($ok == 1) { if (!$xoops->security()->check()) { - $xoops->redirect("content.php", 3, implode(",", $xoops->security()->getErrors())); + $xoops->redirect('content.php', 3, implode(',', $xoops->security()->getErrors())); } // Deleting the content - if ($content_Handler->delete($obj)) { - // deleting permissions + if ($content_Handler->delete($obj)) { + // update permissions + $gperm_Handler->updatePerms($content_id); + + // deleting page_related_link $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('gperm_itemid', $content_id, '=')); - $criteria->add(new Criteria('gperm_modid', $xoops->module->getVar('mid'),'=')); - $criteria->add(new Criteria('gperm_name', 'page_view_item', '=')); - $gperm_handler->deleteAll($criteria); - // deleting secondary - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('related_group', 0, '!=')); - $criteria->add(new Criteria('related_contentid', $content_id)); - $related_Handler->deleteAll($criteria); + $criteria->add(new Criteria('link_content_id', $content_id)); + $link_Handler->deleteAll($criteria); + // deleting comments - if ($xoops->isActiveModule('comments')) { - $comment_handler = Comments::getInstance()->getHandlerComment()->deleteByItemId($xoops->module->getVar('mid'), $content_id); - } - // deleting main and secondary - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('related_group', 0)); - $criteria->add(new Criteria('related_contentid', $content_id)); - $related_arr = $related_Handler->getAll($criteria); - if (count($related_arr) > 0) { - foreach (array_keys($related_arr) as $i) { - $obj_related = $related_Handler->get($related_arr[$i]->getVar("related_id")); - $related_Handler->delete($obj_related); - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('related_group', $related_arr[$i]->getVar("related_id"))); - $related_Handler->deleteAll($criteria); - } - } - $xoops->redirect("content.php", 2, _AM_PAGE_DBUPDATED); + if ($xoops->isActiveModule('comments')) { + $comment_handler = Comments::getInstance()->getHandlerComment()->deleteByItemId($helper->getModule()->getVar('mid'), $content_id); } + + $xoops->redirect('content.php', 2, XoopsLocale::S_DATABASE_UPDATED); } else { echo $xoops->alert('error', $obj->getHtmlErrors()); } } else { // deleting main and secondary - $related_name = ''; - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('related_group', 0)); - $criteria->add(new Criteria('related_contentid', $content_id)); - $related_arr = $related_Handler->getAll($criteria); - if (count($related_arr) > 0) { - $related_name .= '<br />' . _AM_PAGE_RELATED_DELMAIN . '<br />'; - foreach (array_keys($related_arr) as $i) { - $related_name .= '<span style="color : Red">'; - $related_name .= $related_arr[$i]->getVar("related_name"); - $related_name .= '</span>'; - $related_name .= '<br />'; - } - } - $xoops->confirm(array("ok" => 1, "id" => $content_id, "op" => "delete"), 'content.php', sprintf(_AM_PAGE_SUREDEL, $obj->getvar('content_title')) . '<br />' . $related_name); + $xoops->confirm(array('ok' => 1, 'content_id' => $content_id, 'op' => 'delete'), 'content.php', + XoopsLocale::Q_ARE_YOU_SURE_YOU_WANT_TO_DELETE_THIS_ITEM . '<br /><span class="red">' . $obj->getvar('content_title') . '<span>'); } break; case 'update_status': - $content_id = $system->cleanVars($_POST, 'content_id', 0, 'int'); + $content_id = $request->asInt('content_id', 0); if ($content_id > 0) { $obj = $content_Handler->get($content_id); $old = $obj->getVar('content_status'); @@ -306,7 +212,7 @@ break; case 'update_display': - $content_id = $system->cleanVars($_POST, 'content_id', 0, 'int'); + $content_id = $request->asInt('content_id', 0); if ($content_id > 0) { $obj = $content_Handler->get($content_id); $old = $obj->getVar('content_maindisplay'); @@ -319,47 +225,15 @@ break; case 'clone': - $content_id = $system->cleanVars($_REQUEST, 'id', 0, 'int'); - $content = $content_Handler->get($content_id); - $obj = $content_Handler->create(); - $obj->setVar("content_title", _AM_PAGE_CONTENT_COPY . $content->getVar("content_title")); - $obj->setVar("content_weight", 0); - $obj->setVar("content_create", time()); - $obj->setVar("content_shorttext", $content->getVar("content_shorttext")); - $obj->setVar("content_text", $content->getVar("content_text")); - $obj->setVar("content_mkeyword", $content->getVar("content_mkeyword")); - $obj->setVar("content_mdescription", $content->getVar("content_mdescription")); - $obj->setVar("content_author", $content->getVar("content_author")); - $obj->setVar("content_status", $content->getVar("content_status")); - $obj->setVar("content_maindisplay", $content->getVar("content_maindisplay")); - $obj->setVar("content_dopdf", $content->getVar("content_dopdf")); - $obj->setVar("content_doprint", $content->getVar("content_doprint")); - $obj->setVar("content_domail", $content->getVar("content_domail")); - $obj->setVar("content_doauthor", $content->getVar("content_doauthor")); - $obj->setVar("content_dodate", $content->getVar("content_dodate")); - $obj->setVar("content_dohits", $content->getVar("content_dohits")); - $obj->setVar("content_dorating", $content->getVar("content_dorating")); - $obj->setVar("content_docoms", $content->getVar("content_docoms")); - $obj->setVar("content_doncoms", $content->getVar("content_doncoms")); - $obj->setVar("content_dosocial", $content->getVar("content_dosocial")); - $obj->setVar("content_dotitle", $content->getVar("content_dotitle")); - $obj->setVar("content_donotifications", $content->getVar("content_donotifications")); - if ($content_Handler->insert($obj)) { - $newcontent_id = $obj->get_new_id(); - $gperm_handler = $xoops->getHandler('groupperm'); - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('gperm_itemid', $content_id, '=')); - $criteria->add(new Criteria('gperm_modid', $xoops->module->getVar('mid'),'=')); - $criteria->add(new Criteria('gperm_name', 'page_view_item', '=')); - $gperm_arr = $gperm_handler->getall($criteria); - //permissions view - foreach (array_keys($gperm_arr) as $i) { - $gperm_handler->addRight('page_view_item', $newcontent_id, $gperm_arr[$i]->getVar("gperm_groupid"), $xoopsModule->getVar('mid')); - } - $xoops->redirect("content.php", 2, _AM_PAGE_DBUPDATED); + $content_id = $request->asInt('content_id', 0); + $obj = $content_Handler->getClone($content_id); + + if ($newcontent_id = $content_Handler->insert($obj)) { + $gperm_arr = $gperm_Handler->getGroupIds('page_view_item', $content_id, $module_id); + $gperm_Handler->updatePerms($newcontent_id, array_values($gperm_arr)); + $xoops->redirect('content.php', 2, XoopsLocale::S_DATABASE_UPDATED); } echo $xoops->alert('error', $obj->getHtmlErrors()); - break; } $xoops->footer(); \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/header.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/header.php 2013-01-29 13:28:01 UTC (rev 10943) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/header.php 2013-01-29 16:25:04 UTC (rev 10944) @@ -21,5 +21,31 @@ */ require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/include/cp_header.php'; -$xoops = Xoops::getInstance(); -XoopsLoad::load('system', 'system'); \ No newline at end of file +// Get main instance +XoopsLoad::load('system', 'system'); +$system = System::getInstance(); + +$request = Xoops_Request::getInstance(); +$helper = Page::getInstance(); +$xoops = $helper->xoops(); + +// Get handler +$content_Handler = $helper->getContentHandler(); +$related_Handler = $helper->getRelatedHandler(); +$link_Handler = $helper->getLinkHandler(); +$rating_Handler = $helper->getRatingHandler(); +$gperm_Handler = $helper->getGrouppermHandler(); + +// Get $_POST, $_GET, $_REQUEST +$op = $request->asStr('op', 'list'); +$start = $request->asInt('start', 0); + +// Parameters +$nb_limit = $helper->getConfig('page_adminpager'); +$module_id = $helper->getModule()->getVar('mid'); + +// Define Stylesheet +$xoops->theme()->addStylesheet('modules/system/css/admin.css'); + +// Add Scripts +$xoops->theme()->addScript('media/xoops/xoops.js'); Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/index.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/index.php 2013-01-29 13:28:01 UTC (rev 10943) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/index.php 2013-01-29 16:25:04 UTC (rev 10944) @@ -20,39 +20,39 @@ * @version $Id$ */ include dirname(__FILE__) . '/header.php'; + // heaser -$xoops = Xoops::getInstance(); $xoops->header(); -// Get page handler -$content_Handler = $xoops->getModuleHandler('page_content'); // content not display $criteria = new CriteriaCompo(); $criteria->add(new Criteria('content_status', 0)); $content_notdisplay = $content_Handler->getCount($criteria); + // content display $criteria = new CriteriaCompo(); $criteria->add(new Criteria('content_status', 0, '!=')); $content_display = $content_Handler->getCount($criteria); -// folder path -//$folder_path = XOOPS_ROOT_PATH . '/uploads/page'; - $admin_page = new XoopsModuleAdmin(); $admin_page->displayNavigation('index.php'); // content -$admin_page->addInfoBox(_MI_PAGE_CONTENT, 'content'); -$admin_page->addInfoBoxLine(sprintf(_AM_PAGE_INDEX_TOTALCONTENT, $content_notdisplay + $content_display), 'content'); -$admin_page->addInfoBoxLine(sprintf(_AM_PAGE_INDEX_TOTALDISPLAY, '<span class="green">' . $content_display . '</span>'), 'content'); -$admin_page->addInfoBoxLine(sprintf(_AM_PAGE_INDEX_TOTALNOTDISPLAY, '<span class="red">' . $content_notdisplay . '</span>'), 'content'); +$admin_page->addInfoBox(XoopsLocale::CONTENT, 'content'); +$admin_page->addInfoBoxLine(sprintf(PageLocale::TOTALCONTENT, $content_notdisplay + $content_display), 'content'); +$admin_page->addInfoBoxLine(sprintf(PageLocale::TOTALDISPLAY, $content_display), 'content'); +$admin_page->addInfoBoxLine(sprintf(PageLocale::TOTALNOTDISPLAY, $content_notdisplay), 'content'); // extension +$extensions = array('comments' => 'extension', + 'notifications' => 'extension', + 'pdf' => 'extension', + 'xoosocialnetwork' => 'extension', + ); -$admin_page->addConfigBoxLine(array('comments', 'warning'), 'extension'); -$admin_page->addConfigBoxLine(array('notifications', 'warning'), 'extension'); -$admin_page->addConfigBoxLine(array('pdf', 'warning'), 'extension'); -$admin_page->addConfigBoxLine(array('xoosocialnetwork', 'warning'), 'extension'); +foreach ($extensions as $module => $type) { + $admin_page->addConfigBoxLine(array($module, 'warning'), $type); +} $admin_page->displayIndex(); $xoops->footer(); \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/menu.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/menu.php 2013-01-29 13:28:01 UTC (rev 10943) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/menu.php 2013-01-29 16:25:04 UTC (rev 10944) @@ -22,22 +22,22 @@ $adminmenu = array(); $i = 1; -$adminmenu[$i]['title'] = _MI_PAGE_INDEX; +$adminmenu[$i]['title'] = XoopsLocale::HOME; $adminmenu[$i]['link'] = 'admin/index.php'; $adminmenu[$i]['icon'] = 'home.png'; $i++; -$adminmenu[$i]['title'] = _MI_PAGE_CONTENT; +$adminmenu[$i]['title'] = PageLocale::SYSTEM_CONTENT; $adminmenu[$i]['link'] = 'admin/content.php'; $adminmenu[$i]['icon'] = 'content.png'; $i++; -$adminmenu[$i]['title'] = _MI_PAGE_RELATED; +$adminmenu[$i]['title'] = PageLocale::SYSTEM_RELATED; $adminmenu[$i]['link'] = 'admin/related.php'; $adminmenu[$i]['icon'] = 'groupmod.png'; $i++; -$adminmenu[$i]['title'] = _MI_PAGE_PERMISSIONS; +$adminmenu[$i]['title'] =PageLocale::SYSTEM_PERMISSIONS; $adminmenu[$i]['link'] = 'admin/permissions.php'; $adminmenu[$i]['icon'] = 'permissions.png'; $i++; -$adminmenu[$i]['title'] = _MI_PAGE_ABOUT; +$adminmenu[$i]['title'] = PageLocale::SYSTEM_ABOUT; $adminmenu[$i]['link'] = 'admin/about.php'; $adminmenu[$i]['icon'] = 'about.png'; \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/permissions.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/permissions.php 2013-01-29 13:28:01 UTC (rev 10943) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/permissions.php 2013-01-29 16:25:04 UTC (rev 10944) @@ -19,42 +19,32 @@ * @author Mage Gr�gory (AKA Mage) * @version $Id$ */ + include dirname(__FILE__) . '/header.php'; -// Get main instance -$system = System::getInstance(); -$xoops = Xoops::getInstance(); -// Parameters -$nb_content = $xoops->getModuleConfig('page_adminpager'); + // Get Action type -$op = $system->cleanVars($_REQUEST, 'op', 'global', 'string'); -// Get handler -$content_Handler = $xoops->getModuleHandler('page_content'); -$gperm_handler = $xoops->getHandler('groupperm'); +$op = $request->asStr('op', 'global'); + // Call header $xoops->header('page_admin_permissions.html'); -// Get start pager -$start = $system->cleanVars($_REQUEST, 'start', 0, 'int'); - $admin_page = new XoopsModuleAdmin(); $admin_page->renderNavigation('permissions.php'); $opform = new XoopsSimpleForm('', 'opform', 'permissions.php', 'get'); -$op_select = new XoopsFormSelect("", 'op', $op); +$op_select = new XoopsFormSelect('', 'op', $op); $op_select->setExtra('onchange="document.forms.opform.submit()"'); -$op_select->addOption('global', _AM_PAGE_PERMISSIONS_GLOBAL); -$op_select->addOption('view', _AM_PAGE_PERMISSIONS_VIEW); +$op_select->addOption('global', PageLocale::PERMISSIONS_RATE); +$op_select->addOption('view', PageLocale::PERMISSIONS_VIEW); $opform->addElement($op_select); $xoops->tpl()->assign('form', $opform->render()); -$module_id = $xoops->module->getVar('mid'); - switch ($op) { case 'global': - default: - $global_perm_array = array('4' => _AM_PAGE_PERMISSIONS_GLOBAL_RATE); - $form = new XoopsGroupPermForm(_AM_PAGE_PERMISSIONS_GLOBAL, $module_id, "page_global", _AM_PAGE_PERMISSIONS_GLOBAL_DSC, 'admin/permissions.php', true); + default: + $global_perm_array = array('1' => PageLocale::PERMISSIONS_RATE); + $form = new XoopsGroupPermForm('', $module_id, 'page_global', '', 'admin/permissions.php', true); foreach( $global_perm_array as $perm_id => $perm_name ) { $form->addItem($perm_id , $perm_name) ; } @@ -62,55 +52,44 @@ break; case 'view': - // View permission + // Content + $content_count = $content_Handler->countPage($start, $nb_limit); + $content_arr = $content_Handler->getPage($start, $nb_limit); - // Add Scripts - $xoops->theme()->addScript('media/xoops/xoops.js'); - // Criteria - $criteria = new CriteriaCompo(); - $criteria->setSort('content_weight ASC, content_title'); - $criteria->setOrder('ASC'); - $criteria->setStart($start); - $criteria->setLimit($nb_content); - $content_count = $content_Handler->getCount($criteria); - $content_arr = $content_Handler->getAll($criteria); // Assign Template variables $xoops->tpl()->assign('content_count', $content_count); + if ($content_count > 0) { - $member_handler = $xoops->getHandler('member'); - $group_list = $member_handler->getGroupList(); + $group_list = $xoops->getHandler('member')->getGroupList(); - $module_id = $xoops->isModule() ? $xoops->module->getVar('mid', 'n') : 1; - $xoops->tpl()->assign('groups', $group_list); foreach (array_keys($content_arr) as $i) { - $content_id = $content_arr[$i]->getVar("content_id"); + $content_id = $content_arr[$i]->getVar('content_id'); $perms = ''; - $groups_ids_view = $gperm_handler->getGroupIds('page_view_item', $content_id, $module_id); + $groups_ids_view = $gperm_Handler->getGroupIds('page_view_item', $content_id, $module_id); $groups_ids_view = array_values($groups_ids_view); foreach (array_keys($group_list) as $j) { $perms .= '<img id="loading_display' . $content_id . '_' . $j .'" src="' . $xoops->url('media/xoops/images/spinner.gif') . '" style="display:none;" alt="' . _AM_SYSTEM_LOADING . '" />'; if (in_array($j, $groups_ids_view)) { - $perms .= "<img class=\"cursorpointer\" id=\"display" . $content_id . "_" . $j . "\" onclick=\"Xoops.changeStatus( 'permissions.php', { op: 'update_view', content_id: " . $content_id . ", group: " . $j . ", status: 'no' }, 'display" . $content_id . "_" . $j ."', 'permissions.php' )\" src=\"" . $xoops->url('modules/system/images/icons/default/success.png') . "\" alt=\"" . _AM_PAGE_OFF . "\" title=\"" . _AM_PAGE_OFF . "\" />"; + $perms .= "<img class=\"cursorpointer\" id=\"display" . $content_id . "_" . $j . "\" onclick=\"Xoops.changeStatus( 'permissions.php', { op: 'update_view', content_id: " . $content_id . ", group: " . $j . ", status: 'no' }, 'display" . $content_id . "_" . $j ."', 'permissions.php' )\" src=\"" . $xoops->url('modules/system/images/icons/default/success.png') . "\" alt=\"" . XoopsLocale::A_DISABLE . "\" title=\"" . XoopsLocale::A_DISABLE . "\" />"; } else { - $perms .= "<img class=\"cursorpointer\" id=\"display" . $content_id . "_" . $j . "\" onclick=\"Xoops.changeStatus( 'permissions.php', { op: 'update_view', content_id: " . $content_id . ", group: " . $j . ", status: 'yes' }, 'display" . $content_id . "_" . $j ."', 'permissions.php' )\" src=\"" . $xoops->url('modules/system/images/icons/default/cancel.png') . "\" alt=\"" . _AM_PAGE_ON . "\" title=\"" . _AM_PAGE_ON . "\" />"; - + $perms .= "<img class=\"cursorpointer\" id=\"display" . $content_id . "_" . $j . "\" onclick=\"Xoops.changeStatus( 'permissions.php', { op: 'update_view', content_id: " . $content_id . ", group: " . $j . ", status: 'yes' }, 'display" . $content_id . "_" . $j ."', 'permissions.php' )\" src=\"" . $xoops->url('modules/system/images/icons/default/cancel.png') . "\" alt=\"" . XoopsLocale::A_ENABLE . "\" title=\"" . XoopsLocale::A_ENABLE . "\" />"; } $perms .= $group_list[$j] . '<br />'; } $content['id'] = $content_id; - $content['title'] = $content_arr[$i]->getVar("content_title"); + $content['title'] = $content_arr[$i]->getVar('content_title'); $content['permissions'] = $perms; $xoops->tpl()->append_by_ref('content', $content); unset($content); } // Display Page Navigation - if ($content_count > $nb_content) { - $nav = new XoopsPageNav($content_count, $nb_content, $start, 'start', 'op=view'); + if ($content_count > $nb_limit) { + $nav = new XoopsPageNav($content_count, $nb_limit, $start, 'start', 'op=view'); $xoops->tpl()->assign('nav_menu', $nav->renderNav(4)); } } else { - $xoops->tpl()->assign('error_message', _AM_PAGE_CONTENT_ERROR_NOCONTENT); + $xoops->tpl()->assign('error_message', PageLocale::E_NO_CONTENT); } break; @@ -122,17 +101,16 @@ if ($status == 'no') { // deleting permissions $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('gperm_groupid', $group, '=')); - $criteria->add(new Criteria('gperm_itemid', $content_id, '=')); - $criteria->add(new Criteria('gperm_modid', $xoopsModule->getVar('mid'),'=')); - $criteria->add(new Criteria('gperm_name', 'page_view_item', '=')); - $gperm_handler->deleteAll($criteria); + $criteria->add(new Criteria('gperm_groupid', $group)); + $criteria->add(new Criteria('gperm_itemid', $content_id)); + $criteria->add(new Criteria('gperm_modid', $module_id)); + $criteria->add(new Criteria('gperm_name', 'page_view_item')); + $gperm_Handler->deleteAll($criteria); } else { // add permissions - $gperm_handler->addRight('page_view_item', $content_id, $group, $xoopsModule->getVar('mid')); + $gperm_Handler->addRight('page_view_item', $content_id, $group, $module_id); } } break; } - $xoops->footer(); \ No newline at end of file Modified: XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/related.php =================================================================== --- XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/related.php 2013-01-29 13:28:01 UTC (rev 10943) +++ XoopsCore/branches/2.6.x/2.6.0/htdocs/modules/page/admin/related.php 2013-01-29 16:25:04 UTC (rev 10944) @@ -20,20 +20,9 @@ * @version $Id$ */ include dirname(__FILE__) . '/header.php'; -// Get main instance -$system = System::getInstance(); -$xoops = Xoops::getInstance(); -// Parameters -$nb_related = $xoops->getModuleConfig('page_adminpager'); -// Get Action type -$op = $system->cleanVars($_REQUEST, 'op', 'default', 'string'); -// Get handler -$related_Handler = $xoops->getModuleHandler('page_related'); -$content_Handler = $xoops->getModuleHandler('page_content'); + // Call header $xoops->header('page_admin_related.html'); -// Get start pager -$start = $system->cleanVars($_REQUEST, 'start', 0, 'int'); $admin_page = new XoopsModuleAdmin(); $admin_page->renderNavigation('related.php'); @@ -42,186 +31,148 @@ case 'list': default: - // Define Stylesheet - $xoops->theme()->addStylesheet('media/jquery/ui/' . $xoops->getModuleConfig('jquery_theme', 'system') . '/ui.all.css'); - // Define scripts - $xoops->theme()->addScript('media/xoops/xoops.js'); - $xoops->theme()->addScript($xoops->url('/media/jquery/ui/jquery.ui.js')); - $xoops->theme()->addScript('modules/system/js/admin.js'); - - $admin_page->addTips(_AM_PAGE_RELATED_TIPS); - $admin_page->addItemButton(_AM_PAGE_RELATED_ADD, 'related.php?op=new', 'add'); + $admin_page->addTips(PageLocale::RELATED_TIPS); + $admin_page->addItemButton(PageLocale::A_ADD_RELATED, 'related.php?op=new', 'add'); $admin_page->renderTips(); $admin_page->renderButton(); - //joint - $criteria = new CriteriaCompo(); - $criteria->setSort('related_name'); - $criteria->setOrder('ASC'); - $criteria->setStart($start); - $criteria->setLimit($nb_related); - $criteria->add(new Criteria('related_name', '/', '!=')); - $related_Handler->table_link = $related_Handler->db->prefix('page_content'); - $related_Handler->field_link = 'content_id'; // champ de la table en jointure - $related_Handler->field_object = 'related_contentid'; // champ de la table courante - $related_arr = $related_Handler->getByLink($criteria); - $related_count = $related_Handler->getCount($criteria); - // Assign Template variables + $related_count = $related_Handler->countRelated($start, $nb_limit); + $related_arr = $related_Handler->getRelated($start, $nb_limit); + $xoops->tpl()->assign('related_count', $related_count); + $xoops->tpl()->assign('related', $related_arr); + if ($related_count > 0) { - foreach (array_keys($related_arr) as $i) { - $related_id = $related_arr[$i]->getVar("related_id"); - $related['id'] = $related_id; - $related['name'] = $related_arr[$i]->getVar("related_name"); - $related['main_name'] = $related_arr[$i]->getVar("content_title"); - $related['main_contentid'] = $related_arr[$i]->getVar("related_contentid"); - $related['domenu'] = $related_arr[$i]->getVar("related_domenu"); - switch ($related_arr[$i]->getVar("related_navigation")) { - case 1: - default: - $related['navigation'] = _AM_PAGE_RELATED_NAVIGATION_OPTION1; - break; - case 2: - $related['navigation'] = _AM_PAGE_RELATED_NAVIGATION_OPTION2; - break; - case 3: - $related['navigation'] = _AM_PAGE_RELATED_NAVIGATION_OPTION3; - break; - case 4: - $related['navigation'] = _AM_PAGE_RELATED_NAVIGATION_OPTION4; - break; - case 5: - $related['navigation'] = _AM_PAGE_RELATED_NAVIGATION_OPTION5; - break; - } - //joint - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('related_group', $related_arr[$i]->getVar("related_contentid"))); - $criteria->setSort('related_weight'); - $criteria->setOrder('ASC'); - $related_Handler->table_link = $related_Handler->db->prefix('page_content'); - $related_Handler->field_link = 'content_id'; // champ de la table en jointure - $related_Handler->field_object = 'related_contentid'; // champ de la table courante - $secondary_arr = $related_Handler->getByLink($criteria); - $related['secondary'] = ''; - if (count($secondary_arr) != 0) { - - $related['secondary'] .= '<ul>'; - foreach (array_keys($secondary_arr) as $j) { - if ($secondary_arr[$j]->getVar("related_name") == '/') { - $related['secondary'] .= '<li><a href="content.php?op=edit&id=' . $secondary_arr[$j]->getVar("related_contentid") . '" title="' . _AM_PAGE_EDIT . '">' . $secondary_arr[$j]->getVar("content_title") . '</a></li>'; - } - } - $related['secondary'] .= '</ul>'; - } - $xoops->tpl()->append_by_ref('related', $related); - $xoops->tpl()->append_by_ref('popup_related', $related); - unset($related); - } // Display Page Navigation - if ($related_count > $nb_related) { - $nav = new XoopsPageNav($related_count, $nb_related, $start, 'start'); + if ($related_count > $nb_limit) { + $nav = new XoopsPageNav($related_count, $nb_limit, $start, 'start'); $xoops->tpl()->assign('nav_menu', $nav->renderNav(4)); } } else { - $xoops->tpl()->assign('error_message', _AM_PAGE_RELATED_ERROR_NORELATED); + $xoops->tpl()->assign('error_message', PageLocale::E_NO_RELATED); } break; case 'new': if ($related_Handler->getCount() == $content_Handler->getCount()) { - $xoops->tpl()->assign('error_message', _AM_PAGE_RELATED_ERROR_NOFREECONTENT); + $xoops->tpl()->assign('error_message', PageLocale::E_NO_FREE_CONTENT); } else { - $admin_page->addItemButton(_AM_PAGE_CONTENT_LIST, 'related.php', 'application-view-detail'); + $admin_page->addItemButton(PageLocale::A_LIST_CONTENT, 'related.php', 'application-view-detail'); $admin_page->renderButton(); $obj = $related_Handler->create(); - $form = $xoops->getModuleForm($obj, 'page_related'); + $form = $helper->getForm($obj, 'page_related'); $xoops->tpl()->assign('form', $form->render()); } break; case 'edit': - $admin_page->addItemButton(_AM_PAGE_CONTENT_LIST, 'related.php', 'application-view-detail'); - $admin_page->addItemButton(_AM_PAGE_CONTENT_ADD, 'related.php?op=new', 'add'); + $admin_page->addItemButton(PageLocale::A_LIST_CONTENT, 'related.php', 'application-view-detail'); + $admin_page->addItemButton(PageLocale::A_ADD_CONTENT, 'related.php?op=new', 'add'); $admin_page->renderButton(); // Create form - $obj = $related_Handler->get($system->cleanVars($_REQUEST, 'id', 0, 'int')); - $form = $xoops->getModuleForm($obj, 'page_related'); + $related_id = $request->asInt('related_id', 0); + $obj = $related_Handler->get($related_id); + $form = $helper->getForm($obj, 'page_related'); $xoops->tpl()->assign('form', $form->render()); break; case 'save': if (!$xoops->security()->check()) { - $xoops->redirect("related.php", 3, implode(",", $xoops->security()->getErrors())); + $xoops->redirect('related.php', 3, implode(',', $xoops->security()->getErrors())); } - $related_id = $system->cleanVars($_REQUEST, 'related_id', 0, 'int'); + + $related_id = $request->asInt('related_id', 0); if ($related_id > 0) { $obj = $related_Handler->get($related_id); - $criteria = new CriteriaCompo(); - $criteria->add(new Criteria('related_group', $obj->getVar('related_group'))); - $criteria->add(new Criteria('related_name', '/')); - $related_Handler->deleteAll($criteria); } else { $obj = $related_Handler->create(); } + //main - $obj->setVar("related_name", $_POST["related_name"]); - $obj->setVar("related_group", $_POST["related_main"]); - $obj->setVar("related_contentid", $_POST["related_main"]); - $obj->setVar("related_domenu", $_POST["related_domenu"]); - $obj->setVar("related_navigation", $_POST["related_navigation"]); - if ($related_Handler->insert($obj)) { - //secondary - $secondary_max = 10; - for ($i = 1; $i <= $secondary_max; $i++) { - if ($_POST["related_secondary" . $i] != 0 && $_POST["related_secondary" . $i] != $_POST["related_main"]) { - $obj = $related_Handler->create(); - $obj->setVar("related_name", "/"); - $obj->setVar("related_group", $_POST["related_main"]); - $obj->setVar("related_contentid", $_POST["related_secondary" . $i]); - $obj->setVar("related_domenu", $_POST["related_domenu"]); - $obj->setVar("related_navigation", $_POST["related_navigation"]); - $obj->setVar("related_weight", $i); - $related_Handler->insert($obj); - unset($obj); + $obj->setVar('related_name', $request->asStr('related_name', '')); + $obj->setVar('related_domenu', $request->asInt('related_domenu', 1)); + $obj->setVar('related_navigation', $request->asInt('related_navigation', 1)); + + if ( $related_newid = $related_Handler->insert($obj)) { + $related_id = $related_id != 0 ? $related_id : $related_newid; + $datas = $request->asArray('datas'); + $datas_exists = $link_Handler->getContentByRelated($related_newid); + $datas_delete = array_diff(array_values($datas_exists), $datas); + $datas_add = array_diff($datas, array_values($datas_exists)); + + // delete + if (count($datas_delete) != 0 ) { + $criteria = $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('link_related_id', $related_id)); + $criteria->add(new Criteria('link_content_id', '(' . implode(', ', $datas_delete) . ')', 'IN')); + $links_ids = $link_Handler->getIds($criteria); + if (!$link_Handler->DeleteByIds($links_ids)) { } } - $xoops->redirect("related.php", 2, _AM_PAGE_DBUPDATED); + // Add + if (count($datas_add) != 0 ) { + foreach ($datas_add as $weight => $content_id) { + $obj = $link_Handler->create(); + $obj->setVar('link_related_id', $related_id); + $obj->setVar('link_content_id', $content_id); + $obj->setVar('link_weight', $weight); + if (!$link_Handler->insert($obj)) { + } + } + } + //update + if (count($datas) != 0 ) { + foreach ($datas as $weight => $content_id) { + $criteria = $criteria = new CriteriaCompo(); + $criteria->add(new Criteria('link_related_id', $related_id)); + $criteria->add(new Criteria('link_content_id', $content_id)); + $links_ids = $link_Handler->getIds($criteria); + + $obj = $link_Handler->get($links_ids[0]); + $obj->setVar('link_weight', $weight); + if (!$link_Handler->insert($obj)) { + } + } + } + + $xoops->redirect('related.php', 2, XoopsLocale::S_DATABASE_UPDATED); } else { echo $xoops->alert('error', $obj->getHtmlErrors()); } - $form = $xoops->getModuleForm($obj, 'page_related'); + $form = $helper->getForm($obj, 'page_related'); $xoops->tpl()->assign('form', $form->render()); break; case 'delete': - $admin_page->addItemButton(_AM_PAGE_CONTENT_LIST, 'related.php', 'application-view-detail'); - $admin_page->addItemButton(_AM_PAGE_CONTENT_ADD, 'related.php?op=new', 'add'); + $admin_page->addItemButton(PageLocale::A_LIST_CONTENT, 'related.php', 'application-view-detail'); + $admin_page->addItemButton(PageLocale::A_ADD_CONTENT, 'related.php?op=new', 'add'); $admin_page->renderButton(); - // Define Stylesheet - $xoops->theme()->addStylesheet('modules/system/css/admin.css'); - $related_id = $system->cleanVars($_REQUEST, 'id', 0, 'int'); + + $related_id = $request->asInt('related_id', 0); + $ok = $request->asInt('ok', 0); + $obj = $related_Handler->get($related_id); - if (isset($_POST["ok"]) && $_POST["ok"] == 1) { + if ($ok == 1) { if (!$xoops->security()->check()) { - $xoops->redirect("related.php", 3, implode(",", $xoops->security()->getErrors())); + $xoops->redirect('related.php', 3, implode(',', $xoops->security()->getErrors())); } ... [truncated message content] |