* @author ThemePunch <info@themepunch.com>
* @link https://www.themepunch.com/
* @copyright 2024 ThemePunch
if(!defined('ABSPATH')) exit();
class RevSliderCssParser extends RevSliderFunctions {
* init the parser, set css content
* @before: RevSliderCssParser::initContent()
public function init_css($css){
* get array of slide classes, between two sections.
* @before: RevSliderCssParser::getArrClasses()
public function get_classes($start_text = '', $end_text = '', $explodeonspace = false){
$pos_start = strpos($content, $start_text);
$content = ($pos_start !== false) ? substr($content, $pos_start, strlen($content) - $pos_start) : $content;
$pos_end = strpos($content, $end_text);
$content = ($pos_end !== false) ? substr($content, 0, $pos_end) : $content;
$lines = explode("\n", $content);
foreach($lines as $key => $line){
if(strpos($line, '{') === false || strpos($line, '.caption a') || strpos($line, '.tp-caption a') !== false)
//get style out of the line
$class = trim(str_replace('{', '', $line));
//skip captions like this: .tp-caption.imageclass img
if(strpos($class, ' ') !== false){
$class = explode(',', $class);
//skip captions like this: .tp-caption.imageclass:hover, :before, :after
if(strpos($class, ':') !== false)
$class = str_replace(array('.caption.', '.tp-caption.'), '.', $class);
$class = trim(str_replace('.', '', $class));
$words = explode(' ', $class);
$class = $words[count($words)-1];
* parse css stylesheet to an array
* @before: RevSliderCssParser::parseCssToArray();
public function css_to_array($css){
while(strpos($css, '/*') !== false){
if(strpos($css, '*/') === false) return false;
$start = strpos($css, '/*');
$end = strpos($css, '*/') + 2;
$css = str_replace(substr($css, $start, $end - $start), '', $css);
//preg_match_all('/(?ims)([a-z0-9\s\.\:#_\-@]+)\{([^\}]*)\}/', $css, $arr);
preg_match_all('/(?ims)([a-z0-9\,\s\.\:#_\-@]+)\{([^\}]*)\}/', $css, $arr);
foreach($arr[0] as $i => $x){
$selector = trim($arr[1][$i]);
if(strpos($selector, '{') !== false || strpos($selector, '}') !== false) return false;
$rules = explode(';', trim($arr[2][$i]));
$result[$selector] = array();
foreach($rules as $strRule){
$rule = explode(':', $strRule);
//does not work if in css is another { or }
//if(strpos($rule[0], '{') !== false || strpos($rule[0], '}') !== false || strpos($rule[1], '{') !== false || strpos($rule[1], '}') !== false) return false;
//put back everything but not $rule[0];
$values = implode(':', $rule);
$result[$selector][trim($key)] = trim(str_replace("'", '"', $values));
* parse database entry to css
* @before: RevSliderCssParser::parseDbArrayToCss();
public function parse_db_to_css($css_array, $nl = "\n\r"){
$deformations = $this->get_deformation_css_tags();
'color' => 'color-transparency',
'background-color' => 'background-transparency',
'border-color' => 'border-transparency'
$check_parameters = array(
foreach($css_array as $id => $attr){
$stripped = (strpos($attr['handle'], '.tp-caption') !== false) ? trim(str_replace('.tp-caption', '', $attr['handle'])) : '';
$attr['advanced'] = json_decode($attr['advanced'], true);
$styles = json_decode(str_replace("'", '"', $attr['params']), true);
$styles_adv = $attr['advanced']['idle'];
$css .= (!empty($stripped)) ? ', '.$stripped : '';
if(is_array($styles) || is_array($styles_adv)){
foreach($styles as $name => $style){
if(in_array($name, $deformations) && $name !== 'cursor') continue;
if(!is_array($name) && isset($transparency[$name])){ //the style can have transparency!
if(isset($styles[$transparency[$name]]) && $style !== 'transparent'){
$style = $this->hex2rgba($style, $styles[$transparency[$name]] * 100);
if(!is_array($name) && isset($check_parameters[$name])){
$style = $this->add_missing_val($style, $check_parameters[$name]);
if(is_array($style) || is_object($style)) $style = implode(' ', $style);
$ret = $this->check_for_modifications($name, $style);
if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
$css .= $ret['name'].':'.$ret['style'].";".$nl;
if(is_array($styles_adv)){
foreach($styles_adv as $name => $style){
if(in_array($name, $deformations) && $name !== 'cursor') continue;
if(is_array($style) || is_object($style)) $style = implode(' ', $style);
$ret = $this->check_for_modifications($name, $style);
if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
$css .= $ret['name'].':'.$ret['style'].";".$nl;
$setting = json_decode($attr['settings'], true);
if(isset($setting['hover']) && $setting['hover'] == 'true'){
$hover = json_decode(str_replace("'", '"', $attr['hover']), true);
$hover_adv = $attr['advanced']['hover'];
if(is_array($hover) || is_array($hover_adv)){
$css .= $attr['handle'].':hover';
if(!empty($stripped)) $css .= ', '.$stripped.':hover';
foreach($hover as $name => $style){
if(in_array($name, $deformations) && $name !== 'cursor') continue;
if(!is_array($name) && isset($transparency[$name])){ //the style can have transparency!
if(isset($hover[$transparency[$name]]) && $style !== 'transparent'){
$style = $this->hex2rgba($style, $hover[$transparency[$name]] * 100);
if(!is_array($name) && isset($check_parameters[$name])){
$style = $this->add_missing_val($style, $check_parameters[$name]);
if(is_array($style)|| is_object($style)) $style = implode(' ', $style);
$ret = $this->check_for_modifications($name, $style);
if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
$css .= $ret['name'].':'.$ret['style'].";".$nl;
if(is_array($hover_adv)){
foreach($hover_adv as $name => $style){
if(in_array($name, $deformations) && $name !== 'cursor') continue;
if(is_array($style)|| is_object($style)) $style = implode(' ', $style);
$ret = $this->check_for_modifications($name, $style);
if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
$css .= $ret['name'].':'.$ret['style'].";".$nl;
* Check for Modifications like with cursor
public function check_for_modifications($name, $style){
$style = ($style == 'zoom-in') ? 'zoom-in; -webkit-zoom-in; cursor: -moz-zoom-in' : $style;
$style = ($style == 'zoom-out') ? 'zoom-out; -webkit-zoom-out; cursor: -moz-zoom-out' : $style;
return array('name' => $name, 'style' => $style);
* Check for Modifications like with cursor
* @before: RevSliderCssParser::parseArrayToCss();
public function array_to_css($css_array, $nl = "\n\r", $adv = false){
$deformations = $this->get_deformation_css_tags();
foreach($css_array as $id => $attr){
$setting = (array)$attr['settings'];
$advanced = (array)$attr['advanced'];
$stripped = (strpos($attr['handle'], '.tp-caption') !== false) ? trim(str_replace('.tp-caption', '', $attr['handle'])) : '';
$styles = (array)$attr['params'];
$css .= (!empty($stripped)) ? ', '.$stripped : $css;
if($adv && isset($advanced['idle'])){
$styles = array_merge($styles, (array)$advanced['idle']);
if(isset($setting['type'])){
$styles['type'] = $setting['type'];
if(is_array($styles) && !empty($styles)){
foreach($styles as $name => $style){
if(in_array($name, $deformations) && $name !== 'cursor') continue;
if($name == 'background-color' && strpos($style, 'rgba') !== false){ //rgb && rgba
$rgb = explode(',', str_replace('rgba', 'rgb', $style));
unset($rgb[count($rgb)-1]);
$rgb = implode(',', $rgb).')';
$css .= $name.':'.$rgb.';'.$nl;
$style = (is_array($style) || is_object($style)) ? implode(' ', $style) : $style;
$css .= $name.':'.$style.';'.$nl;
if(isset($setting['hover']) && $setting['hover'] == 'true'){
$hover = (array)$attr['hover'];
if($adv && isset($advanced['hover'])){
$styles = array_merge($styles, (array)$advanced['hover']);
$css .= $attr['handle'].':hover';
if(!empty($stripped)) $css.= ', '.$stripped.':hover';
foreach($hover as $name => $style){
if($name == 'background-color' && strpos($style, 'rgba') !== false){ //rgb && rgba
$rgb = explode(',', str_replace('rgba', 'rgb', $style));
unset($rgb[count($rgb)-1]);
$rgb = implode(',', $rgb).')';
$css .= $name.':'.$rgb.';'.$nl;
$style = (is_array($style) || is_object($style)) ? implode(' ', $style) : $style;
$css .= $name.':'.$style.';'.$nl;
* parse static database to css
* @before: RevSliderCssParser::parseStaticArrayToCss();
public function static_to_css($css_array, $nl = "\n"){
return $this->simple_array_to_css($css_array);
* parse simple array to css
* @before: RevSliderCssParser::parseSimpleArrayToCss();
public function simple_array_to_css($css_array, $nl = "\n"){
foreach($css_array as $class => $styles){
if(is_array($styles) && !empty($styles)){
foreach($styles as $name => $style){
$style = (is_array($style) || is_object($style)) ? implode(' ', $style) : $style;
$css .= $name.':'.$style.';'.$nl;
* parse db array to array
* @before: RevSliderCssParser::parseDbArrayToArray();
public function db_array_to_array($css_array, $handle = false){
if(!is_array($css_array) || empty($css_array)) return false;
foreach($css_array as $key => $css){
if($this->get_val($css_array[$key], 'handle') == '.tp-caption.'.$handle){
$css_array[$key]['params'] = json_decode(str_replace("'", '"', $this->get_val($css, 'params')));
$css_array[$key]['hover'] = json_decode(str_replace("'", '"', $this->get_val($css, 'hover')));
$css_array[$key]['advanced'] = json_decode(str_replace("'", '"', $this->get_val($css, 'advanced')));
$css_array[$key]['settings'] = json_decode(str_replace("'", '"', $this->get_val($css, 'settings')));
$css_array[$key]['params'] = json_decode(str_replace("'", '"', $this->get_val($css, 'params')));
$css_array[$key]['hover'] = json_decode(str_replace("'", '"', $this->get_val($css, 'hover')));
$css_array[$key]['advanced'] = json_decode(str_replace("'", '"', $this->get_val($css, 'advanced')));
$css_array[$key]['settings'] = json_decode(str_replace("'", '"', $this->get_val($css, 'settings')));
public function compress_css($buffer){
$buffer = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", '', $buffer) ;
/* remove tabs, spaces, newlines, etc. */
$arr = array("\r\n", "\r", "\n", "\t", ' ', ' ', ' ');
$rep = array('', '', '', '', ' ', ' ', ' ');
$buffer = str_replace($arr, $rep, $buffer);
/* remove whitespaces around {}:, */
$buffer = preg_replace("/\s*([\{\}:,])\s*/", "$1", $buffer);
$buffer = str_replace(';}', '}', $buffer);
* Defines the default CSS Classes, can be given a version number to order them accordingly
public function default_css_classes(){
$c.'.medium_grey' => '4',
$c.'.medium_text' => '4',
$c.'.very_large_text' => '4',
$c.'.very_big_white' => '4',
$c.'.very_big_black' => '4',
$c.'.modern_medium_fat' => '4',
$c.'.modern_medium_fat_white' => '4',
$c.'.modern_medium_light' => '4',
$c.'.modern_big_bluebg' => '4',
$c.'.modern_big_redbg' => '4',
$c.'.modern_small_text_dark' => '4',
$c.'.thinheadline_dark' => '4',
$c.'.thintext_dark' => '4',
$c.'.largeblackbg' => '4',
$c.'.largepinkbg' => '4',
$c.'.largewhitebg' => '4',
$c.'.largegreenbg' => '4',
$c.'.large_bold_grey' => '4',
$c.'.medium_thin_grey' => '4',
$c.'.small_thin_grey' => '4',
$c.'.lightgrey_divider' => '4',
$c.'.large_bold_darkblue' => '4',
$c.'.medium_bg_darkblue' => '4',
$c.'.medium_bold_red' => '4',
$c.'.medium_light_red' => '4',
$c.'.medium_bg_red' => '4',
$c.'.medium_bold_orange' => '4',
$c.'.medium_bg_orange' => '4',
$c.'.large_bold_white' => '4',
$c.'.medium_light_white' => '4',
$c.'.mediumlarge_light_white' => '4',
$c.'.mediumlarge_light_white_center' => '4',
$c.'.medium_bg_asbestos' => '4',
$c.'.medium_light_black' => '4',
$c.'.large_bold_black' => '4',
$c.'.mediumlarge_light_darkblue'=> '4',
$c.'.small_light_white' => '4',
$c.'.roundedimage' => '4',
$c.'.large_bg_black' => '4',
$c.'.mediumwhitebg' => '4',
$c.'.MarkerDisplay' => '5.0',
$c.'.Restaurant-Display' => '5.0',
$c.'.Restaurant-Cursive' => '5.0',
$c.'.Restaurant-ScrollDownText' => '5.0',
$c.'.Restaurant-Description' => '5.0',
$c.'.Restaurant-Price' => '5.0',
$c.'.Restaurant-Menuitem' => '5.0',
$c.'.Furniture-LogoText' => '5.0',
$c.'.Furniture-Plus' => '5.0',
$c.'.Furniture-Title' => '5.0',
$c.'.Furniture-Subtitle' => '5.0',
$c.'.Gym-Display' => '5.0',
$c.'.Gym-Subline' => '5.0',
$c.'.Gym-SmallText' => '5.0',
$c.'.Fashion-SmallText' => '5.0',
$c.'.Fashion-BigDisplay' => '5.0',
$c.'.Fashion-TextBlock' => '5.0',
$c.'.Sports-Display' => '5.0',
$c.'.Sports-DisplayFat' => '5.0',
$c.'.Sports-Subline' => '5.0',
$c.'.Instagram-Caption' => '5.0',
$c.'.News-Title' => '5.0',
$c.'.News-Subtitle' => '5.0',
$c.'.Photography-Display' => '5.0',
$c.'.Photography-Subline' => '5.0',
$c.'.Photography-ImageHover' => '5.0',
$c.'.Photography-Menuitem' => '5.0',
$c.'.Photography-Textblock' => '5.0',
$c.'.Photography-Subline-2' => '5.0',
$c.'.Photography-ImageHover2' => '5.0',
$c.'.WebProduct-Title' => '5.0',
$c.'.WebProduct-SubTitle' => '5.0',
$c.'.WebProduct-Content' => '5.0',
$c.'.WebProduct-Menuitem' => '5.0',
$c.'.WebProduct-Title-Light' => '5.0',
$c.'.WebProduct-SubTitle-Light' => '5.0',
$c.'.WebProduct-Content-Light' => '5.0',
$c.'.FatRounded' => '5.0',
$c.'.NotGeneric-Title' => '5.0',
$c.'.NotGeneric-SubTitle' => '5.0',
$c.'.NotGeneric-CallToAction' => '5.0',
$c.'.NotGeneric-Icon' => '5.0',