saving metadata via ui works, now just needs some tests written
This commit is contained in:
parent
45e432c824
commit
195ac26b8a
@ -47,11 +47,22 @@ class ComicPressBackendFilesystemFactory {
|
|||||||
if (isset($result[0][$root])) {
|
if (isset($result[0][$root])) {
|
||||||
$return = new ComicPressBackendFilesystem();
|
$return = new ComicPressBackendFilesystem();
|
||||||
$return->id = $id;
|
$return->id = $id;
|
||||||
|
$return->root = $root;
|
||||||
|
|
||||||
foreach (array('files_by_type', 'file_urls_by_type') as $index => $name) {
|
foreach (array('files_by_type', 'file_urls_by_type') as $index => $name) {
|
||||||
$return->{$name} = $result[$index][$root];
|
$return->{$name} = $result[$index][$root];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (($result = get_post_meta($post_id, 'backend_filesystem_image_meta', true)) !== false) {
|
||||||
|
if (is_array($result)) {
|
||||||
|
if (isset($result[$root])) {
|
||||||
|
foreach ($result[$root] as $key => $value) {
|
||||||
|
$return->{$key} = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,6 +114,7 @@ class ComicPressBackendFilesystemFactory {
|
|||||||
if (!empty($files)) {
|
if (!empty($files)) {
|
||||||
$grouped_by_root = $this->group_by_root($filename_pattern, $files);
|
$grouped_by_root = $this->group_by_root($filename_pattern, $files);
|
||||||
$urls_by_root = $this->get_urls_for_post_roots($grouped_by_root, $post);
|
$urls_by_root = $this->get_urls_for_post_roots($grouped_by_root, $post);
|
||||||
|
$image_meta_by_root = array();
|
||||||
|
|
||||||
update_post_meta($post->ID, 'backend_filesystem_files_by_type', array($grouped_by_root, $urls_by_root));
|
update_post_meta($post->ID, 'backend_filesystem_files_by_type', array($grouped_by_root, $urls_by_root));
|
||||||
foreach ($grouped_by_root as $root => $files_for_root) {
|
foreach ($grouped_by_root as $root => $files_for_root) {
|
||||||
@ -112,6 +124,14 @@ class ComicPressBackendFilesystemFactory {
|
|||||||
$fs->file_urls_by_type = $urls_by_root[$root];
|
$fs->file_urls_by_type = $urls_by_root[$root];
|
||||||
|
|
||||||
$return[] = $fs;
|
$return[] = $fs;
|
||||||
|
|
||||||
|
$image_meta_by_root[$root] = array(
|
||||||
|
'alt_text' => '',
|
||||||
|
'title_text' => ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!($check = get_post_meta($post->ID, 'backend_filesystem_image_meta', true))) {
|
||||||
|
update_post_meta($post->ID, 'backend_filesystem_image_meta', array($image_meta_by_root));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -325,6 +345,8 @@ class ComicPressBackendFilesystemAdmin {
|
|||||||
include('partials/backend-filesystem/image-type-holder.inc');
|
include('partials/backend-filesystem/image-type-holder.inc');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
function handle_update_comicpress_options($info) {
|
function handle_update_comicpress_options($info) {
|
||||||
if (isset($info['backend_options']['filesystem'])) {
|
if (isset($info['backend_options']['filesystem'])) {
|
||||||
$info = $info['backend_options']['filesystem'];
|
$info = $info['backend_options']['filesystem'];
|
||||||
@ -351,11 +373,60 @@ class ComicPressBackendFilesystemAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function save_post($post_id) {
|
||||||
|
if (isset($_POST['cp'])) {
|
||||||
|
$info = $_POST['cp'];
|
||||||
|
if (isset($info['attachments'])) {
|
||||||
|
$image_meta_updates = array();
|
||||||
|
foreach ($info['attachments'] as $id => $properties) {
|
||||||
|
if ($backend = ComicPressBackend::generate_from_id($id)) {
|
||||||
|
if (is_a($backend, 'ComicPressBackendFilesystem')) {
|
||||||
|
$image_meta_updates[$backend->root] = array();
|
||||||
|
foreach (array('alt_text', 'title_text') as $field) {
|
||||||
|
if (isset($properties[$field])) {
|
||||||
|
$image_meta_updates[$backend->root][$field] = strip_tags($properties[$field]);
|
||||||
|
} else {
|
||||||
|
$image_meta_updates[$backend->root][$field] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
update_post_meta($post_id, 'backend_filesystem_image_meta', $image_meta_updates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
|
||||||
|
function comic_ordering_holder($backend) {
|
||||||
|
if (is_a($backend, 'ComicPressBackendFilesystem')) {
|
||||||
|
?>
|
||||||
|
<table class="widefat">
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Title (hover) text:</th>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="cp[attachments][<?php echo esc_attr($backend->id) ?>][title_text]" value="<?php echo esc_attr($backend->title()) ?>" style="width:100%" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Alt (accessibility) text:</th>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="cp[attachments][<?php echo esc_attr($backend->id) ?>][alt_text]" value="<?php echo esc_attr($backend->alt()) ?>" style="width:100%" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function actions() {
|
function actions() {
|
||||||
return array(
|
return array(
|
||||||
array('comicpress-options-admin', array('ComicPressBackendFilesystemAdmin', 'options_admin')),
|
array('comicpress-options-admin', array('ComicPressBackendFilesystemAdmin', 'options_admin')),
|
||||||
array('comicpress-image-type-holder', array('ComicPressBackendFilesystemAdmin', 'image_type_holder'), 10, 1),
|
array('comicpress-image-type-holder', array('ComicPressBackendFilesystemAdmin', 'image_type_holder'), 10, 1),
|
||||||
array('comicpress-handle_update_comicpress_options', array('ComicPressBackendFilesystemAdmin', 'handle_update_comicpress_options'), 10, 1)
|
array('comicpress-handle_update_comicpress_options', array('ComicPressBackendFilesystemAdmin', 'handle_update_comicpress_options'), 10, 1),
|
||||||
|
array('comicpress-comic-ordering-holder', array('ComicPressBackendFilesystemAdmin', 'comic_ordering_holder'), 10, 1),
|
||||||
|
array('save_post', array('ComicPressBackendFilesystemAdmin', 'save_post'), 10, 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
<p><strong><?php echo esc_html($result->source_name) ?>:</strong> <?php echo esc_html(basename($info['file'])) ?></p>
|
<p><strong><?php echo esc_html($result->source_name) ?>:</strong> <?php echo esc_html(basename($info['file'])) ?></p>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?php if (count($comicpress->comicpress_options['image_types']) > 1) { ?>
|
<?php if (count($comicpress->comicpress_options['image_types']) > 1) { ?>
|
||||||
|
|
||||||
<a class="comic-ordering-show-associations" href="#"><?php _e('Edit associations', 'comicpress') ?></a>
|
<a class="comic-ordering-show-associations" href="#"><?php _e('Edit associations', 'comicpress') ?></a>
|
||||||
<div class="comic-ordering-associations">
|
<div class="comic-ordering-associations">
|
||||||
<ul>
|
<ul>
|
||||||
@ -38,6 +37,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
<?php do_action('comicpress-comic-ordering-holder', $result) ?>
|
||||||
</div>
|
</div>
|
||||||
<br style="clear: both" />
|
<br style="clear: both" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -105,14 +105,6 @@ ComicImageOrdering.setup = function() {
|
|||||||
ComicImageOrdering.build_response();
|
ComicImageOrdering.build_response();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var associations_box = att.select('.comic-ordering-associations').pop();
|
|
||||||
associations_box[($H(ComicImageOrdering.ids_with_children[id]).keys().length == 0) ? 'hide' : 'show']();
|
|
||||||
|
|
||||||
att.select('.comic-ordering-show-associations').pop().observe('click', function(e) {
|
|
||||||
Event.stop(e);
|
|
||||||
new Effect[associations_box.visible() ? 'BlindUp' : 'BlindDown'](associations_box, { duration: 0.25 });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$$('#comic-ordering input[type=checkbox]').each(function(ch) {
|
$$('#comic-ordering input[type=checkbox]').each(function(ch) {
|
||||||
|
@ -20,6 +20,9 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase
|
|||||||
$valid_backend->id = 'filesystem-1--test';
|
$valid_backend->id = 'filesystem-1--test';
|
||||||
$valid_backend->files_by_type = array('comic' => 'comic-file');
|
$valid_backend->files_by_type = array('comic' => 'comic-file');
|
||||||
$valid_backend->file_urls_by_type = array('comic' => 'comic-url');
|
$valid_backend->file_urls_by_type = array('comic' => 'comic-url');
|
||||||
|
$valid_backend->alt_text = 'alt text';
|
||||||
|
$valid_backend->title_text = 'title text';
|
||||||
|
$valid_backend->root = '-test';
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array('blah', false),
|
array('blah', false),
|
||||||
@ -45,6 +48,17 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
update_post_meta(
|
||||||
|
1,
|
||||||
|
'backend_filesystem_image_meta',
|
||||||
|
array(
|
||||||
|
'-test' => array(
|
||||||
|
'alt_text' => 'alt text',
|
||||||
|
'title_text' => 'title text'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if ($is_successful) {
|
if ($is_successful) {
|
||||||
$return = $is_successful;
|
$return = $is_successful;
|
||||||
} else {
|
} else {
|
||||||
@ -130,6 +144,15 @@ class ComicPressBackendFilesystemFactoryTest extends PHPUnit_Framework_TestCase
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
), get_post_meta(1, 'backend_filesystem_files_by_type', true));
|
), get_post_meta(1, 'backend_filesystem_files_by_type', true));
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
array(
|
||||||
|
'root' => array(
|
||||||
|
'alt_text' => '',
|
||||||
|
'title_text' => ''
|
||||||
|
)
|
||||||
|
)
|
||||||
|
), get_post_meta(1, 'backend_filesystem_image_meta', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user