<?php
/**
* @version 1.0.0
* @category Anahita Social Engineâ¢
* @copyright Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
* @link http://www.anahitapolis.com
*/
class AnUikitTemplate
{
static protected $_overwrites = array();
/**
* Include a uikit js asset
* @return
* @param $name Object
* @param $options Object
*/
static public function uikitjs($name, $options = array())
{
$path = 'media/plg_socialengine/uikit/'.$name;
self::script($path, $options);
}
/**
* Include a uikit css asset
* @return
* @param $name Object
* @param $options Object
*/
static public function uikitcss($name, $options = array())
{
$path = 'media/plg_socialengine/uikit/'.$name;
self::stylesheet($path, $options);
}
/**
* Include a css file in the document. The css file can be overriden at the template level by pasing the
* $options['overwrite_path'] = 'path/from/template';
* @param $url String
* @param $options Array[optional]
*/
static public function stylesheet($url, $options=array())
{
$url = self::getURL($url, $options);
KFactory::get('lib.joomla.document')->addStylesheet($url);
}
/**
* Include a script file in the document. The css file can be overriden at the template level by pasing the
* $options['overwrite_path'] = 'path/from/template';
* @param $url Object
* @param $options Array[optional]
*/
static public function script($url, $options=array())
{
$default = array('include_if_ajax'=>true);
$options = array_merge($default, $options);
$options = new KObjectArray(array('data'=>$options));
$url = self::getURL($url, $options);
if ( KRequest::type() == 'AJAX' && $options['include_if_ajax']) {
print "<script>".file_get_contents($options['physical_path'])."</script>";
} else {
KFactory::get('lib.joomla.document')->addScript($url);
}
}
/**
* Return a url path. Accept $options['overwrite_path'] if the path exists then return the url of the path
* @return String
* @param $url String
* @param $options Array
*/
static public function getURL($url, $options)
{
static $_overwrites;
$filename = basename($url);
//if it's file then keep the file and add it to the end of the overwrite path
if ( strpos($filename, '.') === false )
$filename = null;
$overwrite = isset($options['overwrite_path']) ? $options['overwrite_path'] : false;
$options['physical_path'] = JPATH_BASE.DS.str_replace('/', DS, $url);
if ($overwrite) {
if (!isset($_overwrites[$url]))
{
$overwriteURL = 'templates/'.KFactory::get('lib.joomla.application')->getTemplate().'/'.$overwrite;
if ( $filename )
$overwriteURL .= '/'.$filename;
//find the file path to the template
$path = JPATH_BASE.DS.str_replace('/',DS,$overwriteURL);
if (file_exists($path)) {
$_overwrites[$url] = $overwriteURL;
$options['physical_path'] = $path;
} else
$_overwrites[$url] = $url;
}
$url = $_overwrites[$url];
}
return JFactory::getURI()->base().$url;
}
//end class
}