📄 admin.categories.php
字号:
/*** Deletes one or more categories from the categories table* @param string The name of the category section* @param array An array of unique category id numbers*/function removeCategories( $section, $cid ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_( 'Select a category to delete', true )); } $cids = implode( ',', $cid ); if (intval( $section ) > 0) { $table = 'content'; } else if (strpos( $section, 'com_' ) === 0) { $table = substr( $section, 4 ); } else { $table = $section; } $tablesAllowed = $db->getTableList(); if (!in_array($db->getPrefix().$table, $tablesAllowed)) { $table = 'content'; } $query = 'SELECT c.id, c.name, c.title, COUNT( s.catid ) AS numcat' . ' FROM #__categories AS c' . ' LEFT JOIN #__'.$table.' AS s ON s.catid = c.id' . ' WHERE c.id IN ( '.$cids.' )' . ' GROUP BY c.id' ; $db->setQuery( $query ); if (!($rows = $db->loadObjectList())) { JError::raiseError( 500, $db->stderr() ); return false; } $err = array(); $cid = array(); foreach ($rows as $row) { if ($row->numcat == 0) { $cid[] = (int) $row->id; } else { $err[] = $row->title; } } if (count( $cid )) { $cids = implode( ',', $cid ); $query = 'DELETE FROM #__categories' . ' WHERE id IN ( '.$cids.' )' ; $db->setQuery( $query ); if (!$db->query()) { JError::raiseError( 500, $db->stderr() ); return false; } } if (count( $err )) { $cids = implode( ", ", $err ); $msg = JText::sprintf( 'WARNNOTREMOVEDRECORDS', $cids ); $mainframe->redirect( 'index.php?option=com_categories§ion='. $section, $msg ); } $mainframe->redirect( 'index.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, $cid=null, $publish=1 ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $uid = $user->get('id'); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { $action = $publish ? 'publish' : 'unpublish'; JError::raiseError(500, JText::_( 'Select a category to '.$action, true ) ); } $cids = implode( ',', $cid ); $query = 'UPDATE #__categories' . ' SET published = ' . (int) $publish . ' WHERE id IN ( '.$cids.' )' . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $uid.' ) )' ; $db->setQuery( $query ); if (!$db->query()) { JError::raiseError(500, $db->getErrorMsg() ); } if (count( $cid ) == 1) { $row =& JTable::getInstance('category'); $row->checkin( $cid[0] ); } $mainframe->redirect( 'index.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 $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $redirect = JRequest::getCmd( 'redirect', '', 'post' ); $row =& JTable::getInstance('category'); $row->bind( JRequest::get( 'post' )); $row->checkin(); $mainframe->redirect( 'index.php?option=com_categories§ion='. $redirect );}/*** Moves the order of a record* @param integer The increment to reorder by*/function orderCategory( $uid, $inc ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $row =& JTable::getInstance('category' ); $row->load( $uid ); $row->move( $inc, 'section = '.$db->Quote($row->section) ); $section = JRequest::getCmd('section'); if($section) { $section = '§ion='. $section; } $mainframe->redirect( 'index.php?option=com_categories'. $section );}/*** Form for moving item(s) to a specific menu*/function moveCategorySelect( $option, $cid, $sectionOld ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); $db =& JFactory::getDBO(); $redirect = JRequest::getCmd( 'section', 'com_content', 'post' ); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_( 'Select an item to move', true )); } ## query to list selected categories $cids = implode( ',', $cid ); $query = 'SELECT a.title, a.section' . ' FROM #__categories AS a' . ' WHERE a.id IN ( '.$cids.' )' ; $db->setQuery( $query ); $items = $db->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' ; $db->setQuery( $query ); $contents = $db->loadObjectList(); ## query to choose section to move to $query = 'SELECT a.title AS text, a.id AS value' . ' FROM #__sections AS a' . ' WHERE a.published = 1' . ' ORDER BY a.title' ; $db->setQuery( $query ); $sections = $db->loadObjectList(); // build the html select list $SectionList = JHTML::_('select.genericlist', $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 $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); $db =& JFactory::getDBO(); $sectionMove = JRequest::getCmd( 'sectionmove' ); //Check to see of a section was selected to copy the items too if (!$sectionMove) { $msg = JText::_('Please select a section from the list'); moveCategorySelect( 'com_categories', $cid, $sectionOld ); JError::raiseWarning(500, $msg); return; } JArrayHelper::toInteger($cid, array(0)); $sectionNew =& JTable::getInstance('section'); $sectionNew->load( $sectionMove ); //Remove the categories was in destination section $cids = implode( ',', $cid ); $query = 'SELECT id, title' . ' FROM #__categories' . ' WHERE id IN ( '.$cids.' )' . ' AND section = '.$db->Quote($sectionMove) ; $db->setQuery( $query ); $scid = $db->loadResultArray(0); $title = $db->loadResultArray(1); $cid = array_diff($cid, $scid); // if ( !empty($cid) ) { $cids = implode( ',', $cid ); $total = count( $cid ); $query = 'UPDATE #__categories' . ' SET section = '.$db->Quote($sectionMove) . ' WHERE id IN ( '.$cids.' )' ; $db->setQuery( $query ); if ( !$db->query() ) { JError::raiseError(500, $db->getErrorMsg() ); } $query = 'UPDATE #__content' . ' SET sectionid = '.$db->Quote($sectionMove) . ' WHERE catid IN ( '.$cids.' )' ; $db->setQuery( $query ); if ( !$db->query() ) { JError::raiseError(500, $db->getErrorMsg()); } $msg = JText::sprintf( 'Categories moved to', $sectionNew->title ); $mainframe->enqueueMessage($msg); } if ( !empty($title) && is_array($title) ) { if ( count($title) == 1 ) { $msg = JText::sprintf( 'Category already in', implode( ', ', $title ), $sectionNew->title ); } else { $msg = JText::sprintf( 'Categories already in', implode( ', ', $title ), $sectionNew->title ); } $mainframe->enqueueMessage($msg); } $mainframe->redirect( 'index.php?option=com_categories§ion='. $sectionOld );}/*** Form for copying item(s) to a specific menu*/function copyCategorySelect( $option, $cid, $sectionOld ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); $db =& JFactory::getDBO(); $redirect = JRequest::getCmd( 'section', 'com_content', 'post' ); JArrayHelper::toInteger($cid); if (count( $cid ) < 1) { JError::raiseError(500, JText::_( 'Select an item to move', true )); } ## query to list selected categories $cids = implode( ',', $cid ); $query = 'SELECT a.title, a.section' . ' FROM #__categories AS a' . ' WHERE a.id IN ( '.$cids.' )' ; $db->setQuery( $query ); $items = $db->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' ; $db->setQuery( $query ); $contents = $db->loadObjectList(); ## query to choose section to move to $query = 'SELECT a.title AS `text`, a.id AS `value`' . ' FROM #__sections AS a' . ' WHERE a.published = 1' . ' ORDER BY a.name' ; $db->setQuery( $query ); $sections = $db->loadObjectList(); // build the html select list $SectionList = JHTML::_('select.genericlist', $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 $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $sectionMove = JRequest::getInt( 'sectionmove' ); //Check to see of a section was selected to copy the items too if (!$sectionMove) { $msg = JText::_('Please select a section from the list'); copyCategorySelect( 'com_categories', $cid, $sectionOld ); JError::raiseWarning(500, $msg); return; } $contentid = JRequest::getVar( 'item', null, '', 'array' ); JArrayHelper::toInteger($contentid); $category =& JTable::getInstance('category'); foreach( $cid as $id ) { $category->load( $id ); $category->id = NULL; $category->title = JText::sprintf( 'Copy of', $category->title ); $category->name = JText::sprintf( 'Copy of', $category->name ); $category->section = $sectionMove; if (!$category->check()) { JError::raiseError(500, $category->getError()); } if (!$category->store()) { JError::raiseError(500, $category->getError()); } $category->checkin(); // stores original catid $newcatids[]["old"] = $id; // pulls new catid $newcatids[]["new"] = $category->id; } $content =& JTable::getInstance('content'); 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()) { JError::raiseError(500, $content->getError()); } if (!$content->store()) { JError::raiseError(500, $content->getError()); } $content->checkin(); } $sectionNew =& JTable::getInstance('section'); $sectionNew->load( $sectionMove ); $msg = JText::sprintf( 'Categories copied to', count($cid), $sectionNew->title ); $mainframe->redirect( 'index.php?option=com_categories§ion='. $sectionOld, $msg );}/*** changes the access level of a record* @param integer The increment to reorder by*/function accessMenu( $uid, $access, $section ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $row =& JTable::getInstance('category'); $row->load( $uid ); $row->access = $access; if ( !$row->check() ) { return $row->getError(); } if ( !$row->store() ) { return $row->getError(); } $mainframe->redirect( 'index.php?option=com_categories§ion='. $section );}function saveOrder( &$cid, $section ){ global $mainframe; // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $db =& JFactory::getDBO(); $total = count( $cid ); $order = JRequest::getVar( 'order', array(0), 'post', 'array' ); JArrayHelper::toInteger($order, array(0)); $row =& JTable::getInstance('category'); $groupings = array(); // update ordering values for( $i=0; $i < $total; $i++ ) { $row->load( (int) $cid[$i] ); // track sections $groupings[] = $row->section; if ($row->ordering != $order[$i]) { $row->ordering = $order[$i]; if (!$row->store()) { JError::raiseError(500, $db->getErrorMsg()); } } } // execute updateOrder for each parent group $groupings = array_unique( $groupings ); foreach ($groupings as $group){ $row->reorder('section = '.$db->Quote($group)); } $msg = JText::_( 'New ordering saved' ); $mainframe->redirect( 'index.php?option=com_categories§ion='. $section, $msg );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -