Plugin Directory

Changeset 1385454


Ignore:
Timestamp:
04/03/2016 06:13:38 AM (10 years ago)
Author:
binarystash01
Message:

Added page indicator to PDF uploader

Location:
wp-booklet/trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • wp-booklet/trunk/assets/js/wpbooklet-editor.js

    r1289197 r1385454  
    9696        e.preventDefault();
    9797       
    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        
    10798        pdf_uploader.open();
    10899       
     
    110101   
    111102    function showPreloader(text) {
    112         jQuery(".wp-booklet-preloader-overlay .wp-booklet-preloader-note").html(text);
     103        updatePreloader(text);
    113104        jQuery(".wp-booklet-preloader-overlay").show().animate({opacity:0.8},200);
    114105    }
     106    function updatePreloader(text) {
     107        jQuery(".wp-booklet-preloader-overlay .wp-booklet-preloader-note").html(text);
     108    }   
    115109    function hidePreloader() {
    116110        jQuery(".wp-booklet-preloader-overlay").animate({opacity:0},200).hide();
     
    128122        jQuery.post(ajaxurl,data,function(verification) {
    129123            if ( verification.wpb_success ) {
    130                 hidePreloader();
    131124                showPreloader('Processing PDF. Please keep this window open.');
    132125                var data = {
     
    135128                    'action':'process_pdf'
    136129                }
    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                               
    146157                        }
    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();
    160168               
    161169            }
  • wp-booklet/trunk/classes/class-wp-booklet2-booklet-editor.php

    r1289197 r1385454  
    263263       
    264264        $pdf_id = $_POST['pdf_id'];
     265        $pdf_offset = $_POST['pdf_offset'];
     266        $pdf_limit = 1;
    265267        $pdf_path = get_attached_file( $pdf_id );
    266268       
     
    272274        );
    273275       
    274         $images = $pdf->get_pages_as_photos();
     276        $images = $pdf->get_pages_as_photos($pdf_offset);
    275277       
    276278        if ( $images ) {
     
    301303        try {
    302304            $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            );
    304309        }
    305310        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            );
    307315        }
    308316       
  • wp-booklet/trunk/classes/class-wp-booklet2-command.php

    r1193008 r1385454  
    3636        $existence = exec( $this->_command ." ". $this->_modifiers . " 2>&1", $output, $return_var );
    3737
    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 );
    3951    }
    4052
     
    4860            exec( $this->_command . " " . $this->_modifiers . " 2>&1", $output, $return_var );
    4961       
    50             if ( $return_var === 0 ) {
     62            if ( $this->_is_exit_code_valid($return_var) ) {
    5163                $result['error'] = false;
    5264                $result['message'] = implode(" ",$output);
     65                $result['output'] = $output;
    5366            }
    5467            else {
  • wp-booklet/trunk/classes/class-wp-booklet2-pdf.php

    r1211263 r1385454  
    2525     * Get PDF page count
    2626     *
    27      * return int
     27     * return mixed - int on success, false on failure
    2828     */
    2929    protected function _get_pdf_page_count() {
    3030
    31         $file = $this->_file;
     31        $pdfinfo = new WP_Booklet2_PDFInfo($this->_file);
     32       
     33        return $pdfinfo->get_pages();
     34       
     35    }
    3236
    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   
    4555    }
    4656
     
    7484        $command = new WP_Booklet2_Command("convert", "-limit memory 32MiB -limit map 64MiB {$pdf} {$target}");
    7585        $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() ) {
    7890            $file_exists = file_exists( $target );
    7991            @unlink( $target );
     
    89101     * Converts PDF images into Wordpress attachments
    90102     *
    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
    92105     *
    93106     * @return mixed - array of attachments, false on error
    94107     */
    95     function get_pages_as_photos() {
    96 
     108    function get_pages_as_photos($offset=0,$limit=1) {
     109       
     110        //Set vars
    97111        $pdf_path = $this->_file;
    98112        $upload_dir = wp_upload_dir();
     
    100114        $image_group = uniqid();
    101115        $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        }
    104126       
    105127        //Check that upload directory is writable by server
     
    109131       
    110132        //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");
    112134        $operation = $command->run_command();
    113135       
     
    119141        $images = array();
    120142
    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            }
    122152           
    123153            //Prepare attachment
    124             $filename = $upload_path."/".$image_group."-".$ctr.".jpg";
    125154            $wp_filetype = wp_check_filetype(basename($filename), null );
    126155            $attachment = array(
  • wp-booklet/trunk/classes/class-wp-booklet2-settings-page.php

    r1179381 r1385454  
    1616     */
    1717    function booklet_settings_page() {
    18         add_option('wp-booklet2-pdf-limit-status',"on");
    1918        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 page
    25      *
    26      * @return void
    27      */
    28     function booklet_settings_store() {
    29         register_setting('wp-booklet2-settings', 'wp-booklet2-pdf-limit-status');
    3019    }
    3120   
     
    3726    function display_settings_page() {
    3827       
     28        //Define test pdf
     29        $pdf = new WP_Booklet2_PDF( realpath( WP_BOOKLET2_DIR . 'assets/pdf/test.pdf' ) );
     30
    3931        //Check Ghostscript status
    4032       
     
    7971            $im_status['message'] = $e->getMessage();
    8072        }
    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
    8279        //Is uploads folder writable by web server?
    8380        $upload_dir = wp_upload_dir();
     
    9087        //Do the actual test
    9188        try {
    92             $pdf = new WP_Booklet2_PDF( realpath( WP_BOOKLET2_DIR . 'assets/pdf/test.pdf' ) );
    9389            $actual_test = $pdf->is_convertible_to_image();
    9490        }
  • wp-booklet/trunk/readme.txt

    r1289197 r1385454  
    44Tags: flip book, flipbook, booklet
    55Requires at least: 3.9
    6 Tested up to: 4.2.2
    7 Stable tag: 2.1.1
     6Tested up to: 4.2.7
     7Stable tag: 2.1.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6363= Why can't I see the "Upload PDF" button? =
    6464
    65 WP Booklet relies on 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.
     65WP 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.
    6666
    6767You also need to ensure that your uploads folder is writable by the web server. Check this status under Booklet->Settings.
     
    8787== Changelog ==
    8888
     89= 2.1.2 =
     90* Added page indicator to PDF uploader
     91
    8992= 2.1.1 =
    9093* PDF upload now terminates once maxiumum PHP execution time is reached.
     
    183186== Upgrade Notice ==
    184187
     188= 2.1.2 =
     189* Added page indicator to PDF uploader
     190
    185191= 2.1.1 =
    186192* PDF upload now terminates once maxiumum PHP execution time is reached.
  • wp-booklet/trunk/themes/admin/default/settings-page.php

    r1166511 r1385454  
    22
    33    <h2>Settings</h2>
     4
     5    <h3 class="title">Server Environment</h3>
    46   
    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>
    7437
    7538</div>
  • wp-booklet/trunk/wp-booklet.php

    r1289197 r1385454  
    33 * Plugin Name: WP Booklet
    44 * Description: Allows creation of flip books using the jQuery Booklet plugin. Successor to WP Booklet 1.x
    5  * Version: 2.1.1
     5 * Version: 2.1.2
    66 * Author: BinaryStash
    77 * Author URI:  http://www.binarystash.net
     
    9696 
    9797$wp_booklet_included_classes = array(
     98    'class-wp-booklet2-pdfinfo.php',
    9899    'class-wp-booklet2-booklet.php',
    99100    'class-wp-booklet2-page.php',
Note: See TracChangeset for help on using the changeset viewer.