<?php
/**
* @copyright Copyright (C) 2016 Cédric KEIFLIN alias ced1870
* http://www.template-creator.com
* http://www.joomlack.fr
* @license GNU/GPL
* */
defined('_JEXEC') or die;
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
class modSliderckHelper {
/**
* Test if there is already a unit, else add the px
*
* @param string $value
* @return string
*/
static function testUnit($value) {
if ((stristr($value, 'px')) OR (stristr($value, 'em')) OR (stristr($value, '%')) OR (stristr($value, 'auto')) ) {
return $value;
}
if ($value == '') {
$value = 0;
}
return $value . 'px';
}
/**
* Convert a hexa decimal color code to its RGB equivalent
*
* @param string $hexStr (hexadecimal color value)
* @param boolean $returnAsString (if set true, returns the value separated by the separator character. Otherwise returns associative array)
* @param string $seperator (to separate RGB values. Applicable only if second parameter is true.)
* @return array or string (depending on second parameter. Returns False if invalid hex color value)
*/
static function hex2RGB($hexStr, $opacity) {
if ($opacity > 1) $opacity = $opacity/100;
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
$rgbArray = array();
if (strlen($hexStr) == 6) { //If a proper hex code, convert using bitwise operation. No overhead... faster
$colorVal = hexdec($hexStr);
$rgbArray['red'] = 0xFF & ($colorVal >> 0x10);
$rgbArray['green'] = 0xFF & ($colorVal >> 0x8);
$rgbArray['blue'] = 0xFF & $colorVal;
} elseif (strlen($hexStr) == 3) { //if shorthand notation, need some string manipulations
$rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
$rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
$rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
} else {
return false; //Invalid hex color code
}
$rgbacolor = "rgba(" . $rgbArray['red'] . "," . $rgbArray['green'] . "," . $rgbArray['blue'] . "," . $opacity . ")";
return $rgbacolor;
}
/**
* Get the CSS of sliderck style
*/
public static function getStyleLayoutcss($id) {
if (! $id) return '';
// Create a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select('a.layoutcss');
$query->from($db->quoteName('#__sliderck_styles') . ' AS a');
$query->where('(a.state IN (0, 1))');
$query->where('a.id = ' . (int)$id);
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results = $db->loadResult();
return $results;
}
/*
* Make empty slide object
*/
public static function initItem() {
$item = new stdClass();
$item->path = null;
$item->link = null;
$item->title = null;
$item->desc = null;
$item->more = array();
// $item->button = null;
return $item;
}
/**
* Get a subtring with the max word setting
*
* @param string $text;
* @param int $length limit characters showing;
* @param string $replacer;
* @return tring;
*/
public static function substrword($text, $length = 100, $replacer = '...', $isStrips = true, $stringtags = '') {
if($isStrips){
$text = preg_replace('/\<p.*\>/Us','',$text);
$text = str_replace('</p>','<br/>',$text);
$text = strip_tags($text, $stringtags);
}
$tmp = explode(" ", $text);
if (count($tmp) < $length)
return $text;
$text = implode(" ", array_slice($tmp, 0, $length)) . $replacer;
return $text;
}
/**
* Get a subtring with the max length setting.
*
* @param string $text;
* @param int $length limit characters showing;
* @param string $replacer;
* @return tring;
*/
public static function substring($text, $length = 100, $replacer = '...', $isStrips = true, $stringtags = '') {
if($isStrips){
$text = preg_replace('/\<p.*\>/Us','',$text);
$text = str_replace('</p>','<br/>',$text);
$text = strip_tags($text, $stringtags);
}
if(function_exists('mb_strlen')){
if (mb_strlen($text) < $length) return $text;
$text = mb_substr($text, 0, $length);
}else{
if (strlen($text) < $length) return $text;
$text = substr($text, 0, $length);
}
return $text . $replacer;
}
}