Commit inicial powerservice
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Addons
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
?>
|
||||
<div id="compressx-root">
|
||||
<div id="compressx-wrap">
|
||||
<?php
|
||||
$this->output_nav();
|
||||
$this->output_header();
|
||||
$this->output_addons();
|
||||
$this->output_footer();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_nav()
|
||||
{
|
||||
do_action('compressx_output_nav');
|
||||
}
|
||||
|
||||
public function output_header()
|
||||
{
|
||||
do_action('compressx_output_header');
|
||||
}
|
||||
|
||||
public function output_addons()
|
||||
{
|
||||
?>
|
||||
<header>
|
||||
<div class="compressx-container compressx-header">
|
||||
<div class="compressx-header-dashboard">
|
||||
<h5>Addons <a href="https://compressx.io">(Pro Only)</a></h5>
|
||||
</div>
|
||||
<div class="compressx-addons-grid">
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-admin-generic compressx-icon-style" style="color:green"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Advanced Compression Level Settings</h5>
|
||||
<span>Maximize image optimization with smart algorithms that reduce file size while preserving visual quality. Ideal for users who want the best balance of speed and image clarity for their site</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-admin-appearance compressx-icon-style"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Remove JPG/PNG Thumbnails</h5>
|
||||
<span>Automatically delete original JPG/PNG thumbnails after converting them to WebP or AVIF to free up disk space.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-calendar-alt compressx-icon-style"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Cron Support</h5>
|
||||
<span>Automates your image optimization workflows with a robust cron system, flexibly scheduling AVIF/WebP conversions for new, existing, and popular images.</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-format-gallery compressx-icon-style" style="color:#f25767"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Thumbnails Generation/reGeneration</h5>
|
||||
<span>Regenerate thumbnails (WebP, AVIF, JPG, or PNG) for your website images based on your settings. Add custom thumbnail sizes. Remove unused and orphan thumbnails and their metadata.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-shortcode compressx-icon-style" style="color:#071c4d"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>WP-CLI</h5>
|
||||
<span>Use WP-CLI to efficiently convert images in your WordPress media library. You can choose to convert all images, or a specific image, or convert the latest n images(coming soon).</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-cover-image compressx-icon-style"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Watermark</h5>
|
||||
<span>Add watermarks to your images during the process of uploading, bulk WebP/AVIF conversion, and thumbnail regeneration (WebP, AVIF, JPG, or PNG).</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-cloud compressx-icon-style"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>CDN Integration</h5>
|
||||
<span>Integrate with Cloudflare pro to convert and serve your website images as WebP/AVIF formats. Enable ‘Vary for images’ to dynamically serve correct variants.</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-groups compressx-icon-style" style="color:#f25767"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Roles and Capabilities</h5>
|
||||
<span>Control CompressX Pro settings and features by setting a super admin. The super admin can grant access for other user roles include admin.</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="cx-addons" style="position: relative;">
|
||||
<div class="cx-addons-icon-block">
|
||||
<span class="dashicons dashicons-wordpress compressx-icon-style" style="color:#ffb116"></span>
|
||||
</div>
|
||||
<div>
|
||||
<h5>Multisite Support</h5>
|
||||
<span>Coming soon..</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_footer()
|
||||
{
|
||||
do_action('compressx_output_footer');
|
||||
}
|
||||
}
|
||||
+409
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Advanced_Compression_Level_Display
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
//add_action('wp_ajax_compressx_save_compression', array($this, 'save_compression'));
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
?>
|
||||
<div id="compressx-root">
|
||||
<div id="compressx-wrap">
|
||||
<?php
|
||||
$this->output_nav();
|
||||
$this->output_header();
|
||||
$this->output_advanced_custom_compression_level();
|
||||
$this->output_footer();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_nav()
|
||||
{
|
||||
do_action('compressx_output_nav');
|
||||
}
|
||||
|
||||
public function output_header()
|
||||
{
|
||||
do_action('compressx_output_header');
|
||||
}
|
||||
|
||||
public function output_footer()
|
||||
{
|
||||
do_action('compressx_output_footer');
|
||||
}
|
||||
|
||||
public function output_advanced_custom_compression_level()
|
||||
{
|
||||
$options=CompressX_Options::get_option('compressx_quality',array());
|
||||
$quality=isset($options['quality'])?$options['quality']:'lossy';
|
||||
$quality_webp=isset($options['quality_webp'])?$options['quality_webp']: 80;
|
||||
$quality_avif=isset($options['quality_avif'])?$options['quality_avif']: 60;
|
||||
?>
|
||||
<section>
|
||||
<div class="compressx-container compressx-section ">
|
||||
<div class="compressx-general-settings">
|
||||
<div class="compressx-general-settings-header" style="position: relative;">
|
||||
<h5><span>Advanced Custom Compression Level Settings</span></h5>
|
||||
</div>
|
||||
<div class="compressx-general-settings-body">
|
||||
<div class="compressx-general-settings-body-grid">
|
||||
<div>
|
||||
<span>
|
||||
<span class="dashicons dashicons-admin-site"></span><strong>Global compression level</strong>
|
||||
</span>
|
||||
<p style="padding-left: 2rem;">
|
||||
<span>Webp<input id="cx_quality_webp" type="text" style="width: 2.5rem;" value="<?php echo esc_attr($quality_webp); ?>"></span><span style="padding: 0 0.5rem;"></span>
|
||||
<span>AVIF<input id="cx_quality_avif" type="text" style="width: 2.5rem;" value="<?php echo esc_attr($quality_avif); ?>"></span>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<div class="compressing-converting-information">
|
||||
|
||||
<span><strong>Compression Levels by Categories</strong> have <strong>higher</strong> priority than the <strong>global compression level.</strong>
|
||||
This means that images assigned to specific categories will use their category's compression level to be processed, while all other images will fall back to the global compression setting.</span><br>
|
||||
<span>You can choose which image categories should receive special compression treatment.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<strong><span class="dashicons dashicons-wordpress" style="color:#00749C"></span><span>Compression Levels by Category (WordPress Standard Image Types)</span></strong>
|
||||
<span><a href="https://compressx.io">(Pro only)</a></span>
|
||||
</p>
|
||||
<div class="compressx-table" style="padding-bottom: 2rem;">
|
||||
<div class="compressx-table-3-cols-header">
|
||||
<div><strong><input type="checkbox" title="Check all" class="cx-table-all-check" disabled>Image Usage Type</strong></div>
|
||||
<div><strong>Webp/AVIF</strong></div>
|
||||
<div><strong>Recommended Compression Level</strong></div>
|
||||
</div>
|
||||
<?php
|
||||
$list=$this->get_advanced_custom_compression_list();
|
||||
foreach ($list as $item)
|
||||
{
|
||||
if($item['enable'])
|
||||
{
|
||||
$quality_enbale="checked";
|
||||
}
|
||||
else
|
||||
{
|
||||
$quality_enbale="";
|
||||
}
|
||||
?>
|
||||
<div class="compressx-table-3-cols-body">
|
||||
<div>
|
||||
<input class="cx-table-check" type="checkbox" <?php echo esc_attr($quality_enbale); ?> option="cx_advanced_quality_enable" name="<?php echo esc_attr($item['type']); ?>" disabled>
|
||||
<span><strong><?php echo esc_html($item['display']); ?></strong></span>
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" style="width: 2.5rem;" option="cx_advanced_webp_quality" name="<?php echo esc_attr($item['type']); ?>" value="<?php echo esc_attr($item['webp']); ?>" disabled>
|
||||
<input type="text" style="width: 2.5rem;" option="cx_advanced_avif_quality" name="<?php echo esc_attr($item['type']); ?>" value="<?php echo esc_attr($item['avif']); ?>" disabled>
|
||||
</div>
|
||||
<div>
|
||||
<span class="compressx-compression-level-items">
|
||||
<?php echo esc_html($item['description']); ?>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="compressx-table-3-cols-footer">
|
||||
<div><strong><input type="checkbox" title="Check all" class="cx-table-all-check" disabled>Image Usage Type</strong></div>
|
||||
<div><strong>Webp/AVIF</strong></div>
|
||||
<div><strong>Recommended Compression Level</strong></div>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<strong><span class="dashicons dashicons-cart" style="color:#96588a"></span>Compression Levels by Category (WooCommerce Image Type)</strong>
|
||||
<span><a href="https://compressx.io">(Pro only)</a></span>
|
||||
</p>
|
||||
<div class="compressx-table">
|
||||
<div class="compressx-table-3-cols-header">
|
||||
<div><strong><input type="checkbox" title="Check all" class="cx-woo-table-all-check" disabled>Image Usage Type</strong></div>
|
||||
<div><strong>Webp/AVIF</strong></div>
|
||||
<div><strong>Recommended Compression Level</strong></div>
|
||||
</div>
|
||||
<?php
|
||||
$list=$this->get_advanced_custom_woocommerce_compression_list();
|
||||
foreach ($list as $item)
|
||||
{
|
||||
if($item['enable'])
|
||||
{
|
||||
$quality_enbale="checked";
|
||||
}
|
||||
else
|
||||
{
|
||||
$quality_enbale="";
|
||||
}
|
||||
?>
|
||||
<div class="compressx-table-3-cols-body">
|
||||
<div>
|
||||
<input class="cx-woo-table-check" type="checkbox" <?php echo esc_attr($quality_enbale); ?> option="cx_advanced_quality_enable" name="<?php echo esc_attr($item['type']); ?>" disabled>
|
||||
<span><strong><?php echo esc_html($item['display']); ?></strong></span>
|
||||
</div>
|
||||
<div>
|
||||
<input type="text" style="width: 2.5rem;" option="cx_advanced_webp_quality" name="<?php echo esc_attr($item['type']); ?>" value="<?php echo esc_attr($item['webp']); ?>" disabled>
|
||||
<input type="text" style="width: 2.5rem;" option="cx_advanced_avif_quality" name="<?php echo esc_attr($item['type']); ?>" value="<?php echo esc_attr($item['avif']); ?>" disabled>
|
||||
</div>
|
||||
<div>
|
||||
<span class="compressx-compression-level-items">
|
||||
<?php echo esc_html($item['description']); ?>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<div class="compressx-table-3-cols-footer">
|
||||
<div><strong><input type="checkbox" title="Check all" class="cx-woo-table-all-check" disabled>Image Usage Type</strong></div>
|
||||
<div><strong>Webp</strong></div>
|
||||
<div><strong>AVIF</strong></div>
|
||||
</div>
|
||||
<div class="compressx-compression-level">
|
||||
<div class="compressx-compression-level-items"><span class="compressx-compression-level-item-high" style="background-color:#4caf50"></span><span><strong>High Quality</strong></span></div>
|
||||
<div class="compressx-compression-level-items"><span class="compressx-compression-level-item-high" style="background-color:#ffeb3b"></span><span><strong>Balanced Quality</strong></span></div>
|
||||
<div class="compressx-compression-level-items"><span class="compressx-compression-level-item-high" style="background-color:#ff9800"></span><span><strong>Medium Quality</strong></span></div>
|
||||
<div class="compressx-compression-level-items"><span class="compressx-compression-level-item-high" style="background-color:#f44336"></span><span><strong>Aggressive Quality</strong></span></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="compressx-general-settings-footer">
|
||||
<input class="button-primary cx-button" id="compressx_save_advance_compression" type="submit" value="Save Changes">
|
||||
<span style="padding:0 0.2rem;"></span>
|
||||
<span id="compressx_save_advance_progress" style="display: none">
|
||||
<img src="../wp-admin/images/loading.gif" alt="">
|
||||
</span>
|
||||
<span id="compressx_save_advance_text" class="success hidden" aria-hidden="true" style="color:#007017"><?php esc_html_e('Saved!','compressx')?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<script>
|
||||
//
|
||||
jQuery('.cx-table-all-check').click(function()
|
||||
{
|
||||
var check=true;
|
||||
if(jQuery(this).prop('checked'))
|
||||
{
|
||||
check = true;
|
||||
}
|
||||
else {
|
||||
check = false;
|
||||
}
|
||||
|
||||
jQuery('input[type="checkbox"].cx-table-check').each(function()
|
||||
{
|
||||
jQuery(this).prop('checked',check);
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('.cx-woo-table-all-check').click(function()
|
||||
{
|
||||
var check=true;
|
||||
if(jQuery(this).prop('checked'))
|
||||
{
|
||||
check = true;
|
||||
}
|
||||
else {
|
||||
check = false;
|
||||
}
|
||||
|
||||
jQuery('input[type="checkbox"].cx-woo-table-check').each(function()
|
||||
{
|
||||
jQuery(this).prop('checked',check);
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('#compressx_save_advance_compression').click(function()
|
||||
{
|
||||
compressx_save_advance_compression();
|
||||
});
|
||||
|
||||
function compressx_save_advance_compression()
|
||||
{
|
||||
var webp_quality = jQuery('#cx_quality_webp').val();
|
||||
var avif_quality = jQuery('#cx_quality_avif').val();
|
||||
|
||||
var ajax_data = {
|
||||
'action': 'compressx_save_compression',
|
||||
'webp_quality': webp_quality,
|
||||
'avif_quality': avif_quality
|
||||
};
|
||||
jQuery('#compressx_save_advance_compression').css({'pointer-events': 'none', 'opacity': '0.4'});
|
||||
jQuery('#compressx_save_advance_progress').show();
|
||||
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
jQuery('#compressx_save_advance_compression').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_save_advance_progress').hide();
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#compressx_save_advance_text').removeClass("hidden");
|
||||
setTimeout(function ()
|
||||
{
|
||||
jQuery('#compressx_save_advance_text').addClass( 'hidden' );
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
alert(err);
|
||||
jQuery('#compressx_save_advance_compression').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_save_advance_progress').hide();
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
jQuery('#compressx_save_advance_compression').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_save_advance_progress').hide();
|
||||
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function get_advanced_custom_compression_list()
|
||||
{
|
||||
$advanced_quality_list=CompressX_Options::get_default_advanced_quality_option();
|
||||
$display_list=array();
|
||||
foreach ($advanced_quality_list as $type=>$item)
|
||||
{
|
||||
$item['type']=$type;
|
||||
$item['display']=$this->get_advanced_quality_display_name($type);
|
||||
$item['description']=$this->get_advanced_quality_description($type);
|
||||
$display_list[]=$item;
|
||||
}
|
||||
|
||||
return $display_list;
|
||||
}
|
||||
|
||||
public function get_advanced_custom_woocommerce_compression_list()
|
||||
{
|
||||
$advanced_quality_list=CompressX_Options::get_default_advanced_woocommerce_quality_option();
|
||||
$display_list=array();
|
||||
foreach ($advanced_quality_list as $type=>$item)
|
||||
{
|
||||
$item['type']=$type;
|
||||
$item['display']=$this->get_advanced_quality_display_name($type);
|
||||
$item['description']=$this->get_advanced_quality_description($type);
|
||||
$display_list[]=$item;
|
||||
}
|
||||
|
||||
return $display_list;
|
||||
}
|
||||
|
||||
public function get_advanced_quality_display_name($type)
|
||||
{
|
||||
$list= [
|
||||
// core
|
||||
'site_logo' => ['display' => 'Site logo'],
|
||||
'header_background' => ['display' => 'Header background image'],
|
||||
'featured_post' => ['display' => 'Featured image (Post)'],
|
||||
'featured_page' => ['display' => 'Featured image (Page)'],
|
||||
'sidebar_widget' => ['display' => 'Image in sidebar'],
|
||||
'acf_image_fields' => ['display' => 'Image field used via ACF(Advanced Custom Fields)'],
|
||||
|
||||
// WooCommerce
|
||||
'wc_product_featured_images' => ['display' => 'Product featured image'],
|
||||
'wc_product_gallery_images' => ['display' => 'Product gallery image'],
|
||||
'wc_variation_images' => ['display' => 'Variation-specific image'],
|
||||
'wc_product_category_images' => ['display' => 'Category image (taxonomy thumbnail)'],
|
||||
];
|
||||
return isset($list[$type]['display'])?$list[$type]['display']:'';
|
||||
}
|
||||
|
||||
public function get_advanced_quality_description($type)
|
||||
{
|
||||
$list= [
|
||||
// core
|
||||
'site_logo' => ['level' => 'high','text'=>'Webp (90+), AVIF (90+)---branding clarity is essential'],
|
||||
'header_background' => ['level' => 'mid','text'=>'Webp (75-85), AVIF (75-85)---may span full width, retain clarity'],
|
||||
'featured_post' => ['level' => 'high','text'=>'Webp (85-90), AVIF (85-90)---visually impactful, often shared'],
|
||||
'featured_page' => ['level' => 'high','text'=>'Webp (85-90), AVIF (85-90)---visually impactful, often shared'],
|
||||
'sidebar_widget' => ['level' => 'aggressive','text'=>'Webp (60-75), AVIF (60-75)---small visual element'],
|
||||
'acf_image_fields' => ['level' => 'balanced','text'=>'Webp (70-80), AVIF (70-80)---depends on context, often supportive'],
|
||||
|
||||
// WooCommerce
|
||||
'wc_product_featured_images' => ['level' => 'high','text'=>'Webp (85-90), AVIF (85-90)---brand/visual integrity important'],
|
||||
'wc_product_gallery_images' => ['level' => 'mid','text'=>'Webp (75-85), AVIF (75-85)---visual but secondary to main image'],
|
||||
'wc_variation_images' => ['level' => 'mid','text'=>'Webp (75-85), AVIF (75-85)---often similar to gallery use'],
|
||||
'wc_product_category_images' => ['level' => 'balanced','text'=>'Webp (70-80), AVIF (70-80)---smaller, not full focus'],
|
||||
];
|
||||
|
||||
if(isset($list[$type]))
|
||||
{
|
||||
$html='';
|
||||
if($list[$type]['level']=='high')
|
||||
{
|
||||
$html.='<span class="compressx-compression-level-item-high" style="background-color:#4caf50"></span>';
|
||||
$html.='<span><strong>High</strong>';
|
||||
}
|
||||
else if($list[$type]['level']=='mid')
|
||||
{
|
||||
$html.='<span class="compressx-compression-level-item-high" style="background-color:#ff9800"></span>';
|
||||
$html.='<span><strong>Medium</strong>';
|
||||
}
|
||||
else if($list[$type]['level']=='aggressive')
|
||||
{
|
||||
$html.='<span class="compressx-compression-level-item-high" style="background-color:#f44336"></span>';
|
||||
$html.='<span><strong>Aggressive</strong>';
|
||||
}
|
||||
else if($list[$type]['level']=='balanced')
|
||||
{
|
||||
$html.='<span class="compressx-compression-level-item-high" style="background-color:#ffeb3b"></span>';
|
||||
$html.='<span><strong>Balanced</strong>';
|
||||
}
|
||||
|
||||
$html.='<span>: '.$list[$type]['text'].'</span></span>';
|
||||
return $html;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function save_compression()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-general-settings');
|
||||
|
||||
if(!isset($_POST['webp_quality']))
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
if(!isset($_POST['avif_quality']))
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
$webp_quality = sanitize_text_field($_POST['webp_quality']);
|
||||
$avif_quality = sanitize_text_field($_POST['avif_quality']);
|
||||
|
||||
$options=CompressX_Options::get_option('compressx_quality',array());
|
||||
|
||||
$options['quality_webp']=intval($webp_quality);
|
||||
$options['quality_avif']=intval($avif_quality);
|
||||
|
||||
CompressX_Options::update_option('compressx_quality',$options);
|
||||
|
||||
$ret['result']='success';
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Bulk_Action
|
||||
{
|
||||
public $end_shutdown_function;
|
||||
public function __construct()
|
||||
{
|
||||
add_action('wp_ajax_compressx_start_scan_unoptimized_image', array($this, 'start_scan_unoptimized_image'));
|
||||
add_action('wp_ajax_compressx_init_bulk_optimization_task', array($this, 'init_bulk_optimization_task'));
|
||||
add_action('wp_ajax_compressx_run_optimize', array($this, 'run_optimize'));
|
||||
add_action('wp_ajax_compressx_get_opt_progress', array($this, 'get_opt_progress'));
|
||||
}
|
||||
|
||||
public function start_scan_unoptimized_image()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-convert');
|
||||
|
||||
$force=isset($_POST['force'])?sanitize_key($_POST['force']):'0';
|
||||
if($force=='1')
|
||||
{
|
||||
$force=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$force=false;
|
||||
}
|
||||
|
||||
$start_row=isset($_POST['offset'])?sanitize_key($_POST['offset']):0;
|
||||
|
||||
$ret=CompressX_Image_Scanner::scan_unoptimized_images($force,$start_row);
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
public function init_bulk_optimization_task()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-convert');
|
||||
|
||||
$force=isset($_POST['force'])?sanitize_key($_POST['force']):'0';
|
||||
if($force=='1')
|
||||
{
|
||||
$force=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$force=false;
|
||||
}
|
||||
|
||||
$task=new CompressX_ImgOptim_Task();
|
||||
$ret=$task->init_task($force);
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
public function run_optimize()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-convert');
|
||||
|
||||
set_time_limit(120);
|
||||
$task=new CompressX_ImgOptim_Task();
|
||||
|
||||
$ret=$task->get_task_status();
|
||||
|
||||
if($ret['result']=='success'&&$ret['status']=='completed')
|
||||
{
|
||||
$this->flush($ret);
|
||||
$task->do_optimize_image();
|
||||
//echo wp_json_encode($ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo wp_json_encode($ret);
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
private function flush($ret)
|
||||
{
|
||||
$json=wp_json_encode($ret);
|
||||
if(!headers_sent())
|
||||
{
|
||||
header('Content-Length: '.strlen($json));
|
||||
header('Connection: close');
|
||||
header('Content-Encoding: none');
|
||||
}
|
||||
|
||||
|
||||
if (session_id())
|
||||
session_write_close();
|
||||
echo wp_json_encode($ret);
|
||||
|
||||
if(function_exists('fastcgi_finish_request'))
|
||||
{
|
||||
fastcgi_finish_request();
|
||||
}
|
||||
else
|
||||
{
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public function get_opt_progress()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-convert');
|
||||
|
||||
$task=new CompressX_ImgOptim_Task();
|
||||
|
||||
$result=$task->get_task_progress();
|
||||
|
||||
echo wp_json_encode($result);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_CDN
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action('wp_ajax_compressx_save_cdn', array($this, 'save_cdn'));
|
||||
add_action('wp_ajax_compressx_purge_cache', array($this, 'purge_cache'));
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
?>
|
||||
<div id="compressx-root">
|
||||
<div id="compressx-wrap">
|
||||
<?php
|
||||
$this->output_nav();
|
||||
$this->output_header();
|
||||
$this->output_cdn();
|
||||
$this->output_footer();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_nav()
|
||||
{
|
||||
do_action('compressx_output_nav');
|
||||
}
|
||||
|
||||
public function output_header()
|
||||
{
|
||||
do_action('compressx_output_header');
|
||||
}
|
||||
|
||||
public function output_footer()
|
||||
{
|
||||
do_action('compressx_output_footer');
|
||||
}
|
||||
|
||||
public function output_cdn()
|
||||
{
|
||||
$options=CompressX_Options::get_option('compressx_general_settings',array());
|
||||
|
||||
$zone_id=isset($options['cf_cdn']['zone_id'])?$options['cf_cdn']['zone_id']:'';
|
||||
$email=isset($options['cf_cdn']['email'])?$options['cf_cdn']['email']:'';
|
||||
$api_key=isset($options['cf_cdn']['api_key'])?$options['cf_cdn']['api_key']:'';
|
||||
|
||||
$auto_purge_cache=isset($options['cf_cdn']['auto_purge_cache'])?$options['cf_cdn']['auto_purge_cache']:true;
|
||||
|
||||
if($auto_purge_cache)
|
||||
{
|
||||
$auto_purge_cache='checked';
|
||||
}
|
||||
else
|
||||
{
|
||||
$auto_purge_cache='';
|
||||
}
|
||||
|
||||
$auto_purge_cache_after_manual=isset($options['cf_cdn']['auto_purge_cache_after_manual'])?$options['cf_cdn']['auto_purge_cache_after_manual']:true;
|
||||
|
||||
if($auto_purge_cache_after_manual)
|
||||
{
|
||||
$auto_purge_cache_after_manual='checked';
|
||||
}
|
||||
else
|
||||
{
|
||||
$auto_purge_cache_after_manual='';
|
||||
}
|
||||
|
||||
?>
|
||||
<section>
|
||||
<div class="compressx-container compressx-section ">
|
||||
<div class="compressx-general-settings">
|
||||
<div class="compressx-general-settings-header">
|
||||
<h5><?php esc_html_e('Cloudflare Integration','compressx')?></h5>
|
||||
</div>
|
||||
<div class="compressx-general-settings-body">
|
||||
<div class="compressx-general-settings-body-grid">
|
||||
<div class="compressing-converting" style="margin-top: 0;">
|
||||
<span class="cx-title">
|
||||
<strong><?php esc_html_e('Cloudflare E-mail: ','compressx')?></strong>
|
||||
</span>
|
||||
<p>
|
||||
<input style="width: 100%;" type="text" option="cf_cdn" name="email" value="<?php echo esc_attr($email); ?>" >
|
||||
</p>
|
||||
<span class="cx-title">
|
||||
<strong><?php esc_html_e('Global API Key: ','compressx')?></strong>
|
||||
</span>
|
||||
<p>
|
||||
<input style="width: 100%;" type="password" autocomplete="new-password" option="cf_cdn" name="api_key" value="<?php echo esc_attr($api_key); ?>" >
|
||||
</p>
|
||||
<span class="cx-title">
|
||||
<strong><?php esc_html_e('Zone ID: ','compressx')?></strong>
|
||||
</span>
|
||||
<p>
|
||||
<input style="width: 100%;" type="password" autocomplete="new-password" option="cf_cdn" name="zone_id" value="<?php echo esc_attr($zone_id); ?>" >
|
||||
</p>
|
||||
<span class="cx-title">
|
||||
<strong><?php esc_html_e('Purge Cache Automatically: ','compressx')?></strong>
|
||||
</span>
|
||||
<p>
|
||||
<input id="compressx_auto_purge_cache" type="checkbox" option="cf_cdn" name="auto_purge_cache" <?php echo esc_attr($auto_purge_cache); ?>>
|
||||
<?php esc_html_e('Purge all cache automatically after successfully converting images in bulk.','compressx')?>
|
||||
</p>
|
||||
<p>
|
||||
<input id="compressx_auto_purge_cache_after_manual" type="checkbox" option="cf_cdn" name="auto_purge_cache_after_manual" <?php echo esc_attr($auto_purge_cache_after_manual); ?>>
|
||||
<?php esc_html_e('Purge all cache automatically after 5 minutes of manually converting images on media library.','compressx')?>
|
||||
</p>
|
||||
</div>
|
||||
<div class="compressing-converting">
|
||||
<div class="compressing-converting-information">
|
||||
<span><strong><?php esc_html_e('Cloudflare Email:','compressx')?></strong> <?php esc_html_e('Email address associated to your Cloudflare account','compressx')?></span>
|
||||
<p><span><strong><?php esc_html_e('Global API Key:','compressx')?></strong> <?php esc_html_e('A key for granting access to Cloudflare API to perform actions. You can find it in your Cloudflare dashboard > My Profile > API Tokens > Global API Key.','compressx')?></span></p>
|
||||
<span><strong><?php esc_html_e('Zone ID:','compressx')?></strong> <?php esc_html_e('A zone ID is generated automatically when a domain is added to Cloudflare and is required for API operations. You can find it in your Cloudflare Dashboard > The website overview > API section.','compressx')?></span>
|
||||
<br>
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<input id="compressx_purge_cache" class="button" type="submit" value="<?php esc_attr_e('Purge All Cloudflare CDN Cache Manually','compressx')?>">
|
||||
<span style="padding:0 0.2rem;"></span>
|
||||
<span id="compressx_purge_cache_progress" style="display: none">
|
||||
<img src="../wp-admin/images/loading.gif" alt="">
|
||||
</span>
|
||||
<span id="compressx_purge_cache_text" class="success hidden" aria-hidden="true" style="color:#007017"><?php esc_html_e('Done!','compressx')?></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="compressx-general-settings-footer">
|
||||
<input class="button-primary cx-button" id="compressx_save_cdn" type="submit" value="<?php esc_attr_e('Save Changes','compressx')?>">
|
||||
<span style="padding:0 0.2rem;"></span>
|
||||
<span id="compressx_save_cdn_progress" style="display: none">
|
||||
<img src="../wp-admin/images/loading.gif" alt="">
|
||||
</span>
|
||||
<span id="compressx_save_cdn_text" class="success hidden" aria-hidden="true" style="color:#007017"><?php esc_html_e('Saved!','compressx')?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<script>
|
||||
jQuery('#compressx_save_cdn').click(function()
|
||||
{
|
||||
compressx_save_cdn_setting();
|
||||
});
|
||||
|
||||
jQuery('#compressx_purge_cache').click(function()
|
||||
{
|
||||
compressx_purge_cache();
|
||||
});
|
||||
//
|
||||
|
||||
function compressx_purge_cache()
|
||||
{
|
||||
var json = {};
|
||||
|
||||
var setting_data = compressx_ajax_data_transfer('cf_cdn');
|
||||
var json1 = JSON.parse(setting_data);
|
||||
|
||||
jQuery.extend(json1, json);
|
||||
setting_data=JSON.stringify(json1);
|
||||
|
||||
var ajax_data = {
|
||||
'action': 'compressx_purge_cache',
|
||||
'setting': setting_data,
|
||||
};
|
||||
jQuery('#compressx_purge_cache').css({'pointer-events': 'none', 'opacity': '0.4'});
|
||||
jQuery('#compressx_purge_cache_progress').show();
|
||||
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
jQuery('#compressx_purge_cache_progress').hide();
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
jQuery('#compressx_purge_cache').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#compressx_purge_cache_text').removeClass("hidden");
|
||||
setTimeout(function ()
|
||||
{
|
||||
jQuery('#compressx_purge_cache_text').addClass( 'hidden' );
|
||||
}, 3000); }
|
||||
else
|
||||
{
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
alert(err);
|
||||
jQuery('#compressx_purge_cache').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
jQuery('#compressx_purge_cache_progress').hide();
|
||||
jQuery('#compressx_purge_cache').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
function compressx_save_cdn_setting()
|
||||
{
|
||||
var json = {};
|
||||
|
||||
var setting_data = compressx_ajax_data_transfer('cf_cdn');
|
||||
var json1 = JSON.parse(setting_data);
|
||||
|
||||
jQuery.extend(json1, json);
|
||||
setting_data=JSON.stringify(json1);
|
||||
|
||||
var ajax_data = {
|
||||
'action': 'compressx_save_cdn',
|
||||
'setting': setting_data,
|
||||
};
|
||||
jQuery('#compressx_save_cdn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
||||
jQuery('#compressx_save_cdn_progress').show();
|
||||
//
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
jQuery('#compressx_save_cdn').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_save_cdn_progress').hide();
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#compressx_save_cdn_text').removeClass("hidden");
|
||||
setTimeout(function ()
|
||||
{
|
||||
jQuery('#compressx_save_cdn_text').addClass( 'hidden' );
|
||||
}, 3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
alert(err);
|
||||
jQuery('#compressx_save_cdn').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_save_cdn_progress').hide();
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
jQuery('#compressx_save_cdn').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_save_cdn_progress').hide();
|
||||
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function save_cdn()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-cdn');
|
||||
|
||||
if(isset($_POST['setting'])&&!empty($_POST['setting']))
|
||||
{
|
||||
$json_setting = sanitize_text_field($_POST['setting']);
|
||||
$json_setting = stripslashes($json_setting);
|
||||
$setting = json_decode($json_setting, true);
|
||||
if (is_null($setting))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='json decode failed';
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
if($this->need_test($setting))
|
||||
{
|
||||
include_once COMPRESSX_DIR . '/includes/class-compressx-cloudflare-cdn.php';
|
||||
$cdn=new CompressX_CloudFlare_CDN($setting);
|
||||
|
||||
$ret=$cdn->purge_cache();
|
||||
|
||||
if($ret['result']!='success')
|
||||
{
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$options=CompressX_Options::get_option('compressx_general_settings',array());
|
||||
|
||||
$options['cf_cdn']['zone_id']=$setting['zone_id'];
|
||||
$options['cf_cdn']['email']=$setting['email'];
|
||||
$options['cf_cdn']['api_key']=$setting['api_key'];
|
||||
if(isset($setting['auto_purge_cache']))
|
||||
{
|
||||
$options['cf_cdn']['auto_purge_cache']=$setting['auto_purge_cache'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$options['cf_cdn']['auto_purge_cache']=false;
|
||||
}
|
||||
|
||||
if(isset($setting['auto_purge_cache_after_manual']))
|
||||
{
|
||||
$options['cf_cdn']['auto_purge_cache_after_manual']=$setting['auto_purge_cache_after_manual'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$options['cf_cdn']['auto_purge_cache_after_manual']=false;
|
||||
}
|
||||
|
||||
CompressX_Options::update_option('compressx_general_settings',$options);
|
||||
|
||||
$ret['result']='success';
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function need_test($setting)
|
||||
{
|
||||
if(isset($setting['auto_purge_cache'])&&$setting['auto_purge_cache'])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(isset($setting['auto_purge_cache_after_manual'])&&$setting['auto_purge_cache_after_manual'])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function purge_cache()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-cdn');
|
||||
|
||||
if(isset($_POST['setting'])&&!empty($_POST['setting']))
|
||||
{
|
||||
$json_setting = sanitize_text_field($_POST['setting']);
|
||||
$json_setting = stripslashes($json_setting);
|
||||
$setting = json_decode($json_setting, true);
|
||||
if (is_null($setting))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='json decode failed';
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/class-compressx-cloudflare-cdn.php';
|
||||
|
||||
$cdn=new CompressX_CloudFlare_CDN($setting);
|
||||
|
||||
$ret=$cdn->purge_cache();
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
include_once COMPRESSX_DIR . '/includes/class-compressx-cloudflare-cdn.php';
|
||||
|
||||
$options=CompressX_Options::get_option('compressx_general_settings',array());
|
||||
|
||||
$setting=$options['cf_cdn'];
|
||||
|
||||
$cdn=new CompressX_CloudFlare_CDN($setting);
|
||||
|
||||
$ret=$cdn->purge_cache();
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,676 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Custom_Bulk_Action
|
||||
{
|
||||
public $support_extension;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->support_extension=array();
|
||||
$this->support_extension[]='jpg';
|
||||
$this->support_extension[]='jpeg';
|
||||
$this->support_extension[]='png';
|
||||
$this->support_extension[]='webp';
|
||||
|
||||
add_action('wp_ajax_compressx_get_custom_tree_dir_ex', array($this, 'get_custom_tree_dir_ex'));
|
||||
add_action('wp_ajax_compressx_add_include_folders', array($this, 'add_include_folders'));
|
||||
add_action('wp_ajax_compressx_remove_include_folders', array($this, 'remove_include_folders'));
|
||||
//
|
||||
add_action('wp_ajax_compressx_start_scan_custom_images', array($this, 'start_scan_custom_images'));
|
||||
add_action('wp_ajax_compressx_init_custom_bulk_optimization_task', array($this, 'init_custom_bulk_optimization_task'));
|
||||
add_action('wp_ajax_compressx_run_custom_optimize', array($this, 'run_custom_optimize'));
|
||||
add_action('wp_ajax_compressx_get_custom_opt_progress', array($this, 'get_custom_opt_progress'));
|
||||
add_action('wp_ajax_compressx_get_dir_info', array($this, 'get_dir_info'));
|
||||
//
|
||||
add_action('cx_output_custom_bulk',array($this, 'output_custom_bulk'));
|
||||
}
|
||||
|
||||
public function output_custom_bulk()
|
||||
{
|
||||
CompressX_Custom_Image_Meta::check_custom_table();
|
||||
|
||||
$includes=CompressX_Options::get_option('compressx_custom_includes',array());
|
||||
$stats=$this->get_custom_stats($includes);
|
||||
$found=$stats['files'];
|
||||
$saved=$stats['saved'];
|
||||
$processed=$stats['processed_files'];
|
||||
?>
|
||||
<header>
|
||||
<div class="compressx-container compressx-header">
|
||||
<div class="compressx-general-settings" style="padding-bottom: 0;">
|
||||
<div class="compressx-general-settings-header">
|
||||
<h5><?php esc_html_e('Custom Folders','compressx')?></h5>
|
||||
</div>
|
||||
<div class="compressing-converting-information" style="margin-top: 1rem;">
|
||||
<?php esc_html_e('Select custom folders in the /wp-content folder and process images inside them.','compressx')?>
|
||||
</div>
|
||||
<div class="compressx-general-settings-body">
|
||||
<?php
|
||||
$this->output_custom_folders();
|
||||
?>
|
||||
<div class="cx-custom-overview">
|
||||
<div>
|
||||
<span id="cx_custom_overview">
|
||||
<span><?php esc_html_e('Media Files Found: ','compressx')?></span><span id="cx_custom_founds"><?php echo esc_html($found);?></span><span> | </span>
|
||||
<span><?php esc_html_e('Total Savings: ','compressx')?></span><span id="cx_custom_total_saving"><?php echo esc_html($saved);?></span><span>%</span><span> | </span>
|
||||
<span><?php esc_html_e('Processed Media Files: ','compressx')?></span><span id="cx_custom_processed"><?php echo esc_html($processed);?></span>
|
||||
</span>
|
||||
</div>
|
||||
<div style="padding-top:1rem;">
|
||||
<input type="submit" id="compressx_start_custom_bulk_optimization" class="button-primary cx-button" value="<?php esc_attr_e('Bulk Process Now','compressx')?>">
|
||||
<input class="button-primary cx-button" style="display: none" id="compressx_cancel_custom_bulk_optimization" type="submit" value="<?php esc_attr_e('Cancel Processing','compressx')?>">
|
||||
<span id="cx_custom_bulk_progress_text" style="display: none"></span>
|
||||
</div>
|
||||
<div style="padding-top:1rem;">
|
||||
<span><input id="cx_custom_force_optimization" type="checkbox"><?php esc_html_e('Force all images to be re-processed','compressx')?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function get_custom_stats($includes)
|
||||
{
|
||||
$stats=array();
|
||||
|
||||
$stats['files']=0;
|
||||
$stats['saved']=0;
|
||||
$stats['processed_files']=0;
|
||||
$stats['total']=0;
|
||||
$stats['processed']=0;
|
||||
|
||||
$convert_to_webp=CompressX_Image_Opt_Method::get_convert_to_webp();
|
||||
$convert_to_avif=CompressX_Image_Opt_Method::get_convert_to_avif();
|
||||
|
||||
foreach ($includes as $include)
|
||||
{
|
||||
$this->get_folder_stats($include,$stats,$convert_to_webp,$convert_to_avif);
|
||||
}
|
||||
|
||||
if($stats['total']>0)
|
||||
{
|
||||
$stats['saved'] = ( $stats['processed'] / $stats['total'] ) * 100;
|
||||
$stats['saved'] = round( $stats['saved'], 1 );
|
||||
}
|
||||
|
||||
return $stats;
|
||||
}
|
||||
|
||||
public function get_folder_stats($path,&$stats,$convert_to_webp,$convert_to_avif)
|
||||
{
|
||||
try {
|
||||
$count=0;
|
||||
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
||||
|
||||
foreach ($rii as $file)
|
||||
{
|
||||
if ($file->isDir())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if($this->is_support_extension($file->getExtension()))
|
||||
{
|
||||
$filename=$path.'/'.$file->getFilename();
|
||||
$filename=$this->transfer_path($filename);
|
||||
|
||||
$type=pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
if($convert_to_webp&&$type!="webp")
|
||||
{
|
||||
if(CompressX_Custom_Image_Meta::is_convert_webp($filename))
|
||||
{
|
||||
$stats['processed_files']++;
|
||||
$stats['processed']+=CompressX_Custom_Image_Meta::get_convert_webp_size($filename);
|
||||
}
|
||||
|
||||
$count++;
|
||||
$stats['files']++;
|
||||
$stats['total']+=$file->getSize();
|
||||
}
|
||||
else if($convert_to_avif&&$type!="avif")
|
||||
{
|
||||
if(CompressX_Custom_Image_Meta::is_convert_avif($filename))
|
||||
{
|
||||
$stats['processed_files']++;
|
||||
$stats['processed']+=CompressX_Custom_Image_Meta::get_convert_avif_size($filename);
|
||||
}
|
||||
|
||||
$count++;
|
||||
$stats['files']++;
|
||||
$stats['total']+=$file->getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function is_support_extension($extension)
|
||||
{
|
||||
if(in_array($extension,$this->support_extension))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function output_custom_folders()
|
||||
{
|
||||
$includes=CompressX_Options::get_option('compressx_custom_includes',array());
|
||||
$abs_path = trailingslashit(str_replace('\\', '/', realpath(ABSPATH)));
|
||||
|
||||
$convert_to_avif=CompressX_Options::get_option('compressx_output_format_avif',1);
|
||||
|
||||
if($convert_to_avif&&CompressX_Image_Opt_Method::is_support_avif())
|
||||
{
|
||||
$convert_to_avif=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$convert_to_avif=false;
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="cx-mediafolder-rules">
|
||||
<div class="cx-mediafolders">
|
||||
<span>
|
||||
<span class="dashicons dashicons-open-folder cx-icon-color-techblue"></span><span>wp-content:</span>
|
||||
</span>
|
||||
<div class="cx-upload-treeviewer" id="compressx_custom_include_js_tree">
|
||||
</div>
|
||||
</div>
|
||||
<div class="cx-mediafolder-included">
|
||||
<span>
|
||||
<span class="dashicons dashicons-open-folder cx-icon-color-techblue"></span>
|
||||
<span><strong><?php esc_html_e('Included Folders: ','compressx')?></strong><?php esc_html_e('Media files inside these folders will be processed','compressx')?></span>
|
||||
</span>
|
||||
<div class="cx-mediafolder-list" id="compressx_include_dir_node">
|
||||
<ul>
|
||||
<?php
|
||||
|
||||
foreach ($includes as $include)
|
||||
{
|
||||
$path=str_replace($abs_path,'',$include);
|
||||
?>
|
||||
<li>
|
||||
<span class="dashicons dashicons-open-folder cx-icon-color-techblue"></span>
|
||||
<span><?php echo esc_html($path.'('.$this->get_children_count($include,$convert_to_avif).')')?></span>
|
||||
<span class="dashicons dashicons-remove cx-remove-rule cx-remove-custom-include-tree" data-id="<?php echo esc_attr($include)?>"></span>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function get_custom_tree_dir_ex()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
try{
|
||||
$node_array = array();
|
||||
|
||||
if ($_POST['tree_node']['node']['id'] == '#')
|
||||
{
|
||||
$path = ABSPATH;
|
||||
|
||||
if (!empty($_POST['tree_node']['path']))
|
||||
{
|
||||
$path = sanitize_text_field($_POST['tree_node']['path']);
|
||||
}
|
||||
} else {
|
||||
$path = sanitize_text_field($_POST['tree_node']['node']['id']);
|
||||
}
|
||||
|
||||
$path = trailingslashit(str_replace('\\', '/', realpath($path)));
|
||||
|
||||
if ($dh = opendir($path))
|
||||
{
|
||||
while (substr($path, -1) == '/')
|
||||
{
|
||||
$path = rtrim($path, '/');
|
||||
}
|
||||
$skip_paths = array(".", "..");
|
||||
|
||||
while (($value = readdir($dh)) !== false)
|
||||
{
|
||||
trailingslashit(str_replace('\\', '/', $value));
|
||||
if (!in_array($value, $skip_paths))
|
||||
{
|
||||
if (is_dir($path . '/' . $value))
|
||||
{
|
||||
if(!$this->is_media_folder($path . '/' . $value))
|
||||
{
|
||||
$node['children'] = $this->has_children($path . '/' . $value);
|
||||
$node['id'] = $path . '/' . $value;
|
||||
$node['icon'] = 'dashicons dashicons-category cx-icon-color-techblue';
|
||||
$node['text'] ='<span>'.$value.'</span>';
|
||||
$node['text'] .='<span class="dashicons dashicons-insert cx-remove-rule cx-add-custom-include-tree" data-id="'.$node['id'].'"></span>';
|
||||
$node_array[] = $node;
|
||||
}
|
||||
}
|
||||
else{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ret['nodes'] = $node_array;
|
||||
echo wp_json_encode($ret);
|
||||
}
|
||||
catch (Exception $error) {
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
//error_log($message);
|
||||
echo wp_json_encode(array('result'=>'failed','error'=>$message));
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
public function has_children($path)
|
||||
{
|
||||
if ($dh = opendir($path))
|
||||
{
|
||||
while (substr($path, -1) == '/')
|
||||
{
|
||||
$path = rtrim($path, '/');
|
||||
}
|
||||
$skip_paths = array(".", "..");
|
||||
|
||||
while (($value = readdir($dh)) !== false)
|
||||
{
|
||||
trailingslashit(str_replace('\\', '/', $value));
|
||||
if (!in_array($value, $skip_paths))
|
||||
{
|
||||
if (is_dir($path . '/' . $value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function is_media_folder($path)
|
||||
{
|
||||
$upload_dir = wp_upload_dir();
|
||||
$base_dir = $upload_dir['basedir'];
|
||||
$base_dir = trailingslashit(str_replace('\\', '/', realpath($base_dir)));
|
||||
$path=str_replace( $base_dir, '', $path );
|
||||
$path_arr = explode( '/', $path );
|
||||
|
||||
if ( count( $path_arr ) >= 1)
|
||||
{
|
||||
if(is_numeric( $path_arr[0] ) && $path_arr[0] > 1950 && $path_arr[0] < 2050)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$path=$this->transfer_path($path);
|
||||
$upload_root=$this->transfer_path($upload_dir['basedir']);
|
||||
$compressx1=$this->transfer_path(WP_CONTENT_DIR.'/compressx');
|
||||
$compressx2=$this->transfer_path(WP_CONTENT_DIR.'/compressx-nextgen');
|
||||
|
||||
if($path==$compressx1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if($path==$compressx2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if($path==$upload_root)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function get_children_count($path,$convert_to_avif)
|
||||
{
|
||||
try {
|
||||
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
|
||||
$files = 0;
|
||||
|
||||
/** @var SplFileInfo $file */
|
||||
foreach ($rii as $file)
|
||||
{
|
||||
if ($file->isDir())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if($this->is_support_extension($file->getExtension()))
|
||||
{
|
||||
$filename=$path.'/'.$file->getFilename();
|
||||
$type=pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
if($type=='webp'&&$convert_to_avif)
|
||||
{
|
||||
$files++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$files++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function add_include_folders()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
$includes=CompressX_Options::get_option('compressx_custom_includes',array());
|
||||
|
||||
$new_include = sanitize_text_field($_POST['id']);
|
||||
|
||||
$new_includes[$new_include]=$new_include;
|
||||
|
||||
$includes=array_merge($includes,$new_includes);
|
||||
|
||||
CompressX_Options::update_option('compressx_custom_includes',$includes);
|
||||
|
||||
$stats=array();
|
||||
|
||||
$stats['files']=0;
|
||||
$stats['saved']=0;
|
||||
$stats['processed_files']=0;
|
||||
$stats['total']=0;
|
||||
$stats['processed']=0;
|
||||
|
||||
$convert_to_webp=CompressX_Image_Opt_Method::get_convert_to_webp();
|
||||
$convert_to_avif=CompressX_Image_Opt_Method::get_convert_to_avif();
|
||||
|
||||
$abs_path = trailingslashit(str_replace('\\', '/', realpath(ABSPATH)));
|
||||
|
||||
$html='<ul>';
|
||||
foreach ($includes as $include)
|
||||
{
|
||||
$path=str_replace($abs_path,'',$include);
|
||||
$html.= '<li><span class="dashicons dashicons-open-folder cx-icon-color-techblue"></span>'.
|
||||
'<span>'.$path.'('.$this->get_folder_stats($include,$stats,$convert_to_webp,$convert_to_avif).')'.'</span>'.
|
||||
'<span class="dashicons dashicons-remove cx-remove-rule cx-remove-custom-include-tree" data-id="'.$include.'"></span></li>';
|
||||
}
|
||||
$html.='<ul>';
|
||||
|
||||
if($stats['total']>0)
|
||||
{
|
||||
$stats['saved'] = ( $stats['processed'] / $stats['total'] ) * 100;
|
||||
$stats['saved'] = round( $stats['saved'], 1 );
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['html']=$html;
|
||||
$ret['found']=$stats['files'];
|
||||
$ret['saved']=$stats['saved'];
|
||||
$ret['processed']=$stats['processed_files'];
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
public function get_dir_info()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
$includes=CompressX_Options::get_option('compressx_custom_includes',array());
|
||||
|
||||
$stats=array();
|
||||
|
||||
$stats['files']=0;
|
||||
$stats['saved']=0;
|
||||
$stats['processed_files']=0;
|
||||
$stats['total']=0;
|
||||
$stats['processed']=0;
|
||||
|
||||
$convert_to_webp=CompressX_Image_Opt_Method::get_convert_to_webp();
|
||||
$convert_to_avif=CompressX_Image_Opt_Method::get_convert_to_avif();
|
||||
|
||||
foreach ($includes as $include)
|
||||
{
|
||||
$this->get_folder_stats($include,$stats,$convert_to_webp,$convert_to_avif);
|
||||
}
|
||||
|
||||
if($stats['total']>0)
|
||||
{
|
||||
$stats['saved'] = ( $stats['processed'] / $stats['total'] ) * 100;
|
||||
$stats['saved'] = round( $stats['saved'], 1 );
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['found']=$stats['files'];
|
||||
$ret['saved']=$stats['saved'];
|
||||
$ret['processed']=$stats['processed_files'];
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
public function remove_include_folders()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
$includes=CompressX_Options::get_option('compressx_custom_includes',array());
|
||||
|
||||
$id = sanitize_text_field($_POST['id']);
|
||||
unset($includes[$id]);
|
||||
|
||||
CompressX_Options::update_option('compressx_custom_includes',$includes);
|
||||
|
||||
$stats=array();
|
||||
|
||||
$stats['files']=0;
|
||||
$stats['saved']=0;
|
||||
$stats['processed_files']=0;
|
||||
$stats['total']=0;
|
||||
$stats['processed']=0;
|
||||
|
||||
$convert_to_webp=CompressX_Image_Opt_Method::get_convert_to_webp();
|
||||
$convert_to_avif=CompressX_Image_Opt_Method::get_convert_to_avif();
|
||||
|
||||
foreach ($includes as $include)
|
||||
{
|
||||
$this->get_folder_stats($include,$stats,$convert_to_webp,$convert_to_avif);
|
||||
}
|
||||
|
||||
if($stats['total']>0)
|
||||
{
|
||||
$stats['saved'] = ( $stats['processed'] / $stats['total'] ) * 100;
|
||||
$stats['saved'] = round( $stats['saved'], 1 );
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['found']=$stats['files'];
|
||||
$ret['saved']=$stats['saved'];
|
||||
$ret['processed']=$stats['processed_files'];
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
public function start_scan_custom_images()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
$includes=CompressX_Options::get_option('compressx_custom_includes',array());
|
||||
if(empty($includes))
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']='Please select at least one folder to process.';
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
CompressX_Options::update_option("compressx_need_optimized_custom_images",array());
|
||||
|
||||
$images=array();
|
||||
|
||||
foreach ($includes as $include)
|
||||
{
|
||||
$this->get_folder_images($images,$include);
|
||||
}
|
||||
|
||||
CompressX_Options::update_option("compressx_need_optimized_custom_images",$images);
|
||||
|
||||
$ret['result']='success';
|
||||
$ret['progress']=sprintf(
|
||||
'Scanning: %1$d Found | View Log',
|
||||
sizeof($images));
|
||||
$ret['finished']=true;
|
||||
$ret['test']=$includes;
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
public function get_folder_images(&$images,$path)
|
||||
{
|
||||
if(is_dir($path))
|
||||
{
|
||||
$handler = opendir($path);
|
||||
if($handler!==false)
|
||||
{
|
||||
while (($filename = readdir($handler)) !== false)
|
||||
{
|
||||
if ($filename != "." && $filename != "..")
|
||||
{
|
||||
if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
|
||||
{
|
||||
$this->get_folder_images($images, $path . DIRECTORY_SEPARATOR . $filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->check_image($path . DIRECTORY_SEPARATOR . $filename))
|
||||
{
|
||||
$images[] = $path . DIRECTORY_SEPARATOR . $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($handler)
|
||||
@closedir($handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function check_image($file)
|
||||
{
|
||||
if ( ! file_exists( $file ))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$extension = array('jpg', 'jpeg', 'png','webp','avif');
|
||||
|
||||
$ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
|
||||
|
||||
if ( !in_array( $ext, $extension, true ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function init_custom_bulk_optimization_task()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
$force=isset($_POST['force'])?sanitize_key($_POST['force']):'0';
|
||||
if($force=='1')
|
||||
{
|
||||
$force=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$force=false;
|
||||
}
|
||||
|
||||
$task=new CompressX_Custom_ImgOptim_Task();
|
||||
$ret=$task->init_task($force);
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
|
||||
public function run_custom_optimize()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
set_time_limit(180);
|
||||
|
||||
$task=new CompressX_Custom_ImgOptim_Task();
|
||||
|
||||
$ret=$task->get_task_status();
|
||||
|
||||
if($ret['result']=='success'&&$ret['status']=='completed')
|
||||
{
|
||||
$ret=$task->do_optimize_image();
|
||||
echo wp_json_encode($ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo wp_json_encode($ret);
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
public function get_custom_opt_progress()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-bulk-custom-convert');
|
||||
|
||||
$task=new CompressX_Custom_ImgOptim_Task();
|
||||
|
||||
$result=$task->get_task_progress();
|
||||
|
||||
echo wp_json_encode($result);
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
private function transfer_path($path)
|
||||
{
|
||||
$path = str_replace('\\','/',$path);
|
||||
$values = explode('/',$path);
|
||||
return implode(DIRECTORY_SEPARATOR,$values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Custom_Media_Lib
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if(is_multisite())
|
||||
return;
|
||||
|
||||
add_filter( 'manage_media_columns', array($this,'optimize_columns'));
|
||||
add_action( 'manage_media_custom_column', array($this, 'optimize_column_display'),10,2);
|
||||
add_action( 'attachment_submitbox_misc_actions', array( $this,'submitbox') );
|
||||
add_filter( 'wp_prepare_attachment_for_js', array($this,'attachment_fields_to_edit'), 10, 2 );
|
||||
|
||||
add_action('wp_ajax_compressx_get_opt_single_image_progress', array($this, 'get_opt_single_image_progress'));
|
||||
|
||||
//wp_prepare_attachment_for_js
|
||||
|
||||
//add_action( 'restrict_manage_posts', array($this,'add_dropdown') );
|
||||
//add_action( 'pre_get_posts', array( $this, 'filter_posts' ) );
|
||||
}
|
||||
|
||||
public function optimize_columns($defaults)
|
||||
{
|
||||
$defaults['compressx'] = 'CompressX';
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
public function optimize_column_display($column_name, $id )
|
||||
{
|
||||
if ( 'compressx' === $column_name )
|
||||
{
|
||||
echo $this->optimize_action_columns( $id );
|
||||
}
|
||||
}
|
||||
|
||||
public function optimize_action_columns($id)
|
||||
{
|
||||
$allowed_mime_types = CompressX_Image_Opt_Method::supported_mime_types_ex();
|
||||
|
||||
if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ),$allowed_mime_types ) )
|
||||
{
|
||||
return __('Not support','compressx');
|
||||
}
|
||||
|
||||
$html=$this->output_item($id);
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function submitbox()
|
||||
{
|
||||
global $post;
|
||||
$id=$post->ID;
|
||||
|
||||
$allowed_mime_types = CompressX_Image_Method::supported_mime_types_ex();
|
||||
|
||||
if ( ! wp_attachment_is_image( $post->ID ) || ! in_array( get_post_mime_type( $post->ID ),$allowed_mime_types ) )
|
||||
{
|
||||
echo esc_html__('Not support','compressx');
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->is_skipped($id))
|
||||
{
|
||||
echo esc_html__('Skipped','compressx');
|
||||
return;
|
||||
}
|
||||
|
||||
$html=$this->output_item_edit($id);
|
||||
echo $html;
|
||||
}
|
||||
|
||||
public function attachment_fields_to_edit(array $response, \WP_Post $attachment)
|
||||
{
|
||||
$source_post_id = (string) isset( $_REQUEST['post_id'])?$_REQUEST['post_id']:'';
|
||||
if ( $source_post_id !== '0' )
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
|
||||
$allowed_mime_types = CompressX_Image_Method::supported_mime_types_ex();
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment->ID ) || ! in_array( get_post_mime_type( $attachment->ID ),$allowed_mime_types ) )
|
||||
{
|
||||
return $response;
|
||||
}
|
||||
|
||||
$html=$this->output_item_attachment($attachment->ID);
|
||||
$response['compat']['meta'] .=$html;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function output_item($id)
|
||||
{
|
||||
if($this->is_skipped($id))
|
||||
{
|
||||
return __('Skipped','compressx');
|
||||
}
|
||||
|
||||
$html='<div class="cx-media-item" data-id="'.esc_attr($id).'">';
|
||||
$html.='<ul>';
|
||||
$html.=$this->output_item_detail($id);
|
||||
$html.=$this->output_item_action($id);
|
||||
$html.='</ul>';
|
||||
$html.='</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function output_item_edit($id)
|
||||
{
|
||||
if($this->is_skipped($id))
|
||||
{
|
||||
return __('Skipped','compressx');
|
||||
}
|
||||
|
||||
$html='<div class="misc-pub-section misc-pub-cx" data-id="'.esc_attr($id).'"><h4>' . esc_html__('CompressX','compressx') . '</h4>';
|
||||
$html.='<ul>';
|
||||
$html.=$this->output_item_detail($id);
|
||||
$html.=$this->output_item_action($id);
|
||||
$html.='</ul>';
|
||||
$html.='</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function output_item_attachment($id)
|
||||
{
|
||||
$html='<div class="cx-media-attachment" data-id="'.esc_attr($id).'"><h4>' . esc_html__('CompressX','compressx') . '</h4>';
|
||||
$html.='<ul>';
|
||||
$html.=$this->output_item_detail($id);
|
||||
$html.=$this->output_item_action($id);
|
||||
$html.='</ul>';
|
||||
$html.='</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function output_item_detail($id)
|
||||
{
|
||||
$html='';
|
||||
$og_size=CompressX_Image_Meta_V2::get_og_size($id);
|
||||
if(empty($og_size))
|
||||
{
|
||||
$file_path = get_attached_file( $id );
|
||||
if(file_exists($file_path))
|
||||
$og_size=filesize($file_path);
|
||||
else
|
||||
$og_size=0;
|
||||
}
|
||||
|
||||
$html.='<li><span>Original : </span><strong>'.esc_html(size_format($og_size,2)).'</strong></li>';
|
||||
|
||||
$webp_size=CompressX_Image_Meta_V2::get_webp_converted_size($id);
|
||||
if($webp_size>0&&$og_size>$webp_size)
|
||||
{
|
||||
$webp_percent = round(100 - ($webp_size / $og_size) * 100, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$webp_percent=0;
|
||||
}
|
||||
|
||||
$html.='<li><span>Webp : <strong>'.esc_html(size_format($webp_size,2)).'</strong> Saved : <strong>'.esc_html($webp_percent).'%</strong></span></li>';
|
||||
|
||||
$avif_size=CompressX_Image_Meta_V2::get_avif_converted_size($id);
|
||||
|
||||
if($avif_size>0&&$og_size>$avif_size)
|
||||
{
|
||||
$avif_percent = round(100 - ($avif_size / $og_size) * 100, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
$avif_percent=0;
|
||||
}
|
||||
|
||||
$html.='<li><span>AVIF : <strong>'.esc_html(size_format($avif_size,2)).'</strong> Saved : <strong>'.esc_html($avif_percent).'%</strong></span></li>';
|
||||
|
||||
$meta=CompressX_Image_Meta_V2::get_image_meta($id);
|
||||
if(isset($meta['size'])&&!empty($meta['size']))
|
||||
{
|
||||
$thumbnail_counts=count($meta['size']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$thumbnail_counts=0;
|
||||
}
|
||||
$html.='<li><span>Thumbnails generated : </span><strong>'.esc_html($thumbnail_counts).'</strong></li>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function output_item_action($id)
|
||||
{
|
||||
$html='<li>';
|
||||
$html.='<select class="cx-media-selected">';
|
||||
$html.='<option value="">Select Action</option>';
|
||||
if(CompressX_Image_Meta_V2::is_image_optimized($id))
|
||||
{
|
||||
$html.='<option value="delete">Delete</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$html.='<option value="convert">Convert</option>';
|
||||
if(CompressX_Image_Meta_V2::has_optimized_file($id))
|
||||
{
|
||||
$html.='<option value="delete">Delete</option>';
|
||||
}
|
||||
}
|
||||
|
||||
$html.='</select>';
|
||||
if($this->is_image_progressing($id))
|
||||
{
|
||||
$html.='<a class="cx-media button-disabled button" data-id="'.esc_attr($id).'">Progressing</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$html.='<a class="cx-media button" data-id="'.esc_attr($id).'">Apply</a>';
|
||||
}
|
||||
|
||||
$html.='</li>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function is_skipped($image_id)
|
||||
{
|
||||
if(CompressX_Image_Meta_V2::get_image_meta_status($image_id)==='skip')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function is_image_progressing($post_id)
|
||||
{
|
||||
$progressing=CompressX_Image_Meta_V2::get_image_progressing($post_id);
|
||||
|
||||
if(empty($progressing))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$current_time=time();
|
||||
if(($current_time-$progressing)>180)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_opt_single_image_progress()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-convert');
|
||||
|
||||
if(!isset($_POST['ids'])||!is_string($_POST['ids']))
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
$ids=sanitize_text_field($_POST['ids']);
|
||||
$ids=json_decode($ids,true);
|
||||
|
||||
$running=false;
|
||||
|
||||
if(isset($_POST['page']))
|
||||
{
|
||||
$page=sanitize_text_field($_POST['page']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$page='media';
|
||||
}
|
||||
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
if(!CompressX_Image_Meta_V2::is_image_optimized($id))
|
||||
{
|
||||
if($this->is_image_progressing($id))
|
||||
{
|
||||
$running=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ret['result']='success';
|
||||
if($running)
|
||||
{
|
||||
$ret['continue']=1;
|
||||
$ret['finished']=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['continue']=0;
|
||||
$ret['finished']=1;
|
||||
}
|
||||
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
if($page=='edit')
|
||||
{
|
||||
$html=$this->output_item_edit($id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$html=$this->output_item($id);
|
||||
}
|
||||
|
||||
$ret[$id]['html']=$html;
|
||||
}
|
||||
|
||||
echo wp_json_encode($ret);
|
||||
|
||||
die();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,891 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Display
|
||||
{
|
||||
public $dashboard;
|
||||
public $bulk_action;
|
||||
public $custom_bulk_action;
|
||||
public $log;
|
||||
public $system_info;
|
||||
public $cdn;
|
||||
public $compression;
|
||||
public $addons;
|
||||
public $image_optimization;
|
||||
public $settings;
|
||||
|
||||
public $media_replace;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->load_v2();
|
||||
/*
|
||||
$interface_version = CompressX_Options::get_interface_version();
|
||||
if($interface_version === 'v2')
|
||||
{
|
||||
$this->load_v2();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load();
|
||||
}*/
|
||||
}
|
||||
|
||||
/*
|
||||
public function load()
|
||||
{
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-dashboard.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-bulk-action.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-custom-bulk-action.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-cdn.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-logs.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-system-info.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display/class-compressx-addons.php';
|
||||
|
||||
$this->dashboard=new CompressX_Dashboard();
|
||||
$this->bulk_action=new CompressX_Bulk_Action();
|
||||
$this->custom_bulk_action=new CompressX_Custom_Bulk_Action();
|
||||
$this->cdn=new CompressX_CDN();
|
||||
$this->log=new CompressX_Logs();
|
||||
$this->system_info=new CompressX_System_Info();
|
||||
$this->addons=new CompressX_Addons();
|
||||
|
||||
add_action('admin_enqueue_scripts',array( $this,'enqueue_styles'));
|
||||
add_action('admin_enqueue_scripts',array( $this,'enqueue_scripts'));
|
||||
|
||||
add_action('compressx_output_nav',array( $this,'output_nav'));
|
||||
add_action('compressx_output_header',array( $this,'output_header'));
|
||||
add_action('compressx_output_footer',array( $this,'output_footer'));
|
||||
|
||||
if(is_multisite())
|
||||
{
|
||||
add_action('network_admin_menu',array( $this,'add_plugin_network_admin_menu'));
|
||||
}
|
||||
else
|
||||
{
|
||||
add_action('admin_menu',array( $this,'add_plugin_admin_menu'));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public function load_v2()
|
||||
{
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-image-optimization-display.php';
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-bulk-optimization-display.php';
|
||||
|
||||
$this->image_optimization=new CompressX_Image_Optimization_Display();
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-settings-display.php';
|
||||
$this->settings=new CompressX_Settings_Display();
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-cdn-display.php';
|
||||
$this->cdn=new CompressX_CDN_Display();
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-system-info-display.php';
|
||||
$this->system_info=new CompressX_System_Info_Display();
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-addons-display.php';
|
||||
$this->addons=new CompressX_Addons_Display();
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-custom-bulk-action-v2.php';
|
||||
$this->custom_bulk_action=new CompressX_Custom_Bulk_Action_V2();
|
||||
//
|
||||
include_once COMPRESSX_DIR . '/includes/display_v2/class-compressx-media-replace-display.php';
|
||||
$this->media_replace=new CompressX_Media_Replace_Display();
|
||||
|
||||
add_action('admin_enqueue_scripts',array( $this,'enqueue_styles_v2'));
|
||||
add_action('admin_enqueue_scripts',array( $this,'enqueue_scripts_v2'));
|
||||
|
||||
add_action('compressx_output_nav',array( $this,'output_nav'));
|
||||
add_action('compressx_output_header',array( $this,'output_header'));
|
||||
add_action('compressx_output_footer',array( $this,'output_footer_v2'));
|
||||
|
||||
if(is_multisite())
|
||||
{
|
||||
add_action('network_admin_menu',array( $this,'add_plugin_network_admin_menu'));
|
||||
}
|
||||
else
|
||||
{
|
||||
add_action('admin_menu',array( $this,'add_plugin_admin_menu_v2'));
|
||||
add_action('admin_menu',array( $this,'add_media_replace_menu'));
|
||||
add_action('submenu_file', array($this, 'hide_media_replace_menu'));
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_styles()
|
||||
{
|
||||
if(is_multisite())
|
||||
{
|
||||
$screen_ids[]='toplevel_page_CompressX-network';
|
||||
}
|
||||
else
|
||||
{
|
||||
$screen_ids[]='toplevel_page_'.COMPRESSX_SLUG;
|
||||
$screen_ids[]='compressx_page_info-compressx';
|
||||
$screen_ids[]='compressx_page_logs-compressx';
|
||||
$screen_ids[]='compressx_page_cdn-compressx';
|
||||
$screen_ids[]='compressx_page_addons-compressx';
|
||||
$screen_ids[]='compressx_page_compression-level-compressx';
|
||||
}
|
||||
|
||||
$screen_ids=apply_filters('compressx_get_screen_ids',$screen_ids);
|
||||
|
||||
if(in_array(get_current_screen()->id,$screen_ids))
|
||||
{
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'jstree', COMPRESSX_URL . '/includes/display/js/jstree/dist/themes/default/style.min.css', array(), COMPRESSX_VERSION, 'all');
|
||||
wp_enqueue_style(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/css/compressx-style.css', array(), COMPRESSX_VERSION, 'all');
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'-percentage-circle-style', COMPRESSX_URL . '/includes/display/css/compressx-percentage-circle-style.css', array(), COMPRESSX_VERSION, 'all');
|
||||
}
|
||||
else if(get_current_screen()->id=='upload'||get_current_screen()->id=='attachment')
|
||||
{
|
||||
wp_enqueue_style(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/css/compressx-media.css', array(), COMPRESSX_VERSION, 'all');
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_scripts()
|
||||
{
|
||||
$screen_ids[]='toplevel_page_'.COMPRESSX_SLUG;
|
||||
$screen_ids[]='compressx_page_info-compressx';
|
||||
$screen_ids[]='compressx_page_logs-compressx';
|
||||
$screen_ids[]='compressx_page_cdn-compressx';
|
||||
$screen_ids[]='compressx_page_compression-level-compressx';
|
||||
$screen_ids=apply_filters('compressx_get_screen_ids',$screen_ids);
|
||||
|
||||
if(in_array(get_current_screen()->id,$screen_ids))
|
||||
{
|
||||
wp_enqueue_script(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/js/compressx.js', array('jquery'), COMPRESSX_VERSION, false);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'jstree', COMPRESSX_URL . '/includes/display/js/jstree/dist/jstree.min.js', array('jquery'), COMPRESSX_VERSION, false);
|
||||
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_ajax_object', array('ajax_url' => admin_url('admin-ajax.php'),'ajax_nonce'=>wp_create_nonce('compressx_ajax')));
|
||||
|
||||
wp_enqueue_script('plupload-all');
|
||||
}
|
||||
else if(get_current_screen()->id=='upload'||get_current_screen()->id=='attachment')
|
||||
{
|
||||
wp_enqueue_script(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/js/compressx.js', array('jquery'), COMPRESSX_VERSION, false);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_media', COMPRESSX_URL . '/includes/display/js/optimize.js', array('jquery'), COMPRESSX_VERSION, true);
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_ajax_object', array('ajax_url' => admin_url('admin-ajax.php'),'ajax_nonce'=>wp_create_nonce('compressx_ajax')));
|
||||
}
|
||||
|
||||
$toplevel_screen_id='toplevel_page_'.COMPRESSX_SLUG;
|
||||
$toplevel_screen_id=apply_filters('compressx_get_screen_id',$toplevel_screen_id);
|
||||
if(get_current_screen()->id==$toplevel_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$path = $upload_dir['basedir'];
|
||||
$path = str_replace('\\','/',$path);
|
||||
$uploads_path = $path.'/';
|
||||
|
||||
$path = WP_CONTENT_DIR;
|
||||
$path = str_replace('\\','/',$path);
|
||||
$custom_root_path = $path.'/';
|
||||
|
||||
if(CompressX_Image_Opt_Method::check_imagick_avif())
|
||||
{
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_alert', array('imagick_avif' => false));
|
||||
}
|
||||
else
|
||||
{
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_alert', array('imagick_avif' => true));
|
||||
}
|
||||
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_uploads_root', array('path' => $uploads_path,'custom_path'=>$custom_root_path));
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_setting', COMPRESSX_URL . '/includes/display/js/compressx_setting.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_custom_bulk', COMPRESSX_URL . '/includes/display/js/compressx_custom_bulk.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
|
||||
$cdn_screen_id='compressx_page_cdn-compressx';
|
||||
$cdn_screen_id=apply_filters('compressx_get_screen_id',$cdn_screen_id);
|
||||
if(get_current_screen()->id=='compressx_page_cdn-compressx')
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_setting', COMPRESSX_URL . '/includes/display/js/compressx_setting.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
|
||||
$logs_screen_id='compressx_page_logs-compressx';
|
||||
$logs_screen_id=apply_filters('compressx_get_screen_id',$logs_screen_id);
|
||||
if(get_current_screen()->id==$logs_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_logs', COMPRESSX_URL . '/includes/display/js/compressx_log.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
|
||||
$info_screen_id='compressx_page_info-compressx';
|
||||
$info_screen_id=apply_filters('compressx_get_screen_id',$info_screen_id);
|
||||
if(get_current_screen()->id==$info_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_systeminfo', COMPRESSX_URL . '/includes/display/js/compressx_system_info.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_styles_v2()
|
||||
{
|
||||
if(is_multisite())
|
||||
{
|
||||
$screen_ids[]='toplevel_page_CompressX-network';
|
||||
}
|
||||
else
|
||||
{
|
||||
$screen_ids[]='toplevel_page_'.COMPRESSX_SLUG;
|
||||
$screen_ids[]='compressx_page_image-optimization-compressx';
|
||||
$screen_ids[]='compressx_page_settings-compressx';
|
||||
$screen_ids[]='compressx_page_cdn-compressx';
|
||||
$screen_ids[]='compressx_page_info-compressx';
|
||||
$screen_ids[]='compressx_page_addons-compressx';
|
||||
//Replace Media
|
||||
$screen_ids[]='media_page_media-replace-compressx';
|
||||
}
|
||||
|
||||
$screen_ids=apply_filters('compressx_get_screen_ids',$screen_ids);
|
||||
|
||||
if(in_array(get_current_screen()->id,$screen_ids))
|
||||
{
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'jstree', COMPRESSX_URL . '/includes/display/js/jstree/dist/themes/default/style.min.css', array(), COMPRESSX_VERSION, 'all');
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'_v2', COMPRESSX_URL . '/includes/display_v2/css/compressx-style-v2.css', array(), COMPRESSX_VERSION, 'all');
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'-percentage-circle-style', COMPRESSX_URL . '/includes/display/css/compressx-percentage-circle-style.css', array(), COMPRESSX_VERSION, 'all');
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'-twentytwenty', COMPRESSX_URL . '/includes/display_v2/css/twentytwenty/twentytwenty.css', array(), COMPRESSX_VERSION);
|
||||
wp_enqueue_style(COMPRESSX_SLUG.'-folder-tree', COMPRESSX_URL . '/includes/display_v2/css/compressx-folder-tree.css', array(), COMPRESSX_VERSION, 'all');
|
||||
|
||||
}
|
||||
else if(get_current_screen()->id=='upload'||get_current_screen()->id=='attachment')
|
||||
{
|
||||
wp_enqueue_style(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/css/compressx-media.css', array(), COMPRESSX_VERSION, 'all');
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_scripts_v2()
|
||||
{
|
||||
$screen_ids[]='toplevel_page_'.COMPRESSX_SLUG;
|
||||
$screen_ids[]='compressx_page_image-optimization-compressx';
|
||||
$screen_ids[]='compressx_page_settings-compressx';
|
||||
$screen_ids[]='compressx_page_cdn-compressx';
|
||||
$screen_ids[]='compressx_page_info-compressx';
|
||||
$screen_ids[]='compressx_page_addons-compressx';
|
||||
|
||||
$screen_ids[]='media_page_media-replace-compressx';
|
||||
|
||||
$screen_ids=apply_filters('compressx_get_screen_ids',$screen_ids);
|
||||
|
||||
if(in_array(get_current_screen()->id,$screen_ids))
|
||||
{
|
||||
wp_enqueue_script(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/js/compressx.js', array('jquery'), COMPRESSX_VERSION, false);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'jstree', COMPRESSX_URL . '/includes/display/js/jstree/dist/jstree.min.js', array('jquery'), COMPRESSX_VERSION, false);
|
||||
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_ajax_object', array('ajax_url' => admin_url('admin-ajax.php'),'ajax_nonce'=>wp_create_nonce('compressx_ajax')));
|
||||
|
||||
wp_enqueue_script('plupload-all');
|
||||
}
|
||||
else if(get_current_screen()->id=='upload'||get_current_screen()->id=='attachment')
|
||||
{
|
||||
wp_enqueue_script(COMPRESSX_SLUG, COMPRESSX_URL . '/includes/display/js/compressx.js', array('jquery'), COMPRESSX_VERSION, false);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_media', COMPRESSX_URL . '/includes/display/js/optimize.js', array('jquery'), COMPRESSX_VERSION, true);
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_ajax_object', array('ajax_url' => admin_url('admin-ajax.php'),'ajax_nonce'=>wp_create_nonce('compressx_ajax')));
|
||||
}
|
||||
|
||||
$toplevel_screen_id='toplevel_page_'.COMPRESSX_SLUG;
|
||||
$toplevel_screen_id=apply_filters('compressx_get_screen_id',$toplevel_screen_id);
|
||||
if(get_current_screen()->id==$toplevel_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
if(CompressX_Image_Opt_Method::check_imagick_avif())
|
||||
{
|
||||
$imagick_avif=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$imagick_avif=true;
|
||||
}
|
||||
|
||||
if(CompressX_Image_Method::is_support_gd_webp())
|
||||
{
|
||||
$support_gd_webp=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$support_gd_webp=false;
|
||||
}
|
||||
|
||||
if(CompressX_Image_Method::is_support_imagick_webp())
|
||||
{
|
||||
$support_imagick_webp=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$support_imagick_webp=false;
|
||||
}
|
||||
|
||||
if(CompressX_Image_Method::is_support_gd_avif())
|
||||
{
|
||||
$support_gd_avif=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$support_gd_avif=false;
|
||||
}
|
||||
|
||||
if(CompressX_Image_Method::is_support_imagick_avif())
|
||||
{
|
||||
$support_imagick_avif=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$support_imagick_avif=false;
|
||||
}
|
||||
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_alert',
|
||||
array('imagick_avif' => $imagick_avif,
|
||||
'support_gd_webp'=>$support_gd_webp,
|
||||
'support_imagick_webp'=>$support_imagick_webp,
|
||||
'support_gd_avif'=>$support_gd_avif,
|
||||
'support_imagick_avif'=>$support_imagick_avif,
|
||||
)
|
||||
);
|
||||
wp_enqueue_script('compressx-jquery-event-move', COMPRESSX_URL . '/includes/display/js/twentytwenty/jquery.event.move.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
wp_enqueue_script('compressx-twentytwenty', COMPRESSX_URL . '/includes/display/js/twentytwenty/jquery.twentytwenty.js', array('jquery', 'compressx-jquery-event-move'), COMPRESSX_VERSION, $arg);
|
||||
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_image_optimization', COMPRESSX_URL . '/includes/display_v2/js/compressx_image_optimization.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
wp_localize_script(
|
||||
COMPRESSX_SLUG . '_image_optimization',
|
||||
'compressx_image_optimization_i18n',
|
||||
array(
|
||||
'enable_webp_confirm' => __( 'Are you sure to enable WebP as output format? This will convert your images to WebP format.', 'compressx' ),
|
||||
'disable_webp_confirm' => __( 'Are you sure to disable WebP as output format?', 'compressx' ),
|
||||
'imagick6_avif_warning' => __( 'We detect that you use ImageMagick 6.x, this version has a known bug that can cause AVIF conversion timeout. Enabling AVIF conversion with this version is not recommended. Are you sure you wish to proceed?', 'compressx' ),
|
||||
'enable_avif_confirm' => __( 'Are you sure to enable AVIF as output format? This will convert your images to AVIF format.', 'compressx' ),
|
||||
'disable_avif_confirm' => __( 'Are you sure to disable AVIF as output format?', 'compressx' ),
|
||||
'supported' => __( 'Supported', 'compressx' ),
|
||||
'unsupported' => __( 'Unsupported', 'compressx' ),
|
||||
'failed_save' => __( 'Failed to save settings.', 'compressx' ),
|
||||
'save_error' => __( 'An error occurred while saving settings.', 'compressx' ),
|
||||
)
|
||||
);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_comparison', COMPRESSX_URL . '/includes/display_v2/js/compressx_image_comparison.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_bulk', COMPRESSX_URL . '/includes/display_v2/js/compressx_bulk.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
wp_localize_script(
|
||||
COMPRESSX_SLUG . '_bulk',
|
||||
'compressx_bulk_i18n',
|
||||
array(
|
||||
'cancel_confirm' => __( 'Are you sure to cancel this progressing?', 'compressx' ),
|
||||
'pause_confirm' => __( 'Are you sure to pause this progressing?', 'compressx' ),
|
||||
'delete_log_confirm' => __( 'Are you sure you want to delete this log file?', 'compressx' ),
|
||||
'leave_page_confirm' => __( 'Are you sure you want to leave this page?', 'compressx' ),
|
||||
'optimization_success' => __( 'Optimization Success', 'compressx' ),
|
||||
)
|
||||
);
|
||||
wp_enqueue_script('compressx-chart', COMPRESSX_URL . '/includes/display_v2/js/chart.umd.min.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
|
||||
|
||||
}
|
||||
|
||||
$settings_screen_id='compressx_page_settings-compressx';
|
||||
$settings_screen_id=apply_filters('compressx_get_screen_id',$settings_screen_id);
|
||||
if(get_current_screen()->id==$settings_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$path = $upload_dir['basedir'];
|
||||
$path = str_replace('\\','/',$path);
|
||||
$uploads_path = $path.'/';
|
||||
|
||||
$path = WP_CONTENT_DIR;
|
||||
$path = str_replace('\\','/',$path);
|
||||
$custom_root_path = $path.'/';
|
||||
|
||||
wp_localize_script(COMPRESSX_SLUG, 'compressx_uploads_root', array('path' => $uploads_path,'custom_path'=>$custom_root_path));
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_setting', COMPRESSX_URL . '/includes/display_v2/js/compressx_setting.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_custom_bulk', COMPRESSX_URL . '/includes/display/js/compressx_custom_bulk.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
|
||||
$cdn_screen_id='compressx_page_cdn-compressx';
|
||||
$cdn_screen_id=apply_filters('compressx_get_screen_id',$cdn_screen_id);
|
||||
if(get_current_screen()->id==$cdn_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_cdn', COMPRESSX_URL . '/includes/display_v2/js/compressx_cdn.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
|
||||
$logs_screen_id='compressx_page_info-compressx';
|
||||
$logs_screen_id=apply_filters('compressx_get_screen_id',$logs_screen_id);
|
||||
if(get_current_screen()->id==$logs_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_logs', COMPRESSX_URL . '/includes/display_v2/js/compressx_log.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}
|
||||
|
||||
$media_replace_id='media_page_media-replace-compressx';
|
||||
if(get_current_screen()->id==$media_replace_id)
|
||||
{
|
||||
if (array_key_exists("attachment_id", $_GET) && intval($_GET["attachment_id"]) > 0)
|
||||
{
|
||||
$attachment_id = intval($_GET["attachment_id"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$attachment_id=0;
|
||||
}
|
||||
|
||||
$mime_type=get_post_mime_type($attachment_id);
|
||||
$file = get_attached_file($attachment_id);
|
||||
$ft = wp_check_filetype($file);
|
||||
$ext = !empty($ft['ext']) ? $ft['ext'] : '';
|
||||
$type = $ext ? strtoupper($ext) : '-';
|
||||
|
||||
$url=admin_url("post.php?post=$attachment_id&action=edit");
|
||||
wp_localize_script('CompressX', 'compressx_media_replace', array('redirect_url' => $url,'type'=>$type));
|
||||
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
wp_enqueue_script('CompressX_media_replace', COMPRESSX_URL . '/includes/display_v2/js/compressx_media-replace.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
$info_screen_id='compressx_page_info-compressx';
|
||||
$info_screen_id=apply_filters('compressx_get_screen_id',$info_screen_id);
|
||||
if(get_current_screen()->id==$info_screen_id)
|
||||
{
|
||||
$arg=array();
|
||||
$arg['in_footer']=true;
|
||||
wp_enqueue_script(COMPRESSX_SLUG.'_systeminfo', COMPRESSX_URL . '/includes/display/js/compressx_system_info.js', array('jquery'), COMPRESSX_VERSION, $arg);
|
||||
}*/
|
||||
}
|
||||
|
||||
public function add_plugin_network_admin_menu()
|
||||
{
|
||||
if(apply_filters('compressx_support_mu',false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$menu['page_title']= 'CompressX';
|
||||
$menu['menu_title']= 'CompressX';
|
||||
$menu['capability']='manage_options';
|
||||
$menu['menu_slug']=COMPRESSX_SLUG;
|
||||
$menu['function']=array($this, 'mu_display');
|
||||
$menu['icon_url']='dashicons-images-alt2';
|
||||
$menu['position']=100;
|
||||
|
||||
add_menu_page( $menu['page_title'],$menu['menu_title'], $menu['capability'], $menu['menu_slug'], $menu['function'], $menu['icon_url'], $menu['position']);
|
||||
}
|
||||
|
||||
public function add_plugin_admin_menu()
|
||||
{
|
||||
$menu['page_title']= 'CompressX';
|
||||
$menu['menu_title']= 'CompressX';
|
||||
$menu['capability']='manage_options';
|
||||
$menu['menu_slug']=COMPRESSX_SLUG;
|
||||
$menu['function']=array($this->dashboard, 'display');
|
||||
$menu['icon_url']='dashicons-images-alt2';
|
||||
$menu['position']=100;
|
||||
$menu = apply_filters('compressx_get_main_admin_menus', $menu);
|
||||
|
||||
add_menu_page( $menu['page_title'],$menu['menu_title'], $menu['capability'], $menu['menu_slug'], $menu['function'], $menu['icon_url'], $menu['position']);
|
||||
|
||||
$submenu['parent_slug']=COMPRESSX_SLUG;
|
||||
$submenu['page_title']="Settings";
|
||||
$submenu['menu_title']="Settings";
|
||||
$submenu['capability']="manage_options";
|
||||
$submenu['index']=1;
|
||||
$submenu['menu_slug']=COMPRESSX_SLUG;
|
||||
$submenu['function']=array($this->dashboard, 'display');
|
||||
|
||||
$submenus[ $submenu['menu_slug']]=$submenu;
|
||||
|
||||
if(apply_filters('compressx_current_user_can',true,'compressx-can-use-cdn'))
|
||||
{
|
||||
$submenu['parent_slug']=COMPRESSX_SLUG;
|
||||
$submenu['page_title']="CDN Integration";
|
||||
$submenu['menu_title']="CDN Integration";
|
||||
$submenu['capability']="manage_options";
|
||||
$submenu['menu_slug']="cdn-compressx";
|
||||
$submenu['index']=3;
|
||||
$submenu['function']=array($this->cdn, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']]=$submenu;
|
||||
}
|
||||
|
||||
if(apply_filters('compressx_current_user_can',true,'compressx-can-use-logs'))
|
||||
{
|
||||
$submenu['parent_slug']=COMPRESSX_SLUG;
|
||||
$submenu['page_title']="Logs";
|
||||
$submenu['menu_title']="Logs";
|
||||
if(apply_filters('compressx_current_user_has',false,'compressx-can-use-logs'))
|
||||
{
|
||||
$submenu['capability']="compressx-can-use-logs";
|
||||
}
|
||||
else
|
||||
{
|
||||
$submenu['capability']="manage_options";
|
||||
}
|
||||
$submenu['menu_slug']="logs-compressx";
|
||||
$submenu['index']=19;
|
||||
$submenu['function']=array($this->log, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']]=$submenu;
|
||||
}
|
||||
|
||||
if(apply_filters('compressx_current_user_can',true,'compressx-can-use-system-info'))
|
||||
{
|
||||
$submenu['parent_slug']=COMPRESSX_SLUG;
|
||||
$submenu['page_title']="System Information";
|
||||
$submenu['menu_title']="System Information";
|
||||
if(apply_filters('compressx_current_user_has',false,'compressx-can-use-system-info'))
|
||||
{
|
||||
$submenu['capability']="compressx-can-use-system-info";
|
||||
}
|
||||
else
|
||||
{
|
||||
$submenu['capability']="manage_options";
|
||||
}
|
||||
$submenu['menu_slug']="info-compressx";
|
||||
$submenu['index']=20;
|
||||
$submenu['function']=array($this->system_info, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']]=$submenu;
|
||||
}
|
||||
|
||||
$submenu['parent_slug']=COMPRESSX_SLUG;
|
||||
$submenu['page_title']="Addons";
|
||||
$submenu['menu_title']="Addons";
|
||||
$submenu['capability']="manage_options";
|
||||
$submenu['menu_slug']="addons-compressx";
|
||||
$submenu['index']=21;
|
||||
$submenu['function']=array($this->addons, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']]=$submenu;
|
||||
|
||||
$submenus = apply_filters('compressx_get_admin_menus', $submenus);
|
||||
usort($submenus, function ($a, $b)
|
||||
{
|
||||
if ($a['index'] == $b['index'])
|
||||
return 0;
|
||||
|
||||
if ($a['index'] > $b['index'])
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
});
|
||||
|
||||
foreach ($submenus as $submenu)
|
||||
{
|
||||
add_submenu_page(
|
||||
$submenu['parent_slug'],
|
||||
$submenu['page_title'],
|
||||
$submenu['menu_title'],
|
||||
$submenu['capability'],
|
||||
$submenu['menu_slug'],
|
||||
$submenu['function']);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_plugin_admin_menu_v2()
|
||||
{
|
||||
$menu['page_title']= 'CompressX';
|
||||
$menu['menu_title']= 'CompressX';
|
||||
$menu['capability']='manage_options';
|
||||
$menu['menu_slug']=COMPRESSX_SLUG;
|
||||
$menu['function']=array($this->image_optimization, 'display');
|
||||
$menu['icon_url']='dashicons-images-alt2';
|
||||
$menu['position']=100;
|
||||
$menu = apply_filters('compressx_get_main_admin_menus', $menu);
|
||||
|
||||
add_menu_page( $menu['page_title'],$menu['menu_title'], $menu['capability'], $menu['menu_slug'], $menu['function'], $menu['icon_url'], $menu['position']);
|
||||
|
||||
if (apply_filters('compressx_current_user_can', true, 'compressx-can-convert'))
|
||||
{
|
||||
$submenu['parent_slug'] = COMPRESSX_SLUG;
|
||||
$submenu['page_title'] = "Image Optimization";
|
||||
$submenu['menu_title'] = "Image Optimization";
|
||||
if (apply_filters('compressx_current_user_has', false, 'compressx-can-convert'))
|
||||
{
|
||||
$submenu['capability'] = "compressx-can-convert";
|
||||
} else {
|
||||
$submenu['capability'] = "manage_options";
|
||||
}
|
||||
$submenu['index'] = 1;
|
||||
$submenu['menu_slug'] = COMPRESSX_SLUG;
|
||||
$submenu['function'] = array($this->image_optimization, 'display');
|
||||
$submenus[$submenu['menu_slug']] = $submenu;
|
||||
}
|
||||
|
||||
if (apply_filters('compressx_current_user_can', true, 'compressx-can-use-general-settings') || apply_filters('compressx_current_user_can', true, 'compressx-can-use-thumbnail-settings')) {
|
||||
$submenu['parent_slug'] = COMPRESSX_SLUG;
|
||||
$submenu['page_title'] = "Global Settings";
|
||||
$submenu['menu_title'] = "Settings";
|
||||
$submenu['capability'] = "manage_options";
|
||||
$submenu['menu_slug'] = "settings-compressx";
|
||||
$submenu['index'] = 2;
|
||||
$submenu['function'] = array($this->settings, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']] = $submenu;
|
||||
}
|
||||
|
||||
if (apply_filters('compressx_current_user_can', true, 'compressx-can-use-cdn')) {
|
||||
$submenu['parent_slug'] = COMPRESSX_SLUG;
|
||||
$submenu['page_title'] = "CDN Support";
|
||||
$submenu['menu_title'] = "CDN Support";
|
||||
if (apply_filters('compressx_current_user_has', false, 'compressx-can-use-cdn')) {
|
||||
$submenu['capability'] = "compressx-can-use-cdn";
|
||||
} else {
|
||||
$submenu['capability'] = "manage_options";
|
||||
}
|
||||
$submenu['menu_slug'] = "cdn-compressx";
|
||||
$submenu['index'] = 3;
|
||||
$submenu['function'] = array($this->cdn, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']] = $submenu;
|
||||
}
|
||||
|
||||
|
||||
if (apply_filters('compressx_current_user_can', true, 'compressx-can-use-system-info')) {
|
||||
$submenu['parent_slug'] = COMPRESSX_SLUG;
|
||||
$submenu['page_title'] = "Logs & System Information";
|
||||
$submenu['menu_title'] = "Logs & System Info";
|
||||
if (apply_filters('compressx_current_user_has', false, 'compressx-can-use-system-info')) {
|
||||
$submenu['capability'] = "compressx-can-use-system-info";
|
||||
} else {
|
||||
$submenu['capability'] = "manage_options";
|
||||
}
|
||||
$submenu['menu_slug'] = "info-compressx";
|
||||
$submenu['index'] = 19;
|
||||
$submenu['function'] = array($this->system_info, 'display');
|
||||
|
||||
$submenus[$submenu['menu_slug']] = $submenu;
|
||||
}
|
||||
|
||||
$submenu['parent_slug']=COMPRESSX_SLUG;
|
||||
$submenu['page_title']="Addons";
|
||||
$submenu['menu_title']="Addons";
|
||||
$submenu['capability']="manage_options";
|
||||
$submenu['menu_slug']="addons-compressx";
|
||||
$submenu['index']=21;
|
||||
$submenu['function']=array($this->addons, 'display');
|
||||
$submenus[$submenu['menu_slug']] = $submenu;
|
||||
|
||||
$submenus = apply_filters('compressx_get_admin_menus', $submenus);
|
||||
usort($submenus, function ($a, $b)
|
||||
{
|
||||
if ($a['index'] == $b['index'])
|
||||
return 0;
|
||||
|
||||
if ($a['index'] > $b['index'])
|
||||
return 1;
|
||||
else
|
||||
return -1;
|
||||
});
|
||||
|
||||
foreach ($submenus as $submenu)
|
||||
{
|
||||
add_submenu_page(
|
||||
$submenu['parent_slug'],
|
||||
$submenu['page_title'],
|
||||
$submenu['menu_title'],
|
||||
$submenu['capability'],
|
||||
$submenu['menu_slug'],
|
||||
$submenu['function']);
|
||||
}
|
||||
}
|
||||
|
||||
public function add_media_replace_menu()
|
||||
{
|
||||
$has=false;
|
||||
if(apply_filters('compressx_pro_media_replace',$has))
|
||||
{
|
||||
return;
|
||||
}
|
||||
$submenu['parent_slug']='upload.php';
|
||||
$submenu['page_title']="Replace Media";
|
||||
$submenu['menu_title']="Replace Media";
|
||||
$submenu['capability']="upload_files";
|
||||
$submenu['menu_slug']="media-replace-compressx";
|
||||
$submenu['function']=array($this->media_replace, 'display');
|
||||
|
||||
add_submenu_page( $submenu['parent_slug'],$submenu['page_title'], $submenu['menu_title'], $submenu['capability'], $submenu['menu_slug'], $submenu['function']);
|
||||
}
|
||||
|
||||
public function hide_media_replace_menu($submenu_file)
|
||||
{
|
||||
$has=false;
|
||||
if(apply_filters('compressx_pro_media_replace',$has))
|
||||
{
|
||||
return $submenu_file;
|
||||
}
|
||||
|
||||
global $plugin_page;
|
||||
// Select another submenu item to highlight (optional).
|
||||
if ( $plugin_page && $plugin_page == 'media-replace-compressx' )
|
||||
{
|
||||
$submenu_file = 'upload.php';
|
||||
}
|
||||
|
||||
// Hide the submenu.
|
||||
|
||||
remove_submenu_page( 'upload.php', 'media-replace-compressx' );
|
||||
|
||||
return $submenu_file;
|
||||
}
|
||||
|
||||
public function mu_display()
|
||||
{
|
||||
?>
|
||||
<div id="compressx-root">
|
||||
<div id="compressx-wrap">
|
||||
<?php
|
||||
$this->output_nav();
|
||||
$this->output_header();
|
||||
?>
|
||||
<section style="display:block;">
|
||||
<div class="compressx-container compressx-section">
|
||||
<div class="compressx-notification">
|
||||
<p><span class="dashicons dashicons-warning" style="color:#FF3951;"></span>
|
||||
<span>Currently, AVIF, WebP Converter Plugin (CompressX.io) does not support WordPress Multisite.</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_nav()
|
||||
{
|
||||
?>
|
||||
<nav>
|
||||
<div class="compressx-container compressx-menu">
|
||||
<h2>Compress<span style="color:#175cff;">X</span><span style="font-size:1.2rem;">.io</span>
|
||||
<span class="compressx-pro-version" style="font-size:0.7rem;">
|
||||
<span><?php echo esc_html(COMPRESSX_VERSION);?></span><span> FREE</span>
|
||||
<?php
|
||||
if($this->check_update())
|
||||
{
|
||||
$url=get_admin_url().'plugins.php?s=compressx&plugin_status=all';
|
||||
?><span style="padding:0 0.2rem"></span><a href="<?php echo esc_url($url)?>">(Latest Version: <?php echo esc_html( $this->latest_version());?>)</a><?php
|
||||
}
|
||||
?>
|
||||
</span>
|
||||
</h2>
|
||||
<ul class="cx-menu-ul-large">
|
||||
<li><a href="https://compressx.io/docs/compressx-overview/"><strong><?php esc_html_e('Documentation','compressx')?></strong></a></li>
|
||||
<li><a href="https://compressx.io/docs/troubleshooting/"><strong><?php esc_html_e('Troubleshooting','compressx')?></strong></a></li>
|
||||
<li><a href="https://wordpress.org/support/plugin/compressx/"><strong><?php esc_html_e('Support','compressx')?></strong></a></li>
|
||||
</ul>
|
||||
<ul class="cx-menu-ul-mini">
|
||||
<li><a href="">Documentation</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function check_update()
|
||||
{
|
||||
$update_data = wp_get_update_data();
|
||||
if (isset($update_data['counts']['plugins']))
|
||||
{
|
||||
$plugins = get_site_transient('update_plugins');
|
||||
if (isset($plugins->response[COMPRESSX_NAME]))
|
||||
{
|
||||
$plugin_data = $plugins->response[COMPRESSX_NAME];
|
||||
$latest_version = $plugin_data->new_version;
|
||||
if(version_compare($latest_version,COMPRESSX_VERSION,'>'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function latest_version()
|
||||
{
|
||||
$plugins = get_site_transient('update_plugins');
|
||||
if (isset($plugins->response[COMPRESSX_NAME]))
|
||||
{
|
||||
$plugin_data = $plugins->response[COMPRESSX_NAME];
|
||||
return $plugin_data->new_version;
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
public function output_header()
|
||||
{
|
||||
?>
|
||||
<header>
|
||||
<div class="compressx-container compressx-header">
|
||||
|
||||
</div>
|
||||
</header>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_footer()
|
||||
{
|
||||
?>
|
||||
<footer>
|
||||
<div class="compressx-container compressx-menu">
|
||||
<div style="margin: auto;"><strong><span>If you like our plugin, a <a href="https://wordpress.org/support/plugin/compressx/reviews"><span class="dashicons dashicons-star-filled" style="color:#ffb900;"></span>
|
||||
<span class="dashicons dashicons-star-filled" style="color:#ffb900;"></span>
|
||||
<span class="dashicons dashicons-star-filled" style="color:#ffb900;"></span>
|
||||
<span class="dashicons dashicons-star-filled" style="color:#ffb900;"></span>
|
||||
<span class="dashicons dashicons-star-filled" style="color:#ffb900;"></span></a>
|
||||
<span>will help us a lot, thanks in advance!</span></strong>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_footer_v2()
|
||||
{
|
||||
$defaults = array(
|
||||
'show_review_link' => true,
|
||||
'review_url' => 'https://wordpress.org/support/plugin/compressx/reviews',
|
||||
'review_text' => __('Enjoying CompressX? Please', 'compressx') .
|
||||
'<a href="%s" target="_blank">' .
|
||||
__('leave us a', 'compressx') . ' ' .
|
||||
'<span class="compressx-v2-text-yellow-500">★★★★★</span> ' .
|
||||
__('review', 'compressx') .
|
||||
'</a> — ' .
|
||||
__('it helps a lot!', 'compressx'),
|
||||
'container_class' => 'compressx-v2-border-t compressx-v2-pt-4 compressx-v2-text-center',
|
||||
'text_class' => 'compressx-v2-text-sm compressx-v2-text-gray-600'
|
||||
);
|
||||
|
||||
$args=$defaults;
|
||||
|
||||
if (!$args['show_review_link'])
|
||||
{
|
||||
return;
|
||||
}
|
||||
?>
|
||||
<!-- Footer -->
|
||||
<div class="<?php echo esc_attr($args['container_class']) ?>">
|
||||
<p class="<?php echo esc_attr($args['text_class']) ?>">
|
||||
<?php echo wp_kses_post(sprintf($args['review_text'], esc_url($args['review_url']))); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,642 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_Logs
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
//add_action('wp_ajax_compressx_open_log',array( $this,'open_log'));
|
||||
//add_action('wp_ajax_compressx_download_log', array($this, 'download_log'));
|
||||
//add_action('wp_ajax_compressx_delete_log', array($this, 'delete_log'));
|
||||
//add_action('wp_ajax_compressx_delete_all_log', array($this, 'delete_all_log'));
|
||||
//
|
||||
//add_action('wp_ajax_compressx_get_logs_list', array($this, 'get_logs_list'));
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
?>
|
||||
<div id="compressx-root">
|
||||
<div id="compressx-wrap">
|
||||
<?php
|
||||
$this->output_nav();
|
||||
$this->output_header();
|
||||
$this->output_logs();
|
||||
$this->output_footer();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_nav()
|
||||
{
|
||||
do_action('compressx_output_nav');
|
||||
}
|
||||
|
||||
public function output_header()
|
||||
{
|
||||
do_action('compressx_output_header');
|
||||
}
|
||||
|
||||
public function output_footer()
|
||||
{
|
||||
do_action('compressx_output_footer');
|
||||
}
|
||||
|
||||
public function output_logs()
|
||||
{
|
||||
?>
|
||||
<section>
|
||||
<div class="compressx-container compressx-header">
|
||||
<div class="compressx-logs">
|
||||
<article>
|
||||
<div class="cx-title"><span><?php esc_html_e('Logs: ','compressx')?></span>
|
||||
<span class="cx-bulk-opt-results">
|
||||
<span><a style="cursor: pointer" id="cx_empty_log"><?php esc_html_e('Empty Logs','compressx')?></a></span>
|
||||
</div>
|
||||
<div id="cx_log_list" class="cx-table-overflow">
|
||||
<?php
|
||||
//$list=$this->get_log_list();
|
||||
//$log_list=new CompressX_Log_List();
|
||||
//$log_list->set_log_list($list);
|
||||
//$log_list->prepare_items();
|
||||
//$log_list->display();
|
||||
?>
|
||||
</div>
|
||||
</article>
|
||||
<div id="cx_log_scroll_test"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="cx_log_detail_section" style="display: none">
|
||||
<div class="compressx-container compressx-section">
|
||||
<div class="compressx-bulk-log">
|
||||
<article>
|
||||
<div class="cx-title">
|
||||
<span>Log: </span><span id="cx_log_name"></span>
|
||||
</div>
|
||||
<div class="cx-logs-table">
|
||||
<textarea id="cx_read_optimize_log_content" style="width:100%; height:300px; overflow-x:auto;">
|
||||
</textarea>
|
||||
</div>
|
||||
<div class="compressx-general-settings-footer">
|
||||
<input class="button-primary cx-button" id="cx_close_log" type="submit" value="Close">
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<?php
|
||||
}
|
||||
|
||||
/* not use anymore
|
||||
public function get_log_list()
|
||||
{
|
||||
$log_list=array();
|
||||
$log=new CompressX_Log();
|
||||
$dir=$log->GetSaveLogFolder();
|
||||
$files=array();
|
||||
$handler=opendir($dir);
|
||||
$regex='#^compressx.*_log.txt#';
|
||||
if($handler!==false)
|
||||
{
|
||||
while(($filename=readdir($handler))!==false)
|
||||
{
|
||||
if($filename != "." && $filename != "..")
|
||||
{
|
||||
if(is_dir($dir.$filename))
|
||||
{
|
||||
continue;
|
||||
}else{
|
||||
if(preg_match($regex,$filename))
|
||||
{
|
||||
$files[$filename] = $dir.$filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($handler)
|
||||
@closedir($handler);
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$handle = @fopen($file, "r");
|
||||
if ($handle)
|
||||
{
|
||||
$log_file['file_name']=basename($file);
|
||||
if(preg_match('/compressx-(.*?)_/', basename($file), $matches))
|
||||
{
|
||||
$id= $matches[0];
|
||||
$id=substr($id,0,strlen($id)-1);
|
||||
$log_file['id']=$id;
|
||||
}
|
||||
$log_file['path']=$file;
|
||||
$log_file['size']=filesize($file);
|
||||
$log_file['name']=basename($file);
|
||||
$log_file['time']=filemtime($file);
|
||||
|
||||
$offset=get_option('gmt_offset');
|
||||
$localtime = $log_file['time'] + $offset * 60 * 60;
|
||||
$log_file['date']=gmdate('M-d-y H:i',$localtime);
|
||||
|
||||
$line = fgets($handle);
|
||||
if($line!==false)
|
||||
{
|
||||
$pos=strpos($line,'Log created: ');
|
||||
if($pos!==false)
|
||||
{
|
||||
$log_file['time']=substr ($line,$pos+strlen('Log created: '));
|
||||
}
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
$log_list[basename($file)]=$log_file;
|
||||
}
|
||||
}
|
||||
|
||||
$log_list =$this->sort_list($log_list);
|
||||
|
||||
return $log_list;
|
||||
}
|
||||
|
||||
public function get_log_list_ex($start_date,$start_time,$end_date,$end_time)
|
||||
{
|
||||
if(empty($start_date))
|
||||
{
|
||||
$start=0;
|
||||
}
|
||||
else if(empty($start_time))
|
||||
{
|
||||
$start=strtotime($start_date);
|
||||
}
|
||||
else
|
||||
{
|
||||
$start=strtotime($start_date.' '.$start_time);
|
||||
}
|
||||
|
||||
if($start>0)
|
||||
{
|
||||
$offset=get_option('gmt_offset');
|
||||
$start = $start - $offset * 60 * 60;
|
||||
}
|
||||
|
||||
if(empty($end_date))
|
||||
{
|
||||
$end=0;
|
||||
}
|
||||
else if(empty($end_time))
|
||||
{
|
||||
$end=strtotime($end_date);
|
||||
}
|
||||
else
|
||||
{
|
||||
$end=strtotime($end_date.' '.$end_time);
|
||||
}
|
||||
|
||||
if($end>0)
|
||||
{
|
||||
$offset=get_option('gmt_offset');
|
||||
$end = $end - $offset * 60 * 60;
|
||||
}
|
||||
|
||||
|
||||
$log_list=array();
|
||||
$log=new CompressX_Log();
|
||||
$dir=$log->GetSaveLogFolder();
|
||||
$files=array();
|
||||
$handler=opendir($dir);
|
||||
$regex='#^compressx.*_log.txt#';
|
||||
if($handler!==false)
|
||||
{
|
||||
while(($filename=readdir($handler))!==false)
|
||||
{
|
||||
if($filename != "." && $filename != "..")
|
||||
{
|
||||
if(is_dir($dir.$filename))
|
||||
{
|
||||
continue;
|
||||
}else{
|
||||
if(preg_match($regex,$filename))
|
||||
{
|
||||
$files[$filename] = $dir.$filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($handler)
|
||||
@closedir($handler);
|
||||
}
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$handle = @fopen($file, "r");
|
||||
if ($handle)
|
||||
{
|
||||
$log_file['file_name']=basename($file);
|
||||
if(preg_match('/compressx-(.*?)_/', basename($file), $matches))
|
||||
{
|
||||
$id= $matches[0];
|
||||
$id=substr($id,0,strlen($id)-1);
|
||||
$log_file['id']=$id;
|
||||
}
|
||||
$log_file['path']=$file;
|
||||
$log_file['size']=filesize($file);
|
||||
$log_file['name']=basename($file);
|
||||
$log_file['time']=preg_replace('/[^0-9]/', '', basename($file));
|
||||
|
||||
$offset=get_option('gmt_offset');
|
||||
$localtime = strtotime($log_file['time']) + $offset * 60 * 60;
|
||||
$log_file['date']=gmdate('M-d-y H:i',$localtime);
|
||||
|
||||
$line = fgets($handle);
|
||||
if($line!==false)
|
||||
{
|
||||
$pos=strpos($line,'Log created: ');
|
||||
if($pos!==false)
|
||||
{
|
||||
$log_file['time']=substr ($line,$pos+strlen('Log created: '));
|
||||
}
|
||||
}
|
||||
|
||||
fclose($handle);
|
||||
|
||||
if($start>0&&$end>0)
|
||||
{
|
||||
if($localtime>=$start&&$localtime<=$end)
|
||||
{
|
||||
$log_list[basename($file)]=$log_file;
|
||||
}
|
||||
}
|
||||
else if($start>0)
|
||||
{
|
||||
if($localtime>=$start)
|
||||
{
|
||||
$log_list[basename($file)]=$log_file;
|
||||
}
|
||||
}
|
||||
else if($end>0)
|
||||
{
|
||||
if($localtime<=$end)
|
||||
{
|
||||
$log_list[basename($file)]=$log_file;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$log_list[basename($file)]=$log_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$log_list =$this->sort_list($log_list);
|
||||
|
||||
return $log_list;
|
||||
}
|
||||
|
||||
public function sort_list($list)
|
||||
{
|
||||
uasort ($list,function($a, $b)
|
||||
{
|
||||
if($a['time']>$b['time'])
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if($a['time']===$b['time'])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function get_logs_list()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-logs');
|
||||
|
||||
if(isset($_POST['start_date']))
|
||||
{
|
||||
$start_date=sanitize_key($_POST['start_date']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$start_date='';
|
||||
}
|
||||
|
||||
if(isset($_POST['start_time']))
|
||||
{
|
||||
$start_time=sanitize_key($_POST['start_time']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$start_time='';
|
||||
}
|
||||
|
||||
if(isset($_POST['end_date']))
|
||||
{
|
||||
$end_date=sanitize_key($_POST['end_date']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$end_date='';
|
||||
}
|
||||
|
||||
if(isset($_POST['end_time']))
|
||||
{
|
||||
$end_time=sanitize_key($_POST['end_time']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$end_time='';
|
||||
}
|
||||
|
||||
if(isset($_POST['page']))
|
||||
{
|
||||
$page=sanitize_key($_POST['page']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$page=0;
|
||||
}
|
||||
|
||||
$list=$this->get_log_list_ex($start_date,$start_time,$end_date,$end_time);
|
||||
$log_list=new CompressX_Log_List();
|
||||
$log_list->set_log_list($list,$page);
|
||||
$log_list->prepare_items();
|
||||
ob_start();
|
||||
$log_list->display();
|
||||
$json['result'] = 'success';
|
||||
$json['html'] = ob_get_clean();
|
||||
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
|
||||
public function open_log()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-logs');
|
||||
|
||||
try
|
||||
{
|
||||
if(!isset($_POST['filename']))
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
$file_name=sanitize_text_field($_POST['filename']);
|
||||
$loglist=$this->get_log_list();
|
||||
if(!empty($loglist))
|
||||
{
|
||||
if(isset($loglist[$file_name]))
|
||||
{
|
||||
$log=$loglist[$file_name];
|
||||
}
|
||||
else
|
||||
{
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] =__('The log not found ','compressx').$file_name;
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
|
||||
$path=$log['path'];
|
||||
if (!file_exists($path))
|
||||
{
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] = __('The log not found ','compressx').$file_name;
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
|
||||
$file = fopen($path, 'r');
|
||||
|
||||
if (!$file) {
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] = __('Unable to open the log file.','compressx');
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
|
||||
$offset=get_option('gmt_offset');
|
||||
$localtime = strtotime($log['time']) + $offset * 60 * 60;
|
||||
$buffer = 'Open log file created:'.gmdate('Y-m-d',$localtime).' '.PHP_EOL;
|
||||
while (!feof($file)) {
|
||||
$buffer .= fread($file, 1024);
|
||||
}
|
||||
fclose($file);
|
||||
|
||||
$json['result'] = 'success';
|
||||
$json['html'] = $buffer;
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] = 'The log not found.';
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
}
|
||||
catch (Exception $error)
|
||||
{
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
echo wp_json_encode(array('result'=>'failed','error'=>$message));
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
public function download_log()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-logs');
|
||||
|
||||
$admin_url = admin_url();
|
||||
|
||||
try
|
||||
{
|
||||
if (isset($_REQUEST['log']))
|
||||
{
|
||||
$log = sanitize_text_field($_REQUEST['log']);
|
||||
$log = basename($log);
|
||||
$loglist=$this->get_log_list();
|
||||
|
||||
if(isset($loglist[$log]))
|
||||
{
|
||||
$log=$loglist[$log];
|
||||
}
|
||||
else
|
||||
{
|
||||
$message= 'Log does not exist. It might have been deleted or lost during a website migration.';
|
||||
echo esc_html($message);
|
||||
die();
|
||||
}
|
||||
|
||||
$path=$log['path'];
|
||||
|
||||
if (!file_exists($path))
|
||||
{
|
||||
$message= 'Log does not exist. It might have been deleted or lost during a website migration.';
|
||||
echo esc_html($message);
|
||||
die();
|
||||
}
|
||||
|
||||
if (file_exists($path))
|
||||
{
|
||||
if (session_id())
|
||||
session_write_close();
|
||||
|
||||
$size = filesize($path);
|
||||
if (!headers_sent())
|
||||
{
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: text');
|
||||
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Content-Length: ' . $size);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
readfile($path);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo esc_html(' file not found.');
|
||||
die();
|
||||
}
|
||||
|
||||
} else {
|
||||
$message = 'Reading the log failed. Please try again.';
|
||||
echo esc_html($message);
|
||||
die();
|
||||
}
|
||||
}
|
||||
catch (Exception $error)
|
||||
{
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
echo esc_html($message);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_log()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-logs');
|
||||
|
||||
try
|
||||
{
|
||||
if(!isset($_POST['filename']))
|
||||
{
|
||||
die();
|
||||
}
|
||||
|
||||
$file_name=sanitize_text_field($_POST['filename']);
|
||||
$loglist=$this->get_log_list();
|
||||
if(!empty($loglist))
|
||||
{
|
||||
if(isset($loglist[$file_name]))
|
||||
{
|
||||
$log=$loglist[$file_name];
|
||||
}
|
||||
else
|
||||
{
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] = __('The log not found ','compressx').$file_name;
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
|
||||
$path=$log['path'];
|
||||
@wp_delete_file($path);
|
||||
|
||||
$list=$this->get_log_list();
|
||||
$log_list=new CompressX_Log_List();
|
||||
$log_list->set_log_list($list);
|
||||
$log_list->prepare_items();
|
||||
ob_start();
|
||||
$log_list->display();
|
||||
$json['result'] = 'success';
|
||||
$json['html'] = ob_get_clean();
|
||||
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] = __('The log not found ','compressx');
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
}
|
||||
catch (Exception $error)
|
||||
{
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
echo wp_json_encode(array('result'=>'failed','error'=>$message));
|
||||
}
|
||||
die();
|
||||
}
|
||||
|
||||
public function delete_all_log()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-logs');
|
||||
|
||||
try
|
||||
{
|
||||
$loglist=$this->get_log_list();
|
||||
if(!empty($loglist))
|
||||
{
|
||||
foreach ($loglist as $log)
|
||||
{
|
||||
$path=$log['path'];
|
||||
@wp_delete_file($path);
|
||||
}
|
||||
|
||||
$list=$this->get_log_list();
|
||||
$log_list=new CompressX_Log_List();
|
||||
$log_list->set_log_list($list);
|
||||
$log_list->prepare_items();
|
||||
ob_start();
|
||||
$log_list->display();
|
||||
$json['result'] = 'success';
|
||||
$json['html'] = ob_get_clean();
|
||||
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
else
|
||||
{
|
||||
$json['result'] = 'failed';
|
||||
$json['error'] = __('The log not found ','compressx');
|
||||
echo wp_json_encode($json);
|
||||
die();
|
||||
}
|
||||
}
|
||||
catch (Exception $error)
|
||||
{
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
echo wp_json_encode(array('result'=>'failed','error'=>$message));
|
||||
}
|
||||
die();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,616 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
class CompressX_System_Info
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
//add_action('wp_ajax_compressx_create_debug_package',array( $this,'create_debug_package'));
|
||||
//add_action('wp_ajax_compressx_send_debug_info',array( $this,'send_debug_info'));
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
public function display()
|
||||
{
|
||||
?>
|
||||
<div id="compressx-root">
|
||||
<div id="compressx-wrap">
|
||||
<?php
|
||||
$this->output_nav();
|
||||
$this->output_header();
|
||||
$this->output_debug();
|
||||
$this->output_footer();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function output_nav()
|
||||
{
|
||||
do_action('compressx_output_nav');
|
||||
}
|
||||
|
||||
public function output_header()
|
||||
{
|
||||
do_action('compressx_output_header');
|
||||
}
|
||||
|
||||
public function output_debug()
|
||||
{
|
||||
?>
|
||||
<section>
|
||||
<div class="compressx-container compressx-section ">
|
||||
<div class="compressx-bulk-log">
|
||||
<article>
|
||||
<div style="padding: 0 0 20px 10px;">
|
||||
<?php esc_html_e('There are two ways available to send us the debug information. The first one is recommended.', 'compressx'); ?>
|
||||
</div>
|
||||
<div style="padding-left: 10px;">
|
||||
<strong><?php esc_html_e('Method 1.', 'compressx'); ?></strong> <?php esc_html_e('If you have configured SMTP on your site, enter your email address and click the button below to send us the relevant information (website info and errors logs) when you are encountering errors. This will help us figure out what happened. Once the issue is resolved, we will inform you by your email address.', 'compressx'); ?>
|
||||
</div>
|
||||
<div style="padding:10px 10px 0">
|
||||
<span>
|
||||
<?php esc_html_e('CompressX support email:', 'compressx'); ?>
|
||||
</span><input type="text" id="compressx_support_mail" value="support@compressx.io" readonly />
|
||||
<span>
|
||||
<?php esc_html_e('Your email:', 'compressx'); ?>
|
||||
</span>
|
||||
<input type="text" id="compressx_user_mail" />
|
||||
</div>
|
||||
<div style="padding:10px 10px;">
|
||||
<textarea id="compressx_debug_comment" class="wp-editor-area" style="width:100%; height: 200px;" autocomplete="off" cols="60" placeholder="<?php esc_attr_e('Please describe your problem here.', 'compressx'); ?>" ></textarea>
|
||||
</div>
|
||||
<div style="padding:10px 10px;">
|
||||
<input id="compressx_debug_submit" class="button-primary" type="submit" value="<?php esc_attr_e( 'Send Debug Information to Us', 'compressx' ); ?>" />
|
||||
<span style="padding:0 0.2rem;"></span>
|
||||
<span id="compressx_send_success_text" class="success hidden" aria-hidden="true" style="color:#007017"><?php esc_html_e('Send succeeded.','compressx')?></span>
|
||||
</div>
|
||||
<div style="clear:both;"></div>
|
||||
<div style="padding-left: 10px;">
|
||||
<strong><?php esc_html_e('Method 2.', 'compressx'); ?></strong> <?php esc_html_e('If you didn’t configure SMTP on your site, click the button below to download the relevant information (website info and error logs) to your PC when you are encountering some errors. Sending the files to us will help us diagnose what happened.', 'compressx'); ?>
|
||||
</div>
|
||||
<div style="padding: 10px 10px;">
|
||||
<input class="button-primary" id="compressx_download_debug_info" type="submit" value="<?php esc_attr_e( 'Download', 'compressx' ); ?>" />
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section>
|
||||
<div class="compressx-container compressx-section ">
|
||||
<div class="compressx-bulk-log" style="padding-bottom: 0;">
|
||||
<?php
|
||||
//$this->output_debug_info();
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<?php
|
||||
}
|
||||
|
||||
/*not ues any more
|
||||
public function output_debug_info()
|
||||
{
|
||||
?>
|
||||
<article>
|
||||
<div class="cx-title">
|
||||
<span><?php esc_html_e('Debug Information', 'compressx'); ?>: </span>
|
||||
</div>
|
||||
<div class="cx-table-overflow">
|
||||
<table class="wp-list-table widefat striped">
|
||||
<thead class="website-info-head">
|
||||
<tr>
|
||||
<th class="row-title" style="min-width: 260px;" colspan="3"><?php esc_html_e('Debug Information', 'compressx'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$debug_info=$this->get_debug_info();
|
||||
if(!empty($debug_info))
|
||||
{
|
||||
foreach ($debug_info as $key=>$value)
|
||||
{
|
||||
if($key=='setting')
|
||||
continue;
|
||||
|
||||
$website_value='';
|
||||
if (is_array($value))
|
||||
{
|
||||
foreach ($value as $arr_value)
|
||||
{
|
||||
if (empty($website_value))
|
||||
{
|
||||
$website_value = $website_value . $arr_value;
|
||||
} else {
|
||||
$website_value = $website_value . ', ' . $arr_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($value === true || $value === false)
|
||||
{
|
||||
if($value === true) {
|
||||
$website_value = 'true';
|
||||
}
|
||||
else{
|
||||
$website_value = 'false';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$website_value = $value;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td class="row-title tablelistcolumn"><label for="tablecell"><?php echo esc_html($key); ?></label></td>
|
||||
<td class="tablelistcolumn"><?php echo esc_html($website_value); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</article>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function get_debug_info()
|
||||
{
|
||||
global $wp_version;
|
||||
$debug_info=array();
|
||||
|
||||
$debug_info['home']=$this->get_domain();
|
||||
$debug_info['Server name']=$_SERVER['SERVER_NAME'];
|
||||
$debug_info['Web Server'] = sanitize_text_field($_SERVER["SERVER_SOFTWARE"]);
|
||||
$debug_info['CompressX version'] = COMPRESSX_VERSION;
|
||||
$debug_info['Wordpress version'] = $wp_version;
|
||||
|
||||
$debug_info['PHP version'] = phpversion();
|
||||
|
||||
if( !function_exists( 'gd_info' ))
|
||||
{
|
||||
$debug_info['GD extension']=__("GD extension is not installed or enabled.",'compressx');
|
||||
}
|
||||
else
|
||||
{
|
||||
$debug_info['GD extension']=__("The GD extension has been properly installed.",'compressx');
|
||||
|
||||
$info=gd_info();
|
||||
$debug_info['GD Version']=isset($info['GD Version'])?$info['GD Version']:'';
|
||||
$debug_info['GD WebP Support']=isset($info['WebP Support'])?$info['WebP Support']:false;
|
||||
$debug_info['GD AVIF Support']=isset($info['AVIF Support'])?$info['AVIF Support']:false;
|
||||
}
|
||||
|
||||
if ( extension_loaded( 'imagick' ) && class_exists( '\Imagick' ) )
|
||||
{
|
||||
$debug_info['Imagick extension']=__("The imagick extension has been properly installed.",'compressx');
|
||||
$debug_info['Imagick Version']=\Imagick::getVersion();
|
||||
|
||||
if( \Imagick::queryformats( 'WEBP' ))
|
||||
{
|
||||
$debug_info['Imagick WebP Support']=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$debug_info['Imagick WebP Support']=false;
|
||||
}
|
||||
|
||||
if( \Imagick::queryformats( 'AVIF' ))
|
||||
{
|
||||
$debug_info['Imagick AVIF Support']=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$debug_info['Imagick AVIF Support']=false;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$debug_info['Imagick extension']=__("Imagick extension is not installed or enabled.",'compressx');
|
||||
}
|
||||
|
||||
$debug_info['active_plugins'] = get_option('active_plugins');
|
||||
$debug_info['active_theme'] = wp_get_theme()->get_template();
|
||||
|
||||
$debug_info['memory_current'] = size_format(memory_get_usage(),2);
|
||||
$debug_info['memory_peak'] = size_format(memory_get_peak_usage(),2);
|
||||
$debug_info['memory_limit'] = ini_get('memory_limit');
|
||||
|
||||
include_once COMPRESSX_DIR . '/includes/class-compressx-rewrite-checker.php';
|
||||
$test=new CompressX_Rewrite_Checker();
|
||||
$result=$test->test_ex();
|
||||
if($result['result']=='success')
|
||||
{
|
||||
$debug_info['Rewrite rules test'] = 'success';
|
||||
}
|
||||
else
|
||||
{
|
||||
$debug_info['Rewrite rules test'] = $result['error'];
|
||||
}
|
||||
|
||||
$options=get_option('compressx_general_settings',array());
|
||||
$debug_info['setting']=$options;
|
||||
|
||||
$quality_options=get_option('compressx_quality',array());
|
||||
$converter_method=get_option('compressx_converter_method',false);
|
||||
$output_format_webp=get_option('compressx_output_format_webp',1);
|
||||
$output_format_avif=get_option('compressx_output_format_avif',1);
|
||||
$debug_info['setting']['quality']=$quality_options;
|
||||
$debug_info['setting']['output_format_webp']=$output_format_webp;
|
||||
$debug_info['setting']['output_format_avif']=$output_format_avif;
|
||||
$debug_info['setting']['converter_method']=$converter_method;
|
||||
$debug_info['setting']=wp_json_encode($debug_info['setting']);
|
||||
return $debug_info;
|
||||
}
|
||||
|
||||
public function get_domain()
|
||||
{
|
||||
global $wpdb;
|
||||
$home_url = home_url();
|
||||
$db_home_url = home_url();
|
||||
$home_url_sql = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name = %s", 'home' ) );
|
||||
foreach ( $home_url_sql as $home )
|
||||
{
|
||||
$db_home_url = untrailingslashit($home->option_value);
|
||||
}
|
||||
|
||||
if($home_url === $db_home_url)
|
||||
{
|
||||
$domain = $home_url;
|
||||
}
|
||||
else
|
||||
{
|
||||
$domain = $db_home_url;
|
||||
}
|
||||
|
||||
return strtolower($domain);
|
||||
}
|
||||
|
||||
public function output_footer()
|
||||
{
|
||||
do_action('compressx_output_footer');
|
||||
}
|
||||
|
||||
public function get_website_info()
|
||||
{
|
||||
try
|
||||
{
|
||||
$version = COMPRESSX_VERSION;
|
||||
$ret['result'] = 'success';
|
||||
$ret['data']['version'] = $version;
|
||||
$ret['data']['home_url'] = get_home_url();
|
||||
$ret['data']['abspath'] = ABSPATH;
|
||||
$ret['data']['wp_content_path'] = WP_CONTENT_DIR;
|
||||
$ret['data']['wp_plugin_path'] = WP_PLUGIN_DIR;
|
||||
$ret['data']['active_plugins'] = get_option('active_plugins');
|
||||
|
||||
global $wp_version;
|
||||
$ret['wp_version'] = $wp_version;
|
||||
if (is_multisite()) {
|
||||
$ret['data']['multisite'] = 'enable';
|
||||
} else {
|
||||
$ret['data']['multisite'] = 'disable';
|
||||
}
|
||||
$ret['data']['web_server'] = sanitize_text_field($_SERVER["SERVER_SOFTWARE"]);
|
||||
$ret['data']['php_version'] = phpversion();
|
||||
global $wpdb;
|
||||
$ret['data']['mysql_version'] = $wpdb->db_version();
|
||||
if (defined('WP_DEBUG')) {
|
||||
$ret['data']['wp_debug'] = WP_DEBUG;
|
||||
} else {
|
||||
$ret['wp_debug'] = false;
|
||||
}
|
||||
$ret['data']['language'] = get_bloginfo('language');
|
||||
$ret['data']['upload_max_filesize'] = ini_get("upload_max_filesize");
|
||||
|
||||
$current_offset = get_option( 'gmt_offset' );
|
||||
$timezone = get_option( 'timezone_string' );
|
||||
|
||||
if ( false !== strpos( $timezone, 'Etc/GMT' ) ) {
|
||||
$timezone = '';
|
||||
}
|
||||
|
||||
if ( empty( $timezone ) ) {
|
||||
if ( 0 == $current_offset ) {
|
||||
$timezone = 'UTC+0';
|
||||
} elseif ( $current_offset < 0 ) {
|
||||
$timezone = 'UTC' . $current_offset;
|
||||
} else {
|
||||
$timezone = 'UTC+' . $current_offset;
|
||||
}
|
||||
}
|
||||
|
||||
$ret['data']['max_execution_time'] = ini_get("max_execution_time");
|
||||
$ret['data']['max_input_vars'] = ini_get("max_input_vars");
|
||||
$ret['data']['max_input_vars'] = ini_get("max_input_vars");
|
||||
$ret['data']['timezone'] = $timezone;//date_default_timezone_get();
|
||||
if(function_exists('php_uname'))
|
||||
{
|
||||
$ret['data']['OS'] = php_uname();
|
||||
}
|
||||
$ret['data']['memory_current'] = size_format(memory_get_usage(),2);
|
||||
$ret['data']['memory_peak'] = size_format(memory_get_peak_usage(),2);
|
||||
$ret['data']['memory_limit'] = ini_get('memory_limit');
|
||||
$ret['data']['post_max_size'] = ini_get('post_max_size');
|
||||
$ret['data']['allow_url_fopen'] = ini_get('allow_url_fopen');
|
||||
$ret['data']['safe_mode'] = ini_get('safe_mode');
|
||||
$ret['data']['pcre.backtrack_limit'] = ini_get('pcre.backtrack_limit');
|
||||
$extensions = get_loaded_extensions();
|
||||
if (array_search('exif', $extensions)) {
|
||||
$ret['data']['exif'] = 'support';
|
||||
} else {
|
||||
$ret['data']['exif'] = 'not support';
|
||||
}
|
||||
|
||||
if (array_search('xml', $extensions)) {
|
||||
$ret['data']['xml'] = 'support';
|
||||
} else {
|
||||
$ret['data']['xml'] = 'not support';
|
||||
}
|
||||
|
||||
if (array_search('suhosin', $extensions)) {
|
||||
$ret['data']['suhosin'] = 'support';
|
||||
} else {
|
||||
$ret['data']['suhosin'] = 'not support';
|
||||
}
|
||||
|
||||
if (array_search('gd', $extensions)) {
|
||||
$ret['data']['IPTC'] = 'support';
|
||||
} else {
|
||||
$ret['data']['IPTC'] = 'not support';
|
||||
}
|
||||
|
||||
$ret['data']['extensions'] = $extensions;
|
||||
|
||||
if (function_exists('apache_get_modules')) {
|
||||
$ret['data']['apache_modules'] = apache_get_modules();
|
||||
} else {
|
||||
$ret['data']['apache_modules'] = array();
|
||||
}
|
||||
|
||||
if (array_search('pdo_mysql', $extensions))
|
||||
{
|
||||
$ret['data']['pdo_mysql'] = 'support';
|
||||
} else {
|
||||
$ret['data']['pdo_mysql'] = 'not support';
|
||||
}
|
||||
|
||||
$ret['data']['mysql_mode'] = '';
|
||||
global $wpdb;
|
||||
$result = $wpdb->get_results('SELECT @@SESSION.sql_mode', ARRAY_A);
|
||||
foreach ($result as $row)
|
||||
{
|
||||
$ret['data']['mysql_mode'] = $row["@@SESSION.sql_mode"];
|
||||
}
|
||||
|
||||
if (!class_exists('PclZip')) include_once(ABSPATH . '/wp-admin/includes/class-pclzip.php');
|
||||
if (!class_exists('PclZip'))
|
||||
{
|
||||
$ret['data']['PclZip'] = 'not support';
|
||||
} else {
|
||||
$ret['data']['PclZip'] = 'support';
|
||||
}
|
||||
|
||||
if (is_multisite() && !defined('MULTISITE')) {
|
||||
$prefix = $wpdb->base_prefix;
|
||||
} else {
|
||||
$prefix = $wpdb->get_blog_prefix(0);
|
||||
}
|
||||
|
||||
$ret['data']['wp_prefix'] = $prefix;
|
||||
|
||||
$sapi_type = php_sapi_name();
|
||||
|
||||
if ($sapi_type == 'cgi-fcgi' || $sapi_type == ' fpm-fcgi') {
|
||||
$ret['data']['fast_cgi'] = 'On';
|
||||
} else {
|
||||
$ret['data']['fast_cgi'] = 'Off';
|
||||
}
|
||||
}
|
||||
catch (Exception $error) {
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
return array('result'=>'failed','error'=>$message);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function create_debug_package()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-system-info');
|
||||
|
||||
try
|
||||
{
|
||||
if (!class_exists('PclZip'))
|
||||
include_once(ABSPATH . '/wp-admin/includes/class-pclzip.php');
|
||||
|
||||
$backup_path="compressx";
|
||||
|
||||
$path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_debug.zip';
|
||||
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path))
|
||||
{
|
||||
wp_mkdir_p(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path);
|
||||
@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'index.html', 'x');
|
||||
$tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'.htaccess', 'x');
|
||||
if($tempfile)
|
||||
{
|
||||
$text="deny from all";
|
||||
fwrite($tempfile,$text );
|
||||
fclose($tempfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($path)) {
|
||||
@wp_delete_file($path);
|
||||
}
|
||||
|
||||
|
||||
$archive = new PclZip($path);
|
||||
|
||||
$server_info = wp_json_encode($this->get_debug_info());
|
||||
$server_file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_server_info.json';
|
||||
if (file_exists($server_file_path)) {
|
||||
@wp_delete_file($server_file_path);
|
||||
}
|
||||
$server_file = fopen($server_file_path, 'x');
|
||||
fclose($server_file);
|
||||
file_put_contents($server_file_path, $server_info);
|
||||
if (!$archive->add($server_file_path, PCLZIP_OPT_REMOVE_ALL_PATH))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
@wp_delete_file($server_file_path);
|
||||
|
||||
$log=new CompressX_Log();
|
||||
$files=$log->get_logs();
|
||||
if(!empty($files))
|
||||
{
|
||||
if(!$archive->add($files,PCLZIP_OPT_REMOVE_ALL_PATH))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (session_id())
|
||||
session_write_close();
|
||||
|
||||
$size = filesize($path);
|
||||
if (!headers_sent()) {
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/zip');
|
||||
header('Content-Disposition: attachment; filename="' . basename($path) . '"');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Content-Length: ' . $size);
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
}
|
||||
|
||||
|
||||
ob_end_clean();
|
||||
readfile($path);
|
||||
@wp_delete_file($path);
|
||||
}
|
||||
catch (Exception $error) {
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
echo wp_json_encode(array('result'=>'failed','error'=>$message));
|
||||
die();
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public function send_debug_info()
|
||||
{
|
||||
global $compressx;
|
||||
$compressx->ajax_check_security('compressx-can-use-system-info');
|
||||
|
||||
try
|
||||
{
|
||||
if (!isset($_POST['user_mail']) || empty($_POST['user_mail']))
|
||||
{
|
||||
$ret['result'] = 'failed';
|
||||
$ret['error'] = __('User\'s email address is required.', 'compressx');
|
||||
}
|
||||
else
|
||||
{
|
||||
$pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i';
|
||||
if (!preg_match($pattern, $_POST['user_mail']))
|
||||
{
|
||||
$ret['result'] = 'failed';
|
||||
$ret['error'] = __('Please enter a valid email address.', 'compressx');
|
||||
}
|
||||
else
|
||||
{
|
||||
$user_mail=sanitize_email($_POST['user_mail']);
|
||||
$comment=sanitize_text_field($_POST['comment']);
|
||||
|
||||
$ret =$this->_send_debug_info($user_mail,$comment);
|
||||
}
|
||||
}
|
||||
echo wp_json_encode($ret);
|
||||
die();
|
||||
}
|
||||
catch (Exception $error)
|
||||
{
|
||||
$message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
|
||||
error_log($message);
|
||||
echo wp_json_encode(array('result'=>'failed','error'=>$message));
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
public function _send_debug_info($user_email,$comment)
|
||||
{
|
||||
$send_to = 'support@compressx.io';
|
||||
$subject = 'Debug Information';
|
||||
$body = '<div>User\'s email: '.$user_email.'.</div>';
|
||||
$body .= '<div>Comment: '.$comment.'.</div>';
|
||||
$headers = array('Content-Type: text/html; charset=UTF-8');
|
||||
|
||||
if (!class_exists('PclZip'))
|
||||
include_once(ABSPATH . '/wp-admin/includes/class-pclzip.php');
|
||||
|
||||
$backup_path="compressx";
|
||||
|
||||
$path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_debug.zip';
|
||||
if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path))
|
||||
{
|
||||
wp_mkdir_p(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path);
|
||||
@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'index.html', 'x');
|
||||
$tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'.htaccess', 'x');
|
||||
if($tempfile)
|
||||
{
|
||||
$text="deny from all";
|
||||
fwrite($tempfile,$text );
|
||||
fclose($tempfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($path)) {
|
||||
@wp_delete_file($path);
|
||||
}
|
||||
|
||||
$archive = new PclZip($path);
|
||||
|
||||
$server_info = wp_json_encode($this->get_debug_info());
|
||||
$server_file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_path . DIRECTORY_SEPARATOR . 'compressx_server_info.json';
|
||||
if (file_exists($server_file_path))
|
||||
{
|
||||
@wp_delete_file($server_file_path);
|
||||
}
|
||||
$server_file = fopen($server_file_path, 'x');
|
||||
fclose($server_file);
|
||||
file_put_contents($server_file_path, $server_info);
|
||||
$archive->add($server_file_path, PCLZIP_OPT_REMOVE_ALL_PATH);
|
||||
@wp_delete_file($server_file_path);
|
||||
|
||||
$log=new CompressX_Log();
|
||||
$files=$log->get_logs();
|
||||
if(!empty($files))
|
||||
{
|
||||
$archive->add($files,PCLZIP_OPT_REMOVE_ALL_PATH);
|
||||
}
|
||||
|
||||
$attachments[] = $path;
|
||||
|
||||
if(wp_mail( $send_to, $subject, $body,$headers,$attachments)===false)
|
||||
{
|
||||
$ret['result']='failed';
|
||||
$ret['error']=__('Unable to send email. Please check the configuration of email server.', 'compressx');
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret['result']='success';
|
||||
}
|
||||
|
||||
@wp_delete_file($path);
|
||||
return $ret;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
.compressx-tooltip {
|
||||
display:inline-block;
|
||||
position:relative;
|
||||
text-align:left;
|
||||
}
|
||||
/* tooltip - bottom */
|
||||
.compressx-bottom {
|
||||
min-width:300px;
|
||||
top:40px;
|
||||
left:50%;
|
||||
transform:translate(-50%, 0);
|
||||
padding:10px 20px;
|
||||
color:#444444;
|
||||
background-color:#fff;
|
||||
font-weight:normal;
|
||||
font-size:13px;
|
||||
border-radius:8px;
|
||||
position:absolute;
|
||||
z-index:99999999;
|
||||
box-sizing:border-box;
|
||||
box-shadow:0 1px 8px rgba(0,0,0,0.2);
|
||||
visibility:hidden; opacity:0; transition:opacity 0.4s;
|
||||
}
|
||||
.compressx-dashicons-help a{
|
||||
color: #888;
|
||||
}
|
||||
.compressx-dashicons-help a:hover{
|
||||
color: #575757;
|
||||
}
|
||||
.compressx-dashicons-help:hover .compressx-bottom {
|
||||
visibility:visible; opacity:1;
|
||||
}
|
||||
.compressx-dashicons-white:hover .compressx-bottom{
|
||||
visibility:visible; opacity:1;
|
||||
}
|
||||
.compressx-tooltip .compressx-bottom i {
|
||||
position:absolute;
|
||||
bottom:100%;
|
||||
left:50%;
|
||||
margin-left:-12px;
|
||||
width:24px;
|
||||
height:12px;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
.compressx-tooltip .compressx-bottom i::after {
|
||||
content:'';
|
||||
position:absolute;
|
||||
width:12px;
|
||||
height:12px;
|
||||
left:50%;
|
||||
transform:translate(-50%,50%) rotate(45deg);
|
||||
background-color:#fff;
|
||||
box-shadow:0 1px 8px rgba(0,0,0,0.5);
|
||||
}
|
||||
/* tooltip - left */
|
||||
+879
@@ -0,0 +1,879 @@
|
||||
/****************************************************************
|
||||
*
|
||||
* CSS Percentage Circle
|
||||
* Author: Andre Firchow
|
||||
*
|
||||
*****************************************************************/
|
||||
.rect-auto, .c100.p51 .slice, .c100.p52 .slice, .c100.p53 .slice, .c100.p54 .slice, .c100.p55 .slice, .c100.p56 .slice, .c100.p57 .slice, .c100.p58 .slice, .c100.p59 .slice, .c100.p60 .slice, .c100.p61 .slice, .c100.p62 .slice, .c100.p63 .slice, .c100.p64 .slice, .c100.p65 .slice, .c100.p66 .slice, .c100.p67 .slice, .c100.p68 .slice, .c100.p69 .slice, .c100.p70 .slice, .c100.p71 .slice, .c100.p72 .slice, .c100.p73 .slice, .c100.p74 .slice, .c100.p75 .slice, .c100.p76 .slice, .c100.p77 .slice, .c100.p78 .slice, .c100.p79 .slice, .c100.p80 .slice, .c100.p81 .slice, .c100.p82 .slice, .c100.p83 .slice, .c100.p84 .slice, .c100.p85 .slice, .c100.p86 .slice, .c100.p87 .slice, .c100.p88 .slice, .c100.p89 .slice, .c100.p90 .slice, .c100.p91 .slice, .c100.p92 .slice, .c100.p93 .slice, .c100.p94 .slice, .c100.p95 .slice, .c100.p96 .slice, .c100.p97 .slice, .c100.p98 .slice, .c100.p99 .slice, .c100.p100 .slice {
|
||||
clip: rect(auto, auto, auto, auto);
|
||||
}
|
||||
|
||||
.pie, .c100 .bar, .c100.p51 .fill, .c100.p52 .fill, .c100.p53 .fill, .c100.p54 .fill, .c100.p55 .fill, .c100.p56 .fill, .c100.p57 .fill, .c100.p58 .fill, .c100.p59 .fill, .c100.p60 .fill, .c100.p61 .fill, .c100.p62 .fill, .c100.p63 .fill, .c100.p64 .fill, .c100.p65 .fill, .c100.p66 .fill, .c100.p67 .fill, .c100.p68 .fill, .c100.p69 .fill, .c100.p70 .fill, .c100.p71 .fill, .c100.p72 .fill, .c100.p73 .fill, .c100.p74 .fill, .c100.p75 .fill, .c100.p76 .fill, .c100.p77 .fill, .c100.p78 .fill, .c100.p79 .fill, .c100.p80 .fill, .c100.p81 .fill, .c100.p82 .fill, .c100.p83 .fill, .c100.p84 .fill, .c100.p85 .fill, .c100.p86 .fill, .c100.p87 .fill, .c100.p88 .fill, .c100.p89 .fill, .c100.p90 .fill, .c100.p91 .fill, .c100.p92 .fill, .c100.p93 .fill, .c100.p94 .fill, .c100.p95 .fill, .c100.p96 .fill, .c100.p97 .fill, .c100.p98 .fill, .c100.p99 .fill, .c100.p100 .fill {
|
||||
position: absolute;
|
||||
border: 0.08em solid #175cff;
|
||||
width: 0.84em;
|
||||
height: 0.84em;
|
||||
clip: rect(0em, 0.5em, 1em, 0em);
|
||||
-webkit-border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
-ms-border-radius: 50%;
|
||||
-o-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
-webkit-transform: rotate(0deg);
|
||||
-moz-transform: rotate(0deg);
|
||||
-ms-transform: rotate(0deg);
|
||||
-o-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
.pie-fill, .c100.p51 .bar:after, .c100.p51 .fill, .c100.p52 .bar:after, .c100.p52 .fill, .c100.p53 .bar:after, .c100.p53 .fill, .c100.p54 .bar:after, .c100.p54 .fill, .c100.p55 .bar:after, .c100.p55 .fill, .c100.p56 .bar:after, .c100.p56 .fill, .c100.p57 .bar:after, .c100.p57 .fill, .c100.p58 .bar:after, .c100.p58 .fill, .c100.p59 .bar:after, .c100.p59 .fill, .c100.p60 .bar:after, .c100.p60 .fill, .c100.p61 .bar:after, .c100.p61 .fill, .c100.p62 .bar:after, .c100.p62 .fill, .c100.p63 .bar:after, .c100.p63 .fill, .c100.p64 .bar:after, .c100.p64 .fill, .c100.p65 .bar:after, .c100.p65 .fill, .c100.p66 .bar:after, .c100.p66 .fill, .c100.p67 .bar:after, .c100.p67 .fill, .c100.p68 .bar:after, .c100.p68 .fill, .c100.p69 .bar:after, .c100.p69 .fill, .c100.p70 .bar:after, .c100.p70 .fill, .c100.p71 .bar:after, .c100.p71 .fill, .c100.p72 .bar:after, .c100.p72 .fill, .c100.p73 .bar:after, .c100.p73 .fill, .c100.p74 .bar:after, .c100.p74 .fill, .c100.p75 .bar:after, .c100.p75 .fill, .c100.p76 .bar:after, .c100.p76 .fill, .c100.p77 .bar:after, .c100.p77 .fill, .c100.p78 .bar:after, .c100.p78 .fill, .c100.p79 .bar:after, .c100.p79 .fill, .c100.p80 .bar:after, .c100.p80 .fill, .c100.p81 .bar:after, .c100.p81 .fill, .c100.p82 .bar:after, .c100.p82 .fill, .c100.p83 .bar:after, .c100.p83 .fill, .c100.p84 .bar:after, .c100.p84 .fill, .c100.p85 .bar:after, .c100.p85 .fill, .c100.p86 .bar:after, .c100.p86 .fill, .c100.p87 .bar:after, .c100.p87 .fill, .c100.p88 .bar:after, .c100.p88 .fill, .c100.p89 .bar:after, .c100.p89 .fill, .c100.p90 .bar:after, .c100.p90 .fill, .c100.p91 .bar:after, .c100.p91 .fill, .c100.p92 .bar:after, .c100.p92 .fill, .c100.p93 .bar:after, .c100.p93 .fill, .c100.p94 .bar:after, .c100.p94 .fill, .c100.p95 .bar:after, .c100.p95 .fill, .c100.p96 .bar:after, .c100.p96 .fill, .c100.p97 .bar:after, .c100.p97 .fill, .c100.p98 .bar:after, .c100.p98 .fill, .c100.p99 .bar:after, .c100.p99 .fill, .c100.p100 .bar:after, .c100.p100 .fill {
|
||||
-webkit-transform: rotate(180deg);
|
||||
-moz-transform: rotate(180deg);
|
||||
-ms-transform: rotate(180deg);
|
||||
-o-transform: rotate(180deg);
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.c100 {
|
||||
position: relative;
|
||||
font-size: 120px;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
-webkit-border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
-ms-border-radius: 50%;
|
||||
-o-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
float: left;
|
||||
margin: 0 0.1em 0.1em 0;
|
||||
background-color: #cccccc;
|
||||
}
|
||||
.c100 *, .c100 *:before, .c100 *:after {
|
||||
-webkit-box-sizing: content-box;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
.c100.center {
|
||||
float: none;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.c100.big {
|
||||
font-size: 240px;
|
||||
}
|
||||
.c100.small {
|
||||
font-size: 80px;
|
||||
}
|
||||
.c100 > span {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 5em;
|
||||
line-height: 5em;
|
||||
font-size: 0.2em;
|
||||
color: #cccccc;
|
||||
display: block;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
-webkit-transition-property: all;
|
||||
-moz-transition-property: all;
|
||||
-o-transition-property: all;
|
||||
transition-property: all;
|
||||
-webkit-transition-duration: 0.2s;
|
||||
-moz-transition-duration: 0.2s;
|
||||
-o-transition-duration: 0.2s;
|
||||
transition-duration: 0.2s;
|
||||
-webkit-transition-timing-function: ease-out;
|
||||
-moz-transition-timing-function: ease-out;
|
||||
-o-transition-timing-function: ease-out;
|
||||
transition-timing-function: ease-out;
|
||||
}
|
||||
.c100:after {
|
||||
position: absolute;
|
||||
top: 0.08em;
|
||||
left: 0.08em;
|
||||
display: block;
|
||||
content: " ";
|
||||
-webkit-border-radius: 50%;
|
||||
-moz-border-radius: 50%;
|
||||
-ms-border-radius: 50%;
|
||||
-o-border-radius: 50%;
|
||||
border-radius: 50%;
|
||||
background-color: whitesmoke;
|
||||
width: 0.84em;
|
||||
height: 0.84em;
|
||||
-webkit-transition-property: all;
|
||||
-moz-transition-property: all;
|
||||
-o-transition-property: all;
|
||||
transition-property: all;
|
||||
-webkit-transition-duration: 0.2s;
|
||||
-moz-transition-duration: 0.2s;
|
||||
-o-transition-duration: 0.2s;
|
||||
transition-duration: 0.2s;
|
||||
-webkit-transition-timing-function: ease-in;
|
||||
-moz-transition-timing-function: ease-in;
|
||||
-o-transition-timing-function: ease-in;
|
||||
transition-timing-function: ease-in;
|
||||
}
|
||||
.c100 .slice {
|
||||
position: absolute;
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
clip: rect(0em, 1em, 1em, 0.5em);
|
||||
}
|
||||
.c100.p1 .bar {
|
||||
-webkit-transform: rotate(3.6deg);
|
||||
-moz-transform: rotate(3.6deg);
|
||||
-ms-transform: rotate(3.6deg);
|
||||
-o-transform: rotate(3.6deg);
|
||||
transform: rotate(3.6deg);
|
||||
}
|
||||
.c100.p2 .bar {
|
||||
-webkit-transform: rotate(7.2deg);
|
||||
-moz-transform: rotate(7.2deg);
|
||||
-ms-transform: rotate(7.2deg);
|
||||
-o-transform: rotate(7.2deg);
|
||||
transform: rotate(7.2deg);
|
||||
}
|
||||
.c100.p3 .bar {
|
||||
-webkit-transform: rotate(10.8deg);
|
||||
-moz-transform: rotate(10.8deg);
|
||||
-ms-transform: rotate(10.8deg);
|
||||
-o-transform: rotate(10.8deg);
|
||||
transform: rotate(10.8deg);
|
||||
}
|
||||
.c100.p4 .bar {
|
||||
-webkit-transform: rotate(14.4deg);
|
||||
-moz-transform: rotate(14.4deg);
|
||||
-ms-transform: rotate(14.4deg);
|
||||
-o-transform: rotate(14.4deg);
|
||||
transform: rotate(14.4deg);
|
||||
}
|
||||
.c100.p5 .bar {
|
||||
-webkit-transform: rotate(18deg);
|
||||
-moz-transform: rotate(18deg);
|
||||
-ms-transform: rotate(18deg);
|
||||
-o-transform: rotate(18deg);
|
||||
transform: rotate(18deg);
|
||||
}
|
||||
.c100.p6 .bar {
|
||||
-webkit-transform: rotate(21.6deg);
|
||||
-moz-transform: rotate(21.6deg);
|
||||
-ms-transform: rotate(21.6deg);
|
||||
-o-transform: rotate(21.6deg);
|
||||
transform: rotate(21.6deg);
|
||||
}
|
||||
.c100.p7 .bar {
|
||||
-webkit-transform: rotate(25.2deg);
|
||||
-moz-transform: rotate(25.2deg);
|
||||
-ms-transform: rotate(25.2deg);
|
||||
-o-transform: rotate(25.2deg);
|
||||
transform: rotate(25.2deg);
|
||||
}
|
||||
.c100.p8 .bar {
|
||||
-webkit-transform: rotate(28.8deg);
|
||||
-moz-transform: rotate(28.8deg);
|
||||
-ms-transform: rotate(28.8deg);
|
||||
-o-transform: rotate(28.8deg);
|
||||
transform: rotate(28.8deg);
|
||||
}
|
||||
.c100.p9 .bar {
|
||||
-webkit-transform: rotate(32.4deg);
|
||||
-moz-transform: rotate(32.4deg);
|
||||
-ms-transform: rotate(32.4deg);
|
||||
-o-transform: rotate(32.4deg);
|
||||
transform: rotate(32.4deg);
|
||||
}
|
||||
.c100.p10 .bar {
|
||||
-webkit-transform: rotate(36deg);
|
||||
-moz-transform: rotate(36deg);
|
||||
-ms-transform: rotate(36deg);
|
||||
-o-transform: rotate(36deg);
|
||||
transform: rotate(36deg);
|
||||
}
|
||||
.c100.p11 .bar {
|
||||
-webkit-transform: rotate(39.6deg);
|
||||
-moz-transform: rotate(39.6deg);
|
||||
-ms-transform: rotate(39.6deg);
|
||||
-o-transform: rotate(39.6deg);
|
||||
transform: rotate(39.6deg);
|
||||
}
|
||||
.c100.p12 .bar {
|
||||
-webkit-transform: rotate(43.2deg);
|
||||
-moz-transform: rotate(43.2deg);
|
||||
-ms-transform: rotate(43.2deg);
|
||||
-o-transform: rotate(43.2deg);
|
||||
transform: rotate(43.2deg);
|
||||
}
|
||||
.c100.p13 .bar {
|
||||
-webkit-transform: rotate(46.8deg);
|
||||
-moz-transform: rotate(46.8deg);
|
||||
-ms-transform: rotate(46.8deg);
|
||||
-o-transform: rotate(46.8deg);
|
||||
transform: rotate(46.8deg);
|
||||
}
|
||||
.c100.p14 .bar {
|
||||
-webkit-transform: rotate(50.4deg);
|
||||
-moz-transform: rotate(50.4deg);
|
||||
-ms-transform: rotate(50.4deg);
|
||||
-o-transform: rotate(50.4deg);
|
||||
transform: rotate(50.4deg);
|
||||
}
|
||||
.c100.p15 .bar {
|
||||
-webkit-transform: rotate(54deg);
|
||||
-moz-transform: rotate(54deg);
|
||||
-ms-transform: rotate(54deg);
|
||||
-o-transform: rotate(54deg);
|
||||
transform: rotate(54deg);
|
||||
}
|
||||
.c100.p16 .bar {
|
||||
-webkit-transform: rotate(57.6deg);
|
||||
-moz-transform: rotate(57.6deg);
|
||||
-ms-transform: rotate(57.6deg);
|
||||
-o-transform: rotate(57.6deg);
|
||||
transform: rotate(57.6deg);
|
||||
}
|
||||
.c100.p17 .bar {
|
||||
-webkit-transform: rotate(61.2deg);
|
||||
-moz-transform: rotate(61.2deg);
|
||||
-ms-transform: rotate(61.2deg);
|
||||
-o-transform: rotate(61.2deg);
|
||||
transform: rotate(61.2deg);
|
||||
}
|
||||
.c100.p18 .bar {
|
||||
-webkit-transform: rotate(64.8deg);
|
||||
-moz-transform: rotate(64.8deg);
|
||||
-ms-transform: rotate(64.8deg);
|
||||
-o-transform: rotate(64.8deg);
|
||||
transform: rotate(64.8deg);
|
||||
}
|
||||
.c100.p19 .bar {
|
||||
-webkit-transform: rotate(68.4deg);
|
||||
-moz-transform: rotate(68.4deg);
|
||||
-ms-transform: rotate(68.4deg);
|
||||
-o-transform: rotate(68.4deg);
|
||||
transform: rotate(68.4deg);
|
||||
}
|
||||
.c100.p20 .bar {
|
||||
-webkit-transform: rotate(72deg);
|
||||
-moz-transform: rotate(72deg);
|
||||
-ms-transform: rotate(72deg);
|
||||
-o-transform: rotate(72deg);
|
||||
transform: rotate(72deg);
|
||||
}
|
||||
.c100.p21 .bar {
|
||||
-webkit-transform: rotate(75.6deg);
|
||||
-moz-transform: rotate(75.6deg);
|
||||
-ms-transform: rotate(75.6deg);
|
||||
-o-transform: rotate(75.6deg);
|
||||
transform: rotate(75.6deg);
|
||||
}
|
||||
.c100.p22 .bar {
|
||||
-webkit-transform: rotate(79.2deg);
|
||||
-moz-transform: rotate(79.2deg);
|
||||
-ms-transform: rotate(79.2deg);
|
||||
-o-transform: rotate(79.2deg);
|
||||
transform: rotate(79.2deg);
|
||||
}
|
||||
.c100.p23 .bar {
|
||||
-webkit-transform: rotate(82.8deg);
|
||||
-moz-transform: rotate(82.8deg);
|
||||
-ms-transform: rotate(82.8deg);
|
||||
-o-transform: rotate(82.8deg);
|
||||
transform: rotate(82.8deg);
|
||||
}
|
||||
.c100.p24 .bar {
|
||||
-webkit-transform: rotate(86.4deg);
|
||||
-moz-transform: rotate(86.4deg);
|
||||
-ms-transform: rotate(86.4deg);
|
||||
-o-transform: rotate(86.4deg);
|
||||
transform: rotate(86.4deg);
|
||||
}
|
||||
.c100.p25 .bar {
|
||||
-webkit-transform: rotate(90deg);
|
||||
-moz-transform: rotate(90deg);
|
||||
-ms-transform: rotate(90deg);
|
||||
-o-transform: rotate(90deg);
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
.c100.p26 .bar {
|
||||
-webkit-transform: rotate(93.6deg);
|
||||
-moz-transform: rotate(93.6deg);
|
||||
-ms-transform: rotate(93.6deg);
|
||||
-o-transform: rotate(93.6deg);
|
||||
transform: rotate(93.6deg);
|
||||
}
|
||||
.c100.p27 .bar {
|
||||
-webkit-transform: rotate(97.2deg);
|
||||
-moz-transform: rotate(97.2deg);
|
||||
-ms-transform: rotate(97.2deg);
|
||||
-o-transform: rotate(97.2deg);
|
||||
transform: rotate(97.2deg);
|
||||
}
|
||||
.c100.p28 .bar {
|
||||
-webkit-transform: rotate(100.8deg);
|
||||
-moz-transform: rotate(100.8deg);
|
||||
-ms-transform: rotate(100.8deg);
|
||||
-o-transform: rotate(100.8deg);
|
||||
transform: rotate(100.8deg);
|
||||
}
|
||||
.c100.p29 .bar {
|
||||
-webkit-transform: rotate(104.4deg);
|
||||
-moz-transform: rotate(104.4deg);
|
||||
-ms-transform: rotate(104.4deg);
|
||||
-o-transform: rotate(104.4deg);
|
||||
transform: rotate(104.4deg);
|
||||
}
|
||||
.c100.p30 .bar {
|
||||
-webkit-transform: rotate(108deg);
|
||||
-moz-transform: rotate(108deg);
|
||||
-ms-transform: rotate(108deg);
|
||||
-o-transform: rotate(108deg);
|
||||
transform: rotate(108deg);
|
||||
}
|
||||
.c100.p31 .bar {
|
||||
-webkit-transform: rotate(111.6deg);
|
||||
-moz-transform: rotate(111.6deg);
|
||||
-ms-transform: rotate(111.6deg);
|
||||
-o-transform: rotate(111.6deg);
|
||||
transform: rotate(111.6deg);
|
||||
}
|
||||
.c100.p32 .bar {
|
||||
-webkit-transform: rotate(115.2deg);
|
||||
-moz-transform: rotate(115.2deg);
|
||||
-ms-transform: rotate(115.2deg);
|
||||
-o-transform: rotate(115.2deg);
|
||||
transform: rotate(115.2deg);
|
||||
}
|
||||
.c100.p33 .bar {
|
||||
-webkit-transform: rotate(118.8deg);
|
||||
-moz-transform: rotate(118.8deg);
|
||||
-ms-transform: rotate(118.8deg);
|
||||
-o-transform: rotate(118.8deg);
|
||||
transform: rotate(118.8deg);
|
||||
}
|
||||
.c100.p34 .bar {
|
||||
-webkit-transform: rotate(122.4deg);
|
||||
-moz-transform: rotate(122.4deg);
|
||||
-ms-transform: rotate(122.4deg);
|
||||
-o-transform: rotate(122.4deg);
|
||||
transform: rotate(122.4deg);
|
||||
}
|
||||
.c100.p35 .bar {
|
||||
-webkit-transform: rotate(126deg);
|
||||
-moz-transform: rotate(126deg);
|
||||
-ms-transform: rotate(126deg);
|
||||
-o-transform: rotate(126deg);
|
||||
transform: rotate(126deg);
|
||||
}
|
||||
.c100.p36 .bar {
|
||||
-webkit-transform: rotate(129.6deg);
|
||||
-moz-transform: rotate(129.6deg);
|
||||
-ms-transform: rotate(129.6deg);
|
||||
-o-transform: rotate(129.6deg);
|
||||
transform: rotate(129.6deg);
|
||||
}
|
||||
.c100.p37 .bar {
|
||||
-webkit-transform: rotate(133.2deg);
|
||||
-moz-transform: rotate(133.2deg);
|
||||
-ms-transform: rotate(133.2deg);
|
||||
-o-transform: rotate(133.2deg);
|
||||
transform: rotate(133.2deg);
|
||||
}
|
||||
.c100.p38 .bar {
|
||||
-webkit-transform: rotate(136.8deg);
|
||||
-moz-transform: rotate(136.8deg);
|
||||
-ms-transform: rotate(136.8deg);
|
||||
-o-transform: rotate(136.8deg);
|
||||
transform: rotate(136.8deg);
|
||||
}
|
||||
.c100.p39 .bar {
|
||||
-webkit-transform: rotate(140.4deg);
|
||||
-moz-transform: rotate(140.4deg);
|
||||
-ms-transform: rotate(140.4deg);
|
||||
-o-transform: rotate(140.4deg);
|
||||
transform: rotate(140.4deg);
|
||||
}
|
||||
.c100.p40 .bar {
|
||||
-webkit-transform: rotate(144deg);
|
||||
-moz-transform: rotate(144deg);
|
||||
-ms-transform: rotate(144deg);
|
||||
-o-transform: rotate(144deg);
|
||||
transform: rotate(144deg);
|
||||
}
|
||||
.c100.p41 .bar {
|
||||
-webkit-transform: rotate(147.6deg);
|
||||
-moz-transform: rotate(147.6deg);
|
||||
-ms-transform: rotate(147.6deg);
|
||||
-o-transform: rotate(147.6deg);
|
||||
transform: rotate(147.6deg);
|
||||
}
|
||||
.c100.p42 .bar {
|
||||
-webkit-transform: rotate(151.2deg);
|
||||
-moz-transform: rotate(151.2deg);
|
||||
-ms-transform: rotate(151.2deg);
|
||||
-o-transform: rotate(151.2deg);
|
||||
transform: rotate(151.2deg);
|
||||
}
|
||||
.c100.p43 .bar {
|
||||
-webkit-transform: rotate(154.8deg);
|
||||
-moz-transform: rotate(154.8deg);
|
||||
-ms-transform: rotate(154.8deg);
|
||||
-o-transform: rotate(154.8deg);
|
||||
transform: rotate(154.8deg);
|
||||
}
|
||||
.c100.p44 .bar {
|
||||
-webkit-transform: rotate(158.4deg);
|
||||
-moz-transform: rotate(158.4deg);
|
||||
-ms-transform: rotate(158.4deg);
|
||||
-o-transform: rotate(158.4deg);
|
||||
transform: rotate(158.4deg);
|
||||
}
|
||||
.c100.p45 .bar {
|
||||
-webkit-transform: rotate(162deg);
|
||||
-moz-transform: rotate(162deg);
|
||||
-ms-transform: rotate(162deg);
|
||||
-o-transform: rotate(162deg);
|
||||
transform: rotate(162deg);
|
||||
}
|
||||
.c100.p46 .bar {
|
||||
-webkit-transform: rotate(165.6deg);
|
||||
-moz-transform: rotate(165.6deg);
|
||||
-ms-transform: rotate(165.6deg);
|
||||
-o-transform: rotate(165.6deg);
|
||||
transform: rotate(165.6deg);
|
||||
}
|
||||
.c100.p47 .bar {
|
||||
-webkit-transform: rotate(169.2deg);
|
||||
-moz-transform: rotate(169.2deg);
|
||||
-ms-transform: rotate(169.2deg);
|
||||
-o-transform: rotate(169.2deg);
|
||||
transform: rotate(169.2deg);
|
||||
}
|
||||
.c100.p48 .bar {
|
||||
-webkit-transform: rotate(172.8deg);
|
||||
-moz-transform: rotate(172.8deg);
|
||||
-ms-transform: rotate(172.8deg);
|
||||
-o-transform: rotate(172.8deg);
|
||||
transform: rotate(172.8deg);
|
||||
}
|
||||
.c100.p49 .bar {
|
||||
-webkit-transform: rotate(176.4deg);
|
||||
-moz-transform: rotate(176.4deg);
|
||||
-ms-transform: rotate(176.4deg);
|
||||
-o-transform: rotate(176.4deg);
|
||||
transform: rotate(176.4deg);
|
||||
}
|
||||
.c100.p50 .bar {
|
||||
-webkit-transform: rotate(180deg);
|
||||
-moz-transform: rotate(180deg);
|
||||
-ms-transform: rotate(180deg);
|
||||
-o-transform: rotate(180deg);
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.c100.p51 .bar {
|
||||
-webkit-transform: rotate(183.6deg);
|
||||
-moz-transform: rotate(183.6deg);
|
||||
-ms-transform: rotate(183.6deg);
|
||||
-o-transform: rotate(183.6deg);
|
||||
transform: rotate(183.6deg);
|
||||
}
|
||||
.c100.p52 .bar {
|
||||
-webkit-transform: rotate(187.2deg);
|
||||
-moz-transform: rotate(187.2deg);
|
||||
-ms-transform: rotate(187.2deg);
|
||||
-o-transform: rotate(187.2deg);
|
||||
transform: rotate(187.2deg);
|
||||
}
|
||||
.c100.p53 .bar {
|
||||
-webkit-transform: rotate(190.8deg);
|
||||
-moz-transform: rotate(190.8deg);
|
||||
-ms-transform: rotate(190.8deg);
|
||||
-o-transform: rotate(190.8deg);
|
||||
transform: rotate(190.8deg);
|
||||
}
|
||||
.c100.p54 .bar {
|
||||
-webkit-transform: rotate(194.4deg);
|
||||
-moz-transform: rotate(194.4deg);
|
||||
-ms-transform: rotate(194.4deg);
|
||||
-o-transform: rotate(194.4deg);
|
||||
transform: rotate(194.4deg);
|
||||
}
|
||||
.c100.p55 .bar {
|
||||
-webkit-transform: rotate(198deg);
|
||||
-moz-transform: rotate(198deg);
|
||||
-ms-transform: rotate(198deg);
|
||||
-o-transform: rotate(198deg);
|
||||
transform: rotate(198deg);
|
||||
}
|
||||
.c100.p56 .bar {
|
||||
-webkit-transform: rotate(201.6deg);
|
||||
-moz-transform: rotate(201.6deg);
|
||||
-ms-transform: rotate(201.6deg);
|
||||
-o-transform: rotate(201.6deg);
|
||||
transform: rotate(201.6deg);
|
||||
}
|
||||
.c100.p57 .bar {
|
||||
-webkit-transform: rotate(205.2deg);
|
||||
-moz-transform: rotate(205.2deg);
|
||||
-ms-transform: rotate(205.2deg);
|
||||
-o-transform: rotate(205.2deg);
|
||||
transform: rotate(205.2deg);
|
||||
}
|
||||
.c100.p58 .bar {
|
||||
-webkit-transform: rotate(208.8deg);
|
||||
-moz-transform: rotate(208.8deg);
|
||||
-ms-transform: rotate(208.8deg);
|
||||
-o-transform: rotate(208.8deg);
|
||||
transform: rotate(208.8deg);
|
||||
}
|
||||
.c100.p59 .bar {
|
||||
-webkit-transform: rotate(212.4deg);
|
||||
-moz-transform: rotate(212.4deg);
|
||||
-ms-transform: rotate(212.4deg);
|
||||
-o-transform: rotate(212.4deg);
|
||||
transform: rotate(212.4deg);
|
||||
}
|
||||
.c100.p60 .bar {
|
||||
-webkit-transform: rotate(216deg);
|
||||
-moz-transform: rotate(216deg);
|
||||
-ms-transform: rotate(216deg);
|
||||
-o-transform: rotate(216deg);
|
||||
transform: rotate(216deg);
|
||||
}
|
||||
.c100.p61 .bar {
|
||||
-webkit-transform: rotate(219.6deg);
|
||||
-moz-transform: rotate(219.6deg);
|
||||
-ms-transform: rotate(219.6deg);
|
||||
-o-transform: rotate(219.6deg);
|
||||
transform: rotate(219.6deg);
|
||||
}
|
||||
.c100.p62 .bar {
|
||||
-webkit-transform: rotate(223.2deg);
|
||||
-moz-transform: rotate(223.2deg);
|
||||
-ms-transform: rotate(223.2deg);
|
||||
-o-transform: rotate(223.2deg);
|
||||
transform: rotate(223.2deg);
|
||||
}
|
||||
.c100.p63 .bar {
|
||||
-webkit-transform: rotate(226.8deg);
|
||||
-moz-transform: rotate(226.8deg);
|
||||
-ms-transform: rotate(226.8deg);
|
||||
-o-transform: rotate(226.8deg);
|
||||
transform: rotate(226.8deg);
|
||||
}
|
||||
.c100.p64 .bar {
|
||||
-webkit-transform: rotate(230.4deg);
|
||||
-moz-transform: rotate(230.4deg);
|
||||
-ms-transform: rotate(230.4deg);
|
||||
-o-transform: rotate(230.4deg);
|
||||
transform: rotate(230.4deg);
|
||||
}
|
||||
.c100.p65 .bar {
|
||||
-webkit-transform: rotate(234deg);
|
||||
-moz-transform: rotate(234deg);
|
||||
-ms-transform: rotate(234deg);
|
||||
-o-transform: rotate(234deg);
|
||||
transform: rotate(234deg);
|
||||
}
|
||||
.c100.p66 .bar {
|
||||
-webkit-transform: rotate(237.6deg);
|
||||
-moz-transform: rotate(237.6deg);
|
||||
-ms-transform: rotate(237.6deg);
|
||||
-o-transform: rotate(237.6deg);
|
||||
transform: rotate(237.6deg);
|
||||
}
|
||||
.c100.p67 .bar {
|
||||
-webkit-transform: rotate(241.2deg);
|
||||
-moz-transform: rotate(241.2deg);
|
||||
-ms-transform: rotate(241.2deg);
|
||||
-o-transform: rotate(241.2deg);
|
||||
transform: rotate(241.2deg);
|
||||
}
|
||||
.c100.p68 .bar {
|
||||
-webkit-transform: rotate(244.8deg);
|
||||
-moz-transform: rotate(244.8deg);
|
||||
-ms-transform: rotate(244.8deg);
|
||||
-o-transform: rotate(244.8deg);
|
||||
transform: rotate(244.8deg);
|
||||
}
|
||||
.c100.p69 .bar {
|
||||
-webkit-transform: rotate(248.4deg);
|
||||
-moz-transform: rotate(248.4deg);
|
||||
-ms-transform: rotate(248.4deg);
|
||||
-o-transform: rotate(248.4deg);
|
||||
transform: rotate(248.4deg);
|
||||
}
|
||||
.c100.p70 .bar {
|
||||
-webkit-transform: rotate(252deg);
|
||||
-moz-transform: rotate(252deg);
|
||||
-ms-transform: rotate(252deg);
|
||||
-o-transform: rotate(252deg);
|
||||
transform: rotate(252deg);
|
||||
}
|
||||
.c100.p71 .bar {
|
||||
-webkit-transform: rotate(255.6deg);
|
||||
-moz-transform: rotate(255.6deg);
|
||||
-ms-transform: rotate(255.6deg);
|
||||
-o-transform: rotate(255.6deg);
|
||||
transform: rotate(255.6deg);
|
||||
}
|
||||
.c100.p72 .bar {
|
||||
-webkit-transform: rotate(259.2deg);
|
||||
-moz-transform: rotate(259.2deg);
|
||||
-ms-transform: rotate(259.2deg);
|
||||
-o-transform: rotate(259.2deg);
|
||||
transform: rotate(259.2deg);
|
||||
}
|
||||
.c100.p73 .bar {
|
||||
-webkit-transform: rotate(262.8deg);
|
||||
-moz-transform: rotate(262.8deg);
|
||||
-ms-transform: rotate(262.8deg);
|
||||
-o-transform: rotate(262.8deg);
|
||||
transform: rotate(262.8deg);
|
||||
}
|
||||
.c100.p74 .bar {
|
||||
-webkit-transform: rotate(266.4deg);
|
||||
-moz-transform: rotate(266.4deg);
|
||||
-ms-transform: rotate(266.4deg);
|
||||
-o-transform: rotate(266.4deg);
|
||||
transform: rotate(266.4deg);
|
||||
}
|
||||
.c100.p75 .bar {
|
||||
-webkit-transform: rotate(270deg);
|
||||
-moz-transform: rotate(270deg);
|
||||
-ms-transform: rotate(270deg);
|
||||
-o-transform: rotate(270deg);
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
.c100.p76 .bar {
|
||||
-webkit-transform: rotate(273.6deg);
|
||||
-moz-transform: rotate(273.6deg);
|
||||
-ms-transform: rotate(273.6deg);
|
||||
-o-transform: rotate(273.6deg);
|
||||
transform: rotate(273.6deg);
|
||||
}
|
||||
.c100.p77 .bar {
|
||||
-webkit-transform: rotate(277.2deg);
|
||||
-moz-transform: rotate(277.2deg);
|
||||
-ms-transform: rotate(277.2deg);
|
||||
-o-transform: rotate(277.2deg);
|
||||
transform: rotate(277.2deg);
|
||||
}
|
||||
.c100.p78 .bar {
|
||||
-webkit-transform: rotate(280.8deg);
|
||||
-moz-transform: rotate(280.8deg);
|
||||
-ms-transform: rotate(280.8deg);
|
||||
-o-transform: rotate(280.8deg);
|
||||
transform: rotate(280.8deg);
|
||||
}
|
||||
.c100.p79 .bar {
|
||||
-webkit-transform: rotate(284.4deg);
|
||||
-moz-transform: rotate(284.4deg);
|
||||
-ms-transform: rotate(284.4deg);
|
||||
-o-transform: rotate(284.4deg);
|
||||
transform: rotate(284.4deg);
|
||||
}
|
||||
.c100.p80 .bar {
|
||||
-webkit-transform: rotate(288deg);
|
||||
-moz-transform: rotate(288deg);
|
||||
-ms-transform: rotate(288deg);
|
||||
-o-transform: rotate(288deg);
|
||||
transform: rotate(288deg);
|
||||
}
|
||||
.c100.p81 .bar {
|
||||
-webkit-transform: rotate(291.6deg);
|
||||
-moz-transform: rotate(291.6deg);
|
||||
-ms-transform: rotate(291.6deg);
|
||||
-o-transform: rotate(291.6deg);
|
||||
transform: rotate(291.6deg);
|
||||
}
|
||||
.c100.p82 .bar {
|
||||
-webkit-transform: rotate(295.2deg);
|
||||
-moz-transform: rotate(295.2deg);
|
||||
-ms-transform: rotate(295.2deg);
|
||||
-o-transform: rotate(295.2deg);
|
||||
transform: rotate(295.2deg);
|
||||
}
|
||||
.c100.p83 .bar {
|
||||
-webkit-transform: rotate(298.8deg);
|
||||
-moz-transform: rotate(298.8deg);
|
||||
-ms-transform: rotate(298.8deg);
|
||||
-o-transform: rotate(298.8deg);
|
||||
transform: rotate(298.8deg);
|
||||
}
|
||||
.c100.p84 .bar {
|
||||
-webkit-transform: rotate(302.4deg);
|
||||
-moz-transform: rotate(302.4deg);
|
||||
-ms-transform: rotate(302.4deg);
|
||||
-o-transform: rotate(302.4deg);
|
||||
transform: rotate(302.4deg);
|
||||
}
|
||||
.c100.p85 .bar {
|
||||
-webkit-transform: rotate(306deg);
|
||||
-moz-transform: rotate(306deg);
|
||||
-ms-transform: rotate(306deg);
|
||||
-o-transform: rotate(306deg);
|
||||
transform: rotate(306deg);
|
||||
}
|
||||
.c100.p86 .bar {
|
||||
-webkit-transform: rotate(309.6deg);
|
||||
-moz-transform: rotate(309.6deg);
|
||||
-ms-transform: rotate(309.6deg);
|
||||
-o-transform: rotate(309.6deg);
|
||||
transform: rotate(309.6deg);
|
||||
}
|
||||
.c100.p87 .bar {
|
||||
-webkit-transform: rotate(313.2deg);
|
||||
-moz-transform: rotate(313.2deg);
|
||||
-ms-transform: rotate(313.2deg);
|
||||
-o-transform: rotate(313.2deg);
|
||||
transform: rotate(313.2deg);
|
||||
}
|
||||
.c100.p88 .bar {
|
||||
-webkit-transform: rotate(316.8deg);
|
||||
-moz-transform: rotate(316.8deg);
|
||||
-ms-transform: rotate(316.8deg);
|
||||
-o-transform: rotate(316.8deg);
|
||||
transform: rotate(316.8deg);
|
||||
}
|
||||
.c100.p89 .bar {
|
||||
-webkit-transform: rotate(320.4deg);
|
||||
-moz-transform: rotate(320.4deg);
|
||||
-ms-transform: rotate(320.4deg);
|
||||
-o-transform: rotate(320.4deg);
|
||||
transform: rotate(320.4deg);
|
||||
}
|
||||
.c100.p90 .bar {
|
||||
-webkit-transform: rotate(324deg);
|
||||
-moz-transform: rotate(324deg);
|
||||
-ms-transform: rotate(324deg);
|
||||
-o-transform: rotate(324deg);
|
||||
transform: rotate(324deg);
|
||||
}
|
||||
.c100.p91 .bar {
|
||||
-webkit-transform: rotate(327.6deg);
|
||||
-moz-transform: rotate(327.6deg);
|
||||
-ms-transform: rotate(327.6deg);
|
||||
-o-transform: rotate(327.6deg);
|
||||
transform: rotate(327.6deg);
|
||||
}
|
||||
.c100.p92 .bar {
|
||||
-webkit-transform: rotate(331.2deg);
|
||||
-moz-transform: rotate(331.2deg);
|
||||
-ms-transform: rotate(331.2deg);
|
||||
-o-transform: rotate(331.2deg);
|
||||
transform: rotate(331.2deg);
|
||||
}
|
||||
.c100.p93 .bar {
|
||||
-webkit-transform: rotate(334.8deg);
|
||||
-moz-transform: rotate(334.8deg);
|
||||
-ms-transform: rotate(334.8deg);
|
||||
-o-transform: rotate(334.8deg);
|
||||
transform: rotate(334.8deg);
|
||||
}
|
||||
.c100.p94 .bar {
|
||||
-webkit-transform: rotate(338.4deg);
|
||||
-moz-transform: rotate(338.4deg);
|
||||
-ms-transform: rotate(338.4deg);
|
||||
-o-transform: rotate(338.4deg);
|
||||
transform: rotate(338.4deg);
|
||||
}
|
||||
.c100.p95 .bar {
|
||||
-webkit-transform: rotate(342deg);
|
||||
-moz-transform: rotate(342deg);
|
||||
-ms-transform: rotate(342deg);
|
||||
-o-transform: rotate(342deg);
|
||||
transform: rotate(342deg);
|
||||
}
|
||||
.c100.p96 .bar {
|
||||
-webkit-transform: rotate(345.6deg);
|
||||
-moz-transform: rotate(345.6deg);
|
||||
-ms-transform: rotate(345.6deg);
|
||||
-o-transform: rotate(345.6deg);
|
||||
transform: rotate(345.6deg);
|
||||
}
|
||||
.c100.p97 .bar {
|
||||
-webkit-transform: rotate(349.2deg);
|
||||
-moz-transform: rotate(349.2deg);
|
||||
-ms-transform: rotate(349.2deg);
|
||||
-o-transform: rotate(349.2deg);
|
||||
transform: rotate(349.2deg);
|
||||
}
|
||||
.c100.p98 .bar {
|
||||
-webkit-transform: rotate(352.8deg);
|
||||
-moz-transform: rotate(352.8deg);
|
||||
-ms-transform: rotate(352.8deg);
|
||||
-o-transform: rotate(352.8deg);
|
||||
transform: rotate(352.8deg);
|
||||
}
|
||||
.c100.p99 .bar {
|
||||
-webkit-transform: rotate(356.4deg);
|
||||
-moz-transform: rotate(356.4deg);
|
||||
-ms-transform: rotate(356.4deg);
|
||||
-o-transform: rotate(356.4deg);
|
||||
transform: rotate(356.4deg);
|
||||
}
|
||||
.c100.p100 .bar {
|
||||
-webkit-transform: rotate(360deg);
|
||||
-moz-transform: rotate(360deg);
|
||||
-ms-transform: rotate(360deg);
|
||||
-o-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
.c100:hover {
|
||||
cursor: default;
|
||||
}
|
||||
.c100:hover > span {
|
||||
width: 3.33em;
|
||||
line-height: 3.33em;
|
||||
font-size: 0.3em;
|
||||
color: #307bbb;
|
||||
}
|
||||
.c100:hover:after {
|
||||
top: 0.04em;
|
||||
left: 0.04em;
|
||||
width: 0.92em;
|
||||
height: 0.92em;
|
||||
}
|
||||
.c100.dark {
|
||||
background-color: #777777;
|
||||
}
|
||||
.c100.dark .bar,
|
||||
.c100.dark .fill {
|
||||
border-color: #c6ff00 !important;
|
||||
}
|
||||
.c100.dark > span {
|
||||
color: #777777;
|
||||
}
|
||||
.c100.dark:after {
|
||||
background-color: #666666;
|
||||
}
|
||||
.c100.dark:hover > span {
|
||||
color: #c6ff00;
|
||||
}
|
||||
.c100.green .bar, .c100.green .fill {
|
||||
border-color: #4db53c !important;
|
||||
}
|
||||
.c100.green:hover > span {
|
||||
color: #4db53c;
|
||||
}
|
||||
.c100.green.dark .bar, .c100.green.dark .fill {
|
||||
border-color: #5fd400 !important;
|
||||
}
|
||||
.c100.green.dark:hover > span {
|
||||
color: #5fd400;
|
||||
}
|
||||
.c100.orange .bar, .c100.orange .fill {
|
||||
border-color: #dd9d22 !important;
|
||||
}
|
||||
.c100.orange:hover > span {
|
||||
color: #dd9d22;
|
||||
}
|
||||
.c100.orange.dark .bar, .c100.orange.dark .fill {
|
||||
border-color: #e08833 !important;
|
||||
}
|
||||
.c100.orange.dark:hover > span {
|
||||
color: #e08833;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,102 @@
|
||||
/* Custom styles for TwentyTwenty integration with CompressX */
|
||||
|
||||
/* Ensure TwentyTwenty container fits properly */
|
||||
.twentytwenty-container {
|
||||
position: relative !important;
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
min-height: 280px;
|
||||
background: #ffffff !important;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Ensure images maintain aspect ratio */
|
||||
.twentytwenty-container img {
|
||||
max-width: 100% !important;
|
||||
height: auto !important;
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Override any conflicting flex styles */
|
||||
.twentytwenty-container.compressx-v2-flex {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
/* Ensure proper overlay positioning */
|
||||
.twentytwenty-overlay {
|
||||
background: rgba(0, 0, 0, 0) !important;
|
||||
}
|
||||
|
||||
/* Custom handle styling to match CompressX theme */
|
||||
.twentytwenty-handle {
|
||||
border: 3px solid #3b82f6 !important;
|
||||
background: #ffffff !important;
|
||||
}
|
||||
|
||||
.twentytwenty-handle:before,
|
||||
.twentytwenty-handle:after {
|
||||
background: #3b82f6 !important;
|
||||
}
|
||||
|
||||
/* Enhanced visibility */
|
||||
.twentytwenty-container::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: #ffffff;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
/* Improved image visibility */
|
||||
.twentytwenty-container img {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Better overlay contrast */
|
||||
.twentytwenty-overlay {
|
||||
background: rgba(0, 0, 0, 0) !important;
|
||||
color: #ffffff !important;
|
||||
font-weight: 600 !important;
|
||||
}
|
||||
|
||||
/* Responsive adjustments */
|
||||
@media (max-width: 768px) {
|
||||
.twentytwenty-container {
|
||||
min-height: 200px;
|
||||
}
|
||||
|
||||
.twentytwenty-overlay {
|
||||
font-size: 11px !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prevent FOUC (Flash of Unstyled Content) */
|
||||
.cx-comparison-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* Loading state */
|
||||
.twentytwenty-container.loading {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.twentytwenty-container.loading::after {
|
||||
content: "Loading...";
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
padding: 10px 20px;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
.twentytwenty-horizontal .twentytwenty-handle:before, .twentytwenty-horizontal .twentytwenty-handle:after, .twentytwenty-vertical .twentytwenty-handle:before, .twentytwenty-vertical .twentytwenty-handle:after {
|
||||
content: " ";
|
||||
display: block;
|
||||
background: white;
|
||||
position: absolute;
|
||||
z-index: 30;
|
||||
-webkit-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
-moz-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5); }
|
||||
|
||||
.twentytwenty-horizontal .twentytwenty-handle:before, .twentytwenty-horizontal .twentytwenty-handle:after {
|
||||
width: 3px;
|
||||
height: 9999px;
|
||||
left: 50%;
|
||||
margin-left: -1.5px; }
|
||||
|
||||
.twentytwenty-vertical .twentytwenty-handle:before, .twentytwenty-vertical .twentytwenty-handle:after {
|
||||
width: 9999px;
|
||||
height: 3px;
|
||||
top: 50%;
|
||||
margin-top: -1.5px; }
|
||||
|
||||
.twentytwenty-before-label, .twentytwenty-after-label, .twentytwenty-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%; }
|
||||
|
||||
.twentytwenty-before-label, .twentytwenty-after-label, .twentytwenty-overlay {
|
||||
-webkit-transition-duration: 0.5s;
|
||||
-moz-transition-duration: 0.5s;
|
||||
transition-duration: 0.5s; }
|
||||
|
||||
.twentytwenty-before-label, .twentytwenty-after-label {
|
||||
-webkit-transition-property: opacity;
|
||||
-moz-transition-property: opacity;
|
||||
transition-property: opacity; }
|
||||
|
||||
.twentytwenty-before-label:before, .twentytwenty-after-label:before {
|
||||
color: white;
|
||||
font-size: 13px;
|
||||
letter-spacing: 0.1em; }
|
||||
|
||||
.twentytwenty-before-label:before, .twentytwenty-after-label:before {
|
||||
position: absolute;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
line-height: 38px;
|
||||
padding: 0 20px;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
border-radius: 2px; }
|
||||
|
||||
.twentytwenty-horizontal .twentytwenty-before-label:before, .twentytwenty-horizontal .twentytwenty-after-label:before {
|
||||
top: 50%;
|
||||
margin-top: -19px; }
|
||||
|
||||
.twentytwenty-vertical .twentytwenty-before-label:before, .twentytwenty-vertical .twentytwenty-after-label:before {
|
||||
left: 50%;
|
||||
margin-left: -45px;
|
||||
text-align: center;
|
||||
width: 90px; }
|
||||
|
||||
.twentytwenty-left-arrow, .twentytwenty-right-arrow, .twentytwenty-up-arrow, .twentytwenty-down-arrow {
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: 6px inset transparent;
|
||||
position: absolute; }
|
||||
|
||||
.twentytwenty-left-arrow, .twentytwenty-right-arrow {
|
||||
top: 50%;
|
||||
margin-top: -6px; }
|
||||
|
||||
.twentytwenty-up-arrow, .twentytwenty-down-arrow {
|
||||
left: 50%;
|
||||
margin-left: -6px; }
|
||||
|
||||
.twentytwenty-container {
|
||||
-webkit-box-sizing: content-box;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
z-index: 0;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none; }
|
||||
.twentytwenty-container img {
|
||||
max-width: 100%;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
display: block; }
|
||||
.twentytwenty-container.active .twentytwenty-overlay, .twentytwenty-container.active :hover.twentytwenty-overlay {
|
||||
background: rgba(0, 0, 0, 0); }
|
||||
.twentytwenty-container.active .twentytwenty-overlay .twentytwenty-before-label,
|
||||
.twentytwenty-container.active .twentytwenty-overlay .twentytwenty-after-label, .twentytwenty-container.active :hover.twentytwenty-overlay .twentytwenty-before-label,
|
||||
.twentytwenty-container.active :hover.twentytwenty-overlay .twentytwenty-after-label {
|
||||
opacity: 0; }
|
||||
.twentytwenty-container * {
|
||||
-webkit-box-sizing: content-box;
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box; }
|
||||
|
||||
.twentytwenty-before-label {
|
||||
opacity: 0; }
|
||||
.twentytwenty-before-label:before {
|
||||
content: attr(data-content); }
|
||||
|
||||
.twentytwenty-after-label {
|
||||
opacity: 0; }
|
||||
.twentytwenty-after-label:before {
|
||||
content: attr(data-content); }
|
||||
|
||||
.twentytwenty-horizontal .twentytwenty-before-label:before {
|
||||
left: 10px; }
|
||||
|
||||
.twentytwenty-horizontal .twentytwenty-after-label:before {
|
||||
right: 10px; }
|
||||
|
||||
.twentytwenty-vertical .twentytwenty-before-label:before {
|
||||
top: 10px; }
|
||||
|
||||
.twentytwenty-vertical .twentytwenty-after-label:before {
|
||||
bottom: 10px; }
|
||||
|
||||
.twentytwenty-overlay {
|
||||
-webkit-transition-property: background;
|
||||
-moz-transition-property: background;
|
||||
transition-property: background;
|
||||
background: rgba(0, 0, 0, 0);
|
||||
z-index: 25; }
|
||||
.twentytwenty-overlay:hover {
|
||||
background: rgba(0, 0, 0, 0.5); }
|
||||
.twentytwenty-overlay:hover .twentytwenty-after-label {
|
||||
opacity: 1; }
|
||||
.twentytwenty-overlay:hover .twentytwenty-before-label {
|
||||
opacity: 1; }
|
||||
|
||||
.twentytwenty-before {
|
||||
z-index: 20; }
|
||||
|
||||
.twentytwenty-after {
|
||||
z-index: 10; }
|
||||
|
||||
.twentytwenty-handle {
|
||||
height: 38px;
|
||||
width: 38px;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
margin-left: -22px;
|
||||
margin-top: -22px;
|
||||
border: 3px solid white;
|
||||
-webkit-border-radius: 1000px;
|
||||
-moz-border-radius: 1000px;
|
||||
border-radius: 1000px;
|
||||
-webkit-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
-moz-box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
box-shadow: 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
z-index: 40;
|
||||
cursor: pointer; }
|
||||
|
||||
.twentytwenty-horizontal .twentytwenty-handle:before {
|
||||
bottom: 50%;
|
||||
margin-bottom: 22px;
|
||||
-webkit-box-shadow: 0 3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
-moz-box-shadow: 0 3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
box-shadow: 0 3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5); }
|
||||
.twentytwenty-horizontal .twentytwenty-handle:after {
|
||||
top: 50%;
|
||||
margin-top: 22px;
|
||||
-webkit-box-shadow: 0 -3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
-moz-box-shadow: 0 -3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
box-shadow: 0 -3px 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5); }
|
||||
|
||||
.twentytwenty-vertical .twentytwenty-handle:before {
|
||||
left: 50%;
|
||||
margin-left: 22px;
|
||||
-webkit-box-shadow: 3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
-moz-box-shadow: 3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
box-shadow: 3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5); }
|
||||
.twentytwenty-vertical .twentytwenty-handle:after {
|
||||
right: 50%;
|
||||
margin-right: 22px;
|
||||
-webkit-box-shadow: -3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
-moz-box-shadow: -3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5);
|
||||
box-shadow: -3px 0 0 white, 0px 0px 12px rgba(51, 51, 51, 0.5); }
|
||||
|
||||
.twentytwenty-left-arrow {
|
||||
border-right: 6px solid white;
|
||||
left: 50%;
|
||||
margin-left: -17px; }
|
||||
|
||||
.twentytwenty-right-arrow {
|
||||
border-left: 6px solid white;
|
||||
right: 50%;
|
||||
margin-right: -17px; }
|
||||
|
||||
.twentytwenty-up-arrow {
|
||||
border-bottom: 6px solid white;
|
||||
top: 50%;
|
||||
margin-top: -17px; }
|
||||
|
||||
.twentytwenty-down-arrow {
|
||||
border-top: 6px solid white;
|
||||
bottom: 50%;
|
||||
margin-bottom: -17px; }
|
||||
@@ -0,0 +1,74 @@
|
||||
|
||||
function compressx_post_request(ajax_data, callback, error_callback, time_out)
|
||||
{
|
||||
if(typeof time_out === 'undefined') time_out = 30000;
|
||||
ajax_data.nonce=compressx_ajax_object.ajax_nonce;
|
||||
jQuery.ajax({
|
||||
type: "post",
|
||||
url: compressx_ajax_object.ajax_url,
|
||||
data: ajax_data,
|
||||
success: function (data) {
|
||||
callback(data);
|
||||
},
|
||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
||||
error_callback(XMLHttpRequest, textStatus, errorThrown);
|
||||
},
|
||||
timeout: time_out
|
||||
});
|
||||
}
|
||||
|
||||
function compressx_output_ajaxerror(action, textStatus, errorThrown){
|
||||
//action = 'trying to establish communication with your server';
|
||||
var error_msg = "compressx_request: "+ textStatus + "(" + errorThrown + "): an error occurred when " + action + ". " +
|
||||
"It could be because the request did not reach or the server did not respond. Please try again later.";
|
||||
return error_msg;
|
||||
}
|
||||
|
||||
function compressx_ajax_data_transfer(data_type)
|
||||
{
|
||||
var json = {};
|
||||
jQuery('input:checkbox[option='+data_type+']').each(function() {
|
||||
var value = '0';
|
||||
var key = jQuery(this).prop('name');
|
||||
if(jQuery(this).prop('checked')) {
|
||||
value = '1';
|
||||
}
|
||||
else {
|
||||
value = '0';
|
||||
}
|
||||
json[key]=value;
|
||||
});
|
||||
jQuery('input:radio[option='+data_type+']').each(function() {
|
||||
if(jQuery(this).prop('checked'))
|
||||
{
|
||||
var key = jQuery(this).prop('name');
|
||||
var value = jQuery(this).prop('value');
|
||||
json[key]=value;
|
||||
}
|
||||
});
|
||||
jQuery('input:text[option='+data_type+']').each(function(){
|
||||
var obj = {};
|
||||
var key = jQuery(this).prop('name');
|
||||
var value = jQuery(this).val();
|
||||
json[key]=value;
|
||||
});
|
||||
jQuery('textarea[option='+data_type+']').each(function(){
|
||||
var obj = {};
|
||||
var key = jQuery(this).prop('name');
|
||||
var value = jQuery(this).val();
|
||||
json[key]=value;
|
||||
});
|
||||
jQuery('input:password[option='+data_type+']').each(function(){
|
||||
var obj = {};
|
||||
var key = jQuery(this).prop('name');
|
||||
var value = jQuery(this).val();
|
||||
json[key]=value;
|
||||
});
|
||||
jQuery('select[option='+data_type+']').each(function(){
|
||||
var obj = {};
|
||||
var key = jQuery(this).prop('name');
|
||||
var value = jQuery(this).val();
|
||||
json[key]=value;
|
||||
});
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
@@ -0,0 +1,426 @@
|
||||
|
||||
var cx_cancel_custom_bulk_optimization=false;
|
||||
|
||||
jQuery('#compressx_start_custom_bulk_optimization').click(function()
|
||||
{
|
||||
compressx_start_custom_bulk_optimization();
|
||||
});
|
||||
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').click(function()
|
||||
{
|
||||
var descript = 'Are you sure to cancel this progressing?';
|
||||
|
||||
var ret = confirm(descript);
|
||||
if(ret === true)
|
||||
{
|
||||
cx_cancel_custom_bulk_optimization=true;
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').css({'pointer-events': 'none', 'opacity': '0.4'});
|
||||
}
|
||||
});
|
||||
|
||||
function compressx_custom_bulk_optimization_canceled()
|
||||
{
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
|
||||
compressx_get_dir_info();
|
||||
}
|
||||
|
||||
function compressx_start_custom_bulk_optimization()
|
||||
{
|
||||
var ajax_data = {
|
||||
'action': 'compressx_start_scan_custom_images',
|
||||
};
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'none', 'opacity': '0.4'});
|
||||
jQuery('#cx_custom_bulk_progress_text').show();
|
||||
jQuery('#cx_custom_bulk_progress_text').html("Processing...");
|
||||
jQuery('#cx_custom_overview').hide();
|
||||
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').show();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').hide();
|
||||
cx_cancel_custom_bulk_optimization=false;
|
||||
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
if(cx_cancel_custom_bulk_optimization)
|
||||
{
|
||||
compressx_custom_bulk_optimization_canceled();
|
||||
alert("The process has been canceled");
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
if(jsonarray.finished==true)
|
||||
{
|
||||
jQuery('#cx_custom_bulk_progress_text').html(jsonarray.progress);
|
||||
compressx_init_custom_bulk_optimization_task();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
jQuery('#cx_custom_overview').show();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
jQuery('#cx_custom_overview').show();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
var error_message = compressx_output_ajaxerror('scan images', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
|
||||
function compressx_init_custom_bulk_optimization_task()
|
||||
{
|
||||
var force="0";
|
||||
|
||||
if(jQuery('#cx_custom_force_optimization').prop('checked'))
|
||||
{
|
||||
force = '1';
|
||||
}
|
||||
else {
|
||||
force = '0';
|
||||
}
|
||||
|
||||
var ajax_data = {
|
||||
'action': 'compressx_init_custom_bulk_optimization_task',
|
||||
'force':force
|
||||
};
|
||||
jQuery('#compressx_bulk_progress_step2').addClass("cx-active");
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
if(cx_cancel_custom_bulk_optimization)
|
||||
{
|
||||
compressx_custom_bulk_optimization_canceled();
|
||||
alert("The process has been canceled");
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
compressx_run_custom_optimize();
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
jQuery('#cx_custom_overview').show();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
jQuery('#cx_custom_overview').show();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
var error_message = compressx_output_ajaxerror('start bulk optimization', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
|
||||
function compressx_run_custom_optimize()
|
||||
{
|
||||
var ajax_data = {
|
||||
'action': 'compressx_run_custom_optimize',
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
compressx_get_custom_optimize_task_status();
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
jQuery('#cx_custom_overview').show();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
compressx_get_custom_optimize_task_status();
|
||||
});
|
||||
}
|
||||
|
||||
function compressx_get_custom_optimize_task_status()
|
||||
{
|
||||
var ajax_data = {
|
||||
'action': 'compressx_get_custom_opt_progress'
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#cx_custom_bulk_progress_text').html(jsonarray.log);
|
||||
if(jsonarray.continue)
|
||||
{
|
||||
setTimeout(function ()
|
||||
{
|
||||
compressx_get_custom_optimize_task_status();
|
||||
}, 1000);
|
||||
}
|
||||
else if(jsonarray.finished)
|
||||
{
|
||||
compressx_get_dir_info();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
jQuery('#cx_custom_overview').show();
|
||||
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
compressx_custom_show_review_box(jsonarray);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cx_cancel_custom_bulk_optimization)
|
||||
{
|
||||
compressx_custom_bulk_optimization_canceled();
|
||||
alert("The process has been canceled");
|
||||
return;
|
||||
}
|
||||
compressx_run_custom_optimize();
|
||||
}
|
||||
}
|
||||
else if (jsonarray.result === 'failed')
|
||||
{
|
||||
if(jsonarray.timeout)
|
||||
{
|
||||
if(cx_cancel_custom_bulk_optimization)
|
||||
{
|
||||
compressx_custom_bulk_optimization_canceled();
|
||||
alert("The process has been canceled");
|
||||
return;
|
||||
}
|
||||
compressx_run_custom_optimize();
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(jsonarray.error);
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_overview').show();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
alert(err);
|
||||
jQuery('#compressx_start_custom_bulk_optimization').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
jQuery('#cx_custom_bulk_progress_text').hide();
|
||||
|
||||
jQuery('#compressx_cancel_custom_bulk_optimization').hide();
|
||||
jQuery('#compressx_start_custom_bulk_optimization').show();
|
||||
|
||||
jQuery('#cx_custom_overview').show();
|
||||
}
|
||||
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
setTimeout(function ()
|
||||
{
|
||||
compressx_get_custom_optimize_task_status();
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
function compressx_custom_show_review_box(jsonarray)
|
||||
{
|
||||
if(jsonarray.show_review)
|
||||
{
|
||||
jQuery('#cx_rating_box').show();
|
||||
jQuery('#cx_size_of_opt_images').html(jsonarray.opt_size);
|
||||
}
|
||||
}
|
||||
|
||||
function compressx_get_dir_info()
|
||||
{
|
||||
var ajax_data = {
|
||||
'action': 'compressx_get_dir_info',
|
||||
};
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#cx_custom_founds').html(jsonarray.found);
|
||||
jQuery('#cx_custom_total_saving').html(jsonarray.saved);
|
||||
jQuery('#cx_custom_processed').html(jsonarray.processed);
|
||||
}
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
//alert(err);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
});
|
||||
}
|
||||
|
||||
function compressx_init_custom_exclude_tree()
|
||||
{
|
||||
jQuery('#compressx_custom_include_js_tree').on('activate_node.jstree', function (event, data) {
|
||||
}).jstree({
|
||||
"core": {
|
||||
"check_callback": true,
|
||||
"multiple": true,
|
||||
"data": function (node_id, callback) {
|
||||
var tree_node = {
|
||||
'node': node_id,
|
||||
'path': compressx_uploads_root.custom_path
|
||||
};
|
||||
var ajax_data = {
|
||||
'action': 'compressx_get_custom_tree_dir_ex',
|
||||
'tree_node': tree_node,
|
||||
};
|
||||
ajax_data.nonce=compressx_ajax_object.ajax_nonce;
|
||||
jQuery.ajax({
|
||||
type: "post",
|
||||
url: compressx_ajax_object.ajax_url,
|
||||
data: ajax_data,
|
||||
success: function (data) {
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
callback.call(this, jsonarray.nodes);
|
||||
},
|
||||
error: function (XMLHttpRequest, textStatus, errorThrown) {
|
||||
//alert("error");
|
||||
},
|
||||
timeout: 30000
|
||||
});
|
||||
},
|
||||
'themes': {
|
||||
'stripes': true
|
||||
}
|
||||
},
|
||||
"plugins": ["sort"],
|
||||
"sort": function(a, b) {
|
||||
a1 = this.get_node(a);
|
||||
b1 = this.get_node(b);
|
||||
if (a1.icon === b1.icon) {
|
||||
return (a1.text.toLowerCase() > b1.text.toLowerCase()) ? 1 : -1;
|
||||
} else {
|
||||
return (a1.icon > b1.icon) ? 1 : -1;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
jQuery(document).ready(function ()
|
||||
{
|
||||
compressx_init_custom_exclude_tree();
|
||||
});
|
||||
|
||||
jQuery('#compressx_custom_include_js_tree').on('click', '.cx-add-custom-include-tree', function()
|
||||
{
|
||||
var id=jQuery(this).data("id");
|
||||
var ajax_data = {
|
||||
'action': 'compressx_add_include_folders',
|
||||
'id': id,
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#cx_custom_founds').html(jsonarray.found);
|
||||
jQuery('#cx_custom_total_saving').html(jsonarray.saved);
|
||||
jQuery('#cx_custom_processed').html(jsonarray.processed);
|
||||
jQuery('#compressx_include_dir_node').html(jsonarray.html);
|
||||
}
|
||||
else {
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
alert(err);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
jQuery('#compressx_include_dir_node').on('click', '.cx-remove-custom-include-tree', function()
|
||||
{
|
||||
var id=jQuery(this).data("id");
|
||||
var node=jQuery(this).parent();
|
||||
var ajax_data = {
|
||||
'action': 'compressx_remove_include_folders',
|
||||
'id': id,
|
||||
};
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
jQuery('#cx_custom_founds').html(jsonarray.found);
|
||||
jQuery('#cx_custom_total_saving').html(jsonarray.saved);
|
||||
jQuery('#cx_custom_processed').html(jsonarray.processed);
|
||||
node.remove();
|
||||
}
|
||||
else {
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
alert(err);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
var error_message = compressx_output_ajaxerror('changing settings', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,297 @@
|
||||
jQuery('#cx_edit_apiserver').click(function()
|
||||
{
|
||||
jQuery('#cx_apiserver').hide();
|
||||
jQuery('#cx_apiserver_edit').show();
|
||||
});
|
||||
|
||||
jQuery('#cx_apiserver_edit_btn').click(function()
|
||||
{
|
||||
jQuery('#cx_apiserver_edit_progress').show();
|
||||
var api_server=jQuery('#cx_apiserver_select').val();
|
||||
var ajax_data = {
|
||||
'action': 'compressx_set_api_server',
|
||||
'api_server': api_server,
|
||||
};
|
||||
jQuery('#cx_apiserver_edit_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
|
||||
compressx_post_request(ajax_data, function (data)
|
||||
{
|
||||
jQuery('#cx_apiserver_edit_progress').hide();
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
|
||||
jQuery('#cx_apiserver_edit_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
//
|
||||
jQuery('#cx_apiserver_text').html(jsonarray.html);
|
||||
jQuery('#cx_apiserver').show();
|
||||
jQuery('#cx_apiserver_edit').hide();
|
||||
}
|
||||
else {
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch (err)
|
||||
{
|
||||
alert(err);
|
||||
jQuery('#cx_apiserver_edit_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
jQuery('#cx_apiserver_edit_progress').hide();
|
||||
jQuery('#cx_apiserver_edit_btn').css({'pointer-events': 'auto', 'opacity': '1'});
|
||||
var error_message = compressx_output_ajaxerror('set api server', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("click",'#cx_log_search_by_date',function()
|
||||
{
|
||||
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
|
||||
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
|
||||
|
||||
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
|
||||
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
|
||||
|
||||
compressx_get_logs_list(start_date,start_time,end_date,end_time);
|
||||
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.first-page',function() {
|
||||
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
|
||||
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
|
||||
|
||||
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
|
||||
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
|
||||
compressx_get_logs_list(start_date,start_time,end_date,end_time,'first');
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.prev-page',function() {
|
||||
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
|
||||
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
|
||||
|
||||
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
|
||||
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
|
||||
var page=parseInt(jQuery(this).attr('value'));
|
||||
compressx_get_logs_list(start_date,start_time,end_date,end_time,page-1);
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.next-page',function() {
|
||||
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
|
||||
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
|
||||
|
||||
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
|
||||
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
|
||||
var page=parseInt(jQuery(this).attr('value'));
|
||||
compressx_get_logs_list(start_date,start_time,end_date,end_time,page+1);
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.last-page',function() {
|
||||
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
|
||||
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
|
||||
|
||||
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
|
||||
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
|
||||
compressx_get_logs_list(start_date,start_time,end_date,end_time,'last');
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("keypress", '.current-page', function() {
|
||||
var start_date = jQuery('#cx_log_list').find('#cx_log_start_date').val();
|
||||
var start_time = jQuery('#cx_log_list').find('#cx_log_start_time').val();
|
||||
|
||||
var end_date = jQuery('#cx_log_list').find('#cx_log_end_date').val();
|
||||
var end_time = jQuery('#cx_log_list').find('#cx_log_end_time').val();
|
||||
if(event.keyCode === 13){
|
||||
var page = jQuery(this).val();
|
||||
compressx_get_logs_list(start_date,start_time,end_date,end_time,page);
|
||||
}
|
||||
});
|
||||
|
||||
function compressx_get_logs_list(start_date,start_time,end_date,end_time,page=0)
|
||||
{
|
||||
var ajax_data = {
|
||||
'action':'compressx_get_logs_list',
|
||||
'start_date':start_date,
|
||||
'start_time':start_time,
|
||||
'end_date':end_date,
|
||||
'end_time':end_time,
|
||||
'page':page
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
if (jsonarray.result === "success")
|
||||
{
|
||||
jQuery('#cx_log_list').html(jsonarray.html);
|
||||
jQuery('#cx_log_list').find('#cx_log_start_date').val(start_date);
|
||||
jQuery('#cx_log_list').find('#cx_log_start_time').val(start_time);
|
||||
jQuery('#cx_log_list').find('#cx_log_end_date').val(end_date);
|
||||
jQuery('#cx_log_list').find('#cx_log_end_time').val(end_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
alert(err);
|
||||
}
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
var error_message =compressx_output_ajaxerror('get logs list', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
|
||||
jQuery('#cx_close_log').click(function()
|
||||
{
|
||||
jQuery('#cx_log_detail_section').hide();
|
||||
});
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.cs-log-detail',function()
|
||||
{
|
||||
var file_name = jQuery(this).closest('td').data('id');
|
||||
compressx_open_log(file_name);
|
||||
});
|
||||
|
||||
function compressx_open_log(file_name)
|
||||
{
|
||||
var ajax_data = {
|
||||
'action':'compressx_open_log',
|
||||
'filename':file_name
|
||||
};
|
||||
|
||||
jQuery('#cx_log_name').html(file_name);
|
||||
jQuery('#cx_read_optimize_log_content').html("");
|
||||
jQuery('#cx_log_detail_section').show();
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
if (jsonarray.result === "success")
|
||||
{
|
||||
jQuery('#cx_read_optimize_log_content').html(jsonarray.html);
|
||||
jQuery('html, body').animate({scrollTop: jQuery("#cx_log_scroll_test").offset().top}, 'slow');
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery('#cx_read_optimize_log_content').html(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
alert(err);
|
||||
var div = "Reading the log failed. Please try again.";
|
||||
jQuery('#cx_read_optimize_log_content').html(div);
|
||||
}
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
var error_message =compressx_output_ajaxerror('open log', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.cs-log-download',function()
|
||||
{
|
||||
var file_name = jQuery(this).closest('td').data('id');
|
||||
compressx_download_log(file_name);
|
||||
});
|
||||
|
||||
function compressx_download_log(file_name)
|
||||
{
|
||||
location.href =ajaxurl+'?_wpnonce='+compressx_ajax_object.ajax_nonce+'&action=compressx_download_log&log='+file_name;
|
||||
}
|
||||
|
||||
jQuery('#cx_log_list').on("click",'.cs-log-delete',function()
|
||||
{
|
||||
var file_name = jQuery(this).closest('td').data('id');
|
||||
|
||||
var descript = 'Are you sure to delete this log file?';
|
||||
|
||||
var ret = confirm(descript);
|
||||
if(ret === true)
|
||||
{
|
||||
compressx_delete_log(file_name);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function compressx_delete_log(file_name)
|
||||
{
|
||||
var ajax_data = {
|
||||
'action':'compressx_delete_log',
|
||||
'filename':file_name
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
if (jsonarray.result === "success")
|
||||
{
|
||||
jQuery('#cx_log_list').html(jsonarray.html);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
alert(err);
|
||||
}
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
var error_message =compressx_output_ajaxerror('delete log', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
|
||||
jQuery('#cx_empty_log').click(function()
|
||||
{
|
||||
var descript = 'Are you sure to delete All log file?';
|
||||
|
||||
var ret = confirm(descript);
|
||||
if(ret === true)
|
||||
{
|
||||
compressx_delete_all_log();
|
||||
}
|
||||
});
|
||||
|
||||
function compressx_delete_all_log()
|
||||
{
|
||||
var ajax_data = {
|
||||
'action':'compressx_delete_all_log',
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
if (jsonarray.result === "success")
|
||||
{
|
||||
jQuery('#cx_log_list').html(jsonarray.html);
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
alert(err);
|
||||
}
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
var error_message =compressx_output_ajaxerror('delete log', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
jQuery('#compressx_download_debug_info').click(function()
|
||||
{
|
||||
cx_download_website_info();
|
||||
});
|
||||
|
||||
function cx_download_website_info()
|
||||
{
|
||||
location.href =ajaxurl+'?_wpnonce='+compressx_ajax_object.ajax_nonce+'&action=compressx_create_debug_package';
|
||||
}
|
||||
|
||||
jQuery('#compressx_debug_submit').click(function()
|
||||
{
|
||||
cx_debug_submit();
|
||||
});
|
||||
|
||||
function cx_debug_submit()
|
||||
{
|
||||
var user_mail = jQuery('#compressx_user_mail').val();
|
||||
var comment = jQuery('#compressx_debug_comment').val();
|
||||
|
||||
var ajax_data = {
|
||||
'action': 'compressx_send_debug_info',
|
||||
'user_mail': user_mail,
|
||||
'comment':comment
|
||||
};
|
||||
compressx_post_request(ajax_data, function (data) {
|
||||
try {
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
if (jsonarray.result === "success")
|
||||
{
|
||||
jQuery('#compressx_debug_comment').html("");
|
||||
jQuery('#compressx_send_success_text').removeClass("hidden");
|
||||
setTimeout(function ()
|
||||
{
|
||||
jQuery('#compressx_send_success_text').addClass( 'hidden' );
|
||||
}, 3000);
|
||||
}
|
||||
else {
|
||||
alert(jsonarray.error);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
alert(err);
|
||||
}
|
||||
}, function (XMLHttpRequest, textStatus, errorThrown) {
|
||||
var error_message = compressx_output_ajaxerror('sending debug information', textStatus, errorThrown);
|
||||
alert(error_message);
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
+1146
File diff suppressed because it is too large
Load Diff
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 8.9 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
+1102
File diff suppressed because it is too large
Load Diff
+1
File diff suppressed because one or more lines are too long
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,273 @@
|
||||
|
||||
window.compressx = window.compressx || {};
|
||||
|
||||
(function($, w, undefined)
|
||||
{
|
||||
w.compressx.media={
|
||||
progress_queue:[],
|
||||
lock:false,
|
||||
init:function()
|
||||
{
|
||||
$( document ).on( 'click', '.cx-media-item a.cx-media', this.handle_action_button);
|
||||
$( document ).on( 'click', '.misc-pub-cx a.cx-media', this.handle_action_button_edit);
|
||||
$( document ).on( 'click', '.cx-media-attachment a.cx-media', this.handle_action_button_attachment);
|
||||
w.compressx.media.get_progress();
|
||||
},
|
||||
handle_action_button:function ()
|
||||
{
|
||||
if(w.compressx.media.islockbtn())
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
var $row = $(this).closest('.cx-media-item');
|
||||
var $select = $row.find('.cx-media-selected');
|
||||
var action = $select.val();
|
||||
|
||||
if(action==="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var id=$( this ).data( 'id' );
|
||||
$( this ).html("Progressing...");
|
||||
$( this ).removeClass('cx-media');
|
||||
w.compressx.media.lockbtn(true);
|
||||
|
||||
var ajax_action=w.compressx.media.get_ajax_action(action);
|
||||
|
||||
var ajax_data = {
|
||||
'action': ajax_action,
|
||||
'id':id
|
||||
};
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
w.compressx.media.get_progress();
|
||||
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
w.compressx.media.get_progress();
|
||||
});
|
||||
},
|
||||
handle_action_button_edit:function()
|
||||
{
|
||||
if(w.compressx.media.islockbtn())
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
var $row = $(this).closest('.misc-pub-cx');
|
||||
var $select = $row.find('.cx-media-selected');
|
||||
var action = $select.val();
|
||||
|
||||
if(action==="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var id=$( this ).data( 'id' );
|
||||
$( this ).html("Converting...");
|
||||
$( this ).removeClass('cx-media');
|
||||
w.compressx.media.lockbtn(true);
|
||||
|
||||
var ajax_action=w.compressx.media.get_ajax_action(action);
|
||||
var ajax_data = {
|
||||
'action': ajax_action,
|
||||
'id':id
|
||||
};
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
w.compressx.media.get_progress('edit');
|
||||
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
w.compressx.media.get_progress('edit');
|
||||
});
|
||||
},
|
||||
handle_action_button_attachment:function()
|
||||
{
|
||||
if(w.compressx.media.islockbtn())
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
var $row = $(this).closest('.cx-media-attachment');
|
||||
var $select = $row.find('.cx-media-selected');
|
||||
var action = $select.val();
|
||||
|
||||
if(action==="")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var id=$( this ).data( 'id' );
|
||||
$( this ).html("Converting...");
|
||||
$( this ).removeClass('cx-media');
|
||||
w.compressx.media.lockbtn(true);
|
||||
|
||||
var ajax_action=w.compressx.media.get_ajax_action(action);
|
||||
var ajax_data = {
|
||||
'action': ajax_action,
|
||||
'id':id
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
w.compressx.media.get_progress('attachment');
|
||||
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
w.compressx.media.get_progress('attachment');
|
||||
});
|
||||
},
|
||||
get_ajax_action: function(action) {
|
||||
switch (action) {
|
||||
case 'convert': return 'compressx_opt_single_image';
|
||||
case 'delete': return 'compressx_delete_single_image';
|
||||
default: return '';
|
||||
}
|
||||
},
|
||||
get_progress:function(page='media')
|
||||
{
|
||||
var ids=[];
|
||||
if(page=='media')
|
||||
{
|
||||
var media=$('.cx-media-item');
|
||||
if ( media.length>0 )
|
||||
{
|
||||
media.each( function()
|
||||
{
|
||||
ids.push( $( this ).data( 'id' ) );
|
||||
} );
|
||||
}
|
||||
}
|
||||
else if(page=='attachment')
|
||||
{
|
||||
var id=$('.cx-media-attachment').data( 'id' );
|
||||
ids.push(id );
|
||||
}
|
||||
else
|
||||
{
|
||||
var id=$('.misc-pub-cx').data( 'id' );
|
||||
ids.push(id );
|
||||
}
|
||||
|
||||
if(ids.length<1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var ids_json=JSON.stringify(ids);
|
||||
var ajax_data = {
|
||||
'action': 'compressx_get_opt_single_image_progress',
|
||||
ids:ids_json,
|
||||
page:page
|
||||
};
|
||||
|
||||
compressx_post_request(ajax_data, function(data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(typeof data !== 'undefined' && data !== '')
|
||||
{
|
||||
var jsonarray = jQuery.parseJSON(data);
|
||||
w.compressx.media.update(jsonarray,page);
|
||||
if (jsonarray.result === 'success')
|
||||
{
|
||||
if(jsonarray.continue)
|
||||
{
|
||||
setTimeout(function ()
|
||||
{
|
||||
w.compressx.media.get_progress(page);
|
||||
}, 1000);
|
||||
}
|
||||
else if(jsonarray.finished)
|
||||
{
|
||||
w.compressx.media.lockbtn(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
//w.compressx.media.optimize_timeout_image(page);
|
||||
w.compressx.media.lockbtn(false);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if(jsonarray.timeout)
|
||||
{
|
||||
//w.compressx.media.optimize_timeout_image(page);
|
||||
w.compressx.media.lockbtn(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
w.compressx.media.lockbtn(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
alert(err);
|
||||
w.compressx.media.lockbtn(false);
|
||||
}
|
||||
|
||||
}, function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
setTimeout(function ()
|
||||
{
|
||||
w.compressx.media.get_progress(page);
|
||||
}, 1000);
|
||||
});
|
||||
},
|
||||
update:function (jsonarray,page='media')
|
||||
{
|
||||
if(page=='edit')
|
||||
{
|
||||
var id=$('.misc-pub-cx').data( 'id' );
|
||||
if(jsonarray.hasOwnProperty(id))
|
||||
{
|
||||
$( '.misc-pub-cx' ).html(jsonarray[id]['html']);
|
||||
}
|
||||
}
|
||||
else if(page=='attachment')
|
||||
{
|
||||
var media=$('.cx-media-attachment');
|
||||
if ( media.length>0 )
|
||||
{
|
||||
media.each( function()
|
||||
{
|
||||
var id=$( this ).data( 'id' );
|
||||
if(jsonarray.hasOwnProperty(id))
|
||||
{
|
||||
$( this ).html(jsonarray[id]['html']);
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var media=$('.cx-media-item');
|
||||
if ( media.length>0 )
|
||||
{
|
||||
media.each( function()
|
||||
{
|
||||
var id=$( this ).data( 'id' );
|
||||
if(jsonarray.hasOwnProperty(id))
|
||||
{
|
||||
$( this ).html(jsonarray[id]['html']);
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
},
|
||||
lockbtn:function (status)
|
||||
{
|
||||
w.compressx.media.lock=status;
|
||||
},
|
||||
islockbtn:function ()
|
||||
{
|
||||
return w.compressx.media.lock;
|
||||
}
|
||||
};
|
||||
w.compressx.media.init();
|
||||
})(jQuery, window);
|
||||
@@ -0,0 +1,599 @@
|
||||
// DOM.event.move
|
||||
//
|
||||
// 2.0.0
|
||||
//
|
||||
// Stephen Band
|
||||
//
|
||||
// Triggers 'movestart', 'move' and 'moveend' events after
|
||||
// mousemoves following a mousedown cross a distance threshold,
|
||||
// similar to the native 'dragstart', 'drag' and 'dragend' events.
|
||||
// Move events are throttled to animation frames. Move event objects
|
||||
// have the properties:
|
||||
//
|
||||
// pageX:
|
||||
// pageY: Page coordinates of pointer.
|
||||
// startX:
|
||||
// startY: Page coordinates of pointer at movestart.
|
||||
// distX:
|
||||
// distY: Distance the pointer has moved since movestart.
|
||||
// deltaX:
|
||||
// deltaY: Distance the finger has moved since last event.
|
||||
// velocityX:
|
||||
// velocityY: Average velocity over last few events.
|
||||
|
||||
|
||||
(function(fn) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([], fn);
|
||||
} else if ((typeof module !== "undefined" && module !== null) && module.exports) {
|
||||
module.exports = fn;
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
})(function(){
|
||||
var assign = Object.assign || window.jQuery && jQuery.extend;
|
||||
|
||||
// Number of pixels a pressed pointer travels before movestart
|
||||
// event is fired.
|
||||
var threshold = 8;
|
||||
|
||||
// Shim for requestAnimationFrame, falling back to timer. See:
|
||||
// see http://paulirish.com/2011/requestanimationframe-for-smart-animating/
|
||||
var requestFrame = (function(){
|
||||
return (
|
||||
window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
function(fn, element){
|
||||
return window.setTimeout(function(){
|
||||
fn();
|
||||
}, 25);
|
||||
}
|
||||
);
|
||||
})();
|
||||
|
||||
// Shim for customEvent
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
|
||||
(function () {
|
||||
if ( typeof window.CustomEvent === "function" ) return false;
|
||||
function CustomEvent ( event, params ) {
|
||||
params = params || { bubbles: false, cancelable: false, detail: undefined };
|
||||
var evt = document.createEvent( 'CustomEvent' );
|
||||
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
|
||||
return evt;
|
||||
}
|
||||
|
||||
CustomEvent.prototype = window.Event.prototype;
|
||||
window.CustomEvent = CustomEvent;
|
||||
})();
|
||||
|
||||
var ignoreTags = {
|
||||
textarea: true,
|
||||
input: true,
|
||||
select: true,
|
||||
button: true
|
||||
};
|
||||
|
||||
var mouseevents = {
|
||||
move: 'mousemove',
|
||||
cancel: 'mouseup dragstart',
|
||||
end: 'mouseup'
|
||||
};
|
||||
|
||||
var touchevents = {
|
||||
move: 'touchmove',
|
||||
cancel: 'touchend',
|
||||
end: 'touchend'
|
||||
};
|
||||
|
||||
var rspaces = /\s+/;
|
||||
|
||||
|
||||
// DOM Events
|
||||
|
||||
var eventOptions = { bubbles: true, cancelable: true };
|
||||
|
||||
var eventsSymbol = typeof Symbol === "function" ? Symbol('events') : {};
|
||||
|
||||
function createEvent(type) {
|
||||
return new CustomEvent(type, eventOptions);
|
||||
}
|
||||
|
||||
function getEvents(node) {
|
||||
return node[eventsSymbol] || (node[eventsSymbol] = {});
|
||||
}
|
||||
|
||||
function on(node, types, fn, data, selector) {
|
||||
types = types.split(rspaces);
|
||||
|
||||
var events = getEvents(node);
|
||||
var i = types.length;
|
||||
var handlers, type;
|
||||
|
||||
function handler(e) { fn(e, data); }
|
||||
|
||||
while (i--) {
|
||||
type = types[i];
|
||||
handlers = events[type] || (events[type] = []);
|
||||
handlers.push([fn, handler]);
|
||||
node.addEventListener(type, handler);
|
||||
}
|
||||
}
|
||||
|
||||
function off(node, types, fn, selector) {
|
||||
types = types.split(rspaces);
|
||||
|
||||
var events = getEvents(node);
|
||||
var i = types.length;
|
||||
var type, handlers, k;
|
||||
|
||||
if (!events) { return; }
|
||||
|
||||
while (i--) {
|
||||
type = types[i];
|
||||
handlers = events[type];
|
||||
if (!handlers) { continue; }
|
||||
k = handlers.length;
|
||||
while (k--) {
|
||||
if (handlers[k][0] === fn) {
|
||||
node.removeEventListener(type, handlers[k][1]);
|
||||
handlers.splice(k, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function trigger(node, type, properties) {
|
||||
// Don't cache events. It prevents you from triggering an event of a
|
||||
// given type from inside the handler of another event of that type.
|
||||
var event = createEvent(type);
|
||||
if (properties) { assign(event, properties); }
|
||||
node.dispatchEvent(event);
|
||||
}
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
function Timer(fn){
|
||||
var callback = fn,
|
||||
active = false,
|
||||
running = false;
|
||||
|
||||
function trigger(time) {
|
||||
if (active){
|
||||
callback();
|
||||
requestFrame(trigger);
|
||||
running = true;
|
||||
active = false;
|
||||
}
|
||||
else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.kick = function(fn) {
|
||||
active = true;
|
||||
if (!running) { trigger(); }
|
||||
};
|
||||
|
||||
this.end = function(fn) {
|
||||
var cb = callback;
|
||||
|
||||
if (!fn) { return; }
|
||||
|
||||
// If the timer is not running, simply call the end callback.
|
||||
if (!running) {
|
||||
fn();
|
||||
}
|
||||
// If the timer is running, and has been kicked lately, then
|
||||
// queue up the current callback and the end callback, otherwise
|
||||
// just the end callback.
|
||||
else {
|
||||
callback = active ?
|
||||
function(){ cb(); fn(); } :
|
||||
fn ;
|
||||
|
||||
active = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
function noop() {}
|
||||
|
||||
function preventDefault(e) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function isIgnoreTag(e) {
|
||||
return !!ignoreTags[e.target.tagName.toLowerCase()];
|
||||
}
|
||||
|
||||
function isPrimaryButton(e) {
|
||||
// Ignore mousedowns on any button other than the left (or primary)
|
||||
// mouse button, or when a modifier key is pressed.
|
||||
return (e.which === 1 && !e.ctrlKey && !e.altKey);
|
||||
}
|
||||
|
||||
function identifiedTouch(touchList, id) {
|
||||
var i, l;
|
||||
|
||||
if (touchList.identifiedTouch) {
|
||||
return touchList.identifiedTouch(id);
|
||||
}
|
||||
|
||||
// touchList.identifiedTouch() does not exist in
|
||||
// webkit yet… we must do the search ourselves...
|
||||
|
||||
i = -1;
|
||||
l = touchList.length;
|
||||
|
||||
while (++i < l) {
|
||||
if (touchList[i].identifier === id) {
|
||||
return touchList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function changedTouch(e, data) {
|
||||
var touch = identifiedTouch(e.changedTouches, data.identifier);
|
||||
|
||||
// This isn't the touch you're looking for.
|
||||
if (!touch) { return; }
|
||||
|
||||
// Chrome Android (at least) includes touches that have not
|
||||
// changed in e.changedTouches. That's a bit annoying. Check
|
||||
// that this touch has changed.
|
||||
if (touch.pageX === data.pageX && touch.pageY === data.pageY) { return; }
|
||||
|
||||
return touch;
|
||||
}
|
||||
|
||||
|
||||
// Handlers that decide when the first movestart is triggered
|
||||
|
||||
function mousedown(e){
|
||||
// Ignore non-primary buttons
|
||||
if (!isPrimaryButton(e)) { return; }
|
||||
|
||||
// Ignore form and interactive elements
|
||||
if (isIgnoreTag(e)) { return; }
|
||||
|
||||
on(document, mouseevents.move, mousemove, e);
|
||||
on(document, mouseevents.cancel, mouseend, e);
|
||||
}
|
||||
|
||||
function mousemove(e, data){
|
||||
checkThreshold(e, data, e, removeMouse);
|
||||
}
|
||||
|
||||
function mouseend(e, data) {
|
||||
removeMouse();
|
||||
}
|
||||
|
||||
function removeMouse() {
|
||||
off(document, mouseevents.move, mousemove);
|
||||
off(document, mouseevents.cancel, mouseend);
|
||||
}
|
||||
|
||||
function touchstart(e) {
|
||||
// Don't get in the way of interaction with form elements
|
||||
if (ignoreTags[e.target.tagName.toLowerCase()]) { return; }
|
||||
|
||||
var touch = e.changedTouches[0];
|
||||
|
||||
// iOS live updates the touch objects whereas Android gives us copies.
|
||||
// That means we can't trust the touchstart object to stay the same,
|
||||
// so we must copy the data. This object acts as a template for
|
||||
// movestart, move and moveend event objects.
|
||||
var data = {
|
||||
target: touch.target,
|
||||
pageX: touch.pageX,
|
||||
pageY: touch.pageY,
|
||||
identifier: touch.identifier,
|
||||
|
||||
// The only way to make handlers individually unbindable is by
|
||||
// making them unique.
|
||||
touchmove: function(e, data) { touchmove(e, data); },
|
||||
touchend: function(e, data) { touchend(e, data); }
|
||||
};
|
||||
|
||||
on(document, touchevents.move, data.touchmove, data);
|
||||
on(document, touchevents.cancel, data.touchend, data);
|
||||
}
|
||||
|
||||
function touchmove(e, data) {
|
||||
var touch = changedTouch(e, data);
|
||||
if (!touch) { return; }
|
||||
checkThreshold(e, data, touch, removeTouch);
|
||||
}
|
||||
|
||||
function touchend(e, data) {
|
||||
var touch = identifiedTouch(e.changedTouches, data.identifier);
|
||||
if (!touch) { return; }
|
||||
removeTouch(data);
|
||||
}
|
||||
|
||||
function removeTouch(data) {
|
||||
off(document, touchevents.move, data.touchmove);
|
||||
off(document, touchevents.cancel, data.touchend);
|
||||
}
|
||||
|
||||
function checkThreshold(e, data, touch, fn) {
|
||||
var distX = touch.pageX - data.pageX;
|
||||
var distY = touch.pageY - data.pageY;
|
||||
|
||||
// Do nothing if the threshold has not been crossed.
|
||||
if ((distX * distX) + (distY * distY) < (threshold * threshold)) { return; }
|
||||
|
||||
triggerStart(e, data, touch, distX, distY, fn);
|
||||
}
|
||||
|
||||
function triggerStart(e, data, touch, distX, distY, fn) {
|
||||
var touches = e.targetTouches;
|
||||
var time = e.timeStamp - data.timeStamp;
|
||||
|
||||
// Create a movestart object with some special properties that
|
||||
// are passed only to the movestart handlers.
|
||||
var template = {
|
||||
altKey: e.altKey,
|
||||
ctrlKey: e.ctrlKey,
|
||||
shiftKey: e.shiftKey,
|
||||
startX: data.pageX,
|
||||
startY: data.pageY,
|
||||
distX: distX,
|
||||
distY: distY,
|
||||
deltaX: distX,
|
||||
deltaY: distY,
|
||||
pageX: touch.pageX,
|
||||
pageY: touch.pageY,
|
||||
velocityX: distX / time,
|
||||
velocityY: distY / time,
|
||||
identifier: data.identifier,
|
||||
targetTouches: touches,
|
||||
finger: touches ? touches.length : 1,
|
||||
enableMove: function() {
|
||||
this.moveEnabled = true;
|
||||
this.enableMove = noop;
|
||||
e.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
// Trigger the movestart event.
|
||||
trigger(data.target, 'movestart', template);
|
||||
|
||||
// Unbind handlers that tracked the touch or mouse up till now.
|
||||
fn(data);
|
||||
}
|
||||
|
||||
|
||||
// Handlers that control what happens following a movestart
|
||||
|
||||
function activeMousemove(e, data) {
|
||||
var timer = data.timer;
|
||||
|
||||
data.touch = e;
|
||||
data.timeStamp = e.timeStamp;
|
||||
timer.kick();
|
||||
}
|
||||
|
||||
function activeMouseend(e, data) {
|
||||
var target = data.target;
|
||||
var event = data.event;
|
||||
var timer = data.timer;
|
||||
|
||||
removeActiveMouse();
|
||||
|
||||
endEvent(target, event, timer, function() {
|
||||
// Unbind the click suppressor, waiting until after mouseup
|
||||
// has been handled.
|
||||
setTimeout(function(){
|
||||
off(target, 'click', preventDefault);
|
||||
}, 0);
|
||||
});
|
||||
}
|
||||
|
||||
function removeActiveMouse() {
|
||||
off(document, mouseevents.move, activeMousemove);
|
||||
off(document, mouseevents.end, activeMouseend);
|
||||
}
|
||||
|
||||
function activeTouchmove(e, data) {
|
||||
var event = data.event;
|
||||
var timer = data.timer;
|
||||
var touch = changedTouch(e, event);
|
||||
|
||||
if (!touch) { return; }
|
||||
|
||||
// Stop the interface from gesturing
|
||||
e.preventDefault();
|
||||
|
||||
event.targetTouches = e.targetTouches;
|
||||
data.touch = touch;
|
||||
data.timeStamp = e.timeStamp;
|
||||
|
||||
timer.kick();
|
||||
}
|
||||
|
||||
function activeTouchend(e, data) {
|
||||
var target = data.target;
|
||||
var event = data.event;
|
||||
var timer = data.timer;
|
||||
var touch = identifiedTouch(e.changedTouches, event.identifier);
|
||||
|
||||
// This isn't the touch you're looking for.
|
||||
if (!touch) { return; }
|
||||
|
||||
removeActiveTouch(data);
|
||||
endEvent(target, event, timer);
|
||||
}
|
||||
|
||||
function removeActiveTouch(data) {
|
||||
off(document, touchevents.move, data.activeTouchmove);
|
||||
off(document, touchevents.end, data.activeTouchend);
|
||||
}
|
||||
|
||||
|
||||
// Logic for triggering move and moveend events
|
||||
|
||||
function updateEvent(event, touch, timeStamp) {
|
||||
var time = timeStamp - event.timeStamp;
|
||||
|
||||
event.distX = touch.pageX - event.startX;
|
||||
event.distY = touch.pageY - event.startY;
|
||||
event.deltaX = touch.pageX - event.pageX;
|
||||
event.deltaY = touch.pageY - event.pageY;
|
||||
|
||||
// Average the velocity of the last few events using a decay
|
||||
// curve to even out spurious jumps in values.
|
||||
event.velocityX = 0.3 * event.velocityX + 0.7 * event.deltaX / time;
|
||||
event.velocityY = 0.3 * event.velocityY + 0.7 * event.deltaY / time;
|
||||
event.pageX = touch.pageX;
|
||||
event.pageY = touch.pageY;
|
||||
}
|
||||
|
||||
function endEvent(target, event, timer, fn) {
|
||||
timer.end(function(){
|
||||
trigger(target, 'moveend', event);
|
||||
return fn && fn();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Set up the DOM
|
||||
|
||||
function movestart(e) {
|
||||
if (e.defaultPrevented) { return; }
|
||||
if (!e.moveEnabled) { return; }
|
||||
|
||||
var event = {
|
||||
startX: e.startX,
|
||||
startY: e.startY,
|
||||
pageX: e.pageX,
|
||||
pageY: e.pageY,
|
||||
distX: e.distX,
|
||||
distY: e.distY,
|
||||
deltaX: e.deltaX,
|
||||
deltaY: e.deltaY,
|
||||
velocityX: e.velocityX,
|
||||
velocityY: e.velocityY,
|
||||
identifier: e.identifier,
|
||||
targetTouches: e.targetTouches,
|
||||
finger: e.finger
|
||||
};
|
||||
|
||||
var data = {
|
||||
target: e.target,
|
||||
event: event,
|
||||
timer: new Timer(update),
|
||||
touch: undefined,
|
||||
timeStamp: e.timeStamp
|
||||
};
|
||||
|
||||
function update(time) {
|
||||
updateEvent(event, data.touch, data.timeStamp);
|
||||
trigger(data.target, 'move', event);
|
||||
}
|
||||
|
||||
if (e.identifier === undefined) {
|
||||
// We're dealing with a mouse event.
|
||||
// Stop clicks from propagating during a move
|
||||
on(e.target, 'click', preventDefault);
|
||||
on(document, mouseevents.move, activeMousemove, data);
|
||||
on(document, mouseevents.end, activeMouseend, data);
|
||||
}
|
||||
else {
|
||||
// In order to unbind correct handlers they have to be unique
|
||||
data.activeTouchmove = function(e, data) { activeTouchmove(e, data); };
|
||||
data.activeTouchend = function(e, data) { activeTouchend(e, data); };
|
||||
|
||||
// We're dealing with a touch.
|
||||
on(document, touchevents.move, data.activeTouchmove, data);
|
||||
on(document, touchevents.end, data.activeTouchend, data);
|
||||
}
|
||||
}
|
||||
|
||||
on(document, 'mousedown', mousedown);
|
||||
on(document, 'touchstart', touchstart);
|
||||
on(document, 'movestart', movestart);
|
||||
|
||||
|
||||
// jQuery special events
|
||||
//
|
||||
// jQuery event objects are copies of DOM event objects. They need
|
||||
// a little help copying the move properties across.
|
||||
|
||||
if (!window.jQuery) { return; }
|
||||
|
||||
var properties = ("startX startY pageX pageY distX distY deltaX deltaY velocityX velocityY").split(' ');
|
||||
|
||||
function enableMove1(e) { e.enableMove(); }
|
||||
function enableMove2(e) { e.enableMove(); }
|
||||
function enableMove3(e) { e.enableMove(); }
|
||||
|
||||
function add(handleObj) {
|
||||
var handler = handleObj.handler;
|
||||
|
||||
handleObj.handler = function(e) {
|
||||
// Copy move properties across from originalEvent
|
||||
var i = properties.length;
|
||||
var property;
|
||||
|
||||
while(i--) {
|
||||
property = properties[i];
|
||||
e[property] = e.originalEvent[property];
|
||||
}
|
||||
|
||||
handler.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
jQuery.event.special.movestart = {
|
||||
setup: function() {
|
||||
// Movestart must be enabled to allow other move events
|
||||
on(this, 'movestart', enableMove1);
|
||||
|
||||
// Do listen to DOM events
|
||||
return false;
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
off(this, 'movestart', enableMove1);
|
||||
return false;
|
||||
},
|
||||
|
||||
add: add
|
||||
};
|
||||
|
||||
jQuery.event.special.move = {
|
||||
setup: function() {
|
||||
on(this, 'movestart', enableMove2);
|
||||
return false;
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
off(this, 'movestart', enableMove2);
|
||||
return false;
|
||||
},
|
||||
|
||||
add: add
|
||||
};
|
||||
|
||||
jQuery.event.special.moveend = {
|
||||
setup: function() {
|
||||
on(this, 'movestart', enableMove3);
|
||||
return false;
|
||||
},
|
||||
|
||||
teardown: function() {
|
||||
off(this, 'movestart', enableMove3);
|
||||
return false;
|
||||
},
|
||||
|
||||
add: add
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
(function($){
|
||||
|
||||
$.fn.twentytwenty = function(options) {
|
||||
var options = $.extend({
|
||||
default_offset_pct: 0.5,
|
||||
orientation: 'horizontal',
|
||||
before_label: 'Before',
|
||||
after_label: 'After',
|
||||
no_overlay: false,
|
||||
move_slider_on_hover: false,
|
||||
move_with_handle_only: true,
|
||||
click_to_move: false
|
||||
}, options);
|
||||
|
||||
return this.each(function() {
|
||||
|
||||
var sliderPct = options.default_offset_pct;
|
||||
var container = $(this);
|
||||
var sliderOrientation = options.orientation;
|
||||
var beforeDirection = (sliderOrientation === 'vertical') ? 'down' : 'left';
|
||||
var afterDirection = (sliderOrientation === 'vertical') ? 'up' : 'right';
|
||||
|
||||
|
||||
container.wrap("<div class='twentytwenty-wrapper twentytwenty-" + sliderOrientation + "'></div>");
|
||||
if(!options.no_overlay) {
|
||||
container.append("<div class='twentytwenty-overlay'></div>");
|
||||
var overlay = container.find(".twentytwenty-overlay");
|
||||
overlay.append("<div class='twentytwenty-before-label' data-content='"+options.before_label+"'></div>");
|
||||
overlay.append("<div class='twentytwenty-after-label' data-content='"+options.after_label+"'></div>");
|
||||
}
|
||||
var beforeImg = container.find("img:first");
|
||||
var afterImg = container.find("img:last");
|
||||
container.append("<div class='twentytwenty-handle'></div>");
|
||||
var slider = container.find(".twentytwenty-handle");
|
||||
slider.append("<span class='twentytwenty-" + beforeDirection + "-arrow'></span>");
|
||||
slider.append("<span class='twentytwenty-" + afterDirection + "-arrow'></span>");
|
||||
container.addClass("twentytwenty-container");
|
||||
beforeImg.addClass("twentytwenty-before");
|
||||
afterImg.addClass("twentytwenty-after");
|
||||
|
||||
var calcOffset = function(dimensionPct) {
|
||||
var w = beforeImg.width();
|
||||
var h = beforeImg.height();
|
||||
return {
|
||||
w: w+"px",
|
||||
h: h+"px",
|
||||
cw: (dimensionPct*w)+"px",
|
||||
ch: (dimensionPct*h)+"px"
|
||||
};
|
||||
};
|
||||
|
||||
var adjustContainer = function(offset) {
|
||||
if (sliderOrientation === 'vertical') {
|
||||
beforeImg.css("clip", "rect(0,"+offset.w+","+offset.ch+",0)");
|
||||
afterImg.css("clip", "rect("+offset.ch+","+offset.w+","+offset.h+",0)");
|
||||
}
|
||||
else {
|
||||
beforeImg.css("clip", "rect(0,"+offset.cw+","+offset.h+",0)");
|
||||
afterImg.css("clip", "rect(0,"+offset.w+","+offset.h+","+offset.cw+")");
|
||||
}
|
||||
container.css("height", offset.h);
|
||||
};
|
||||
|
||||
var adjustSlider = function(pct) {
|
||||
var offset = calcOffset(pct);
|
||||
slider.css((sliderOrientation==="vertical") ? "top" : "left", (sliderOrientation==="vertical") ? offset.ch : offset.cw);
|
||||
adjustContainer(offset);
|
||||
};
|
||||
|
||||
// Return the number specified or the min/max number if it outside the range given.
|
||||
var minMaxNumber = function(num, min, max) {
|
||||
return Math.max(min, Math.min(max, num));
|
||||
};
|
||||
|
||||
// Calculate the slider percentage based on the position.
|
||||
var getSliderPercentage = function(positionX, positionY) {
|
||||
var sliderPercentage = (sliderOrientation === 'vertical') ?
|
||||
(positionY-offsetY)/imgHeight :
|
||||
(positionX-offsetX)/imgWidth;
|
||||
|
||||
return minMaxNumber(sliderPercentage, 0, 1);
|
||||
};
|
||||
|
||||
|
||||
$(window).on("resize.twentytwenty", function(e) {
|
||||
adjustSlider(sliderPct);
|
||||
});
|
||||
|
||||
var offsetX = 0;
|
||||
var offsetY = 0;
|
||||
var imgWidth = 0;
|
||||
var imgHeight = 0;
|
||||
var onMoveStart = function(e) {
|
||||
if (((e.distX > e.distY && e.distX < -e.distY) || (e.distX < e.distY && e.distX > -e.distY)) && sliderOrientation !== 'vertical') {
|
||||
e.preventDefault();
|
||||
}
|
||||
else if (((e.distX < e.distY && e.distX < -e.distY) || (e.distX > e.distY && e.distX > -e.distY)) && sliderOrientation === 'vertical') {
|
||||
e.preventDefault();
|
||||
}
|
||||
container.addClass("active");
|
||||
offsetX = container.offset().left;
|
||||
offsetY = container.offset().top;
|
||||
imgWidth = beforeImg.width();
|
||||
imgHeight = beforeImg.height();
|
||||
};
|
||||
var onMove = function(e) {
|
||||
if (container.hasClass("active")) {
|
||||
sliderPct = getSliderPercentage(e.pageX, e.pageY);
|
||||
adjustSlider(sliderPct);
|
||||
}
|
||||
};
|
||||
var onMoveEnd = function() {
|
||||
container.removeClass("active");
|
||||
};
|
||||
|
||||
var moveTarget = options.move_with_handle_only ? slider : container;
|
||||
moveTarget.on("movestart",onMoveStart);
|
||||
moveTarget.on("move",onMove);
|
||||
moveTarget.on("moveend",onMoveEnd);
|
||||
|
||||
if (options.move_slider_on_hover) {
|
||||
container.on("mouseenter", onMoveStart);
|
||||
container.on("mousemove", onMove);
|
||||
container.on("mouseleave", onMoveEnd);
|
||||
}
|
||||
|
||||
slider.on("touchmove", function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
container.find("img").on("mousedown", function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
if (options.click_to_move) {
|
||||
container.on('click', function(e) {
|
||||
offsetX = container.offset().left;
|
||||
offsetY = container.offset().top;
|
||||
imgWidth = beforeImg.width();
|
||||
imgHeight = beforeImg.height();
|
||||
|
||||
sliderPct = getSliderPercentage(e.pageX, e.pageY);
|
||||
adjustSlider(sliderPct);
|
||||
});
|
||||
}
|
||||
|
||||
$(window).trigger("resize.twentytwenty");
|
||||
});
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user