Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/administrator/components/com_frontpage/admin.frontpage.php
f43d1a4680a9
10.6 KiB
text/x-php
menubar 0 to 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | <?php
/**
* @version $Id: admin.frontpage.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Content
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
// Make sure the user is authorized to view this page
$user = & JFactory::getUser();
if (!$user->authorize( 'com_frontpage', 'manage' )) {
$mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
}
// Set the table directory
JTable::addIncludePath(JPATH_COMPONENT.DS.DS.'tables');
// Set the helper directory
JHTML::addIncludePath( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_content'.DS.'helper' );
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
JArrayHelper::toInteger($cid, array(0));
switch ( JRequest::getCmd( 'task' ) )
{
case 'publish':
changeFrontPage( $cid, 1, $option );
break;
case 'unpublish':
changeFrontPage( $cid, 0, $option );
break;
case 'archive':
changeFrontPage( $cid, -1, $option );
break;
case 'remove':
removeFrontPage( $cid, $option );
break;
case 'orderup':
orderFrontPage( $cid[0], -1, $option );
break;
case 'orderdown':
orderFrontPage( $cid[0], 1, $option );
break;
case 'saveorder':
saveOrder( $cid );
break;
case 'accesspublic':
accessMenu( $cid[0], 0 );
break;
case 'accessregistered':
accessMenu( $cid[0], 1 );
break;
case 'accessspecial':
accessMenu( $cid[0], 2 );
break;
default:
viewFrontPage( $option );
break;
}
/**
* Compiles a list of frontpage items
*/
function viewFrontPage( $option )
{
global $mainframe;
$db =& JFactory::getDBO();
$filter_order = $mainframe->getUserStateFromRequest( $option.'.filter_order', 'filter_order', 'fpordering', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'.filter_order_Dir', 'filter_order_Dir', '', 'word' );
$filter_state = $mainframe->getUserStateFromRequest( $option.'.filter_state', 'filter_state', '', 'word' );
$catid = $mainframe->getUserStateFromRequest( $option.'.catid', 'catid', 0, 'int' );
$filter_authorid = $mainframe->getUserStateFromRequest( $option.'.filter_authorid', 'filter_authorid', 0, 'int' );
$filter_sectionid = $mainframe->getUserStateFromRequest( $option.'.filter_sectionid', 'filter_sectionid', -1, 'int' );
$search = $mainframe->getUserStateFromRequest( $option.'.search', 'search', '', 'string' );
$search = JString::strtolower( $search );
$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
JToolBarHelper::title( JText::_( 'Frontpage Manager' ), 'frontpage.png' );
JToolBarHelper::archiveList();
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::custom('remove','delete.png','delete_f2.png','Remove', true);
JToolBarHelper::help( 'screen.frontpage' );
$where = array(
"c.state >= 0"
);
// used by filter
if ( $filter_sectionid >= 0 ) {
$where[] = 'c.sectionid = '.(int) $filter_sectionid;
}
if ( $catid > 0 ) {
$where[] = 'c.catid = '.(int) $catid;
}
if ( $filter_authorid > 0 ) {
$where[] = 'c.created_by = '. (int) $filter_authorid;
}
if ( $filter_state ) {
if ( $filter_state == 'P' ) {
$where[] = 'c.state = 1';
} else if ($filter_state == 'U' ) {
$where[] = 'c.state = 0';
}
}
if ($search) {
$where[] = 'LOWER( c.title ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}
$where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', fpordering';
// get the total number of records
$query = 'SELECT count(*)'
. ' FROM #__content AS c'
. ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
. ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
. ' INNER JOIN #__content_frontpage AS f ON f.content_id = c.id'
. $where
;
$db->setQuery( $query );
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
$query = 'SELECT c.*, g.name AS groupname, cc.title as name, s.title AS sect_name, u.name AS editor, f.ordering AS fpordering, v.name AS author'
. ' FROM #__content AS c'
. ' LEFT JOIN #__categories AS cc ON cc.id = c.catid'
. ' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope="content"'
. ' INNER JOIN #__content_frontpage AS f ON f.content_id = c.id'
. ' INNER JOIN #__groups AS g ON g.id = c.access'
. ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
. ' LEFT JOIN #__users AS v ON v.id = c.created_by'
. $where
. $orderby
;
$db->setQuery( $query, $pageNav->limitstart,$pageNav->limit );
$rows = $db->loadObjectList();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
// get list of categories for dropdown filter
$query = 'SELECT cc.id AS value, cc.title AS text, section'
. ' FROM #__categories AS cc'
. ' INNER JOIN #__sections AS s ON s.id = cc.section '
. ' ORDER BY s.ordering, cc.ordering'
;
$db->setQuery( $query );
$categories[] = JHTML::_('select.option', '-1', '- '. JText::_( 'Select Category' ) .' -' );
$categories = array_merge( $categories, $db->loadObjectList() );
$lists['catid'] = JHTML::_('select.genericlist', $categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $catid );
// get list of sections for dropdown filter
$javascript = 'onchange="document.adminForm.submit();"';
$lists['sectionid'] = JHTML::_('list.section', 'filter_sectionid', $filter_sectionid, $javascript );
// get list of Authors for dropdown filter
$query = 'SELECT c.created_by, u.name'
. ' FROM #__content AS c'
. ' INNER JOIN #__sections AS s ON s.id = c.sectionid'
. ' LEFT JOIN #__users AS u ON u.id = c.created_by'
. ' WHERE c.state <> -1'
. ' AND c.state <> -2'
. ' GROUP BY u.name'
. ' ORDER BY u.name'
;
$db->setQuery( $query );
$authors[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Author' ) .' -', 'created_by', 'name' );
$authors = array_merge( $authors, $db->loadObjectList() );
$lists['authorid'] = JHTML::_('select.genericlist', $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'created_by', 'name', $filter_authorid );
// state filter
$lists['state'] = JHTML::_('grid.state', $filter_state );
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
require_once(JPATH_COMPONENT.DS.'views'.DS.'frontpage.php');
FrontpageView::showList( $rows, $pageNav, $option, $lists );
}
/**
* Changes the state of one or more content pages
* @param array An array of unique category id numbers
* @param integer 0 if unpublishing, 1 if publishing
*/
function changeFrontPage( $cid=null, $state=0, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
JArrayHelper::toInteger($cid);
if (count( $cid ) < 1) {
$action = $state == 1 ? 'publish' : ($state == -1 ? 'archive' : 'unpublish');
JError::raiseError(500, JText::_( 'Select an item to' .$action, true ) );
}
$cids = implode( ',', $cid );
$query = 'UPDATE #__content'
. ' SET state = '.(int) $state
. ' WHERE id IN ( '. $cids .' )'
. ' AND ( checked_out = 0 OR ( checked_out = ' .(int) $user->get('id'). ' ) )'
;
$db->setQuery( $query );
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg() );
}
if (count( $cid ) == 1) {
$row =& JTable::getInstance('content');
$row->checkin( $cid[0] );
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$mainframe->redirect( 'index.php?option='.$option );
}
function removeFrontPage( &$cid, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
if (!is_array( $cid ) || count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'Select an item to delete', true ) );
}
$fp =& JTable::getInstance('frontpage', 'Table');
foreach ($cid as $id) {
if (!$fp->delete( $id )) {
JError::raiseError(500, $fp->getError() );
}
$obj =& JTable::getInstance('content');
$obj->load( $id );
$obj->mask = 0;
if (!$obj->store()) {
JError::raiseError(500, $fp->getError() );
}
}
$fp->reorder();
$cache = & JFactory::getCache('com_content');
$cache->clean();
$mainframe->redirect( 'index.php?option='.$option );
}
/**
* Moves the order of a record
* @param integer The increment to reorder by
*/
function orderFrontPage( $uid, $inc, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$fp =& JTable::getInstance('frontpage','Table');
$fp->load( $uid );
$fp->move( $inc );
$cache = & JFactory::getCache('com_content');
$cache->clean();
$mainframe->redirect( 'index.php?option='.$option );
}
/**
* @param integer The id of the article
* @param integer The new access level
* @param string The URL option
*/
function accessMenu( $uid, $access )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db = & JFactory::getDBO();
$row =& JTable::getInstance('content');
$row->load( $uid );
$row->access = $access;
if ( !$row->check() ) {
return $row->getError();
}
if ( !$row->store() ) {
return $row->getError();
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$mainframe->redirect( 'index.php?option=com_frontpage' );
}
function saveOrder( &$cid )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$total = count( $cid );
$order = JRequest::getVar( 'order', array(0), 'post', 'array' );
for( $i=0; $i < $total; $i++ )
{
$query = 'UPDATE #__content_frontpage'
. ' SET ordering = ' . (int) $order[$i]
. ' WHERE content_id = ' . (int) $cid[$i];
$db->setQuery( $query );
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg() );
}
}
$cache = & JFactory::getCache('com_content');
$cache->clean();
$msg = JText::_( 'New ordering saved' );
$mainframe->redirect( 'index.php?option=com_frontpage', $msg );
}
|