Changeset 1385454
- Timestamp:
- 04/03/2016 06:13:38 AM (10 years ago)
- Location:
- wp-booklet/trunk
- Files:
-
- 3 added
- 8 edited
-
assets/bin (added)
-
assets/bin/pdfinfowin.exe (added)
-
assets/js/wpbooklet-editor.js (modified) (4 diffs)
-
classes/class-wp-booklet2-booklet-editor.php (modified) (3 diffs)
-
classes/class-wp-booklet2-command.php (modified) (2 diffs)
-
classes/class-wp-booklet2-pdf.php (modified) (6 diffs)
-
classes/class-wp-booklet2-pdfinfo.php (added)
-
classes/class-wp-booklet2-settings-page.php (modified) (4 diffs)
-
readme.txt (modified) (4 diffs)
-
themes/admin/default/settings-page.php (modified) (1 diff)
-
wp-booklet.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-booklet/trunk/assets/js/wpbooklet-editor.js
r1289197 r1385454 96 96 e.preventDefault(); 97 97 98 if ( pdfLimit == 'on' ) {99 if ( !confirm("This feature only adds the first 10 pages of the PDF file. Continue?") ) { return; }100 }101 102 if ( pdf_uploader ) {103 pdf_uploader.open();104 return;105 }106 107 98 pdf_uploader.open(); 108 99 … … 110 101 111 102 function showPreloader(text) { 112 jQuery(".wp-booklet-preloader-overlay .wp-booklet-preloader-note").html(text);103 updatePreloader(text); 113 104 jQuery(".wp-booklet-preloader-overlay").show().animate({opacity:0.8},200); 114 105 } 106 function updatePreloader(text) { 107 jQuery(".wp-booklet-preloader-overlay .wp-booklet-preloader-note").html(text); 108 } 115 109 function hidePreloader() { 116 110 jQuery(".wp-booklet-preloader-overlay").animate({opacity:0},200).hide(); … … 128 122 jQuery.post(ajaxurl,data,function(verification) { 129 123 if ( verification.wpb_success ) { 130 hidePreloader();131 124 showPreloader('Processing PDF. Please keep this window open.'); 132 125 var data = { … … 135 128 'action':'process_pdf' 136 129 } 137 jQuery.post(ajaxurl,data,function(response) { 138 if ( response.wpb_success ) { 139 for( var ctr = 0; ctr < response.images.length; ctr++ ) { 140 jQuery(".wp-booklet-sortable").append(newPage); 141 var currPage = jQuery(".wp-booklet-sortable .wp-booklet-portlet").last(); 142 currPage.find('.wp-booklet-portlet-content-left').prepend('<img data-width='+response.images[ctr].width+' data-height='+response.images[ctr].height+' src='+response.images[ctr].src+' class="wp-booklet-img"/> '); 143 currPage.find('.wp-booklet-attachment-id').val(response.images[ctr].id); 144 currPage.find('.wp-booklet-image-upload').val('Replace image'); 145 currPage.find('.wp-booklet-page-placeholder').remove(); 130 var pageCount = verification.wpb_page_count; 131 var pageOffset = -1; 132 133 function processPage() { 134 135 pageOffset = pageOffset + 1; 136 data.pdf_offset = pageOffset; 137 138 updatePreloader('Processing page ' + (pageOffset + 1) + '/' + pageCount + '. Please keep this window open.'); 139 140 jQuery.post(ajaxurl,data,function(response) { 141 if ( response.wpb_success ) { 142 for( var ctr = 0; ctr < response.images.length; ctr++ ) { 143 jQuery(".wp-booklet-sortable").append(newPage); 144 var currPage = jQuery(".wp-booklet-sortable .wp-booklet-portlet").last(); 145 currPage.find('.wp-booklet-portlet-content-left').prepend('<img data-width='+response.images[ctr].width+' data-height='+response.images[ctr].height+' src='+response.images[ctr].src+' class="wp-booklet-img"/> '); 146 currPage.find('.wp-booklet-attachment-id').val(response.images[ctr].id); 147 currPage.find('.wp-booklet-image-upload').val('Replace image'); 148 currPage.find('.wp-booklet-page-placeholder').remove(); 149 } 150 151 setTimeout(processPage,500); 152 153 if (pageOffset == ( pageCount - 1 ) ) { 154 hidePreloader(); 155 } 156 146 157 } 147 } 148 else { 149 alert(response.wpb_message); 150 } 151 hidePreloader(); 152 clearTimeout(termination); 153 },'json'); 154 155 /* Terminate script if it exceeds PHP timeout */ 156 var termination = setTimeout( function() { 157 hidePreloader(); 158 alert("PDF conversion FAILED because it exceeded allowed PHP execution time. Contact your server administrator for assistance."); 159 },(verification.max_execution_time * 1000)); 158 else { 159 alert(response.wpb_message); 160 hidePreloader(); 161 } 162 163 },'json'); 164 165 } 166 167 processPage(); 160 168 161 169 } -
wp-booklet/trunk/classes/class-wp-booklet2-booklet-editor.php
r1289197 r1385454 263 263 264 264 $pdf_id = $_POST['pdf_id']; 265 $pdf_offset = $_POST['pdf_offset']; 266 $pdf_limit = 1; 265 267 $pdf_path = get_attached_file( $pdf_id ); 266 268 … … 272 274 ); 273 275 274 $images = $pdf->get_pages_as_photos( );276 $images = $pdf->get_pages_as_photos($pdf_offset); 275 277 276 278 if ( $images ) { … … 301 303 try { 302 304 $pdf = new WP_Booklet2_PDF($pdf_path); 303 $result = array( 'wpb_success'=>true ); 305 $result = array( 306 'wpb_success'=>true, 307 'wpb_page_count'=>$pdf->get_pdf_page_count() 308 ); 304 309 } 305 310 catch(Exception $e) { 306 $result = array( 'wpb_success'=>false, 'wpb_message' => 'Please select a valid PDF file.' ); 311 $result = array ( 312 'wpb_success'=>false, 313 'wpb_message' => 'Please select a valid PDF file.' 314 ); 307 315 } 308 316 -
wp-booklet/trunk/classes/class-wp-booklet2-command.php
r1193008 r1385454 36 36 $existence = exec( $this->_command ." ". $this->_modifiers . " 2>&1", $output, $return_var ); 37 37 38 return !($return_var > 0 ); 38 return $this->_is_exit_code_valid($return_var); 39 } 40 41 /** 42 * Exit code is valid 43 * 44 * @param $code int - exit code 45 * 46 * @return bool 47 */ 48 protected function _is_exit_code_valid($code) { 49 $valid_codes = array( 0, 99 ); 50 return in_array( $code, $valid_codes ); 39 51 } 40 52 … … 48 60 exec( $this->_command . " " . $this->_modifiers . " 2>&1", $output, $return_var ); 49 61 50 if ( $ return_var === 0) {62 if ( $this->_is_exit_code_valid($return_var) ) { 51 63 $result['error'] = false; 52 64 $result['message'] = implode(" ",$output); 65 $result['output'] = $output; 53 66 } 54 67 else { -
wp-booklet/trunk/classes/class-wp-booklet2-pdf.php
r1211263 r1385454 25 25 * Get PDF page count 26 26 * 27 * return int27 * return mixed - int on success, false on failure 28 28 */ 29 29 protected function _get_pdf_page_count() { 30 30 31 $file = $this->_file; 31 $pdfinfo = new WP_Booklet2_PDFInfo($this->_file); 32 33 return $pdfinfo->get_pages(); 34 35 } 32 36 33 if(!file_exists($file))return null; 34 if (!$fp = @fopen($file,"r"))return null; 35 $pages=0; 36 while(!feof($fp)) { 37 $line = fgets($fp,255); 38 if (preg_match('/\/Count [0-9]+/', $line, $matches)){ 39 preg_match('/[0-9]+/',$matches[0], $matches2); 40 if ($pages<$matches2[0]) $pages=$matches2[0]; 41 } 42 } 43 fclose($fp); 44 return (int)$pages; 37 /** 38 * Get path 39 * 40 * return string 41 */ 42 function get_path() { 43 return $this->_file; 44 } 45 46 /** 47 * Return page count 48 * 49 * return int 50 */ 51 function get_pdf_page_count() { 52 53 return $this->_get_pdf_page_count(); 54 45 55 } 46 56 … … 74 84 $command = new WP_Booklet2_Command("convert", "-limit memory 32MiB -limit map 64MiB {$pdf} {$target}"); 75 85 $result = $command->run_command(); 76 77 if ( !$result['error'] ) { 86 87 $pdfinfo = new WP_Booklet2_PDFInfo($pdf); 88 89 if ( !$result['error'] && $pdfinfo->supports_environment() ) { 78 90 $file_exists = file_exists( $target ); 79 91 @unlink( $target ); … … 89 101 * Converts PDF images into Wordpress attachments 90 102 * 91 * @param $page_count int - number of pages to be converted into photos. Always starts at the first page of the PDF. 103 * @param $offset int - page number to start at. Defaults to first page. 104 * @param $limit int - number of pages to be converted into photos. Starts at offset. Defaults to 1 92 105 * 93 106 * @return mixed - array of attachments, false on error 94 107 */ 95 function get_pages_as_photos() { 96 108 function get_pages_as_photos($offset=0,$limit=1) { 109 110 //Set vars 97 111 $pdf_path = $this->_file; 98 112 $upload_dir = wp_upload_dir(); … … 100 114 $image_group = uniqid(); 101 115 $actual_page_count = $this->_get_pdf_page_count( $pdf_path ); 102 $attachment_page_count = ( get_option('wp-booklet-pdf-limit-status') == 'on' && $actual_page_count > 10 ) ? 10 : $actual_page_count; 103 $conversion_page_count = ( get_option('wp-booklet-pdf-limit-status') == 'on' && $actual_page_count > 10 ) ? "[0-9]" : ""; 116 117 //Identify start and end pages 118 $end_page = $offset + ( $limit - 1 ); 119 120 if ( $end_page == $offset ) { 121 $conversion_page_count = "[{$offset}]"; 122 } 123 else { 124 $conversion_page_count = "[{$offset}-{$end_page}]"; 125 } 104 126 105 127 //Check that upload directory is writable by server … … 109 131 110 132 //Use Imagemagick and Ghostscript to convert PDF pages into jpegs 111 $command = new WP_Booklet2_Command("convert", "-density 200 -verbose -limit memory 32MiB -limit map 64MiB{$pdf_path}{$conversion_page_count} {$upload_path}/{$image_group}.jpg");133 $command = new WP_Booklet2_Command("convert", "-density 200 -verbose {$pdf_path}{$conversion_page_count} {$upload_path}/{$image_group}.jpg"); 112 134 $operation = $command->run_command(); 113 135 … … 119 141 $images = array(); 120 142 121 for ( $ctr = 0; $ctr < $attachment_page_count; $ctr++ ) { 143 for ( $ctr = 0; $ctr < $limit; $ctr++ ) { 144 145 //If more than 1 page is converted, append a number 146 if ( $limit > 1 ) { 147 $filename = $upload_path."/".$image_group."-".$ctr.".jpg"; 148 } 149 else { 150 $filename = $upload_path."/".$image_group.".jpg"; 151 } 122 152 123 153 //Prepare attachment 124 $filename = $upload_path."/".$image_group."-".$ctr.".jpg";125 154 $wp_filetype = wp_check_filetype(basename($filename), null ); 126 155 $attachment = array( -
wp-booklet/trunk/classes/class-wp-booklet2-settings-page.php
r1179381 r1385454 16 16 */ 17 17 function booklet_settings_page() { 18 add_option('wp-booklet2-pdf-limit-status',"on");19 18 add_submenu_page( 'edit.php?post_type=wp-booklet2', 'Settings', 'Settings', 'manage_options', 'wp-booklet2-settings', array( &$this, 'display_settings_page') ); 20 add_action('admin_init', array( &$this, 'booklet_settings_store') );21 }22 23 /**24 * Register options in the settings page25 *26 * @return void27 */28 function booklet_settings_store() {29 register_setting('wp-booklet2-settings', 'wp-booklet2-pdf-limit-status');30 19 } 31 20 … … 37 26 function display_settings_page() { 38 27 28 //Define test pdf 29 $pdf = new WP_Booklet2_PDF( realpath( WP_BOOKLET2_DIR . 'assets/pdf/test.pdf' ) ); 30 39 31 //Check Ghostscript status 40 32 … … 79 71 $im_status['message'] = $e->getMessage(); 80 72 } 81 73 74 //Check PDFInfo status 75 $pdfinfo = new WP_Booklet2_PDFInfo($pdf->get_path()); 76 $pdfinfo_version = $pdfinfo->get_version(); 77 $pdfinfo_status = $pdfinfo_version == false ? 'No available version is found for your operating system' : $pdfinfo_version; 78 82 79 //Is uploads folder writable by web server? 83 80 $upload_dir = wp_upload_dir(); … … 90 87 //Do the actual test 91 88 try { 92 $pdf = new WP_Booklet2_PDF( realpath( WP_BOOKLET2_DIR . 'assets/pdf/test.pdf' ) );93 89 $actual_test = $pdf->is_convertible_to_image(); 94 90 } -
wp-booklet/trunk/readme.txt
r1289197 r1385454 4 4 Tags: flip book, flipbook, booklet 5 5 Requires at least: 3.9 6 Tested up to: 4.2. 27 Stable tag: 2.1. 16 Tested up to: 4.2.7 7 Stable tag: 2.1.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 63 63 = Why can't I see the "Upload PDF" button? = 64 64 65 WP Booklet relies on Ghostscriptand Imagemagick for PDF conversion. If you can't see the button, then at least one of them is missing or misconfigured. If they are configured properly, you should see their versions under Booklet->Settings.65 WP Booklet relies on PDFInfo, Ghostscript, and Imagemagick for PDF conversion. If you can't see the button, then at least one of them is missing or misconfigured. If they are configured properly, you should see their versions under Booklet->Settings. 66 66 67 67 You also need to ensure that your uploads folder is writable by the web server. Check this status under Booklet->Settings. … … 87 87 == Changelog == 88 88 89 = 2.1.2 = 90 * Added page indicator to PDF uploader 91 89 92 = 2.1.1 = 90 93 * PDF upload now terminates once maxiumum PHP execution time is reached. … … 183 186 == Upgrade Notice == 184 187 188 = 2.1.2 = 189 * Added page indicator to PDF uploader 190 185 191 = 2.1.1 = 186 192 * PDF upload now terminates once maxiumum PHP execution time is reached. -
wp-booklet/trunk/themes/admin/default/settings-page.php
r1166511 r1385454 2 2 3 3 <h2>Settings</h2> 4 5 <h3 class="title">Server Environment</h3> 4 6 5 <?php if( isset($_GET['settings-updated']) ) : ?> 6 <?php if( $_GET['settings-updated'] == "true" ) : ?> 7 <div class="updated"> 8 <p><strong>Settings saved.</strong></p> 9 </div> 10 <?php else: ?> 11 <div class="updated error"> 12 <p><strong>An error ocurred.</strong></p> 13 </div> 14 <?php endif ?> 15 <?php endif ?> 16 17 <form method="post" action="options.php"> 18 19 <?php settings_fields('wp-booklet2-settings'); ?> 20 21 <h3 class="title">Server Environment</h3> 22 23 <table class="form-table"> 24 <tbody> 25 <tr valign="top"> 26 <th scope="row">Can your server convert PDF files?</th> 27 <td> 28 <?php if ( $actual_test ) : ?> 29 <span style="color:green;font-weight:bold;font-size:16px;">Yes. You're all set.</span> 30 <?php else: ?> 31 <span style="color:red;font-weight:bold;font-size:16px;">No. Please contact your server administrator. The information below may help in troubleshooting the problem.</span> 32 <?php endif ?> 33 </td> 34 </tr> 35 <tr valign="top"> 36 <th scope="row">Ghostscript status</th> 37 <td><?php echo $gs_status['message'] ?></td> 38 </tr> 39 <tr valign="top"> 40 <th scope="row">Imagemagick status</th> 41 <td><?php echo $im_status['message'] ?></td> 42 </tr> 43 <tr valign="top"> 44 <th scope="row">Is uploads directory writable by web server?</th> 45 <td><?php echo $writable ?></td> 46 </tr> 47 </tbody> 48 </table> 49 50 <h3 class="title">PDF Options</h3> 51 52 <table class="form-table"> 53 <tbody> 54 <tr valign="top"> 55 <th scope="row"><label for="wp-booklet-pdf-limit-status">PDF page limit</label></th> 56 <td> 57 <input name="wp-booklet2-pdf-limit-status" type="checkbox" id="wp-booklet2-pdf-limit-status" <?php echo get_option('wp-booklet2-pdf-limit-status') == 'on' ? "checked='checked'" : "" ?> /> 58 <label for="wp-booklet2-pdf-limit-status">Limit converted PDF pages to 10.</label> 59 <p class="description">PDF-to-image conversion is resource-intensive and may crash your server so only the first 10 pages of PDF files get converted. You can deactivate the limit. <u><b>Your server is your responsibility.</b></u></p> 60 </td> 61 </tr> 62 </tbody> 63 64 </table> 65 66 <p class="submit"> 67 <input type="submit" class="button-primary" value="Save Changes" /> 68 </p> 69 70 </form> 71 72 73 </form> 7 <table class="form-table"> 8 <tbody> 9 <tr valign="top"> 10 <th scope="row">Can your server convert PDF files?</th> 11 <td> 12 <?php if ( $actual_test ) : ?> 13 <span style="color:green;font-weight:bold;font-size:16px;">Yes. You're all set.</span> 14 <?php else: ?> 15 <span style="color:red;font-weight:bold;font-size:16px;">No. Please contact your server administrator. The information below may help in troubleshooting the problem.</span> 16 <?php endif ?> 17 </td> 18 </tr> 19 <tr valign="top"> 20 <th scope="row">Ghostscript status</th> 21 <td><?php echo $gs_status['message'] ?></td> 22 </tr> 23 <tr valign="top"> 24 <th scope="row">Imagemagick status</th> 25 <td><?php echo $im_status['message'] ?></td> 26 </tr> 27 <tr valign="top"> 28 <th scope="row">PDFInfo status</th> 29 <td><?php echo $pdfinfo_status ?></td> 30 </tr> 31 <tr valign="top"> 32 <th scope="row">Is uploads directory writable by web server?</th> 33 <td><?php echo $writable ?></td> 34 </tr> 35 </tbody> 36 </table> 74 37 75 38 </div> -
wp-booklet/trunk/wp-booklet.php
r1289197 r1385454 3 3 * Plugin Name: WP Booklet 4 4 * Description: Allows creation of flip books using the jQuery Booklet plugin. Successor to WP Booklet 1.x 5 * Version: 2.1. 15 * Version: 2.1.2 6 6 * Author: BinaryStash 7 7 * Author URI: http://www.binarystash.net … … 96 96 97 97 $wp_booklet_included_classes = array( 98 'class-wp-booklet2-pdfinfo.php', 98 99 'class-wp-booklet2-booklet.php', 99 100 'class-wp-booklet2-page.php',
Note: See TracChangeset
for help on using the changeset viewer.