/** * Uses wp_read_video_metadata() and wp_read_audio_metadata() to retrieve * an embedded image to use as a thumbnail. * * @param string $ID The attachment ID to retrieve thumbnail from. * @param int $pg Unused. * * @return bool|string False on failure, URL to thumb on success. */ public function getThumbnail($ID, $pg = 1) { include_once DG_WPADMIN_PATH . 'includes/media.php'; $doc_path = get_attached_file($ID); $mime_type = get_post_mime_type($ID); if (DG_Util::startsWith($mime_type, 'video/')) { $metadata = wp_read_video_metadata($doc_path); } elseif (DG_Util::startsWith($mime_type, 'audio/')) { $metadata = wp_read_audio_metadata($doc_path); } // unsupported mime type || no embedded image present if (!isset($metadata) || empty($metadata['image']['data'])) { return false; } $ext = 'jpg'; switch ($metadata['image']['mime']) { case 'image/gif': $ext = 'gif'; break; case 'image/png': $ext = 'png'; break; } $temp_file = DG_Util::getTempFile($ext); if (!($fp = @fopen($temp_file, 'wb'))) { DG_Logger::writeLog(DG_LogLevel::Error, __('Could not open file: ', 'document-gallery') . $temp_file); return false; } if (!@fwrite($fp, $metadata['image']['data'])) { DG_Logger::writeLog(DG_LogLevel::Error, __('Could not write file: ', 'document-gallery') . $temp_file); fclose($fp); return false; } fclose($fp); return $temp_file; }
/** * Returns a list of x, where x may be any of the fields within a * term object, when provided with a list of term names (not slugs). * (http://codex.wordpress.org/Function_Reference/get_term_by#Return_Values) * * Also appends an entry onto $errs if any invalid names are found. * * @param string $x Field to retrieve from matched term. * @param string $taxon The taxon these terms are a member of. * @param string[] $term_idents Terms to retrieve, identified by either slug or name. * * @return WP_Term[] All matched terms. */ private function getTermXByNames($x, $taxon, $term_idents) { $ret = array(); $valid = true; // taxons may optionally be prefixed by 'tax_' -- // this is only useful when avoiding collisions with other attributes if (!taxonomy_exists($taxon)) { if (DG_Util::startsWith($taxon, 'tax_') && ($tmp = substr($taxon, 4)) && taxonomy_exists($tmp)) { $taxon = $tmp; } else { $this->errs[] = sprintf(DG_GallerySanitization::getUnaryErr(), 'taxon', $taxon); $valid = false; } } // only check terms if we first have a valid taxon if ($valid) { foreach ($term_idents as $ident) { $term = get_term_by('slug', $ident, $taxon); if (!$term) { $term = get_term_by('name', $ident, $taxon); } if ($term) { $ret[] = $term->{$x}; } else { $this->errs[] = sprintf(__('%s is not a valid term slug/name in %s.', 'document-gallery'), $ident, $taxon); } } } return $ret; }
/** * @return bool Whether this instance represents a successful thumb generation. */ public function isSuccess() { return !empty($this->relative_path) && !DG_Util::startsWith($this->getPath(), DG_PATH); }