PageRenderTime 30ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/post-thumbnail-editor/php/functions.php

https://github.com/pica-design/nextstepmaine
PHP | 697 lines | 505 code | 72 blank | 120 comment | 79 complexity | d11fa2a4f9b8b057be4eb3e3a7416943 MD5 | raw file
  1<?php
  2/*
  3 * TODO: add helper functions to get various links to different functions
  4 */
  5
  6require_once(PTE_PLUGINPATH . 'php/log.php');
  7
  8function pte_require_json() {
  9	if ( function_exists( 'ob_start' ) ){
 10		ob_start();
 11	}
 12}
 13
 14/*
 15 * This is used to output JSON
 16 * - Calling this should return all the way up the chain...
 17 */
 18function pte_json_encode($mixed = null){
 19	$logger = PteLogger::singleton();
 20	$options = pte_get_options();
 21	$logs['error'] = array();
 22	$logs['log'] = array();
 23
 24	// If a buffer was started this will check for any residual output
 25	// and add to the existing errors.
 26	if ( function_exists( 'ob_get_flush' ) ){
 27		$buffer = ob_get_clean();
 28		if ( isset( $buffer ) && strlen( $buffer ) > 0 ){
 29			$logger->warn( "Buffered output: {$buffer}" );
 30		}
 31	}
 32
 33	if ( $logger->get_log_count( PteLogMessage::$ERROR ) > 0 
 34		|| $logger->get_log_count( PteLogMessage::$WARN ) > 0 )
 35	{
 36		$logs['error'] = $logger->get_logs( PteLogMessage::$ERROR | PteLogMessage::$WARN );
 37	}
 38	//if ( $logger->get_log_count( PteLogMessage::$WARN ) > 0 ){
 39	//   $logs['warn'] = $logger->get_logs( PteLogMessage::$WARN );
 40	//}
 41	if ( $options['pte_debug'] ){
 42		$logs['log'] = $logger->get_logs();
 43	}
 44
 45	if ( ! function_exists('json_encode') ){
 46		$logs['error'][] = "json_encode not available, upgrade your php";
 47		$messages = implode( "\r\n", $logs['error'] );
 48		die("{\"error\":\"{$messages}\"}");
 49	}
 50
 51	if ( ! isset($mixed) ){
 52		$mixed = array();
 53	}
 54	else if ( ! is_array( $mixed ) ){
 55		$mixed = array('noarray' => $mixed);
 56	}
 57
 58
 59	if ( count( $logs['error'] )+count( $logs['log'] ) > 0 ){
 60		$mixed = array_merge_recursive( $mixed, $logs );
 61	}
 62
 63	print( json_encode($mixed) );
 64	return true;
 65}
 66
 67/*
 68 * pte_json_error - Calling this should return all the way up the chain...
 69 */
 70function pte_json_error( $error ){
 71	$logger = PteLogger::singleton();
 72	$logger->error( $error );
 73	return pte_json_encode();
 74}
 75
 76/*
 77 * pte_filter_sizes
 78 *
 79 * This is used by the get_sizes functions to determine which sizes to
 80 * reduce to
 81 */
 82function pte_filter_sizes( $element ){
 83	global $pte_sizes;
 84	$options = pte_get_options();
 85	// Check if the element is in the pte_sizes array
 86	if ( ( is_array( $pte_sizes ) && !in_array( $element, $pte_sizes ) )
 87		or ( in_array( $element, $options['pte_hidden_sizes'] ) )
 88	){
 89		return false;
 90	}
 91	return true;
 92}
 93
 94/*
 95 * pte_get_alternate_sizes
 96 *
 97 * Creates an array of each thumbnail size and the corresponding data:
 98 *   * height
 99 *   * width
100 *   * crop boolean
101 *
102 * Thanks to the ajax_thumbnail_rebuild plugin
103 */
104function pte_get_alternate_sizes($filter=true){
105	//Put in some code to check if it's already been called...
106	global $_wp_additional_image_sizes, $pte_gas;
107	if ( !isset($pte_gas) ){
108		$pte_gas = array();
109		$sizes = array();
110
111		// Some times we don't want the filter to run (in admin for example)
112		if ($filter){
113			$sizes = array_filter( get_intermediate_image_sizes(), 'pte_filter_sizes' );
114		}
115		else{
116			$sizes = get_intermediate_image_sizes();
117		}
118
119		foreach ($sizes as $s){
120			if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) // For theme-added sizes
121				$width = intval( $_wp_additional_image_sizes[$s]['width'] );
122			else                                                     // For default sizes set in options
123				$width = get_option( "{$s}_size_w" );
124
125			if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) // For theme-added sizes
126				$height = intval( $_wp_additional_image_sizes[$s]['height'] );
127			else                                                      // For default sizes set in options
128				$height = get_option( "{$s}_size_h" );
129
130			if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) // For theme-added sizes
131				$crop = intval( $_wp_additional_image_sizes[$s]['crop'] );
132			else                                                      // For default sizes set in options
133				$crop = get_option( "{$s}_crop" );
134
135			$pte_gas[$s] = array(
136				'width'  => $width,
137				'height' => $height,
138				'crop'   => $crop
139			);
140		}
141	}
142	return $pte_gas;
143}
144
145/*
146 * pte_get_image_data
147 *
148 * Gets specific data for a given image (id) at a given size (size)
149 * Optionally can return the JSON value or PHP array
150 */
151function pte_get_image_data( $id, $size, $size_data ){
152	$logger = PteLogger::singleton();
153
154	$fullsizepath = get_attached_file( $id );
155	$path_information = image_get_intermediate_size($id, $size);
156
157	if ( $path_information && 
158		@file_exists( dirname( $fullsizepath ) . DIRECTORY_SEPARATOR . $path_information['file'] )
159	){
160		return $path_information;
161	}
162
163	// We don't really care how it gets generated, just that it is...
164	// see ajax-thumbnail-rebuild plugin for inspiration
165	if ( FALSE !== $fullsizepath && @file_exists($fullsizepath) ) {
166		// Create the image and update the wordpress metadata
167		$resized = image_make_intermediate_size( $fullsizepath, 
168			$size_data['width'], 
169			$size_data['height'],
170			$size_data['crop']
171		);
172		if ($resized){
173			$metadata = wp_get_attachment_metadata($id, true);
174			$metadata['sizes'][$size] = $resized;
175			wp_update_attachment_metadata( $id, $metadata);
176		}
177	}
178
179	// Finish how we started
180	$path_information = image_get_intermediate_size($id, $size);
181	if ($path_information){
182		return $path_information;
183	}
184	else {
185		$logger->warn( "Couldn't find or generate metadata for image: {$id}-{$size}" );
186	}
187	return false;
188}
189
190/*
191 * pte_get_all_alternate_size_information
192 *
193 * Gets all pertinent data describing the alternate sizes
194 */
195function pte_get_all_alternate_size_information( $id ){
196	$sizes = pte_get_alternate_sizes();
197	foreach ( $sizes as $size => &$info ){
198		if ( $info['crop'] )
199			$info['crop'] = true;
200		else
201			$info['crop'] = false;
202		$info['current'] = pte_get_image_data( $id, $size, $info );
203	}
204	return $sizes;
205}
206
207/*
208 * pte_body
209 *
210 * Returns the base HTML needed to display and transform the inages
211 *
212 * Requires post id as $_GET['id']
213 */
214function pte_body( $id ){
215	ob_start();
216
217	$logger = PteLogger::singleton();
218	$options = pte_get_options();
219
220	// Get the information needed for image preview 
221	//   (See wp-admin/includes/image-edit.php)
222	$nonce = wp_create_nonce("image_editor-$id");
223	$meta = wp_get_attachment_metadata($id, true);
224
225	if ( is_array($meta) && isset( $meta['width'] ) ){
226		$big = max( $meta['width'], $meta['height'] );
227	}
228	else {
229		$logger->error( 
230			sprintf( __( "Invalid meta data for POST #%d: %s" )
231				, $id
232				, print_r( $meta, true ) 
233			) 
234		);
235		$logger->error( __( "Please contact support", PTE_DOMAIN ) );
236	}
237
238	PteLogger::debug( "PTE-VERSION: " . PTE_VERSION .
239		"\nUSER-AGENT:  " . $_SERVER['HTTP_USER_AGENT'] .
240		"\nWORDPRESS:   " . $GLOBALS['wp_version'] );
241
242	$script_url = PTE_PLUGINURL . 'php/load-scripts.php?load=jquery,imgareaselect,jquery-json,pte';
243	$style_url = PTE_PLUGINURL . 'php/load-styles.php?load=imgareaselect,pte';
244	if ( $options['pte_debug'] ){
245		$style_url .= "&d=1";
246		$script_url .= "&d=1";
247	}
248
249	// Generate an image and put into the ptetmp directory
250	if (false === $editor_image = pte_generate_working_image($id)) {
251		$editor_image = sprintf("%s?action=pte_imgedit_preview&amp;_ajax_nonce=%s&amp;postid=%d&amp;rand=%d",
252			admin_url('admin-ajax.php'),
253			$nonce,
254			$id,
255			rand(1,99999)
256		);
257	}
258
259	require( PTE_PLUGINPATH . "html/pte.php" );
260	return ob_get_clean();
261}
262
263function pte_generate_working_image($id)
264{
265	$options = pte_get_options();
266	if (false == $options['pte_imgedit_disk'])
267		return false;
268
269	// SETS PTE_TMP_DIR and PTE_TMP_URL
270	extract( pte_tmp_dir() );
271
272	$original_file = _load_image_to_edit_path( $id );
273	$size = $options['pte_imgedit_max_size'];
274
275	$editor = wp_get_image_editor( $original_file );
276	$finfo    = pathinfo( $original_file );
277	$basename = sprintf("%s-%s.%s", $id, $size, $finfo['extension']);
278	$file     = sprintf("%s%s", $PTE_TMP_DIR, $basename );
279	$url      = sprintf("%s%s", $PTE_TMP_URL, $basename );
280
281	if ( file_exists( $file ) )
282		return $url;
283
284	PteLogger::debug("\nGENERATING WORKING IMAGE:\n  [{$file}]\n  [{$url}]");
285
286	// Resize the image and check the results
287	$results = $editor->resize($size,$size);
288	if ( is_wp_error( $results ) ) {
289		PteLogger::error( $results );
290		return false;
291	}
292
293	// Save the image
294	if ( is_wp_error( $editor->save( $file ) ) ) {
295		PteLogger::error( "Unable to save the generated image falling back to ajax-ed image" );
296		return false;
297	}
298	return $url;
299}
300
301function pte_check_int( $int ){
302	$logger = PteLogger::singleton();
303	if (! is_numeric( $int ) ){
304		$logger->warn( "PARAM not numeric: '{$int}'" );
305		return false;
306	}
307	return $int;
308}
309
310/*
311 * Get Destination width & height
312 * ==============================
313 * When the crop isn't set:
314 *    the size information for the biggest dimension is accurate, 
315 *    but the other dimension is wrong
316 */
317function pte_get_width_height( $size_information, $w, $h ){
318	$logger = PteLogger::singleton();
319	if ( $size_information['crop'] == 1 ){
320		$logger->debug("GETwidthheightCROPPED");
321		$dst_w = $size_information['width'];
322		$dst_h = $size_information['height'];
323	}
324	// Crop isn't set so the height / width should be based on the smallest side
325	// or check if the post_thumbnail has a 0 for a side.
326	else {
327		$use_width = false;
328		if ( $w > $h ) $use_width = true;
329		if ( $size_information['height'] == 0 ) $use_width = true;
330		// This case appeared because theme twentytwelve made a thumbnail 'post-thumbnail'
331		// with 624x9999, no crop... The images it created were huge...
332		if ( $size_information['width'] < $size_information['height'] ) $use_width = true;
333		if ( $size_information['width'] == 0 ) $use_width = false;
334
335		$logger->debug("GETwidthheightPARAMS\nWIDTH: $w\nHEIGHT: $h\nUSE_WIDTH: " . print_r($use_width, true));
336		if ( $use_width ){
337			$dst_w = $size_information['width'];
338			$dst_h = round( ($dst_w/$w) * $h, 0);
339		}
340		else {
341			$dst_h = $size_information['height'];
342			$dst_w = round( ($dst_h/$h) * $w, 0);
343		}
344	}
345
346	// Sanity Check
347	if ( $dst_h == 0 || $dst_w == 0 ){
348		$logger->error( "Invalid derived dimensions: ${dst_w} x ${dst_h}" );
349	}
350	return compact( "dst_w", "dst_h" );
351}
352
353/*
354 * ================
355 * Get the filename
356 * ================
357 * See image_resize function in wp-includes/media.php to follow the same conventions
358 *  - Check if the file exists
359 *
360 * Using the cache buster is a good idea because:
361 *  * we shouldn't overwrite old images that have been placed into posts
362 *  * keeps problems from occuring when I try to debug and people think picture
363 *    didn't save, when it's just a caching issue
364 */
365function pte_generate_filename( $file, $w, $h ){
366	$options      = pte_get_options();
367	$info         = pathinfo( $file );
368	$ext          = $info['extension'];
369	$name         = wp_basename( $file, ".$ext" );
370	$suffix       = "{$w}x{$h}";
371
372	if ( $options['cache_buster'] ){
373		$cache_buster = time();
374		return sprintf( "%s-%s-%s.%s",
375			$name,
376			$suffix,
377			$cache_buster,
378			$ext );
379	}
380	//print_r( compact( "file", "info", "ext", "name", "suffix" ) );
381	return "{$name}-{$suffix}.{$ext}";
382}
383
384
385/*
386 * resize_images
387 *
388 * Take an array of sizes along with the associated resize data (w/h/x/y) 
389 * and save the images to a temp directory
390 * 
391 * OUTPUT: JSON object 'size: url'
392 */
393function pte_resize_images(){
394	$logger = PteLogger::singleton();
395	global $pte_sizes;
396
397	// Require JSON output
398	pte_require_json();
399
400	$id = intval( $_GET['id'] );
401	$w  = pte_check_int( $_GET['w'] );
402	$h  = pte_check_int( $_GET['h'] );
403	$x  = pte_check_int( $_GET['x'] );
404	$y  = pte_check_int( $_GET['y'] );
405	$save = isset( $_GET['save'] ) && ( strtolower( $_GET['save'] ) === "true" );
406
407	if ( pte_check_id( $id ) === false
408		|| $w === false
409		|| $h === false
410		|| $x === false
411		|| $y === false
412	) {
413		return pte_json_error( "ResizeImages initialization failed: '{$id}-{$w}-{$h}-{$x}-{$y}'" );
414	}
415
416	// Get the sizes to process
417	$pte_sizes      = $_GET['pte-sizes'];
418	if ( !is_array( $pte_sizes ) ){
419		$logger->debug( "Converting pte_sizes to array" );
420		$pte_sizes = explode( ",", $pte_sizes );
421	}
422	$sizes          = pte_get_all_alternate_size_information( $id );
423
424	// The following information is common to all sizes
425	// *** common-info
426	$original_file  = _load_image_to_edit_path( $id );
427	$original_size  = @getimagesize( $original_file );
428
429	// SETS PTE_TMP_DIR and PTE_TMP_URL
430	extract( pte_tmp_dir() );
431	$thumbnails     = array();
432
433	if ( !$original_size ){
434		return pte_json_error("Could not read image size");
435	}
436
437	$logger->debug( "BASE FILE DIMENSIONS/INFO: " . print_r( $original_size, true ) );
438	list( $orig_w, $orig_h, $orig_type ) = $original_size;
439	// *** End common-info
440
441	// So this never interrupts the jpeg_quality anywhere else
442	add_filter('jpeg_quality', 'pte_get_jpeg_quality');
443	add_filter('wp_editor_set_quality', 'pte_get_jpeg_quality');
444
445	foreach ( $sizes as $size => $data ){
446		// Get all the data needed to run image_create
447		//
448		//	$dst_w, $dst_h 
449		extract( pte_get_width_height( $data, $w, $h ) );
450		$logger->debug( "WIDTHxHEIGHT: $dst_w x $dst_h" );
451
452		// Set the directory
453		$basename = pte_generate_filename( $original_file, $dst_w, $dst_h );
454		// Set the file and URL's - defines set in pte_ajax
455		$tmpfile  = "{$PTE_TMP_DIR}{$id}" . DIRECTORY_SEPARATOR . "{$basename}";
456
457		// === CREATE IMAGE ===================
458		// This function is in wp-includes/media.php
459		// We've added a filter to return our own editor which extends the wordpress one.
460		add_filter( 'wp_image_editors', 'pte_image_editors' );
461		$editor = wp_get_image_editor( $original_file );
462		if ( is_a( $editor, "WP_Image_Editor_Imagick" ) ) $logger->debug( "EDITOR: ImageMagick" );
463		if ( is_a( $editor, "WP_Image_Editor_GD" ) ) $logger->debug( "EDITOR: GD" );
464		$crop_results = $editor->crop($x, $y, $w, $h, $dst_w, $dst_h); 
465
466		if ( is_wp_error( $crop_results ) ){
467			$logger->error( "Error creating image: {$size}" );
468			continue;
469		}
470
471		// The directory containing the original file may no longer exist when
472		// using a replication plugin.
473		wp_mkdir_p( dirname( $tmpfile ) );
474
475		$tmpfile = dirname( $tmpfile ) . '/' . wp_unique_filename( dirname( $tmpfile ), basename( $tmpfile ) );
476		$tmpurl   = "{$PTE_TMP_URL}{$id}/" . basename( $tmpfile );
477
478		if ( is_wp_error( $editor->save( $tmpfile ) ) ){
479			$logger->error( "Error writing image: {$size} to '{$tmpfile}'" );
480			continue;
481		}
482		// === END CREATE IMAGE ===============
483
484		// URL: wp_upload_dir => base_url/subdir + /basename of $tmpfile
485		// This is for the output
486		$thumbnails[$size]['url'] = $tmpurl;
487		$thumbnails[$size]['file'] = basename( $tmpfile );
488	}
489
490	// Did you process anything?
491	if ( count( $thumbnails ) < 1 ){
492		return pte_json_error("No images processed");
493	}
494
495	$ptenonce = wp_create_nonce( "pte-{$id}" );
496
497	// If save -- return pte_confirm_images
498	if ( $save ){
499		function create_pte_confirm($thumbnail){
500			return $thumbnail['file'];
501		}
502		$_REQUEST['pte-nonce'] = $ptenonce;
503		$_GET['pte-confirm'] = array_map('create_pte_confirm', $thumbnails);
504		$logger->debug( "CONFIRM:" );
505		$logger->debug( print_r( $_GET, true ) );
506		return pte_confirm_images(true);
507	}
508
509	return pte_json_encode( array( 
510		'thumbnails'        => $thumbnails,
511		'pte-nonce'         => $ptenonce,
512		'pte-delete-nonce'  => wp_create_nonce( "pte-delete-{$id}" )
513	) );
514}
515
516function pte_image_editors( $editor_array ){
517	require_once( PTE_PLUGINPATH . 'php/class-pte-image-editor-gd.php' );
518	require_once( PTE_PLUGINPATH . 'php/class-pte-image-editor-imagick.php' );
519	array_unshift( $editor_array, 'PTE_Image_Editor_Imagick', 'PTE_Image_Editor_GD' );
520	return $editor_array;
521}
522
523/*
524 * pte_confirm_images
525 *
526 * Take an array of image sizes, an ID and a nonce and then move the confirmed images
527 * to the official position and update metadata...
528 *
529 * Clean up and return error/success information...
530 */
531function pte_confirm_images($immediate = false){
532	global $pte_sizes;
533	$logger = PteLogger::singleton();
534
535	// Require JSON output
536	pte_require_json();
537
538	$id = (int) $_GET['id'];
539	if ( pte_check_id( $id ) === false ){
540		return pte_json_error( "ID invalid: {$id}" );
541	}
542
543	// Check nonce
544	if ( !check_ajax_referer( "pte-{$id}", 'pte-nonce', false ) ){
545		return pte_json_error( "CSRF Check failed" );
546	}
547
548	// Get the available sizes
549	if ( is_array( $_GET['pte-confirm'] ) ){
550		$pte_sizes = array_keys( $_GET['pte-confirm'] );
551		$sizes = pte_get_all_alternate_size_information( $id );
552		$logger->debug( "pte_get_all_alternate_size_information returned: "
553			. print_r( $sizes, true ) );
554	}
555	else {
556		return pte_json_error( "Invalid Parameters: can't find sizes" );
557	}
558	// === END INITIALIZATION ================================
559
560	// Foreach size:
561	//    Move good image
562	//    Update metadata
563	//    Delete old image
564	// Remove PTE/$id directory
565
566	// SETS PTE_TMP_DIR and PTE_TMP_URL
567	extract( pte_tmp_dir() );
568
569	foreach ( $sizes as $size => $data ){
570		// Make sure we're only moving our files
571		$good_file = $PTE_TMP_DIR
572			. $id . DIRECTORY_SEPARATOR
573			. basename( $_GET['pte-confirm'][$size] );
574
575		if ( ! ( isset( $good_file ) && file_exists( $good_file ) ) ){
576			return pte_json_error("FILE is invalid: {$good_file}");
577		}
578
579		$dir = dirname( get_attached_file( $id ) );
580		$new_file = $dir
581			. DIRECTORY_SEPARATOR
582			. basename( $good_file );
583		if ( isset( $data['current']['file'] ) ){
584			$old_file = $dir
585				. DIRECTORY_SEPARATOR
586				. $data['current']['file'];
587		}
588
589		// Delete/unlink old file
590		if ( isset( $old_file ) )
591		{
592			$logger->debug( "Deleting old thumbnail: {$old_file}" );
593			@unlink( apply_filters( 'wp_delete_file', $old_file ) );
594		}
595
596		// Move good image
597		$logger->debug( "Moving '{$good_file}' to '{$new_file}'" );
598		wp_mkdir_p( dirname( $new_file ) );
599		rename( $good_file, $new_file );
600
601		// Update metadata
602		$image_dimensions  = @getimagesize( $new_file );
603		list( $w, $h, $type ) = $image_dimensions;
604		//print("IMAGE DIMENSIONS...");
605		//print_r( $image_dimensions );
606		$metadata = wp_get_attachment_metadata( $id, true );
607		$metadata['sizes'][$size] = array( 
608			'file' => basename( $new_file ),
609			'width' => $w,
610			'height' => $h 
611		);
612		$logger->debug( "Updating '{$size}' metadata: " . print_r( $metadata['sizes'][$size], true ) );
613		wp_update_attachment_metadata( $id, $metadata);
614	}
615	// Delete tmpdir
616	//pte_rmdir( $PTE_TMP_DIR );
617	return pte_json_encode( array( 
618		'thumbnails' => pte_get_all_alternate_size_information( $id ),
619		'immediate' => $immediate
620	) );
621}
622
623function pte_rmdir( $dir ){
624	$logger = PteLogger::singleton();
625	if ( !is_dir( $dir ) || !preg_match( "/ptetmp/", $dir ) ){
626		$logger->warn("Tried to delete invalid directory: {$dir}");
627		return;
628	}
629	foreach ( scandir( $dir ) as $file ){
630		if ( "." == $file || ".." == $file ) continue;
631		$full_path_to_file = $dir . DIRECTORY_SEPARATOR . $file;
632		$logger->debug("DELETING: {$full_path_to_file}");
633		unlink( $full_path_to_file );
634	}
635	rmdir( $dir );
636}
637
638function pte_delete_images()
639{
640	// Require JSON output
641	pte_require_json();
642
643	$id = (int) $_GET['id'];
644	if ( pte_check_id( $id ) === false ){
645		return pte_json_error( "ID invalid: {$id}" );
646	}
647	// Check nonce
648	if ( !check_ajax_referer( "pte-delete-{$id}", 'pte-nonce', false ) ){
649		return pte_json_error( "CSRF Check failed" );
650	}
651
652	// SETS PTE_TMP_DIR and PTE_TMP_URL
653	extract( pte_tmp_dir() );
654	$PTE_TMP_DIR = $PTE_TMP_DIR . $id . DIRECTORY_SEPARATOR;
655
656	// Delete tmpdir
657	PteLogger::debug( "Deleting [{$PTE_TMP_DIR}]" );
658	pte_rmdir( $PTE_TMP_DIR );
659	return pte_json_encode( array( "success" => "Yay!" ) );
660}
661
662function pte_get_jpeg_quality($quality){
663	$options = pte_get_options();
664	$jpeg_compression = $options['pte_jpeg_compression'];
665	if ( isset( $_GET['pte-jpeg-compression'] ) ) {
666		$tmp_jpeg = intval( $_GET['pte-jpeg-compression'] );
667		if ( 0 <= $tmp_jpeg && $tmp_jpeg <= 100 ){
668			$jpeg_compression = $tmp_jpeg;
669		}
670	}
671	PteLogger::debug( "COMPRESSION: " . $jpeg_compression );
672	return $jpeg_compression;
673}
674
675/**
676 * Sending output to an iframe
677 */
678function pte_init_iframe() {
679	global $title, $pte_iframe;
680	$pte_iframe = true;
681
682	// Provide the base framework/HTML for the editor.
683	require_once( ABSPATH . WPINC . '/script-loader.php' );
684	// Check the input parameters and create the HTML
685	pte_edit_setup();
686
687	print( "<!DOCTYPE html>\n<html><head><title>${title}</title>\n" );
688
689	print_head_scripts();
690	print_admin_styles();
691
692	print( '</head><body class="wp-core-ui pte-iframe">' );
693	// Simply echo the created HTML
694	pte_edit_page();
695	print_footer_scripts();
696	print( '</body></html>' );
697}