Beispiel #1
0
 /**
  * Compress asset files
  */
 function enqueue_compressed_assets()
 {
     if (!empty($_SESSION['wr-pb-assets-frontend'])) {
         global $post;
         if (empty($post)) {
             exit;
         }
         $wr_pb_settings_cache = get_option('wr_pb_settings_cache', 'enable');
         if ($wr_pb_settings_cache != 'enable') {
             exit;
         }
         $contents_of_type = array();
         $this_session = $_SESSION['wr-pb-assets-frontend'][$post->ID];
         // Get content of assets file from shortcode directories
         foreach ($this_session as $type => $list) {
             $contents_of_type[$type] = array();
             foreach ($list as $path => $modified_time) {
                 $fp = @fopen($path, 'r');
                 if ($fp) {
                     $contents_of_type[$type][$path] = fread($fp, filesize($path));
                     fclose($fp);
                 }
             }
         }
         // Write content of css, js to 2 seperate files
         $cache_dir = WR_Pb_Helper_Functions::get_wp_upload_folder('/igcache/pagebuilder');
         foreach ($contents_of_type as $type => $list) {
             $handle_info = $this_session[$type];
             $hash_name = md5(implode(',', array_keys($list)));
             $file_name = "{$hash_name}.{$type}";
             $file_to_write = "{$cache_dir}/{$file_name}";
             // check stored data
             $store = WR_Pb_Helper_Functions::compression_data_store($handle_info, $file_name);
             if ($store[0] == 'exist') {
                 $file_name = $store[1];
                 $file_to_write = "{$cache_dir}/{$file_name}";
             } else {
                 $fp = fopen($file_to_write, 'w');
                 $handle_contents = implode("\n/*------------------------------------------------------------*/\n", $list);
                 fwrite($fp, $handle_contents);
                 fclose($fp);
             }
             // Enqueue script/style to footer of page
             if (file_exists($file_to_write)) {
                 $function = $type == 'css' ? 'wp_enqueue_style' : 'wp_enqueue_script';
                 $function($file_name, WR_Pb_Helper_Functions::get_wp_upload_url('/igcache/pagebuilder') . "/{$file_name}");
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Get uri from dir path
  *
  * @param type $dir
  * @param type $file
  *
  * @return type
  */
 static function get_uri($dir, $file)
 {
     if ($dir == WR_PB_PREMADE_LAYOUT) {
         $uri = WR_PB_PREMADE_LAYOUT_URI;
     } else {
         $path_parts = pathinfo($dir);
         $uri = WR_Pb_Helper_Functions::get_wp_upload_url('/wr-pb-layout/') . $path_parts['basename'];
     }
     return "{$uri}/{$file}";
 }