?? controller.php
字號:
<?php
/**
* @version $Id: controller.php 8682 2007-08-31 18:36:45Z jinx $
* @package Joomla
* @subpackage Modules
* @copyright Copyright (C) 2005 - 2007 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' );
jimport( 'joomla.application.component.controller' );
$client = JRequest::getVar('client', 0, '', 'int');
if ($client == 1) {
JSubMenuHelper::addEntry(JText::_('Site'), 'index.php?option=com_modules&client_id=0');
JSubMenuHelper::addEntry(JText::_('Administrator'), 'index.php?option=com_modules&client=1', true );
} else {
JSubMenuHelper::addEntry(JText::_('Site'), 'index.php?option=com_modules&client_id=0', true );
JSubMenuHelper::addEntry(JText::_('Administrator'), 'index.php?option=com_modules&client=1');
}
class ModulesController extends JController
{
/**
* Constructor
*/
function __construct( $config = array() )
{
parent::__construct( $config );
// Register Extra tasks
$this->registerTask( 'apply', 'save' );
$this->registerTask( 'unpublish', 'publish' );
$this->registerTask( 'orderup', 'reorder' );
$this->registerTask( 'orderdown', 'reorder' );
$this->registerTask( 'accesspublic', 'access' );
$this->registerTask( 'accessregistered','access' );
$this->registerTask( 'accessspecial', 'access' );
}
/**
* Compiles a list of installed or defined modules
*/
function view()
{
global $mainframe;
// Initialize some variables
$db =& JFactory::getDBO();
$client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
$option = 'com_modules';
$filter_order = $mainframe->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'm.position', 'cmd' );
$filter_order_Dir = $mainframe->getUserStateFromRequest( $option.'filter_order_Dir', 'filter_order_Dir', '', 'word' );
$filter_state = $mainframe->getUserStateFromRequest( $option.'filter_state', 'filter_state', '', 'word' );
$filter_position = $mainframe->getUserStateFromRequest( $option.'filter_position', 'filter_position', '', 'cmd' );
$filter_type = $mainframe->getUserStateFromRequest( $option.'filter_type', 'filter_type', '', 'cmd' );
$filter_assigned = $mainframe->getUserStateFromRequest( $option.'filter_assigned', 'filter_assigned', '', 'cmd' );
$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[] = 'm.client_id = '.(int) $client->id;
$joins[] = 'LEFT JOIN #__users AS u ON u.id = m.checked_out';
$joins[] = 'LEFT JOIN #__groups AS g ON g.id = m.access';
$joins[] = 'LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id';
// used by filter
if ( $filter_assigned ) {
$joins[] = 'LEFT JOIN #__templates_menu AS t ON t.menuid = mm.menuid';
$where[] = 't.template = '.$db->Quote($filter_assigned);
}
if ( $filter_position ) {
$where[] = 'm.position = '.$db->Quote($filter_position);
}
if ( $filter_type ) {
$where[] = 'm.module = '.$db->Quote($filter_type);
}
if ( $search ) {
$where[] = 'LOWER( m.title ) LIKE '.$db->Quote('%'.$search.'%');
}
if ( $filter_state ) {
if ( $filter_state == 'P' ) {
$where[] = 'm.published = 1';
} else if ($filter_state == 'U' ) {
$where[] = 'm.published = 0';
}
}
$where = ' WHERE ' . implode( ' AND ', $where );
$join = ' ' . implode( ' ', $joins );
$orderby = ' ORDER BY '. $filter_order .' '. $filter_order_Dir .', m.ordering ASC';
// get the total number of records
$query = 'SELECT COUNT(DISTINCT m.id)'
. ' FROM #__modules AS m'
. $join
. $where
;
$db->setQuery( $query );
$total = $db->loadResult();
jimport('joomla.html.pagination');
$pageNav = new JPagination( $total, $limitstart, $limit );
$query = 'SELECT m.*, u.name AS editor, g.name AS groupname, MIN(mm.menuid) AS pages'
. ' FROM #__modules AS m'
. $join
. $where
. ' GROUP BY m.id'
. $orderby
;
$db->setQuery( $query, $pageNav->limitstart, $pageNav->limit );
$rows = $db->loadObjectList();
if ($db->getErrorNum()) {
echo $db->stderr();
return false;
}
// get list of Positions for dropdown filter
$query = 'SELECT m.position AS value, m.position AS text'
. ' FROM #__modules as m'
. ' WHERE m.client_id = '.(int) $client->id
. ' GROUP BY m.position'
. ' ORDER BY m.position'
;
$positions[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Position' ) .' -' );
$db->setQuery( $query );
$positions = array_merge( $positions, $db->loadObjectList() );
$lists['position'] = JHTML::_('select.genericlist', $positions, 'filter_position', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', "$filter_position" );
// get list of Positions for dropdown filter
$query = 'SELECT module AS value, module AS text'
. ' FROM #__modules'
. ' WHERE client_id = '.(int) $client->id
. ' GROUP BY module'
. ' ORDER BY module'
;
$db->setQuery( $query );
$types[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Type' ) .' -' );
$types = array_merge( $types, $db->loadObjectList() );
$lists['type'] = JHTML::_('select.genericlist', $types, 'filter_type', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', "$filter_type" );
// state filter
$lists['state'] = JHTML::_('grid.state', $filter_state );
// template assignment filter
$query = 'SELECT DISTINCT(template) AS text, template AS value'.
' FROM #__templates_menu' .
' WHERE client_id = '.(int) $client->id;
$db->setQuery( $query );
$assigned[] = JHTML::_('select.option', '0', '- '. JText::_( 'Select Template' ) .' -' );
$assigned = array_merge( $assigned, $db->loadObjectList() );
$lists['assigned'] = JHTML::_('select.genericlist', $assigned, 'filter_assigned', 'class="inputbox" size="1" onchange="this.form.submit()"', 'value', 'text', "$filter_assigned" );
// table ordering
$lists['order_Dir'] = $filter_order_Dir;
$lists['order'] = $filter_order;
// search filter
$lists['search']= $search;
require_once( JApplicationHelper::getPath( 'admin_html' ) );
HTML_modules::view( $rows, $client, $pageNav, $lists );
}
/**
* Compiles information to add or edit a module
* @param string The current GET/POST option
* @param integer The unique id of the record to edit
*/
function copy()
{
// Initialize some variables
$db =& JFactory::getDBO();
$client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
$this->setRedirect( 'index.php?option=com_modules&client='.$client->id );
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$n = count( $cid );
if ($n == 0) {
return JError::raiseWarning( 500, JText::_( 'No items selected' ) );
}
$row =& JTable::getInstance('module');
$tuples = array();
foreach ($cid as $id)
{
// load the row from the db table
$row->load( (int) $id );
$row->title = JText::sprintf( 'Copy of', $row->title );
$row->id = 0;
$row->iscore = 0;
$row->published = 0;
if (!$row->check()) {
return JError::raiseWarning( 500, $row->getError() );
}
if (!$row->store()) {
return JError::raiseWarning( 500, $row->getError() );
}
$row->checkin();
$row->reorder( 'position='.$db->Quote( $row->position ).' AND client_id='.(int) $client->id );
$query = 'SELECT menuid'
. ' FROM #__modules_menu'
. ' WHERE moduleid = '.(int) $cid[0]
;
$db->setQuery( $query );
$rows = $db->loadResultArray();
foreach ($rows as $menuid) {
$tuples[] = '('.(int) $row->id.','.(int) $menuid.')';
}
}
if (!empty( $tuples ))
{
// Module-Menu Mapping: Do it in one query
$query = 'INSERT INTO #__modules_menu (moduleid,menuid) VALUES '.implode( ',', $tuples );
$db->setQuery( $query );
if (!$db->query()) {
return JError::raiseWarning( 500, $row->getError() );
}
}
$msg = JText::sprintf( 'Items Copied', $n );
$this->setRedirect( 'index.php?option=com_modules&client='. $client->id, $msg );
}
/**
* Saves the module after an edit form submit
*/
function save()
{
global $mainframe;
$cache = & JFactory::getCache();
$cache->clean( 'com_content' );
// Initialize some variables
$db =& JFactory::getDBO();
$client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
$this->setRedirect( 'index.php?option=com_modules&client='.$client->id );
$post = JRequest::get( 'post' );
// fix up special html fields
$post['content'] = JRequest::getVar( 'content', '', 'post', 'string', JREQUEST_ALLOWRAW );
$post['client_id'] = $client->id;
$row =& JTable::getInstance('module');
if (!$row->bind( $post, 'selections' )) {
return JError::raiseWarning( 500, $row->getError() );
}
if (!$row->check()) {
return JError::raiseWarning( 500, $row->getError() );
}
// if new item, order last in appropriate group
if (!$row->id) {
$where = 'position='.$db->Quote( $row->position ).' AND client_id='.(int) $client->id ;
$row->ordering = $row->getNextOrder( $where );
}
if (!$row->store()) {
return JError::raiseWarning( 500, $row->getError() );
}
$row->checkin();
$menus = JRequest::getVar( 'menus', '', 'post', 'word' );
$selections = JRequest::getVar( 'selections', array(), 'post', 'array' );
JArrayHelper::toInteger($selections);
// delete old module to menu item associations
$query = 'DELETE FROM #__modules_menu'
. ' WHERE moduleid = '.(int) $row->id
;
$db->setQuery( $query );
if (!$db->query()) {
return JError::raiseWarning( 500, $row->getError() );
}
// check needed to stop a module being assigned to `All`
// and other menu items resulting in a module being displayed twice
if ( $menus == 'all' ) {
// assign new module to `all` menu item associations
$query = 'INSERT INTO #__modules_menu'
. ' SET moduleid = '.(int) $row->id.' , menuid = 0'
;
$db->setQuery( $query );
if (!$db->query()) {
return JError::raiseWarning( 500, $row->getError() );
}
}
else
{
foreach ($selections as $menuid)
{
// this check for the blank spaces in the select box that have been added for cosmetic reasons
if ( (int) $menuid >= 0 ) {
// assign new module to menu item associations
$query = 'INSERT INTO #__modules_menu'
. ' SET moduleid = '.(int) $row->id .', menuid = '.(int) $menuid
;
$db->setQuery( $query );
if (!$db->query()) {
return JError::raiseWarning( 500, $row->getError() );
}
}
}
}
$this->setMessage( JText::_( 'Item saved' ) );
switch ($this->getTask())
{
case 'apply':
$this->setRedirect( 'index.php?option=com_modules&client='. $client->id .'&task=edit&id='. $row->id );
break;
}
}
/**
* Compiles information to add or edit a module
* @param string The current GET/POST option
* @param integer The unique id of the record to edit
*/
function edit( )
{
// Initialize some variables
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int'));
$module = JRequest::getVar( 'module', '', '', 'cmd' );
$id = JRequest::getVar( 'id', 0, 'method', 'int' );
$cid = JRequest::getVar( 'cid', array( $id ), 'method', 'array' );
JArrayHelper::toInteger($cid, array(0));
$model = &$this->getModel('module');
$model->setState( 'id', $cid[0] );
$model->setState( 'clientId', $client->id );
$lists = array();
$row =& JTable::getInstance('module');
// load the row from the db table
$row->load( (int) $cid[0] );
// fail if checked out not by 'me'
if ($row->isCheckedOut( $user->get('id') )) {
$this->setRedirect( 'index.php?option=com_modules&client='.$client->id );
return JError::raiseWarning( 500, JText::sprintf( 'DESCBEINGEDITTED', JText::_( 'The module' ), $row->title ) );
}
$row->content = htmlspecialchars( str_replace( '&', '&', $row->content ) );
if ( $cid[0] ) {
$row->checkout( $user->get('id') );
}
// if a new record we must still prime the JTableModel object with a default
// position and the order; also add an extra item to the order list to
// place the 'new' record in last position if desired
if ($cid[0] == 0) {
$row->position = 'left';
$row->showtitle = true;
$row->published = 1;
//$row->ordering = $l;
$row->module = $module;
}
if ($client->id == 1)
{
$where = 'client_id = 1';
$lists['client_id'] = 1;
$path = 'mod1_xml';
}
else
{
$where = 'client_id = 0';
$lists['client_id'] = 0;
$path = 'mod0_xml';
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -