<?php
/**
* Styles enqueue class.
*
* @since 3.1.1
*/
class Styles {
var $styles = array();
private static $instance;
public static function newInstance()
{
if(!self::$instance instanceof self) {
self::$instance = new self;
}
return self::$instance;
}
public function __construct()
{
$styles = array();
}
/**
* Add style to be loaded
*
* @param type $id
* @param type $url
* @param bool $force
*/
public function addStyle($id, $url, $force = false)
{
$this->styles[$id] = array(
'url' => $url,
'force' => (int)$force
);
}
/**
* Remove style to not be loaded
*
* @param type $id
*/
public function removeStyle($id)
{
unset($this->styles[$id]);
}
/**
* Get the css styles urls
*/
public function getStyles()
{
return $this->styles;
}
/**
* Print the HTML tag to load the necessary style
*/
public function printStyle($id)
{
echo '<link href="' . osc_apply_filter('style_url', $this->styles[$id]['url']) . '" rel="stylesheet" type="text/css" />' . PHP_EOL;
}
/**
* Print the HTML tags to load the styles
*/
public function printStyles()
{
foreach($this->styles as $css) {
if(OC_ADMIN) {
echo '<link href="' . osc_apply_filter('style_url', $css['url']) . '" rel="stylesheet" type="text/css" />' . PHP_EOL;
} else {
if($css['force']) {
echo '<link media="all" href="' . osc_apply_filter('style_url', $css['url']) . '" rel="stylesheet" type="text/css" />' . PHP_EOL;
} else {
echo '<link media="none" onload="this.media=\'all\'" href="' . osc_apply_filter('style_url', $css['url']) . '" rel="stylesheet" type="text/css" />' . PHP_EOL;
}
}
}
}
}