<?php /* Plugin Name: PDF Light Viewer Plugin Plugin URI: http://pdf-light-viewer.wp.teamlead.pw/ Description: Wordpress plugin to embed normal, large and very large pdf documents to the wordpress site as flipbooks with thumbnail navigation. Version: 1.2.3 Author: Teamlead Power Author URI: http://teamlead.pw/ License: GPLv2 Text Domain: pdf-light-viewer */ if (!defined('WPINC')) { die; } define('PDF_LIGHT_VIEWER_PLUGIN', 'pdf-light-viewer'); define('PDF_LIGHT_VIEWER_APPPATH', dirname(__FILE__)); define('PDF_LIGHT_VIEWER_FILE', __FILE__); if (!class_exists('PdfLightViewer_Plugin')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/controllers/Plugin.php'; } PdfLightViewer_Plugin::init();
public static function showPDFPointer() { $plugin_title = PdfLightViewer_Plugin::getData('Title'); $pointer_content = '<h3>' . $plugin_title . '</h3>'; $pointer_content .= '<p>' . __("We have just created new section called PDFs in your dashboard. Use it to import and publish your cool PDF files.", PDF_LIGHT_VIEWER_PLUGIN) . '</p>'; ?> <script type="text/javascript"> (function($){ $(document).ready( function($) { $('#menu-posts-<?php echo PdfLightViewer_PdfController::$type; ?> ').pointer({ content: '<?php echo $pointer_content; ?> ', position: { edge: 'left', align: 'center' }, close: function() { // Once the close button is hit } }).pointer('open'); }); })(jQuery); </script> <?php }
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); }
<code><pre><?php if (file_exists(PdfLightViewer_Plugin::getLogsPath() . date('Y-m-d') . '.php')) { include_once PdfLightViewer_Plugin::getLogsPath() . date('Y-m-d') . '.php'; } else { _e("Today's log file doesn't exist", PDF_LIGHT_VIEWER_PLUGIN); } ?> </pre></code> </div> </div> </div> <div class="pure-u-1"> <?php $documentation_url = PdfLightViewer_Plugin::getDocsUrl(); ?> <div class="pdf-light-viewer-bl"> <div class="row hdr"> <h3> <span class="icons icon-doc"></span> <?php _e('Documentation', PDF_LIGHT_VIEWER_PLUGIN); ?> <a class="right" target="_blank" href="<?php echo $documentation_url; ?> " title="<?php _e('open in the separate tab', PDF_LIGHT_VIEWER_PLUGIN); ?> "><span class="icons icon-link"></span></a>
public static function run() { // third party if (version_compare(PHP_VERSION, '5.3.0', '>=')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/vendor/autoload.php'; } function wp_pdf_light_viewer_cmb_initialize_cmb_meta_boxes() { if (!class_exists('cmb_Meta_Box')) { require_once PDF_LIGHT_VIEWER_APPPATH . '/vendor/WebDevStudios/Custom-Metaboxes-and-Fields-for-WordPress/init.php'; } else { $meta_boxes = array(); $meta_boxes = apply_filters('cmb_meta_boxes', $meta_boxes); foreach ($meta_boxes as $meta_box) { $my_box = new cmb_Meta_Box($meta_box); } } } add_action('init', 'wp_pdf_light_viewer_cmb_initialize_cmb_meta_boxes', 9999); include_once PDF_LIGHT_VIEWER_APPPATH . '/libraries/directory_helper.php'; // if (!class_exists('PdfLightViewer_AssetsController')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/controllers/AssetsController.php'; } if (!class_exists('PdfLightViewer_AdminController')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/controllers/AdminController.php'; } if (!class_exists('PdfLightViewer_FrontController')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/controllers/FrontController.php'; } if (!class_exists('PdfLightViewer_PdfController')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/controllers/PdfController.php'; } if (defined('WP_CLI') && WP_CLI) { include_once PDF_LIGHT_VIEWER_APPPATH . '/controllers/CLIController.php'; } if (!class_exists('PdfLightViewer_Model')) { include_once PDF_LIGHT_VIEWER_APPPATH . '/models/Model.php'; } // assets if (is_admin()) { add_action('admin_enqueue_scripts', array('PdfLightViewer_AssetsController', 'admin_head')); } else { add_action('wp_enqueue_scripts', array('PdfLightViewer_AssetsController', 'frontend_head')); } // post types add_action('init', array('PdfLightViewer_Plugin', 'registerPostTypes')); // shortcodes PdfLightViewer_Plugin::registerShortcodes(); //ADMIN if (is_admin() && (current_user_can('edit_posts') || current_user_can('edit_pages'))) { // settings init add_action('admin_init', array('PdfLightViewer_AdminController', 'settingsInit')); add_action('admin_notices', array('PdfLightViewer_AdminController', 'initGentleNotifications')); // admin page add_action('admin_menu', array('PdfLightViewer_AdminController', 'registerMenuPage')); // admin ajax add_action('admin_init', array('PdfLightViewer_AdminController', 'registerAjaxHandlers')); // notifications init add_action('admin_notices', array('PdfLightViewer_AdminController', 'showAdminNotifications')); } $requirements_met = self::requirements(true); if (!get_option(PDF_LIGHT_VIEWER_PLUGIN . '-notifications-viewed') && $requirements_met || !$requirements_met) { add_action('admin_notices', array('PdfLightViewer_AdminController', 'showActivationMessages')); } update_option(PDF_LIGHT_VIEWER_PLUGIN . '-notifications-viewed', true); if (!get_option(PDF_LIGHT_VIEWER_PLUGIN . '-pointers-viewed')) { add_action('admin_enqueue_scripts', array('PdfLightViewer_AdminController', 'showActivationPointers')); } update_option(PDF_LIGHT_VIEWER_PLUGIN . '-pointers-viewed', true); }
/** * Bulk PDF import * * ## OPTIONS * * <source-dir> * : required, source directory to import PDF files * * <jpeg-compression-quality> * : optional, jpeg compression quality, default 60 * * <jpeg-resolution> * : optional, jpeg resolution, default 300 * * <post-status> * : optional, PDF post status, default "draft" * * <import-pdf-file> * : flag, if set then import PDF file to Wordpress media library * * ## EXAMPLES * * wp pdf-light-viewer bulk-import --source-dir="/path/to/pdfs" * wp pdf-light-viewer bulk-import --source-dir="/path/to/pdfs" --jpeg-compression-quality=60 --jpeg-resolution=300 --post-status=publish --import-pdf-file * * @synopsis --source-dir=<source-dir> [--jpeg-compression-quality=<jpeg-compression-quality>] [--jpeg-resolution=<jpeg-resolution>] [--post-status=<post-status>] [--import-pdf-file] * @subcommand bulk-import */ public function bulk_import($args, $assoc_args) { // options $source_dir = $assoc_args['source-dir']; $jpeg_compression_quality = isset($assoc_args['jpeg-compression-quality']) ? (int) $assoc_args['jpeg-compression-quality'] : 60; $jpeg_resolution = isset($assoc_args['jpeg-resolution']) ? (int) $assoc_args['jpeg-resolution'] : 300; $post_status = isset($assoc_args['post-status']) ? $assoc_args['post-status'] : 'draft'; $import_pdf_file = isset($assoc_args['import-pdf-file']); // check requirements $plugin_title = PdfLightViewer_Plugin::getData('Title'); $requirements_met = PdfLightViewer_Plugin::requirements(true); if (!$requirements_met) { $message = $plugin_title . ': ' . __('requirements not met, please check plugin settings page for more information.', PDF_LIGHT_VIEWER_PLUGIN); WP_ClI::error($message, true); } else { WP_CLI::log($plugin_title . ': ' . __("requirements are met, happy using!", PDF_LIGHT_VIEWER_PLUGIN)); } // check dir if (!is_readable($source_dir) || !is_dir($source_dir)) { WP_CLI::error(__("Source dir doesn't exist or it's not readable", PDF_LIGHT_VIEWER_PLUGIN), true); } else { WP_CLI::log(sprintf(__("Searching PDF files in %s", PDF_LIGHT_VIEWER_PLUGIN), $source_dir)); } // check PDF files $pdf_files = glob($source_dir . '/*.pdf', GLOB_NOSORT); if (empty($pdf_files)) { WP_CLI::error(__("Source dir doesn't contain PDF files", PDF_LIGHT_VIEWER_PLUGIN), true); } else { WP_CLI::log(sprintf(__("%d PDF files found", PDF_LIGHT_VIEWER_PLUGIN), count($pdf_files))); } // start import $pdf_files_count = count($pdf_files); $all_pdfs_progress = new \cli\progress\Bar(__("Processing PDF files", PDF_LIGHT_VIEWER_PLUGIN), $pdf_files_count); foreach ($pdf_files as $pdf_file_path) { // get number of pages $im = new Imagick(); $im->readImage($pdf_file_path); $pdf_pages_number = $im->getNumberImages(); foreach ($im as $_img) { $geometry = $_img->getImageGeometry(); $width = $geometry['width']; $height = $geometry['height']; break; } $im->destroy(); unset($im); $current_pdf_progress = new \cli\progress\Bar(sprintf(__("Processing PDF file %s", PDF_LIGHT_VIEWER_PLUGIN), $pdf_file_path), $pdf_pages_number); // create PDF post $post_id = wp_insert_post(['post_type' => PdfLightViewer_PdfController::$type, 'post_status' => $post_status, 'post_name' => sanitize_title(pathinfo($pdf_file_path, PATHINFO_FILENAME)), 'post_title' => pathinfo($pdf_file_path, PATHINFO_FILENAME)]); if (is_wp_error($post_id)) { WP_CLI::error(sprintf(__("Could not create PDF post: %s", PDF_LIGHT_VIEWER_PLUGIN), $post_id->get_error_message()), false); } else { // save pdf to media library if ($import_pdf_file) { $image_data = file_get_contents($pdf_file_path); $attach_id = PdfLightViewer_Plugin::create_media_from_data(pathinfo($pdf_file_path, PATHINFO_BASENAME), $image_data); update_post_meta($post_id, 'pdf_file_id', $attach_id); } $pdf_upload_dir = PdfLightViewer_Plugin::createUploadDirectory($post_id); $current_page = 1; $ratio = $width / $height; do_action(PDF_LIGHT_VIEWER_PLUGIN . ':before_import', $post_id, $pdf_file_path); update_post_meta($post_id, '_pdf-light-viewer-import-status', PdfLightViewer_PdfController::STATUS_CLI_PROCESSING); update_post_meta($post_id, '_pdf-light-viewer-import-progress', 0); update_post_meta($post_id, '_pdf-light-viewer-import-current-page', $current_page); update_post_meta($post_id, 'pdf-pages-number', $pdf_pages_number); update_post_meta($post_id, 'pdf-page-width', $width); update_post_meta($post_id, 'pdf-page-height', $height); // process pages 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 { PdfLightViewer_PdfController::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)); $error = $e->getMessage(); update_post_meta($post_id, '_pdf-light-viewer-import-status', PdfLightViewer_PdfController::STATUS_FAILED); WP_CLI::warning(sprintf(__('Import of PDF %s failed: %s', PDF_LIGHT_VIEWER_PLUGIN), $pdf_file_path, $error), false); } } $current_pdf_progress->tick(); } do_action(PDF_LIGHT_VIEWER_PLUGIN . ':after_import', $post_id, $pdf_file_path); do_action(PDF_LIGHT_VIEWER_PLUGIN . ':finished_import', $post_id, $pdf_file_path); update_post_meta($post_id, '_pdf-light-viewer-import-status', PdfLightViewer_PdfController::STATUS_FINISHED); WP_CLI::success(sprintf(__('Import of PDF %s finished', PDF_LIGHT_VIEWER_PLUGIN), $pdf_file_path)); } $all_pdfs_progress->tick(); } WP_CLI::success(__('Import finished', PDF_LIGHT_VIEWER_PLUGIN)); }
public static function deleted_post($post_id = '', $arg2 = '') { if ($post_id && get_post_type($post_id) == self::$type) { $pdf_upload_dir = PdfLightViewer_Plugin::createUploadDirectory($post_id); if ($pdf_upload_dir) { self::delete_pages_by_pdf_id($post_id, $pdf_upload_dir); rmdir($pdf_upload_dir); rmdir($pdf_upload_dir . '-thumbs'); } } }