Changeset 2714583
- Timestamp:
- 04/26/2022 01:18:41 AM (2 years ago)
- Location:
- gowebp/trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
gowebp/trunk/gowebp.php
r2703673 r2714583 1 1 <?php 2 2 /* 3 * Plugin Name: G OWEBP4 * Plugin URI: https:// increaserev.com/admanager/5 * Author: Increase Rev LLC6 * Version: 1.0 7 * Description: Using G OWEBP,You can optimize your website to it's potential by optimizing all images. Optimizing images will drastically improved your site speed as images will load faster.3 * Plugin Name: GP 4 * Plugin URI: https:// 5 * Author: 6 * Version: 1.0 7 * Description: Using GP,You can optimize your website to it's potential by optimizing all images. Optimizing images will drastically improved your site speed as images will load faster. 8 8 */ 9 9 if ( ! defined( 'ABSPATH' ) ) exit; … … 14 14 require_once(dirname(__FILE__).'/gowebp_worker.php'); 15 15 require_once(dirname(__FILE__).'/store.php'); 16 17 18 16 class GoWEBP_IR extends GOWEBP_WORKER{ 19 17 20 18 private static $instance; 21 22 19 private function __construct(){ 23 // global $store;24 20 add_action('init', [$this, 'gowebp_admin_init'],0); 25 21 add_action( 'admin_enqueue_scripts', [$this, 'ir_mngr_add_style_and_script'] ); … … 27 23 add_action('activated_plugin', [$this, 'ir_webp_start']); 28 24 if($this->ir_check_active()){ 25 29 26 add_action("publish_post",[$this, "ir_after_publish"]); 30 27 add_action("publish_page",[$this, "ir_after_publish"]); … … 54 51 }); 55 52 }else{ 56 wp_enqueue_style('trial_style',plugin_dir_url( __FILE__) ."lib/css/trial.css", array(), time()); 57 wp_enqueue_style('buttons_style',plugin_dir_url( __FILE__) ."lib/css/buttons.css", array(), time()); 58 wp_enqueue_style('setting_style',plugin_dir_url( __FILE__) ."lib/css/setting_style.css", array(), time()); 59 wp_enqueue_style('form_style',plugin_dir_url( __FILE__) ."lib/css/form.css", array(), time()); 60 61 wp_enqueue_style( 'myboot', plugin_dir_url( __FILE__) .'lib/css/myboot.bootstrap.min.css' ); 62 wp_enqueue_script( 'myboot-script', plugin_dir_url( __FILE__) .'lib/js/myboot.bootstrap.bundle.min.js', array(), null, true ); 63 wp_enqueue_script( "swal",plugin_dir_url( __FILE__) ."lib/js/swal.js", ["jquery"], null, true); 64 wp_enqueue_script( "knobs",plugin_dir_url( __FILE__) ."lib/js/jquery.knob.min.js", ["jquery"], null, true); 65 wp_enqueue_style( 'load-fa', plugin_dir_url( __FILE__) .'lib/css/fontawesome.css'); 66 wp_enqueue_style( 'google-fonts', plugin_dir_url( __FILE__) .'lib/css/fonts.css'); 53 54 if (isset($_GET['page']) && ($_GET['page'] == 'go-webp/gowebp_option2.php')) { 55 wp_enqueue_style('trial_style',plugin_dir_url( __FILE__) ."lib/css/trial.css", array(), time()); 56 wp_enqueue_style('buttons_style',plugin_dir_url( __FILE__) ."lib/css/buttons.css", array(), time()); 57 wp_enqueue_style('setting_style',plugin_dir_url( __FILE__) ."lib/css/setting_style.css", array(), time()); 58 wp_enqueue_style('form_style',plugin_dir_url( __FILE__) ."lib/css/form.css", array(), time()); 59 60 wp_enqueue_style( 'myboot', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css' ); 61 wp_enqueue_script( 'myboot-script', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/js/bootstrap.bundle.min.js', array(), null, true ); 62 wp_enqueue_script( "swal","//cdn.jsdelivr.net/npm/sweetalert2@11", ["jquery"], null, true); 63 wp_enqueue_script( "knobs","https://cdnjs.cloudflare.com/ajax/libs/jQuery-Knob/1.2.13/jquery.knob.min.js", ["jquery"], null, true); 64 wp_enqueue_style( 'load-fa', 'https://use.fontawesome.com/releases/v5.5.0/css/all.css'); 65 wp_enqueue_style( 'google-fonts', 'https://fonts.googleapis.com/css2?family=Raleway&display=swap'); 66 } 67 67 68 68 69 } … … 78 79 79 80 function gowebp_admin_init(){ 81 80 82 if(is_admin()){ 81 83 $GLOBALS['progressbar_show']="hide"; 82 84 // For Checking and updating status from server (once per day) 83 85 $this->ir_check_once(); 84 85 86 wp_enqueue_script( "jquery-form" ); 86 87 87 // On settings page 88 88 if($this->ir_check_optStarted() && check_theme_switched() && $this->ir_check_theme_img_status()){ … … 93 93 $this->ir_optimize_theme_images(); 94 94 } 95 96 }else{95 96 97 97 if($this->ir_check_active()){ 98 98 add_filter("the_content",[$this, "ir_add_lazyload"]); 99 99 add_filter("post_thumbnail_html",[$this, "ir_add_lazyload_thumbnail"]); 100 100 101 add_action('wp_footer', [$this, "ir_compiler_funcs"],10000000000); 101 102 if($this->ir_check_optStarted()){ 103 102 104 add_filter('wp_calculate_image_srcset',[$this, 'ir_update_post_images_url']); 103 105 add_filter( 'wp_get_attachment_image_src',[$this, 'ir_update_featured_images_url'], 10, 4); 106 107 108 104 109 } 105 110 } 111 106 112 } 107 113 } 108 114 } 109 115 116 110 117 $gowebp_ir = GoWEBP_IR::getInstance(); 111 118 remove_action('shutdown','wp_ob_end_flush_all',1); -
gowebp/trunk/gowebp_option2.php
r2703673 r2714583 2 2 if ( ! defined( 'ABSPATH' ) ) exit; 3 3 4 4 5 if(!$gowebp_ir->ir_check_server() && $gowebp_ir->ir_check_active()){ 5 6 … … 62 63 $desktop_dimension = isset($ir_form_data["ir_desktop_dimension"][0]) ? 100-(int)$ir_form_data["ir_desktop_dimension"][0] : 25; 63 64 $desktop_dimension = isset($ir_form_data["ir_desktop_dimension"][0])? 100-(int)$ir_form_data["ir_desktop_dimension"][0] : 25; 64 $tablet_dimension = isset($ir_form_data["ir_tablet_dimension"][0]) ? 100-(int)$ir_form_data["ir_tablet_dimension"][0] : 50;65 $mobile_dimension = isset($ir_form_data["ir_mobile_dimension"][0]) ? 100-(int)$ir_form_data["ir_mobile_dimension"][0] : 65;65 $tablet_dimension = isset($ir_form_data["ir_tablet_dimension"][0]) ? 100-(int)$ir_form_data["ir_tablet_dimension"][0] : ; 66 $mobile_dimension = isset($ir_form_data["ir_mobile_dimension"][0]) ? 100-(int)$ir_form_data["ir_mobile_dimension"][0] : ; 66 67 $thumbnail_dimension = isset($ir_form_data["ir_thumbnail_dimension"][0]) ? 100-(int)$ir_form_data["ir_thumbnail_dimension"][0] : 80; 67 68 … … 243 244 } 244 245 .circlePercent > .counter { 245 246 246 position: absolute; 247 247 box-sizing: border-box; … … 252 252 margin-left: -1px; 253 253 border-radius: 50%; 254 254 255 border: 4px solid #e2e1e1; 255 256 … … 292 293 --progress-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2) inset; 293 294 --progress-flll-shadow: var(--progress-shadow); 295 294 296 --fill-color: linear-gradient(to right,#fffc00 -15%, #00d119 60%,orange 66%, red 95%); 295 297 --thumb-shadow: 0 0 4px rgba(0, 0, 0, 0.3), … … 609 611 .btn-submit:hover{ 610 612 color: #fff !important; 611 /*background: var(--ir-green) !important;*/612 613 background: green !important; 613 614 box-shadow: 1px 1px 5px rgba(0,0,0,0.5); … … 615 616 } 616 617 .btn-submit:focus{ 617 /*border:3px solid #7a0099;*/618 618 box-shadow: 1px 1px 7px rgba(122, 0, 153, 0.5) 619 619 … … 621 621 622 622 .fa-info-circle{ 623 /*color: var(--ir-pink);*/624 623 color: rgba(0,0,0,0.4); 625 624 opacity:0.5; … … 772 771 } 773 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 774 832 </style> 775 833 <div class="wrap" id="ir_blur"> … … 781 839 <!-- Registration Form Start --> 782 840 <div style="<?=$display?>" class="reg_form_div"> 841 783 842 <form id="reg_form"> 784 843 <input type="hidden" name="action" value="ir_submit" > … … 795 854 </div> 796 855 <div class="input-field get_key_div"> 797 <a href="https://gowebp.com/ #pricing?domain=<?=$domain ?>" target="_blank" class="btn btn-key get_key_link" >856 <a href="https://gowebp.com/domain=<?=$domain ?>" target="_blank" class="btn btn-key get_key_link" > 798 857 <strong> Get Key </strong> 799 858 </a> … … 807 866 <section class="ftco-section"> 808 867 <div class="container"> 868 809 869 <div class="row <?php if(!$status){ ?> justify-content-center <?php } ?>"> 810 870 <div class="col-md-12"> … … 842 902 <div class="d-flex align-items-center py-2"> 843 903 <h5 style="padding-right:40px;font-size:18px;">Opt lvl</h5> 844 845 904 <div id="rangePath" class="range-slider grad" style='--min:0; --max:10000; --step:100; --value:<?=$ir_optimize_level*100?>; --text-value:"200"; --prefix:"$"; width:260px;'> 846 905 <input name="rangeValOpt" id="rangeValOpt" value="<?=$ir_optimize_level*100?>" type="range" min="0" max="10000" step="500" oninput="this.parentNode.style.setProperty('--value',this.value); this.parentNode.style.setProperty('--text-value', JSON.stringify((+this.value).toLocaleString()))"> … … 871 930 <span class="gowebp-slider round"></span> 872 931 </label> 873 <!-- <span class="text-muted">( Viewport is enabled ! )</span> -->874 932 <span data-toggle="tooltip" data-placement="top" title="Progressive load requests low resolution images at initial i.e: 50x50 then it loads images as per screen size." class="rounded-circle border-0 text-dark t-1 p-2" style="cursor:pointer; "> <i class="fas fa-info-circle" style="font-size:20px;"></i></span> 875 933 <span class="amp_support" ><?=$amp_msg?></span> … … 1005 1063 <input type="number" step="0.1" value="<?=$shadow_opacity ?>" class='mw-75' name="shadow_opacity" min="0" max="1" > 1006 1064 </td> 1007 <!-- <td></td> -->1008 1065 </tr> 1009 1066 <tr class="subShadow mt-2"> … … 1057 1114 <td style="color:darkblue"> %</td> 1058 1115 </tr> 1059 1060 1116 </table> 1061 1117 <label for="basic-url" class="text-dark form-label mt-4">Additional/Custom path for images</label> … … 1081 1137 <div class='col-md-8 d-flex'> 1082 1138 <button type="button" style="font-size:20px;box-shadow: 0 4px 2px -2px gray;" id="optimizationFormSubmit" class="btn btn-submit px-3" > <strong> Save & Optimize </strong></button> 1083 <!-- Loader Start -->1084 1139 <div style="position:relative; margin-top:6px; margin-left:10px;"> 1085 <div id="loader" style="display:none" class="circlePercent"> 1086 <div class="counter" data-percent="0"></div> 1087 <div class="progress"></div> 1088 <div class="progressEnd"></div> 1089 </div> 1140 1141 <div class="lds-ellipsis" id="myloader1"><div></div><div></div><div></div><div></div></div> 1090 1142 </div> 1091 1143 </div> … … 1102 1154 <h3>Status</h3> 1103 1155 <div class="ir_section_divider"></div> 1104 1105 1156 <div> 1106 1157 <label class="ir_total"> … … 1125 1176 <div style="left:-20px" class="dot-flashing mt-2 d-inline-block img-count-loader"></div> 1126 1177 </div> 1127 1128 1178 <div> 1129 1179 <label class="ir_total"> … … 1145 1195 <div class="ir_section_divider" ></div> 1146 1196 </div> 1147 1148 1197 <div id="previewImage" class="w-100 img" > 1149 1198 </div> … … 1217 1266 jQuery(document).ready(function($){ 1218 1267 1219 let optimize_started = <?=$optimize_started?>; 1220 let optimization_status = <?=$optimize_progress?>; 1268 // let optimize_started = <?=$optimize_started?>; 1269 // let optimization_status = <?=$optimize_progress?>; 1270 let optimize_started = 1; 1271 let optimization_status =1; 1221 1272 if(optimize_started==1) { 1222 1273 $('#optimizationFormSubmit').prop('disabled', true); … … 1224 1275 if(optimization_status==1){ 1225 1276 $("#loader").css("display","block"); 1226 startOptimizationLoader ();1277 startOptimizationLoader(); 1227 1278 // Don't run this function below 1228 1229 } 1230 1231 1279 // handleError(); 1280 1281 1282 1232 1283 // Fade in error messages/For paid version msg 1233 1284 $('.err_trigger_class').click(function(){ … … 1425 1476 let before_img_size = 0; 1426 1477 let img_size_unit = "mb"; 1427 // let pre_status = '<?=$ir_premi_status ?>';1428 irGetImgStats();1429 1430 1478 // Image Shadow 1431 1479 if($("input[name=ir_image_shadow]").is(":checked")){ … … 1484 1532 let a = $("input[name=ir_progload_status]").is(":checked"); 1485 1533 1486 1487 1534 // Before Optimization Image Size End 1488 1535 … … 1503 1550 }, 800); 1504 1551 // change here 1505 // $("#viewport_id").click();1506 1552 $("input[name=ir_viewport_status]").prop("checked",true); 1507 1553 } 1508 // else{1509 // $("#viewport_id").click();1510 // }1511 1554 }); 1512 1555 // Progressive Load Toggle End … … 1563 1606 // Place upload progress bar visibility code here 1564 1607 $(".ir_progress_loader").fadeIn(); 1565 // $("#ir_progress_bar").animate({"width":percentComplete+"%"},{duration:1000});1566 1608 $("#ir_progress_bar").animate({"width":"50%"},{duration:1000}); 1567 1609 } … … 1630 1672 $("#loader").fadeIn(); 1631 1673 1632 setTimeout(startOptimizationLoader, 1000);1674 ); 1633 1675 }, 1634 1676 success:function(response){ 1635 1677 $("#loader").fadeOut(); 1636 // $("#loaderOpt").toggleClass("d-none");1637 1678 if(response == "Limit Reached"){ 1638 1679 Swal.fire({ … … 1657 1698 1658 1699 $('#optimizationFormSubmit').prop('disabled', false); 1659 // optimize_started = 0;1700 ; 1660 1701 }, 1661 1702 error: function(request, status, err){ 1662 1703 handleError(); 1663 // $('#optimizationFormSubmit').prop('disabled', false);1664 1704 1665 1705 } … … 1818 1858 } 1819 1859 else{ 1820 // window.location = response;1821 1860 window.location.reload(); 1822 1861 } … … 2036 2075 loader.hide(); 2037 2076 jQuery("#loadCustomPath").show(); 2038 irGetImgStats();2077 irGetImgStats(); 2039 2078 }, 2040 2079 error: function(data){ … … 2070 2109 data: {action:"del_custom_paths", path}, 2071 2110 success: function(data){ 2072 2073 2111 }, 2074 2112 error: function(data){ … … 2105 2143 2106 2144 } 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2107 2194 2108 2195 </script> 2109 2196 <script src="<?=plugin_dir_url( __FILE__ )."lib/js/option.js" ?>"></script> 2197 2198 2199 2200 2201 2202 2203 2204 2205 2110 2206 2111 2207 <?php … … 2113 2209 <div class="wrap" id="notfound"> 2114 2210 <div class="notfound"> 2115 2211 <!-- <div class="notfound-404"> 2212 <h1></h1> 2213 </div> --> 2116 2214 <div style="position:relative;top:-50px"> 2117 2215 <img width=400px src="<?=plugin_dir_url( __FILE__ )."/lib/img/gowebp-logo.png" ?>" alt=""> … … 2125 2223 <?php 2126 2224 }else{ 2127 2225 $domain = sanitize_text_field( $_SERVER["HTTP_HOST"] ); 2128 2226 $domain = str_replace(['http://','https://','www.'],'',$domain); 2129 2227 ?> … … 2139 2237 </div> 2140 2238 <?php } ?> 2239 -
gowebp/trunk/gowebp_worker.php
r2703673 r2714583 82 82 $ext = pathinfo($img_name, PATHINFO_EXTENSION); 83 83 if($ext == "gif") continue; 84 85 86 87 84 $suffix = "lg"; 88 85 [$is_mobile, $is_tablet] = $this->ir_is_mobile_tablet(); … … 96 93 if($ir_progload_status == true){ 97 94 $img_name2 = str_replace("-holder","_".$suffix,$old_source2); 98 99 $i->setAttribute("src",""); 95 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/emptyloader.png"); 100 96 $i->setAttribute("srcset",""); 101 97 $i->setAttribute("data-original",$old_source2); … … 104 100 } 105 101 elseif($ir_viewport_status == true){ 106 107 108 $i->setAttribute("src",""); 102 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/emptyloader.png"); 109 103 $i->setAttribute("srcset",""); 110 104 $i->setAttribute("data-original",$old_source2); 111 105 } 112 113 114 106 // Changes for Post Images 115 107 if($shadow_on_post==true ){ … … 161 153 $old_source = $i->getAttribute("src"); 162 154 $img_name = $old_source; 163 164 155 $index = $this->ir_getExtIndex($img_name); 165 156 … … 171 162 }elseif($is_tablet){ 172 163 $suffix = "md"; 173 } 174 164 }else{ 165 $suffix = "lg"; 166 } 167 // $suffix = "sm"; 175 168 if($ir_progload_status == true){ 176 169 $img_name2 = str_replace("-holder","_".$suffix,$img_name); 177 178 $i->setAttribute("src",""); 170 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/emptyloader.png"); 179 171 $i->setAttribute("srcset",""); 180 172 $i->setAttribute("data-original",$old_source); … … 182 174 if($this->ir_check_exists($img_name2)) 183 175 $i->setAttribute("data-responsive",$img_name2); 184 // $i->setAttribute("data-responsive",$new_src2);185 186 176 } 187 177 188 178 elseif($ir_viewport_status == true){ 189 190 $i->setAttribute("src",""); 179 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/emptyloader.png"); 191 180 $i->setAttribute("srcset",""); 192 // $i->setAttribute("data-original",$new_src);193 181 $i->setAttribute("data-original",$old_source); 194 195 182 } 196 183 else{ 197 198 184 $i->setAttribute("src",$old_source); 199 185 $i->setAttribute("srcset",$old_source); 200 201 186 } 202 187 … … 220 205 221 206 } 222 223 207 $newHtml = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML())); 224 208 return $newHtml; 225 209 } 226 210 227 228 211 function ir_check_exists($url, $gowebp=true){ 229 212 $server = $gowebp==true ?wp_upload_dir()["basedir"]."/_gowebp_/" : wp_upload_dir()["path"] ; … … 270 253 if($total>0){ 271 254 $counter = 0; 255 272 256 foreach($ir_images as $image){ 257 258 273 259 $id = $image["id"]; 274 260 $image = $image["url"]; … … 276 262 $filename = substr($image,strrpos($image,"/")+1); 277 263 if($this->ir_is_image($filename)){ 278 if(file_exists($image)){ 264 if(file_exists($image)){ 265 266 if($counter>=1000 && !$this->ir_check_feature_pre()){ 267 $this->gowebp_clear_cache(); 268 }else{ 279 269 $this->ir_compressor($path,$filename); 280 270 $this->ir_update_url_array($id,$img_to_webp_ir,$ir_optimize_level); 281 271 $counter++; 282 272 update_user_meta(1,"ir_done_opt_prog",$counter); 273 283 274 } 284 275 } … … 319 310 $ir_exif_status = $ir_exif_status == 1 ? true : false; 320 311 321 // $ir_optimize_level = $ir_form_data["ir_optimize_level"][0] == "" ? 65 : $ir_form_data["ir_optimize_level"][0];322 312 $ir_optimize_level = isset($ir_form_data["ir_optimize_level"][0]) ? $ir_form_data["ir_optimize_level"][0] : 35; 323 313 $ir_optimize_level = (int) $ir_optimize_level; 324 // $ir_to_webp = $ir_form_data["ir_to_webp"][0] == 0 ? false : true;325 314 $ir_to_webp = $ir_form_data["ir_to_webp"][0] ?? 1; 326 315 $ir_to_webp = $ir_to_webp==1 ? true: false; … … 353 342 } 354 343 355 $response1 = wp_remote_get( $from ); 356 $body1 = wp_remote_retrieve_body( $response1 ); 357 $response2 = wp_remote_get( $to ); 358 $body2 = wp_remote_retrieve_body( $response2 ); 359 $data = new PelDataWindow($body1); 360 $data2 = new PelDataWindow($body2); 344 $data = new PelDataWindow(file_get_contents($from)); 345 $data2 = new PelDataWindow(file_get_contents($to)); 361 346 $tiff = null; 362 347 $file = null; … … 444 429 445 430 $ir_form_data = get_user_meta(1); 446 $desktop_dimension = $ir_form_data["ir_desktop_dimension"][0] ?? 85;447 $tablet_dimension = $ir_form_data["ir_tablet_dimension"][0] ?? 50;448 $mobile_dimension = $ir_form_data["ir_mobile_dimension"][0] ?? 35;431 $desktop_dimension = $ir_form_data["ir_desktop_dimension"][0] ?? 5; 432 $tablet_dimension = $ir_form_data["ir_tablet_dimension"][0] ?? ; 433 $mobile_dimension = $ir_form_data["ir_mobile_dimension"][0] ?? ; 449 434 $thumbnail_dimension = $ir_form_data["ir_thumbnail_dimension"][0] ?? 20; 450 435 … … 463 448 imagejpeg($img_resized, $destination, $ir_optimize_level); 464 449 // For Different Screen Size 465 imagejpeg($img_resized_lg, $lg_destination, $ir_optimize_level);466 imagejpeg($img_resized_md, $md_destination, $ir_optimize_level);467 imagejpeg($img_resized_sm, $sm_destination, $ir_optimize_level);468 imagejpeg($img_resized_xs, $xs_destination, $ir_optimize_level);450 imagejpeg($img_resized_lg, $lg_destination, $ir_optimize_level); 451 imagejpeg($img_resized_md, $md_destination, $ir_optimize_level); 452 imagejpeg($img_resized_sm, $sm_destination, $ir_optimize_level); 453 imagejpeg($img_resized_xs, $xs_destination, $ir_optimize_level); 469 454 470 455 } 471 456 elseif ($info['mime'] == 'image/png') { 472 457 if($image){ 473 474 458 $arr1 = [ 475 459 $img_resized, … … 488 472 // foreach($arr as $key => $value){ 489 473 for($i=0; $i<sizeof($arr1); $i++){ 490 $width = imagesx($arr1[$i]);491 $height = imagesy($arr1[$i]);492 $new_image = imagecreatetruecolor($width,$height);493 imagealphablending($new_image,false);494 imagesavealpha($new_image,true);495 imagecopyresampled($new_image,$arr1[$i],0,0,0,0,$width, $height, $width, $height);496 imagepng($new_image, $arr2[$i], floor($ir_optimize_level/10.0));474 $width = imagesx($arr1[$i]); 475 $height = imagesy($arr1[$i]); 476 $new_image = imagecreatetruecolor($width,$height); 477 imagealphablending($new_image,false); 478 imagesavealpha($new_image,true); 479 imagecopyresampled($new_image,$arr1[$i],0,0,0,0,$width, $height, $width, $height); 480 imagepng($new_image, $arr2[$i], floor($ir_optimize_level/10.0)); 497 481 498 482 } … … 734 718 735 719 function ir_is_mobile_tablet() { 736 include_once ( plugin_dir_path(__FILE__) . '/Mobile_Detect.php'); 737 $detect = new Mobile_Detect; 738 if( $detect->isTablet() ) { 739 return [false,true]; 740 } elseif($detect->isMobile()) { 720 // include_once ( plugin_dir_path(__FILE__) . '/Mobile_Detect.php'); 721 // $detect = new Mobile_Detect; 722 // if( $detect->isTablet() ) { 723 // return [false,true]; 724 // } elseif($detect->isMobile()) { 725 // return [true,false]; 726 // }else { 727 // return [false,false]; 728 // } 729 if( wp_is_mobile() ) { 741 730 return [true,false]; 742 731 }else { … … 804 793 if($this->ir_is_image($filename)){ 805 794 $this->ir_insert_single_image_url($path.date("Y/m")."/".$filename ); 795 806 796 } 807 797 return $override; … … 816 806 817 807 function ir_save_cropped_image($context, $attachment_id, $file_path){ 808 818 809 $this->ir_insert_single_image_url($file_path); 819 810 $this->ir_doOptimize(); … … 821 812 822 813 function ir_compiler_funcs(){ 814 823 815 $this->remove_all_scripts_ir(); 824 816 $this->load_compress_img_ir(); 817 825 818 826 819 } … … 851 844 { 852 845 853 854 855 846 if(strpos($source['url'],substr($path,1)) == false){ 856 847 continue; … … 865 856 { 866 857 $img_name = substr($source['url'],strrpos($source['url'],"/")+1); 867 868 869 870 858 $ext = pathinfo($img_name, PATHINFO_EXTENSION); 871 859 $regex = "/-\d\d\dx\d\d\d\.(jpg|jpeg|png|gif|webp|bmp)$/"; … … 896 884 } 897 885 // Change url if it exists // fallback 886 898 887 if($this->ir_check_exists($path."/_gowebp_/".$img_name)) $source['url'] = $path."/_gowebp_/".$img_name; 899 888 } … … 931 920 // Testing 932 921 $path2 = wp_upload_dir()["basedir"]; 933 934 922 $ir_form_data = get_user_meta(1); 935 923 $img_to_webp_ir = $ir_form_data["ir_to_webp"][0] ?? 1 ; … … 996 984 $ir_optimize_status = $ir_form_data["ir_start_optimization"][0] ?? 0; 997 985 $ir_optimize_status = $ir_optimize_status == 1 ? true : false; 998 999 986 $img_to_webp_ir = $ir_form_data["ir_to_webp"][0] ?? 1; 1000 987 $img_to_webp_ir = $img_to_webp_ir == 1 ? true: false ; … … 1042 1029 var img = document.getElementsByTagName("img"); 1043 1030 1044 let ir_optimize_status = "<?php echo esc_js($ir_optimize_status);?>";1045 let ir_to_webp = '<?php echo esc_js($img_to_webp_ir);?>';1046 let border_status = "<?php echo esc_js($ir_border_status);?>";1047 let shadow_status = "<?php echo esc_js($ir_shadow_status);?>";1048 let progload_status = "<?php echo esc_js($ir_progload_status);?>";1049 let viewport_status = "<?php echo esc_js($ir_viewport_status);?>";1031 let ir_optimize_status = "<?php echo ?>"; 1032 let ir_to_webp = '<?php echo ?>'; 1033 let border_status = "<?php echo ?>"; 1034 let shadow_status = "<?php echo ?>"; 1035 let progload_status = "<?php echo ?>"; 1036 let viewport_status = "<?php echo ?>"; 1050 1037 let screen_size = window.innerWidth; 1051 let avatar_url = "<?php echo esc_js(get_avatar_url(1));?>";1052 let ir_path = "<?php echo esc_js(wp_upload_dir()["baseurl"]);?>";1038 let avatar_url = "<?php echo ?>"; 1039 let ir_path = "<?php echo ?>"; 1053 1040 for(i of img){ 1054 1041 let source = i.src; … … 1086 1073 index = source.indexOf(".bmp"); 1087 1074 } 1088 i.style.height = i.getAttribute("height")+"px"; 1089 1090 1091 let border_size = "<?php echo esc_js($border_size); ?>"; 1092 let border_color = "<?php echo esc_js($border_color); ?>"; 1093 let border_radius = "<?php echo esc_js($border_radius); ?>"; 1075 let border_size = "<?php echo $border_size ?>"; 1076 let border_color = "<?php echo $border_color ?>"; 1077 let border_radius = "<?php echo $border_radius ?>"; 1094 1078 if(border_status == "1" && i.hasAttribute("gowebp-border") ){ 1095 1079 i.style.border = `${border_size}px solid`; … … 1098 1082 } 1099 1083 1100 let shadow_size = "<?php echo esc_js($shadow_size);?>";1101 let shadow_color = convertToRGB("<?php echo esc_js($shadow_color);?>");1102 let shadow_opacity = "<?php echo esc_js($shadow_opacity);?>";1084 let shadow_size = "<?php echo ?>"; 1085 let shadow_color = convertToRGB("<?php echo ?>"); 1086 let shadow_opacity = "<?php echo ?>"; 1103 1087 if(shadow_status=="1" && i.hasAttribute("gowebp-shadow")){ 1104 1088 if(shadow_opacity>1){ … … 1143 1127 image.setAttribute("src",image.getAttribute("data-responsive")); 1144 1128 src = image.getAttribute("data-responsive"); 1129 1145 1130 if(src!=null) image.setAttribute("srcset",src); 1146 1131 if(src!=null) image.setAttribute("src",src); 1147 1132 image.onload = ()=>{ 1133 1148 1134 image.removeAttribute("data-responsive"); 1149 1135 … … 1172 1158 let source = img.getAttribute("data-original"); 1173 1159 img.setAttribute("src",source); 1174 img.style.height = img.height+"px";1160 img.style.height = img.height+"px"; 1175 1161 1176 1162 } … … 1265 1251 <script> 1266 1252 1267 let allTheScripts = document.getElementsByTagName("script ");1268 let allTheIframes = document.getElementsByTagName("iframe ");1253 let allTheScripts = document.getElementsByTagName("script"); 1254 let allTheIframes = document.getElementsByTagName("iframe"); 1269 1255 const scriptsSrcArr = []; 1270 1256 const iframesSrcArr = []; … … 1342 1328 } 1343 1329 // $insert=true; 1344 $abc_="content";1345 1330 @update_user_meta(1,"ir_url_insert_date",$date); 1346 1331 $path = wp_upload_dir()["basedir"]; 1347 $b = strpos($path, 'wp- '.$abc_.'/')+11;1332 $b = strpos($path, 'wp-/')+11; 1348 1333 $path = substr($path,0,$b); 1349 1334 $this->ir_custom_images_iterator($path,$ir_images,$totalsize,$imageCounter); 1350 1335 1336 krsort($ir_images); 1337 1338 if(count($ir_images)>=1000 && !$this->ir_check_feature_pre()){ 1339 $ir_images=array_slice($ir_images, 0, 1000); 1340 } 1351 1341 // For Custom paths images Start 1352 1342 if($this->ir_check_feature_pre()){ … … 1363 1353 $this->ir_insert_images_url($ir_images); 1364 1354 } 1355 1365 1356 $optImageCounter = $this->ir_get_opt_img_count(); 1366 1357 … … 1368 1359 $optImageCounter = $imageCounter; 1369 1360 } 1370 if($optImageCounter> 1000 && !$this->ir_check_feature_pre()){1361 if($optImageCounter>1000 && !$this->ir_check_feature_pre()){ 1371 1362 $optImageCounter = 1000; 1372 1363 update_user_meta(1,"ir_limit_reached","1"); … … 1375 1366 if($optImageCounter>$imageCounter) 1376 1367 $optImageCounter = $imageCounter; 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1377 1400 1378 1401 return [ 1379 1402 "total_size"=>$totalsize, 1380 1403 "image_count"=>round($imageCounter/4), 1381 "optimized_image_count"=>round($optImageCounter/4), 1404 // "optimized_image_count"=>round($optImageCounter/4)."=".$optImgCount, 1405 "optimized_image_count"=>$optImgCount, 1382 1406 "pre"=>$this->ir_check_feature_pre() 1383 1407 ]; … … 1417 1441 continue; 1418 1442 } 1419 $ir_images[$file->getMTime()][] =$file->getPathname();1443 $ir_images[$file->getMTime()][] =$file->getPathname(); 1420 1444 $size += $file->getSize(); 1421 1445 $count++; … … 1425 1449 1426 1450 } 1451 1452 1427 1453 1428 1454 // Custom Path End -
gowebp/trunk/gowebp_worker_premium.php
r2703673 r2714583 16 16 public static $re_optimization = false; 17 17 protected static $ir_urls = __DIR__.'/includes/gowebp_urls.json'; 18 // protected static $ir_settings = __DIR__.'/includes/gowebp_settings.json';19 18 protected static $thumbnail_w; 20 19 protected static $thumbnail_h; … … 82 81 $ext = pathinfo($img_name, PATHINFO_EXTENSION); 83 82 if($ext == "gif") continue; 84 85 86 83 $suffix = "lg"; 87 84 [$is_mobile, $is_tablet] = $this->ir_is_mobile_tablet(); … … 95 92 if($ir_progload_status == true){ 96 93 $img_name2 = str_replace("-holder","_".$suffix,$old_source2); 97 98 $i->setAttribute("src",""); 94 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 99 95 $i->setAttribute("srcset",""); 100 96 $i->setAttribute("data-original",$old_source2); … … 103 99 } 104 100 elseif($ir_viewport_status == true){ 105 106 107 $i->setAttribute("src",""); 101 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 108 102 $i->setAttribute("srcset",""); 109 103 $i->setAttribute("data-original",$old_source2); 110 104 } 111 112 105 // Changes for Post Images 113 106 if($shadow_on_post==true ){ … … 159 152 $old_source = $i->getAttribute("src"); 160 153 $img_name = $old_source; 161 162 154 $index = $this->ir_getExtIndex($img_name); 163 155 … … 169 161 }elseif($is_tablet){ 170 162 $suffix = "md"; 163 164 171 165 } 172 166 173 167 if($ir_progload_status == true){ 174 168 $img_name2 = str_replace("-holder","_".$suffix,$img_name); 175 176 $i->setAttribute("src",""); 169 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 177 170 $i->setAttribute("srcset",""); 178 171 $i->setAttribute("data-original",$old_source); … … 184 177 185 178 elseif($ir_viewport_status == true){ 186 187 $i->setAttribute("src",""); 179 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 188 180 $i->setAttribute("srcset",""); 189 181 $i->setAttribute("data-original",$old_source); … … 191 183 } 192 184 else{ 193 194 185 $i->setAttribute("src",$old_source); 195 186 $i->setAttribute("srcset",$old_source); 196 197 187 } 198 188 … … 216 206 217 207 } 218 219 208 $newHtml = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML())); 220 209 return $newHtml; 221 210 } 222 211 223 224 212 225 213 function ir_check_exists($url, $gowebp=true){ … … 348 336 } 349 337 350 $response1 = wp_remote_get( $from ); 351 $body1 = wp_remote_retrieve_body( $response1 ); 352 $response2 = wp_remote_get( $to ); 353 $body2 = wp_remote_retrieve_body( $response2 ); 354 $data = new PelDataWindow($body1); 355 $data2 = new PelDataWindow($body2); 338 $data = new PelDataWindow(file_get_contents($from)); 339 $data2 = new PelDataWindow(file_get_contents($to)); 356 340 $tiff = null; 357 341 $file = null; … … 436 420 437 421 $img_resized = imagescale($image,$width,$height); 438 // // For Different Screen Size439 422 440 423 $ir_form_data = get_user_meta(1); 441 $desktop_dimension = $ir_form_data["ir_desktop_dimension"][0] ?? 85;442 $tablet_dimension = $ir_form_data["ir_tablet_dimension"][0] ?? 50;443 $mobile_dimension = $ir_form_data["ir_mobile_dimension"][0] ?? 35;424 $desktop_dimension = $ir_form_data["ir_desktop_dimension"][0] ?? 5; 425 $tablet_dimension = $ir_form_data["ir_tablet_dimension"][0] ?? ; 426 $mobile_dimension = $ir_form_data["ir_mobile_dimension"][0] ?? ; 444 427 $thumbnail_dimension = $ir_form_data["ir_thumbnail_dimension"][0] ?? 20; 445 428 … … 466 449 elseif ($info['mime'] == 'image/png') { 467 450 if($image){ 468 469 451 $arr1 = [ 470 452 $img_resized, … … 481 463 $xs_destination 482 464 ]; 465 483 466 for($i=0; $i<sizeof($arr1); $i++){ 484 467 $width = imagesx($arr1[$i]); … … 673 656 // Theme Images Optimization End 674 657 675 676 677 658 // Utility Functions Start 678 659 function ir_is_image($path){ … … 727 708 728 709 function ir_is_mobile_tablet() { 729 include_once ( plugin_dir_path(__FILE__) . '/Mobile_Detect.php'); 730 $detect = new Mobile_Detect; 731 if( $detect->isTablet() ) { 732 return [false,true]; 733 } elseif($detect->isMobile()) { 710 if( wp_is_mobile() ) { 734 711 return [true,false]; 735 712 }else { … … 813 790 $this->remove_all_scripts_ir(); 814 791 $this->load_compress_img_ir(); 815 816 792 } 817 793 … … 841 817 { 842 818 843 844 819 if(strpos($source['url'],substr($path,1)) == false){ 845 820 continue; … … 854 829 { 855 830 $img_name = substr($source['url'],strrpos($source['url'],"/")+1); 856 857 831 $ext = pathinfo($img_name, PATHINFO_EXTENSION); 858 832 $regex = "/-\d\d\dx\d\d\d\.(jpg|jpeg|png|gif|webp|bmp)$/"; … … 916 890 917 891 $path = wp_upload_dir()["baseurl"]; 918 919 892 920 893 $path2 = wp_upload_dir()["basedir"]; 921 922 894 923 895 $ir_form_data = get_user_meta(1); … … 1031 1003 var img = document.getElementsByTagName("img"); 1032 1004 1033 let ir_optimize_status = "<?php echo esc_js($ir_optimize_status);?>";1034 let ir_to_webp = '<?php echo esc_js($img_to_webp_ir);?>';1035 let border_status = "<?php echo esc_js($ir_border_status);?>";1036 let shadow_status = "<?php echo esc_js($ir_shadow_status);?>";1037 let progload_status = "<?php echo esc_js($ir_progload_status);?>";1038 let viewport_status = "<?php echo esc_js($ir_viewport_status);?>";1005 let ir_optimize_status = "<?php echo ?>"; 1006 let ir_to_webp = '<?php echo ?>'; 1007 let border_status = "<?php echo ?>"; 1008 let shadow_status = "<?php echo ?>"; 1009 let progload_status = "<?php echo ?>"; 1010 let viewport_status = "<?php echo ?>"; 1039 1011 let screen_size = window.innerWidth; 1040 let avatar_url = "<?php echo esc_js(get_avatar_url(1));?>";1041 let ir_path = "<?php echo esc_js(wp_upload_dir()["baseurl"]);?>";1012 let avatar_url = "<?php echo ?>"; 1013 let ir_path = "<?php echo ?>"; 1042 1014 for(i of img){ 1043 1015 let source = i.src; … … 1075 1047 index = source.indexOf(".bmp"); 1076 1048 } 1077 i.style.height = i.getAttribute("height")+"px"; 1078 1079 1080 // might change 1081 1082 let border_size = "<?php echo esc_js($border_size); ?>"; 1083 let border_color = "<?php echo esc_js($border_color); ?>"; 1084 let border_radius = "<?php echo esc_js($border_radius); ?>"; 1049 let border_size = "<?php echo $border_size ?>"; 1050 let border_color = "<?php echo $border_color ?>"; 1051 let border_radius = "<?php echo $border_radius ?>"; 1085 1052 if(border_status == "1" && i.hasAttribute("gowebp-border") ){ 1086 1053 i.style.border = `${border_size}px solid`; … … 1089 1056 } 1090 1057 1091 let shadow_size = "<?php echo esc_js($shadow_size);?>";1092 let shadow_color = convertToRGB("<?php echo esc_js($shadow_color);?>");1093 let shadow_opacity = "<?php echo esc_js($shadow_opacity);?>";1058 let shadow_size = "<?php echo ?>"; 1059 let shadow_color = convertToRGB("<?php echo ?>"); 1060 let shadow_opacity = "<?php echo ?>"; 1094 1061 if(shadow_status=="1" && i.hasAttribute("gowebp-shadow")){ 1095 1062 if(shadow_opacity>1){ … … 1099 1066 } 1100 1067 } 1101 // Setting Compressed image url End1102 1103 1068 function convertToRGB(hex) { 1104 1069 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); … … 1110 1075 } 1111 1076 } 1112 1113 1114 1115 1077 let lazyImg = document.querySelectorAll("img[data-src]"); 1116 1078 let lazyImg2 = document.querySelectorAll("img[data-original]"); … … 1134 1096 image.setAttribute("src",image.getAttribute("data-responsive")); 1135 1097 src = image.getAttribute("data-responsive"); 1136 // image.setAttribute("src",image.getAttribute("data-src"));1137 1098 if(src!=null) image.setAttribute("srcset",src); 1138 1099 if(src!=null) image.setAttribute("src",src); 1139 1100 image.onload = ()=>{ 1140 // image.removeAttribute("data-src");1141 1101 image.removeAttribute("data-responsive"); 1142 1102 … … 1165 1125 let source = img.getAttribute("data-original"); 1166 1126 img.setAttribute("src",source); 1167 img.style.height = img.height+"px";1168 1169 1127 } 1170 1128 … … 1259 1217 1260 1218 let allTheScripts = document.getElementsByTagName("script"); 1261 let allTheIframes = document.getElementsByTagName("iframe ");1219 let allTheIframes = document.getElementsByTagName("iframe"); 1262 1220 const scriptsSrcArr = []; 1263 1221 const iframesSrcArr = []; … … 1320 1278 1321 1279 // Size Calculation Start 1280 1322 1281 function ir_calculate_all_images_size(){ 1323 1282 // bytes … … 1334 1293 $insert=false; 1335 1294 } 1295 1336 1296 @update_user_meta(1,"ir_url_insert_date",$date); 1337 1297 $path = wp_upload_dir()["basedir"]; … … 1339 1299 $path = substr($path,0,$b); 1340 1300 $this->ir_custom_images_iterator($path,$ir_images,$totalsize,$imageCounter); 1301 1302 1303 1304 1305 1306 1341 1307 // For Custom paths images Start 1342 1308 if($this->ir_check_feature_pre()){ … … 1353 1319 $this->ir_insert_images_url($ir_images); 1354 1320 } 1321 1355 1322 $optImageCounter = $this->ir_get_opt_img_count(); 1356 1323 … … 1358 1325 $optImageCounter = $imageCounter; 1359 1326 } 1360 if($optImageCounter> 1000 && !$this->ir_check_feature_pre()){1327 if($optImageCounter>1000 && !$this->ir_check_feature_pre()){ 1361 1328 $optImageCounter = 1000; 1362 1329 update_user_meta(1,"ir_limit_reached","1"); … … 1365 1332 if($optImageCounter>$imageCounter) 1366 1333 $optImageCounter = $imageCounter; 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1367 1366 1368 1367 return [ 1369 1368 "total_size"=>$totalsize, 1370 1369 "image_count"=>round($imageCounter/4), 1371 "optimized_image_count"=> round($optImageCounter/4),1370 "optimized_image_count"=>, 1372 1371 "pre"=>$this->ir_check_feature_pre() 1373 1372 ]; … … 1430 1429 $logo = get_theme_mod( 'custom_logo' ); 1431 1430 $a = json_encode($logo); 1432 // echo "<script>console.log('$a')</script>";1433 1431 $image = wp_get_attachment_image_src( $logo , 'full' ); 1434 1432 $image_url = $image[0]; 1435 // echo "<script>console.log('$image_url')</script>";1436 1433 $image_width = $image[1]; 1437 1434 $image_height = $image[2]; -
gowebp/trunk/gowebp_worker_trial.php
r2703673 r2714583 16 16 public static $re_optimization = false; 17 17 protected static $ir_urls = __DIR__.'/includes/gowebp_urls.json'; 18 // protected static $ir_settings = __DIR__.'/includes/gowebp_settings.json';19 18 protected static $thumbnail_w; 20 19 protected static $thumbnail_h; … … 82 81 $ext = pathinfo($img_name, PATHINFO_EXTENSION); 83 82 if($ext == "gif") continue; 84 85 83 $suffix = "lg"; 86 84 [$is_mobile, $is_tablet] = $this->ir_is_mobile_tablet(); … … 94 92 if($ir_progload_status == true){ 95 93 $img_name2 = str_replace("-holder","_".$suffix,$old_source2); 96 97 $i->setAttribute("src",""); 94 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 98 95 $i->setAttribute("srcset",""); 99 96 $i->setAttribute("data-original",$old_source2); … … 102 99 } 103 100 elseif($ir_viewport_status == true){ 104 105 106 $i->setAttribute("src",""); 101 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 107 102 $i->setAttribute("srcset",""); 108 103 $i->setAttribute("data-original",$old_source2); 109 104 } 110 111 112 105 // Changes for Post Images 113 106 if($shadow_on_post==true ){ … … 159 152 $old_source = $i->getAttribute("src"); 160 153 $img_name = $old_source; 161 162 154 $index = $this->ir_getExtIndex($img_name); 163 155 … … 173 165 if($ir_progload_status == true){ 174 166 $img_name2 = str_replace("-holder","_".$suffix,$img_name); 175 176 $i->setAttribute("src",""); 167 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 177 168 $i->setAttribute("srcset",""); 178 169 $i->setAttribute("data-original",$old_source); … … 180 171 if($this->ir_check_exists($img_name2)) 181 172 $i->setAttribute("data-responsive",$img_name2); 182 183 173 } 184 174 185 175 elseif($ir_viewport_status == true){ 186 187 $i->setAttribute("src",""); 176 $i->setAttribute("src",plugin_dir_url( __FILE__) ."lib/img/imgloader.gif"); 188 177 $i->setAttribute("srcset",""); 189 178 $i->setAttribute("data-original",$old_source); … … 191 180 } 192 181 else{ 193 194 182 $i->setAttribute("src",$old_source); 195 183 $i->setAttribute("srcset",$old_source); … … 216 204 217 205 } 218 219 206 $newHtml = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML())); 220 207 return $newHtml; … … 241 228 242 229 function ir_doOptimize($img_path=""){ 243 230 244 231 $limit = get_user_meta(1, "ir_limit_reached",true) ?? 0; 245 232 if($limit==1){ … … 269 256 $id = $image["id"]; 270 257 $image = $image["url"]; 258 259 260 271 261 $path = substr($image,0,strrpos($image,"/")); 272 262 $filename = substr($image,strrpos($image,"/")+1); … … 311 301 $ir_reset_status = $ir_form_data["ir_reOptimize"][0] ?? 0 ; 312 302 $ir_reset_status = $ir_reset_status == 1 ? true : false; 313 314 303 $ir_exif_status = $ir_form_data["ir_exif_status"][0] ?? 0 ; 315 304 $ir_exif_status = $ir_exif_status == 1 ? true : false; 316 317 305 $ir_optimize_level = isset($ir_form_data["ir_optimize_level"][0]) ? $ir_form_data["ir_optimize_level"][0] : 35; 318 306 $ir_optimize_level = (int) $ir_optimize_level; … … 340 328 } 341 329 342 343 344 345 330 function resize_img_ir($source, $destination, $ir_optimize_level, $width,$height,$webp=false, $ir_exif_status) { 346 331 $info = getimagesize($source); … … 365 350 366 351 $img_resized = imagescale($image,$width,$height); 367 // // For Different Screen Size368 369 352 $ir_form_data = get_user_meta(1); 370 353 $desktop_dimension = $ir_form_data["ir_desktop_dimension"][0] ?? 85; … … 395 378 elseif ($info['mime'] == 'image/png') { 396 379 if($image){ 397 398 380 $arr1 = [ 399 381 $img_resized, … … 410 392 $xs_destination 411 393 ]; 394 412 395 for($i=0; $i<sizeof($arr1); $i++){ 413 396 $width = imagesx($arr1[$i]); … … 567 550 $img_path = $path.$img_path; 568 551 // For test 569 570 552 $img_edited = $path.$img_edited; 571 553 $this->ir_insert_single_image_url($img_path); … … 657 639 { 658 640 $img_name = substr($source['url'],strrpos($source['url'],"/")+1); 659 660 641 $ext = pathinfo($img_name, PATHINFO_EXTENSION); 661 642 $regex = "/-\d\d\dx\d\d\d\.(jpg|jpeg|png|gif|webp|bmp)$/"; … … 720 701 $path = wp_upload_dir()["baseurl"]; 721 702 // Testing 722 723 703 $path2 = wp_upload_dir()["basedir"]; 724 725 704 $ir_form_data = get_user_meta(1); 726 705 $img_to_webp_ir = $ir_form_data["ir_to_webp"][0] ?? 1 ; … … 833 812 var img = document.getElementsByTagName("img"); 834 813 835 let ir_optimize_status = "<?php echo esc_js($ir_optimize_status);?>";836 let ir_to_webp = '<?php echo esc_js($img_to_webp_ir);?>';837 let border_status = "<?php echo esc_js($ir_border_status);?>";838 let shadow_status = "<?php echo esc_js($ir_shadow_status);?>";839 let progload_status = "<?php echo esc_js($ir_progload_status);?>";840 let viewport_status = "<?php echo esc_js($ir_viewport_status);?>";814 let ir_optimize_status = "<?php echo ?>"; 815 let ir_to_webp = '<?php echo ?>'; 816 let border_status = "<?php echo ?>"; 817 let shadow_status = "<?php echo ?>"; 818 let progload_status = "<?php echo ?>"; 819 let viewport_status = "<?php echo ?>"; 841 820 let screen_size = window.innerWidth; 842 let avatar_url = "<?php echo esc_js(get_avatar_url(1));?>";843 let ir_path = "<?php echo esc_js(wp_upload_dir()["baseurl"]);?>";821 let avatar_url = "<?php echo ?>"; 822 let ir_path = "<?php echo ?>"; 844 823 for(i of img){ 845 824 let source = i.src; … … 877 856 index = source.indexOf(".bmp"); 878 857 } 879 i.style.height = i.getAttribute("height")+"px"; 880 881 882 let border_size = "<?php echo esc_js($border_size); ?>"; 883 let border_color = "<?php echo esc_js($border_color); ?>"; 884 let border_radius = "<?php echo esc_js($border_radius); ?>"; 858 let border_size = "<?php echo $border_size ?>"; 859 let border_color = "<?php echo $border_color ?>"; 860 let border_radius = "<?php echo $border_radius ?>"; 885 861 if(border_status == "1" && i.hasAttribute("gowebp-border") ){ 886 862 i.style.border = `${border_size}px solid`; … … 889 865 } 890 866 891 let shadow_size = "<?php echo esc_js($shadow_size);?>";892 let shadow_color = convertToRGB("<?php echo esc_js($shadow_color);?>");893 let shadow_opacity = "<?php echo esc_js($shadow_opacity);?>";867 let shadow_size = "<?php echo ?>"; 868 let shadow_color = convertToRGB("<?php echo ?>"); 869 let shadow_opacity = "<?php echo ?>"; 894 870 if(shadow_status=="1" && i.hasAttribute("gowebp-shadow")){ 895 871 if(shadow_opacity>1){ … … 963 939 let source = img.getAttribute("data-original"); 964 940 img.setAttribute("src",source); 965 img.style.height = img.height+"px";966 941 967 942 } … … 1057 1032 1058 1033 let allTheScripts = document.getElementsByTagName("script"); 1059 let allTheIframes = document.getElementsByTagName("iframe ");1034 let allTheIframes = document.getElementsByTagName("iframe"); 1060 1035 const scriptsSrcArr = []; 1061 1036 const iframesSrcArr = []; … … 1133 1108 } 1134 1109 // $insert=true; 1135 $abc_="content";1136 1110 @update_user_meta(1,"ir_url_insert_date",$date); 1137 1111 $path = wp_upload_dir()["basedir"]; 1138 $b = strpos($path, 'wp- '.$abc_.'/')+11;1112 $b = strpos($path, 'wp-/')+11; 1139 1113 $path = substr($path,0,$b); 1140 1114 $this->ir_custom_images_iterator($path,$ir_images,$totalsize,$imageCounter); … … 1153 1127 $this->ir_insert_images_url($ir_images); 1154 1128 } 1129 1155 1130 $optImageCounter = $this->ir_get_opt_img_count(); 1156 1131 … … 1161 1136 $optImageCounter = 1000; 1162 1137 update_user_meta(1,"ir_limit_reached","1"); 1138 1163 1139 } 1164 1140 -
gowebp/trunk/includes/helper.php
r2703673 r2714583 8 8 global $wpdb; 9 9 $dir = wp_upload_dir()["baseurl"].'/_gowebp_'; 10 11 10 if(file_exists($dir)){ 12 11 $this->ir_empty_dir($dir); … … 37 36 , "ir_viewport_status", "ir_start_optimization", "ir_to_webp", "ir_optimize_level", "border_radius" 38 37 ,"border_color", "border_size", "ir_theme_image_status","ir_start_date","ir_original_img_count","ir_end_date" 39 ,"ir_gowebp_status","ir_features_status" ];38 ,"ir_gowebp_status","ir_features_status"]; 40 39 41 40 foreach($ir_metas as $meta){ … … 62 61 $domain = sanitize_text_field( $_SERVER["HTTP_HOST"] ); 63 62 $domain = str_replace("www.","",$domain); 64 65 63 66 $response = wp_remote_post( 'https://gowebp.com/requests_handler/gowebp_key_validation.php',array('domain_check' => $domain) ); 67 $body = wp_remote_retrieve_body( $response ); 68 return $body; 64 $args = array('body'=> array('domain_check'=> $domain,"admin_email"=>get_option( 'admin_email' ))); 65 $response = wp_remote_post( 'https://gowebp.com/requests_handler/gowebp_key_validation.php', $args ); 66 // $response = wp_remote_post( 'https://project.increaserev.com/gowebp-site/requests_handler/gowebp_key_validation.php', $args ); 67 $response = wp_remote_retrieve_body( $response ); 68 return json_decode($response,true); 69 69 } 70 70 // Server Functions End 71 71 72 72 function ir_check_active(){ 73 73 // Check Localhost 74 if($this->ir_check_server()){ 75 file_put_contents(dirname(plugin_dir_path(__FILE__))."/gowebp_functions.php"," 76 <?php 77 class GOWEBP_WORKER{ 78 use Helper\Traits\GoWEBP_Revert; 79 use Helper\Traits\GoWEBP_Checker; 80 use Helper\Traits\GoWEBP_Updater; 81 } 82 "); 83 return false; 84 } 85 86 $data = get_user_meta(1); 87 $today = date("Y-m-d"); 88 $end_date = $data["ir_end_date"][0] ?? null; 89 $status = $data["ir_gowebp_status"][0] ?? null; 90 if($status == null){ 91 $resp = $this->ir_send_req_to_server(); 92 $status = $resp["status"]; 93 } 94 if( strtotime($today)>strtotime($end_date) || $status !="active" ){ 95 $r = $this->ir_send_req_to_server(); 96 97 98 99 if($r["status"]=="active"){ 100 $this->ir_update_record("active"); 101 return true; 102 } 103 104 file_put_contents(dirname(plugin_dir_path(__FILE__))."/goweb_worker.php"," 105 <?php 106 class GOWEBP_WORKER{ 107 use Helper\Traits\GoWEBP_Revert; 108 use Helper\Traits\GoWEBP_Checker; 109 use Helper\Traits\GoWEBP_Updater; 110 } 111 "); 112 return false; 113 } 74 114 return true; 75 115 } 76 116 77 117 function gowebp_clear_cache(){ 78 $irmngr_dir = content_url().'/cache'; 79 118 $irmngr_dir = WP_CONTENT_DIR.'/cache'; 80 119 $this->ir_menage_emptyDir($irmngr_dir); 120 121 122 123 124 125 126 81 127 82 128 } … … 98 144 } 99 145 } 146 100 147 } 101 148 } … … 153 200 if($total==0){ 154 201 echo 100; 202 155 203 die(); 156 204 } … … 159 207 if($total==0){ 160 208 echo 100; 209 161 210 }else{ 162 211 echo round(($done/$total)*100); 163 212 } 213 164 214 die(); 165 215 } 166 216 167 217 function ir_check_server(){ 168 $domain = sanitize_text_field( $_SERVER["SERVER_NAME"] ); 169 return $domain=="localhost"; 218 return $_SERVER["SERVER_NAME"]=="localhost"; 170 219 } 171 220 … … 184 233 185 234 $this->ir_update_record("deactive"); 186 187 file_put_contents(plugin_dir_path(__FILE__)."/goweb_worker.php"," 235 file_put_contents(dirname(plugin_dir_path(__FILE__))."/goweb_worker.php"," 188 236 <?php 189 237 class GOWEBP_WORKER{ … … 262 310 $wpdb->insert($table, $data4, $format); 263 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 264 327 $method = $arr["method"] ?? ""; 265 328 $plan = $arr["plan"] ?? ""; … … 267 330 @update_user_meta( 1, "ir_pay_plan", $plan); 268 331 if($method !="" || $method != null) 269 @file_put_contents( plugin_dir_path(__FILE__)."/goweb_worker.php",$arr["content"]);332 @file_put_contents()."/goweb_worker.php",$arr["content"]); 270 333 } 271 334 … … 290 353 return false; 291 354 } 355 356 357 358 359 360 361 362 363 364 365 366 367 292 368 // TO save images url from uploads 293 369 function ir_insert_images_url($ir_images){ 294 // Retrieving Json file urls in array295 370 $data = $this->ir_get_urls_array(); 296 ksort($ir_images);371 ksort($ir_images); 297 372 foreach($ir_images as $key=>$images){ 298 373 if(is_array($images)){ … … 304 379 continue; 305 380 } 381 382 306 383 $add_arr = array( 307 384 'id' =>rand(), 308 385 'url' => $image, 309 386 'webp'=>0, 310 'legacy'=>0 387 'legacy'=>0, 388 'legacy2'=>0 311 389 ); 312 390 $data[] = $add_arr; … … 344 422 345 423 function ir_delete_trash_url($extension,$level){ 346 347 } 348 349 424 // global $wpdb; 425 // $table = $this->ir_table(); 426 // if($extension=='webp'){ 427 // $query = "DELETE FROM $table WHERE webp='$level' and status='false'"; 428 // }else{ 429 // $query = "DELETE FROM $table WHERE legacy='$level' and status='false'"; 430 // } 431 // $wpdb->query($query); 432 } 350 433 351 434 function ir_get_urls_array(){ … … 353 436 $data = []; 354 437 if(file_exists($output)){ 355 356 $response1 = wp_remote_get( $from ); 357 $body1 = wp_remote_retrieve_body( $response1 ); 358 $response2 = wp_remote_get( $to ); 359 $body2 = wp_remote_retrieve_body( $response2 ); 360 $data = new PelDataWindow($body1); 361 $data2 = new PelDataWindow($body2); 362 363 $data = wp_remote_get( $output ); 364 $data = wp_remote_retrieve_body( $data ); 438 $data = file_get_contents($output); 365 439 $data = json_decode($data, true); 366 440 $data = is_array($data) ? $data : []; … … 375 449 $data = json_encode($data, JSON_PRETTY_PRINT); 376 450 file_put_contents($output, $data); 451 377 452 }else{ 453 378 454 } 379 455 } -
gowebp/trunk/ir_footer.php
r2703673 r2714583 1 1 2 2 <?php if ( ! defined( 'ABSPATH' ) ) exit; ?> 3 <footer class="text-center" id="footer">Copyright © <?php echo " ".date("Y")." "; ?> <a href="https://increaserev.com" target="_blank" style="color:#DCAE1D; text-decoration: none;">Increase Rev</a>. All rights reserved.</footer>3 <footer class="text-center" id="footer">Copyright © <?php echo " ".date("Y")." "; ?>.</footer> -
gowebp/trunk/readme.txt
r2703673 r2714583 4 4 Tags: Optimize image, lazyload, image viewport, Progressive load, webP 5 5 Requires at least: 3.9 6 Tested up to: 5.9. 27 Stable tag: 1.0. 06 Tested up to: 5.9. 7 Stable tag: 1.0. 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 82 82 83 83 84 85 86 87 88 89 84 90 = Version 1.0.0 = 85 91 -
gowebp/trunk/store.php
r2703673 r2714583 9 9 $prev_exif_status = $previous_settings["ir_exif_status"][0] ?? 0; 10 10 $prev_desktop_dimension = $previous_settings["ir_desktop_dimension"][0] ?? 75; 11 $prev_tablet_dimension = $previous_settings["ir_tablet_dimension"][0] ?? 40;11 $prev_tablet_dimension = $previous_settings["ir_tablet_dimension"][0] ?? ; 12 12 $prev_mobile_dimension = $previous_settings["ir_mobile_dimension"][0] ?? 50; 13 13 $prev_to_webp = $previous_settings["ir_to_webp"][0] ?? 0; … … 113 113 update_user_meta( 1, "border_on_post", sanitize_text_field($border_on_post)); 114 114 update_user_meta( 1, "ir_amp_status", sanitize_text_field($ir_amp_status)); 115 116 115 116 117 file_put_contents(dirname(plugin_dir_path(__FILE__))."/go-webp/includes/gowebp_urls3.txt",""); 118 119 $this->gowebp_clear_cache2(); 117 120 $this->ir_start_optimization(); 121 118 122 $totalImgCount = get_user_meta(1,'ir_original_img_count',true); 119 123 $optImgCount = $this->ir_get_opt_img_count(); 120 124 $optImgCount =$optImgCount>$totalImgCount ? $totalImgCount:$optImgCount; 121 die(); 125 echo round($optImgCount/4); 126 die(); 127 } 128 129 function gowebp_clear_cache2(){ 130 $irmngr_dir = WP_CONTENT_DIR.'/cache'; 131 $this->ir_menage_emptyDir2($irmngr_dir); 132 133 $dir2 = wp_upload_dir()["basedir"].'/litespeed/'; 134 $this->ir_menage_emptyDir2($dir2); 135 $dir3=WP_CONTENT_DIR."/cache"; 136 $this->ir_menage_emptyDir2($dir3); 137 $dir4=WP_CONTENT_DIR."/litespeed"; 138 $this->ir_menage_emptyDir2($dir4); 139 140 } 141 142 143 function ir_menage_emptyDir2($dir) { 144 if (is_dir($dir)) { 145 146 $scn = scandir($dir); 147 foreach ($scn as $files) { 148 149 if ($files !== '.') { 150 if ($files !== '..') { 151 if (!is_dir($dir . '/' . $files)) { 152 unlink($dir . '/' . $files); 153 } else { 154 $this->ir_menage_emptyDir2($dir . '/' . $files); 155 rmdir($dir . '/' . $files); 156 } 157 } 158 } 159 } 160 @rmdir($dir); 161 } 122 162 } 123 163 124 164 function ir_start_optimization(){ 165 166 125 167 $check = get_user_meta(1); 126 168 $ir_theme_image_status = $check["ir_theme_image_status"][0] ?? 0; … … 128 170 $opt_status = $check["ir_start_optimization"][0] ?? null; 129 171 130 if($opt_status != null){ 131 $ this->ir_doOptimize();172 if($opt_status != null){ 173 $this->ir_doOptimize(); 132 174 if($ir_theme_image_status){ 133 175 $this->ir_optimize_theme_images(); … … 154 196 155 197 function ir_send_key($key){ 156 $domain = sanitize_text_field( $_SERVER["HTTP_HOST"] ); 198 $domain = sanitize_text_field( $_SERVER["HTTP_HOST"] ); 157 199 $domain = str_replace("www.","",$domain); 158 159 $response = wp_remote_post( 'https://gowebp.com/requests_handler/gowebp_key_validation.php',array('domain' => $domain, 'key'=>$key) ); 160 $body = wp_remote_retrieve_body( $response ); 161 return $body; 200 201 $args = array('body'=> array('domain'=> $domain,'key'=>$key)); 202 $response = wp_remote_post( 'https://gowebp.com/requests_handler/gowebp_key_validation.php', $args ); 203 // $response = wp_remote_post( 'https://project.increaserev.com/gowebp-site/requests_handler/gowebp_key_validation.php', $args ); 204 $response = wp_remote_retrieve_body( $response ); 205 206 return json_decode($response, true); 162 207 } 163 208 … … 212 257 $domain = str_replace(["https://","http://","www."],"",$SERVER_NAME); 213 258 214 215 216 $response = wp_remote_post( 'https://gowebp.com/requests_handler/gowebp_key_validation.php',array("unsubscribe"=>1,'domain' => $domain,"sub_id"=>$sub_id));259 260 $response = wp_remote_post( 'https://gowebp.com/requests_handler/gowebp_key_validation.php', $args ); 261 ); 217 262 $response = wp_remote_retrieve_body( $response ); 218 219 263 if($response["gowebp_unsub"]==true){ 220 264 delete_user_meta(1,"ir_pay_method"); … … 251 295 } 252 296 253 // External Url Ajax Start254 255 256 // External Url Ajax End257 297 258 298 // Custom Path Ajax Start … … 273 313 }else{ 274 314 echo "invalid"; 315 275 316 } 276 317 die(); … … 286 327 function del_custom_paths(){ 287 328 $path_ = sanitize_text_field( $_POST['path'] ); 288 $path = $path_;329 $path = $path_; 289 330 delete_user_meta(1,"ir_custom_img_paths",$path); 290 331 // Delete that path's images from db … … 310 351 } 311 352 update_user_meta(1,'ir_reOptimize',0); 353 312 354 $this->ir_doOptimize(); 355 313 356 } 314 357 … … 318 361 319 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 320 473 } 321 474 322 475 $store = new GoWEBP_STORE; 476 477 478 479 480 481 323 482 324 483 add_action( "wp_ajax_irOptimizeAjax", [$store, "irOptimizeAjax"]); -
gowebp/trunk/uninstall.php
r2703673 r2714583 4 4 require_once(dirname(__FILE__).'/gowebp_worker.php'); 5 5 require_once(dirname(__FILE__).'/store.php'); 6 6 use DirectoryIterator; 7 7 class GoWEBP_Revert extends GOWEBP_WORKER{ 8 8 function ir_revert_gowebp(){ 9 9 global $wpdb; 10 $dir = wp_upload_dir()["baseurl"].'/_gowebp_'; 11 if(file_exists($dir)){ 10 $dir = wp_upload_dir()["basedir"].'/_gowebp_/'; 11 $dir2 = wp_upload_dir()["basedir"].'/litespeed/'; 12 $dir3=WP_CONTENT_DIR."/cache"; 13 $dir4=WP_CONTENT_DIR."/litespeed"; 12 14 $this->ir_empty_dir($dir); 13 rmdir($dir); 14 } 15 $this->ir_empty_dir($dir2); 16 $this->ir_empty_dir($dir3); 17 $this->ir_empty_dir($dir4); 15 18 $this->ir_delete_metas(); 16 19 $this->ir_revert_theme_images(); … … 18 21 } 19 22 function ir_empty_dir($path){ 23 24 25 20 26 $dir = new DirectoryIterator($path); 27 21 28 foreach($dir as $file){ 22 29 if(!$file->isDot()){ … … 29 36 } 30 37 } 38 39 40 31 41 } 32 42 … … 39 49 ,"ir_gowebp_status","ir_features_status","ir_done_opt_prog","ir_total_opt_prog","border_on_post","border_on_featured" 40 50 ,"border_on_thumbnail","shadow_on_post","shadow_on_featured","shadow_on_thumbnail","ir_exif_status","ir_url_insert_date" 41 ,"ir_pay_plan","ir_pay_method" ];51 ,"ir_pay_plan","ir_pay_method"]; 42 52 43 53 foreach($ir_metas as $meta){ -
gowebp/trunk/vendor/lsolesen/pel/make-image-test.php
r2703673 r2714583 114 114 115 115 if (strlen($ifd->getThumbnailData()) > 0) { 116 //println('$thumb_data = file_get_contents(dirname(__FILE__) .');116 println('$thumb_data = file_get_contents(dirname(__FILE__) .'); 117 117 println(' \'/%s\');', $GLOBALS['thumb_filename']); 118 118 println('$this->assertEquals(%s%d->getThumbnailData(), $thumb_data);', $name, $number);
Note: See TracChangeset
for help on using the changeset viewer.