Your IP : 216.73.216.68


Current Path : /home/s/u/n/sunflowe/www2/j15/modules/mod_rokweather/elements/
Upload File :
Current File : /home/s/u/n/sunflowe/www2/j15/modules/mod_rokweather/elements/rokweathersources.php

<?php
/**
 * @version        1.7 October 23, 2012
 * @author        RocketTheme http://www.rockettheme.com
 * @copyright     Copyright (C) 2007 - 2012 RocketTheme, LLC
 * @license        http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 *
 */
JHTML::_('behavior.mootools');

defined('_JEXEC') or die ('Restricted access');

class JElementRokWeatherSources extends JElement
{
    static $ROKWEATHER_ROOT;
    static $SOURCE_DIR;

    protected $element_dirs = array();

    public function __construct($parent = null)
    {
        if (!defined('ROKWEATHER')) define('ROKWEATHER', 'ROKWEATHER');

        // Set base dirs
        self::$ROKWEATHER_ROOT = JPATH_ROOT . '/modules/mod_rokweather';
        self::$SOURCE_DIR = self::$ROKWEATHER_ROOT . '/lib/RokWeather/Source';

        //load up the RTCommon
        require_once(self::$ROKWEATHER_ROOT . '/lib/include.php');

        parent::__construct($parent);
    }

    function fetchElement($name, $value, &$node, $control_name)
    {
        $js = "<script type='text/javascript'>
                window.addEvent('domready', function() {
                    var start = '" . $value . "';
                    $$('.source').getParent('td').getParent('tr').setStyle('display','none');
                    $$('.'+start).getParent('td').getParent('tr').removeProperty('style');
                    $('" . $control_name.$name . "').addEvent('change', function(){
                        var sel = this.getValue();
                        $$('.source').getParent('td').getParent('tr').setStyle('display','none');
                        $$('.'+sel).getParent('td').getParent('tr').removeProperty('style');
                    }).fireEvent('change');
                });</script>";

        //Find Sources
        $sources = RokWeather_SourceLoader::getAvailableSources(self::$SOURCE_DIR);
        $options = array();

        foreach ($sources as $source_name => $source) {
            // build the html list for content type
            $options[] = JHTML::_('select.option', $source_name, JText::_(ucwords($source_name)));
        }
        $html = JHTML::_('select.genericlist',  $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'value', 'text', $value, $control_name.$name );

        $buffer = '';
        //Find Sources
        $sources = RokWeather_SourceLoader::getAvailableSources(self::$SOURCE_DIR);
        foreach ($sources as $source_name => $source) {
            if (file_exists($source->paramspath) && is_readable($source->paramspath)) {
                $this->element_dirs[] = dirname($source->paramspath) . "/" . $source->name;
                $language =& JFactory::getLanguage();
                $language->load('com_' . $source->name, JPATH_ADMINISTRATOR);
                $language->load($source->name, dirname($source->paramspath), $language->getTag(), true);
                $buffer .= $this->renderParamFile($source->paramspath, $name, $value, $node, $control_name);
            }
        }
        return $js.$html.$buffer;
    }

    function renderParamFile($file, $name, $value, &$node, $control_name)
    {
        $subparams = new JParameter($this->_parent->_raw, $file);
        foreach ($this->element_dirs as $element_dir) $subparams->addElementPath($element_dir);
        $renders = $subparams->renderToArray();
        $html = array();

        $html[] = '</td></tr>';

        $i = 1;
        foreach ($renders as $param) {
            $html[] = '<tr>';
            if ($param[0]) {
                $html[] = '<td width="40%" class="paramlist_key"><span class="editlinktip">' . $param[0] . '</span></td>';
                $html[] = '<td class="paramlist_value">' . $param[1] . '</td>';
            } else {
                $html[] = '<td class="paramlist_value" colspan="2">' . $param[1] . '</td>';
            }
            $html[] = '</tr>';
        }

        $html[] = '<td class="paramlist_value" colspan="2">';

        return implode("\n", $html);
    }

}