get attachment info
This commit is contained in:
parent
bf9ea351f0
commit
b287c05e21
|
@ -21,7 +21,7 @@ class ComicPress {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
var $backends = array('ComicPressBackendAttachment');
|
var $backends = array();
|
||||||
|
|
||||||
function &get_instance() {
|
function &get_instance() {
|
||||||
static $instance;
|
static $instance;
|
||||||
|
@ -53,7 +53,7 @@ class ComicPress {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the class.
|
* Initialize the class.
|
||||||
*/
|
*/
|
||||||
|
@ -75,6 +75,12 @@ class ComicPress {
|
||||||
update_option("${size}_size_h", $h);
|
update_option("${size}_size_h", $h);
|
||||||
update_option("${size}_crop", 0);
|
update_option("${size}_crop", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (get_declared_classes() as $class) {
|
||||||
|
if (preg_match('#^ComicPressBackend.+$#', $class) > 0) {
|
||||||
|
$this->backends[] = new $class();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WordPress Filters
|
// WordPress Filters
|
||||||
|
|
|
@ -57,23 +57,32 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
function embed($size = 'comic') {
|
function embed($size = 'comic') { return $this->_embed_image($size); }
|
||||||
return $this->_embed_image($size);
|
function file($size = 'comic') { return $this->attachment->guid; }
|
||||||
}
|
|
||||||
|
|
||||||
function alt() { return $this->attachment->post_title; }
|
function alt() { return $this->attachment->post_title; }
|
||||||
function title() { return $this->attachment->post_excerpt; }
|
function title() { return $this->attachment->post_excerpt; }
|
||||||
|
|
||||||
function get_info() { return array(); }
|
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
function generate_from_id($id) {
|
function generate_from_id($id) {
|
||||||
if (strpos($id, 'attachment-') === 0) {
|
if (strpos($id, 'attachment-') === 0) {
|
||||||
$id = str_replace('attachment-', '', $id);
|
$id = str_replace('attachment-', '', $id);
|
||||||
if (is_numeric($id)) {
|
if (is_numeric($id)) {
|
||||||
$post = get_post($id);
|
$post = get_post($id);
|
||||||
if (!empty($post)) {
|
if (!empty($post)) {
|
||||||
return $post;
|
return new ComicPressBackendAttachment($post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<p><em>
|
<p><em>
|
||||||
<?php _e('Drag and drop the comic files below to change the order in which they\'ll appear in within each category.', 'comicpress') ?>
|
<?php _e('Drag and drop the comic files below to change the order in which they\'ll appear.', 'comicpress') ?>
|
||||||
<?php
|
<?php
|
||||||
printf(
|
printf(
|
||||||
__('To upload new images, use the %s.', 'comicpress'),
|
__('To upload new images, use the %s.', 'comicpress'),
|
||||||
|
@ -10,14 +10,13 @@
|
||||||
|
|
||||||
</em></p>
|
</em></p>
|
||||||
<?php if (!empty($ordering)) { ?>
|
<?php if (!empty($ordering)) { ?>
|
||||||
<?php foreach ($ordering as $type => $attachment_ids) { ?>
|
<div class="comic-ordering">
|
||||||
<h3><?php echo $this->comic_image_types[$type] ?></h3>
|
<?php foreach ($ordering as $id => $info) {
|
||||||
<div class="comic-ordering" id="comic-ordering-<?php echo $type ?>">
|
$result = ComicPressBackend::generate_from_id($id);
|
||||||
<?php foreach ($attachment_ids as $attachment_id) {
|
if (!empty($result)) {
|
||||||
$backend = new ComicPressBackendAttachment($attachment_id);
|
$info = $result->get_info(); ?>
|
||||||
$info = $backend->get_info(); ?>
|
<div class="cp-comic-attachment" id="attachment_<?php echo $id ?>">
|
||||||
<div class="cp-comic-attachment" id="attachment_<?php echo $attachment_id ?>">
|
<img src="<?php echo $result->url() ?>" border="0" height="<?php echo $zoom_level ?>" />
|
||||||
<img src="<?php echo $backend->url() ?>" border="0" height="<?php echo $zoom_level ?>" />
|
|
||||||
<div>
|
<div>
|
||||||
<?php if (isset($info['file'])) { ?>
|
<?php if (isset($info['file'])) { ?>
|
||||||
<p><strong><?php echo basename($info['file']) ?></strong></p>
|
<p><strong><?php echo basename($info['file']) ?></strong></p>
|
||||||
|
@ -31,9 +30,9 @@
|
||||||
</div>
|
</div>
|
||||||
<br style="clear: both" />
|
<br style="clear: both" />
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</div>
|
<?php } ?>
|
||||||
<?php } ?>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
|
@ -92,6 +92,27 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
|
||||||
function testGenerateFromID($id, $is_successful) {
|
function testGenerateFromID($id, $is_successful) {
|
||||||
wp_insert_post(array('ID' => 1));
|
wp_insert_post(array('ID' => 1));
|
||||||
|
|
||||||
$this->assertTrue($is_successful == is_object($this->ba->generate_from_id($id)));
|
if ($is_successful) {
|
||||||
|
$return = new ComicPressBackendAttachment((object)array('ID' => 1));
|
||||||
|
} else {
|
||||||
|
$return = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($return, $this->ba->generate_from_id($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetInfo() {
|
||||||
|
$ba = $this->getMock('ComicPressBackendAttachment', array('dims', 'url', 'file'), array(), 'Mock_ComicPressBackendAttachment', false);
|
||||||
|
|
||||||
|
$ba->expects($this->once())->method('dims')->will($this->returnValue(array('width' => 320, 'height' => 240)));
|
||||||
|
$ba->expects($this->once())->method('url')->will($this->returnValue('http://blah/file.jpg'));
|
||||||
|
$ba->expects($this->once())->method('file')->will($this->returnValue('/root/file.jpg'));
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
'width' => 320,
|
||||||
|
'height' => 240,
|
||||||
|
'url' => 'http://blah/file.jpg',
|
||||||
|
'file' => '/root/file.jpg'
|
||||||
|
), $ba->get_info());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue