From 0f53f42a669ca8862032d722f1a63c55ced0e881 Mon Sep 17 00:00:00 2001 From: Filip Penkava Date: Tue, 11 Apr 2017 14:33:28 +0200 Subject: [PATCH] WSP-63 --- admin/admin.php | 64 ++++++++++++++++++++++++++++++++++++++++++ autoload.php | 6 ++-- superdeskPublisher.php | 33 ++++++++++++++++++++-- 3 files changed, 99 insertions(+), 4 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index b7b6b05..9452145 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -3,6 +3,8 @@ add_action('admin_menu', 'superdesk_admin_actions'); add_filter('plugin_action_links_superdesk/superdeskPublisher.php', '_plugin_action_links'); +//var_dump(get_post_format_strings());die(); + function superdesk_admin_actions() { add_options_page('SUPERDESK', 'Superdesk Publisher', 'manage_options', __FILE__, 'superdesk_admin'); } @@ -38,6 +40,9 @@ function superdesk_admin() { 'convert-services' => $_POST['convert-services'], 'subject-type' => $_POST['subject-type'], 'category' => $_POST['category'], + 'separator-caption-image' => $_POST['separator-caption-image'], + 'copyrightholder-image' => $_POST['copyrightholder-image'], + 'copyrightnotice-image' => $_POST['copyrightnotice-image'], ); update_option('superdesk_settings', $settings); } else if (get_option('superdesk_settings')) { @@ -58,6 +63,9 @@ function superdesk_admin() { 'convert-services' => '', 'subject-type' => '', 'category' => '', + 'separator-caption-image' => '', + 'copyrightholder-image' => '', + 'copyrightnotice-image' => '', ); } $statuses = array( @@ -319,6 +327,62 @@ function superdesk_admin() { + + + + + + + + + + + Display the copyrightholder image + + +
+ +
+ +
+ + + + + Display the copyrightnotice image + + +
+ +
+ +
+ +

diff --git a/autoload.php b/autoload.php index df53985..cc853f8 100644 --- a/autoload.php +++ b/autoload.php @@ -11,7 +11,7 @@ $obj = json_decode($json, true); if ($obj['type'] == 'text') { - $settings = get_option('mvp_settings'); + $settings = get_option('superdesk_settings'); if ($obj['pubstatus'] == 'usable') { $content = $obj['description_html'] . "" . $obj['body_html']; @@ -169,7 +169,9 @@ if ($obj['type'] == 'text') { if ($fileExist) { set_post_thumbnail($post_ID, $fileExist->post_id); } else { - saveAttachment($obj['associations']['featuremedia'], $post_ID); + $caption = generate_caption_image($obj['associations']['featuremedia']); + $alt = (!empty($obj['associations']['featuremedia']['body_text'])) ? wp_strip_all_tags($obj['associations']['featuremedia']['body_text']) : ''; + saveAttachment($obj['associations']['featuremedia'], $post_ID, $caption, $alt); } } } elseif ($obj['pubstatus'] == 'canceled') { diff --git a/superdeskPublisher.php b/superdeskPublisher.php index df39634..84f9d41 100644 --- a/superdeskPublisher.php +++ b/superdeskPublisher.php @@ -82,7 +82,7 @@ function generatePassword() { return $password; } -function saveAttachment($picture, $post_ID) { +function saveAttachment($picture, $post_ID, $caption, $alt) { $filenameQ = explode("/", $picture['renditions']['original']['media']); $filename = $filenameQ[count($filenameQ) - 1]; @@ -91,8 +91,9 @@ function saveAttachment($picture, $post_ID) { $attachment = array( 'guid' => wp_upload_dir()['url'] . '/' . basename($filename), 'post_mime_type' => $picture['mimetype'], - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($picture['headline'])), + 'post_title' => $caption, 'post_content' => '', + 'post_excerpt' => $caption, 'post_status' => 'inherit' ); @@ -104,6 +105,8 @@ function saveAttachment($picture, $post_ID) { wp_update_attachment_metadata($attach_id, $attach_data); set_post_thumbnail($post_ID, $attach_id); + + update_post_meta($attach_id, '_wp_attachment_image_alt', wp_slash($alt)); } function custom_wpkses_post_tags($tags, $context) { @@ -119,6 +122,32 @@ function custom_wpkses_post_tags($tags, $context) { return $tags; } +function generate_caption_image($media) { + $caption = ''; + $settings = get_option('superdesk_settings'); + if (!empty(trim($media['description_text']))) { + $caption.= wp_strip_all_tags($media['description_text']); + } + + if (!empty(trim($media['byline']))) { + if (!empty($caption)) { + $caption.=' '; + } + + $caption.= $settings['separator-caption-image'] . ': ' . wp_strip_all_tags($media['byline']); + } + + if (!empty(trim($media['copyrightholder'])) && $settings['copyrightholder-image'] == 'on') { + $caption.= ' / ' . wp_strip_all_tags($media['copyrightholder']); + } + + if (!empty(trim($media['copyrightnotice'])) && $settings['copyrightnotice-image'] == 'on') { + $caption.= ' ' . wp_strip_all_tags($media['copyrightnotice']); + } + + return $caption; +} + add_filter('wp_kses_allowed_html', 'custom_wpkses_post_tags', 10, 2); wp_oembed_add_provider('#http://(www\.)?youtube\.com/watch.*#i', 'http://www.youtube.com/oembed', true);