comicpress-core/classes/backends/ComicPressBackendAttachment...

111 lines
2.9 KiB
PHP
Raw Normal View History

2009-11-04 02:45:56 +00:00
<?php
2009-11-09 03:11:26 +00:00
require_once(dirname(__FILE__) . '/../ComicPressBackend.inc');
class ComicPressBackendAttachment extends ComicPressBackend {
var $root_id = 'attachment';
2009-11-13 21:15:36 +00:00
var $source_name = "Post attachment";
2009-11-09 03:11:26 +00:00
function generate_from_post($post) {
$result = array();
if (is_object($post)) {
if (isset($post->ID)) {
$children = get_children(array(
2009-11-16 17:35:48 +00:00
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image'
));
2009-11-09 03:11:26 +00:00
2009-11-16 17:35:48 +00:00
if (!empty($children)) {
foreach ($children as $child) {
$meta = get_post_meta($child->ID, 'comicpress', true);
if (isset($meta['managed'])) {
if ($meta['managed']) {
$result[] = new ComicPressBackendAttachment($child);
}
}
}
}
2009-11-09 03:11:26 +00:00
}
}
return $result;
}
2009-11-16 17:35:48 +00:00
function ComicPressBackendAttachment($attachment) {
$this->attachment = $attachment;
$this->id = sprintf('%s-%d', $this->root_id, $this->attachment->ID);
$this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true);
}
function dims($size = 'comic') {
$comicpress = ComicPress::get_instance();
2009-11-04 02:45:56 +00:00
2009-11-16 17:35:48 +00:00
$dims = array();
if (isset($comicpress->comicpress_options['image_types'])) {
if ($size == 'default') {
foreach ($comicpress->comicpress_options['image_types'] as $type => $info) {
if ($info['default']) { $size = $type; break; }
}
}
2009-11-16 17:35:48 +00:00
if (isset($comicpress->comicpress_options['image_types'][$size])) {
if (isset($comicpress->comicpress_options['image_types'][$size]['dimensions'])) {
$dims = array_combine(array('width', 'height'), explode("x", $comicpress->comicpress_options['image_types'][$size]['dimensions']));
}
}
}
2009-11-04 02:45:56 +00:00
2009-11-16 17:35:48 +00:00
return $dims;
}
2009-11-09 03:11:26 +00:00
2009-11-16 17:35:48 +00:00
function url($size = 'comic') {
$metadata = image_downsize($this->attachment->ID, $size);
if (!empty($metadata)) {
if (is_array($metadata)) {
return $metadata[0];
}
}
return false;
}
2009-11-12 03:12:27 +00:00
2009-11-16 17:35:48 +00:00
// @codeCoverageIgnoreStart
function embed($size = 'comic') { return $this->_embed_image($size); }
function file($size = 'comic') { return $this->attachment->guid; }
function alt() { return $this->attachment->post_title; }
function title() { return $this->attachment->post_excerpt; }
// @codeCoverageIgnoreEnd
2009-11-12 03:31:36 +00:00
2009-11-16 17:35:48 +00:00
function get_info($size = 'comic') {
$info = array();
foreach (array('dims', 'url', 'file') as $field) {
$result = $this->{$field}($size);
if (is_array($result)) {
$info = array_merge($info, $result);
} else {
$info[$field] = $result;
}
}
return $info;
}
function generate_from_id($id) {
if (strpos($id, 'attachment-') === 0) {
$id = str_replace('attachment-', '', $id);
if (is_numeric($id)) {
$post = get_post($id);
if (!empty($post)) {
$meta = get_post_meta($post->ID, 'comicpress', true);
if (isset($meta['managed'])) {
if ($meta['managed']) {
return new ComicPressBackendAttachment($post);
}
}
}
}
}
return false;
}
2009-11-04 02:45:56 +00:00
}
2009-11-16 17:35:48 +00:00
?>