working on action nonces
This commit is contained in:
parent
ba3ab55b0f
commit
1209336388
@ -1,85 +1,85 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class ComicPressAdmin {
|
class ComicPressAdmin {
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
/**
|
/**
|
||||||
* Initialize the addon.
|
* Initialize the addon.
|
||||||
* @param ComicPress $comicpress The master ComicPress object.
|
* @param ComicPress $comicpress The master ComicPress object.
|
||||||
*/
|
*/
|
||||||
function init() {
|
function init() {
|
||||||
$this->comicpress = &ComicPress::get_instance();
|
$this->comicpress = &ComicPress::get_instance();
|
||||||
|
|
||||||
add_action('admin_menu', array(&$this, 'admin_menu'));
|
add_action('admin_menu', array(&$this, 'admin_menu'));
|
||||||
add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2);
|
add_filter('attachment_fields_to_edit', array(&$this, 'setup_comic_metadata_buttons'), 10, 2);
|
||||||
|
|
||||||
if (current_user_can('edit_posts') && isset($comicpress->comicpress_options['helpers']['show_inline_comic_ordering'])) {
|
if (current_user_can('edit_posts') && isset($comicpress->comicpress_options['helpers']['show_inline_comic_ordering'])) {
|
||||||
add_filter('comicpress_attached_image', array(&$this, 'comicpress_attached_image'), 10, 3);
|
add_filter('comicpress_attached_image', array(&$this, 'comicpress_attached_image'), 10, 3);
|
||||||
add_filter('comicpress_display_attached_images', array(&$this, 'comicpress_display_attached_images'), 10, 2);
|
add_filter('comicpress_display_attached_images', array(&$this, 'comicpress_display_attached_images'), 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->comic_image_types = array(
|
$this->comic_image_types = array(
|
||||||
'none' => __('Not a comic', 'comicpress'),
|
'none' => __('Not a comic', 'comicpress'),
|
||||||
'comic' => __('Comic', 'comicpress'),
|
'comic' => __('Comic', 'comicpress'),
|
||||||
'rss' => __('RSS', 'comicpress'),
|
'rss' => __('RSS', 'comicpress'),
|
||||||
'archive' => __('Archive', 'comicpress')
|
'archive' => __('Archive', 'comicpress')
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_admin()) {
|
if (is_admin()) {
|
||||||
add_action('admin_notices', array(&$this, 'display_messages'));
|
add_action('admin_notices', array(&$this, 'display_messages'));
|
||||||
} else {
|
} else {
|
||||||
add_action('wp_head', array(&$this, 'display_messages'));
|
add_action('wp_head', array(&$this, 'display_messages'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function comicpress_attached_image($content, $attachment_id, $index) {
|
function comicpress_attached_image($content, $attachment_id, $index) {
|
||||||
$content .= '<label class="comic-image-ordering">'
|
$content .= '<label class="comic-image-ordering">'
|
||||||
. __('Image index:', 'comicpress')
|
. __('Image index:', 'comicpress')
|
||||||
. ' '
|
. ' '
|
||||||
. '<input type="text" name="cp[ordering][comic]['
|
. '<input type="text" name="cp[ordering][comic]['
|
||||||
. $attachment_id
|
. $attachment_id
|
||||||
. ']" value="'
|
. ']" value="'
|
||||||
. $index
|
. $index
|
||||||
. '" /></label>';
|
. '" /></label>';
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function comicpress_display_attached_images($content, $post_id) {
|
function comicpress_display_attached_images($content, $post_id) {
|
||||||
$content = '<form method="post">'
|
$content = '<form method="post">'
|
||||||
. '<input type="hidden" name="cp[_nonce]" value="'
|
. '<input type="hidden" name="cp[_nonce]" value="'
|
||||||
. wp_create_nonce('comicpress')
|
. wp_create_nonce('comicpress')
|
||||||
. '" />'
|
. '" />'
|
||||||
. '<input type="hidden" name="post_ID" value="'
|
. '<input type="hidden" name="post_ID" value="'
|
||||||
. $post_id
|
. $post_id
|
||||||
. '" />'
|
. '" />'
|
||||||
. $content
|
. $content
|
||||||
. '<input type="submit" value="'
|
. '<input type="submit" value="'
|
||||||
. __('Change image ordering', 'comicpress')
|
. __('Change image ordering', 'comicpress')
|
||||||
. '" />'
|
. '" />'
|
||||||
. '</form>';
|
. '</form>';
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the admin interface and meta boxes.
|
* Set up the admin interface and meta boxes.
|
||||||
*/
|
*/
|
||||||
function admin_menu() {
|
function admin_menu() {
|
||||||
global $plugin_page, $pagenow, $post;
|
global $plugin_page, $pagenow, $post;
|
||||||
|
|
||||||
add_theme_page(__("ComicPress", 'comicpress'), __('ComicPress', 'comicpress'), 'edit_themes', 'comicpress/render_admin', array(&$this, 'render_admin'));
|
add_theme_page(__("ComicPress", 'comicpress'), __('ComicPress', 'comicpress'), 'edit_themes', 'comicpress/render_admin', array(&$this, 'render_admin'));
|
||||||
|
|
||||||
if (strpos($pagenow, "post") === 0) {
|
if (strpos($pagenow, "post") === 0) {
|
||||||
add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low");
|
add_meta_box("comic-image-ordering", __("Comic Image Ordering", 'comicpress'), array(&$this, 'render_comic_image_ordering'), "post", "normal", "low");
|
||||||
wp_enqueue_script('cp-ordering', get_template_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous', 'scriptaculous-slider'));
|
wp_enqueue_script('cp-ordering', get_template_directory_uri() . '/js/ComicImageOrdering.js', array('scriptaculous', 'scriptaculous-slider'));
|
||||||
wp_enqueue_style('cp-admin', get_template_directory_uri() . '/css/cp-admin.css');
|
wp_enqueue_style('cp-admin', get_template_directory_uri() . '/css/cp-admin.css');
|
||||||
add_action('admin_footer', array(&$this, 'admin_footer'));
|
add_action('admin_footer', array(&$this, 'admin_footer'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($plugin_page == 'comicpress/render_admin') {
|
if ($plugin_page == 'comicpress/render_admin') {
|
||||||
wp_enqueue_style('cp-admin', get_template_directory_uri() . '/css/cp-admin.css');
|
wp_enqueue_style('cp-admin', get_template_directory_uri() . '/css/cp-admin.css');
|
||||||
wp_enqueue_script('cp-admin', get_template_directory_uri() . '/js/Storyline.js', array('prototype', 'scriptaculous'));
|
wp_enqueue_script('cp-admin', get_template_directory_uri() . '/js/Storyline.js', array('prototype', 'scriptaculous'));
|
||||||
add_action('admin_footer', array(&$this, 'admin_footer'));
|
add_action('admin_footer', array(&$this, 'admin_footer'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($pagenow, "-upload") !== false) {
|
if (strpos($pagenow, "-upload") !== false) {
|
||||||
@ -87,57 +87,58 @@ class ComicPressAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function admin_footer() {
|
function admin_footer() {
|
||||||
$nonce = wp_create_nonce('comicpress');
|
$nonce = wp_create_nonce('comicpress');
|
||||||
?><script type="text/javascript">
|
?><script type="text/javascript">
|
||||||
var ComicPressAdmin = {
|
var ComicPressAdmin = {
|
||||||
nonce: '<?php echo $nonce ?>',
|
nonce: '<?php echo $nonce ?>',
|
||||||
ajax_uri: '<?php echo trailingslashit(get_bloginfo('url')) ?>'
|
ajax_uri: '<?php echo trailingslashit(get_bloginfo('url')) ?>'
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<?php }
|
<?php }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify the Media Gallery for ComicPress use.
|
* Modify the Media Gallery for ComicPress use.
|
||||||
*/
|
*/
|
||||||
function setup_comic_metadata_buttons($form_fields, $post) {
|
function setup_comic_metadata_buttons($form_fields, $post) {
|
||||||
global $pagenow;
|
global $pagenow;
|
||||||
|
|
||||||
$comicpress_info = get_post_meta($post->ID, 'comicpress', true);
|
$comicpress_info = get_post_meta($post->ID, 'comicpress', true);
|
||||||
$is_managed = false;
|
$is_managed = false;
|
||||||
if (isset($comicpress_info['managed'])) {
|
if (isset($comicpress_info['managed'])) {
|
||||||
$is_managed = $comicpress_info['managed'];
|
$is_managed = $comicpress_info['managed'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($pagenow !== "media.php") {
|
if ($pagenow !== "media.php") {
|
||||||
$form_fields['auto_attach'] = array(
|
$form_fields['auto_attach'] = array(
|
||||||
'label' => __("Let ComicPress Manage?", 'comicpress'),
|
'label' => __("Let ComicPress Manage?", 'comicpress'),
|
||||||
'input' => 'html',
|
'input' => 'html',
|
||||||
'html' => '<label><input type="checkbox" name="attachments[' . $post->ID . '][comicpress_management]" value="yes" ' . ($is_managed ? 'checked="checked"' : '') . '/> '
|
'html' => '<label><input type="checkbox" name="attachments[' . $post->ID . '][comicpress_management]" value="yes" ' . ($is_managed ? 'checked="checked"' : '') . '/> '
|
||||||
. __('Let ComicPress treat this image as a comic media file', 'comicpress')
|
. __('Let ComicPress treat this image as a comic media file', 'comicpress')
|
||||||
. '</label>'
|
. '</label>'
|
||||||
. '<input type="hidden" name="cp[_nonce]" value="' . wp_create_nonce('comicpress') . '" />'
|
. '<input type="hidden" name="cp[_nonce]" value="' . wp_create_nonce('comicpress') . '" />'
|
||||||
. '<input type="hidden" name="attachments[' . $post->ID . '][post_parent]" value="' . $post->post_parent . '" />'
|
. '<input type="hidden" name="attachments[' . $post->ID . '][post_parent]" value="' . $post->post_parent . '" />'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $form_fields;
|
return $form_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the admin interface.
|
* Render the admin interface.
|
||||||
*/
|
*/
|
||||||
function render_admin() {
|
function render_admin() {
|
||||||
$nonce = wp_create_nonce('comicpress');
|
$nonce = wp_create_nonce('comicpress');
|
||||||
|
$action_nonce = wp_create_nonce('comicpress-comicpress-options');
|
||||||
$storyline = new ComicPressStoryline();
|
$storyline = new ComicPressStoryline();
|
||||||
$storyline->normalize();
|
$storyline->normalize();
|
||||||
$storyline->read_from_options();
|
$storyline->read_from_options();
|
||||||
|
|
||||||
include(dirname(__FILE__) . '/partials/options-admin.inc');
|
include(dirname(__FILE__) . '/partials/options-admin.inc');
|
||||||
}
|
}
|
||||||
|
|
||||||
function _render_admin_storyline_tree($node, $parent_id = "0") {
|
function _render_admin_storyline_tree($node, $parent_id = "0") {
|
||||||
foreach ($node as $category_id => $children) {
|
foreach ($node as $category_id => $children) {
|
||||||
$category = get_category($category_id);
|
$category = get_category($category_id);
|
||||||
echo '<div id="category_' . $parent_id . '-' . $category_id . '" class="cp-category-info">';
|
echo '<div id="category_' . $parent_id . '-' . $category_id . '" class="cp-category-info">';
|
||||||
echo '<span>' . $category->name . '</span>';
|
echo '<span>' . $category->name . '</span>';
|
||||||
@ -150,37 +151,38 @@ class ComicPressAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the comic image ordering interface.
|
* Render the comic image ordering interface.
|
||||||
*/
|
*/
|
||||||
function render_comic_image_ordering($is_ajax = false, $override_post = null) {
|
function render_comic_image_ordering($is_ajax = false, $override_post = null) {
|
||||||
global $post_ID, $temp_ID;
|
global $post_ID, $temp_ID;
|
||||||
|
|
||||||
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
|
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
|
||||||
if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; }
|
if (is_numeric($override_post)) { $uploading_iframe_ID = $override_post; }
|
||||||
|
|
||||||
$comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID));
|
$comic_post = new ComicPressComicPost(get_post($uploading_iframe_ID));
|
||||||
$ordering = $comic_post->normalize_ordering();
|
$ordering = $comic_post->normalize_ordering();
|
||||||
|
|
||||||
$nonce = wp_create_nonce('comicpress');
|
$nonce = wp_create_nonce('comicpress');
|
||||||
$zoom_level = 40;
|
$action_nonce = wp_create_nonce('comicpress-comic-ordering');
|
||||||
$current_user = wp_get_current_user();
|
$zoom_level = 40;
|
||||||
if (!empty($current_user)) {
|
$current_user = wp_get_current_user();
|
||||||
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
|
if (!empty($current_user)) {
|
||||||
if (is_array($comicpress_meta)) {
|
$comicpress_meta = get_usermeta($current_user->ID, 'comicpress-settings');
|
||||||
if (isset($comicpress_meta['zoom_level'])) {
|
if (is_array($comicpress_meta)) {
|
||||||
$zoom_level = floor($comicpress_meta['zoom_level']);
|
if (isset($comicpress_meta['zoom_level'])) {
|
||||||
}
|
$zoom_level = floor($comicpress_meta['zoom_level']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// from wp-admin/includes/media.php O_o
|
// from wp-admin/includes/media.php O_o
|
||||||
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
|
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
|
||||||
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image&TB_iframe=true");
|
$image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image&TB_iframe=true");
|
||||||
|
|
||||||
$comicpress = ComicPress::get_instance();
|
$comicpress = ComicPress::get_instance();
|
||||||
|
|
||||||
$available_attachments = array();
|
$available_attachments = array();
|
||||||
foreach ($this->get_editable_attachment_list($ordering) as $id => $info) {
|
foreach ($this->get_editable_attachment_list($ordering) as $id => $info) {
|
||||||
$result = ComicPressBackend::generate_from_id($id);
|
$result = ComicPressBackend::generate_from_id($id);
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
@ -190,86 +192,86 @@ class ComicPressAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_ajax === true) {
|
if ($is_ajax === true) {
|
||||||
include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc');
|
include(dirname(__FILE__) . '/partials/_comic-image-ordering-sorters.inc');
|
||||||
} else {
|
} else {
|
||||||
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
|
include(dirname(__FILE__) . '/partials/_comic-image-ordering.inc');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
function get_editable_attachment_list($ordering) {
|
function get_editable_attachment_list($ordering) {
|
||||||
foreach ($ordering as $id => $info) {
|
foreach ($ordering as $id => $info) {
|
||||||
if (isset($info['children'])) {
|
if (isset($info['children'])) {
|
||||||
foreach (array_values($info['children']) as $new_id) {
|
foreach (array_values($info['children']) as $new_id) {
|
||||||
$ordering[$new_id] = array('enabled' => true);
|
$ordering[$new_id] = array('enabled' => true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ordering;
|
return $ordering;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a dimension selector.
|
* Create a dimension selector.
|
||||||
* @param string $root The field name root.
|
* @param string $root The field name root.
|
||||||
* @param $dimension The dimension to pre-fill into the fields.
|
* @param $dimension The dimension to pre-fill into the fields.
|
||||||
* @return string The dimension selector as HTML.
|
* @return string The dimension selector as HTML.
|
||||||
*/
|
*/
|
||||||
function create_dimension_selector($root, $dimension) {
|
function create_dimension_selector($root, $dimension) {
|
||||||
$output = array();
|
$output = array();
|
||||||
|
|
||||||
$parts = explode("x", $dimension);
|
$parts = explode("x", $dimension);
|
||||||
foreach (array(
|
foreach (array(
|
||||||
'width' => __('Width', 'comicpress'),
|
'width' => __('Width', 'comicpress'),
|
||||||
'height' => __('Height', 'comicpress')
|
'height' => __('Height', 'comicpress')
|
||||||
) as $id => $name) {
|
) as $id => $name) {
|
||||||
$dim = array_shift($parts);
|
$dim = array_shift($parts);
|
||||||
if (!empty($dim) && !is_numeric($dim)) { $dim = ""; }
|
if (!empty($dim) && !is_numeric($dim)) { $dim = ""; }
|
||||||
$output[] = '<label>' . $name . ': <input type="text" name="' . $root . '[' . $id . ']" value="' . $dim . '" size="4" />px</label><br />';
|
$output[] = '<label>' . $name . ': <input type="text" name="' . $root . '[' . $id . ']" value="' . $dim . '" size="4" />px</label><br />';
|
||||||
}
|
}
|
||||||
return implode("\n", $output);
|
return implode("\n", $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
/**
|
/**
|
||||||
* Update attachment information.
|
* Update attachment information.
|
||||||
*/
|
*/
|
||||||
function handle_update_refresh_ordering($info) {
|
function handle_update_refresh_ordering($info) {
|
||||||
$this->render_comic_image_ordering(true, $info['post_id']);
|
$this->render_comic_image_ordering(true, $info['post_id']);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update attachment information.
|
* Update attachment information.
|
||||||
*/
|
*/
|
||||||
function handle_update_attachments() {
|
function handle_update_attachments() {
|
||||||
foreach ($_POST['attachments'] as $post_id => $settings) {
|
foreach ($_POST['attachments'] as $post_id => $settings) {
|
||||||
if (isset($settings['comicpress_management'])) {
|
if (isset($settings['comicpress_management'])) {
|
||||||
$media_post = get_post($post_id);
|
$media_post = get_post($post_id);
|
||||||
if (isset($media_post->post_parent)) {
|
if (isset($media_post->post_parent)) {
|
||||||
$media_post->post_parent = $settings['post_parent'];
|
$media_post->post_parent = $settings['post_parent'];
|
||||||
wp_update_post($media_post);
|
wp_update_post($media_post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_post_meta($post_id, 'comicpress', array(
|
update_post_meta($post_id, 'comicpress', array(
|
||||||
'managed' => isset($settings['comicpress_management'])
|
'managed' => isset($settings['comicpress_management'])
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update ComicPress options.
|
* Update ComicPress options.
|
||||||
*/
|
*/
|
||||||
function handle_update_comicpress_options($info) {
|
function handle_update_comicpress_options($info) {
|
||||||
foreach ($this->comicpress->comicpress_options as $option => $value) {
|
foreach ($this->comicpress->comicpress_options as $option => $value) {
|
||||||
if (isset($info[$option])) {
|
if (isset($info[$option])) {
|
||||||
switch ($option) {
|
switch ($option) {
|
||||||
case 'image_types':
|
case 'image_types':
|
||||||
if (is_array($info['image_types'])) {
|
if (is_array($info['image_types'])) {
|
||||||
$this->comicpress->comicpress_options['image_types'] = array();
|
$this->comicpress->comicpress_options['image_types'] = array();
|
||||||
$defined_default = null;
|
$defined_default = null;
|
||||||
foreach ($info['image_types'] as $type => $image_info) {
|
foreach ($info['image_types'] as $type => $image_info) {
|
||||||
if (is_array($image_info)) {
|
if (is_array($image_info)) {
|
||||||
$new_value = array();
|
$new_value = array();
|
||||||
@ -289,7 +291,7 @@ class ComicPressAdmin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($type != $new_type) {
|
if ($type != $new_type) {
|
||||||
unset($this->comicpress->comicpress_options['image_types'][$new_type]);
|
unset($this->comicpress->comicpress_options['image_types'][$new_type]);
|
||||||
}
|
}
|
||||||
$this->comicpress->comicpress_options['image_types'][$new_type] = $new_value;
|
$this->comicpress->comicpress_options['image_types'][$new_type] = $new_value;
|
||||||
}
|
}
|
||||||
@ -305,146 +307,146 @@ class ComicPressAdmin {
|
|||||||
$this->comicpress->comicpress_options['image_types'][$defined_default]['default'] = true;
|
$this->comicpress->comicpress_options['image_types'][$defined_default]['default'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
case 'storyline_order':
|
case 'storyline_order':
|
||||||
$storyline = new ComicPressStoryline();
|
$storyline = new ComicPressStoryline();
|
||||||
$storyline->normalize($info[$option]);
|
$storyline->normalize($info[$option]);
|
||||||
break;
|
break;
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// @codeCoverageIgnoreStart
|
$this->comicpress->save();
|
||||||
function _json_decode($string) {
|
|
||||||
if (function_exists('json_decode')) {
|
$this->info(__("ComicPress configuration updated.", 'comicpress'));
|
||||||
return json_decode($string);
|
|
||||||
} else {
|
$this->comicpress->init();
|
||||||
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
|
}
|
||||||
$j = new Moxiecode_JSON();
|
|
||||||
return $j->decode($string);
|
// @codeCoverageIgnoreStart
|
||||||
}
|
function _json_decode($string) {
|
||||||
}
|
if (function_exists('json_decode')) {
|
||||||
|
return json_decode($string);
|
||||||
|
} else {
|
||||||
|
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
|
||||||
|
$j = new Moxiecode_JSON();
|
||||||
|
return $j->decode($string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function _json_encode($data) {
|
function _json_encode($data) {
|
||||||
if (function_exists('json_encode')) {
|
if (function_exists('json_encode')) {
|
||||||
return json_encode($data);
|
return json_encode($data);
|
||||||
} else {
|
} else {
|
||||||
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
|
require_once(ABSPATH."/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php");
|
||||||
$j = new Moxiecode_JSON();
|
$j = new Moxiecode_JSON();
|
||||||
return $j->encode($data);
|
return $j->encode($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_update_comic_ordering() {
|
function handle_update_comic_ordering() {
|
||||||
if (isset($_POST['post_ID'])) {
|
if (isset($_POST['post_ID'])) {
|
||||||
if (is_numeric($_POST['post_ID'])) {
|
if (is_numeric($_POST['post_ID'])) {
|
||||||
if ($post = get_post($_POST['post_ID'])) {
|
if ($post = get_post($_POST['post_ID'])) {
|
||||||
$comic_post = new ComicPressComicPost($post);
|
$comic_post = new ComicPressComicPost($post);
|
||||||
$comic_post->update_post_media_data($this->_json_decode(stripslashes($_POST['cp']['comic_order'])));
|
$comic_post->update_post_media_data($this->_json_decode(stripslashes($_POST['cp']['comic_order'])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_update_get_new_image_type_editor($info) {
|
function handle_update_get_new_image_type_editor($info) {
|
||||||
$type = substr(md5(rand()), 0, 6);
|
$type = substr(md5(rand()), 0, 6);
|
||||||
$info = array(
|
$info = array(
|
||||||
'dimensions' => '100x100',
|
'dimensions' => '100x100',
|
||||||
'default' => false,
|
'default' => false,
|
||||||
'name' => 'New Type'
|
'name' => 'New Type'
|
||||||
);
|
);
|
||||||
|
|
||||||
require_once('partials/_image-type-editor.inc');
|
require_once('partials/_image-type-editor.inc');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the zoom slider info.
|
* Update the zoom slider info.
|
||||||
* @param $info The browser input.
|
* @param $info The browser input.
|
||||||
*/
|
*/
|
||||||
function handle_update_zoom_slider($info) {
|
function handle_update_zoom_slider($info) {
|
||||||
$this->is_ajax = true;
|
$this->is_ajax = true;
|
||||||
|
|
||||||
$current_user = wp_get_current_user();
|
$current_user = wp_get_current_user();
|
||||||
if (!empty($current_user)) {
|
if (!empty($current_user)) {
|
||||||
$this->_update_zoom_slider_meta($current_user->ID, $info['zoom_level']);
|
$this->_update_zoom_slider_meta($current_user->ID, $info['zoom_level']);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
header('HTTP/1.1 500 Internal Server Error');
|
header('HTTP/1.1 500 Internal Server Error');
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the user's zoom slider metadata.
|
* Update the user's zoom slider metadata.
|
||||||
*/
|
*/
|
||||||
function _update_zoom_slider_meta($user_id, $level) {
|
function _update_zoom_slider_meta($user_id, $level) {
|
||||||
$comicpress_meta = get_usermeta($user_id, 'comicpress-settings');
|
$comicpress_meta = get_usermeta($user_id, 'comicpress-settings');
|
||||||
if (!is_array($comicpress_meta)) { $comicpress_meta = array(); }
|
if (!is_array($comicpress_meta)) { $comicpress_meta = array(); }
|
||||||
$comicpress_meta['zoom_level'] = $level;
|
$comicpress_meta['zoom_level'] = $level;
|
||||||
update_usermeta($user_id, 'comicpress-settings', $comicpress_meta);
|
update_usermeta($user_id, 'comicpress-settings', $comicpress_meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle an update.
|
* Handle an update.
|
||||||
*/
|
*/
|
||||||
function handle_update() {
|
function handle_update() {
|
||||||
if (isset($_REQUEST['cp'])) {
|
if (isset($_REQUEST['cp'])) {
|
||||||
if (is_array($_REQUEST['cp'])) {
|
if (is_array($_REQUEST['cp'])) {
|
||||||
if (isset($_REQUEST['cp']['_nonce'])) {
|
if (isset($_REQUEST['cp']['_nonce'])) {
|
||||||
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
|
if (wp_verify_nonce($_REQUEST['cp']['_nonce'], 'comicpress')) {
|
||||||
if (isset($_POST['attachments'])) {
|
if (isset($_POST['attachments'])) {
|
||||||
//coming from media editor
|
//coming from media editor
|
||||||
$this->handle_update_attachments();
|
$this->handle_update_attachments();
|
||||||
} else if (isset($_REQUEST['cp']['action'])) {
|
} else if (isset($_REQUEST['cp']['action'])) {
|
||||||
$method = 'handle_update_' . strtolower(str_replace('-', '_', $_REQUEST['cp']['action']));
|
$action = $_REQUEST['cp']['action'];
|
||||||
if (method_exists($this, $method)) {
|
if (isset($_REQUEST['cp']['_action_nonce'])) {
|
||||||
$this->{$method}($_REQUEST['cp']);
|
if (wp_verify_nonce($_REQUEST['cp']['_action_nonce'], "comicpress-${action}")) {
|
||||||
}
|
$method = 'handle_update_' . strtolower(str_replace('-', '_', $action));
|
||||||
} else {
|
if (method_exists($this, $method)) {
|
||||||
//coming from us
|
$this->{$method}($_REQUEST['cp']);
|
||||||
$this->handle_update_comicpress_options($_REQUEST['cp']);
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->comicpress->save();
|
// @codeCoverageIgnoreStart
|
||||||
|
var $messages = array(
|
||||||
|
'info' => array(),
|
||||||
|
'warn' => array(),
|
||||||
|
'error' => array()
|
||||||
|
);
|
||||||
|
|
||||||
$this->info(__("ComicPress configuration updated.", 'comicpress'));
|
function info($message) { $this->messages['info'][] = $message; }
|
||||||
|
function warn($message) { $this->messages['warn'][] = $message; }
|
||||||
|
function error($message) { $this->messages['error'][] = $message; }
|
||||||
|
|
||||||
$this->comicpress->init();
|
function display_messages() {
|
||||||
}
|
foreach ($this->messages as $type => $messages) {
|
||||||
|
if (!empty($messages)) {
|
||||||
$this->comicpress->load();
|
echo '<div class="updated fade cp-' . $type . '">';
|
||||||
}
|
foreach ($messages as $message) {
|
||||||
}
|
echo '<p>' . $message . '</p>';
|
||||||
}
|
}
|
||||||
}
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// @codeCoverageIgnoreStart
|
}
|
||||||
var $messages = array(
|
// @codeCoverageIgnoreEnd
|
||||||
'info' => array(),
|
|
||||||
'warn' => array(),
|
|
||||||
'error' => array()
|
|
||||||
);
|
|
||||||
|
|
||||||
function info($message) { $this->messages['info'][] = $message; }
|
|
||||||
function warn($message) { $this->messages['warn'][] = $message; }
|
|
||||||
function error($message) { $this->messages['error'][] = $message; }
|
|
||||||
|
|
||||||
function display_messages() {
|
|
||||||
foreach ($this->messages as $type => $messages) {
|
|
||||||
if (!empty($messages)) {
|
|
||||||
echo '<div class="updated fade cp-' . $type . '">';
|
|
||||||
foreach ($messages as $message) {
|
|
||||||
echo '<p>' . $message . '</p>';
|
|
||||||
}
|
|
||||||
echo '</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<div style="overflow: hidden">
|
<div style="overflow: hidden">
|
||||||
<input type="hidden" name="cp[_nonce]" value="<?php echo esc_attr($nonce) ?>" />
|
<input type="hidden" name="cp[_nonce]" value="<?php echo esc_attr($nonce) ?>" />
|
||||||
<input type="hidden" name="cp[action]" value="comic-ordering" />
|
<input type="hidden" name="cp[action]" value="comic-ordering" />
|
||||||
|
<input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" />
|
||||||
<div id="ordering-zoom-slider-holder">
|
<div id="ordering-zoom-slider-holder">
|
||||||
<div id="ordering-zoom-slider">
|
<div id="ordering-zoom-slider">
|
||||||
<div id="ordering-zoom-handle"></div>
|
<div id="ordering-zoom-handle"></div>
|
||||||
@ -17,12 +18,14 @@
|
|||||||
(function() {
|
(function() {
|
||||||
$('ordering-refresh').observe('click', function(e) {
|
$('ordering-refresh').observe('click', function(e) {
|
||||||
Event.stop(e);
|
Event.stop(e);
|
||||||
|
|
||||||
new Ajax.Updater('comic-ordering-holder', ComicPressAdmin.ajax_uri, {
|
new Ajax.Updater('comic-ordering-holder', ComicPressAdmin.ajax_uri, {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
parameters: {
|
parameters: {
|
||||||
'cp[_nonce]': ComicPressAdmin.nonce,
|
'cp[_nonce]': ComicPressAdmin.nonce,
|
||||||
|
'cp[_action_nonce]': '<?php echo esc_js(wp_create_nonce('comicpress-refresh-ordering')) ?>',
|
||||||
'cp[action]': 'refresh-ordering',
|
'cp[action]': 'refresh-ordering',
|
||||||
'cp[post_id]': <?php echo $uploading_iframe_ID ?>
|
'cp[post_id]': <?php echo esc_js($uploading_iframe_ID) ?>
|
||||||
},
|
},
|
||||||
evalScripts: true,
|
evalScripts: true,
|
||||||
onSuccess: function() {
|
onSuccess: function() {
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
<div class="wrap">
|
|
||||||
<h2>Edit partials</h2>
|
|
||||||
<style type="text/css">
|
|
||||||
#partial-list-holder {
|
|
||||||
width: 200px;
|
|
||||||
float: left;
|
|
||||||
display: inline;
|
|
||||||
}
|
|
||||||
|
|
||||||
#partial-list-holder a {
|
|
||||||
font-size: 11px
|
|
||||||
}
|
|
||||||
|
|
||||||
#partial-editor {
|
|
||||||
margin-left: 210px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#partial-editor h3 {
|
|
||||||
margin: 0 0 10px
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<div id="partial-list-holder">
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$valid_partials = array();
|
|
||||||
foreach (glob(get_template_directory() . DIRECTORY_SEPARATOR . 'partials' . DIRECTORY_SEPARATOR . '*.inc') as $partial) {
|
|
||||||
if (preg_match('#(partials.*)\.inc$#', $partial, $matches) > 0) {
|
|
||||||
$valid_partials[] = $matches[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$selected = reset($valid_partials);
|
|
||||||
if (isset($_REQUEST['cp']['partial'])) {
|
|
||||||
if (in_array($_REQUEST['cp']['partial'], $valid_partials)) {
|
|
||||||
$selected = $_REQUEST['cp']['partial'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '<ul>';
|
|
||||||
foreach ($valid_partials as $partial_name) {
|
|
||||||
echo '<li>';
|
|
||||||
if ($partial_name == $selected) { echo '<strong>'; }
|
|
||||||
echo '<a href="' . add_query_arg('cp[partial]', $partial_name) . '">' . $partial_name . '</a>';
|
|
||||||
if ($partial_name == $selected) { echo '</strong>'; }
|
|
||||||
if (isset($this->comicpress->comicpress_options['override_partials'][$partial_name])) {
|
|
||||||
echo "(@)";
|
|
||||||
}
|
|
||||||
echo '</li>';
|
|
||||||
}
|
|
||||||
echo '</ul>';
|
|
||||||
|
|
||||||
$is_original = false;
|
|
||||||
if ($_REQUEST['cp']['action'] == __('Delete override partial', 'comicpress')) {
|
|
||||||
unset($_REQUEST['cp']['code']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_REQUEST['cp']['code'])) {
|
|
||||||
$partial_code = htmlentities($_REQUEST['cp']['code']);
|
|
||||||
} else {
|
|
||||||
if (isset($this->comicpress->comicpress_options['override_partials'][$selected])) {
|
|
||||||
$partial_code = htmlentities($this->comicpress->comicpress_options['override_partials'][$selected]);
|
|
||||||
} else {
|
|
||||||
$is_original = true;
|
|
||||||
$partial_code = htmlentities(file_get_contents(get_template_directory() . DIRECTORY_SEPARATOR . $selected . '.inc'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
</div>
|
|
||||||
<div id="partial-editor">
|
|
||||||
<h3><?php printf(__('Editing %s', 'comicpress'), $selected) ?></h3>
|
|
||||||
<?php if ($is_original) { ?>
|
|
||||||
<p>(<em><?php _e('currently editing default partial', 'comicpress') ?></em>)</p>
|
|
||||||
<?php } ?>
|
|
||||||
<form method="post">
|
|
||||||
<input type="hidden" name="cp[_nonce]" value="<?php echo $nonce ?>" />
|
|
||||||
<input type="hidden" name="cp[partial]" value="<?php echo $selected ?>" />
|
|
||||||
<textarea id="editor" name="cp[code]" rows="20" style="width: 100%"><?php echo $partial_code ?></textarea>
|
|
||||||
<input type="submit" class="button" name="cp[action]" value="<?php _e('Update partial', 'comicpress') ?>" />
|
|
||||||
<input type="submit" class="button" name="cp[action]" value="<?php _e('Delete override partial', 'comicpress') ?>" onclick="return confirm('<?php _e('Are you sure?', 'comicpress') ?>')" />
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
editAreaLoader.init({
|
|
||||||
id: "editor", syntax: "php", start_highlight: true
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<br style="clear: both" />
|
|
||||||
</div>
|
|
@ -1,8 +0,0 @@
|
|||||||
<div class="wrap">
|
|
||||||
<div id="layout-designer">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">
|
|
||||||
|
|
||||||
</script>
|
|
@ -2,6 +2,8 @@
|
|||||||
<h2><?php _e('ComicPress Config', 'comicpress') ?></h2>
|
<h2><?php _e('ComicPress Config', 'comicpress') ?></h2>
|
||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<input type="hidden" name="cp[_nonce]" value="<?php echo esc_attr($nonce) ?>" />
|
<input type="hidden" name="cp[_nonce]" value="<?php echo esc_attr($nonce) ?>" />
|
||||||
|
<input type="hidden" name="cp[action]" value="comicpress-options" />
|
||||||
|
<input type="hidden" name="cp[_action_nonce]" value="<?php echo esc_attr($action_nonce) ?>" />
|
||||||
<h3><?php _e('Global Options', 'comicpress') ?></h3>
|
<h3><?php _e('Global Options', 'comicpress') ?></h3>
|
||||||
<table class="widefat fixed">
|
<table class="widefat fixed">
|
||||||
<tr>
|
<tr>
|
||||||
@ -33,7 +35,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div style="text-align: center; margin-top: 10px;">
|
<div style="text-align: center; margin-top: 10px;">
|
||||||
<input class="button" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
|
<input class="button-primary" type="submit" value="<?php _e('Submit Updated ComicPress Options', 'comicpress') ?>" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -251,45 +251,6 @@ class ComicPressAdminTest extends PHPUnit_Framework_TestCase {
|
|||||||
), get_usermeta(1, 'comicpress-settings'));
|
), get_usermeta(1, 'comicpress-settings'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerTestHandleUpdate() {
|
|
||||||
return array(
|
|
||||||
array(array()),
|
|
||||||
array(array('cp' => true), false),
|
|
||||||
array(array('cp' => array()), false),
|
|
||||||
array(array('cp' => array()), true, true, true),
|
|
||||||
array(array('cp' => array(), 'attachments' => array()), true, true, false),
|
|
||||||
array(array('cp' => array('action' => 'test')), true, true, false),
|
|
||||||
array(array('cp' => array('action' => 'comic_ordering')), true, true, false),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider providerTestHandleUpdate
|
|
||||||
* @covers ComicPressAdmin::handle_update
|
|
||||||
*/
|
|
||||||
function testHandleUpdate($input, $add_nonce = false, $comicpress_load = false, $comicpress_save = false) {
|
|
||||||
$this->admin->comicpress = $this->getMock('ComicPress', array('save', 'init', 'load'));
|
|
||||||
if ($comicpress_load) {
|
|
||||||
$this->admin->comicpress->expects($this->once())->method('load');
|
|
||||||
}
|
|
||||||
if ($comicpress_save) {
|
|
||||||
$this->admin->comicpress->expects($this->once())->method('save');
|
|
||||||
$this->admin->comicpress->expects($this->once())->method('init');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($add_nonce) {
|
|
||||||
if (isset($input['cp'])) {
|
|
||||||
if (is_array($input['cp'])) {
|
|
||||||
$input['cp']['_nonce'] = wp_create_nonce('comicpress');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$_POST = $_REQUEST = $input;
|
|
||||||
|
|
||||||
$this->admin->handle_update();
|
|
||||||
}
|
|
||||||
|
|
||||||
function providerTestGetEditableAttachmentList() {
|
function providerTestGetEditableAttachmentList() {
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
|
Loading…
Reference in New Issue
Block a user