This commit is contained in:
Filip Penkava
2017-04-11 14:33:28 +02:00
parent 7d3875bda8
commit 0f53f42a66
3 changed files with 99 additions and 4 deletions

View File

@@ -3,6 +3,8 @@ add_action('admin_menu', 'superdesk_admin_actions');
add_filter('plugin_action_links_superdesk/superdeskPublisher.php', '_plugin_action_links'); add_filter('plugin_action_links_superdesk/superdeskPublisher.php', '_plugin_action_links');
//var_dump(get_post_format_strings());die();
function superdesk_admin_actions() { function superdesk_admin_actions() {
add_options_page('SUPERDESK', 'Superdesk Publisher', 'manage_options', __FILE__, 'superdesk_admin'); add_options_page('SUPERDESK', 'Superdesk Publisher', 'manage_options', __FILE__, 'superdesk_admin');
} }
@@ -38,6 +40,9 @@ function superdesk_admin() {
'convert-services' => $_POST['convert-services'], 'convert-services' => $_POST['convert-services'],
'subject-type' => $_POST['subject-type'], 'subject-type' => $_POST['subject-type'],
'category' => $_POST['category'], '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); update_option('superdesk_settings', $settings);
} else if (get_option('superdesk_settings')) { } else if (get_option('superdesk_settings')) {
@@ -58,6 +63,9 @@ function superdesk_admin() {
'convert-services' => '', 'convert-services' => '',
'subject-type' => '', 'subject-type' => '',
'category' => '', 'category' => '',
'separator-caption-image' => '',
'copyrightholder-image' => '',
'copyrightnotice-image' => '',
); );
} }
$statuses = array( $statuses = array(
@@ -319,6 +327,62 @@ function superdesk_admin() {
</select> </select>
</td> </td>
</tr> </tr>
<tr>
<th scope="row">
<label for="separator-caption-image">Separator for caption image</label>
</th>
<td>
<input type="text" name="separator-caption-image" id="separator-caption-image" class="regular-text" value="<?php echo($settings['separator-caption-image']); ?>">
</td>
</tr>
<tr>
<th scope="row">
Display the copyrightholder image
</th>
<td>
<fieldset>
<label for="copyrightholder-image-off">
<input type="radio" name="copyrightholder-image" id="copyrightholder-image-off" value="off"<?php
if ($settings['copyrightholder-image'] == 'off') {
echo(' checked');
}
?>> off
</label>
<br>
<label for="copyrightholder-image-on">
<input type="radio" name="copyrightholder-image" id="copyrightholder-image-on" value="on"<?php
if ($settings['copyrightholder-image'] == 'on') {
echo(' checked');
}
?>> on
</label>
</fieldset>
</td>
</tr>
<tr>
<th scope="row">
Display the copyrightnotice image
</th>
<td>
<fieldset>
<label for="copyrightnotice-image-off">
<input type="radio" name="copyrightnotice-image" id="copyrightnotice-image-off" value="off"<?php
if ($settings['copyrightnotice-image'] == 'off') {
echo(' checked');
}
?>> off
</label>
<br>
<label for="copyrightnotice-image-on">
<input type="radio" name="copyrightnotice-image" id="copyrightnotice-image-on" value="on"<?php
if ($settings['copyrightnotice-image'] == 'on') {
echo(' checked');
}
?>> on
</label>
</fieldset>
</td>
</tr>
</tbody> </tbody>
</table> </table>
<p class="submit"> <p class="submit">

View File

@@ -11,7 +11,7 @@ $obj = json_decode($json, true);
if ($obj['type'] == 'text') { if ($obj['type'] == 'text') {
$settings = get_option('mvp_settings'); $settings = get_option('superdesk_settings');
if ($obj['pubstatus'] == 'usable') { if ($obj['pubstatus'] == 'usable') {
$content = $obj['description_html'] . "<!--more-->" . $obj['body_html']; $content = $obj['description_html'] . "<!--more-->" . $obj['body_html'];
@@ -169,7 +169,9 @@ if ($obj['type'] == 'text') {
if ($fileExist) { if ($fileExist) {
set_post_thumbnail($post_ID, $fileExist->post_id); set_post_thumbnail($post_ID, $fileExist->post_id);
} else { } 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') { } elseif ($obj['pubstatus'] == 'canceled') {

View File

@@ -82,7 +82,7 @@ function generatePassword() {
return $password; return $password;
} }
function saveAttachment($picture, $post_ID) { function saveAttachment($picture, $post_ID, $caption, $alt) {
$filenameQ = explode("/", $picture['renditions']['original']['media']); $filenameQ = explode("/", $picture['renditions']['original']['media']);
$filename = $filenameQ[count($filenameQ) - 1]; $filename = $filenameQ[count($filenameQ) - 1];
@@ -91,8 +91,9 @@ function saveAttachment($picture, $post_ID) {
$attachment = array( $attachment = array(
'guid' => wp_upload_dir()['url'] . '/' . basename($filename), 'guid' => wp_upload_dir()['url'] . '/' . basename($filename),
'post_mime_type' => $picture['mimetype'], 'post_mime_type' => $picture['mimetype'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($picture['headline'])), 'post_title' => $caption,
'post_content' => '', 'post_content' => '',
'post_excerpt' => $caption,
'post_status' => 'inherit' 'post_status' => 'inherit'
); );
@@ -104,6 +105,8 @@ function saveAttachment($picture, $post_ID) {
wp_update_attachment_metadata($attach_id, $attach_data); wp_update_attachment_metadata($attach_id, $attach_data);
set_post_thumbnail($post_ID, $attach_id); 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) { function custom_wpkses_post_tags($tags, $context) {
@@ -119,6 +122,32 @@ function custom_wpkses_post_tags($tags, $context) {
return $tags; 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); 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); wp_oembed_add_provider('#http://(www\.)?youtube\.com/watch.*#i', 'http://www.youtube.com/oembed', true);