comicpress-core/classes/ComicPressBackend.inc
2009-12-09 08:21:15 -05:00

64 lines
1.5 KiB
PHP

<?php
class ComicPressBackend {
function _embed_image($size) {
$size = $this->ensure_type($size);
$extras = array();
$dims = $this->dims($size);
if (!empty($dims)) {
if (is_array($dims)) {
$extras = array_merge($extras, $dims);
}
}
foreach ($extras as $field => $value) {
if (!empty($value)) {
$extras[] = "${field}=\"${value}\" ";
}
unset($extras[$field]);
}
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url($size), $this->alt(), $this->title(), implode("", $extras));
return apply_filters('comicpress_embed_image', $output, $this);
}
function generate_from_id($id) {
$comicpress = ComicPress::get_instance();
foreach ($comicpress->backends as $backend) {
$result = call_user_func(array($backend, 'generate_from_id'), $id);
if ($result !== false) {
return $result;
}
}
return false;
}
function ensure_type($type) {
if (is_null($type)) {
$comicpress = ComicPress::get_instance();
if (is_null($type)) {
$type = $comicpress->get_default_image_type();
}
}
return $type;
}
function embed($type = null) { return $this->_embed_image($this->ensure_type($type)); }
function get_info($size = null) {
$size = $this->ensure_type($size);
$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;
}
}