comicpress-core/classes/ComicPressBackend.inc

64 lines
1.5 KiB
PHP
Raw Normal View History

2009-11-09 03:11:26 +00:00
<?php
class ComicPressBackend {
function _embed_image($size) {
2009-12-09 13:21:15 +00:00
$size = $this->ensure_type($size);
2009-11-09 03:11:26 +00:00
$extras = array();
2009-11-11 13:46:26 +00:00
$dims = $this->dims($size);
if (!empty($dims)) {
if (is_array($dims)) {
$extras = array_merge($extras, $dims);
}
2009-11-09 03:11:26 +00:00
}
2009-11-12 03:07:34 +00:00
2009-11-09 03:11:26 +00:00
foreach ($extras as $field => $value) {
2009-11-16 17:35:48 +00:00
if (!empty($value)) {
$extras[] = "${field}=\"${value}\" ";
}
2009-11-09 03:11:26 +00:00
unset($extras[$field]);
}
2009-12-09 13:21:15 +00:00
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url($size), $this->alt(), $this->title(), implode("", $extras));
2009-11-09 03:11:26 +00:00
return apply_filters('comicpress_embed_image', $output, $this);
}
2009-11-12 03:07:34 +00:00
function generate_from_id($id) {
$comicpress = ComicPress::get_instance();
foreach ($comicpress->backends as $backend) {
2009-11-13 01:25:46 +00:00
$result = call_user_func(array($backend, 'generate_from_id'), $id);
2009-11-12 03:07:34 +00:00
if ($result !== false) {
return $result;
}
}
return false;
}
2009-12-09 13:21:15 +00:00
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;
}
2009-11-13 01:25:46 +00:00
}