<?php
/**
* @version $Id: coolfeed.php 100 2012-04-14 17:42:51Z hide@address.com $
* @copyright JoomAvatar.com
* @author Nguyen Quang Trung
* @link http://joomavatar.com
* @license License GNU General Public License version 2 or later http://www.gnu.org/licenses/gpl-2.0.html
* @package Avatar Dream Framework Template
* @facebook http://www.facebook.com/pages/JoomAvatar/120705031368683
* @twitter https://twitter.com/#!/JoomAvatar
* @support http://joomavatar.com/forum/
*/
// no direct access
defined('_JEXEC') or die;
class PlgAvatarModules {
public static function getPositions()
{
$db = JFactory::getDbo();
$positions = array();
$query = $db->getQuery(true);
// Build the query.
$query->select('element, name, enabled');
$query->from('#__extensions');
$query->where('client_id = 0');
$query->where('type = '.$db->quote('template'));
// Set the query and load the templates.
$db->setQuery($query);
$templates = $db->loadObjectList('element');
$client = JApplicationHelper::getClientInfo(0);
foreach ($templates as $template)
{
$path = JPath::clean($client->path.'/templates/'.$template->element.'/templateDetails.xml');
if (file_exists($path))
{
$xml = simplexml_load_file($path);
if (isset($xml->positions[0]))
{
foreach ($xml->positions[0] as $position)
{
$value = (string)$position['value'];
$label = (string)$position;
if (!$value) $value = $label;
if (!isset($positions[$value])) {
$positions[$value] = array();
}
$positions[$value][] = $template->name;
}
}
}
}
return $positions;
}
public static function getPositionHTML($type, $options = array())
{
$function = '_getPositionHTML'.$type;
return self::$function($options);
}
public static function _getPositionHTMLSelectbox($options = array())
{
$positions = self::getPositions();
$html = '<select '. @$options['js'] .' '.@$options['class'].' name="'.$options['name'].'">';
$html .= '<option value="">' . JText::_('AVATAR_TOOL_POSITION_SELECT') . '</option>';
foreach ($positions as $position => $templates) {
$html .= '<option value="'.$position.'">' . $position . '</option>';
}
$html .= '<select>';
return $html;
}
public static function getModuleHTML($type, $options = array())
{
$function = '_getModuleHTML'.$type;
return self::$function($options);
}
public static function _getModuleHTMLSelectbox($options = array())
{
$modules = self::getModules();
$html = '<select '. @$options['js'] .' '.@$options['class'].' name="'.$options['name'].'">';
$html .= '<option value="">' . JText::_('AVATAR_TOOL_MODULES_SELECT') . '</option>';
foreach ($modules as $module) {
$html .= '<option value="'.$module->value.'">' . $module->text . '</option>';
}
$html .= '<select>';
return $html;
}
public static function getModules()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('DISTINCT(m.module) AS value, e.name AS text')
->from('#__modules AS m')
->join('LEFT', '#__extensions AS e ON e.element=m.module')
->where('m.`client_id` = 0')
->order('e.name');
$db->setQuery($query);
return $modules = $db->loadObjectList();
}
}