balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class.pb_build_css.php (4456B)


      1 <?php
      2 namespace CVEC\classes\vc;
      3 
      4 defined( 'ABSPATH' ) || die();
      5 
      6 class pb_build_css {
      7 
      8 	public static $targetdircss        = '/cache/css/';
      9 	public static $targetdirurlcss     = '/cache/css/';
     10 	public static $defaultcssname      = 'default.min.css';
     11 	public static $defaultcsspath      = CVEC_DIR_PATH . 'assets/css/';
     12 	public static $defaultcssURL       = CVEC_DIR_URL. 'assets/css/';
     13 	public static $filename            = '';
     14 	public static $filename_custom_css = '';
     15 	public static function init() {
     16 		$upload_dir            = wp_upload_dir();
     17 		self::$targetdircss    = apply_filters( 'combine_vc_ele_css_pb_build_css_target_css_path', $upload_dir['basedir'] . self::$targetdircss );
     18 		self::$defaultcssname  = apply_filters( 'combine_vc_ele_css_pb_build_css_assets_css_default_name', self::$defaultcssname );
     19 		self::$defaultcsspath  = apply_filters( 'combine_vc_ele_css_pb_build_css_assets_css_path', self::$defaultcsspath );
     20 		self::$defaultcssURL  = apply_filters( 'combine_vc_ele_css_pb_build_css_assets_css_url', self::$defaultcssURL );
     21 
     22 		self::$targetdirurlcss = apply_filters( 'combine_vc_ele_css_pb_build_css_target_css_url', $upload_dir['baseurl'] . self::$targetdirurlcss );
     23 	}
     24 
     25 	public static function pb_build_css_assets_css( $post_id ) {
     26 
     27 		self::$filename            = self::$targetdircss . "cvec_post_{$post_id}.css";
     28 		self::$filename_custom_css = self::$targetdircss . "css_editor_{$post_id}.css";
     29 		self::pb_build_css_remove_css();
     30 		$array = get_post_meta( $post_id, CVEC_OPTION_NAME, true );
     31 		$data  = '';
     32 		if ( file_exists( self::$defaultcsspath . self::$defaultcssname ) ) {
     33 			$data .= file_get_contents( self::$defaultcsspath . self::$defaultcssname );
     34 		}
     35 		if ( ! empty( $array ) ) {
     36 			$array=array_column($array, 'css');
     37 			$array = array_map("unserialize", array_unique(array_map("serialize", $array)));
     38 			foreach ( $array as $sccss ) {
     39 				foreach ( $sccss as $css ) {
     40 
     41 					if ( file_exists( self::$defaultcsspath . "{$css}.min.css" ) ) {
     42 
     43 						$data .= file_get_contents( self::$defaultcsspath . "{$css}.min.css" );
     44 					}
     45 				}
     46 			}
     47 			if ( ! is_dir( self::$targetdircss ) ) {
     48 				@mkdir( self::$targetdircss, 0777, true );
     49 			}
     50 
     51 			if ( $data != '' ) {
     52 				file_put_contents( self::$filename, $data );
     53 			}
     54 		}
     55 
     56 	}
     57 
     58 	public static function pb_get_css_assets_css() {
     59 		global $post;
     60 		if ( ! isset( $post ) || empty( $post ) ) {
     61 			return;
     62 		}
     63 		// $array = get_post_meta($post->ID, CVEC_OPTION_NAME, true);
     64 		self::$filename            = self::$targetdircss . "cvec_post_{$post->ID}.css";
     65 		self::$filename_custom_css = self::$targetdircss . "css_editor_{$post->ID}.css";
     66 		// if (!file_exists(self::$filename)) {
     67 		// self::pb_build_css_assets_css($post->ID);
     68 		// }
     69 		$array = array();
     70 		if ( file_exists( self::$filename ) ) {
     71 			$path_parts                  = pathinfo( self::$filename );
     72 			$array['return_url']         = self::$targetdirurlcss . $path_parts['basename'];
     73 			$array['return_url_version'] = VERSION . '.' . get_post_modified_time( 'U', false, $post );
     74 		}
     75 		if ( file_exists( self::$filename_custom_css ) ) {
     76 			$path_parts                         = pathinfo( self::$filename_custom_css );
     77 			$array['return_url_custom']         = self::$targetdirurlcss . $path_parts['basename'];
     78 			$array['return_url_custom_version'] = VERSION . '.' . get_post_modified_time( 'U', false, $post );
     79 		}
     80 		return $array;
     81 	}
     82 
     83 
     84 	public static function pb_get_css_assets_css_for_editor_mode($array) {
     85 		global $post;
     86 		if ( ! isset( $post ) || empty( $post ) ) {
     87 			return;
     88 		}
     89 		$array=array_column($array, 'css');
     90 		$array = array_map("unserialize", array_unique(array_map("serialize", $array)));
     91 		foreach ( $array as $sccss ) {
     92 			foreach ( $sccss as $css ) {
     93 
     94 				if ( file_exists( self::$defaultcsspath . "{$css}.min.css" ) ) {
     95 					wp_enqueue_style( 'combine-vc-ele-'.$css, self::$defaultcssURL . "{$css}.min.css", null, VERSION . '.' . get_post_modified_time( 'U', false, $post ) );
     96 				}
     97 			}
     98 		}
     99 	}
    100 
    101 
    102 	public static function pb_build_css_remove_css( $post_id = '', $remove_custom = false ) {
    103 		if ( $post_id != '' ) {
    104 			self::$filename            = self::$targetdircss . "cvec_post_{$post_id}.css";
    105 			self::$filename_custom_css = self::$targetdircss . "css_editor_{$post_id}.css";
    106 		}
    107 
    108 		if ( file_exists( self::$filename ) ) {
    109 			unlink( self::$filename );
    110 		}
    111 		if ( $remove_custom ) {
    112 			if ( file_exists( self::$filename_custom_css ) ) {
    113 				unlink( self::$filename_custom_css );
    114 			}
    115 		}
    116 	}
    117 
    118 }