Source Code Documentation


s2member\includes\classes\utils-css.inc.php


  1. <?php
  2. /**
  3. * CSS utilities.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\Utilities
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19.  
  20. if (!class_exists ("c_ws_plugin__s2member_utils_css"))
  21. {
  22. /**
  23. * CSS utilities.
  24. *
  25. * @package s2Member\Utilities
  26. * @since 3.5
  27. */
  28. class c_ws_plugin__s2member_utils_css
  29. {
  30. /**
  31. * Handles CSS compression.
  32. *
  33. * @package s2Member\Utilities
  34. * @since 3.5
  35. *
  36. * @param str $css A string of CSS.
  37. * @return str String of CSS, after compression.
  38. */
  39. public static function compress_css ($css = FALSE)
  40. {
  41. $c6 = "/(\:#| #)([A-Z0-9]{6})/i";
  42. $css = preg_replace ("/\/\*(.*?)\*\//s", "", $css);
  43. $css = preg_replace ("/[\r\n\t]+/", "", $css);
  44. $css = preg_replace ("/ {2,}/", " ", $css);
  45. $css = preg_replace ("/ , | ,|, /", ",", $css);
  46. $css = preg_replace ("/ \> | \>|\> /", ">", $css);
  47. $css = preg_replace ("/\[ /", "[", $css);
  48. $css = preg_replace ("/ \]/", "]", $css);
  49. $css = preg_replace ("/ \!\= | \!\=|\!\= /", "!=", $css);
  50. $css = preg_replace ("/ \|\= | \|\=|\|\= /", "|=", $css);
  51. $css = preg_replace ("/ \^\= | \^\=|\^\= /", "^=", $css);
  52. $css = preg_replace ("/ \$\= | \$\=|\$\= /", "$=", $css);
  53. $css = preg_replace ("/ \*\= | \*\=|\*\= /", "*=", $css);
  54. $css = preg_replace ("/ ~\= | ~\=|~\= /", "~=", $css);
  55. $css = preg_replace ("/ \= | \=|\= /", "=", $css);
  56. $css = preg_replace ("/ \+ | \+|\+ /", "+", $css);
  57. $css = preg_replace ("/ ~ | ~|~ /", "~", $css);
  58. $css = preg_replace ("/ \{ | \{|\{ /", "{", $css);
  59. $css = preg_replace ("/ \} | \}|\} /", "}", $css);
  60. $css = preg_replace ("/ \: | \:|\: /", ":", $css);
  61. $css = preg_replace ("/ ; | ;|; /", ";", $css);
  62. $css = preg_replace ("/;\}/", "}", $css);
  63.  
  64. return preg_replace_callback ($c6, "c_ws_plugin__s2member_utils_css::_compress_css_c3", $css);
  65. }
  66. /**
  67. * Handles CSS compression of hex colors.
  68. *
  69. * Reduces 6 character hex codes to just 3 whenever possible.
  70. *
  71. * @package s2Member\Utilities
  72. * @since 3.5
  73. *
  74. * @param array $m Array of matches from ``preg_replace_callback()``.
  75. * @return str Shortened hex code when possible, full hex code when not possible.
  76. */
  77. public static function _compress_css_c3 ($m = FALSE)
  78. {
  79. if ($m[2][0] === $m[2][1] && $m[2][2] === $m[2][3] && $m[2][4] === $m[2][5])
  80. return $m[1] . $m[2][0] . $m[2][2] . $m[2][4];
  81. return $m[0];
  82. }
  83. }
  84. }
  85. ?>

s2member\includes\classes\utils-css.inc.php

Source Code Documentation