public static function getSetting($name)
 {
     if (self::$cached_settings == null) {
         self::$cached_settings = self::getSettings();
     }
     if (isset(self::$cached_settings[$name])) {
         return self::$cached_settings[$name];
     } else {
         return null;
     }
 }
Example #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;
     }
 }
Example #3
0
								type="hidden"
								name="<?php 
echo PDF_LIGHT_VIEWER_PLUGIN;
?>
[do-not-check-gs]"
								value="0"
								/>
							<input
								type="checkbox"
								name="<?php 
echo PDF_LIGHT_VIEWER_PLUGIN;
?>
[do-not-check-gs]"
								value="1"
								<?php 
echo PdfLightViewer_AdminController::getSetting('do-not-check-gs') ? 'checked="checked"' : '';
?>
								/>
						</p>
						
						<hr />
					
						<div class="row">
							<button class="button-primary" type="submit">
								<?php 
_e('Save', PDF_LIGHT_VIEWER_PLUGIN);
?>
							</button>
						</div>
					</div>
					
 public static function save_post($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || !$_POST) {
         return;
     }
     if (current_user_can('edit_posts')) {
         $form_data = $_REQUEST;
         $pdf_file_id = isset($form_data['pdf_file_id']) ? $form_data['pdf_file_id'] : PdfLightViewer_Model::getPDFFileId($post_id);
         $pdf_file_path = get_attached_file($pdf_file_id);
         if ((isset($form_data['enable_pdf_import']) && $form_data['enable_pdf_import'] == 'on' || isset($form_data['enable_pdf_import']) && (isset($form_data['enable_pdf_import']['cmb-field-0']) || $form_data['enable_pdf_import']['cmb-field-0'])) && $pdf_file_id) {
             do_action(PDF_LIGHT_VIEWER_PLUGIN . ':before_import_scheduled', $pdf_file_path);
             $jpeg_compression_quality = isset($form_data['jpeg_compression_quality']) ? $form_data['jpeg_compression_quality'] : get_post_meta($post_id, 'jpeg_compression_quality', true);
             $jpeg_resolution = isset($form_data['jpeg_resolution']) ? $form_data['jpeg_resolution'] : get_post_meta($post_id, 'jpeg_resolution', true);
             $pdf_upload_dir = PdfLightViewer_Plugin::createUploadDirectory($post_id);
             // delete all files
             self::delete_pages_by_pdf_id($post_id, $pdf_upload_dir);
             if (class_exists('Imagick')) {
                 $im = new Imagick();
                 $im->readImage($pdf_file_path);
                 $pages_number = $im->getNumberImages();
                 foreach ($im as $_img) {
                     $geometry = $_img->getImageGeometry();
                     $width = $geometry['width'];
                     $height = $geometry['height'];
                     break;
                 }
                 $im->destroy();
                 update_post_meta($post_id, '_pdf-light-viewer-import-status', static::STATUS_SCHEDULED);
                 update_post_meta($post_id, '_pdf-light-viewer-import-progress', 0);
                 update_post_meta($post_id, '_pdf-light-viewer-import-current-page', 1);
                 update_post_meta($post_id, 'pdf-pages-number', $pages_number);
                 update_post_meta($post_id, 'pdf-page-width', $width);
                 update_post_meta($post_id, 'pdf-page-height', $height);
                 PdfLightViewer_AdminController::showMessage(sprintf(__('PDF import scheduled.', PDF_LIGHT_VIEWER_PLUGIN), PdfLightViewer_Plugin::getSettingsUrl()), false);
             } else {
                 PdfLightViewer_AdminController::showMessage(sprintf(__('Imagick not found, please check other requirements on <a href="%s">plugin settings page</a> for more information.', PDF_LIGHT_VIEWER_PLUGIN), PdfLightViewer_Plugin::getSettingsUrl()), true);
             }
         }
     }
     unset($_REQUEST['enable_pdf_import']);
     unset($_POST['enable_pdf_import']);
 }