Ejemplo n.º 1
0
 /**
  * Constructs instance of Document.
  *
  * @param WP_Post $attachment Attachment object used to initalize fields.
  * @param DG_Gallery $gallery Instance of Gallery class.
  */
 public function __construct($attachment, $gallery)
 {
     // init general document data
     $this->gallery = $gallery;
     $this->description = wptexturize($attachment->post_content);
     $this->ID = $attachment->ID;
     $this->link = $gallery->linkToAttachmentPg() ? get_attachment_link($attachment->ID) : wp_get_attachment_url($attachment->ID);
     $this->title = wptexturize($attachment->post_title);
     $this->title_attribute = esc_attr(strip_tags($this->title));
     $this->path = get_attached_file($attachment->ID);
     $wp_filetype = wp_check_filetype_and_ext($this->path, basename($this->path));
     $this->extension = $wp_filetype['ext'];
     $this->size = size_format(filesize($this->path));
 }
Ejemplo n.º 2
0
 /**
  * Initializes static values for this class.
  */
 public static function init()
 {
     if (!isset(self::$comment)) {
         self::$comment = PHP_EOL . '<!-- ' . __('Generated using Document Gallery. Get yours here: ', 'document-gallery') . 'http://wordpress.org/extend/plugins/document-gallery -->' . PHP_EOL;
         self::$no_docs = '<!-- ' . __('No attachments to display. How boring! :(', 'document-gallery') . ' -->';
         self::$unary_err = __('The %s value entered, "%s", is not valid.', 'document-gallery');
         self::$binary_err = __('The %s parameter may only be "%s" or "%s." You entered "%s."', 'document-gallery');
     }
 }
/**
 * Validate settings for the tab.
 */
function dg_validate_settings($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']) {
        DG_Thumb::purgeThumbs();
    }
    // 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) {
        DG_Thumb::purgeFailedThumbs();
    }
    // handle modified CSS
    if (trim($ret['css']['text']) !== trim($values['css'])) {
        $ret['css']['text'] = trim($values['css']);
    }
    return $ret;
}
 /**
  * Sanitize the given key/value pair, passing any error to $errs if given.
  *
  * @param string $key The key to reference the current value in the defaults array.
  * @param mixed $value The value to be sanitized.
  * @param string[] $errs The array of errors, which will be appended with any errors found.
  *
  * @return mixed The sanitized value, falling back to the current default value when invalid value given.
  */
 public static function sanitizeParameter($key, $value, &$errs = null)
 {
     // all sanitize methods must be in the following form: sanitize<UpperCamelCaseKey>
     $funct = $key;
     $funct[0] = strtoupper($funct[0]);
     $funct = 'sanitize' . preg_replace_callback('/_([a-z])/', array(__CLASS__, 'secondCharToUpper'), $funct);
     $callable = array(__CLASS__, $funct);
     // avoid looking for method beforehand unless we're running in debug mode -- expensive call
     if (DG_Logger::logEnabled() && !method_exists(__CLASS__, $funct)) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Attempted to call invalid function: ', 'document-gallery') . implode('::', $callable), true);
     }
     // call param-specific sanitization
     $ret = call_user_func_array($callable, array($value, &$err));
     // check for error and return default
     if (isset($err)) {
         $defaults = DG_Gallery::getOptions();
         $ret = $defaults[$key];
         if (!is_null($errs)) {
             $errs[$key] = $err;
         }
     }
     return $ret;
 }
 /**
  * Initializes static values for this class.
  */
 public static function init()
 {
     if (!isset(self::$comment)) {
         self::$comment = PHP_EOL . '<!-- ' . __('Generated using Document Gallery. Get yours here: ', 'document-gallery') . 'http://wordpress.org/extend/plugins/document-gallery -->' . PHP_EOL;
         self::$no_docs = '<!-- ' . __('No attachments to display. How boring! :(', 'document-gallery') . ' -->';
         self::$defaults = array_merge(array('include' => '', 'exclude' => ''), self::getOptions());
     }
 }
				<?php 
}
?>
			</select></td>
		</tr></table>
	</label>

	<label class="setting">
		<table><tr>
			<td><span><?php 
_e('Ascending or descending sorting of documents', 'document-gallery');
?>
</span></td>
			<td><select class="order" name="order" data-setting="order">
				<?php 
foreach (DG_Gallery::getOrderOptions() as $i) {
    ?>
					<option value="<?php 
    echo esc_attr($i);
    ?>
" <#
						if ( '<?php 
    echo $i;
    ?>
' == documentGalleryDefaults.order ) { #>selected="selected"<# }
					#>>
						<?php 
    echo esc_html($i);
    ?>
					</option>
				<?php