Version Description
*Regenerate on the fly
=
Download this release
Release Info
| Developer | turcuciprian |
| Plugin | |
| Version | 1.0 |
| Comparing to | |
| See all releases | |
Code changes from version 0.8.2.7 to 1.0
- README.md +0 -0
- readme.txt +6 -8
- regenerate-thumbnails-advanced.php +225 -14
- screenshot-2.png +0 -0
- script.js +23 -6
- style.css +5 -1
README.md
CHANGED
|
File without changes
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
| 4 |
Tags: regenerate, thumbnails, advanced, easy, day, weeek, month
|
| 5 |
Requires at least: 4.0
|
| 6 |
Tested up to: 4.3.1
|
| 7 |
-
Stable tag: 0
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
|
@@ -23,6 +23,7 @@ Features:
|
|
| 23 |
* The period is last day, last week, last month or all
|
| 24 |
* Clean simple interface where you have a progress bar showing you the percentage of images regenerated
|
| 25 |
* You get to see the total number of images affected by your period, as well as the images afected so far when processing
|
|
|
|
| 26 |
|
| 27 |
== Installation ==
|
| 28 |
|
|
@@ -92,10 +93,8 @@ The script stops, it does not run in the background
|
|
| 92 |
* Added new style
|
| 93 |
* Added datepickers
|
| 94 |
|
| 95 |
-
= 0
|
| 96 |
-
*
|
| 97 |
-
* Fixed a js issue
|
| 98 |
-
|
| 99 |
|
| 100 |
== Upgrade Notice ==
|
| 101 |
|
|
@@ -129,6 +128,5 @@ No issuse with this version that require attention. Small update change. It's ba
|
|
| 129 |
= 0.8.2.6 =
|
| 130 |
This version changes the style and adds a bit of functionality to the general settings (a date start-end option to choose from)
|
| 131 |
|
| 132 |
-
= 0
|
| 133 |
-
|
| 134 |
-
fixes some js issues and ajax issues. it's recommended to update
|
| 4 |
Tags: regenerate, thumbnails, advanced, easy, day, weeek, month
|
| 5 |
Requires at least: 4.0
|
| 6 |
Tested up to: 4.3.1
|
| 7 |
+
Stable tag: 1.0
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 23 |
* The period is last day, last week, last month or all
|
| 24 |
* Clean simple interface where you have a progress bar showing you the percentage of images regenerated
|
| 25 |
* You get to see the total number of images affected by your period, as well as the images afected so far when processing
|
| 26 |
+
* Regenerate thubnails on the fly
|
| 27 |
|
| 28 |
== Installation ==
|
| 29 |
|
| 93 |
* Added new style
|
| 94 |
* Added datepickers
|
| 95 |
|
| 96 |
+
= 1.0 =
|
| 97 |
+
*Regenerate on the fly
|
|
|
|
|
|
|
| 98 |
|
| 99 |
== Upgrade Notice ==
|
| 100 |
|
| 128 |
= 0.8.2.6 =
|
| 129 |
This version changes the style and adds a bit of functionality to the general settings (a date start-end option to choose from)
|
| 130 |
|
| 131 |
+
= 1.0 =
|
| 132 |
+
This version
|
|
|
regenerate-thumbnails-advanced.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
Plugin Name: reGenerate Thumbnails - advanced
|
| 4 |
Plugin URI: http://turcuciprian.com
|
| 5 |
Description: A plugin that makes regenerating thumbnails even easier than before and more flexible.
|
| 6 |
-
Version: 0
|
| 7 |
Author: turcuciprian
|
| 8 |
Author URI: http://turcuciprian.com
|
| 9 |
License: GPLv2 or later
|
|
@@ -11,7 +11,6 @@
|
|
| 11 |
*/
|
| 12 |
|
| 13 |
//Global variables for arguments
|
| 14 |
-
|
| 15 |
class cc {
|
| 16 |
|
| 17 |
// create basic page in the admin panel, with menu settings too
|
|
@@ -22,13 +21,20 @@ class cc {
|
|
| 22 |
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin'));
|
| 23 |
//ajax callback for button click
|
| 24 |
add_action('wp_ajax_rta_ajax', array($this, 'ajax_callback'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
public function ajax_callback() {
|
| 28 |
if (isset($_POST['type'])) {
|
| 29 |
$type = $_POST['type'];
|
| 30 |
}
|
| 31 |
-
$logstatus ='';
|
| 32 |
$offset = 0;
|
| 33 |
switch ($type) {
|
| 34 |
case 'general':
|
|
@@ -60,7 +66,7 @@ class cc {
|
|
| 60 |
break;
|
| 61 |
}
|
| 62 |
}
|
| 63 |
-
if (
|
| 64 |
$fromTo = explode('-', $date);
|
| 65 |
$startDate = date("m/d/Y", strtotime($fromTo[0] . " -1 day"));
|
| 66 |
$endDate = date("m/d/Y", strtotime($fromTo[1] . " +1 day"));
|
|
@@ -82,21 +88,15 @@ class cc {
|
|
| 82 |
}
|
| 83 |
wp_reset_query();
|
| 84 |
wp_reset_postdata();
|
| 85 |
-
$logstatus .= "<pre>" . print_r($the_query, true) . "</pre>";
|
| 86 |
-
|
| 87 |
-
$typeV = $_POST['type'];
|
| 88 |
-
}
|
| 89 |
-
if(!isset($date) || empty($date)){
|
| 90 |
-
$date = '';
|
| 91 |
-
}
|
| 92 |
-
$return_arr = array('pCount' => $post_count, 'fromTo' => $date, 'type' => $typeV, 'period' => $period);
|
| 93 |
// return the total number of results
|
| 94 |
|
| 95 |
|
| 96 |
echo json_encode($return_arr);
|
| 97 |
break;
|
| 98 |
case 'submit':
|
| 99 |
-
$logstatus = '';
|
| 100 |
$error = array();
|
| 101 |
if (isset($_POST['offset'])) {
|
| 102 |
$offset = $_POST['offset'];
|
|
@@ -203,12 +203,16 @@ class cc {
|
|
| 203 |
}
|
| 204 |
//increment offset
|
| 205 |
$result = $offset + 1;
|
|
|
|
|
|
|
| 206 |
echo json_encode(array('offset' => ($offset + 1), 'error' => $error, 'logstatus' => $logstatus, 'startTime' => $_POST['startTime'], 'fromTo' => $_POST['fromTo'], 'type' => $_POST['type'], 'period' => $period));
|
| 207 |
break;
|
| 208 |
}
|
| 209 |
/* Restore original Post Data */
|
| 210 |
wp_reset_query();
|
| 211 |
wp_reset_postdata();
|
|
|
|
|
|
|
| 212 |
wp_die();
|
| 213 |
}
|
| 214 |
|
|
@@ -222,7 +226,7 @@ class cc {
|
|
| 222 |
}
|
| 223 |
|
| 224 |
function enqueue_admin($hook) {
|
| 225 |
-
if (isset($_GET['page']) && isset($hook)) {
|
| 226 |
if ($_GET['page'] !== 'regenerate_thumbnails_advanced' && $hook != 'options-general.php ') {
|
| 227 |
return;
|
| 228 |
}
|
|
@@ -286,7 +290,19 @@ class cc {
|
|
| 286 |
</div><!-- where the errors show -->
|
| 287 |
</p>
|
| 288 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
</div>
|
|
|
|
| 290 |
</div>
|
| 291 |
<!-- Js Works End -->
|
| 292 |
<!--GTA wrap END -->
|
|
@@ -305,3 +321,198 @@ class cc {
|
|
| 305 |
/* var @cc cc */
|
| 306 |
$cc = new cc();
|
| 307 |
$cc->start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
Plugin Name: reGenerate Thumbnails - advanced
|
| 4 |
Plugin URI: http://turcuciprian.com
|
| 5 |
Description: A plugin that makes regenerating thumbnails even easier than before and more flexible.
|
| 6 |
+
Version: 1.0
|
| 7 |
Author: turcuciprian
|
| 8 |
Author URI: http://turcuciprian.com
|
| 9 |
License: GPLv2 or later
|
| 11 |
*/
|
| 12 |
|
| 13 |
//Global variables for arguments
|
|
|
|
| 14 |
class cc {
|
| 15 |
|
| 16 |
// create basic page in the admin panel, with menu settings too
|
| 21 |
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin'));
|
| 22 |
//ajax callback for button click
|
| 23 |
add_action('wp_ajax_rta_ajax', array($this, 'ajax_callback'));
|
| 24 |
+
add_action('wp_ajax_rtaOtfAjax', array($this, 'ajaxOtfCallback'));
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
public function ajaxOtfCallback() {
|
| 28 |
+
if (isset($_POST['otfVal'])) {
|
| 29 |
+
$tempValue = $_POST['tempValue'];
|
| 30 |
+
update_option('rtaOTF', $tempValue);
|
| 31 |
+
}
|
| 32 |
}
|
| 33 |
|
| 34 |
public function ajax_callback() {
|
| 35 |
if (isset($_POST['type'])) {
|
| 36 |
$type = $_POST['type'];
|
| 37 |
}
|
|
|
|
| 38 |
$offset = 0;
|
| 39 |
switch ($type) {
|
| 40 |
case 'general':
|
| 66 |
break;
|
| 67 |
}
|
| 68 |
}
|
| 69 |
+
if (!empty($date)) {
|
| 70 |
$fromTo = explode('-', $date);
|
| 71 |
$startDate = date("m/d/Y", strtotime($fromTo[0] . " -1 day"));
|
| 72 |
$endDate = date("m/d/Y", strtotime($fromTo[1] . " +1 day"));
|
| 88 |
}
|
| 89 |
wp_reset_query();
|
| 90 |
wp_reset_postdata();
|
| 91 |
+
// $logstatus .= "<pre>" . print_r($the_query, true) . "</pre>";
|
| 92 |
+
$return_arr = array('pCount' => $post_count, 'fromTo' => $date, 'type' => $_POST['type'], 'period' => $period);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
// return the total number of results
|
| 94 |
|
| 95 |
|
| 96 |
echo json_encode($return_arr);
|
| 97 |
break;
|
| 98 |
case 'submit':
|
| 99 |
+
// $logstatus = '';
|
| 100 |
$error = array();
|
| 101 |
if (isset($_POST['offset'])) {
|
| 102 |
$offset = $_POST['offset'];
|
| 203 |
}
|
| 204 |
//increment offset
|
| 205 |
$result = $offset + 1;
|
| 206 |
+
// $logstatus .= "<br/>".$the_query->post->ID;
|
| 207 |
+
// $logstatus .= "<br/><pre>" . print_r($args, true) . "</pre>";
|
| 208 |
echo json_encode(array('offset' => ($offset + 1), 'error' => $error, 'logstatus' => $logstatus, 'startTime' => $_POST['startTime'], 'fromTo' => $_POST['fromTo'], 'type' => $_POST['type'], 'period' => $period));
|
| 209 |
break;
|
| 210 |
}
|
| 211 |
/* Restore original Post Data */
|
| 212 |
wp_reset_query();
|
| 213 |
wp_reset_postdata();
|
| 214 |
+
|
| 215 |
+
|
| 216 |
wp_die();
|
| 217 |
}
|
| 218 |
|
| 226 |
}
|
| 227 |
|
| 228 |
function enqueue_admin($hook) {
|
| 229 |
+
if (!isset($_GET['page']) && isset($hook)) {
|
| 230 |
if ($_GET['page'] !== 'regenerate_thumbnails_advanced' && $hook != 'options-general.php ') {
|
| 231 |
return;
|
| 232 |
}
|
| 290 |
</div><!-- where the errors show -->
|
| 291 |
</p>
|
| 292 |
</div>
|
| 293 |
+
<?php
|
| 294 |
+
$rotf = get_option( 'rtaOTF');
|
| 295 |
+
?>
|
| 296 |
+
<div class="otf">
|
| 297 |
+
<h3> When needed</h3>
|
| 298 |
+
<input type="checkbox" class="rtaOtf" name="rtaOtf" value="" <?php checked('checked',$rotf);?> /> Regenerate on the fly
|
| 299 |
+
<p>
|
| 300 |
+
When needed, when user loads a page that does not have the thumbnail generated previously, it is automatically regenerated. WARNING, this may slow down server load
|
| 301 |
+
</p>
|
| 302 |
+
|
| 303 |
+
</div>
|
| 304 |
</div>
|
| 305 |
+
|
| 306 |
</div>
|
| 307 |
<!-- Js Works End -->
|
| 308 |
<!--GTA wrap END -->
|
| 321 |
/* var @cc cc */
|
| 322 |
$cc = new cc();
|
| 323 |
$cc->start();
|
| 324 |
+
//regenerate images on the fly (when they don't exist and it's needed)
|
| 325 |
+
|
| 326 |
+
//add a filter for image_downsize
|
| 327 |
+
// add_filter('image_downsize','test_image_downsize',true, 10,2);
|
| 328 |
+
|
| 329 |
+
//where all the on the fly magic happens
|
| 330 |
+
function test_image_downsize($bool,$imgid,$size){
|
| 331 |
+
|
| 332 |
+
// Get the current image metadata
|
| 333 |
+
$meta = wp_get_attachment_metadata($imgid);
|
| 334 |
+
//get the path to the image
|
| 335 |
+
if(isset($meta['file']) && !empty($meta['file'])){
|
| 336 |
+
$fullsizepath = wp_upload_dir()['path'].$meta['file'];
|
| 337 |
+
}
|
| 338 |
+
// replace the main image with the thumb image name
|
| 339 |
+
// $upload_dir = str_replace($meta['file'],$meta['sizes']['rtatest']['file'],$upload_dir);
|
| 340 |
+
|
| 341 |
+
// echo "<pre>";
|
| 342 |
+
// print_r($meta);
|
| 343 |
+
// echo($meta['sizes']['rtatest']['file']);
|
| 344 |
+
$file_url = wp_get_attachment_url($imgid);
|
| 345 |
+
// echo "<pre>";
|
| 346 |
+
// print_r($meta['sizes'][$size]);
|
| 347 |
+
|
| 348 |
+
if(!isset($meta['sizes'][$size]) && !empty($meta['sizes'][$size])){
|
| 349 |
+
if(!file_exists($file_url)){
|
| 350 |
+
exit;
|
| 351 |
+
// print_r($meta);
|
| 352 |
+
@set_time_limit(900);
|
| 353 |
+
// $metadata = wp_generate_attachment_metadata($imgid, $fullsizepath);
|
| 354 |
+
// print_r($metadata);
|
| 355 |
+
}
|
| 356 |
+
}
|
| 357 |
+
// if(!file_exists($file_url)){
|
| 358 |
+
// echo "does not exist";
|
| 359 |
+
// }
|
| 360 |
+
// echo $file_url;
|
| 361 |
+
echo "<pre>";
|
| 362 |
+
// print_r(array($file_url,$meta['sizes'][$size['width'],$meta['sizes'][$size]['height']));
|
| 363 |
+
echo "</pre>";
|
| 364 |
+
exit;
|
| 365 |
+
return array($file_url,$meta['sizes'][$size]['width'],$meta['sizes'][$size]['height']);
|
| 366 |
+
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
add_action('init','rtaInit');
|
| 370 |
+
function rtaInit(){
|
| 371 |
+
$rotf = get_option( 'rtaOTF');
|
| 372 |
+
if ( ! function_exists( 'gambit_otf_regen_thumbs_media_downsize' ) && $rotf=='checked') {
|
| 373 |
+
|
| 374 |
+
add_filter( 'image_downsize', 'gambit_otf_regen_thumbs_media_downsize', 10, 3 );
|
| 375 |
+
|
| 376 |
+
/**
|
| 377 |
+
* The downsizer. This only does something if the existing image size doesn't exist yet.
|
| 378 |
+
*
|
| 379 |
+
* @param $out boolean false
|
| 380 |
+
* @param $id int Attachment ID
|
| 381 |
+
* @param $size mixed The size name, or an array containing the width & height
|
| 382 |
+
* @return mixed False if the custom downsize failed, or an array of the image if successful
|
| 383 |
+
*/
|
| 384 |
+
function gambit_otf_regen_thumbs_media_downsize( $out, $id, $size ) {
|
| 385 |
+
|
| 386 |
+
// Gather all the different image sizes of WP (thumbnail, medium, large) and,
|
| 387 |
+
// all the theme/plugin-introduced sizes.
|
| 388 |
+
global $_gambit_otf_regen_thumbs_all_image_sizes;
|
| 389 |
+
if ( ! isset( $_gambit_otf_regen_thumbs_all_image_sizes ) ) {
|
| 390 |
+
global $_wp_additional_image_sizes;
|
| 391 |
+
|
| 392 |
+
$_gambit_otf_regen_thumbs_all_image_sizes = array();
|
| 393 |
+
$interimSizes = get_intermediate_image_sizes();
|
| 394 |
+
|
| 395 |
+
foreach ( $interimSizes as $sizeName ) {
|
| 396 |
+
if ( in_array( $sizeName, array( 'thumbnail', 'medium', 'large' ) ) ) {
|
| 397 |
+
|
| 398 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['width'] = get_option( $sizeName . '_size_w' );
|
| 399 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['height'] = get_option( $sizeName . '_size_h' );
|
| 400 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ]['crop'] = (bool) get_option( $sizeName . '_crop' );
|
| 401 |
+
|
| 402 |
+
} elseif ( isset( $_wp_additional_image_sizes[ $sizeName ] ) ) {
|
| 403 |
+
|
| 404 |
+
$_gambit_otf_regen_thumbs_all_image_sizes[ $sizeName ] = $_wp_additional_image_sizes[ $sizeName ];
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
// This now contains all the data that we have for all the image sizes
|
| 410 |
+
$allSizes = $_gambit_otf_regen_thumbs_all_image_sizes;
|
| 411 |
+
|
| 412 |
+
// If image size exists let WP serve it like normally
|
| 413 |
+
$imagedata = wp_get_attachment_metadata( $id );
|
| 414 |
+
|
| 415 |
+
// Image attachment doesn't exist
|
| 416 |
+
if ( ! is_array( $imagedata ) ) {
|
| 417 |
+
return false;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
// If the size given is a string / a name of a size
|
| 421 |
+
if ( is_string( $size ) ) {
|
| 422 |
+
|
| 423 |
+
// If WP doesn't know about the image size name, then we can't really do any resizing of our own
|
| 424 |
+
if ( empty( $allSizes[ $size ] ) ) {
|
| 425 |
+
return false;
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
// If the size has already been previously created, use it
|
| 429 |
+
if ( ! empty( $imagedata['sizes'][ $size ] ) && ! empty( $allSizes[ $size ] ) ) {
|
| 430 |
+
|
| 431 |
+
// But only if the size remained the same
|
| 432 |
+
if ( $allSizes[ $size ]['width'] == $imagedata['sizes'][ $size ]['width']
|
| 433 |
+
&& $allSizes[ $size ]['height'] == $imagedata['sizes'][ $size ]['height'] ) {
|
| 434 |
+
return false;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
// Or if the size is different and we found out before that the size really was different
|
| 438 |
+
if ( ! empty( $imagedata['sizes'][ $size ][ 'width_query' ] )
|
| 439 |
+
&& ! empty( $imagedata['sizes'][ $size ]['height_query'] ) ) {
|
| 440 |
+
if ( $imagedata['sizes'][ $size ]['width_query'] == $allSizes[ $size ]['width']
|
| 441 |
+
&& $imagedata['sizes'][ $size ]['height_query'] == $allSizes[ $size ]['height'] ) {
|
| 442 |
+
return false;
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
// Resize the image
|
| 449 |
+
$resized = image_make_intermediate_size(
|
| 450 |
+
get_attached_file( $id ),
|
| 451 |
+
$allSizes[ $size ]['width'],
|
| 452 |
+
$allSizes[ $size ]['height'],
|
| 453 |
+
$allSizes[ $size ]['crop']
|
| 454 |
+
);
|
| 455 |
+
|
| 456 |
+
// Resize somehow failed
|
| 457 |
+
if ( ! $resized ) {
|
| 458 |
+
return false;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
// Save the new size in WP
|
| 462 |
+
$imagedata['sizes'][ $size ] = $resized;
|
| 463 |
+
|
| 464 |
+
// Save some additional info so that we'll know next time whether we've resized this before
|
| 465 |
+
$imagedata['sizes'][ $size ]['width_query'] = $allSizes[ $size ]['width'];
|
| 466 |
+
$imagedata['sizes'][ $size ]['height_query'] = $allSizes[ $size ]['height'];
|
| 467 |
+
|
| 468 |
+
wp_update_attachment_metadata( $id, $imagedata );
|
| 469 |
+
|
| 470 |
+
// Serve the resized image
|
| 471 |
+
$att_url = wp_get_attachment_url( $id );
|
| 472 |
+
return array( dirname( $att_url ) . '/' . $resized['file'], $resized['width'], $resized['height'], true );
|
| 473 |
+
|
| 474 |
+
|
| 475 |
+
// If the size given is a custom array size
|
| 476 |
+
} else if ( is_array( $size ) ) {
|
| 477 |
+
$imagePath = get_attached_file( $id );
|
| 478 |
+
|
| 479 |
+
// This would be the path of our resized image if the dimensions existed
|
| 480 |
+
$imageExt = pathinfo( $imagePath, PATHINFO_EXTENSION );
|
| 481 |
+
$imagePath = preg_replace( '/^(.*)\.' . $imageExt . '$/', sprintf( '$1-%sx%s.%s', $size[0], $size[1], $imageExt ) , $imagePath );
|
| 482 |
+
|
| 483 |
+
$att_url = wp_get_attachment_url( $id );
|
| 484 |
+
|
| 485 |
+
// If it already exists, serve it
|
| 486 |
+
if ( file_exists( $imagePath ) ) {
|
| 487 |
+
return array( dirname( $att_url ) . '/' . basename( $imagePath ), $size[0], $size[1], true );
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
// If not, resize the image...
|
| 491 |
+
$resized = image_make_intermediate_size(
|
| 492 |
+
get_attached_file( $id ),
|
| 493 |
+
$size[0],
|
| 494 |
+
$size[1],
|
| 495 |
+
true
|
| 496 |
+
);
|
| 497 |
+
|
| 498 |
+
// Get attachment meta so we can add new size
|
| 499 |
+
$imagedata = wp_get_attachment_metadata( $id );
|
| 500 |
+
|
| 501 |
+
// Save the new size in WP so that it can also perform actions on it
|
| 502 |
+
$imagedata['sizes'][ $size[0] . 'x' . $size[1] ] = $resized;
|
| 503 |
+
wp_update_attachment_metadata( $id, $imagedata );
|
| 504 |
+
|
| 505 |
+
// Resize somehow failed
|
| 506 |
+
if ( ! $resized ) {
|
| 507 |
+
return false;
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
// Then serve it
|
| 511 |
+
return array( dirname( $att_url ) . '/' . $resized['file'], $resized['width'], $resized['height'], true );
|
| 512 |
+
}
|
| 513 |
+
|
| 514 |
+
return false;
|
| 515 |
+
}
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
}
|
screenshot-2.png
CHANGED
|
Binary file
|
script.js
CHANGED
|
@@ -7,7 +7,12 @@ jQuery(document).ready(function ($) {
|
|
| 7 |
var err_arr = [];
|
| 8 |
var errors_obj = $('#rta .errors');
|
| 9 |
var pbar = $("#rta #progressbar");
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
// if the progressbar id exists
|
| 12 |
if (pbar[0]) {
|
| 13 |
// set the initial value to 0
|
|
@@ -16,6 +21,7 @@ jQuery(document).ready(function ($) {
|
|
| 16 |
});
|
| 17 |
}
|
| 18 |
var rta_butt = $('.button.RTA');
|
|
|
|
| 19 |
|
| 20 |
var period = $('#rta_period');
|
| 21 |
var fromTo = $('.fromTo');
|
|
@@ -92,20 +98,16 @@ jQuery(document).ready(function ($) {
|
|
| 92 |
|
| 93 |
//var err_arr = new Array();
|
| 94 |
//json response
|
| 95 |
-
console.log(response);
|
| 96 |
var json = JSON.parse(response);
|
| 97 |
-
|
| 98 |
// console.log(json);
|
| 99 |
var startTime = json.startTime;
|
| 100 |
var offset = 0;
|
| 101 |
var tCount = 0;
|
| 102 |
-
|
| 103 |
var rta_total = $('#rta .info .total');
|
| 104 |
var type = json.type;
|
| 105 |
|
| 106 |
switch (type) {
|
| 107 |
case 'general':
|
| 108 |
-
|
| 109 |
var period = $('#rta_period');
|
| 110 |
var rta_total = $('#rta .info .total');
|
| 111 |
var rta_processed = $('#rta .info .processed');
|
|
@@ -190,6 +192,21 @@ jQuery(document).ready(function ($) {
|
|
| 190 |
}
|
| 191 |
});
|
| 192 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
// Append only unique array values
|
| 194 |
function unique_arr_append(val) {
|
| 195 |
var unique = true;
|
|
@@ -214,4 +231,4 @@ jQuery(document).ready(function ($) {
|
|
| 214 |
|
| 215 |
}
|
| 216 |
}
|
| 217 |
-
});
|
| 7 |
var err_arr = [];
|
| 8 |
var errors_obj = $('#rta .errors');
|
| 9 |
var pbar = $("#rta #progressbar");
|
| 10 |
+
var rtaOtf = $('.rtaOtf');
|
| 11 |
+
if(rtaOtf[0]){
|
| 12 |
+
rtaOtf.click(function(){
|
| 13 |
+
otfAjaxRequest($(this).attr('checked'));
|
| 14 |
+
});
|
| 15 |
+
}
|
| 16 |
// if the progressbar id exists
|
| 17 |
if (pbar[0]) {
|
| 18 |
// set the initial value to 0
|
| 21 |
});
|
| 22 |
}
|
| 23 |
var rta_butt = $('.button.RTA');
|
| 24 |
+
var rtaOtf = $('.rtaOtf');
|
| 25 |
|
| 26 |
var period = $('#rta_period');
|
| 27 |
var fromTo = $('.fromTo');
|
| 98 |
|
| 99 |
//var err_arr = new Array();
|
| 100 |
//json response
|
|
|
|
| 101 |
var json = JSON.parse(response);
|
|
|
|
| 102 |
// console.log(json);
|
| 103 |
var startTime = json.startTime;
|
| 104 |
var offset = 0;
|
| 105 |
var tCount = 0;
|
|
|
|
| 106 |
var rta_total = $('#rta .info .total');
|
| 107 |
var type = json.type;
|
| 108 |
|
| 109 |
switch (type) {
|
| 110 |
case 'general':
|
|
|
|
| 111 |
var period = $('#rta_period');
|
| 112 |
var rta_total = $('#rta .info .total');
|
| 113 |
var rta_processed = $('#rta .info .processed');
|
| 192 |
}
|
| 193 |
});
|
| 194 |
}
|
| 195 |
+
//OTF ajax call
|
| 196 |
+
function otfAjaxRequest(tempValue) {
|
| 197 |
+
|
| 198 |
+
//tha ajax data
|
| 199 |
+
var data = {
|
| 200 |
+
'action': 'rtaOtfAjax',
|
| 201 |
+
'tempValue': tempValue,
|
| 202 |
+
'otfVal': 1
|
| 203 |
+
};
|
| 204 |
+
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
| 205 |
+
$.post(ajaxurl, data, function (response) {
|
| 206 |
+
console.log(response);
|
| 207 |
+
|
| 208 |
+
});
|
| 209 |
+
}
|
| 210 |
// Append only unique array values
|
| 211 |
function unique_arr_append(val) {
|
| 212 |
var unique = true;
|
| 231 |
|
| 232 |
}
|
| 233 |
}
|
| 234 |
+
});
|
style.css
CHANGED
|
@@ -52,4 +52,8 @@
|
|
| 52 |
}#rta .wrap{
|
| 53 |
float:left;
|
| 54 |
width:46%;
|
| 55 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}#rta .wrap{
|
| 53 |
float:left;
|
| 54 |
width:46%;
|
| 55 |
+
}
|
| 56 |
+
#rta .otf{
|
| 57 |
+
display: inline-block;
|
| 58 |
+
margin:20px 0 0 0;
|
| 59 |
+
}
|
