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

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';
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) {
2009-11-11 03:12:47 +00:00
$meta = get_post_meta($child->ID, 'comicpress', true);
2009-11-11 03:15:06 +00:00
if (isset($meta['managed'])) {
if ($meta['managed']) {
$result[] = new ComicPressBackendAttachment($child);
}
2009-11-11 03:09:53 +00:00
}
2009-11-09 03:11:26 +00:00
}
}
}
}
return $result;
}
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);
2009-11-04 02:45:56 +00:00
}
2009-11-09 03:11:26 +00:00
function dims($size = 'comic') {
$metadata = image_downsize($this->attachment->ID, $size);
if (!empty($metadata)) {
if (is_array($metadata)) {
return array_combine(array('width', 'height'), array_slice($metadata, 1, 2));
}
}
return false;
2009-11-04 02:45:56 +00:00
}
2009-11-09 03:11:26 +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-04 02:45:56 +00:00
}
2009-11-09 03:11:26 +00:00
2009-11-11 04:11:48 +00:00
// @codeCoverageIgnoreStart
2009-11-12 03:31:36 +00:00
function embed($size = 'comic') { return $this->_embed_image($size); }
function file($size = 'comic') { return $this->attachment->guid; }
2009-11-09 03:11:26 +00:00
function alt() { return $this->attachment->post_title; }
function title() { return $this->attachment->post_excerpt; }
// @codeCoverageIgnoreEnd
2009-11-12 03:12:27 +00:00
2009-11-12 03:31:36 +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;
}
2009-11-12 03:12:27 +00:00
function generate_from_id($id) {
if (strpos($id, 'attachment-') === 0) {
$id = str_replace('attachment-', '', $id);
2009-11-12 03:12:27 +00:00
if (is_numeric($id)) {
$post = get_post($id);
if (!empty($post)) {
2009-11-12 03:31:36 +00:00
return new ComicPressBackendAttachment($post);
2009-11-12 03:12:27 +00:00
}
}
}
return false;
}
2009-11-04 02:45:56 +00:00
}
?>