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;
 }
Esempio n. 2
0
 public static function requirements($boolean = false)
 {
     $upload_dir_message = __('Upload folder', PDF_LIGHT_VIEWER_PLUGIN) . ': <code>' . PdfLightViewer_Plugin::getUploadDirectory() . '</code>';
     $host_url = site_url();
     $Imagick = null;
     $ImagickVersion = null;
     $pdf_format_support = array();
     if (class_exists("Imagick")) {
         $Imagick = new Imagick();
         $ImagickVersion = $Imagick->getVersion();
         $pdf_format_support = $Imagick->queryFormats('PDF');
     }
     if (PdfLightViewer_AdminController::getSetting('do-not-check-gs')) {
         $ghostscript_version = true;
     } else {
         if (function_exists('shell_exec')) {
             if (stristr(php_uname('s'), 'win')) {
                 $ghostscript_version = @shell_exec('gs --version');
             } else {
                 $ghostscript_version = @shell_exec('$(command -v gs) --version');
                 if (!$ghostscript_version) {
                     $ghostscript_version = @shell_exec('$(which gs) --version');
                 }
                 if (!$ghostscript_version) {
                     $ghostscript_version = @shell_exec('gs --version');
                 }
             }
         } else {
             $ghostscript_version = false;
         }
     }
     $logs_dir_message = __('Logs folder', PDF_LIGHT_VIEWER_PLUGIN) . ': <code>' . self::getLogsPath() . '</code>';
     $requirements = array(array('name' => 'PHP', 'status' => version_compare(PHP_VERSION, '5.3.0', '>='), 'success' => sprintf(__('is %s or higher', PDF_LIGHT_VIEWER_PLUGIN), '5.3'), 'fail' => sprintf(__('is lower than %s', PDF_LIGHT_VIEWER_PLUGIN), '5.3'), 'description' => ''), array('name' => __('Imagick PHP Extension', PDF_LIGHT_VIEWER_PLUGIN), 'status' => extension_loaded('imagick'), 'success' => __('is loaded', PDF_LIGHT_VIEWER_PLUGIN), 'fail' => __('is not loaded', PDF_LIGHT_VIEWER_PLUGIN), 'description' => __("Imagick PHP Extension is required for PDF -> JPEG convertation. It cannot be included with the plugin unfortunately, so you or your hosting provider/server administrator should install it.", PDF_LIGHT_VIEWER_PLUGIN)), array('name' => __('Imagick PHP Wrapper', PDF_LIGHT_VIEWER_PLUGIN), 'status' => class_exists("Imagick"), 'success' => __('is supported', PDF_LIGHT_VIEWER_PLUGIN) . ($ImagickVersion ? '. v.' . $ImagickVersion['versionString'] : ''), 'fail' => __('is not supported', PDF_LIGHT_VIEWER_PLUGIN), 'description' => __("Imagick PHP Wrapper is required to make available Imagick PHP Extension functionality in the plugin. Usually it's integrated through the PECL plugin. It cannot be included with the plugin unfortunately, so you or your hosting provider/server administrator should install it.", PDF_LIGHT_VIEWER_PLUGIN)), array('name' => __('Imagick PDF Support', PDF_LIGHT_VIEWER_PLUGIN), 'status' => $Imagick && !empty($pdf_format_support), 'success' => __('is enabled', PDF_LIGHT_VIEWER_PLUGIN), 'fail' => __('is not enabled', PDF_LIGHT_VIEWER_PLUGIN), 'description' => __("Imagick PDF Support is required for PDF -> JPEG convertation.", PDF_LIGHT_VIEWER_PLUGIN)), array('name' => 'GhostScript', 'status' => $ghostscript_version, 'success' => __('is supported', PDF_LIGHT_VIEWER_PLUGIN) . ($ghostscript_version && is_string($ghostscript_version) ? '. v.' . $ghostscript_version : ''), 'fail' => __('is not supported', PDF_LIGHT_VIEWER_PLUGIN), 'description' => __("GhostScript is required for Imagick PDF Support. For cases, when you are sure that GhostScript is installed, but it was not detected by the plugin correctly you can disable this requirement in options below.", PDF_LIGHT_VIEWER_PLUGIN)), array('name' => $upload_dir_message, 'status' => PdfLightViewer_Plugin::createUploadDirectory(), 'success' => __('is writable', PDF_LIGHT_VIEWER_PLUGIN), 'fail' => __('is not writable', PDF_LIGHT_VIEWER_PLUGIN), 'description' => __("This is the folder for converted images.", PDF_LIGHT_VIEWER_PLUGIN)), array('name' => $logs_dir_message, 'status' => self::createLogsDirectory() && is_writable(self::getLogsPath()), 'success' => __('is writable', PDF_LIGHT_VIEWER_PLUGIN), 'fail' => __('is not writable', PDF_LIGHT_VIEWER_PLUGIN), 'description' => __("We will save plugin-specific log files in this folder.", PDF_LIGHT_VIEWER_PLUGIN)));
     if ($boolean) {
         $status = true;
         foreach ($requirements as $requirement) {
             $status = $status && $requirement['status'];
         }
         return $status;
     } else {
         return $requirements;
     }
 }
 public static function metabox_dashboard_usage($post)
 {
     $pdf_upload_dir = PdfLightViewer_Plugin::getUploadDirectory($post->ID);
     $pages = directory_map($pdf_upload_dir);
     $post_id = $post->ID;
     include_once PDF_LIGHT_VIEWER_APPPATH . '/views/metabox/usage.php';
 }