comicpress-theme-core/classes/ComicPressComicPost.inc

87 lines
2.6 KiB
PHP
Raw Normal View History

<?php
class ComicPressComicPost {
var $post;
2009-07-11 00:27:36 +00:00
var $attachments = null;
var $comicpress;
function ComicPressComicPost($post = null, $comicpress = null) {
if (!is_null($post)) { $this->post = $post; }
if (!is_null($comicpress)) { $this->comicpress = $comicpress; }
}
function get_comic_image_attachments() {
2009-07-11 00:27:36 +00:00
if (is_null($this->attachments)) {
$this->attachments = get_children(array(
'post_parent' => $this->post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image'
));
}
return $this->attachments;
}
2009-07-13 02:31:14 +00:00
function display_attached_images($type = "comic", $limit = null, $size_type = null) {
if (is_null($size_type)) { $size_type = $type; }
$found = false;
if (is_array($this->get_comic_image_attachments())) {
2009-07-11 00:27:36 +00:00
foreach ($this->get_comic_image_attachments() as $attachment) {
2009-07-13 02:31:14 +00:00
if (get_post_meta($attachment->ID, "comic_image_type", true) == $type) {
2009-07-13 08:22:50 +00:00
$title = (!empty($attachment->post_excerpt) ? $attachment->post_excerpt : $attachment->post_title);
echo $this->get_comic_img_tag(wp_get_attachment_url($attachment->ID, ''), $size_type, array('title' => $title));
2009-07-13 02:41:36 +00:00
echo "<br />";
2009-07-13 02:31:14 +00:00
$found = true;
if (!is_null($limit)) {
if (--$limit == 0) { break; }
}
}
2009-07-11 00:27:36 +00:00
}
2009-07-13 02:31:14 +00:00
}
return $found;
}
2009-07-13 02:31:14 +00:00
function display_comics() { $this->display_attached_images(); }
function display_archive() {
if (!$this->display_attached_images('archive', 1)) {
$this->display_attached_images('comic', 1, 'archive');
}
}
function display_rss() {
if (!$this->display_attached_images('rss')) {
$this->display_attached_images('comic', null, 'rss');
}
}
function get_comic_img_tag($url, $type, $additional_parameters = array()) {
$dimensions = array();
2009-07-13 02:31:14 +00:00
if (isset($this->comicpress->comicpress_options["${type}_dimensions"])) {
list($width, $height) = explode("x", $this->comicpress->comicpress_options["${type}_dimensions"]);
$dimensions = compact('width', 'height');
}
$output = '<img src="' . $url . '" ';
foreach (array('width', 'height') as $field) {
if (!empty($dimensions[$field])) {
$output .= $field . '="' . $dimensions[$field] . '" ';
}
}
if (is_array($additional_parameters)) {
foreach ($additional_parameters as $parameter => $value) {
$output .= $parameter . '="' . $value . '" ';
}
}
$output .= "/>";
return $output;
}
function normalize_attachment_sorting() {
}
}
?>