comicpress-core/classes/backends/ComicPressBackendAttachment.inc

93 lines
2.4 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
2009-12-06 19:18:11 +00:00
function ComicPressBackendAttachment($attachment = null) {
2009-12-06 21:09:32 +00:00
$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);
2009-11-16 17:35:48 +00:00
}
2009-12-09 13:21:15 +00:00
function dims($size = null) {
$size = $this->ensure_type($size);
2009-11-16 17:35:48 +00:00
$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 (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
2009-12-09 13:21:15 +00:00
function file($size = null) { return $this->attachment->guid; }
2009-11-16 17:35:48 +00:00
function alt() { return $this->attachment->post_title; }
function title() { return $this->attachment->post_excerpt; }
// @codeCoverageIgnoreEnd
2009-12-06 21:09:32 +00:00
}
class ComicPressBackendAttachmentFactory {
function generate_from_post($post) {
$result = array();
if (is_object($post)) {
if (isset($post->ID)) {
$children = get_children(array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image'
));
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);
}
}
}
}
}
}
return $result;
}
2009-11-16 17:35:48 +00:00
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
}