/** * Adds the meta items_per_page default value. * Paginate & skip options were added. * Moving cached thumbs into postmeta table. * * @param mixed[][] $options The options to be modified. */ private static function fourPointZero(&$options) { if (version_compare($options['meta']['version'], '4.0', '<')) { $options['gallery']['paginate'] = true; $options['gallery']['skip'] = 0; $options['meta']['items_per_page'] = 10; $upload_dir = wp_upload_dir(); $upload_len = strlen($upload_dir['basedir']); $dimensions = $options['thumber']['width'] . 'x' . $options['thumber']['height']; foreach ($options['thumber']['thumbs'] as $id => $thumb) { $thumb_obj = new DG_Thumb(); $thumb_obj->setPostId($id); $thumb_obj->setTimestamp($thumb['timestamp']); $thumb_obj->setDimensions($dimensions); if (isset($thumb['thumb_path'])) { $thumb_obj->setRelativePath(substr($thumb['thumb_path'], $upload_len + 1)); $thumb_obj->setGenerator(DG_Util::callableToString($thumb['thumber'])); } $thumb_obj->save(); } unset($options['thumber']['thumbs']); } }
/** * @filter dg_thumbers Allows developers to filter the Thumbers used * for specific filetypes. Index is the regex to match file extensions * supported and the value is anything that can be accepted by call_user_func(). * The function must take two parameters, 1st is the int ID of the attachment * to get a thumbnail for, 2nd is the page to take a thumbnail of * (may not be relevant for some filetypes). * * @return array */ private static function getThumbers() { static $thumbers = null; if (is_null($thumbers)) { $options = self::getOptions(); $active = $options['active']; $thumbers = array(); // Audio/Video embedded images if ($active['av']) { $exts = implode('|', self::getAudioVideoExts()); $thumbers[$exts] = array(__CLASS__, 'getAudioVideoThumbnail'); } // Ghostscript if ($active['gs'] && self::isGhostscriptAvailable()) { $exts = implode('|', self::getGhostscriptExts()); $thumbers[$exts] = array(__CLASS__, 'getGhostscriptThumbnail'); } // Imagick if ($active['imagick'] && self::isImagickAvailable()) { include_once DG_PATH . 'inc/class-image-editor-imagick.php'; if ($exts = DG_Image_Editor_Imagick::query_formats()) { $exts = implode('|', $exts); $thumbers[$exts] = array(__CLASS__, 'getImagickThumbnail'); } } // allow users to filter thumbers used $thumbers = apply_filters('dg_thumbers', $thumbers); // strip out anything that can't be called $thumbers = array_filter($thumbers, 'is_callable'); // log which thumbers are being used if (DG_Logger::logEnabled()) { if (count($thumbers) > 0) { $entry = __('Thumbnail Generators: ', 'document-gallery'); foreach ($thumbers as $k => $v) { $thumber = DG_Util::callableToString($v); // TODO: The following works for all internal regexes, but may have unpredictable // results if developer adds additional thumbnail generators using different regexes $filetypes = str_replace('|', ', ', $k); $entry .= PHP_EOL . "{$thumber}: {$filetypes}"; } } else { $entry = __('No thumbnail generators enabled.', 'document-gallery'); } DG_Logger::writeLog(DG_LogLevel::Detail, $entry); } } return $thumbers; }