cssparser.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <?php
  2. /**
  3. * @author ThemePunch <info@themepunch.com>
  4. * @link http://www.themepunch.com/
  5. * @copyright 2015 ThemePunch
  6. */
  7. if( !defined( 'ABSPATH') ) exit();
  8. class RevSliderCssParser{
  9. private $cssContent;
  10. public function __construct(){
  11. }
  12. /**
  13. *
  14. * init the parser, set css content
  15. */
  16. public function initContent($cssContent){
  17. $this->cssContent = $cssContent;
  18. }
  19. /**
  20. *
  21. * get array of slide classes, between two sections.
  22. */
  23. public function getArrClasses($startText = "",$endText="",$explodeonspace=false){
  24. $content = $this->cssContent;
  25. //trim from top
  26. if(!empty($startText)){
  27. $posStart = strpos($content, $startText);
  28. if($posStart !== false)
  29. $content = substr($content, $posStart,strlen($content)-$posStart);
  30. }
  31. //trim from bottom
  32. if(!empty($endText)){
  33. $posEnd = strpos($content, $endText);
  34. if($posEnd !== false)
  35. $content = substr($content,0,$posEnd);
  36. }
  37. //get styles
  38. $lines = explode("\n",$content);
  39. $arrClasses = array();
  40. foreach($lines as $key=>$line){
  41. $line = trim($line);
  42. if(strpos($line, "{") === false)
  43. continue;
  44. //skip unnessasary links
  45. if(strpos($line, ".caption a") !== false)
  46. continue;
  47. if(strpos($line, ".tp-caption a") !== false)
  48. continue;
  49. //get style out of the line
  50. $class = str_replace("{", "", $line);
  51. $class = trim($class);
  52. //skip captions like this: .tp-caption.imageclass img
  53. if(strpos($class," ") !== false){
  54. if(!$explodeonspace){
  55. continue;
  56. }else{
  57. $class = explode(',', $class);
  58. $class = $class[0];
  59. }
  60. }
  61. //skip captions like this: .tp-caption.imageclass:hover, :before, :after
  62. if(strpos($class,":") !== false)
  63. continue;
  64. $class = str_replace(".caption.", ".", $class);
  65. $class = str_replace(".tp-caption.", ".", $class);
  66. $class = str_replace(".", "", $class);
  67. $class = trim($class);
  68. $arrWords = explode(" ", $class);
  69. $class = $arrWords[count($arrWords)-1];
  70. $class = trim($class);
  71. $arrClasses[] = $class;
  72. }
  73. sort($arrClasses);
  74. return($arrClasses);
  75. }
  76. public static function parseCssToArray($css){
  77. while(strpos($css, '/*') !== false){
  78. if(strpos($css, '*/') === false) return false;
  79. $start = strpos($css, '/*');
  80. $end = strpos($css, '*/') + 2;
  81. $css = str_replace(substr($css, $start, $end - $start), '', $css);
  82. }
  83. //preg_match_all( '/(?ims)([a-z0-9\s\.\:#_\-@]+)\{([^\}]*)\}/', $css, $arr);
  84. preg_match_all( '/(?ims)([a-z0-9\,\s\.\:#_\-@]+)\{([^\}]*)\}/', $css, $arr);
  85. $result = array();
  86. foreach ($arr[0] as $i => $x){
  87. $selector = trim($arr[1][$i]);
  88. if(strpos($selector, '{') !== false || strpos($selector, '}') !== false) return false;
  89. $rules = explode(';', trim($arr[2][$i]));
  90. $result[$selector] = array();
  91. foreach ($rules as $strRule){
  92. if (!empty($strRule)){
  93. $rule = explode(":", $strRule);
  94. if(strpos($rule[0], '{') !== false || strpos($rule[0], '}') !== false || strpos($rule[1], '{') !== false || strpos($rule[1], '}') !== false) return false;
  95. //put back everything but not $rule[0];
  96. $key = trim($rule[0]);
  97. unset($rule[0]);
  98. $values = implode(':', $rule);
  99. $result[$selector][trim($key)] = trim(str_replace("'", '"', $values));
  100. }
  101. }
  102. }
  103. return($result);
  104. }
  105. public static function parseDbArrayToCss($cssArray, $nl = "\n\r"){
  106. $css = '';
  107. $deformations = self::get_deformation_css_tags();
  108. $transparency = array(
  109. 'color' => 'color-transparency',
  110. 'background-color' => 'background-transparency',
  111. 'border-color' => 'border-transparency'
  112. );
  113. $check_parameters = array(
  114. 'border-width' => 'px',
  115. 'border-radius' => 'px',
  116. 'padding' => 'px',
  117. 'font-size' => 'px',
  118. 'line-height' => 'px'
  119. );
  120. foreach($cssArray as $id => $attr){
  121. $stripped = '';
  122. if(strpos($attr['handle'], '.tp-caption') !== false){
  123. $stripped = trim(str_replace('.tp-caption', '', $attr['handle']));
  124. }
  125. $attr['advanced'] = json_decode($attr['advanced'], true);
  126. $styles = json_decode(str_replace("'", '"', $attr['params']), true);
  127. $styles_adv = $attr['advanced']['idle'];
  128. $css.= $attr['handle'];
  129. if(!empty($stripped)) $css.= ', '.$stripped;
  130. $css.= " {".$nl;
  131. if(is_array($styles) || is_array($styles_adv)){
  132. if(is_array($styles)){
  133. foreach($styles as $name => $style){
  134. if(in_array($name, $deformations)) {
  135. if($name !== 'css_cursor' && $name !== 'pointer_events') continue;
  136. }
  137. if(!is_array($name) && isset($transparency[$name])){ //the style can have transparency!
  138. if(isset($styles[$transparency[$name]]) && $style !== 'transparent'){
  139. $style = RevSliderFunctions::hex2rgba($style, $styles[$transparency[$name]] * 100);
  140. }
  141. }
  142. if(!is_array($name) && isset($check_parameters[$name])){
  143. $style = RevSliderFunctions::add_missing_val($style, $check_parameters[$name]);
  144. }
  145. if(is_array($style) || is_object($style)) $style = implode(' ', $style);
  146. $ret = self::check_for_modifications($name, $style);
  147. if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
  148. if($ret['name'] == 'pointer-events' && $ret['style'] == 'auto') continue;
  149. $css.= $ret['name'].':'.$ret['style'].";".$nl;
  150. }
  151. }
  152. if(is_array($styles_adv)){
  153. foreach($styles_adv as $name => $style){
  154. if(in_array($name, $deformations)) {
  155. if($name !== 'css_cursor' && $name !== 'pointer_events') continue;
  156. }
  157. if(is_array($style) || is_object($style)) $style = implode(' ', $style);
  158. $ret = self::check_for_modifications($name, $style);
  159. if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
  160. if($ret['name'] == 'pointer-events' && $ret['style'] == 'auto') continue;
  161. $css.= $ret['name'].':'.$ret['style'].";".$nl;
  162. }
  163. }
  164. }
  165. $css.= "}".$nl.$nl;
  166. //add hover
  167. $setting = json_decode($attr['settings'], true);
  168. if(isset($setting['hover']) && $setting['hover'] == 'true'){
  169. $hover = json_decode(str_replace("'", '"', $attr['hover']), true);
  170. $hover_adv = $attr['advanced']['hover'];
  171. if(is_array($hover) || is_array($hover_adv)){
  172. $css.= $attr['handle'].":hover";
  173. if(!empty($stripped)) $css.= ', '.$stripped.':hover';
  174. $css.= " {".$nl;
  175. if(is_array($hover)){
  176. foreach($hover as $name => $style){
  177. if(in_array($name, $deformations)) {
  178. if($name !== 'css_cursor' && $name !== 'pointer_events') continue;
  179. }
  180. if(!is_array($name) && isset($transparency[$name])){ //the style can have transparency!
  181. if(isset($hover[$transparency[$name]]) && $style !== 'transparent'){
  182. $style = RevSliderFunctions::hex2rgba($style, $hover[$transparency[$name]] * 100);
  183. }
  184. }
  185. if(!is_array($name) && isset($check_parameters[$name])){
  186. $style = RevSliderFunctions::add_missing_val($style, $check_parameters[$name]);
  187. }
  188. if(is_array($style)|| is_object($style)) $style = implode(' ', $style);
  189. $ret = self::check_for_modifications($name, $style);
  190. if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
  191. if($ret['name'] == 'pointer-events' && $ret['style'] == 'auto') continue;
  192. $css.= $ret['name'].':'.$ret['style'].";".$nl;
  193. }
  194. }
  195. if(is_array($hover_adv)){
  196. foreach($hover_adv as $name => $style){
  197. if(in_array($name, $deformations)) {
  198. if($name !== 'css_cursor' && $name !== 'pointer_events') continue;
  199. }
  200. if(is_array($style)|| is_object($style)) $style = implode(' ', $style);
  201. $ret = self::check_for_modifications($name, $style);
  202. if($ret['name'] == 'cursor' && $ret['style'] == 'auto') continue;
  203. $css.= $ret['name'].':'.$ret['style'].";".$nl;
  204. }
  205. }
  206. $css.= "}".$nl.$nl;
  207. }
  208. }
  209. }
  210. return $css;
  211. }
  212. /**
  213. * Check for Modifications like with css_cursor
  214. * @since: 5.1.3
  215. **/
  216. public static function check_for_modifications($name, $style){
  217. if($name == 'css_cursor'){
  218. if($style == 'zoom-in') $style = 'zoom-in; -webkit-zoom-in; cursor: -moz-zoom-in';
  219. if($style == 'zoom-out') $style = 'zoom-out; -webkit-zoom-out; cursor: -moz-zoom-out';
  220. $name = 'cursor';
  221. }
  222. if($name == 'pointer_events'){
  223. $name = 'pointer-events';
  224. }
  225. return array('name' => $name, 'style' => $style);
  226. }
  227. public static function parseArrayToCss($cssArray, $nl = "\n\r", $adv = false){
  228. $deformations = self::get_deformation_css_tags();
  229. $css = '';
  230. foreach($cssArray as $id => $attr){
  231. $setting = (array)$attr['settings'];
  232. $advanced = (array)$attr['advanced'];
  233. $stripped = '';
  234. if(strpos($attr['handle'], '.tp-caption') !== false){
  235. $stripped = trim(str_replace('.tp-caption', '', $attr['handle']));
  236. }
  237. $styles = (array)$attr['params'];
  238. $css.= $attr['handle'];
  239. if(!empty($stripped)) $css.= ', '.$stripped;
  240. $css.= " {".$nl;
  241. if($adv && isset($advanced['idle'])){
  242. $styles = array_merge($styles, (array)$advanced['idle']);
  243. if(isset($setting['type'])){
  244. $styles['type'] = $setting['type'];
  245. }
  246. }
  247. if(is_array($styles) && !empty($styles)){
  248. foreach($styles as $name => $style){
  249. if(in_array($name, $deformations)) {
  250. if($name !== 'css_cursor' && $name !== 'pointer_events') continue;
  251. }
  252. if($name == 'background-color' && strpos($style, 'rgba') !== false){ //rgb && rgba
  253. $rgb = explode(',', str_replace('rgba', 'rgb', $style));
  254. unset($rgb[count($rgb)-1]);
  255. $rgb = implode(',', $rgb).')';
  256. $css.= $name.':'.$rgb.";".$nl;
  257. }
  258. $style = (is_array($style) || is_object($style)) ? implode(' ', $style) : $style;
  259. $css.= $name.':'.$style.";".$nl;
  260. }
  261. }
  262. $css.= "}".$nl.$nl;
  263. //add hover
  264. if(isset($setting['hover']) && $setting['hover'] == 'true'){
  265. $hover = (array)$attr['hover'];
  266. if($adv && isset($advanced['hover'])){
  267. $styles = array_merge($styles, (array)$advanced['hover']);
  268. }
  269. if(is_array($hover)){
  270. $css.= $attr['handle'].":hover";
  271. if(!empty($stripped)) $css.= ', '.$stripped.":hover";
  272. $css.= " {".$nl;
  273. foreach($hover as $name => $style){
  274. if($name == 'background-color' && strpos($style, 'rgba') !== false){ //rgb && rgba
  275. $rgb = explode(',', str_replace('rgba', 'rgb', $style));
  276. unset($rgb[count($rgb)-1]);
  277. $rgb = implode(',', $rgb).')';
  278. $css.= $name.':'.$rgb.";".$nl;
  279. }
  280. $style = (is_array($style) || is_object($style)) ? implode(' ', $style) : $style;
  281. $css.= $name.':'.$style.";".$nl;
  282. }
  283. $css.= "}".$nl.$nl;
  284. }
  285. }
  286. }
  287. return $css;
  288. }
  289. public static function parseStaticArrayToCss($cssArray, $nl = "\n"){
  290. $css = RevSliderCssParser::parseSimpleArrayToCss();
  291. return $css;
  292. }
  293. public static function parseSimpleArrayToCss($cssArray, $nl = "\n"){
  294. $css = '';
  295. foreach($cssArray as $class => $styles){
  296. $css.= $class." {".$nl;
  297. if(is_array($styles) && !empty($styles)){
  298. foreach($styles as $name => $style){
  299. $style = (is_array($style) || is_object($style)) ? implode(' ', $style) : $style;
  300. $css.= $name.':'.$style.";".$nl;
  301. }
  302. }
  303. $css.= "}".$nl.$nl;
  304. }
  305. return $css;
  306. }
  307. public static function parseDbArrayToArray($cssArray, $handle = false){
  308. if(!is_array($cssArray) || empty($cssArray)) return false;
  309. foreach($cssArray as $key => $css){
  310. if($handle != false){
  311. if($cssArray[$key]['handle'] == '.tp-caption.'.$handle){
  312. $cssArray[$key]['params'] = json_decode(str_replace("'", '"', $css['params']));
  313. $cssArray[$key]['hover'] = json_decode(str_replace("'", '"', $css['hover']));
  314. $cssArray[$key]['advanced'] = json_decode(str_replace("'", '"', $css['advanced']));
  315. $cssArray[$key]['settings'] = json_decode(str_replace("'", '"', $css['settings']));
  316. return $cssArray[$key];
  317. }else{
  318. unset($cssArray[$key]);
  319. }
  320. }else{
  321. $cssArray[$key]['params'] = json_decode(str_replace("'", '"', $css['params']));
  322. $cssArray[$key]['hover'] = json_decode(str_replace("'", '"', $css['hover']));
  323. $cssArray[$key]['advanced'] = json_decode(str_replace("'", '"', $css['advanced']));
  324. $cssArray[$key]['settings'] = json_decode(str_replace("'", '"', $css['settings']));
  325. }
  326. }
  327. return $cssArray;
  328. }
  329. public static function compress_css($buffer){
  330. /* remove comments */
  331. $buffer = preg_replace("!/\*[^*]*\*+([^/][^*]*\*+)*/!", "", $buffer) ;
  332. /* remove tabs, spaces, newlines, etc. */
  333. $arr = array("\r\n", "\r", "\n", "\t", " ", " ", " ");
  334. $rep = array("", "", "", "", " ", " ", " ");
  335. $buffer = str_replace($arr, $rep, $buffer);
  336. /* remove whitespaces around {}:, */
  337. $buffer = preg_replace("/\s*([\{\}:,])\s*/", "$1", $buffer);
  338. /* remove last ; */
  339. $buffer = str_replace(';}', "}", $buffer);
  340. return $buffer;
  341. }
  342. /**
  343. * Defines the default CSS Classes, can be given a version number to order them accordingly
  344. * @since: 5.0
  345. **/
  346. public static function default_css_classes(){
  347. $default = array(
  348. '.tp-caption.medium_grey' => '4',
  349. '.tp-caption.small_text' => '4',
  350. '.tp-caption.medium_text' => '4',
  351. '.tp-caption.large_text' => '4',
  352. '.tp-caption.very_large_text' => '4',
  353. '.tp-caption.very_big_white' => '4',
  354. '.tp-caption.very_big_black' => '4',
  355. '.tp-caption.modern_medium_fat' => '4',
  356. '.tp-caption.modern_medium_fat_white' => '4',
  357. '.tp-caption.modern_medium_light' => '4',
  358. '.tp-caption.modern_big_bluebg' => '4',
  359. '.tp-caption.modern_big_redbg' => '4',
  360. '.tp-caption.modern_small_text_dark' => '4',
  361. '.tp-caption.boxshadow' => '4',
  362. '.tp-caption.black' => '4',
  363. '.tp-caption.noshadow' => '4',
  364. '.tp-caption.thinheadline_dark' => '4',
  365. '.tp-caption.thintext_dark' => '4',
  366. '.tp-caption.largeblackbg' => '4',
  367. '.tp-caption.largepinkbg' => '4',
  368. '.tp-caption.largewhitebg' => '4',
  369. '.tp-caption.largegreenbg' => '4',
  370. '.tp-caption.excerpt' => '4',
  371. '.tp-caption.large_bold_grey' => '4',
  372. '.tp-caption.medium_thin_grey' => '4',
  373. '.tp-caption.small_thin_grey' => '4',
  374. '.tp-caption.lightgrey_divider' => '4',
  375. '.tp-caption.large_bold_darkblue' => '4',
  376. '.tp-caption.medium_bg_darkblue' => '4',
  377. '.tp-caption.medium_bold_red' => '4',
  378. '.tp-caption.medium_light_red' => '4',
  379. '.tp-caption.medium_bg_red' => '4',
  380. '.tp-caption.medium_bold_orange' => '4',
  381. '.tp-caption.medium_bg_orange' => '4',
  382. '.tp-caption.grassfloor' => '4',
  383. '.tp-caption.large_bold_white' => '4',
  384. '.tp-caption.medium_light_white' => '4',
  385. '.tp-caption.mediumlarge_light_white' => '4',
  386. '.tp-caption.mediumlarge_light_white_center' => '4',
  387. '.tp-caption.medium_bg_asbestos' => '4',
  388. '.tp-caption.medium_light_black' => '4',
  389. '.tp-caption.large_bold_black' => '4',
  390. '.tp-caption.mediumlarge_light_darkblue' => '4',
  391. '.tp-caption.small_light_white' => '4',
  392. '.tp-caption.roundedimage' => '4',
  393. '.tp-caption.large_bg_black' => '4',
  394. '.tp-caption.mediumwhitebg' => '4',
  395. '.tp-caption.MarkerDisplay' => '5.0',
  396. '.tp-caption.Restaurant-Display' => '5.0',
  397. '.tp-caption.Restaurant-Cursive' => '5.0',
  398. '.tp-caption.Restaurant-ScrollDownText' => '5.0',
  399. '.tp-caption.Restaurant-Description' => '5.0',
  400. '.tp-caption.Restaurant-Price' => '5.0',
  401. '.tp-caption.Restaurant-Menuitem' => '5.0',
  402. '.tp-caption.Furniture-LogoText' => '5.0',
  403. '.tp-caption.Furniture-Plus' => '5.0',
  404. '.tp-caption.Furniture-Title' => '5.0',
  405. '.tp-caption.Furniture-Subtitle' => '5.0',
  406. '.tp-caption.Gym-Display' => '5.0',
  407. '.tp-caption.Gym-Subline' => '5.0',
  408. '.tp-caption.Gym-SmallText' => '5.0',
  409. '.tp-caption.Fashion-SmallText' => '5.0',
  410. '.tp-caption.Fashion-BigDisplay' => '5.0',
  411. '.tp-caption.Fashion-TextBlock' => '5.0',
  412. '.tp-caption.Sports-Display' => '5.0',
  413. '.tp-caption.Sports-DisplayFat' => '5.0',
  414. '.tp-caption.Sports-Subline' => '5.0',
  415. '.tp-caption.Instagram-Caption' => '5.0',
  416. '.tp-caption.News-Title' => '5.0',
  417. '.tp-caption.News-Subtitle' => '5.0',
  418. '.tp-caption.Photography-Display' => '5.0',
  419. '.tp-caption.Photography-Subline' => '5.0',
  420. '.tp-caption.Photography-ImageHover' => '5.0',
  421. '.tp-caption.Photography-Menuitem' => '5.0',
  422. '.tp-caption.Photography-Textblock' => '5.0',
  423. '.tp-caption.Photography-Subline-2' => '5.0',
  424. '.tp-caption.Photography-ImageHover2' => '5.0',
  425. '.tp-caption.WebProduct-Title' => '5.0',
  426. '.tp-caption.WebProduct-SubTitle' => '5.0',
  427. '.tp-caption.WebProduct-Content' => '5.0',
  428. '.tp-caption.WebProduct-Menuitem' => '5.0',
  429. '.tp-caption.WebProduct-Title-Light' => '5.0',
  430. '.tp-caption.WebProduct-SubTitle-Light' => '5.0',
  431. '.tp-caption.WebProduct-Content-Light' => '5.0',
  432. '.tp-caption.FatRounded' => '5.0',
  433. '.tp-caption.NotGeneric-Title' => '5.0',
  434. '.tp-caption.NotGeneric-SubTitle' => '5.0',
  435. '.tp-caption.NotGeneric-CallToAction' => '5.0',
  436. '.tp-caption.NotGeneric-Icon' => '5.0',
  437. '.tp-caption.NotGeneric-Menuitem' => '5.0',
  438. '.tp-caption.MarkerStyle' => '5.0',
  439. '.tp-caption.Gym-Menuitem' => '5.0',
  440. '.tp-caption.Newspaper-Button' => '5.0',
  441. '.tp-caption.Newspaper-Subtitle' => '5.0',
  442. '.tp-caption.Newspaper-Title' => '5.0',
  443. '.tp-caption.Newspaper-Title-Centered' => '5.0',
  444. '.tp-caption.Hero-Button' => '5.0',
  445. '.tp-caption.Video-Title' => '5.0',
  446. '.tp-caption.Video-SubTitle' => '5.0',
  447. '.tp-caption.NotGeneric-Button' => '5.0',
  448. '.tp-caption.NotGeneric-BigButton' => '5.0',
  449. '.tp-caption.WebProduct-Button' => '5.0',
  450. '.tp-caption.Restaurant-Button' => '5.0',
  451. '.tp-caption.Gym-Button' => '5.0',
  452. '.tp-caption.Gym-Button-Light' => '5.0',
  453. '.tp-caption.Sports-Button-Light' => '5.0',
  454. '.tp-caption.Sports-Button-Red' => '5.0',
  455. '.tp-caption.Photography-Button' => '5.0',
  456. '.tp-caption.Newspaper-Button-2' => '5.0'
  457. );
  458. $default = apply_filters('revslider_mod_default_css_handles', $default);
  459. return $default;
  460. }
  461. /**
  462. * Defines the deformation CSS which is not directly usable as pure CSS
  463. * @since: 5.0
  464. **/
  465. public static function get_deformation_css_tags(){
  466. return array(
  467. 'x' => 'x',
  468. 'y' => 'y',
  469. 'z' => 'z',
  470. 'skewx' => 'skewx',
  471. 'skewy' => 'skewy',
  472. 'scalex' => 'scalex',
  473. 'scaley' => 'scaley',
  474. 'opacity' => 'opacity',
  475. 'xrotate' => 'xrotate',
  476. 'yrotate' => 'yrotate',
  477. '2d_rotation' => '2d_rotation',
  478. 'layer_2d_origin_x' => 'layer_2d_origin_x',
  479. 'layer_2d_origin_y' => 'layer_2d_origin_y',
  480. '2d_origin_x' => '2d_origin_x',
  481. '2d_origin_y' => '2d_origin_y',
  482. 'pers' => 'pers',
  483. 'color-transparency' => 'color-transparency',
  484. 'background-transparency' => 'background-transparency',
  485. 'border-transparency' => 'border-transparency',
  486. 'css_cursor' => 'css_cursor',
  487. 'pointer_events' => 'pointer_events',
  488. 'speed' => 'speed',
  489. 'easing' => 'easing',
  490. 'corner_left' => 'corner_left',
  491. 'corner_right' => 'corner_right',
  492. 'parallax' => 'parallax',
  493. 'type' => 'type',
  494. 'padding' => 'padding',
  495. 'margin' => 'margin',
  496. 'text-align' => 'text-align'
  497. );
  498. }
  499. public static function get_captions_sorted(){
  500. $db = new RevSliderDB();
  501. $styles = $db->fetch(RevSliderGlobals::$table_css, '', 'handle ASC');
  502. $arr = array('5.0' => array(), 'Custom' => array(), '4' => array());
  503. foreach($styles as $style){
  504. $setting = json_decode($style['settings'], true);
  505. if(!isset($setting['type'])) $setting['type'] = 'text';
  506. if(array_key_exists('version', $setting) && isset($setting['version'])) $arr[ucfirst($setting['version'])][] = array('label' => trim(str_replace('.tp-caption.', '', $style['handle'])), 'type' => $setting['type']);
  507. }
  508. $sorted = array();
  509. foreach($arr as $version => $class){
  510. foreach($class as $name){
  511. $sorted[] = array('label' => $name['label'], 'version' => $version, 'type' => $name['type']);
  512. }
  513. }
  514. return $sorted;
  515. }
  516. /**
  517. * Handles media queries
  518. * @since: 5.2.0
  519. **/
  520. public static function parse_media_blocks($css){
  521. $mediaBlocks = array();
  522. $start = 0;
  523. while(($start = strpos($css, '@media', $start)) !== false){
  524. $s = array();
  525. $i = strpos($css, '{', $start);
  526. if ($i !== false){
  527. $block = trim(substr($css, $start, $i - $start));
  528. array_push($s, $css[$i]);
  529. $i++;
  530. while(!empty($s)){
  531. if ($css[$i] == '{'){
  532. array_push($s, '{');
  533. }elseif ($css[$i] == '}'){
  534. array_pop($s);
  535. }else{
  536. //broken css?
  537. }
  538. $i++;
  539. }
  540. $mediaBlocks[$block] = substr($css, $start, ($i + 1) - $start);
  541. $start = $i;
  542. }
  543. }
  544. return $mediaBlocks;
  545. }
  546. /**
  547. * removes @media { ... } queries from CSS
  548. * @since: 5.2.0
  549. **/
  550. public static function clear_media_block($css){
  551. $start = 0;
  552. if(strpos($css, '@media', $start) !== false){
  553. $start = strpos($css, '@media', 0);
  554. $i = strpos($css, '{', $start) + 1;
  555. //remove @media ... first {
  556. $remove = substr($css, $start - 1, $i - $start + 1);
  557. $css = str_replace($remove, '', $css);
  558. //remove last }
  559. $css = preg_replace('/}$/', '', $css);
  560. }
  561. return $css;
  562. }
  563. }
  564. /**
  565. * old classname extends new one (old classnames will be obsolete soon)
  566. * @since: 5.0
  567. **/
  568. class UniteCssParserRev extends RevSliderCssParser {}
  569. ?>