%PDF- %PDF-
| Direktori : /home1/lightco1/www/plugins/system/jsnframework/libraries/joomlashine/modules/helper/ |
| Current File : //home1/lightco1/www/plugins/system/jsnframework/libraries/joomlashine/modules/helper/modules.php |
<?php
/**
* @version $Id: modules.php 18023 2012-11-06 07:57:54Z cuongnm $
* @package JSN_Framework
* @author JoomlaShine Team <support@joomlashine.com>
* @copyright Copyright (C) 2012 JoomlaShine.com. All Rights Reserved.
* @license GNU/GPL v2 or later http://www.gnu.org/licenses/gpl-2.0.html
*
* Websites: http://www.joomlashine.com
* Technical Support: Feedback - http://www.joomlashine.com/contact-us/get-support.html
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
/**
* Helper class for rendering modules.
*
* @package JSN_Framework
* @since 1.0.3
*/
abstract class ModulesHelper
{
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
*/
public static function addSubmenu($vName)
{
// Not used in this component.
}
/**
* Gets a list of the actions that can be performed.
*
* @return JObject
*/
public static function getActions()
{
$user = JFactory::getUser();
$result = new JObject;
$actions = JAccess::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/com_modules/access.xml');
foreach ($actions as $action)
{
$result -> set($action -> name, $user -> authorise($action -> name, 'com_modules'));
}
return $result;
}
/**
* Get a list of filter options for the state of a module.
*
* @return array An array of JHtmlOption elements.
*/
public static function getStateOptions()
{
// Build the filter options.
$options = array ();
$options[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED'));
$options[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED'));
$options[] = JHtml::_('select.option', '-2', JText::_('JTRASHED'));
return $options;
}
/**
* Get a list of filter options for the application clients.
*
* @return array An array of JHtmlOption elements.
*/
public static function getClientOptions()
{
// Build the filter options.
$options = array ();
$options[] = JHtml::_('select.option', '0', JText::_('JSITE'));
$options[] = JHtml::_('select.option', '1', JText::_('JADMINISTRATOR'));
return $options;
}
/**
* Get list of module position.
*
* @param integer $clientId Client ID.
*
* @return array
*/
static function getPositions($clientId)
{
jimport('joomla.filesystem.folder');
try
{
$app = JFactory::getApplication('administrator');
$db = JFactory::getDbo();
$query = $db -> getQuery(true);
$query -> select('DISTINCT(position)');
$query -> from('#__modules');
$query -> where($db -> quoteName('client_id') . ' = ' . (int) $clientId);
$template = $app -> getUserState('com_modules.modules.filter.template', null);
if ($template)
{
$listPosition = ModulesHelper::getPositionsByTemplate();
if (!empty($listPosition))
{
$query -> where('position in (' . $listPosition . ')');
}
}
$query -> order('position');
$db -> setQuery($query);
$positions = $db -> loadColumn();
$positions = (is_array($positions)) ? $positions : array ();
} catch (Exception $e)
{
throw $e;
}
// Build the list
$options = array ();
foreach ($positions as $position)
{
if (!$position)
{
$options[] = JHtml::_('select.option', 'none', ':: ' . JText::_('JNONE') . ' ::');
} else
{
$options[] = JHtml::_('select.option', $position, $position);
}
}
return $options;
}
/**
* Get list of template.
*
* @param integer $clientId Client ID.
* @param integer $state Publishing state.
* @param string $template Template name.
*
* @return array
*/
public static function getTemplates($clientId = 0, $state = '', $template = '')
{
// Get database and query object
$db = JFactory::getDbo();
$query = $db -> getQuery(true);
// Build the query
$query -> select('element, name, enabled');
$query -> from('#__extensions');
$query -> where('client_id = ' . (int) $clientId);
$query -> where('type = ' . $db -> quote('template'));
if ($state != '')
{
$query -> where('enabled = ' . $db -> quote($state));
}
if ($template != '')
{
$query -> where('element = ' . $db -> quote($template));
}
// Set the query and load the templates.
$db -> setQuery($query);
$templates = $db -> loadObjectList('element');
return $templates;
}
/**
* Get a list of the unique modules installed in the client application.
*
* @param integer $clientId Client ID.
*
* @return array
*/
public static function getModules($clientId)
{
$db = JFactory::getDbo();
$query = $db -> getQuery(true);
$query -> select('element AS value, name AS text');
$query -> from('#__extensions as e');
$query -> where('e.client_id = ' . (int) $clientId);
$query -> where('type = ' . $db -> quote('module'));
$query -> leftJoin('#__modules as m ON m.module=e.element AND m.client_id=e.client_id');
$query -> where('m.module IS NOT NULL');
$query -> group('element,name');
$db -> setQuery($query);
$modules = $db -> loadObjectList();
$lang = JFactory::getLanguage();
foreach ($modules as $i => $module)
{
$extension = $module -> value;
$path = $clientId ? JPATH_ADMINISTRATOR : JPATH_SITE;
$source = $path . "/modules/$extension";
$lang -> load("$extension.sys", $path, null, false, false) || $lang -> load("$extension.sys", $source, null, false, false) || $lang -> load("$extension.sys", $path, $lang -> getDefault(), false, false) || $lang -> load("$extension.sys", $source, $lang -> getDefault(), false, false);
$modules[$i] -> text = JText::_($module -> text);
}
JArrayHelper::sortObjects($modules, 'text', 1, true, $lang -> getLocale());
return $modules;
}
/**
* Get a list of the assignment options for modules to menus.
*
* @param integer $clientId Client ID.
*
* @return array
*/
public static function getAssignmentOptions($clientId)
{
$options = array ();
$options[] = JHtml::_('select.option', '0', 'COM_MODULES_OPTION_MENU_ALL');
$options[] = JHtml::_('select.option', '-', 'COM_MODULES_OPTION_MENU_NONE');
if ($clientId == 0)
{
$options[] = JHtml::_('select.option', '1', 'COM_MODULES_OPTION_MENU_INCLUDE');
$options[] = JHtml::_('select.option', '-1', 'COM_MODULES_OPTION_MENU_EXCLUDE');
}
return $options;
}
public static function getPositionsByTemplate()
{
// Initialise variables.
$db = JFactory::getDbo();
$app = JFactory::getApplication('administrator');
$template = $app -> getUserState('com_modules.modules.filter.template', null);
$clientId = $app -> getUserState('com_modules.modules.filter.client_id', null);
$client = JApplicationHelper::getClientInfo($clientId);
$path = JPath::clean($client -> path . '/templates/' . $template . '/templateDetails.xml');
if (file_exists($path))
{
$xml = simplexml_load_file($path);
if (isset($xml -> positions[0] -> position))
{
$positions = array ();
foreach ($xml -> positions[0] -> position as $item)
{
$positions[] = $db -> Quote($item);
}
$listPosition = implode(",", $positions);
return $listPosition;
}
}
}
}