/**
 * Register settings for the tab.
 */
function dg_register_settings()
{
    global $dg_options;
    include_once DG_PATH . 'inc/class-gallery.php';
    include_once DG_PATH . 'inc/class-gallery-sanitization.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'), 'dg_render_default_settings_section', DG_OPTION_NAME);
    add_settings_section('thumbnail_generation', __('Thumbnail Generation', 'document-gallery'), 'dg_render_thumber_section', DG_OPTION_NAME);
    add_settings_section('css', __('Custom CSS', 'document-gallery'), 'dg_render_css_section', DG_OPTION_NAME);
    add_settings_field('gallery_defaults_attachment_pg', 'attachment_pg', array('DG_Admin', '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('DG_Admin', '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('DG_Admin', '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('DG_Admin', '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('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_order', 'name' => 'gallery_defaults][order', 'value' => esc_attr($defaults['order']), 'options' => DG_GallerySanitization::getOrderOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __('Ascending or descending sorting of documents.', 'document-gallery')));
    add_settings_field('gallery_defaults_orderby', 'orderby', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_orderby', 'name' => 'gallery_defaults][orderby', 'value' => esc_attr($defaults['orderby']), 'options' => DG_GallerySanitization::getOrderbyOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __('Which field to order documents by.', 'document-gallery')));
    add_settings_field('gallery_defaults_relation', 'relation', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_relation', 'name' => 'gallery_defaults][relation', 'value' => esc_attr($defaults['relation']), 'options' => DG_GallerySanitization::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('DG_Admin', '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('DG_Admin', '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 <a href="http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types">MIME types</a>.', 'document-gallery')));
    add_settings_field('gallery_defaults_new_window', 'new_window', array('DG_Admin', '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_paginate', 'paginate', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_paginate', 'name' => 'gallery_defaults][paginate', 'value' => esc_attr($defaults['paginate']), 'option_name' => DG_OPTION_NAME, 'description' => __('When a limit exists, paginate rather than truncating gallery.', 'document-gallery')));
    add_settings_field('gallery_defaults_post_status', 'post_status', array('DG_Admin', '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_GallerySanitization::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('DG_Admin', '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_GallerySanitization::getPostTypes(), 'option_name' => DG_OPTION_NAME, 'description' => __('Which post type to look for when querying documents.', 'document-gallery')));
    add_settings_field('thumbnail_generation_thumber-co', __('Thumber.co', 'document-gallery'), array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'thumbnail_generation', array('label_for' => 'label_thumbnail_generation_thumber-co', 'name' => 'thumbnail_generation][thumber-co', 'value' => esc_attr($active['thumber-co']), 'option_name' => DG_OPTION_NAME, 'description' => __('Use your <a href="http://thumber.co" target="_blank">Thumber.co</a> subscription to remotely generate document thumbnails.', 'document-gallery'), 'disabled' => !DG_ThumberCoThumber::isThumberCoAvailable()));
    add_settings_field('thumbnail_generation_av', __('Audio/Video', 'document-gallery'), array('DG_Admin', '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('DG_Admin', '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_GhostscriptThumber::isGhostscriptAvailable() ? __('Use <a href="http://www.ghostscript.com/" target="_blank">Ghostscript</a> for faster local PDF processing (compared to Imagick).', 'document-gallery') : __('Your server is not configured to run <a href="http://www.ghostscript.com/" target="_blank">Ghostscript</a>.', 'document-gallery'), 'disabled' => !DG_GhostscriptThumber::isGhostscriptAvailable()));
    add_settings_field('thumbnail_generation_imagick', 'Imagick', array('DG_Admin', '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_ImagickThumber::isImagickAvailable() ? __('Use <a href="http://www.php.net/manual/en/book.imagick.php" target="_blank">Imagick</a> to handle lots of filetypes locally.', 'document-gallery') : __('Your server is not configured to run <a href="http://www.php.net/manual/en/book.imagick.php" target="_blank">Imagick</a>.', 'document-gallery'), 'disabled' => !DG_ImagickThumber::isImagickAvailable()));
    add_settings_field('thumbnail_generation_width', __('Max Thumbnail Dimensions', 'document-gallery'), array('DG_Admin', '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'))));
}
 /**
  * The default DG options to be used on install and when validating structure of options.
  *
  * @param $skeleton bool When true, expensive values are not calculated. Only keys may be trusted when returning skeleton.
  *
  * @return mixed[][] Contains default options for DG.
  */
 public static function getDefaultOptions($skeleton = false)
 {
     include_once DG_PATH . 'inc/class-thumber.php';
     $gs = $donate_link = null;
     if (!$skeleton) {
         $gs = DG_GhostscriptThumber::getGhostscriptExecutable();
         $donate_link = self::getDonateLink();
     }
     return array('thumber' => array('gs' => $gs, 'active' => DG_Thumber::getDefaultThumbers($skeleton), 'width' => 200, 'height' => 200), 'thumber-co' => array('uid' => null, 'secret' => null, 'subscription' => array(), 'direct_upload' => false, 'mime_types' => array()), 'gallery' => array('attachment_pg' => false, 'columns' => 4, 'descriptions' => false, 'fancy' => true, 'limit' => -1, 'mime_types' => implode(',', self::getDefaultMimeTypes()), 'new_window' => false, 'order' => 'ASC', 'orderby' => 'menu_order', 'paginate' => true, 'post_status' => 'any', 'post_type' => 'attachment', 'relation' => 'AND', 'skip' => 0), 'css' => array('text' => ''), 'meta' => array('version' => DG_VERSION, 'items_per_page' => 10, 'donate_link' => $donate_link), 'logging' => array('enabled' => defined('WP_DEBUG') && WP_DEBUG, 'purge_interval' => 7));
 }
 /**
  * Returns the default mapping of thumber slug to whether it is active or not.
  *
  * @param $skeleton bool When true, values that require computation will be
  *        skipped. Useful when only structure of options is needed.
  *
  * @return bool[] The default thumbnail generation methods.
  */
 public static function getDefaultThumbers($skeleton = false)
 {
     $gs_active = $imagick_active = null;
     if (!$skeleton) {
         $gs_active = (bool) DG_GhostscriptThumber::getGhostscriptExecutable();
         $imagick_active = DG_ImagickThumber::isImagickAvailable();
     }
     return array('av' => true, 'gs' => $gs_active, 'imagick' => $imagick_active, 'thumber-co' => false);
 }
            // GoDaddy and others aren't setup in such a way that
            // the above works so we need to fallback to a direct
            // filesystem check in most common location
            exec('test -e /usr/bin/gs', $dummy, $ret);
            $executable = $ret === 0 ? '/usr/bin/gs' : false;
            return $executable;
        }
        return $executable;
    }
    /**
     * @return bool Whether we can use the GS executable.
     */
    public static function isGhostscriptAvailable()
    {
        static $ret = null;
        if (is_null($ret)) {
            $options = DG_Thumber::getOptions();
            $ret = $options['gs'] && self::isExecAvailable();
        }
        return $ret;
    }
    /**
     * @return int An integer from 0 to 100. Higher priorities will be attempted before lower priority thumbers.
     */
    public function getPriority()
    {
        return 75;
    }
}
DG_GhostscriptThumber::init();