📄 admin.categories.php
字号:
* @param string The name of the category section* @param array An array of unique category id numbers*/function removeCategories( $section, $cid ) { global $database; global $adminLanguage; if (count( $cid ) < 1) { echo "<script> alert('".$adminLanguage->A_COMP_CATEG_DELETE."'); window.history.go(-1);</script>\n"; exit; } $cids = implode( ',', $cid ); //Get Section ID prior to removing Category, in order to update counts //$database->setQuery( "SELECT section FROM #__categories WHERE id IN ($cids)" ); //$secid = $database->loadResult(); if (intval( $section ) > 0) { $table = 'content'; } else if (strpos( $section, 'com_' ) === 0) { $table = substr( $section, 4 ); } else { $table = $section; } $query = "SELECT c.id, c.name, COUNT(s.catid) AS numcat" . "\n FROM #__categories AS c" . "\n LEFT JOIN #__$table AS s ON s.catid=c.id" . "\n WHERE c.id IN ($cids)" . "\n GROUP BY c.id" ; $database->setQuery( $query ); if (!($rows = $database->loadObjectList())) { echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; } $err = array(); $cid = array(); foreach ($rows as $row) { if ($row->numcat == 0) { $cid[] = $row->id; } else { $err[] = $row->name; } } if (count( $cid )) { $cids = implode( ',', $cid ); $database->setQuery( "DELETE FROM #__categories WHERE id IN ($cids)" ); if (!$database->query()) { echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; } } if (count( $err )) { $cids = implode( "\', \'", $err ); $msg = $adminLanguage->A_COMP_CATEG_CATEG_S.": ". $cids ." ".$adminLanguage->A_COMP_CATEG_CANNOT_REMOVE; mosRedirect( 'index2.php?option=com_categories§ion='. $section .'&mosmsg='. $msg ); } mosRedirect( 'index2.php?option=com_categories§ion='. $section );}/*** Publishes or Unpublishes one or more categories* @param string The name of the category section* @param integer A unique category id (passed from an edit form)* @param array An array of unique category id numbers* @param integer 0 if unpublishing, 1 if publishing* @param string The name of the current user*/function publishCategories( $section, $categoryid=null, $cid=null, $publish=1 ) { global $database, $my; global $adminLanguage; if (!is_array( $cid )) { $cid = array(); } if ($categoryid) { $cid[] = $categoryid; } if (count( $cid ) < 1) { $action = $publish ? 'publish' : 'unpublish'; echo "<script> alert('".$adminLanguage->A_COMP_CATEG_SELECT." ".$action."'); window.history.go(-1);</script>\n"; exit; } $cids = implode( ',', $cid ); $query = "UPDATE #__categories SET published='$publish'" . "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" ; $database->setQuery( $query ); if (!$database->query()) { echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; exit(); } if (count( $cid ) == 1) { $row = new mosCategory( $database ); $row->checkin( $cid[0] ); } mosRedirect( 'index2.php?option=com_categories§ion='. $section );}/*** Cancels an edit operation* @param string The name of the category section* @param integer A unique category id*/function cancelCategory() { global $database; $redirect = mosGetParam( $_POST, 'redirect', '' ); $row = new mosCategory( $database ); $row->bind( $_POST ); $row->checkin(); mosRedirect( 'index2.php?option=com_categories§ion='. $redirect );}/*** Moves the order of a record* @param integer The increment to reorder by*/function orderCategory( $uid, $inc ) { global $database; $row = new mosCategory( $database ); $row->load( $uid ); $row->move( $inc, "section='$row->section'" ); mosRedirect( 'index2.php?option=com_categories§ion='. $row->section );}/*** Form for moving item(s) to a specific menu*/function moveCategorySelect( $option, $cid, $sectionOld ) { global $database; global $adminLanguage; $redirect = mosGetParam( $_POST, 'section', 'content' );; if (!is_array( $cid ) || count( $cid ) < 1) { echo "<script> alert('".$adminLanguage->A_COMP_CATEG_ITEM_MOVE."'); window.history.go(-1);</script>\n"; exit; } ## query to list selected categories $cids = implode( ',', $cid ); $query = "SELECT a.name, a.section FROM #__categories AS a WHERE a.id IN ( ". $cids ." )"; $database->setQuery( $query ); $items = $database->loadObjectList(); ## query to list items from categories $query = "SELECT a.title FROM #__content AS a WHERE a.catid IN ( ". $cids ." ) ORDER BY a.catid, a.title"; $database->setQuery( $query ); $contents = $database->loadObjectList(); ## query to choose section to move to $query = "SELECT a.name AS `text`, a.id AS `value` FROM #__sections AS a WHERE a.published = '1' ORDER BY a.name"; $database->setQuery( $query ); $sections = $database->loadObjectList(); // build the html select list $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); categories_html::moveCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect );}/*** Save the item(s) to the menu selected*/function moveCategorySave( $cid, $sectionOld ) { global $database; global $adminLanguage; $sectionMove = mosGetParam( $_REQUEST, 'sectionmove', '' ); $cids = implode( ',', $cid ); $total = count( $cid ); $query = "UPDATE #__categories SET section = '". $sectionMove ."' " . "WHERE id IN ( ". $cids ." )" ; $database->setQuery( $query ); if ( !$database->query() ) { echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; exit(); } $query = "UPDATE #__content SET sectionid = '". $sectionMove ."' " . "WHERE catid IN ( ". $cids ." )" ; $database->setQuery( $query ); if ( !$database->query() ) { echo "<script> alert('". $database->getErrorMsg() ."'); window.history.go(-1); </script>\n"; exit(); } $sectionNew = new mosSection ( $database ); $sectionNew->load( $sectionMove ); $msg = $total ." ".$adminLanguage->A_COMP_CATEG_MOVED_TO." ".$sectionNew->name; mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg );}/*** Form for copying item(s) to a specific menu*/function copyCategorySelect( $option, $cid, $sectionOld ) { global $database; global $adminLanguage; $redirect = mosGetParam( $_POST, 'section', 'content' );; if (!is_array( $cid ) || count( $cid ) < 1) { echo "<script> alert('".$adminLanguage->A_COMP_CATEG_ITEM_MOVE."'); window.history.go(-1);</script>\n"; exit; } ## query to list selected categories $cids = implode( ',', $cid ); $query = "SELECT a.name, a.section FROM #__categories AS a WHERE a.id IN ( ". $cids ." )"; $database->setQuery( $query ); $items = $database->loadObjectList(); ## query to list items from categories $query = "SELECT a.title, a.id FROM #__content AS a WHERE a.catid IN ( ". $cids ." ) ORDER BY a.catid, a.title"; $database->setQuery( $query ); $contents = $database->loadObjectList(); ## query to choose section to move to $query = "SELECT a.name AS `text`, a.id AS `value` FROM #__sections AS a WHERE a.published = '1' ORDER BY a.name"; $database->setQuery( $query ); $sections = $database->loadObjectList(); // build the html select list $SectionList = mosHTML::selectList( $sections, 'sectionmove', 'class="inputbox" size="10"', 'value', 'text', null ); categories_html::copyCategorySelect( $option, $cid, $SectionList, $items, $sectionOld, $contents, $redirect );}/*** Save the item(s) to the menu selected*/function copyCategorySave( $cid, $sectionOld ) { global $database; global $adminLanguage; $sectionMove = mosGetParam( $_REQUEST, 'sectionmove', '' ); $contentid = mosGetParam( $_REQUEST, 'item', '' ); $total = count( $contentid ); $category = new mosCategory ( $database ); foreach( $cid as $id ) { $category->load( $id ); $category->id = NULL; $category->title = $adminLanguage->A_COMP_CATEG_COPY_OF." ".$category->title; $category->name = $adminLanguage->A_COMP_CATEG_COPY_OF." ".$category->name; $category->section = $sectionMove; if (!$category->check()) { echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; exit(); } if (!$category->store()) { echo "<script> alert('".$category->getError()."'); window.history.go(-1); </script>\n"; exit(); } $category->checkin(); // stores original catid $newcatids[]["old"] = $id; // pulls new catid $newcatids[]["new"] = $category->id; } $content = new mosContent ( $database ); foreach( $contentid as $id) { $content->load( $id ); $content->id = NULL; $content->sectionid = $sectionMove; $content->hits = 0; foreach( $newcatids as $newcatid ) { if ( $content->catid == $newcatid["old"] ) { $content->catid = $newcatid["new"]; } } if (!$content->check()) { echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; exit(); } if (!$content->store()) { echo "<script> alert('".$content->getError()."'); window.history.go(-1); </script>\n"; exit(); } $content->checkin(); } $sectionNew = new mosSection ( $database ); $sectionNew->load( $sectionMove ); $msg = $total ." ".$adminLanguage->A_COMP_CATEG_COPIED_TO." ".$sectionNew->name; mosRedirect( 'index2.php?option=com_categories§ion='. $sectionOld .'&mosmsg='. $msg );}/*** changes the access level of a record* @param integer The increment to reorder by*/function accessMenu( $uid, $access, $section ) { global $database; $row = new mosCategory( $database ); $row->load( $uid ); $row->access = $access; if ( !$row->check() ) { return $row->getError(); } if ( !$row->store() ) { return $row->getError(); } mosRedirect( 'index2.php?option=com_categories§ion='. $section );}function menuLink( $id ) { global $database; $category = new mosCategory( $database ); $category->bind( $_POST ); $category->checkin(); $redirect = mosGetParam( $_POST, 'redirect', '' ); $menu = mosGetParam( $_POST, 'menuselect', '' ); $name = mosGetParam( $_POST, 'link_name', '' ); $sectionid = mosGetParam( $_POST, 'sectionid', '' ); $type = mosGetParam( $_POST, 'link_type', '' ); switch ( $type ) { case 'content_category': $link = 'index.php?option=com_content&task=category§ionid='. $sectionid .'&id='. $id; $menutype = 'Content Category Table'; break; case 'content_blog_category': $link = 'index.php?option=com_content&task=blogcategory&id='. $id; $menutype = 'Content Category Blog'; break; case 'content_archive_category': $link = 'index.php?option=com_content&task=archivecategory&id='. $id; $menutype = 'Content Category Blog Archive'; break; case 'contact_category_table': $link = 'index.php?option=com_contact&catid='. $id; $menutype = 'Contact Category Table'; break; case 'newsfeed_category_table': $link = 'index.php?option=com_newsfeeds&catid='. $id; $menutype = 'Newsfeed Category Table'; break; case 'weblink_category_table': $link = 'index.php?option=com_weblinks&catid='. $id; $menutype = 'Weblink Category Table'; break; default:; } $row = new mosMenu( $database ); $row->menutype = $menu; $row->name = $name; $row->type = $type; $row->published = 1; $row->componentid = $id; $row->link = $link; $row->ordering = 9999; if (!$row->check()) { echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; exit(); } if (!$row->store()) { echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; exit(); } $row->checkin(); $row->updateOrder( "menutype='". $menu ."'" ); $msg = $name .' ( '. $menutype .' ) in menu: '. $menu .' successfully created'; mosRedirect( 'index2.php?option=com_categories§ion='. $redirect .'&task=editA&hidemainmenu=1&id='. $id, $msg );}function saveOrder( &$cid, $section ) { global $database; $total = count( $cid ); $order = mosGetParam( $_POST, 'order', array(0) ); $row = new mosCategory( $database ); $conditions = array(); // update ordering values for( $i=0; $i < $total; $i++ ) { $row->load( $cid[$i] ); if ($row->ordering != $order[$i]) { $row->ordering = $order[$i]; if (!$row->store()) { echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; exit(); } // if // remember to updateOrder this group $condition = "section='$row->section'"; $found = false; foreach ( $conditions as $cond ) if ($cond[1]==$condition) { $found = true; break; } // if if (!$found) $conditions[] = array($row->id, $condition); } // if } // for // execute updateOrder for each group foreach ( $conditions as $cond ) { $row->load( $cond[0] ); $row->updateOrder( $cond[1] ); } // foreach $msg = 'New ordering saved'; mosRedirect( 'index2.php?option=com_categories§ion='. $section, $msg );} // saveOrder?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -