<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Rapyd Components
 *
 * An open source library for CodeIgniter application development framework for PHP 4.3.2 or newer
 *
 * @package		rapyd.components
 * @author		Felice Ostuni
 * @license		http://www.fsf.org/licensing/licenses/lgpl.txt LGPL
 * @version		0.9.5
 * @filesource
 */
 
// ------------------------------------------------------------------------


$obj =& get_instance();
 
if (!defined('RAPYD_PATH')){

  if(!defined('BASEURL')) define('BASEURL', $obj->config->slash_item('base_url'));

  include(APPPATH.'config/rapyd'.EXT);
  define('APPPDIR',  BASEURL.RAPYD_APPPATH);
  define('RAPYD_DIR',  APPPDIR.'rapyd/');
  $img = ($rpd['images_path']!='') ? $rpd['images_path'] : RAPYD_DIR.'images/';
  $lib = ($rpd['libraries_path']!='') ? $rpd['libraries_path'] : RAPYD_DIR.'libraries/';
  //$img = "https://localhost/cloudnet360/application/rapyd/images/";
  define('RAPYD_IMAGES', $img);
  define('RAPYD_LIBRARIES', $lib);
  define('RAPYD_PATH', APPPATH.'rapyd/');  
}

unset($rpd);
unset($obj);


/**
 * helpers inclusion
 */
require_once(RAPYD_PATH.'helpers/datehelper'.EXT);
require_once(RAPYD_PATH.'helpers/html'.EXT);
require_once(RAPYD_PATH.'helpers/highlight'.EXT);
require_once(RAPYD_PATH.'classes/rapyd_uri'.EXT);
require_once(RAPYD_PATH.'classes/rapyd_session'.EXT);
require_once(RAPYD_PATH.'classes/rapyd_lang'.EXT);
require_once(RAPYD_PATH.'helpers/lang'.EXT);
require_once(RAPYD_PATH.'classes/rapyd_auth'.EXT);
require_once(RAPYD_PATH.'helpers/auth'.EXT);

/**
 * common inclusion
 */
require_once(RAPYD_PATH.'common'.EXT);



/**
 * rapyd library main class
 *
 * @package    rapyd.components
 * @access     public
 */
	class Rapyd {
	
		var $config = array();
		var $load;
		
    var $js = array();
    var $css = array();
    var $script = array();
    var $style = array();
		
		function Rapyd()
		{
			$this->ci =& get_instance();
      
      $rpd = array();
      if (file_exists(APPPATH.'config/rapyd'.EXT))
      {
        include(APPPATH.'config/rapyd'.EXT);
      }
      
      foreach ($rpd['uri_keywords'] as $key=>$value){
        if (!defined('RAPYD_URI_'.strtoupper($key))){
          define('RAPYD_URI_'.strtoupper($key), $value);
        }
      }
      
      $this->config = new rapyd_config($rpd);
      $this->session = new rapyd_session();
      $this->uri = new rapyd_uri($this);
      $this->language = new rapyd_lang($this);
      $this->auth = new rapyd_auth($this);
		}
    
		function load()
		{
			$components = func_get_args();
			foreach($components as $component)
			{
			    $this->language->load_language();
				require_once(RAPYD_PATH.'classes/'.$component.EXT);
			}
		}

		function set_view_path()
		{
            $this->ci->load->add_package_path(RAPYD_PATH, true);
		}
		
		function reset_view_path()
		{
			$this->ci->load->_ci_view_path = APPPATH.'views/';
		}


		function get_head(){
			
			$buffer = '';
			
			//css links
			foreach ($this->css as $css){
				$buffer .= HTML::cssLinkTag($css);
			}
			
			//javascript links
			foreach ($this->js as $js){
				$buffer .= HTML::javascriptLinkTag($js);
			}

			//javascript in page
			$script = join("\n\n",$this->script)."\n";
			$buffer .= HTML::javascriptTag($script);

			//style in page
			$this->set_view_path();
			$this->style[] = $this->ci->load->view('css',null,true);
			$this->reset_view_path();
			$style = join("\n\n",$this->style)."\n";
			$buffer .= HTML::cssTag($style); 

			return $buffer;
		}

	}

/**
 * rapyd config class
 *
 * @package    rapyd.components
 * @access     private
 */
	class rapyd_config{
	
		var $config = array();
		
		function rapyd_config(&$config)
		{
			$this->config = &$config;
      
		}

		function item($item)
		{

			return $this->config[$item];
		}

		function set_item($item, $value)
		{
			$this->config[$item] = $value;
		}
		
	}




?>