__('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 ($hook !== DG_Admin::$hook) return; wp_enqueue_style('document-gallery-admin', DG_URL . 'assets/css/admin.css', null, DG_VERSION); wp_enqueue_script('document-gallery-admin', DG_URL . 'assets/js/admin.js', array('jquery'), DG_VERSION, true); wp_localize_script('document-gallery-admin', 'dg_admin_vars', array('upload_limit' => wp_max_upload_size())); if ($hook == 'post.php') { wp_localize_script('document-gallery-admin', 'ajax_object', array('ajax_url' => admin_url('admin-ajax.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_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', 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', 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', 'Logging', array(__CLASS__, 'renderCheckboxField'), DG_OPTION_NAME, 'advanced', array ( 'label_for' => 'label_advanced_logging', 'name' => 'logging', 'value' => esc_attr($dg_options['logging']), 'option_name' => DG_OPTION_NAME, 'description' => __('Whether to log debug and error information related to Document Gallery.', 'document-gallery') )); add_settings_field( 'advanced_validation', 'Option Validation', array(__CLASS__, 'renderCheckboxField'), DG_OPTION_NAME, 'advanced', array ( 'label_for' => 'label_advanced_validation', 'name' => 'validation', 'value' => esc_attr($dg_options['validation']), 'option_name' => DG_OPTION_NAME, 'description' => __('Whether option structure should be validated before save. This is not generally necessary.', 'document-gallery') )); add_settings_field( 'advanced_thumb_timeout', 'Thumbnail Generation Timeout', array(__CLASS__, 'renderTextField'), DG_OPTION_NAME, 'advanced', array ( 'label_for' => 'label_advanced_thumb_timeout', 'name' => 'timeout', 'value' => esc_attr($dg_options['thumber']['timeout']), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __('Max number of seconds to wait for thumbnail generation before defaulting to filetype icons.', 'document-gallery') . ' ' . __('Note that generation will continue where timeout happened next time the gallery is loaded.', 'document-gallery') . '')); add_settings_field( 'advanced_gs', 'Ghostscript Absolute Path', 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) { if (empty($values['tab']) || !array_key_exists($values['tab'], self::getTabs())) { reset(self::getTabs()); $values['tab'] = key(self::getTabs()); } $funct = 'validate'.$values['tab'].'Settings'; unset($values['tab']); return DG_Admin::$funct($values); } /** * 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 $k => $v) { if (empty($v['thumber'])) { unset($ret['thumber']['thumbs'][$k]); } } break; } } } // handle modified CSS if (trim($ret['css']['text']) !== trim($values['css'])) { $ret['css']['text'] = trim($values['css']); $ret['css']['minified'] = DocumentGallery::compileCustomCss($ret['css']['text']); } 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 = $ret['thumber']['thumbs'][$ID]['thumb_path']; $uploaded_filename = self::validateUploadedFile(); if ($uploaded_filename && DG_Thumber::setThumbnail($ID, $uploaded_filename)) { if ($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 (isset($values['ajax'])) { echo DG_Util::jsonEncode($responseArr); add_filter('wp_redirect', array(__CLASS__, '_exit'), 1, 0); } return $ret; } /** * Validates uploaded file as a semi for potential thumbnail. * @param str $var File field name. * @return bool|str 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']); } } // handle setting timeout if (isset($values['timeout'])) { $timeout = (int)$values['timeout']; if ($timeout > 0) { $ret['thumber']['timeout'] = $timeout; } else { add_settings_error(DG_OPTION_NAME, 'thumber-timeout', __('Invalid timeout given: ', 'document-gallery') . $values['timeout']); } } // validation checkbox $ret['validation'] = isset($values['validation']); // logging checkbox $ret['logging'] = isset($values['logging']); 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.'), 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'); $att_ids = array(); if (isset($_REQUEST['orderby']) && in_array(strtolower($_REQUEST['orderby']), array('title', 'date'))) { $orderby = strtolower($_REQUEST['orderby']); $URL_params['orderby'] = $orderby; switch ($orderby) { case 'date': foreach ($options['thumbs'] as $key => $node) { $keyArray[$key] = $node['timestamp']; $options['thumbs'][$key]['thumb_id'] = $att_ids[] = $key; } break; case 'title': foreach ($options['thumbs'] as $key => $node) { $keyArray[$key] = basename($node['thumb_path']); $options['thumbs'][$key]['thumb_id'] = $att_ids[] = $key; } break; } $order = strtolower($_REQUEST['order']); if (!isset($_REQUEST['order']) || !in_array($order, array('asc', 'desc'))) { $order = 'asc'; } $URL_params['order'] = $order; if ($order == 'asc') { array_multisort($keyArray, SORT_ASC, $options['thumbs']); } else { array_multisort($keyArray, SORT_DESC, $options['thumbs']); } } else { $orderby = ''; foreach ($options['thumbs'] as $key => $node) { $options['thumbs'][$key]['thumb_id'] = $att_ids[] = $key; } } static $limit_options = array(10, 25, 75); if (!isset($_REQUEST['limit']) || !in_array(intval($_REQUEST['limit']), $limit_options)) { $limit = $limit_options[0]; } else { $limit = intval($_REQUEST['limit']); } $URL_params['limit'] = $limit; $select_limit = ''; foreach ($limit_options as $l_o) { $select_limit .= ''.PHP_EOL; } $thumbs_number = count($options['thumbs']); $lastsheet = ceil($thumbs_number/$limit); $sheet = isset($_REQUEST['sheet']) ? intval($_REQUEST['sheet']) : 1; if ($sheet <= 0 || $sheet > $lastsheet) { $sheet = 1; } $offset = ($sheet - 1) * $limit; $att_ids = array_slice($att_ids, $offset, $limit); // https://core.trac.wordpress.org/ticket/12212 $atts = array(); if (!empty($att_ids)) { $atts = get_posts( array( 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => -1, 'post__in' => $att_ids, 'orderby' => 'post__in' )); } $titles = array(); $contents = array(); foreach ($atts as $att) { $path_parts = pathinfo($att->guid); $titles[$att->ID] = $att->post_title; $types[$att->ID] = $path_parts['extension']; $contents[$att->ID] = $att->post_content; } unset($atts); $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').''. '
'. '
'; ?>
$offset + $limit) { break; } $icon = isset($v['thumb_url']) ? $v['thumb_url'] : DG_Thumber::getDefaultThumbnail($v['thumb_id']); $title = isset($titles[$v['thumb_id']]) ? $titles[$v['thumb_id']] : ''; $type = $types[$v['thumb_id']]; $description = $contents[$v['thumb_id']]; $date = DocumentGallery::localDateTimeFromTimestamp($v['timestamp']); echo ''.PHP_EOL; } ?>
'.'' . ($title ? ''.$title.' '.$type.'' : __('Attachment not found', 'document-gallery')) . '
'.$description.'
'. '
' . '' . '' . 'Drop file here or ' . '' . '' . '' . '' . '' . ''.$date.'
Thumbnail for Document Gallery', 'document-gallery' ), array(__CLASS__, 'renderMetaBox'), $screen, 'normal' ); } DG_Admin::$hook = 'post.php'; 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_options['thumber']['thumbs'][$ID]['thumb_path']; $uploaded_filename = self::validateUploadedFile(); if ($uploaded_filename && DG_Thumber::setThumbnail($ID, $uploaded_filename)) { if ($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'])) { echo DG_Util::jsonEncode($responseArr); wp_die(); } } /** * 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())); $thead = ''. ''.__('Date', 'document-gallery').''. ''.__('Level', 'document-gallery').''. ''.__('Message', 'document-gallery').''. ''; ?>
\1\2 ', $v[2]); // bold the place where log entry was submitted $v[2] = preg_replace('/^(\(\w+::\w+\)) /', '\1 ', $v[2]); // italicize any function references within log entry $v[2] = preg_replace('/(\(?\w+::\w+\)?)/m', '\1', $v[2]); echo '' . '' . '' . ''.PHP_EOL; } ?>
'.$date.''.$levels[$v[1]].''.(empty($v[3]) ? '
'.$v[2].'
' : '
'.$v[2].'
'.$v[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']; } /** * Wraps the PHP exit language construct. */ public static function _exit() { exit; } /** * Blocks instantiation. All functions are static. */ private function __construct() { } }