Your IP : 216.73.216.201


Current Path : /home/sunflowe/www/modules/mod_rokweather/lib/RokWeather/
Upload File :
Current File : /home/sunflowe/www/modules/mod_rokweather/lib/RokWeather/SourceLoader.php

<?php
/**
 * @version   $Id: SourceLoader.php 6565 2013-01-16 17:20:38Z btowles $
 * @author    RocketTheme http://www.rockettheme.com
 * @copyright Copyright (C) 2007 - 2015 RocketTheme, LLC
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */

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

class RokWeather_SourceLoader implements RTCommon_Loader
{

    const CLASS_NAME_PREFIX = 'RokWeatherSource';

    public function __construct()
    {
        $this->addSourcePath(dirname(__FILE__) . '/Source');
    }

    /**
     * @var array
     */
    private $_orderedPaths = array();
    private $_allPaths = array();

    public function addSourcePath($path, $priority = 10)
    {
        if (in_array($path, $this->_allPaths))
            return;
        if (!file_exists($path) || !is_dir($path))
        {
            throw new RokWeather_Exception($path . ' is not a valid directory.');
        }
        $this->_orderedPaths[$priority][$path] = $path;
        $this->_allPaths[] = $path;
    }

    /**
     * @param  string $className the class name to look for and load
     * @return bool True if the class was found and loaded.
     */
    public function loadClass($className)
    {
        $fileName = strtolower(str_replace(self::CLASS_NAME_PREFIX, '', $className) . self::FILE_EXTENSION);
        foreach ($this->_orderedPaths as $priority => $priorityPaths)
        {
            foreach ($priorityPaths as $path)
            {
                $full_file_path = $path . DIRECTORY_SEPARATOR . $fileName;
                if (file_exists($full_file_path) && is_readable($full_file_path))
                {
                    require($full_file_path);
                    return true;
                }

            }
        }
        return false;
    }

    public static function getAvailableSources($sourcedir)
    {
        jimport('joomla.filesystem.folder');
        jimport('joomla.filesystem.file');
        $paths = self::getFrontsideTemplates();
        $paths[] = $sourcedir;

        foreach ($paths as $path)
        {
            RokWeather::addSourcesPath($path);
        }

        $results = array();
        foreach ($paths as $source_path)
        {
            if (JFolder::exists($source_path))
            {
                $source_files = JFolder::files($source_path);
                foreach ($source_files as $entry)
                {
                    $source_name = basename($entry, ".php");
                    $path = $source_path . '/' . $source_name . '.php';
                    if (JFile::exists($path) && !array_key_exists($source_name, $results))
                    {
                        $sourceClass = self::CLASS_NAME_PREFIX . ucfirst($source_name);
                        $source = new $sourceClass();
                        if ($source->available())
                        {
                            $source_info = new stdClass();
                            $source_info->name = $source_name;
                            $source_info->source = $source;
                            $source_info->paramspath = $source_path . '/' . $source_name . '.xml';
                            $results[$source_name] = $source_info;
                        }

                    }

                }
            }
        }

        return $results;
    }

    private static function getFrontsideTemplates()
    {
        jimport('joomla.filesystem.folder');
        $templateDirs = JFolder::folders(JPATH_ROOT . '/templates');
        $rows = array();
        foreach ($templateDirs as $templateDir)
        {
            $posible_sourcedir = $templateDir . "/html/mod_rokweather/sources";
            if (file_exists($posible_sourcedir) && is_dir($posible_sourcedir))
            {
                $rows[] = $posible_sourcedir;
            }
        }
        return $rows;
    }
}