Merge branch 'master' of ssh://claritycomic.com/home/john/repositories/comicpress-core
This commit is contained in:
commit
da2072e718
@ -237,8 +237,10 @@ class ComicPress {
|
||||
if (isset($this->comicpress_options['image_types'])) {
|
||||
if (is_array($this->comicpress_options['image_types'])) {
|
||||
foreach ($this->comicpress_options['image_types'] as $type => $properties) {
|
||||
if ($properties['default'] === true) {
|
||||
return $type;
|
||||
if (isset($properties['default'])) {
|
||||
if ($properties['default'] === true) {
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class ComicPressAdmin {
|
||||
}
|
||||
|
||||
add_action('edit_form_advanced', array(&$this, 'edit_form_advanced'));
|
||||
add_action('save_post', array(&$this, 'save_post'), 10, 1);
|
||||
|
||||
add_filter('comicpress_core_version', array(&$this, 'comicpress_core_version'));
|
||||
|
||||
@ -418,16 +419,14 @@ class ComicPressAdmin {
|
||||
}
|
||||
}
|
||||
|
||||
function handle_update_comic_ordering() {
|
||||
if (isset($_POST['post_ID'])) {
|
||||
if (is_numeric($_POST['post_ID'])) {
|
||||
if ($post = get_post($_POST['post_ID'])) {
|
||||
$comic_post = new ComicPressComicPost($post);
|
||||
$data = $this->_json_decode(stripslashes($_POST['cp']['comic_order']));
|
||||
if (!empty($data)) {
|
||||
if (is_array($data)) {
|
||||
$comic_post->update_post_media_data($data);
|
||||
}
|
||||
function save_post($post_id) {
|
||||
if (ComicPressAdmin::verify_nonces() === 'handle_update_edit_form_advanced') {
|
||||
if ($post = get_post($psot_id)) {
|
||||
$comic_post = new ComicPressComicPost($post);
|
||||
$data = $this->_json_decode(stripslashes($_POST['cp']['comic_order']));
|
||||
if (!empty($data)) {
|
||||
if (is_array($data)) {
|
||||
$comic_post->update_post_media_data($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -477,27 +476,17 @@ class ComicPressAdmin {
|
||||
* Handle an update.
|
||||
*/
|
||||
function handle_update() {
|
||||
if (isset($_REQUEST['cp'])) {
|
||||
if (is_array($_REQUEST['cp'])) {
|
||||
if (isset($_REQUEST['cp']['_nonce'])) {
|
||||
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
|
||||
if (isset($_POST['attachments'])) {
|
||||
//coming from media editor
|
||||
$this->handle_update_attachments();
|
||||
} else if (isset($_REQUEST['cp']['action'])) {
|
||||
$action = $_REQUEST['cp']['action'];
|
||||
if (isset($_REQUEST['cp']['_action_nonce'])) {
|
||||
if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], "comicpress-${action}")) {
|
||||
$method = 'handle_update_' . strtolower(str_replace('-', '_', $action));
|
||||
if (method_exists($this, $method)) {
|
||||
$this->{$method}($_REQUEST['cp']);
|
||||
}
|
||||
do_action("comicpress-${method}", $_REQUEST['cp']);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($method = ComicPressAdmin::verify_nonces()) {
|
||||
switch ($method) {
|
||||
case 'attachments':
|
||||
$this->handle_update_attachments();
|
||||
break;
|
||||
default:
|
||||
if (method_exists($this, $method)) {
|
||||
$this->{$method}($_REQUEST['cp']);
|
||||
}
|
||||
}
|
||||
do_action("comicpress-${method}", $_REQUEST['cp']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -525,4 +514,28 @@ class ComicPressAdmin {
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
function verify_nonces() {
|
||||
if (isset($_REQUEST['cp'])) {
|
||||
if (is_array($_REQUEST['cp'])) {
|
||||
if (isset($_REQUEST['cp']['_nonce'])) {
|
||||
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
|
||||
if (isset($_POST['attachments'])) {
|
||||
//coming from media editor
|
||||
return 'attachments';
|
||||
} else if (isset($_REQUEST['cp']['action'])) {
|
||||
$action = $_REQUEST['cp']['action'];
|
||||
if (isset($_REQUEST['cp']['_action_nonce'])) {
|
||||
if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], "comicpress-${action}")) {
|
||||
$method = 'handle_update_' . strtolower(str_replace('-', '_', $action));
|
||||
return $method;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
class ComicPressBackend {
|
||||
function _embed_image($size) {
|
||||
$size = $this->ensure_type($size);
|
||||
$extras = array();
|
||||
$dims = $this->dims($size);
|
||||
if (!empty($dims)) {
|
||||
@ -17,7 +18,7 @@ class ComicPressBackend {
|
||||
unset($extras[$field]);
|
||||
}
|
||||
|
||||
$output = sprintf('<img src="%s" alt="%s" title="%s" %s/>', $this->url(), $this->alt(), $this->title(), implode("", $extras));
|
||||
$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);
|
||||
}
|
||||
|
||||
@ -31,4 +32,32 @@ class ComicPressBackend {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -12,17 +12,12 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
||||
$this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true);
|
||||
}
|
||||
|
||||
function dims($size = 'comic') {
|
||||
function dims($size = null) {
|
||||
$size = $this->ensure_type($size);
|
||||
$comicpress = ComicPress::get_instance();
|
||||
|
||||
$dims = array();
|
||||
if (isset($comicpress->comicpress_options['image_types'])) {
|
||||
if ($size == 'default') {
|
||||
foreach ($comicpress->comicpress_options['image_types'] as $type => $info) {
|
||||
if ($info['default']) { $size = $type; break; }
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($comicpress->comicpress_options['image_types'][$size])) {
|
||||
if (isset($comicpress->comicpress_options['image_types'][$size]['dimensions'])) {
|
||||
$dims = array_combine(array('width', 'height'), explode("x", $comicpress->comicpress_options['image_types'][$size]['dimensions']));
|
||||
@ -44,24 +39,10 @@ class ComicPressBackendAttachment extends ComicPressBackend {
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
function embed($size = 'comic') { return $this->_embed_image($size); }
|
||||
function file($size = 'comic') { return $this->attachment->guid; }
|
||||
function file($size = null) { return $this->attachment->guid; }
|
||||
function alt() { return $this->attachment->post_title; }
|
||||
function title() { return $this->attachment->post_excerpt; }
|
||||
// @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;
|
||||
}
|
||||
}
|
||||
|
||||
class ComicPressBackendAttachmentFactory {
|
||||
|
@ -21,6 +21,10 @@ class ComicPressBackendURL extends ComicPressBackend {
|
||||
$valid_urls[$type] = $url;
|
||||
if ($type == $default_type) { $key = substr(md5($url), 0, 10); }
|
||||
}
|
||||
} else {
|
||||
if (strpos($type, '__') === 0) {
|
||||
$valid_urls[$type] = $url;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -30,6 +34,7 @@ class ComicPressBackendURL extends ComicPressBackend {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta($post->ID, 'backend_url_image_urls', $valid_url_groups);
|
||||
}
|
||||
}
|
||||
@ -44,6 +49,8 @@ class ComicPressBackendURL extends ComicPressBackend {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function dims($size = null) { return false; }
|
||||
}
|
||||
|
||||
class ComicPressBackendURLFactory {
|
||||
@ -57,7 +64,14 @@ class ComicPressBackendURLFactory {
|
||||
if (isset($meta[$key])) {
|
||||
$backend = new ComicPressBackendURL();
|
||||
$backend->id = $id;
|
||||
$backend->urls_by_type = $meta[$key];
|
||||
$backend->urls_by_type = array();
|
||||
foreach ($meta[$key] as $k => $v) {
|
||||
if (strpos($k, '__') === 0) {
|
||||
$backend->{substr($k, 2)} = $v;
|
||||
} else {
|
||||
$backend->urls_by_type[$k] = $v;
|
||||
}
|
||||
}
|
||||
return $backend;
|
||||
}
|
||||
}
|
||||
@ -119,7 +133,16 @@ class ComicPressBackendURLAdmin {
|
||||
include('partials/backend-url/_editor.inc');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
function save_post($post_id) {
|
||||
if (ComicPressAdmin::verify_nonces() === 'handle_update_edit_form_advanced') {
|
||||
if ($post = get_post($post_id)) {
|
||||
ComicPressBackendURL::update_post_urls($post_id, $_REQUEST['cp']['url']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_action('admin_menu', array('ComicPressBackendURLAdmin', 'admin_menu'));
|
||||
add_action('comicpress-handle_update_backend_url_new_editor', array('ComicPressBackendURLAdmin', 'handle_update_backend_url_new_editor'));
|
||||
add_action('save_post', array('ComicPressBackendURLAdmin', 'save_post'), 10, 1);
|
||||
|
@ -1,14 +1,37 @@
|
||||
<div class="comicpress-url-backend-holder">
|
||||
<div class="comicpress-backend-url-holder">
|
||||
<table class="widefat">
|
||||
<tr>
|
||||
<td align="right" colspan="2">
|
||||
<a class="comicpress-backend-url-deleter" href="#">X</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
foreach ($comicpress->comicpress_options['image_types'] as $type => $info) {
|
||||
$url = isset($backend->urls_by_type[$type]) ? $backend->urls_by_type[$type] : ''; ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo esc_html($info['name']) ?></th>
|
||||
<th scope="row">
|
||||
<?php echo esc_html($info['name']) ?>
|
||||
<?php if (isset($info['default'])) { ?>
|
||||
<?php if ($info['default']) { ?>
|
||||
<em><?php _e('(required)', 'comicpress') ?></em>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</th>
|
||||
<td><input type="text" style="width: 100%" name="cp[url][<?php echo esc_attr($backend->id) ?>][<?php echo esc_attr($type) ?>]" value="<?php echo esc_attr($url) ?>" />
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
foreach (array(
|
||||
'alt_text' => __('Image alt text', 'comicpress'),
|
||||
'hover_text' => __('Hover/title text', 'comicpress')
|
||||
) as $type => $label) {
|
||||
$value = isset($backend->{$type}) ? $backend->{$type} : ''; ?>
|
||||
<tr>
|
||||
<th scope="row"><?php echo $label ?></th>
|
||||
<td><input type="text" style="width: 100%" name="cp[url][<?php echo esc_attr($backend->id) ?>][__<?php echo $type ?>]" value="<?php echo esc_attr($value) ?>" />
|
||||
</tr>
|
||||
<?php }
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
|
@ -7,18 +7,38 @@
|
||||
</div>
|
||||
<a href="#" id="comicpress-backend-url-add-new">Add a new image</a>
|
||||
<script type="text/javascript">
|
||||
$('comicpress-backend-url-add-new').observe('click', function(e) {
|
||||
Event.stop(e);
|
||||
new Ajax.Updater(
|
||||
'comicpress-backend-url-holder-container',
|
||||
ComicPressAdmin.ajax_uri, {
|
||||
'insertion': 'bottom',
|
||||
'parameters': {
|
||||
'cp[_nonce]': ComicPressAdmin.nonce,
|
||||
'cp[action]': 'backend-url-new-editor',
|
||||
'cp[_action_nonce]': '<?php echo esc_js(wp_create_nonce('comicpress-backend-url-new-editor')) ?>'
|
||||
(function() {
|
||||
var set_up_deleters = function() {
|
||||
$$('.comicpress-backend-url-holder').each(function(d) {
|
||||
var deleter = d.select('.comicpress-backend-url-deleter').pop();
|
||||
if (deleter) {
|
||||
deleter.stopObserving();
|
||||
deleter.observe('click', function(e) {
|
||||
Event.stop(e);
|
||||
if (confirm('Delete this image?')) {
|
||||
d.remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$('comicpress-backend-url-add-new').observe('click', function(e) {
|
||||
Event.stop(e);
|
||||
new Ajax.Updater(
|
||||
'comicpress-backend-url-holder-container',
|
||||
ComicPressAdmin.ajax_uri, {
|
||||
'insertion': 'bottom',
|
||||
'parameters': {
|
||||
'cp[_nonce]': ComicPressAdmin.nonce,
|
||||
'cp[action]': 'backend-url-new-editor',
|
||||
'cp[_action_nonce]': '<?php echo esc_js(wp_create_nonce('comicpress-backend-url-new-editor')) ?>'
|
||||
},
|
||||
onComplete: set_up_deleters
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
set_up_deleters();
|
||||
}());
|
||||
</script>
|
||||
|
@ -36,7 +36,7 @@ class ComicPressBackendTest extends PHPUnit_Framework_TestCase {
|
||||
$backend = $this->getMock('ComicPressBackend', array('dims', 'url', 'alt', 'title'));
|
||||
|
||||
$backend->expects($this->once())->method('dims')->with('comic')->will($this->returnValue($dims_result));
|
||||
$backend->expects($this->once())->method('url')->will($this->returnValue('http://comic'));
|
||||
$backend->expects($this->once())->method('url')->with('comic')->will($this->returnValue('http://comic'));
|
||||
$backend->expects($this->once())->method('alt')->will($this->returnValue('alt'));
|
||||
$backend->expects($this->once())->method('title')->will($this->returnValue('title'));
|
||||
|
||||
@ -67,4 +67,51 @@ class ComicPressBackendTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertEquals($expected_result, ComicPressBackend::generate_from_id($id));
|
||||
}
|
||||
|
||||
function providerTestEnsureType() {
|
||||
return array(
|
||||
array(null, 'comic'),
|
||||
array('comic', 'comic'),
|
||||
array('rss', 'rss')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestEnsureType
|
||||
*/
|
||||
function testEnsureType($provided, $expected) {
|
||||
$comicpress = ComicPress::get_instance();
|
||||
$comicpress->comicpress_options = array(
|
||||
'image_types' => array(
|
||||
'comic' => array('default' => true),
|
||||
'rss' => array('default' => false)
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals($expected, ComicPressBackend::ensure_type($provided));
|
||||
}
|
||||
|
||||
function testGetEmbed() {
|
||||
$ba = $this->getMock('ComicPressBackend', array('_embed_image', 'ensure_type'));
|
||||
$ba->expects($this->once())->method('ensure_type')->with('test')->will($this->returnValue('ensured'));
|
||||
$ba->expects($this->once())->method('_embed_image')->with('ensured')->will($this->returnValue('embed'));
|
||||
|
||||
$this->assertEquals('embed', $ba->embed('test'));
|
||||
}
|
||||
|
||||
|
||||
function testGetInfo() {
|
||||
$ba = $this->getMock('ComicPressBackend', array('dims', 'url', 'file'), array(), 'Mock_ComicPressBackend', 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());
|
||||
}
|
||||
}
|
@ -301,6 +301,13 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
|
||||
),
|
||||
'comic'
|
||||
),
|
||||
array(
|
||||
array(
|
||||
'rss' => array(),
|
||||
'comic' => array('default' => true),
|
||||
),
|
||||
'comic'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
|
||||
array('comic', true, array()),
|
||||
array('comic', array(), array()),
|
||||
array('comic', array('dimensions' => '300x200'), array('width' => 300, 'height' => 200)),
|
||||
array('default', array('dimensions' => '300x200', 'default' => true), array('width' => 300, 'height' => 200))
|
||||
array(null, array('default' => true, 'dimensions' => '300x200'), array('width' => 300, 'height' => 200)),
|
||||
);
|
||||
}
|
||||
|
||||
@ -40,30 +40,16 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
|
||||
array(false, false),
|
||||
array(true, false),
|
||||
array(array(), false),
|
||||
array(array('url', 300, 200, false), 'url')
|
||||
);
|
||||
array(array('url', 300, 200, false), 'url'),
|
||||
array(array('url', 300, 200, false), 'url', null),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestUrl
|
||||
*/
|
||||
function testUrl($image_downsize_result, $expected_result) {
|
||||
_set_image_downsize_result(1, 'comic', $image_downsize_result);
|
||||
function testUrl($image_downsize_result, $expected_result, $which = 'comic') {
|
||||
_set_image_downsize_result(1, 'comic', $image_downsize_result);
|
||||
$this->assertEquals($expected_result, $this->ba->url('comic'));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ class ComicPressBackendUrlFactoryTest extends PHPUnit_Framework_TestCase {
|
||||
'comic' => 'comic',
|
||||
'rss' => 'rss'
|
||||
);
|
||||
$valid_backend->alt_text = 'alt text';
|
||||
$valid_backend->hover_text = 'hover text';
|
||||
|
||||
return array(
|
||||
array('', false),
|
||||
@ -60,7 +62,14 @@ class ComicPressBackendUrlFactoryTest extends PHPUnit_Framework_TestCase {
|
||||
function testGenerateFromID($id, $expected_result) {
|
||||
wp_insert_post((object)array('ID' => 1));
|
||||
|
||||
update_post_meta(1, 'backend_url_image_urls', array('12345' => array('comic' => 'comic', 'rss' => 'rss')));
|
||||
update_post_meta(1, 'backend_url_image_urls', array(
|
||||
'12345' => array(
|
||||
'comic' => 'comic',
|
||||
'rss' => 'rss',
|
||||
'__alt_text' => 'alt text',
|
||||
'__hover_text' => 'hover text'
|
||||
)
|
||||
));
|
||||
|
||||
$this->assertEquals($expected_result, $this->fa->generate_from_id($id));
|
||||
}
|
||||
|
@ -21,12 +21,16 @@ class ComicPressBackendUrlTest extends PHPUnit_Framework_TestCase {
|
||||
'test' => array(
|
||||
'comic' => 'http://test/test',
|
||||
'rss' => 'http://test/test2',
|
||||
'__alt_text' => 'alt text',
|
||||
'__hover_text' => 'hover text',
|
||||
)
|
||||
),
|
||||
array(
|
||||
$key => array(
|
||||
'comic' => 'http://test/test',
|
||||
'rss' => 'http://test/test2'
|
||||
'rss' => 'http://test/test2',
|
||||
'__alt_text' => 'alt text',
|
||||
'__hover_text' => 'hover text',
|
||||
)
|
||||
),
|
||||
)
|
||||
|
@ -1,5 +1,3 @@
|
||||
<?php
|
||||
|
||||
set_include_path(realpath(dirname(__FILE__) . '/../classes') . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user