| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: controller.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @subpackage Config 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 jimport( 'joomla.application.component.controller' ); 19 20 /** 21 * Plugins Component Controller 22 * 23 * @package Joomla 24 * @subpackage Plugins 25 * @since 1.5 26 */ 27 class PluginsController extends JController 28 { 29 /** 30 * Custom Constructor 31 */ 32 function __construct( $default = array()) 33 { 34 parent::__construct( $default ); 35 36 $this->registerTask( 'apply', 'save'); 37 $this->registerTask( 'unpublish', 'publish'); 38 $this->registerTask( 'edit' , 'display' ); 39 $this->registerTask( 'add' , 'display' ); 40 $this->registerTask( 'orderup' , 'order' ); 41 $this->registerTask( 'orderdown' , 'order' ); 42 43 $this->registerTask( 'accesspublic' , 'access' ); 44 $this->registerTask( 'accessregistered' , 'access' ); 45 $this->registerTask( 'accessspecial' , 'access' ); 46 47 } 48 49 function display( ) 50 { 51 switch($this->getTask()) 52 { 53 case 'add' : 54 case 'edit' : 55 { 56 JRequest::setVar( 'hidemainmenu', 1 ); 57 JRequest::setVar( 'layout', 'form' ); 58 JRequest::setVar( 'view', 'plugin' ); 59 } break; 60 } 61 62 parent::display(); 63 } 64 65 function save() 66 { 67 // Check for request forgeries 68 JRequest::checkToken() or jexit( 'Invalid Token' ); 69 70 $db =& JFactory::getDBO(); 71 $row =& JTable::getInstance('plugin'); 72 $task = $this->getTask(); 73 74 $client = JRequest::getWord( 'filter_client', 'site' ); 75 76 if (!$row->bind(JRequest::get('post'))) { 77 JError::raiseError(500, $row->getError() ); 78 } 79 if (!$row->check()) { 80 JError::raiseError(500, $row->getError() ); 81 } 82 if (!$row->store()) { 83 JError::raiseError(500, $row->getError() ); 84 } 85 $row->checkin(); 86 87 if ($client == 'admin') { 88 $where = "client_id=1"; 89 } else { 90 $where = "client_id=0"; 91 } 92 93 $row->reorder( 'folder = '.$db->Quote($row->folder).' AND ordering > -10000 AND ordering < 10000 AND ( '.$where.' )' ); 94 95 switch ( $task ) 96 { 97 case 'apply': 98 $msg = JText::sprintf( 'Successfully Saved changes to Plugin', $row->name ); 99 $this->setRedirect( 'index.php?option=com_plugins&view=plugin&client='. $client .'&task=edit&cid[]='. $row->id, $msg ); 100 break; 101 102 case 'save': 103 default: 104 $msg = JText::sprintf( 'Successfully Saved Plugin', $row->name ); 105 $this->setRedirect( 'index.php?option=com_plugins&client='. $client, $msg ); 106 break; 107 } 108 } 109 110 function publish( ) 111 { 112 // Check for request forgeries 113 JRequest::checkToken() or jexit( 'Invalid Token' ); 114 115 $db =& JFactory::getDBO(); 116 $user =& JFactory::getUser(); 117 $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); 118 JArrayHelper::toInteger($cid, array(0)); 119 $publish = ( $this->getTask() == 'publish' ? 1 : 0 ); 120 $client = JRequest::getWord( 'filter_client', 'site' ); 121 122 if (count( $cid ) < 1) { 123 $action = $publish ? JText::_( 'publish' ) : JText::_( 'unpublish' ); 124 JError::raiseError(500, JText::_( 'Select a plugin to '.$action ) ); 125 } 126 127 $cids = implode( ',', $cid ); 128 129 $query = 'UPDATE #__plugins SET published = '.(int) $publish 130 . ' WHERE id IN ( '.$cids.' )' 131 . ' AND ( checked_out = 0 OR ( checked_out = '.(int) $user->get('id').' ))' 132 ; 133 $db->setQuery( $query ); 134 if (!$db->query()) { 135 JError::raiseError(500, $db->getErrorMsg() ); 136 } 137 138 if (count( $cid ) == 1) { 139 $row =& JTable::getInstance('plugin'); 140 $row->checkin( $cid[0] ); 141 } 142 143 $this->setRedirect( 'index.php?option=com_plugins&client='. $client ); 144 } 145 146 function cancel( ) 147 { 148 // Check for request forgeries 149 JRequest::checkToken() or jexit( 'Invalid Token' ); 150 151 $client = JRequest::getWord( 'filter_client', 'site' ); 152 153 $db =& JFactory::getDBO(); 154 $row =& JTable::getInstance('plugin'); 155 $row->bind(JRequest::get('post')); 156 $row->checkin(); 157 158 $this->setRedirect( JRoute::_( 'index.php?option=com_plugins&client='. $client, false ) ); 159 } 160 161 function order( ) 162 { 163 // Check for request forgeries 164 JRequest::checkToken() or jexit( 'Invalid Token' ); 165 166 $db =& JFactory::getDBO(); 167 168 $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); 169 JArrayHelper::toInteger($cid, array(0)); 170 171 $uid = $cid[0]; 172 $inc = ( $this->getTask() == 'orderup' ? -1 : 1 ); 173 $client = JRequest::getWord( 'filter_client', 'site' ); 174 175 176 // Currently Unsupported 177 if ($client == 'admin') { 178 $where = "client_id = 1"; 179 } else { 180 $where = "client_id = 0"; 181 } 182 $row =& JTable::getInstance('plugin'); 183 $row->load( $uid ); 184 $row->move( $inc, 'folder='.$db->Quote($row->folder).' AND ordering > -10000 AND ordering < 10000 AND ('.$where.')' ); 185 186 $this->setRedirect( 'index.php?option=com_plugins' ); 187 } 188 189 function access( ) 190 { 191 // Check for request forgeries 192 JRequest::checkToken() or jexit( 'Invalid Token' ); 193 194 $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); 195 JArrayHelper::toInteger($cid, array(0)); 196 197 $uid = $cid[0]; 198 $access = $this->getTask(); 199 200 $db =& JFactory::getDBO(); 201 switch ( $access ) 202 { 203 case 'accesspublic': 204 $access = 0; 205 break; 206 207 case 'accessregistered': 208 $access = 1; 209 break; 210 211 case 'accessspecial': 212 $access = 2; 213 break; 214 } 215 216 $row =& JTable::getInstance('plugin'); 217 $row->load( $uid ); 218 $row->access = $access; 219 220 if ( !$row->check() ) { 221 return $row->getError(); 222 } 223 if ( !$row->store() ) { 224 return $row->getError(); 225 } 226 227 $this->setRedirect( 'index.php?option=com_plugins' ); 228 } 229 230 function saveorder( ) 231 { 232 // Check for request forgeries 233 JRequest::checkToken() or jexit( 'Invalid Token' ); 234 235 $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); 236 JArrayHelper::toInteger($cid, array(0)); 237 238 $db =& JFactory::getDBO(); 239 $total = count( $cid ); 240 $order = JRequest::getVar( 'order', array(0), 'post', 'array' ); 241 JArrayHelper::toInteger($order, array(0)); 242 243 $cid = JRequest::getVar( 'cid', array(0), 'post', 'array' ); 244 JArrayHelper::toInteger($cid, array(0)); 245 246 $row =& JTable::getInstance('plugin'); 247 $conditions = array(); 248 249 // update ordering values 250 for ( $i=0; $i < $total; $i++ ) 251 { 252 $row->load( (int) $cid[$i] ); 253 if ($row->ordering != $order[$i]) 254 { 255 $row->ordering = $order[$i]; 256 if (!$row->store()) { 257 JError::raiseError(500, $db->getErrorMsg() ); 258 } 259 // remember to updateOrder this group 260 $condition = 'folder = '.$db->Quote($row->folder).' AND ordering > -10000 AND ordering < 10000 AND client_id = ' . (int) $row->client_id; 261 $found = false; 262 foreach ( $conditions as $cond ) 263 { 264 if ($cond[1]==$condition) { 265 $found = true; 266 break; 267 } 268 } 269 if (!$found) $conditions[] = array($row->id, $condition); 270 } 271 } 272 273 // execute updateOrder for each group 274 foreach ( $conditions as $cond ) { 275 $row->load( $cond[0] ); 276 $row->reorder( $cond[1] ); 277 } 278 279 $msg = JText::_( 'New ordering saved' ); 280 $this->setRedirect( 'index.php?option=com_plugins', $msg ); 281 } 282 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |