public static function parseDefaultsSettings($args, $post = null)
 {
     $defaults = array('template' => 'shortcode-pdf-light-viewer', 'download_link' => '', 'download_allowed' => (bool) PdfLightViewer_Plugin::get_post_meta($post->ID, 'download_allowed', true), 'hide_thumbnails_navigation' => (bool) PdfLightViewer_Plugin::get_post_meta($post->ID, 'hide_thumbnails_navigation', true), 'hide_fullscreen_button' => (bool) PdfLightViewer_Plugin::get_post_meta($post->ID, 'hide_fullscreen_button', true), 'disable_page_zoom' => (bool) PdfLightViewer_Plugin::get_post_meta($post->ID, 'disable_page_zoom', true), 'page_width' => PdfLightViewer_Plugin::get_post_meta($post->ID, 'pdf-page-width', true), 'page_height' => PdfLightViewer_Plugin::get_post_meta($post->ID, 'pdf-page-height', true), 'pages' => array(), 'thumbs' => array(), 'print_allowed' => false, 'enabled_pdf_text' => false, 'enabled_pdf_search' => false, 'enabled_archive' => false);
     return wp_parse_args($args, $defaults);
 }
 public static function pdf_partially_import()
 {
     $unimported = PdfLightViewer_Model::getOneUnimported();
     $post_id = $unimported->ID;
     if (!$post_id) {
         header('Content-Type: application/json');
         echo json_encode(array('status' => 'error', 'progress' => 0, 'error' => __('Currently there are no unimported files in the queue.', PDF_LIGHT_VIEWER_PLUGIN)));
         return;
     }
     $status = PdfLightViewer_Plugin::get_post_meta($post_id, '_pdf-light-viewer-import-status', true);
     if ($status == static::STATUS_SCHEDULED) {
         $status_label = __('scheduled', PDF_LIGHT_VIEWER_PLUGIN);
         update_post_meta($post_id, '_pdf-light-viewer-import-status', static::STATUS_STARTED);
     } else {
         if ($status == static::STATUS_STARTED) {
             $status_label = __('started', PDF_LIGHT_VIEWER_PLUGIN);
             update_post_meta($post_id, '_pdf-light-viewer-import-status', 'processing');
         } else {
             $status_label = __('processing', PDF_LIGHT_VIEWER_PLUGIN);
         }
     }
     ignore_user_abort(true);
     set_time_limit(0);
     $pdf_file_id = PdfLightViewer_Model::getPDFFileId($post_id);
     $pdf_file_path = get_attached_file($pdf_file_id);
     do_action(PDF_LIGHT_VIEWER_PLUGIN . ':before_import', $post_id, $pdf_file_path);
     $pdf_upload_dir = PdfLightViewer_Plugin::createUploadDirectory($post_id);
     $jpeg_resolution = PdfLightViewer_Plugin::get_post_meta($post_id, 'jpeg_resolution', true);
     $jpeg_compression_quality = PdfLightViewer_Plugin::get_post_meta($post_id, 'jpeg_compression_quality', true);
     $pdf_pages_number = (int) PdfLightViewer_Plugin::get_post_meta($post_id, 'pdf-pages-number', true);
     $current_page = (int) PdfLightViewer_Plugin::get_post_meta($post_id, '_pdf-light-viewer-import-current-page', true);
     $width = (int) PdfLightViewer_Plugin::get_post_meta($post_id, 'pdf-page-width', true);
     $height = (int) PdfLightViewer_Plugin::get_post_meta($post_id, 'pdf-page-height', true);
     if (!$width || !$height) {
         header('Content-Type: application/json');
         echo json_encode(array('status' => 'error', 'progress' => 0, 'error' => __('Cannot get width and height of the first page.', PDF_LIGHT_VIEWER_PLUGIN)));
         return;
     }
     $ratio = $width / $height;
     if (!$current_page) {
         header('Content-Type: application/json');
         echo json_encode(array('status' => 'error', 'progress' => 0, 'error' => __('Cannot detect current imported PDF page.', PDF_LIGHT_VIEWER_PLUGIN)));
         return;
     }
     $error = '';
     for ($current_page; $current_page <= $pdf_pages_number; $current_page++) {
         $page_number = sprintf('%1$05d', $current_page);
         if (!file_exists($pdf_upload_dir . '/page-' . $page_number . '.jpg')) {
             try {
                 $percent = static::process_pdf_page($post_id, $current_page, $page_number, $pdf_pages_number, $pdf_file_path, $pdf_upload_dir, $jpeg_resolution, $jpeg_compression_quality, $ratio);
             } catch (Exception $e) {
                 PdfLightViewer_Plugin::log('Import exception: ' . $e->getMessage(), print_r($e, true));
                 $status_label = __('failed', PDF_LIGHT_VIEWER_PLUGIN);
                 $error = $e->getMessage();
                 update_post_meta($post_id, '_pdf-light-viewer-import-status', static::STATUS_FAILED);
             }
             break;
         }
     }
     do_action(PDF_LIGHT_VIEWER_PLUGIN . ':after_import', $post_id, $pdf_file_path);
     if ($percent >= 100) {
         do_action(PDF_LIGHT_VIEWER_PLUGIN . ':finished_import', $post_id, $pdf_file_path);
         $status_label = __('finished', PDF_LIGHT_VIEWER_PLUGIN);
         update_post_meta($post_id, '_pdf-light-viewer-import-status', static::STATUS_FINISHED);
     }
     header('Content-Type: application/json');
     echo json_encode(array('status' => $status_label, 'progress' => (int) $percent, 'error' => $error));
     exit;
 }