Changeset 3186406
- Timestamp:
- 11/12/2024 10:22:29 AM (15 months ago)
- Location:
- sirv/trunk
- Files:
-
- 11 edited
-
plugdata/css/wp-options.css (modified) (2 diffs)
-
plugdata/css/wp-sirv.css (modified) (1 diff)
-
plugdata/htmlBuilders/elementor/SirvControl.php (modified) (1 diff)
-
plugdata/includes/classes/utils.class.php (modified) (1 diff)
-
plugdata/includes/classes/wc.product.helper.class.php (modified) (4 diffs)
-
plugdata/includes/classes/woo.class.php (modified) (12 diffs)
-
plugdata/js/wp-sirv.js (modified) (7 diffs)
-
plugdata/media_library.php (modified) (1 diff)
-
plugdata/submenu_pages/sync.php (modified) (4 diffs)
-
readme.txt (modified) (2 diffs)
-
sirv.php (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sirv/trunk/plugdata/css/wp-options.css
r3162079 r3186406 771 771 772 772 .optiontable.form-table h3 { 773 margin: 0px 0 10px 0;773 margin: 5px 0 10px 0; 774 774 } 775 775 … … 2116 2116 height: 40px; 2117 2117 } 2118 2119 .sirv-media-lib-title{ 2120 padding: 0 10px !important; 2121 } 2122 .sirv-media-lib-title h3{ 2123 margin-bottom: 0 !important; 2124 } -
sirv/trunk/plugdata/css/wp-sirv.css
r3039643 r3186406 1364 1364 width: 100%; 1365 1365 } 1366 1367 1368 .ui-tooltip { 1369 padding: 8px; 1370 position: absolute; 1371 z-index: 99999999; 1372 max-width: 400px; 1373 background-color: white !important; 1374 background-image: none; 1375 } 1376 1377 .sirv-ui-widget-content { 1378 border: none; 1379 background-image: none; 1380 } 1381 1382 /* Corner radius */ 1383 .sirv-ui-corner-all { 1384 border-radius: 3px; 1385 } 1386 1387 .sirv-ui-widget-shadow { 1388 box-shadow: 0px 0px 5px #666666 !important; 1389 } -
sirv/trunk/plugdata/htmlBuilders/elementor/SirvControl.php
r3115018 r3186406 26 26 wp_register_style( 'sirv_mce_style', SIRV_PLUGIN_SUBDIR_URL_PATH . 'css/wp-sirv-shortcode-view.css' ); 27 27 wp_enqueue_style('sirv_mce_style'); 28 wp_register_script( 'sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array( 'jquery', 'jquery-ui-sortable,sirv_toast_js' ), false);28 wp_register_script( 'sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array( 'jquery','jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'sirv_toast_js' ), false); 29 29 wp_localize_script( 'sirv_logic', 'sirv_ajax_object', array( 30 30 'ajaxurl' => admin_url( 'admin-ajax.php' ), -
sirv/trunk/plugdata/includes/classes/utils.class.php
r3162079 r3186406 103 103 public static function get_file_extension($filepath){ 104 104 return pathinfo($filepath, PATHINFO_EXTENSION); 105 } 106 107 108 public static function parse_html_tag_attrs($html_data){ 109 $tag_metadata = array(); 110 111 if ( ! empty($html_data) ) { 112 preg_match_all('/\s(\w*)=\"([^"]*)\"/ims', $html_data, $matches_tag_attrs, PREG_SET_ORDER); 113 $tag_metadata = self::convert_matches_to_assoc_array($matches_tag_attrs); 114 } 115 116 return $tag_metadata; 117 } 118 119 120 public static function convert_matches_to_assoc_array($matches){ 121 $assoc_array = array(); 122 123 for ($i=0; $i < count($matches); $i++) { 124 $assoc_array[$matches[$i][1]] = $matches[$i][2]; 125 } 126 127 return $assoc_array; 128 } 129 130 131 public static function join_tag_attrs($tag_metadata, $skip_attrs = array()){ 132 $tag_attrs = array(); 133 134 foreach ($tag_metadata as $attr_name => $value) { 135 if( in_array($attr_name, $skip_attrs) ) continue; 136 137 $tag_attrs[] = $attr_name . '="' . $value . '"'; 138 } 139 140 return implode(' ', $tag_attrs); 141 } 142 143 144 145 public static function get_sirv_item_info($sirv_url){ 146 $context = stream_context_create(array('http' => array('method' => "GET"))); 147 $sirv_item_metadata = @json_decode(@file_get_contents($sirv_url . '?info', false, $context)); 148 149 return empty($sirv_item_metadata) ? false : $sirv_item_metadata; 150 } 151 152 153 public static function build_html_tag($tag_name, $tag_metadata, $skip_attrs = array()){ 154 $tag_attrs = self::join_tag_attrs($tag_metadata, $skip_attrs); 155 156 return '<' . $tag_name . ' ' . $tag_attrs . '>'; 105 157 } 106 158 -
sirv/trunk/plugdata/includes/classes/wc.product.helper.class.php
r2972273 r3186406 26 26 "_wp_attachment_image_alt" => preg_replace('/\.[^.]+$/', '', basename($sirv_url)), 27 27 "sirv_woo_product_image_attachment" => $sirv_url, 28 "_wp_attachment_metadata" => self::get_sirv_item_metadata($sirv_url, $sirv_item_type_data ['sirv_type']),28 "_wp_attachment_metadata" => self::get_sirv_item_metadata($sirv_url, $sirv_item_type_data), 29 29 ), 30 30 ); … … 41 41 42 42 public static function get_sirv_item_type($sirv_url){ 43 $sirv_type = array(" sirv_type" => '');43 $sirv_type = array("type" => '', "ext" => '', "mime_type" => ''); 44 44 45 $filetype = wp_check_filetype(basename($sirv_url) , null);45 $filetype = wp_check_filetype(basename($sirv_url)); 46 46 47 if( !empty($filetype ) && !empty($filetype['type'])){47 if( !empty($filetype['type']) ){ 48 48 $sirv_type['ext'] = $filetype['ext']; 49 $sirv_type[' type'] = $filetype['type'];49 $sirv_type['mime_type'] = $filetype['type']; 50 50 list($type, $ext) = explode('/', $filetype['type']); 51 51 switch ($type) { 52 52 case 'sirv': 53 if($ext == 'spin') $sirv_type[' sirv_type'] = 'spin';53 if($ext == 'spin') $sirv_type['type'] = 'spin'; 54 54 break; 55 55 56 56 default: 57 $sirv_type[' sirv_type'] = $type;57 $sirv_type['type'] = $type; 58 58 break; 59 59 } 60 }else{ 61 $sirv_type['ext'] = pathinfo($sirv_url, PATHINFO_EXTENSION); 60 62 } 61 63 … … 64 66 65 67 66 protected static function get_sirv_item_metadata($sirv_url, $sirv_item_type ){68 protected static function get_sirv_item_metadata($sirv_url, $sirv_item_type_data){ 67 69 68 $sirv_metadata = array("sirv_type" => $sirv_item_type); 69 70 $sirv_metadata = array("sirv_type" => ''); 70 71 $allow_dimensions_types = array('image', 'video'); 71 72 72 if( in_array($sirv_item_type, $allow_dimensions_types) ){ 73 $string_metadata = @file_get_contents($sirv_url . '?info'); 73 $sirv_item_metadata = Utils::get_sirv_item_info($sirv_url); 74 74 75 if( !empty($string_metadata)){ 76 $metadata = json_decode($string_metadata, true); 75 if ( $sirv_item_type_data['type'] ) { 76 $sirv_metadata["sirv_type"] = $sirv_item_type_data['type']; 77 } else { 78 if( $sirv_item_metadata ){ 79 if (isset($sirv_item_metadata->original->File->MIMEType)) { 80 $sirv_metadata['sirv_type'] = explode('/', $sirv_item_metadata->original->File->MIMEType)[0]; 81 } 77 82 83 if (isset($sirv_item_metadata->layers)) { 84 $sirv_metadata['sirv_type'] = 'spin'; 85 } 86 }else{ 87 $sirv_metadata['sirv_type'] = 'image'; 88 } 78 89 79 if (isset($metadata['original']['width'])) $sirv_metadata['width'] = $metadata['original']['width']; 80 if (isset($metadata['original']['height'])) $sirv_metadata['height'] = $metadata['original']['height']; 90 } 91 92 if( in_array($sirv_metadata['sirv_type'], $allow_dimensions_types) ){ 93 94 if( !empty($sirv_item_metadata)){ 95 96 if ( isset($sirv_item_metadata->original->width) ) $sirv_metadata['width'] = $sirv_item_metadata->original->width; 97 if ( isset($sirv_item_metadata->original->height) ) $sirv_metadata['height'] = $sirv_item_metadata->original->height; 81 98 } 82 99 }else{ … … 89 106 } 90 107 91 $filesize = self::get_filesize($sirv_url, $sirv_ item_type);108 $filesize = self::get_filesize($sirv_url, $sirv_metadata['sirv_type']) ; 92 109 93 110 if( !empty($filesize) ) $sirv_metadata['filesize'] = $filesize; -
sirv/trunk/plugdata/includes/classes/woo.class.php
r3162079 r3186406 40 40 $cached_data = self::get_post_sirv_data($id, '_sirv_woo_viewf_data'); 41 41 $prod_path = $this->getProductPath($id, $isVariation); 42 $headers = $this->get_HEAD_request($prod_path . '.view'); 42 //$headers = $this->get_HEAD_request($prod_path . '.view'); 43 $headers = Utils::get_head_request($prod_path . '.view'); 43 44 if ((!isset($cached_data->file_version) && isset($headers['X-File-VersionId'])) || (isset($headers['X-File-VersionId']) && $cached_data->file_version !== $headers['X-File-VersionId'])) { 44 45 … … 322 323 <div class="sirv-woo-gallery-toolbar hide-if-no-js"> 323 324 <div class="sirv-woo-gallery-toolbar-main"> 324 <a class="button button-primary button-large sirv-woo-add-media" data-type="<?php echo $type; ?>" data-id="<?php echo $id; ?>">Add Sirv Media</a>325 <a class="button button-primary button-large sirv-woo-add-online-video" data-id="<?php echo $id; ?>">Add Online Video</a>325 <a class="button button-primary button-large sirv-woo-add-media" data-type="<?php echo $type; ?>" data-id="<?php echo $id; ?>">Add Sirv media</a> 326 <a class="button button-primary button-large sirv-woo-add-online-video" data-id="<?php echo $id; ?>">Add online video</a> 326 327 </div> 327 328 <div class="sirv-add-online-videos-container" id="sirv-add-online-videos-container_<?php echo $id; ?>"> … … 400 401 if (!isset($sirv_remote_data->items)) $sirv_remote_data->items = array(); 401 402 403 $sirv_data = $this->merge_object_data($sirv_local_data->items, $sirv_remote_data->items, true); 404 402 405 $main_product_image_data = $this->get_main_image($this->product_id); 403 404 $sirv_data = $this->merge_object_data($sirv_local_data->items, $sirv_remote_data->items, true);405 406 406 407 $wc_gallery = $this->parse_wc_gallery($this->product_id); … … 413 414 414 415 return $html; 416 } 417 418 419 protected function get_sirv_items_data($isVariation){ 420 $sirv_local_data = (object) $this->get_sirv_local_data($this->product_id); 421 $sirv_remote_data = (object) $this->get_sirv_remote_data($this->product_id, $isVariation); 422 423 if (!isset($sirv_local_data->items)) $sirv_local_data->items = array(); 424 if (!isset($sirv_remote_data->items)) $sirv_remote_data->items = array(); 425 426 return $this->merge_object_data($sirv_local_data->items, $sirv_remote_data->items, true); 427 } 428 429 430 public function get_export_data_to_csv_column($isVariation){ 431 $sirv_gallery = $this->get_sirv_items_data($isVariation); 432 $sirv_item_urls = array(); 433 434 if( !$isVariation && $this->isSirvProductImage($this->product_id) ){ 435 $sirv_main_image_url = self::get_post_sirv_data($this->product_id, 'sirv_woo_product_image', false, false); 436 437 if( $sirv_main_image_url ){ 438 $sirv_item_urls[] = $sirv_main_image_url; 439 } 440 } 441 442 foreach ($sirv_gallery as $sirv_item) { 443 $sirv_item_urls[] = $sirv_item->url; 444 } 445 446 return implode(", ", $sirv_item_urls); 415 447 } 416 448 … … 550 582 protected function get_HEAD_request($url) 551 583 { 552 //TODO: use curl to get HEAD request. 553 $default_stream = stream_context_get_default(); 554 $default_stream_options = stream_context_get_options($default_stream); 555 556 stream_context_set_default( 584 585 $context = stream_context_create( 557 586 array( 558 587 'http' => array( … … 562 591 ); 563 592 564 $headers = get_headers($url, true); 565 566 stream_context_set_default(array()); 593 $headers = get_headers($url, true, $context); 567 594 568 595 return $headers; … … 746 773 protected function get_product_sku($product_id) 747 774 { 748 $product = new WC_Product($product_id); 749 $sku = $product->get_sku(); 750 $sku = empty($sku) ? 'error-no-sku' : $sku; 775 try{ 776 $product = new WC_Product($product_id); 777 $sku = $product->get_sku(); 778 $sku = empty($sku) ? 'error-no-sku' : $sku; 779 }catch(Exception $e){ 780 $sku = 'error-no-sku'; 781 } 751 782 752 783 return $sku; … … 974 1005 $sirv_remote_variation = $this->get_sirv_remote_data($variation_id, true); 975 1006 976 if (!empty($sirv_local_variation->items) && !empty($sirv_remote_variation->items)) { 1007 $sirv_local_variation = $this->fix_item_viewIds($variation_id, $sirv_local_variation); 1008 1009 1010 if (!empty($sirv_local_variation->items) && !empty($sirv_remote_variation)) { 977 1011 $variation_data = $this->merge_object_data($sirv_local_variation->items, $sirv_remote_variation->items, true); 978 1012 } else { … … 989 1023 990 1024 return $variation_data; 1025 } 1026 1027 1028 function fix_item_viewIds($currnet_item_id, $sirv_variation_data){ 1029 if( !empty($sirv_variation_data->items) && $sirv_variation_data->items[0]->viewId !== $currnet_item_id){ 1030 foreach($sirv_variation_data->items as $item){ 1031 $item->viewId = $currnet_item_id; 1032 } 1033 $sirv_variation_data->id = $currnet_item_id; 1034 } 1035 1036 return $sirv_variation_data; 991 1037 } 992 1038 … … 1209 1255 } 1210 1256 1211 p rotectedfunction remove_script_tag($string)1257 public function remove_script_tag($string) 1212 1258 { 1213 1259 return preg_replace('/<(\/)*script.*?>/im', '', $string); … … 1419 1465 $isCaption = false; 1420 1466 1421 $mv_custom_options = $this->remove_script_tag(get_option('SIRV_WOO_MV_CUSTOM_OPTIONS'));1422 $mv_custom_options_block = !empty($mv_custom_options) ? '<script nowprocket>' . $mv_custom_options . '</script>' . PHP_EOL : ''; 1467 /* $mv_custom_options = $this->remove_script_tag(get_option('SIRV_WOO_MV_CUSTOM_OPTIONS')); 1468 $mv_custom_options_block = !empty($mv_custom_options) ? '<script nowprocket>' . $mv_custom_options . '</script>' . PHP_EOL : ''; */ 1423 1469 1424 1470 $mv_custom_css = get_option('SIRV_WOO_MV_CUSTOM_CSS'); … … 1484 1530 $json_data_block = '<div style="display: none;" ' . $data_item_by_variation_id . 'data-existings-ids=\'' . json_encode($existings_ids, JSON_HEX_QUOT | JSON_HEX_APOS) . '\' id="sirv-woo-gallery_data_' . $this->product_id . '" data-is-caption="' . $isCaption . '"></div>' . PHP_EOL; 1485 1531 1486 return $json_data_block . '<div class="Sirv' . $opacityClass . '" id="sirv-woo-gallery_' . $this->product_id . '"' . $this->render_viewer_options($viewer_options) . '>' . PHP_EOL . $items_html . '</div>' . PHP_EOL . $mv_custom_options_block. $mv_custom_css . $max_height_style;1532 return /* $mv_custom_options_block . PHP_EOL . */$json_data_block . '<div class="Sirv' . $opacityClass . '" id="sirv-woo-gallery_' . $this->product_id . '"' . $this->render_viewer_options($viewer_options) . '>' . PHP_EOL . $items_html . '</div>' . PHP_EOL. $mv_custom_css . $max_height_style; 1487 1533 } 1488 1534 -
sirv/trunk/plugdata/js/wp-sirv.js
r3162079 r3186406 794 794 meta.main = formatVideoDuration(data.meta.duration); 795 795 break; 796 case 'model': 797 meta.main = shortDate; 798 break; 796 799 797 800 default: … … 1889 1892 let groupedImages = groupedFiles(files, maxFileSize, maxFilesCount, sirvFileSizeLimit); 1890 1893 let countFiles = files.length; 1891 1892 1894 //let currentDir = htmlDecode($('#filesToUpload').attr('data-current-folder')); 1893 1895 let currentDir = getCurrentDir(hasLastSlash = true); … … 1966 1968 let fileItem = overSizedImages[index]; 1967 1969 let reader = new FileReader(); 1970 1968 1971 uploadImageByChunk(fileItem, 0, reader, 1, totalOverSizedFiles, currentDir); 1969 1972 } … … 1989 1992 data.append('action', 'sirv_upload_file_by_chunks'); 1990 1993 data.append("_ajax_nonce", sirv_ajax_object.ajaxnonce); 1991 data.append("filename", file.name); 1994 //data.append("filename", file.name); 1995 data.append("filename", fileItem.fullPath); 1992 1996 data.append('totalParts', totalSlices); 1993 1997 data.append('totalFiles', totalOverSizedFiles); … … 2024 2028 2025 2029 if(!!json_res.error){ 2030 toastr.error(`Error: ${json_res.error}`, "", {preventDuplicates: true, timeOut: 5000, positionClass: "toast-top-center"}); 2031 } 2032 2033 if(!!json_res.critical_error){ 2026 2034 $(".sirv-upload-ajax").hide(); 2027 toastr.error(`Error: ${json_res.error}`, "", {preventDuplicates: true, timeOut: 4000, positionClass: "toast-top-center"});2035 toastr.error(`Error: ${json_res.error}`, "", {preventDuplicates: true, timeOut: 5000, positionClass: "toast-top-center"}); 2028 2036 getContentFromSirv(window.sirvGetPath); 2029 2037 return; 2030 }2031 2032 if ( nextSlice < file.size ) {2033 uploadImageByChunk(fileItem, nextSlice, reader, partNum + 1, totalOverSizedFiles, currentDir);2034 2038 } 2035 2039 … … 2039 2043 realRequestSize = 0; 2040 2044 } 2045 2046 if ( nextSlice < file.size ) { 2047 uploadImageByChunk(fileItem, nextSlice, reader, partNum + 1, totalOverSizedFiles, currentDir); 2048 } 2049 2041 2050 } 2042 2051 }, … … 3873 3882 getPhpFilesLimitations(); 3874 3883 3884 $(document).tooltip({ 3885 classes:{ 3886 "ui-tooltip": "sirv-ui-widget-content sirv-ui-corner-all sirv-ui-widget-shadow", 3887 }, 3888 show: false, 3889 hide: false, 3890 position: { 3891 my: "left bottom-25", 3892 at: "left bottom", 3893 collision: "flipfit", 3894 }, 3895 }); 3896 3875 3897 if($('.sirv-items-container').length > 0) getContentFromSirv(); 3876 3898 -
sirv/trunk/plugdata/media_library.php
r3039643 r3186406 26 26 wp_enqueue_style('sirv_style'); 27 27 28 wp_enqueue_script( 'sirv_logic', plugins_url('js/wp-sirv.js', __FILE__), array( 'jquery', 'jquery-ui- sortable', 'sirv_toast_js' ), false);28 wp_enqueue_script( 'sirv_logic', plugins_url('js/wp-sirv.js', __FILE__), array( 'jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'sirv_toast_js' ), false); 29 29 wp_localize_script( 'sirv_logic', 'sirv_ajax_object', array( 30 30 'ajaxurl' => admin_url( 'admin-ajax.php' ), -
sirv/trunk/plugdata/submenu_pages/sync.php
r3162079 r3186406 22 22 </tr> 23 23 <tr> 24 <td >25 <h 2>WordPress media</h2>24 <td class="sirv-media-lib-title"> 25 <h3>Your WordPress media library</h3> 26 26 </td> 27 27 </tr> … … 42 42 </div> 43 43 <div class="sirv-calc-library-size-view-column sirv-calc-library-size-view-data"> 44 <div class="sirv-calc-library-size-show-analizing"><span class="sirv-traffic-loading-ico"></span>Analizing... <span class="sirv-calc-library-size-analizing-progress">0%</span></div>44 <div class="sirv-calc-library-size-show-analizing"><span class="sirv-traffic-loading-ico"></span>Analizing... <span class="sirv-calc-library-size-analizing-progress">0%</span></div> 45 45 <div class="sirv-calc-media-size-data"> 46 46 <span class="sirv-calc-media-size-approx_symbol"><?php echo $approximately_symbol; ?></span> … … 71 71 <tr> 72 72 <td colspan="2"> 73 <h3>S tatus</h3>74 <p class="sirv-options-desc"> Images are copied to Sirv the first time they are viewed, which can take 1-2 seconds per image. To perform a full synchronization now, click Sync images:</p>73 <h3>Sync to Sirv</h3> 74 <p class="sirv-options-desc">Your images will automatically copy to Sirv the first time they're viewed. This usually takes 1-2 seconds per image.</p> 75 75 </td> 76 76 </tr> … … 204 204 <span class="sirv-traffic-loading-ico" style="display: none;"></span> 205 205 </div> 206 </td> 207 </tr> 208 <tr> 209 <td> 210 <p>You can pre-sync all images to Sirv. This will remove the 1-2 second delay the first time an image is requested.</p> 206 211 </td> 207 212 </tr> -
sirv/trunk/readme.txt
r3162079 r3186406 5 5 Requires PHP: 5.6 6 6 Requires at least: 3.0.1 7 Tested up to: 6. 67 Tested up to: 6.7 8 8 Stable tag: trunk 9 9 License: GPLv2 or later … … 240 240 == Changelog == 241 241 242 = 7.3.1 (2024-11-12) = 243 * Tested with the latest WordPress version 6.7. 244 * Improved security for uploading large images. 245 * Improved integration with WooCommerce variation images. 246 * Improved detection of media uploaded to Sirv folders. 247 * Improved loading of custom Sirv JS global options. 248 * Improved design of the Synchronization tab. 249 * Fixed issue with incorrect initialization of Advanced Editor Tools (TinyMCE plugin). 250 * Many small fixes and optimizations. 251 242 252 = 7.3.0 (2024-10-03) = 243 253 * Improved plugin security. -
sirv/trunk/sirv.php
r3162079 r3186406 5 5 * Plugin URI: http://sirv.com 6 6 * Description: Fully-automatic image optimization, next-gen formats (WebP), responsive resizing, lazy loading and CDN delivery. Every best-practice your website needs. Use "Add Sirv Media" button to embed images, galleries, zooms, 360 spins and streaming videos in posts / pages. Stunning media viewer for WooCommerce. Watermarks, text titles... every WordPress site deserves this plugin! <a href="admin.php?page=sirv/data/options.php">Settings</a> 7 * Version: 7.3. 07 * Version: 7.3.1 8 8 * Requires PHP: 5.6 9 9 * Requires at least: 3.0.1 … … 16 16 17 17 18 define('SIRV_PLUGIN_VERSION', '7.3. 0');18 define('SIRV_PLUGIN_VERSION', '7.3.1'); 19 19 define('SIRV_PLUGIN_DIR', 'sirv'); 20 20 define('SIRV_PLUGIN_SUBDIR', 'plugdata'); … … 121 121 122 122 123 //filters for export products woo feature 124 add_filter('woocommerce_product_export_column_names', 'sirv_add_column_to_export_csv'); 125 add_filter('woocommerce_product_export_product_default_columns', 'sirv_add_column_to_export_csv'); 126 function sirv_add_column_to_export_csv( $columns ) { 127 128 // column slug => column name 129 $columns['sirv_woo_all_urls'] = 'Sirv product media URLs'; 130 131 return $columns; 132 } 133 134 135 // Filter you want to hook into will be: 'woocommerce_product_export_product_column_{$column_slug}'. 136 add_filter('woocommerce_product_export_product_column_sirv_woo_all_urls', 'sirv_add_export_data', 10, 2); 137 function sirv_add_export_data( $value, $product ) { 138 //$product_id = $product->get_id(); 139 $post_type = $product->post_type; 140 $is_variation = $post_type == 'product_variation' ? true : false; 141 142 $woo = new Woo($product->get_id()); 143 $value = $woo->get_export_data_to_csv_column($is_variation); 144 /* sirv_qdebug($product_id, '$product_id'); 145 sirv_qdebug($value, '$value'); 146 147 $value = "TEST TEST TEST"; */ 148 return $value; 149 } 150 151 123 152 add_action('woocommerce_init', 'sirv_wc_init'); 124 153 function sirv_wc_init(){ … … 264 293 //TODO: Add posibillity to get size from html 265 294 function sirv_variation_image_html($image_html, $product_id, $variaition_id){ 266 $modified_image_html = $image_html;295 //$modified_image_html = $image_html; 267 296 $sirv_url = ''; 268 297 269 298 if ($variaition_id > 0) { 299 $image_tag_metadata = Utils::parse_html_tag_attrs($image_html); 300 $width = isset($image_tag_metadata['width']) ? $image_tag_metadata['width'] : 300; 301 $height = isset($image_tag_metadata['height']) ? $image_tag_metadata['height'] : 300; 302 270 303 $woo = new Woo($product_id); 271 304 … … 275 308 if ($wc_variation[0]->provider == 'sirv') { 276 309 $sirv_url = $wc_variation[0]->url; 277 $sirv_parametrized_url = sirv_get_parametrized_url($sirv_url, array(250, 250), true); 278 $modified_image_html = preg_replace('/(src=".*?")/', "src=\"$sirv_parametrized_url\"", $image_html); 310 $sirv_parametrized_url = sirv_get_parametrized_url($sirv_url, array($width, $height), true); 311 //$modified_image_html = preg_replace('/(src=".*?")/', "src=\"$sirv_parametrized_url\"", $image_html); 312 $image_tag_metadata['src'] = $sirv_parametrized_url; 279 313 } else { 280 314 return $image_html; … … 291 325 292 326 if (!empty($sirv_url)) { 293 $sirv_parametrized_url = sirv_get_parametrized_url($sirv_url, array(250, 250), true); 294 $modified_image_html = preg_replace('/(src=".*?")/', "src=\"$sirv_parametrized_url\"", $image_html); 327 $sirv_parametrized_url = sirv_get_parametrized_url($sirv_url, array($width, $height), true); 328 //$modified_image_html = preg_replace('/(src=".*?")/', "src=\"$sirv_parametrized_url\"", $image_html); 329 $image_tag_metadata['src'] = $sirv_parametrized_url; 295 330 } 296 } 297 } 298 299 return $modified_image_html; 331 //return $modified_image_html; 332 return Utils::build_html_tag('img', $image_tag_metadata, array('srcset', 'sizes', 'data-src')); 333 } 334 } 335 336 return $image_html; 300 337 } 301 338 … … 1363 1400 wp_enqueue_style('sirv_mce_style'); 1364 1401 1365 wp_register_script('sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array('jquery', 'jquery-ui- sortable', 'sirv_toast_js'), false);1402 wp_register_script('sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'sirv_toast_js'), false); 1366 1403 wp_localize_script('sirv_logic', 'sirv_ajax_object', array( 1367 1404 'ajaxurl' => admin_url('admin-ajax.php'), … … 1454 1491 wp_register_style('sirv_mce_style', SIRV_PLUGIN_SUBDIR_URL_PATH . 'css/wp-sirv-shortcode-view.css'); 1455 1492 wp_enqueue_style('sirv_mce_style'); 1456 wp_register_script('sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array('jquery', 'jquery-ui-sortable', 'sirv_toast_js'), '1.1.0');1493 wp_register_script('sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array('jquery','jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'sirv_toast_js'), '1.1.0'); 1457 1494 wp_localize_script('sirv_logic', 'sirv_ajax_object', array( 1458 1495 'ajaxurl' => admin_url('admin-ajax.php'), … … 1530 1567 wp_register_style('sirv_style', SIRV_PLUGIN_SUBDIR_URL_PATH . 'css/wp-sirv.css'); 1531 1568 wp_enqueue_style('sirv_style'); 1532 wp_enqueue_script('sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array('jquery', 'jquery-ui-sortable', 'sirv_toast_js'), false);1569 wp_enqueue_script('sirv_logic', SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv.js', array('jquery','jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'sirv_toast_js'), false); 1533 1570 wp_localize_script('sirv_logic', 'sirv_ajax_object', array( 1534 1571 'ajaxurl' => admin_url('admin-ajax.php'), … … 1571 1608 add_filter('mce_external_plugins', 'sirv_tinyMCE_plugin_shortcode_view'); 1572 1609 1573 function sirv_tinyMCE_plugin_shortcode_view(){ 1574 return array('sirvgallery' => SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv-shortcode-view.js'); 1610 function sirv_tinyMCE_plugin_shortcode_view($plugins){ 1611 $plugins['sirvgallery'] = SIRV_PLUGIN_SUBDIR_URL_PATH . 'js/wp-sirv-shortcode-view.js'; 1612 1613 return $plugins; 1575 1614 } 1576 1615 … … 1853 1892 $sirv_js_path = getValue::getOption('SIRV_JS_FILE'); 1854 1893 1894 global $post; 1895 1855 1896 wp_register_script('sirv-js', $sirv_js_path, array(), false, false); 1856 1897 wp_enqueue_script('sirv-js'); 1898 1899 if (isset($post->post_type) && $post->post_type == 'product') { 1900 $sirv_woo_is_enable_option = get_option('SIRV_WOO_IS_ENABLE'); 1901 $sirv_woo_is_enable = !empty($sirv_woo_is_enable_option) && $sirv_woo_is_enable_option == '2' ? true : false; 1902 if( $sirv_woo_is_enable ){ 1903 $woo = new Woo($post->ID); 1904 $mv_custom_options = $woo->remove_script_tag(get_option('SIRV_WOO_MV_CUSTOM_OPTIONS')); 1905 1906 wp_add_inline_script('sirv-js', $mv_custom_options, 'after'); 1907 } 1908 } 1857 1909 } 1858 1910 … … 1896 1948 $sirv_js_path = getValue::getOption('SIRV_JS_FILE'); 1897 1949 1950 global $post; 1951 1952 $mv_custom_options_block = ''; 1953 1954 if (isset($post->post_type) && $post->post_type == 'product') { 1955 $sirv_woo_is_enable_option = get_option('SIRV_WOO_IS_ENABLE'); 1956 $sirv_woo_is_enable = !empty($sirv_woo_is_enable_option) && $sirv_woo_is_enable_option == '2' ? true : false; 1957 if ($sirv_woo_is_enable) { 1958 $woo = new Woo($post->ID); 1959 $mv_custom_options = $woo->remove_script_tag(get_option('SIRV_WOO_MV_CUSTOM_OPTIONS')); 1960 $mv_custom_options_block = !empty($mv_custom_options) ? PHP_EOL . '<script nowprocket>' . PHP_EOL . $mv_custom_options . PHP_EOL . '</script>' . PHP_EOL : ''; 1961 1962 } 1963 } 1964 1898 1965 if(preg_match($link_prefetch_pattern, $content) === 1){ 1899 $content = preg_replace($link_prefetch_pattern, '$1<script src="' . $sirv_js_path . '"></script>', $content, 1);1966 $content = preg_replace($link_prefetch_pattern, '$1'. PHP_EOL .'<script src="' . $sirv_js_path . '"></script>'. $mv_custom_options_block, $content, 1); 1900 1967 }else{ 1901 1968 $content = preg_replace('/(<\/head>)/is', '<script src="' . $sirv_js_path . '"></script>$1', $content, 1); … … 2029 2096 $url = wp_get_attachment_url($attachment_id); 2030 2097 2098 if( !$url ) return false; 2099 2031 2100 if (sirv_is_sirv_item($url)) { 2032 2101 $post = get_post($attachment_id); … … 2078 2147 2079 2148 function sirv_is_sirv_item($url){ 2080 if( empty($url) ) return false; 2081 //$sirv_cdn_url = get_option('SIRV_CDN_URL'); 2082 $sirv_cdn_url = sirv_get_cached_cdn_url(); 2083 $sirv_url = empty($sirv_cdn_url) ? 'sirv.com' : $sirv_cdn_url; 2084 return stripos($url, $sirv_url) !== false; 2149 if( empty($url) ) return false; 2150 2151 //does not give 100% guarantee that this is sirv image 2152 $count = substr_count($url, 'http'); 2153 if( $count > 1 ) return true; 2154 2155 //$sirv_cdn_url = get_option('SIRV_CDN_URL'); 2156 $sirv_cdn_url = sirv_get_cached_cdn_url(); 2157 $sirv_url = empty($sirv_cdn_url) ? 'sirv.com' : $sirv_cdn_url; 2158 return stripos($url, $sirv_url) !== false; 2085 2159 } 2086 2160 … … 2616 2690 2617 2691 if( empty($size)){ 2618 if( $sirv_item_type_data[' sirv_type'] == 'video' ) return sirv_add_profile($sirv_image . "?thumbnail=500");2619 if( $sirv_item_type_data[' sirv_type'] == 'spin' ) return sirv_add_profile($sirv_image . "?thumb");2692 if( $sirv_item_type_data['type'] == 'video' ) return sirv_add_profile($sirv_image . "?thumbnail=500"); 2693 if( $sirv_item_type_data['type'] == 'spin' ) return sirv_add_profile($sirv_image . "?thumb"); 2620 2694 2621 2695 return sirv_add_profile($sirv_image); … … 2624 2698 $item_show_pattern = ''; 2625 2699 2626 if( $sirv_item_type_data[' sirv_type'] == 'video' ){2700 if( $sirv_item_type_data['type'] == 'video' ){ 2627 2701 $image = sirv_get_correct_item_size($size, $isCrop); 2628 2702 $url = $sirv_image . "?thumbnail=" . $image['width']; 2629 2703 return sirv_add_profile($url); 2630 2704 2631 }else if( $sirv_item_type_data[' sirv_type'] == 'spin' ){2705 }else if( $sirv_item_type_data['type'] == 'spin' ){ 2632 2706 $item_show_pattern = "?thumb"; 2633 2707 } … … 4694 4768 function sirv_upload_file_by_chunks_callback(){ 4695 4769 if (!(is_array($_POST) && isset($_POST['binPart']) && defined('DOING_AJAX') && DOING_AJAX)) { 4696 return; 4770 echo json_encode(array('critical_error' => 'AJAX not allowed')); 4771 wp_die(); 4697 4772 } 4698 4773 4699 4774 if (!sirv_is_allow_ajax_connect('sirv_logic_ajax_validation_nonce', 'edit_posts')) { 4700 echo json_encode(array(' error' => 'Access to the requested resource is forbidden'));4775 echo json_encode(array('critical_error' => 'Access to the requested resource is forbidden')); 4701 4776 wp_die(); 4702 4777 } 4703 4778 4779 $response = array(); 4780 $error = ''; 4704 4781 $is_upload_file = true; 4705 4706 4782 $arr_content = array(); 4707 4783 … … 4718 4794 4719 4795 if( !$tmp_filepath ){ 4720 echo json_encode(array(' error' => 'Can\'t create tmp file. Please check if php tmp path is correctly set.'));4796 echo json_encode(array('critical_error' => 'Can\'t create tmp file. Please check if php tmp path is correctly set')); 4721 4797 wp_die(); 4722 4798 } … … 4736 4812 4737 4813 if($partNum < $totalParts){ 4738 echo json_encode(array('status' => 'processing', 'stop' => false)); 4814 $response['status'] = 'processing'; 4815 $response['stop'] = false; 4739 4816 4740 4817 } … … 4744 4821 4745 4822 $mime_type = Utils::get_mime_type($tmp_filepath); 4746 4747 4823 if( in_array($mime_type, $disallowed_types) ){ 4748 4824 unlink($tmp_filepath); 4749 delete_option($filename); 4750 4751 echo json_encode(array('error' => 'File type is not allowed')); 4752 wp_die(); 4753 } 4754 4755 //sanitize svg file before upload 4756 if (Utils::get_mime_subtype($tmp_filepath) == 'svg+xml') { 4757 $is_upload_file = sirv_sanitize_svg($tmp_filepath); 4758 } 4759 4760 4761 4762 if($is_upload_file){ 4763 $APIClient = sirv_getAPIClient(); 4764 $result = $APIClient->uploadImage($tmp_filepath, $sirv_path); 4765 4766 unlink($tmp_filepath); 4767 delete_option($filename); 4768 }else{ 4769 $filename = basename(urldecode($sirv_path)); 4770 $result['error'] = "SVG file $filename cannot be sanitized. Upload is forbidden"; 4771 } 4772 4773 4774 if( isset($result["error"]) ){ 4775 echo json_encode(array('error' => $result["error"])); 4776 wp_die(); 4777 } 4825 sirv_remove_tmp_option($filename); 4826 4827 $error ="File $filename type is not allowed"; 4828 } 4829 4830 if( !$error ){ 4831 //sanitize svg file before upload 4832 if ( Utils::get_mime_subtype($tmp_filepath) == 'svg+xml' ) { 4833 $is_upload_file = sirv_sanitize_svg($tmp_filepath); 4834 } 4835 4836 if( $is_upload_file ){ 4837 $APIClient = sirv_getAPIClient(); 4838 $result = $APIClient->uploadImage($tmp_filepath, $sirv_path); 4839 }else{ 4840 $filename = basename(urldecode($sirv_path)); 4841 $error = "SVG file $filename cannot be sanitized. Upload is forbidden"; 4842 } 4843 4844 4845 @unlink($tmp_filepath); 4846 sirv_remove_tmp_option($filename); 4847 } 4848 4778 4849 4779 4850 session_id("image-uploading-status"); … … 4788 4859 4789 4860 if ($arr_content['processedImage'] == $arr_content['count']){ 4790 echo json_encode(array('stop' => true)); 4861 $response['stop'] = true; 4862 $response['status'] = 'done'; 4791 4863 }else{ 4792 echo json_encode(array('status' => 'processing', 'stop' => false)); 4793 } 4794 } 4795 4864 $response['status'] = 'processing'; 4865 $response['stop'] = false; 4866 } 4867 } 4868 4869 if ($error) $response['error'] = $error; 4870 4871 echo json_encode($response); 4796 4872 wp_die(); 4797 4873 } 4798 4874 4799 4875 4800 function sirv_get_tmp_filename($db_key){ 4801 $tmp_filepath = get_option($db_key); 4876 function sirv_get_tmp_filename($raw_option_key){ 4877 4878 $option_key = sirv_get_tmp_option_name($raw_option_key); 4879 $tmp_filepath = get_option($option_key); 4802 4880 4803 4881 if( $tmp_filepath ){ … … 4808 4886 4809 4887 if($tmp_filepath){ 4810 update_option($ db_key, $tmp_filepath);4888 update_option($option_key, $tmp_filepath); 4811 4889 } 4812 4890 … … 4815 4893 return $tmp_filepath; 4816 4894 4895 } 4896 4897 4898 function sirv_get_tmp_option_name($filename){ 4899 return "SIRV_TMP_FILEPATH" . '_' . md5($filename); 4900 } 4901 4902 4903 function sirv_remove_tmp_option($raw_option_key){ 4904 $option_key = sirv_get_tmp_option_name($raw_option_key); 4905 delete_option($option_key); 4817 4906 } 4818 4907 … … 5893 5982 ); */ 5894 5983 $media_storage_data = array( 5895 'date' => date('\o\n F d, Y'),5984 'date' => date('\o\n F j, Y'), 5896 5985 'size' => Utils::getFormatedFileSize($upload_space), 5897 5986 'img_count' => $post_images_count … … 5953 6042 if( in_array($stored_data['status'], array('initial', 'done', 'stopped')) ){ 5954 6043 $stored_data['all_images_count'] = sirv_get_all_post_images_count(); 5955 $stored_data['date'] = date('F d, Y');6044 $stored_data['date'] = date('F j, Y'); 5956 6045 } 5957 6046 … … 6476 6565 //if (is_admin() || $isAdmin) return; 6477 6566 6567 $forbidden_actions = array('query-attachments'); 6568 6478 6569 if (defined('DOING_AJAX') && DOING_AJAX) { 6479 6570 $action = ''; … … 6484 6575 $action = isset($_GET['action']) ? $_GET['action'] : ''; 6485 6576 } 6577 6578 if(in_array($action, $forbidden_actions)) return; 6486 6579 6487 6580 if (!empty($action) && sirv_is_frontend_ajax($action)) {
Note: See TracChangeset
for help on using the changeset viewer.