Skip to content

Commit

Permalink
Merge pull request #2626 from kprajapatii/master
Browse files Browse the repository at this point in the history
Allow to play video file in post images lightbox - ADDED
  • Loading branch information
kprajapatii authored Jul 4, 2024
2 parents 79bb121 + e144721 commit c4ce2c7
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 33 deletions.
107 changes: 79 additions & 28 deletions includes/image-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ function geodir_get_screenshot( $url, $params = array() ) {
$args['vpw'] = $params['vpw'];
$args['vph'] = $params['vph'];
}

if ( ! empty( $params['requeue'] ) ) {
$args['requeue'] = 'true';
}
Expand All @@ -215,15 +216,25 @@ function geodir_get_screenshot( $url, $params = array() ) {
return apply_filters( 'geodir_get_screenshot', $screenshot, $url, $params, $args );
}

function geodir_get_field_screenshot( $field, $sizes = array( 'w' => 825, 'h' => 430, 'image' => 1 ) ) {
function geodir_get_field_screenshot( $field, $sizes = array(), $the_post = array() ) {
global $gd_post;

if ( empty( $sizes ) || ! is_array( $sizes ) ) {
$sizes = array( 'w' => 825, 'h' => 430, 'image' => 1 );
}

if ( empty( $the_post ) ) {
$the_post = $gd_post;
}

$url = '';
if ( isset( $gd_post->{$field} ) && esc_url( $gd_post->{$field}) ) {

if ( isset( $the_post->{$field} ) && esc_url( $the_post->{$field} ) ) {
// check if maybe a video URL
if ($video = geodir_get_video_screenshot( $gd_post->{$field})) {
if ($video = geodir_get_video_screenshot( $the_post->{$field} ) ) {
$url = $video;
}else{
$url = geodir_get_screenshot( $gd_post->{$field}, $sizes );
$url = geodir_get_screenshot( $the_post->{$field}, $sizes );
}
}

Expand Down Expand Up @@ -273,6 +284,12 @@ function geodir_get_images( $post_id = 0, $limit = '', $logo = false, $revision_

$post_images = array();

$the_post = ! empty( $gd_post ) && $gd_post->ID == $post_id ? $gd_post : array();

if ( empty( $the_post->post_id ) && ! empty( $post_id ) ) {
$the_post = geodir_get_post_info( $post_id );
}

if ( ! empty( $types ) ) {
$original_types = $types;

Expand All @@ -283,7 +300,7 @@ function geodir_get_images( $post_id = 0, $limit = '', $logo = false, $revision_
if ( stripos( strrev( $val ), "tohsneercs_" ) === 0 ) {
$field = str_replace( "_screenshot", "", $val );

if ( isset( $gd_post->{$field} ) && esc_url( $gd_post->{$field} ) ) {
if ( isset( $the_post->{$field} ) && esc_url( $the_post->{$field} ) ) {
$has_screenshots = true;
} else {
unset( $types[$key] ); // Unset if an invalid screenshot type
Expand All @@ -305,24 +322,58 @@ function geodir_get_images( $post_id = 0, $limit = '', $logo = false, $revision_
if ( stripos( strrev( $type ), "tohsneercs_") === 0 ) {
$field = str_replace( "_screenshot", "", $type );

if ( isset( $gd_post->{$field} ) && esc_url( $gd_post->{$field} ) ) {
$image_src = geodir_get_field_screenshot( $field );

if ( $image_src ) {
$image = new stdClass();
$image->ID = 0;
$image->post_id = $post_id;
$image->user_id = 0;
$image->title = wp_sprintf( __( '%s screenshot', 'geodirectory' ), esc_attr( $field ) );
$image->caption = '';
$image->file = ltrim( $image_src, '/\\' );
$image->mime_type = '';
$image->menu_order = 0;
$image->featured= 0;
$image->is_approved = 1;
$image->metadata = '';
$image->type = esc_attr( $field ) . '_screenshot';
$new_images[] = $image;
if ( isset( $the_post->{$field} ) && esc_url( $the_post->{$field} ) ) {
$file_fields = GeoDir_Media::get_file_fields( $the_post->post_type );

if ( ! empty( $file_fields ) && isset( $file_fields[ $field ] ) ) {
$attachments = GeoDir_Media::get_attachments_by_type( $post_id, $field, $limit, $revision_id, '', $status );
} else {
$attachments = array();
}

if ( ! empty( $attachments ) ) {
foreach ( $attachments as $ia => $attachment ) {
$media_url = geodir_get_image_src( $attachment );
$media_image = geodir_get_screenshot( $media_url, array( 'w' => 825, 'h' => 430, 'image' => 1 ) );

if ( $media_image ) {
$image = new stdClass();
$image->ID = 0;
$image->post_id = $post_id;
$image->user_id = 0;
$image->title = ! empty( $attachment->title ) ? $attachment->title : wp_sprintf( __( '%s screenshot', 'geodirectory' ), esc_attr( $field ) );
$image->caption = ! empty( $attachment->caption ) ? $attachment->caption : '';
$image->file = ltrim( $media_image, '/\\' );
$image->mime_type = $attachment->mime_type;
$image->menu_order = 0;
$image->featured = 0;
$image->is_approved = 1;
$image->metadata = array( 'media_url' => $media_url, 'mime_type' => $attachment->mime_type );
$image->type = esc_attr( $field ) . '_screenshot';

$new_images[] = $image;
}
}
} else {
$image_src = geodir_get_field_screenshot( $field, array(), $the_post );

if ( $image_src ) {
$image = new stdClass();
$image->ID = 0;
$image->post_id = $post_id;
$image->user_id = 0;
$image->title = wp_sprintf( __( '%s screenshot', 'geodirectory' ), esc_attr( $field ) );
$image->caption = '';
$image->file = ltrim( $image_src, '/\\' );
$image->mime_type = '';
$image->menu_order = 0;
$image->featured= 0;
$image->is_approved = 1;
$image->metadata = '';
$image->type = esc_attr( $field ) . '_screenshot';

$new_images[] = $image;
}
}
}
} else {
Expand Down Expand Up @@ -361,7 +412,7 @@ function geodir_get_images( $post_id = 0, $limit = '', $logo = false, $revision_
// Fallback images
foreach( $fallback_types as $fallback_type ) {
// Logo
if ( $fallback_type == 'logo' && isset( $gd_post->logo ) && $gd_post->logo && geodir_post_has_image_types( 'logo', $post_id ) ) {
if ( $fallback_type == 'logo' && isset( $the_post->logo ) && $the_post->logo && geodir_post_has_image_types( 'logo', $post_id ) ) {
$logo_image = GeoDir_Media::get_attachments_by_type( $post_id, 'logo', 1, '', '', $status );
if ( $logo_image ) {
$post_images = $logo_image;
Expand Down Expand Up @@ -439,9 +490,9 @@ function geodir_get_images( $post_id = 0, $limit = '', $logo = false, $revision_
}
}

if ( $fallback_type == 'cpt_default' && ! empty( $gd_post ) ) {
if ( $fallback_type == 'cpt_default' && ! empty( $the_post ) ) {
// Check for CPT default image
$cpt = $gd_post->post_type;
$cpt = $the_post->post_type;
if ( $cpt ) {
$cpts = geodir_get_posttypes('array');
if ( ! empty( $cpts[$cpt]['default_image'] ) ) {
Expand All @@ -467,8 +518,8 @@ function geodir_get_images( $post_id = 0, $limit = '', $logo = false, $revision_
if ( stripos( strrev( $fallback_type ), "tohsneercs_" ) === 0 ) { // screenshots
$field = str_replace( "_screenshot", "", $fallback_type );

if ( isset( $gd_post->{$field} ) && esc_url( $gd_post->{$field} ) ) {
$image_src = geodir_get_field_screenshot( $field );
if ( isset( $the_post->{$field} ) && esc_url( $the_post->{$field} ) ) {
$image_src = geodir_get_field_screenshot( $field, array(), $the_post );

if ( $image_src ) {
$image = new stdClass();
Expand Down
16 changes: 14 additions & 2 deletions includes/widgets/class-geodir-widget-post-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ public function output_images( $options ) {
$post_id = absint( $options['id'] );
}

$current_post = ! empty( $gd_post ) && $gd_post->ID == $post_id ? $gd_post : array();

if ( empty( $current_post->post_id ) && ! empty( $post_id ) ) {
$current_post = geodir_get_post_info( $post_id );
}

if ( $block_preview ) {
$options['ajax_load'] = false; // disable ajax loading
$post_id = -1;
Expand All @@ -430,7 +436,7 @@ public function output_images( $options ) {
}

if ( $block_preview ) {
$post_images = $this->get_dummy_images();
$post_images = $this->get_dummy_images( $options['limit'] );
} else {
// Show images with all statuses to admin & post author.
if ( is_preview() && geodir_listing_belong_to_current_user( $post_id ) ) {
Expand Down Expand Up @@ -559,6 +565,7 @@ public function output_images( $options ) {
$main_wrapper_class_x = 'card-img-top embed-responsive-item';

$args = array(
'current_post' => $current_post,
'main_wrapper_class' => " " . $main_wrapper_class . " " . geodir_sanitize_html_class( $options['css_class'] ),
'type' => $options['type'],
'slider_id' => $slider_id,
Expand Down Expand Up @@ -626,7 +633,7 @@ public static function get_image_sizes() {
*
* @return array
*/
public static function get_dummy_images() {
public static function get_dummy_images( $limit = 0 ) {
$images = array();
$dummy_image_url = 'https://ayecode.b-cdn.net/dummy/plugin/';
$dummy_images = array(
Expand Down Expand Up @@ -655,6 +662,11 @@ public static function get_dummy_images() {
$image->metadata = '';
$image->type = '_dummy';
$images[] = $image;

if ( $limit > 0 && $limit == $count ) {
return $images;
}

$count++;
}

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ __WARNING: GDv2 is a significant update over GDv1 and may require manual work, s

= GeoDirectory v2.3.60 - TBD =
* Category default image is not set during dummy data import - FIXED
* Allow to play video file in post images lightbox - ADDED

= GeoDirectory v2.3.59 - 2024-06-27 =
* Use default distance radius when service_distance value is not set - CHANGED
Expand Down
24 changes: 21 additions & 3 deletions templates/bootstrap/images/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @see https://docs.wpgeodirectory.com/article/346-customizing-templates/
* @package GeoDirectory/Templates
* @version 2.3.58
* @version 2.3.60
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -47,6 +47,11 @@

global $gd_post, $aui_bs5, $geodir_carousel_open;

$the_post = $gd_post;

if ( empty( $the_post ) && ! empty( $current_post ) ) {
$the_post = $current_post;
}
?>
<div class="<?php echo esc_attr( $main_wrapper_class ); ?>">
<?php
Expand Down Expand Up @@ -144,9 +149,19 @@
$link_tag_close_ss = "<i class=\"fas fa-search-plus w-auto h-auto\" aria-hidden=\"true\"></i></a>";
} else if ( $link_screenshot_to == 'lightbox_url' ) {
$field_key = str_replace( "_screenshot", "", $image->type );
$link = isset( $gd_post->{$field_key} ) ? $gd_post->{$field_key} : '';
$link = isset( $the_post->{$field_key} ) ? $the_post->{$field_key} : '';
$fa_icon = 'fas fa-link';

if ( ! empty( $meta ) && is_array( $meta ) ) {
if ( ! empty( $meta['media_url'] ) ) {
$link = $meta['media_url'];
}

if ( ! empty( $meta['mime_type'] ) && strpos( $meta['mime_type'], 'video' ) === 0 ) {
$fa_icon = 'fas fa-video';
}
}

// Check if youtube
$screenshot_base_url = 'https://www.youtube.com/embed/%s';

Expand All @@ -163,7 +178,10 @@
} else if ( $link_screenshot_to == 'url' || $link_screenshot_to == 'url_same' ) {
$field_key = str_replace( "_screenshot", "", $image->type );
$link_icon = $link_screenshot_to == 'url' ? "fas fa-external-link-alt" : 'fas fa-link';
$link = isset( $gd_post->{$field_key} ) ? $gd_post->{$field_key} : '';
$link = isset( $the_post->{$field_key} ) ? $the_post->{$field_key} : '';
if ( ! empty( $meta ) && is_array( $meta ) && ! empty( $meta['media_url'] ) ) {
$link = $meta['media_url'];
}
$link_tag_open_ss = '<a href="%s" class="' . esc_attr( $responsive_image_class ) . '" rel="nofollow noopener noreferrer"' . ( $link_screenshot_to == 'url' ? " target='_blank'" : '' ) . '>';
$link_tag_close_ss = '<i class="' . esc_attr( $link_icon ) . ' w-auto h-auto" aria-hidden="true"></i></a>';
}
Expand Down

0 comments on commit c4ce2c7

Please sign in to comment.