Files
@ a45f0dabc59c
Branch filter:
Location: hot67beta/administrator/components/com_trash/admin.trash.php
a45f0dabc59c
10.8 KiB
text/x-php
mneh
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 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | <?php
/**
* @version $Id: admin.trash.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Trash
* @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_trash', 'manage' )) {
$mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
}
require_once( JApplicationHelper::getPath( 'admin_html' ) );
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$mid = JRequest::getVar( 'mid', array(0), 'post', 'array' );
JArrayHelper::toInteger($cid, array(0));
JArrayHelper::toInteger($mid, array(0));
switch ($task)
{
case 'deleteconfirm':
viewdeleteTrash( $cid, $mid, $option );
break;
case 'delete':
deleteTrash( $cid, $option );
break;
case 'restoreconfirm':
viewrestoreTrash( $cid, $mid, $option );
break;
case 'restore':
restoreTrash( $cid, $option );
break;
case 'viewMenu':
viewTrashMenu( $option );
break;
case 'viewContent':
viewTrashContent( $option );
break;
default:
$return = JRequest::getCmd( 'return', 'viewContent', 'post' );
if ( $return == 'viewMenu' ) {
viewTrashMenu( $option );
} else {
viewTrashContent( $option );
}
break;
}
/**
* Compiles a list of trash items
*/
function viewTrashContent( $option )
{
global $mainframe;
$db =& JFactory::getDBO();
$filter_order = $mainframe->getUserStateFromRequest( "$option.viewContent.filter_order", 'filter_order', 'sectname', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.viewContent.filter_order_Dir", 'filter_order_Dir', '', 'word' );
$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' );
$where[] = 'c.state = -2';
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 .', s.name, cc.name, c.title';
// get the total number of content
$query = 'SELECT count(c.id)'
. ' 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"'
. ' LEFT JOIN #__groups AS g ON g.id = c.access'
. ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
. $where
;
$db->setQuery( $query );
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
// Query articles
$query = 'SELECT c.title, c.id, c.sectionid, c.catid, g.name AS groupname, cc.title AS catname, s.title AS sectname'
. ' 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"'
. ' LEFT JOIN #__groups AS g ON g.id = c.access'
. ' LEFT JOIN #__users AS u ON u.id = c.checked_out'
. $where
. $orderby
;
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$contents = $db->loadObjectList();
for ( $i = 0; $i < count($contents); $i++ ) {
if ( ( $contents[$i]->sectionid == 0 ) && ( $contents[$i]->catid == 0 ) ) {
$contents[$i]->sectname = JText::_('UNCATEGORIZED');
}
}
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
HTML_trash::showListContent( $option, $contents, $pageNav, $lists );
}
/**
* Compiles a list of trash items
*/
function viewTrashMenu( $option )
{
global $mainframe;
$db =& JFactory::getDBO();
$filter_order = $mainframe->getUserStateFromRequest( "$option.viewMenu.filter_order", 'filter_order', 'm.menutype', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( "$option.viewMenu.filter_order_Dir", 'filter_order_Dir', '', 'word' );
$limit = $mainframe->getUserStateFromRequest( "limit", 'limit', $mainframe->getCfg('list_limit'), 'int' );
$limitstart = $mainframe->getUserStateFromRequest( "$option.viewMenu.limitstart", 'limitstart', 0, 'int' );
$search = $mainframe->getUserStateFromRequest( "$option.search", 'search', '', 'string' );
$search = JString::strtolower( $search );
$where[] = 'm.published = -2';
if ($search) {
$where[] = 'LOWER(m.name) LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}
$where = ( count( $where ) ? ' WHERE ' . implode( ' AND ', $where ) : '' );
$orderby = ' ORDER BY '. $filter_order . ' ' . $filter_order_Dir .', m.menutype, m.ordering, m.ordering, m.name';
$query = 'SELECT count(*)'
. ' FROM #__menu AS m'
. ' LEFT JOIN #__users AS u ON u.id = m.checked_out'
. $where
;
$db->setQuery( $query );
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
// Query menu items
$query = 'SELECT m.name, m.id, m.menutype, m.type, com.name AS com_name'
. ' FROM #__menu AS m'
. ' LEFT JOIN #__users AS u ON u.id = m.checked_out'
. ' LEFT JOIN #__components AS com ON com.id = m.componentid AND m.type = "components"'
. $where
. $orderby
;
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$menus = $db->loadObjectList();
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
HTML_trash::showListMenu( $option, $menus, $pageNav, $lists );
}
/**
* Compiles a list of the items you have selected to permanently delte
*/
function viewdeleteTrash( $cid, $mid, $option )
{
global $mainframe;
$db =& JFactory::getDBO();
$return = JRequest::getCmd( 'return', 'viewContent', 'post' );
JArrayHelper::toInteger($cid, array(0));
JArrayHelper::toInteger($mid, array(0));
// seperate contentids
$cids = implode( ',', $cid );
$mids = implode( ',', $mid );
if ( $cids ) {
// Articles query
$query = 'SELECT a.title AS name'
. ' FROM #__content AS a'
. ' WHERE ( a.id IN ( '.$cids.' ) )'
. ' ORDER BY a.title'
;
$db->setQuery( $query );
$items = $db->loadObjectList();
$id = $cid;
$type = "content";
} else if ( $mids ) {
// Articles query
$query = 'SELECT a.name'
. ' FROM #__menu AS a'
. ' WHERE ( a.id IN ( '.$mids.' ) )'
. ' ORDER BY a.name'
;
$db->setQuery( $query );
$items = $db->loadObjectList();
$id = $mid;
$type = "menu";
}
HTML_trash::showDelete( $option, $id, $items, $type, $return );
}
/**
* Permanently deletes the selected list of trash items
*/
function deleteTrash( $cid, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db =& JFactory::getDBO();
$return = JRequest::getCmd( 'return', 'viewContent', 'post' );
$type = JRequest::getCmd( 'type', '', 'post' );
$total = count( $cid );
if ( $type == 'content' )
{
$obj =& JTable::getInstance('content');
require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_frontpage'.DS.'tables'.DS.'frontpage.php');
$fp = new TableFrontPage( $db );
foreach ( $cid as $id ) {
$id = intval( $id );
$obj->delete( $id );
$fp->delete( $id );
}
} else if ( $type == "menu" ) {
$obj =& JTable::getInstance('menu');
foreach ( $cid as $id ) {
$id = intval( $id );
$obj->delete( $id );
}
}
$msg = JText::sprintf( 'Item(s) successfully Deleted', $total );
$mainframe->redirect( 'index.php?option='.$option.'&task='.$return, $msg );
}
/**
* Compiles a list of the items you have selected to permanently delte
*/
function viewrestoreTrash( $cid, $mid, $option ) {
global $mainframe;
$db =& JFactory::getDBO();
$return = JRequest::getCmd( 'return', 'viewContent', 'post' );
JArrayHelper::toInteger($cid, array(0));
JArrayHelper::toInteger($mid, array(0));
// seperate contentids
$cids = implode( ',', $cid );
$mids = implode( ',', $mid );
if ( $cids ) {
// Articles query
$query = 'SELECT a.title AS name'
. ' FROM #__content AS a'
. ' WHERE ( a.id IN ( '.$cids.' ) )'
. ' ORDER BY a.title'
;
$db->setQuery( $query );
$items = $db->loadObjectList();
$id = $cid;
$type = "content";
} else if ( $mids ) {
// Articles query
$query = 'SELECT a.name'
. ' FROM #__menu AS a'
. ' WHERE ( a.id IN ( '.$mids.' ) )'
. ' ORDER BY a.name'
;
$db->setQuery( $query );
$items = $db->loadObjectList();
$id = $mid;
$type = "menu";
}
HTML_trash::showRestore( $option, $id, $items, $type, $return );
}
/**
* Restores items selected to normal - restores to an unpublished state
*/
function restoreTrash( $cid, $option )
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$db = & JFactory::getDBO();
$type = JRequest::getCmd( 'type', '', 'post' );
$total = count( $cid );
// restores to an unpublished state
$state = 0;
$ordering = 9999;
if ( $type == 'content' ) {
$return = 'viewContent';
//seperate contentids
JArrayHelper::toInteger($cid, array(0));
$cids = implode( ',', $cid );
// query to restore article
$query = 'UPDATE #__content'
. ' SET state = '.(int) $state.', ordering = '.(int) $ordering
. ' WHERE id IN ( '.$cids.' )'
;
$db->setQuery( $query );
if ( !$db->query() ) {
JError::raiseError(500, $db->getErrorMsg() );
}
} else if ( $type == 'menu' ) {
$return = 'viewMenu';
jimport('joomla.application.component.model');
JModel::addIncludePath(JPATH_BASE.DS.'components'.DS.'com_menus'.DS.'models');
$model =& JModel::getInstance('List', 'MenusModel');
$total = $model->fromTrash($cid);
if (!$total) {
JError::raiseError(500, $db->getErrorMsg() );
}
}
$msg = JText::sprintf( 'Item(s) successfully Restored', $total );
$mainframe->redirect( 'index.php?option='.$option.'&task='.$return, $msg );
}
function ReadMenuXML( $type, $component=-1 )
{
// xml file for module
$xmlfile = JPATH_ADMINISTRATOR .'/components/com_menus/'. $type .'/'. $type .'.xml';
$data = JApplicationHelper::parseXMLInstallFile($xmlfile);
if ( $data['type'] == 'component' || $data['type'] == 'menu' )
{
if ( ( $component <> -1 ) && ( $data['name'] == 'Component') ) {
$data['name'] .= ' - '. $component;
}
$row[0] = $data['name'];
}
return $row;
}
|