mirror of
https://github.com/Frumph/comic-easel.git
synced 2026-08-24 21:41:31 -04:00
2647482d1d
Co-authored-by: gpt-5.6-sol <noreply@openai.com>
281 lines
12 KiB
PHP
281 lines
12 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) exit;
|
|
|
|
function ceo_display_featured_image_comic($size = 'full') {
|
|
global $post;
|
|
$output = '';
|
|
$usemap = '';
|
|
$next_comic = '';
|
|
$comic_has_map = false;
|
|
// Allow the size to be filtered for external plugins and the like to change it on whim.
|
|
$size = apply_filters('ceo_display_featured_image_comic_size', $size);
|
|
$post_image_id = get_post_thumbnail_id($post->ID);
|
|
if ($post_image_id) { // If there's a featured image.
|
|
$hovertext = ceo_the_hovertext();
|
|
if (!empty($hovertext)) {
|
|
$hovertext = 'alt="'.$hovertext.'" title="'.$hovertext.'" ';
|
|
} else {
|
|
$title = ceo_title_for_attribute($post->ID);
|
|
$hovertext = 'alt="'.$title.'" title="'.$title.'" ';
|
|
}
|
|
$thumbnail = wp_get_attachment_image_src( $post_image_id, $size, false);
|
|
if (is_array($thumbnail)) {
|
|
$thumbnail = reset($thumbnail);
|
|
|
|
$comic_has_map = get_post_meta($post->ID, 'comic-has-map', true);
|
|
if (!$comic_has_map || is_wp_error($comic_has_map)) $comic_has_map = false;
|
|
|
|
$comic_lightbox = get_post_meta($post->ID, 'comic-open-lightbox', true);
|
|
if (is_wp_error($comic_lightbox)) $comic_lightbox = false;
|
|
|
|
if (ceo_pluginfo('navigate_only_chapters')) {
|
|
$next_comic = ceo_get_next_comic_in_chapter_permalink();
|
|
} else {
|
|
$next_comic = ceo_get_next_comic_permalink();
|
|
}
|
|
|
|
$linkto = '';
|
|
$linkto = get_post_meta($post->ID, 'link-to', true);
|
|
|
|
if ($linkto) $next_comic = esc_url($linkto);
|
|
|
|
if ($linkto && !$comic_has_map) $output .= '<a href="'.esc_url($linkto).'" '.$hovertext.'>';
|
|
|
|
if ($comic_lightbox && !$linkto && !$comic_has_map) {
|
|
$output .= '<a href="'.esc_url($thumbnail).'" '.$hovertext.' rel="lightbox">';
|
|
}
|
|
|
|
if (ceo_pluginfo('click_comic_next') && !empty($next_comic) && !$comic_lightbox && !$linkto && !$comic_has_map) {
|
|
$output .= '<a href="'.esc_url($next_comic).'" '.$hovertext.'>';
|
|
}
|
|
// only show if the comic is not linkable
|
|
if ($comic_has_map) $usemap = 'usemap="#comicmap" ';
|
|
|
|
$output .= '<img src="'.esc_url($thumbnail).'" '.$hovertext.' '.$usemap.' />';
|
|
if ((ceo_pluginfo('click_comic_next') && !empty($next_comic) && !$comic_has_map) || $comic_lightbox || $linkto) {
|
|
$output .= '</a>';
|
|
}
|
|
// if ($comic_lightbox) $output .= '<div class="comic-lightbox-text">'.__('Click comic to view larger version.','comiceasel').'</div>';
|
|
}
|
|
}
|
|
return apply_filters('ceo_display_featured_image_comic', $output);
|
|
}
|
|
|
|
function ceo_display_comic_gallery($size = 'full') {
|
|
global $post;
|
|
$output = '';
|
|
if (ceo_pluginfo('click_comic_next')) {
|
|
if (ceo_pluginfo('navigate_only_chapters')) {
|
|
$next_comic = ceo_get_next_comic_in_chapter_permalink();
|
|
} else {
|
|
$next_comic = ceo_get_next_comic_permalink();
|
|
}
|
|
}
|
|
$hovertext = ceo_the_hovertext();
|
|
$comic_galleries_full = get_post_meta( $post->ID, 'comic-gallery-full', true );
|
|
if ($comic_galleries_full) {
|
|
$comic_lightbox = get_post_meta( $post->ID, 'comic-open-lightbox', true );
|
|
$comic_galleries_jquery = get_post_meta( $post->ID, 'comic-gallery-jquery', true );
|
|
if ($images = get_posts(array(
|
|
'post_parent' => $post->ID,
|
|
'post_type' => 'attachment',
|
|
'numberposts' => -1, // show all
|
|
'post_status' => null,
|
|
'post_mime_type' => 'image',
|
|
'orderby' => 'menu_order',
|
|
'order' => 'ASC'
|
|
))) {
|
|
$count = 0;
|
|
if ($comic_galleries_jquery) wp_enqueue_script('multicomic', ceo_pluginfo('plugin_url') . 'js/multicomic.js', null, null, true);
|
|
foreach($images as $image) {
|
|
if ($comic_galleries_jquery) $output .= '<div id="comic-'.$count.'" class="comicpane">';
|
|
$thumbnail = wp_get_attachment_image_src($image->ID, 'full');
|
|
$thumbnail = reset($thumbnail);
|
|
|
|
// $thumbnail = apply_filters('jetpack_photon_url', $thumbnail);
|
|
|
|
if ($comic_lightbox) {
|
|
$output .= '<a href="'.esc_url($thumbnail).'" title="'.$hovertext.'" rel="lightbox">';
|
|
}
|
|
if (ceo_pluginfo('click_comic_next') && !empty($next_comic) && !$comic_lightbox) {
|
|
$output .= '<a href="'.esc_url($next_comic).'" title="'.$hovertext.'">';
|
|
}
|
|
$output .= '<img src="'.esc_url($thumbnail).'" alt="'.$hovertext.'" title="'.$hovertext.'" />';
|
|
if ((ceo_pluginfo('click_comic_next') && !empty($next_comic)) || $comic_lightbox) {
|
|
$output .= '</a>';
|
|
}
|
|
|
|
if ($comic_galleries_jquery) $output .= "</div>\r\n";
|
|
$count += 1;
|
|
}
|
|
if ($comic_galleries_jquery) $output .= "<button id=\"show-".$count."\" type=\"button\" style=\"display:none;\">".$count."</button>\r\n";
|
|
// if ($comic_lightbox) $output .= '<div class="comic-lightbox-text">'.__('Click comic to view larger version.','comiceasel').'</div>';
|
|
}
|
|
} else {
|
|
$output .= ceo_display_featured_image_comic($size);
|
|
$columns = get_post_meta( $post->ID, 'comic-gallery-columns', true );
|
|
if (empty($columns)) $columns = 5;
|
|
$args = array(
|
|
'id' => $post->ID,
|
|
'columns' => $columns,
|
|
'exclude' => array($post->ID)
|
|
);
|
|
$output .= gallery_shortcode($args);
|
|
}
|
|
return apply_filters('ceo_display_comic_gallery', $output);
|
|
}
|
|
|
|
function ceo_display_flash_comic($post, $flash_url) {
|
|
$height = get_post_meta( $post->ID, "flash_height", true );
|
|
$width = get_post_meta( $post->ID, "flash_width", true );
|
|
if (empty($height)) $height = '380';
|
|
if (empty($width)) $width = '520';
|
|
$output = '';
|
|
$output .= '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="'.esc_attr($width).'" height="'.esc_attr($height).'" id="flash_comic" align="middle">'."\r\n";
|
|
$output .= ' <param name="movie" value="'.esc_url($flash_url).'"/>'."\r\n";
|
|
$output .= ' <!--[if !IE]>-->'."\r\n";
|
|
$output .= ' <object type="application/x-shockwave-flash" data="'.esc_url($flash_url).'" width="'.esc_attr($width).'" height="'.esc_attr($height).'">'."\r\n";
|
|
$output .= ' <param name="movie" value="'.esc_url($flash_url).'"/>'."\r\n";
|
|
$output .= ' <!--<![endif]-->'."\r\n";
|
|
$output .= ceo_display_featured_image_comic('full');
|
|
$output .= ' <a href="http://www.adobe.com/go/getflash">'."\r\n";
|
|
$output .= ' <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>'."\r\n";
|
|
$output .= ' </a>'."\r\n";
|
|
$output .= ' <!--[if !IE]>-->'."\r\n";
|
|
$output .= ' </object>'."\r\n";
|
|
$output .= ' <!--<![endif]-->'."\r\n";
|
|
$output .= '</object>';
|
|
add_action('wp_footer', 'ceo_init_comic_swf');
|
|
return apply_filters('ceo_display_flash_comic', $output);
|
|
}
|
|
|
|
function ceo_init_comic_swf() {
|
|
wp_enqueue_script('swfobject', '', array(), false, true);
|
|
}
|
|
|
|
function ceo_display_comic($size = 'full') {
|
|
global $post;
|
|
if ( post_password_required() ) {
|
|
return __('This comic is password protected.','comiceasel');
|
|
}
|
|
$refer_only = get_post_meta( $post->ID, 'refer-only', 'true');
|
|
|
|
if (!empty($refer_only) && !defined('CEO_DISABLE_REFER_ONLY')) {
|
|
$ref_only_msg = '';
|
|
$refer_only_msg = get_post_meta( $post->ID, 'refer-only-msg', 'true') ? get_post_meta( $post->ID, 'refer-only-msg', 'true') : __('Read post message below to find out how to view this.', 'comiceasel');
|
|
if (ceo_get_referer() !== $refer_only) {
|
|
$refer_only_msg = ceo_escape_stored_text($refer_only_msg);
|
|
return apply_filters('ceo_refer_only_msg', $refer_only_msg);
|
|
}
|
|
}
|
|
$output = '';
|
|
if (ceo_the_above_html()) $output .= ceo_comic_html_for_output(ceo_the_above_html(), $post)."\r\n";
|
|
|
|
if ($flash_file = get_post_meta($post->ID, "flash_file", true)) {
|
|
$output .= ceo_display_flash_comic($post, $flash_file);
|
|
} elseif (($media_url = get_post_meta( $post->ID, 'media_url', true )) && !defined('CEO_FEATURE_MEDIA_EMBED')) {
|
|
$output .= '<center>';
|
|
global $content_width;
|
|
$old_content_width = $content_width;
|
|
$media_width = get_post_meta($post->ID, 'media_width', true);
|
|
if (!empty($media_width)) $content_width = $media_width;
|
|
$output .= wp_oembed_get( $media_url );
|
|
$content_width=$old_content_width;
|
|
$output .= '</center>';
|
|
} else {
|
|
$comic_galleries = get_post_meta( $post->ID, 'comic-gallery', true );
|
|
if ($comic_galleries) {
|
|
$output .= ceo_display_comic_gallery($size);
|
|
} else {
|
|
$output .= ceo_display_featured_image_comic($size);
|
|
}
|
|
}
|
|
if (ceo_the_below_html()) $output .= ceo_comic_html_for_output(ceo_the_below_html(), $post)."\r\n";
|
|
if ($output) {
|
|
return apply_filters('ceo_comics_display_comic', $output);
|
|
} else
|
|
return apply_filters('ceo_comics_display_comic', __('<!-- No HTML, Gallery or Featured Image Found. //-->', 'comiceasel'));
|
|
}
|
|
|
|
add_filter('ceo_comics_display_comic', 'ceo_filter_comic_output',10,1);
|
|
|
|
function ceo_filter_comic_output($output = '') {
|
|
global $post;
|
|
return $output;
|
|
}
|
|
|
|
function ceo_the_hovertext($override_post = null) {
|
|
global $post;
|
|
$post_to_use = !is_null($override_post) ? $override_post : $post;
|
|
$hovertext = esc_attr( get_post_meta( $post_to_use->ID, 'comic-hovertext', true ) );
|
|
if (empty($hovertext)) $hovertext = esc_attr( get_post_meta($post_to_use->ID, 'hovertext', true) ); // check if using old hovertext
|
|
// return (empty($hovertext)) ? get_the_title($post_to_use->ID) : $hovertext;
|
|
return (empty($hovertext)) ? '' : $hovertext;
|
|
}
|
|
|
|
/**
|
|
* Prepare a comic-html-above / comic-html-below value for output.
|
|
*
|
|
* These two fields are meant to hold markup, so the value is not escaped. It
|
|
* cannot be trusted blindly either: the meta keys are unprotected on a post
|
|
* type that declares custom-fields support, so anyone who can edit a comic can
|
|
* write to them through WordPress's own Custom Fields panel, bypassing the
|
|
* plugin's meta box entirely.
|
|
*
|
|
* The stored value therefore arrives in two shapes -- entity-encoded when it
|
|
* came through the meta box (which escapes on save), raw when it came through
|
|
* Custom Fields -- so decode first to normalise, then apply WordPress's own
|
|
* trust rule: content from an author who holds unfiltered_html renders as
|
|
* written, anything else is filtered exactly like post content would be.
|
|
*/
|
|
function ceo_comic_html_for_output($value, $post_to_use = null) {
|
|
$html = html_entity_decode((string)$value, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401);
|
|
if (is_null($post_to_use) || empty($post_to_use->post_author)) return wp_kses_post($html);
|
|
|
|
$author = (int)$post_to_use->post_author;
|
|
if (!user_can($author, 'unfiltered_html')) return wp_kses_post($html);
|
|
|
|
// The author being trusted is not enough on its own: someone else may have
|
|
// edited the post since. On multisite an Editor lacks unfiltered_html but can
|
|
// still edit an administrator's comic, so check whoever touched it last too.
|
|
$last_editor = (int)get_post_meta($post_to_use->ID, '_edit_last', true);
|
|
if ($last_editor && $last_editor !== $author && !user_can($last_editor, 'unfiltered_html')) return wp_kses_post($html);
|
|
|
|
return $html;
|
|
}
|
|
|
|
function ceo_the_above_html($override_post = null) {
|
|
global $post;
|
|
$post_to_use = !is_null($override_post) ? $override_post : $post;
|
|
$html_to_use = get_post_meta( $post_to_use->ID, 'comic-html-above', true);
|
|
return $html_to_use;
|
|
}
|
|
|
|
function ceo_the_below_html($override_post = null) {
|
|
global $post;
|
|
$post_to_use = !is_null($override_post) ? $override_post : $post;
|
|
$html_to_use = get_post_meta( $post_to_use->ID, 'comic-html-below', true);
|
|
return $html_to_use;
|
|
}
|
|
|
|
// Do the thumbnail display functions here.
|
|
function ceo_display_comic_thumbnail($thumbnail_size = 'thumbnail', $override_post = null, $size = array()) {
|
|
global $post;
|
|
$thumbnail = $output = '';
|
|
$post_to_use = !empty($override_post) ? $override_post : $post;
|
|
if (class_exists('MultiPostThumbnails') && ($thumbnail_size == 'secondary-image') && is_null($override_post)) {
|
|
$thumbnail = MultiPostThumbnails::get_the_post_thumbnail(get_post_type(), 'secondary-image');
|
|
} else {
|
|
if (!empty($size)) {
|
|
$thumbnail = get_the_post_thumbnail($post_to_use->ID, $size);
|
|
} else
|
|
$thumbnail = get_the_post_thumbnail($post_to_use->ID, $thumbnail_size);
|
|
}
|
|
if ( has_post_thumbnail($post_to_use->ID) ) {
|
|
$output = '<a href="'.esc_url(get_permalink($post_to_use->ID)).'" rel="bookmark" title="'.ceo_title_for_attribute($post_to_use->ID).'">'.$thumbnail.'</a>'."\r\n";
|
|
} else {
|
|
// $output = "No Thumbnail Found.";
|
|
}
|
|
return apply_filters('easel_display_comic_thumbnail', $output);
|
|
}
|