__( 'General', 'document-gallery' ), 'Thumbnail' => __( 'Thumbnail Management', 'document-gallery' ), 'Logging' => __( 'Logging', 'document-gallery' ), 'Advanced' => __( 'Advanced', 'document-gallery' ) ); } return self::$tabs; } /** * Renders Document Gallery options page. */ public static function renderOptions() { ?>

' . __( 'Settings', 'document-gallery' ) . ''; array_unshift( $links, $settings ); return $links; } /** * Adds donate link to main plugin view. */ public static function addDonateLink( $links, $file ) { if ( $file === DG_BASENAME ) { global $dg_options; $donate = '' . ' ' . __( 'Donate', 'document-gallery' ) . ''; $links[] = $donate; } return $links; } /** * Adds Document Gallery settings page to admin navigation. */ public static function addAdminPage() { DG_Admin::$hook = add_options_page( __( 'Document Gallery Settings', 'document-gallery' ), __( 'Document Gallery', 'document-gallery' ), 'manage_options', DG_OPTION_NAME, array( __CLASS__, 'renderOptions' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueueScriptsAndStyles' ) ); } /** * Enqueues styles and scripts for the admin settings page. */ public static function enqueueScriptsAndStyles( $hook ) { if ( in_array( $hook, array( DG_Admin::$hook, 'post.php', 'post-new.php' ), true ) ) { // Settings Page DG_Util::enqueueAsset( 'document-gallery-admin', 'assets/css/admin.css' ); // gracefully degrade for older WP versions if ( version_compare( get_bloginfo( 'version' ), '3.8', '<' ) ) { ?> wp_max_upload_size() ) ); if ( $hook !== self::$hook ) { //if $hook is 'post.php' or 'post-new.php' wp_localize_script( 'document-gallery-admin', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); // Media Manager global $dg_options; DG_Util::enqueueAsset( 'document-gallery-media-manager', 'assets/js/media_manager.js', array( 'media-views' ) ); wp_localize_script( 'document-gallery-media-manager', 'DGl10n', array( 'documentGalleryMenuTitle' => __( 'Create Document Gallery', 'document-gallery' ), 'documentGalleryButton' => __( 'Create a new Document Gallery', 'document-gallery' ), 'cancelDocumentGalleryTitle' => '← ' . __( 'Cancel Document Gallery', 'document-gallery' ), 'updateDocumentGallery' => __( 'Update Document Gallery', 'document-gallery' ), 'insertDocumentGallery' => __( 'Insert Document Gallery', 'document-gallery' ), 'addToDocumentGallery' => __( 'Add to Document Gallery', 'document-gallery' ), 'addToDocumentGalleryTitle' => __( 'Add to Document Gallery', 'document-gallery' ), 'editDocumentGalleryTitle' => __( 'Edit Document Gallery', 'document-gallery' ) ) ); wp_localize_script( 'document-gallery-media-manager', 'documentGalleryDefaults', $dg_options['gallery'] ); } } } /** * Load Document Gallery Custom templates. */ public static function loadCustomTemplates() { include_once DG_PATH . 'admin/media-manager-template.php'; } /** * Registers settings for the Document Gallery options page. */ public static function registerSettings() { if ( empty( $_REQUEST['tab'] ) || ! array_key_exists( $_REQUEST['tab'], self::getTabs() ) ) { reset( self::getTabs() ); self::$current = key( self::getTabs() ); } else { self::$current = $_REQUEST['tab']; } register_setting( DG_OPTION_NAME, DG_OPTION_NAME, array( __CLASS__, 'validateSettings' ) ); $funct = 'register' . self::$current . 'Settings'; DG_Admin::$funct(); } /** * Registers settings for the general tab. */ private static function registerGeneralSettings() { global $dg_options; include_once DG_PATH . 'inc/class-gallery.php'; include_once DG_PATH . 'inc/class-thumber.php'; $defaults = $dg_options['gallery']; $active = $dg_options['thumber']['active']; add_settings_section( 'gallery_defaults', __( 'Default Settings', 'document-gallery' ), array( __CLASS__, 'renderDefaultSettingsSection' ), DG_OPTION_NAME ); add_settings_section( 'thumbnail_generation', __( 'Thumbnail Generation', 'document-gallery' ), array( __CLASS__, 'renderThumberSection' ), DG_OPTION_NAME ); add_settings_section( 'css', __( 'Custom CSS', 'document-gallery' ), array( __CLASS__, 'renderCssSection' ), DG_OPTION_NAME ); add_settings_field( 'gallery_defaults_attachment_pg', 'attachment_pg', array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_attachment_pg', 'name' => 'gallery_defaults][attachment_pg', 'value' => esc_attr( $defaults['attachment_pg'] ), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Link to attachment page rather than to file', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_columns', 'columns', array( __CLASS__, 'renderTextField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_columns', 'name' => 'gallery_defaults][columns', 'value' => esc_attr( $defaults['columns'] ), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __( 'The number of columns to display when not rendering descriptions.', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_descriptions', 'descriptions', array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_descriptions', 'name' => 'gallery_defaults][descriptions', 'value' => esc_attr( $defaults['descriptions'] ), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Include document descriptions', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_fancy', 'fancy', array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_fancy', 'name' => 'gallery_defaults][fancy', 'value' => esc_attr( $defaults['fancy'] ), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Use auto-generated document thumbnails', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_order', 'order', array( __CLASS__, 'renderSelectField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_order', 'name' => 'gallery_defaults][order', 'value' => esc_attr( $defaults['order'] ), 'options' => DG_Gallery::getOrderOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Ascending or descending sorting of documents', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_orderby', 'orderby', array( __CLASS__, 'renderSelectField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_orderby', 'name' => 'gallery_defaults][orderby', 'value' => esc_attr( $defaults['orderby'] ), 'options' => DG_Gallery::getOrderbyOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Which field to order documents by', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_relation', 'relation', array( __CLASS__, 'renderSelectField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_relation', 'name' => 'gallery_defaults][relation', 'value' => esc_attr( $defaults['relation'] ), 'options' => DG_Gallery::getRelationOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Whether matched documents must have all taxa_names (AND) or at least one (OR)', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_limit', 'limit', array( __CLASS__, 'renderTextField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_limit', 'name' => 'gallery_defaults][limit', 'value' => esc_attr( $defaults['limit'] ), 'type' => 'number" min="-1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __( 'Limit the number of documents included. -1 means no limit.', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_mime_types', 'mime_types', array( __CLASS__, 'renderTextField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_mime_types', 'name' => 'gallery_defaults][mime_types', 'value' => esc_attr( $defaults['mime_types'] ), 'type' => 'text', 'option_name' => DG_OPTION_NAME, 'description' => __( 'Comma-delimited list of MIME types.', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_new_window', 'new_window', array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_new_window', 'name' => 'gallery_defaults][new_window', 'value' => esc_attr( $defaults['new_window'] ), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Open thumbnail links in new window', 'document-gallery' ) . '.' ) ); add_settings_field( 'gallery_defaults_post_status', 'post_status', array( __CLASS__, 'renderSelectField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_post_status', 'name' => 'gallery_defaults][post_status', 'value' => esc_attr( $defaults['post_status'] ), 'options' => DG_Gallery::getPostStatuses(), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Which post status to look for when querying documents.', 'document-gallery' ) ) ); add_settings_field( 'gallery_defaults_post_type', 'post_type', array( __CLASS__, 'renderSelectField' ), DG_OPTION_NAME, 'gallery_defaults', array( 'label_for' => 'label_gallery_defaults_post_type', 'name' => 'gallery_defaults][post_type', 'value' => esc_attr( $defaults['post_type'] ), 'options' => DG_Gallery::getPostTypes(), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Which post type to look for when querying documents.', 'document-gallery' ) ) ); add_settings_field( 'thumbnail_generation_av', __( 'Audio/Video', 'document-gallery' ), array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'thumbnail_generation', array( 'label_for' => 'label_thumbnail_generation_av', 'name' => 'thumbnail_generation][av', 'value' => esc_attr( $active['av'] ), 'option_name' => DG_OPTION_NAME, 'description' => esc_html__( 'Locally generate thumbnails for audio & video files.', 'document-gallery' ) ) ); add_settings_field( 'thumbnail_generation_gs', 'Ghostscript', array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'thumbnail_generation', array( 'label_for' => 'label_thumbnail_generation_gs', 'name' => 'thumbnail_generation][gs', 'value' => esc_attr( $active['gs'] ), 'option_name' => DG_OPTION_NAME, 'description' => DG_Thumber::isGhostscriptAvailable() ? __( 'Use Ghostscript for faster local PDF processing (compared to Imagick).', 'document-gallery' ) : __( 'Your server is not configured to run Ghostscript.', 'document-gallery' ), 'disabled' => ! DG_Thumber::isGhostscriptAvailable() ) ); add_settings_field( 'thumbnail_generation_imagick', 'Imagick', array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'thumbnail_generation', array( 'label_for' => 'label_thumbnail_generation_imagick', 'name' => 'thumbnail_generation][imagick', 'value' => esc_attr( $active['imagick'] ), 'option_name' => DG_OPTION_NAME, 'description' => DG_Thumber::isImagickAvailable() ? __( 'Use Imagick to handle lots of filetypes locally.', 'document-gallery' ) : __( 'Your server is not configured to run Imagick.', 'document-gallery' ), 'disabled' => ! DG_Thumber::isImagickAvailable() ) ); add_settings_field( 'thumbnail_generation_width', __( 'Max Thumbnail Dimensions', 'document-gallery' ), array( __CLASS__, 'renderMultiTextField' ), DG_OPTION_NAME, 'thumbnail_generation', array( array( 'label_for' => 'label_advanced_width', 'name' => 'thumbnail_generation][width', 'value' => esc_attr( $dg_options['thumber']['width'] ), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => ' x ' ), array( 'label_for' => 'label_advanced_height', 'name' => 'thumbnail_generation][height', 'value' => esc_attr( $dg_options['thumber']['height'] ), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __( 'The max width and height (in pixels) that thumbnails will be generated.', 'document-gallery' ) ) ) ); } /** * Registers settings for the thumbnail management tab. */ private static function registerThumbnailSettings() { add_settings_section( 'thumbnail_table', '', array( __CLASS__, 'renderThumbnailSection' ), DG_OPTION_NAME ); } /** * Registers settings for the logging tab. */ private static function registerLoggingSettings() { add_settings_section( 'logging_table', '', array( __CLASS__, 'renderLoggingSection' ), DG_OPTION_NAME ); } /** * Registers settings for the advanced tab. */ private static function registerAdvancedSettings() { global $dg_options; add_settings_section( 'advanced', __( 'Advanced Thumbnail Generation', 'document-gallery' ), array( __CLASS__, 'renderAdvancedSection' ), DG_OPTION_NAME ); add_settings_field( 'advanced_logging_enabled', __( 'Logging Enabled', 'document-gallery' ), array( __CLASS__, 'renderCheckboxField' ), DG_OPTION_NAME, 'advanced', array( 'label_for' => 'label_advanced_logging_enabled', 'name' => 'logging_enabled', 'value' => esc_attr( $dg_options['logging']['enabled'] ), 'option_name' => DG_OPTION_NAME, 'description' => __( 'Whether to log debug and error information related to Document Gallery.', 'document-gallery' ) ) ); add_settings_field( 'advanced_logging_purge_interval', __( 'Logging Purge Interval', 'document-gallery' ), array( __CLASS__, 'renderTextField' ), DG_OPTION_NAME, 'advanced', array( 'label_for' => 'label_advanced_logging_purge_interval', 'name' => 'logging_purge_interval', 'value' => esc_attr( $dg_options['logging']['purge_interval'] ), 'type' => 'number" min="0" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __( 'Number of days to keep old log entries (0 disables purging).', 'document-gallery' ) ) ); add_settings_field( 'advanced_gs', __( 'Ghostscript Absolute Path', 'document-gallery' ), array( __CLASS__, 'renderTextField' ), DG_OPTION_NAME, 'advanced', array( 'label_for' => 'label_advanced_gs', 'name' => 'gs', 'value' => esc_attr( $dg_options['thumber']['gs'] ), 'option_name' => DG_OPTION_NAME, 'description' => $dg_options['thumber']['gs'] ? __( 'Successfully auto-detected the location of Ghostscript.', 'document-gallery' ) : __( 'Failed to auto-detect the location of Ghostscript.', 'document-gallery' ) ) ); add_settings_section( 'advanced_options_dump', __( 'Options Array Dump', 'document-gallery' ), array( __CLASS__, 'renderOptionsDumpSection' ), DG_OPTION_NAME ); } /** * Validates submitted options, sanitizing any invalid options. * * @param array $values User-submitted new options. * * @return array Sanitized new options. */ public static function validateSettings( $values ) { // NOTE: WP double-calls this function -- below logic prevents potential // side effects by processing a maximum of one call to validate // per page load, re-returning the previous result on any // subsequent calls. static $ret = null; if ( is_null( $ret ) ) { if ( empty( $values['tab'] ) || ! array_key_exists( $values['tab'], self::getTabs() ) ) { global $dg_options; return $dg_options; } else { if ( array_key_exists( 'ajax', $values ) ) { unset( $values['ajax'] ); define( 'DOING_AJAX', true ); } $funct = 'validate' . $values['tab'] . 'Settings'; unset( $values['tab'] ); $ret = DG_Admin::$funct( $values ); } } return $ret; } /** * Validates general settings, sanitizing any invalid options. * * @param array $values User-submitted new options. * * @return array Sanitized new options. */ private static function validateGeneralSettings( $values ) { global $dg_options; $ret = $dg_options; include_once DG_PATH . 'inc/class-gallery.php'; $thumbs_cleared = false; // handle gallery shortcode defaults $errs = array(); $ret['gallery'] = DG_Gallery::sanitizeDefaults( null, $values['gallery_defaults'], $errs ); foreach ( $errs as $k => $v ) { add_settings_error( DG_OPTION_NAME, str_replace( '_', '-', $k ), $v ); } // handle setting width if ( isset( $values['thumbnail_generation']['width'] ) ) { $width = (int) $values['thumbnail_generation']['width']; if ( $width > 0 ) { $ret['thumber']['width'] = $width; } else { add_settings_error( DG_OPTION_NAME, 'thumber-width', __( 'Invalid width given: ', 'document-gallery' ) . $values['thumbnail_generation']['width'] ); } unset( $values['thumbnail_generation']['width'] ); } // handle setting height if ( isset( $values['thumbnail_generation']['height'] ) ) { $height = (int) $values['thumbnail_generation']['height']; if ( $height > 0 ) { $ret['thumber']['height'] = $height; } else { add_settings_error( DG_OPTION_NAME, 'thumber-height', __( 'Invalid height given: ', 'document-gallery' ) . $values['thumbnail_generation']['height'] ); } unset( $values['thumbnail_generation']['width'] ); } // delete thumb cache to force regeneration if max dimensions changed if ( $ret['thumber']['width'] !== $dg_options['thumber']['width'] || $ret['thumber']['height'] !== $dg_options['thumber']['height'] ) { foreach ( $ret['thumber']['thumbs'] as $v ) { if ( isset( $v['thumber'] ) ) { @unlink( $v['thumb_path'] ); } } $ret['thumber']['thumbs'] = array(); $thumbs_cleared = true; } // handle setting the active thumbers foreach ( array_keys( $ret['thumber']['active'] ) as $k ) { $ret['thumber']['active'][ $k ] = isset( $values['thumbnail_generation'][ $k ] ); } // if new thumbers available, clear failed thumbnails for retry if ( ! $thumbs_cleared ) { foreach ( $dg_options['thumber']['active'] as $k => $v ) { if ( ! $v && $ret['thumber']['active'][ $k ] ) { foreach ( $dg_options['thumber']['thumbs'] as $k2 => $v2 ) { if ( empty( $v['thumber'] ) ) { unset( $ret['thumber']['thumbs'][ $k2 ] ); } } break; } } } // handle modified CSS if ( trim( $ret['css']['text'] ) !== trim( $values['css'] ) ) { $ret['css']['text'] = trim( $values['css'] ); } return $ret; } /** * Validates thumbnail management settings, sanitizing any invalid options. * * @param array $values User-submitted new options. * * @return array Sanitized new options. */ private static function validateThumbnailSettings( $values ) { global $dg_options; $ret = $dg_options; $responseArr = array( 'result' => false ); if ( isset( $values['entry'] ) ) { $ID = intval( $values['entry'] ); } else { $ID = - 1; } // Thumbnail(s) cleanup; // cleanup value is a marker if ( isset( $values['cleanup'] ) && isset( $values['ids'] ) ) { $deleted = array_values( array_intersect( array_keys( $dg_options['thumber']['thumbs'] ), $values['ids'] ) ); foreach ( $deleted as $k ) { if ( isset( $ret['thumber']['thumbs'][ $k ]['thumber'] ) ) { @unlink( $ret['thumber']['thumbs'][ $k ]['thumb_path'] ); } unset( $ret['thumber']['thumbs'][ $k ] ); } $responseArr['result'] = true; $responseArr['deleted'] = $deleted; } // Attachment title update // title value is a marker elseif ( isset( $values['title'] ) && $ID != - 1 ) { $attachment = array( 'ID' => $ID, 'post_title' => rawurldecode( addslashes( $values['title'] ) ) ); if ( wp_update_post( $attachment ) ) { $responseArr['result'] = true; } } // Attachment description update // description value is a marker elseif ( isset( $values['description'] ) && $ID != - 1 ) { $attachment = array( 'ID' => $ID, 'post_content' => rawurldecode( addslashes( $values['description'] ) ) ); if ( wp_update_post( $attachment ) ) { $responseArr['result'] = true; } } // Thumbnail file manual refresh (one at a time) // upload value is a marker elseif ( isset( $values['upload'] ) && isset( $_FILES['file'] ) && isset( $ret['thumber']['thumbs'][ $ID ] ) ) { $old_path = DG_Util::hasThumb( $ID ) ? $ret['thumber']['thumbs'][ $ID ]['thumb_path'] : null; $uploaded_filename = self::validateUploadedFile(); if ( $uploaded_filename && DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) { if ( ! is_null( $old_path ) && $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] !== $old_path ) { @unlink( $old_path ); } $responseArr['result'] = true; $responseArr['url'] = $dg_options['thumber']['thumbs'][ $ID ]['thumb_url']; $ret['thumber']['thumbs'][ $ID ] = $dg_options['thumber']['thumbs'][ $ID ]; } } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { @header( 'Content-Type: application/json; charset=' . get_option( 'blog_charset' ) ); echo wp_json_encode( $responseArr ); add_filter( 'wp_redirect', array( __CLASS__, '_exit' ), 1, 0 ); } return $ret; } /** * Validates uploaded file as a semi for potential thumbnail. * * @param string $var File field name. * * @return bool|string False on failure, path to temp file on success. */ public static function validateUploadedFile( $var = 'file' ) { // checking if any file was delivered if ( ! isset( $_FILES[ $var ] ) ) { return false; } // we gonna process only first one if ( ! is_array( $_FILES[ $var ]['error'] ) ) { $upload_err = $_FILES[ $var ]['error']; $upload_path = $_FILES[ $var ]['tmp_name']; $upload_size = $_FILES[ $var ]['size']; $upload_type = $_FILES[ $var ]['type']; $upload_name = $_FILES[ $var ]['name']; } else { $upload_err = $_FILES[ $var ]['error'][0]; $upload_path = $_FILES[ $var ]['tmp_name'][0]; $upload_size = $_FILES[ $var ]['size'][0]; $upload_type = $_FILES[ $var ]['type'][0]; $upload_name = $_FILES[ $var ]['name'][0]; } $info = getimagesize( $upload_path ); if ( $info ) { if ( $info['mime'] != $upload_type ) {// in DG_Thumber::getExt() we'll define and set appropriate extension DG_Logger::writeLog( DG_LogLevel::Warning, __( 'File extension doesn\'t match the MIME type of the image: ', 'document-gallery' ) . $upload_name . ' - ' . $info['mime'] ); } if ( $upload_size > wp_max_upload_size() ) { DG_Logger::writeLog( DG_LogLevel::Warning, __( 'Uploaded file size exceeds the allowable limit: ', 'document-gallery' ) . $upload_name . ' - ' . $upload_size . 'b' ); return false; } } else { DG_Logger::writeLog( DG_LogLevel::Warning, __( 'Uploaded file is not an image: ', 'document-gallery' ) . $upload_name ); return false; } if ( $upload_err == UPLOAD_ERR_OK && $upload_size > 0 ) { $temp_file = $upload_path; } else { DG_Logger::writeLog( DG_LogLevel::Error, __( 'Failed to get uploaded file: ', 'document-gallery' ) . $upload_err ); return false; } return $temp_file; } /** * Validates logging settings, sanitizing any invalid options. * * @param array $values User-submitted new options. * * @return array Sanitized new options. */ private static function validateLoggingSettings( $values ) { global $dg_options; if ( isset( $values['clearLog'] ) ) { DG_Logger::clearLog(); } return $dg_options; } /** * Validates advanced settings, sanitizing any invalid options. * * @param array $values User-submitted new options. * * @return array Sanitized new options. */ private static function validateAdvancedSettings( $values ) { global $dg_options; $ret = $dg_options; // handle setting the Ghostscript path if ( isset( $values['gs'] ) && 0 != strcmp( $values['gs'], $ret['thumber']['gs'] ) ) { if ( false === strpos( $values['gs'], ';' ) ) { $ret['thumber']['gs'] = $values['gs']; } else { add_settings_error( DG_OPTION_NAME, 'thumber-gs', __( 'Invalid Ghostscript path given: ', 'document-gallery' ) . $values['gs'] ); } } // logging settings $ret['logging']['enabled'] = isset( $values['logging_enabled'] ); if ( isset( $values['logging_purge_interval'] ) ) { $purge_interval = (int) $values['logging_purge_interval']; if ( $purge_interval >= 0 ) { $ret['logging']['purge_interval'] = $purge_interval; } else { add_settings_error( DG_OPTION_NAME, 'thumber-logging-purge-interval', __( 'Invalid logging purge interval given: ', 'document-gallery' ) . $values['logging_purge_interval'] ); } } return $ret; } /** * @return bool Whether to register settings. */ public static function doRegisterSettings() { if ( ! is_multisite() ) { $script = ! empty( $GLOBALS['pagenow'] ) ? $GLOBALS['pagenow'] : null; } else { $script = parse_url( $_SERVER['REQUEST_URI'] ); $script = basename( $script['path'] ); } return ! empty( $script ) && ( 'options-general.php' === $script || 'options.php' === $script ); } /** * Render the Default Settings section. */ public static function renderDefaultSettingsSection() { ?>

style.css.', 'document-gallery' ), DG_URL . 'assets/css/style.css' ); ?>

really know what you\'re doing, you should not touch these values.', 'document-gallery' ); ?>

exec() is not accessible. Ghostscript will not function.', 'document-gallery' ); ?>

readonly text should be provided when reporting a bug:', 'documet-gallery' ); ?>

DG_OPTION_NAME, 'tab' => 'Thumbnail' ); $orderby = self::$URL_params['orderby'] = self::getOrderbyParam($orderby_options); $order = self::$URL_params['order'] = self::getOrderParam($order_options); $limit = self::$URL_params['limit'] = self::getLimitParam($limit_options); $thumbs = $options['thumbs']; uasort( $thumbs, array( __CLASS__, 'cmpThumb' ) ); $thumbs_number = count( $options['thumbs'] ); $lastsheet = ceil( $thumbs_number / $limit ); $sheet = array_key_exists( 'sheet', $_REQUEST ) ? absint( $_REQUEST['sheet'] ) : 1; if ( $sheet === 0 || $sheet > $lastsheet ) { $sheet = 1; } $offset = ( $sheet - 1 ) * $limit; $thumbs = array_slice( $thumbs, $offset, $limit, true ); // https://core.trac.wordpress.org/ticket/12212 $posts = array(); if ( ! empty( $thumbs ) ) { $posts = get_posts( array( 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => - 1, 'post__in' => array_keys( $thumbs ), 'orderby' => 'post__in' ) ); } foreach ( $posts as $post ) { $path_parts = pathinfo( $post->guid ); $t = &$thumbs[$post->ID]; $t['title'] = !empty( $post->post_title ) ? $post->post_title : $path_parts['filename']; $t['ext'] = array_key_exists( 'extension', $path_parts ) ? $path_parts['extension'] : ''; $t['description'] = $post->post_content; $t['icon'] = array_key_exists( 'thumb_url', $t ) ? $t['thumb_url'] : DG_Thumber::getDefaultThumbnail( $post->ID ); } unset( $posts ); $select_limit = ''; foreach ( $limit_options as $l_o ) { $select_limit .= '' . PHP_EOL; } $thead = '' . '' . '' . '' . '' . '' . __( 'Thumbnail', 'document-gallery' ) . '' . '' . __( 'File name', 'document-gallery' ) . '' . '' . __( 'Description', 'document-gallery' ) . '' . '' . '' . __( 'Date', 'document-gallery' ) . '' . ''; $pagination = '
' . '' . $thumbs_number . ' ' . _n( 'item', 'items', $thumbs_number ) . '' . ( $lastsheet > 1 ? '' . '«' . '' . '' . ' ' . __( 'of', 'document-gallery' ) . ' ' . $lastsheet . '' . '' . '»' . '' : ' | ' ) . ' ' . __( 'items per page', 'document-gallery' ) . '' . '
' . '
'; ?>
$thumb ) { $icon = $thumb['icon']; $title = $thumb['title']; $ext = $thumb['ext']; $description = $thumb['description']; $date = DocumentGallery::localDateTimeFromTimestamp( $thumb['timestamp'] ); ?>
">
Drop file here or
Thumbnail for Document Gallery', 'document-gallery' ), array( __CLASS__, 'renderMetaBox' ), $screen, 'normal' ); } add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueueScriptsAndStyles' ) ); } /** * Render a Meta Box. */ public static function renderMetaBox( $post ) { global $dg_options; wp_nonce_field( DG_OPTION_NAME . '_meta_box', DG_OPTION_NAME . '_meta_box_nonce' ); $ID = $post->ID; $icon = isset( $dg_options['thumber']['thumbs'][ $ID ]['thumb_url'] ) ? $dg_options['thumber']['thumbs'][ $ID ]['thumb_url'] : DG_Thumber::getDefaultThumbnail( $ID ); echo '' . '
' . '' . '' . '' . 'Drop file here or ' . '' . '' . '' . '' . '' . '
' . ( empty( $dg_options['thumber']['thumbs'][ $ID ] ) ? 'Please note this attachment hasn't been used in any Document Gallery instance and so there is no autogenerated thumbnail, in the meantime default one is used instead.' : '' ) . PHP_EOL; } /** * Save a Meta Box. */ public static function saveMetaBox( $post_id ) { // Check if our nonce is set. // Verify that the nonce is valid. // If this is an autosave, our form has not been submitted, so we don't want to do anything. if ( ! isset( $_POST[ DG_OPTION_NAME . '_meta_box_nonce' ] ) || ! wp_verify_nonce( $_POST[ DG_OPTION_NAME . '_meta_box_nonce' ], DG_OPTION_NAME . '_meta_box' ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) { return; } global $dg_options; $responseArr = array( 'result' => false ); if ( isset( $_POST[ DG_OPTION_NAME ]['entry'] ) ) { $ID = intval( $_POST[ DG_OPTION_NAME ]['entry'] ); } else { $ID = - 1; } if ( isset( $_POST[ DG_OPTION_NAME ]['upload'] ) && isset( $_FILES['file'] ) && isset( $dg_options['thumber']['thumbs'][ $ID ] ) ) { $old_path = DG_Util::hasThumb($ID) ? $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] : null; $uploaded_filename = self::validateUploadedFile(); if ( $uploaded_filename && DG_Thumber::setThumbnail( $ID, $uploaded_filename ) ) { if ( ! is_null($old_path) && $dg_options['thumber']['thumbs'][ $ID ]['thumb_path'] !== $old_path ) { @unlink( $old_path ); } $responseArr['result'] = true; $responseArr['url'] = $dg_options['thumber']['thumbs'][ $ID ]['thumb_url']; } } if ( isset( $_POST[ DG_OPTION_NAME ]['ajax'] ) ) { wp_send_json( $responseArr ); } } /** * Render the Logging table. */ public static function renderLoggingSection() { $log_list = DG_Logger::readLog(); if ( $log_list ) { $levels = array_map( array( __CLASS__, 'getLogLabelSpan' ), array_keys( DG_LogLevel::getLogLevels() ) ); $fmt = '' . '' . '%s' . '' . '%s' . '%s' . ''; $thead = sprintf( $fmt, __( 'Date', 'document-gallery' ), __( 'Level', 'document-gallery' ), __( 'Message', 'document-gallery' ) ); ?>
0; $i -- ) { $log_entry = $log_list[ $i - 1 ]; $date = DocumentGallery::localDateTimeFromTimestamp( $log_entry[0] ); // convert attachment names to links $log_entry[2] = preg_replace( '/[ ^](attachment #)(\d+)[.,: ]/i', ' \1\2 ', $log_entry[2] ); // bold the place where log entry was submitted $log_entry[2] = preg_replace( '/^(\((?:\w+(?:::|->))?\w+\)) /', '\1 ', $log_entry[2] ); // italicize any function references within log entry $log_entry[2] = preg_replace( '/(\(?\w+(?:::|->)\w+\)?)/m', '\1', $log_entry[2] ); echo '' . '' . '' . '' . PHP_EOL; } ?>
' . $date . '' . $levels[ $log_entry[1] ] . '' . ( empty( $log_entry[3] ) ? '
' . $log_entry[2] . '
' : '
' . $log_entry[2] . '
' . $log_entry[3] . '
' ) . '
' . __( 'There are no log entries at this time.', 'document-gallery' ) . '
' . __( 'For Your information:', 'document-gallery' ) . ' ' . __( 'Logging', 'document-gallery' ) . ' ' . ( DG_Logger::logEnabled() ? '' . __( 'is turned ON', 'document-gallery' ) . '!' : '' . __( 'is turned OFF', 'document-gallery' ) . '!' ) . ''; } } /** * Takes label name and returns SPAN tag. * * @param string $e label name. * * @return string SPAN tag */ private static function getLogLabelSpan( $e ) { return '' . strtoupper( $e ) . ''; } /** * Render a checkbox field. * * @param array $args */ public static function renderCheckboxField( $args ) { $args['disabled'] = isset( $args['disabled'] ) ? $args['disabled'] : false; printf( '', $args['option_name'], $args['name'], $args['label_for'], checked( $args['value'], 1, false ), disabled( $args['disabled'], true, false ), $args['description'] ); } /** * Render a text field. * * @param array $args */ public static function renderTextField( $args ) { printf( ' %6$s', isset( $args['type'] ) ? $args['type'] : 'text', $args['value'], $args['option_name'], $args['name'], $args['label_for'], $args['description'] ); } /** * Accepts a two-dimensional array where each inner array consists of valid arguments for renderTextField. * * @param array $args */ public static function renderMultiTextField( $args ) { foreach ( $args as $arg ) { self::renderTextField( $arg ); } } /** * Render a select field. * * @param array $args */ public static function renderSelectField( $args ) { printf( ' ' . $args['description']; } /** * @param $t1 array Thumbnail array #1. * @param $t2 array Thumbnail array #2 * * @return int The result of comparing the two thumbnail arrays using arguments in $URL_params. */ public static function cmpThumb($t1, $t2) { $ret = 0; switch (self::$URL_params['orderby']) { case 'date': $ret = $t1['timestamp'] - $t2['timestamp']; break; case 'title': $ret = strcmp( basename( $t1['thumb_path'] ), basename( $t2['thumb_path'] ) ); break; } return 'asc' === self::$URL_params['order'] ? $ret : -$ret; } /** * Wraps the PHP exit language construct. */ public static function _exit() { exit; } /** * Blocks instantiation. All functions are static. */ private function __construct() { } }