public static function admin_head() { // styles $styles = array('purecss.grids.responsive' => 'assets/bower_components/pure/grids-responsive-min.css', 'purecss.grids.core' => 'assets/bower_components/pure/grids-core-min.css', 'purecss.forms' => 'assets/bower_components/pure/forms-min.css', 'simple-line-icons' => 'assets/bower_components/simple-line-icons/css/simple-line-icons.css', 'jquery.bxslider.css' => 'assets/bower_components/bxslider-4/dist/jquery.bxslider.css', 'backend.' . PDF_LIGHT_VIEWER_PLUGIN => 'assets/css/backend.css'); foreach ($styles as $id => $file) { $ver = null; if (file_exists(PDF_LIGHT_VIEWER_APPPATH . '/' . $file)) { $ver = filemtime(PDF_LIGHT_VIEWER_APPPATH . '/' . $file); } wp_enqueue_style($id, plugins_url($file, PDF_LIGHT_VIEWER_FILE), null, $ver); } // scripts $jquery_plugins = array('jquery.scrollstop.js' => 'assets/bower_components/jquery.lazyload/jquery.scrollstop.js', 'jquery.lazyload.js' => 'assets/bower_components/jquery.lazyload/jquery.lazyload.js', 'hash.turn.js' => 'assets/js/turn.js/hash.js', 'jquery.fullscreen.js' => 'assets/bower_components/kayahr-jquery-fullscreen-plugin/jquery.fullscreen-min.js', 'html4.turn.js' => 'assets/js/turn.js/turn.html4.min.js', 'turn.js' => 'assets/js/turn.js/turn.min.js', 'jquery.bxslider.js' => 'assets/bower_components/bxslider-4/dist/jquery.bxslider.min.js', 'jquery.zoom.js' => 'assets/bower_components/jquery-zoom/jquery.zoom.min.js'); foreach ($jquery_plugins as $id => $file) { $ver = null; if (file_exists(PDF_LIGHT_VIEWER_APPPATH . '/' . $file)) { $ver = filemtime(PDF_LIGHT_VIEWER_APPPATH . '/' . $file); } wp_enqueue_script($id, plugins_url($file, PDF_LIGHT_VIEWER_FILE), array('jquery'), $ver); } wp_enqueue_script('magazine.' . PDF_LIGHT_VIEWER_FILE, plugins_url('assets/js/magazine.js', PDF_LIGHT_VIEWER_FILE), array('jquery', 'jquery.lazyload.js', 'turn.js'), filemtime(PDF_LIGHT_VIEWER_APPPATH . '/assets/js/magazine.js')); wp_enqueue_script('admin.' . PDF_LIGHT_VIEWER_FILE, plugins_url('assets/js/admin.js', PDF_LIGHT_VIEWER_FILE), array('jquery', 'jquery.lazyload.js', 'turn.js'), filemtime(PDF_LIGHT_VIEWER_APPPATH . '/assets/js/admin.js')); // javascript settings if (!PdfLightViewer_Model::$unimported) { PdfLightViewer_Model::$unimported = PdfLightViewer_Model::getOneUnimported(); } wp_localize_script('admin.' . PDF_LIGHT_VIEWER_FILE, 'PdfLightViewer', array('url' => array('ajaxurl' => admin_url('admin-ajax.php')), 'flags' => array('ping_import' => (bool) PdfLightViewer_Model::$unimported), '__' => array('Import process was successfully finished. Please check results on the PDF page.' => __('Import process was successfully finished. Please check results on the PDF page.', PDF_LIGHT_VIEWER_PLUGIN), 'Import process failed due to the unknown error.' => __('Import process failed due to the unknown error.', PDF_LIGHT_VIEWER_PLUGIN), 'Import process failed due to the error:' => __('Import process failed due to the error:', PDF_LIGHT_VIEWER_PLUGIN)))); }
public static function registerAjaxHandlers() { if (!PdfLightViewer_Model::$unimported) { PdfLightViewer_Model::$unimported = PdfLightViewer_Model::getOneUnimported(); } if (!empty(PdfLightViewer_Model::$unimported)) { add_action('wp_ajax_' . PDF_LIGHT_VIEWER_PLUGIN . '_ping_import', array('PdfLightViewer_PdfController', 'pdf_partially_import')); } add_action('wp_ajax_' . PDF_LIGHT_VIEWER_PLUGIN . '_notification_viewed', array(__CLASS__, 'notification_viewed')); }
public static function getConfig($atts, $post) { $pdf_light_viewer_config = self::parseDefaultsSettings($atts, $post); // download options if ($pdf_light_viewer_config['download_allowed']) { $pdf_file_id = PdfLightViewer_Model::getPDFFileId($post->ID); $pdf_file_url = wp_get_attachment_url($pdf_file_id); $alternate_download_link = PdfLightViewer_Plugin::get_post_meta($post->ID, 'alternate_download_link', true); $pdf_light_viewer_config['download_link'] = $alternate_download_link ? $alternate_download_link : $pdf_file_url; } $pdf_upload_dir = PdfLightViewer_Plugin::getUploadDirectory($post->ID); $pdf_upload_dir_url = PdfLightViewer_Plugin::getUploadDirectoryUrl($post->ID); $pdf_light_viewer_config['pdf_upload_dir_url'] = $pdf_upload_dir_url; $pages = directory_map($pdf_upload_dir); $thumbs = directory_map($pdf_upload_dir . '-thumbs'); if (empty($pages) || empty($thumbs)) { echo '<span style="color: Salmon">' . __('[pdf-light-viewer] shortcode cannot be rendered due to the error: No converted pages found', PDF_LIGHT_VIEWER_PLUGIN) . '</span>'; return; } sort($pages); sort($thumbs); // check permissions $current_user = wp_get_current_user(); $current_user_roles = $current_user->roles; $pages_limits = PdfLightViewer_Plugin::get_post_meta($post->ID, 'pdf_light_viewer_permissions_metabox_repeat_group', true); $limit = 0; if (!empty($pages_limits)) { foreach ($pages_limits as $pages_limit) { if (empty($current_user_roles) && $pages_limit['pages_limit_user_role'] == 'anonymous') { $limit = isset($pages_limit['pages_limit_visible_pages']) ? $pages_limit['pages_limit_visible_pages'] : null; } else { if (in_array($pages_limit['pages_limit_user_role'], $current_user_roles)) { $limit = isset($pages_limit['pages_limit_visible_pages']) ? $pages_limit['pages_limit_visible_pages'] : null; } } } } // limit allowed pages for user role if (!$limit) { $pdf_light_viewer_config['pages'] = $pages; $pdf_light_viewer_config['thumbs'] = $thumbs; } else { for ($page = 0; $page < $limit; $page++) { $pdf_light_viewer_config['pages'][$page] = $pages[$page]; $pdf_light_viewer_config['thumbs'][$page] = $thumbs[$page]; } } $pdf_light_viewer_config = apply_filters(PDF_LIGHT_VIEWER_PLUGIN . ':front_config', $pdf_light_viewer_config, $post); return $pdf_light_viewer_config; }
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; }