WC_Compare_Less

The WooCommerce Compare Products LITE WC Compare Less class.

Defined (1)

The class is defined in the following location(s).

/admin/less/sass.php  
  1. class WC_Compare_Less 
  2. public $plugin_name = 'wc_compare_product'; 
  3. public $css_file_name = 'wc_compare_product'; 
  4. public $css_product_comparison_file_name = 'wc_product_comparison'; 
  5. public $plugin_folder = WOOCP_FOLDER; 
  6. public $plugin_dir = WOOCP_DIR; 
  7.  
  8. /**-----------------------------------------------------------------------------------*/ 
  9. /** Constructor */ 
  10. /**-----------------------------------------------------------------------------------*/ 
  11. public function __construct() 
  12. add_action( $this->plugin_name.'_after_settings_save_reset', array ($this, 'plugin_build_sass') ); 
  13. add_action( 'wp_enqueue_scripts', array ($this, 'apply_style_css_fontend'), 11 ); 
  14.  
  15. public function apply_style_css_fontend() 
  16. $_upload_dir = wp_upload_dir(); 
  17. if ( file_exists( $_upload_dir['basedir'] . '/sass/' . $this->css_file_name . '.min.css' ) ) { 
  18. wp_enqueue_style( 'a3' . $this->css_file_name, str_replace( array('http:', 'https:'), '', $_upload_dir['baseurl'] ) . '/sass/' . $this->css_file_name . '.min.css', array(), $this->get_css_file_version() ); 
  19.  
  20. public function plugin_build_sass() 
  21. $sass = $this->sass_content_data(); 
  22. $this->plugin_compile_less_mincss( $sass ); 
  23.  
  24. $sass_comparison = $this->sass_content_comparison_data(); 
  25. $this->plugin_compile_less_mincss( $sass_comparison, $this->css_product_comparison_file_name ); 
  26. $this->set_css_file_version(); 
  27. public function custom_filesystem_method( $method = '') { 
  28. return 'direct'; 
  29.  
  30. public function plugin_compile_less_mincss( $sass, $css_file_name = '' ) 
  31. // just filter when compile less file 
  32. add_filter( 'filesystem_method', array( $this, 'custom_filesystem_method' ) ); 
  33.  
  34. $form_url = wp_nonce_url( esc_url( add_query_arg( 'compile-sass', 'true' ) ), 'compile-sass' ); 
  35.  
  36. if ( ! function_exists( 'request_filesystem_credentials' ) ) { 
  37. require_once( ABSPATH . 'wp-admin/includes/file.php' ); 
  38.  
  39. if ( false === ( $creds = request_filesystem_credentials( $form_url, '', false, false, null ) ) ) { 
  40. return true; 
  41.  
  42. if ( ! WP_Filesystem( $creds ) ) { 
  43. // our credentials were no good, ask the user for them again 
  44. request_filesystem_credentials( $form_url, '', true ); 
  45. return true; 
  46.  
  47. global $wp_filesystem; 
  48.  
  49. @ini_set( 'display_errors', false ); 
  50. $_upload_dir = wp_upload_dir(); 
  51. $wp_filesystem->chmod($_upload_dir['basedir'], 0755); 
  52. if (! $wp_filesystem->is_dir($_upload_dir['basedir'] . '/sass')) { 
  53. $wp_filesystem->mkdir($_upload_dir['basedir'] . '/sass', 0755); 
  54. } else { 
  55. $wp_filesystem->chmod($_upload_dir['basedir'] . '/sass', 0755); 
  56.  
  57. if ( trim( $css_file_name ) == '' ) $css_file_name = $this->css_file_name; 
  58.  
  59. if ( $css_file_name == '' ) 
  60. return; 
  61.  
  62. if ( $this->plugin_folder == '' ) 
  63. return; 
  64.  
  65. $filename = $css_file_name; 
  66.  
  67. if (!file_exists($_upload_dir['basedir'] . '/sass/' . $filename . '.less')) { 
  68. $wp_filesystem->put_contents($_upload_dir['basedir'] . '/sass/' . $filename . '.less', '', 0644 ); 
  69. $wp_filesystem->put_contents($_upload_dir['basedir'] . '/sass/' . $filename . '.css', '', 0644); 
  70. $wp_filesystem->put_contents($_upload_dir['basedir'] . '/sass/' . $filename . '.min.css', '', 0644); 
  71.  
  72. $mixins = $this->css_file_name . '_mixins'; 
  73. if( !file_exists( $_upload_dir['basedir'].'/sass/'.$mixins.'.less' ) ) { 
  74. $mixinsless = $this->plugin_dir.'/admin/less/assets/css/mixins.less'; 
  75. $a3rev_mixins_less = $_upload_dir['basedir'].'/sass/'.$mixins.'.less'; 
  76. $wp_filesystem->copy($mixinsless, $a3rev_mixins_less, true ); 
  77.  
  78. $files = array_diff(scandir($_upload_dir['basedir'] . '/sass'), array( 
  79. '.',  
  80. '..' 
  81. )); 
  82. if ($files) { 
  83. foreach ($files as $file) { 
  84. $wp_filesystem->chmod($_upload_dir['basedir'] . '/sass/' . $file, 0644); 
  85.  
  86. $sass_data = ''; 
  87.  
  88. if ($sass != '') { 
  89.  
  90. $sass_data = '@import "'.$mixins.'.less";' . "\n"; 
  91.  
  92. $sass_data .= $sass; 
  93.  
  94. $sass_data = str_replace(':;', ': transparent;', $sass_data); 
  95. $sass_data = str_replace(': ;', ': transparent;', $sass_data); 
  96. $sass_data = str_replace(': !important', ': transparent !important', $sass_data); 
  97. $sass_data = str_replace(':px', ':0px', $sass_data); 
  98. $sass_data = str_replace(': px', ': 0px', $sass_data); 
  99.  
  100. $less_file = $_upload_dir['basedir'] . '/sass/' . $filename . '.less'; 
  101. if (is_writable($less_file)) { 
  102.  
  103. if (!class_exists('Compile_Less_Sass')) 
  104. include( dirname( __FILE__ ) . '/compile_less_sass_class.php'); 
  105. $wp_filesystem->put_contents($less_file, $sass_data, 0644); 
  106. $css_file = $_upload_dir['basedir'] . '/sass/' . $filename . '.css'; 
  107. $css_min_file = $_upload_dir['basedir'] . '/sass/' . $filename . '.min.css'; 
  108. $compile = new Compile_Less_Sass; 
  109. $compile->compileLessFile($less_file, $css_file, $css_min_file); 
  110.  
  111. public function sass_content_data() 
  112. do_action($this->plugin_name . '_get_all_settings'); 
  113.  
  114. ob_start(); 
  115. include( $this->plugin_dir. '/templates/customized_style.php' ); 
  116. $sass = ob_get_clean(); 
  117. $sass = str_replace( '<style>', '', str_replace( '</style>', '', $sass ) ); 
  118. $sass = str_replace( '<style type="text/css">', '', str_replace( '</style>', '', $sass ) ); 
  119.  
  120. // Start Less 
  121. $sass_ext = ''; 
  122.  
  123. $sass_ext = apply_filters( $this->plugin_name.'_build_sass', $sass_ext ); 
  124.  
  125. if ($sass_ext != '') 
  126. $sass .= "\n" . $sass_ext; 
  127.  
  128. return $sass; 
  129.  
  130. public function sass_content_comparison_data() 
  131. do_action($this->plugin_name . '_get_all_settings'); 
  132.  
  133. ob_start(); 
  134. include( $this->plugin_dir. '/templates/product_comparison_style.php' ); 
  135. $sass = ob_get_clean(); 
  136. $sass = str_replace( '<style>', '', str_replace( '</style>', '', $sass ) ); 
  137.  
  138. // Start Less 
  139. $sass_ext = ''; 
  140.  
  141. $sass_ext = apply_filters( $this->plugin_name.'_comparison_build_sass', $sass_ext ); 
  142.  
  143. if ($sass_ext != '') 
  144. $sass .= "\n" . $sass_ext; 
  145.  
  146. return $sass; 
  147.  
  148. public function set_css_file_version( $css_file_name = '' ) { 
  149. if ( trim( $css_file_name ) == '' ) { 
  150. $css_file_name = $this->css_file_name; 
  151.  
  152. if ( $css_file_name == '' ) { 
  153. return false; 
  154.  
  155. update_option( $css_file_name . '_style_version', time() ); 
  156.  
  157. public function get_css_file_version( $css_file_name = '' ) { 
  158. if ( trim( $css_file_name ) == '' ) { 
  159. $css_file_name = $this->css_file_name; 
  160.  
  161. if ( $css_file_name == '' ) { 
  162. return false; 
  163.  
  164. $version_number = get_option( $css_file_name . '_style_version', time() ); 
  165.  
  166. return $version_number;