Skip to content

Commit

Permalink
Merge pull request #3 from Armanul46/github
Browse files Browse the repository at this point in the history
1/Preview & slider image hide/show options to single listing page.
  • Loading branch information
AazzTech authored Feb 7, 2019
2 parents 1ee94b9 + a8c7d39 commit 801adef
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 15 deletions.
4 changes: 2 additions & 2 deletions directorist-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public function show_related_listing($post)
*/
public function get_related_listings($post)
{
$rel_listing_num = get_directorist_option('rel_listing_num', 2);
$rel_listing_num = get_directorist_option('rel_listing_num', 3);
$atbd_cats = get_the_terms($post, ATBDP_CATEGORY);
$atbd_tags = get_the_terms($post, ATBDP_TAGS);
// get the tag ids of the listing post type
Expand Down Expand Up @@ -733,7 +733,7 @@ public function get_related_listings($post)
'terms' => $atbd_tags_ids,
),
),
'posts_per_page' => -1,
'posts_per_page' => (int)$rel_listing_num,
'post__not_in' => array($post->ID),
);

Expand Down
10 changes: 5 additions & 5 deletions includes/classes/class-metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ public function post_submitbox_meta($post)
{
if(ATBDP_POST_TYPE !=$post->post_type) return; // vail if it is not our post type
// show expiration date and featured listing.
$expire_in_days = get_directorist_option('listing_expire_in_days');
$expire_in_days = get_directorist_option('listing_expire_in_days');
$f_active = get_directorist_option('enable_featured_listing');
$never_expire = get_post_meta($post->ID, '_never_expire', true);
$never_expire = !empty($never_expire) ? (int) $never_expire : (empty($expire_in_days) ? 1 : 0);
$never_expire = !empty($never_expire) ? (int) $never_expire : (empty($expire_in_days) ? 1 : 0);

$e_d = get_post_meta($post->ID, '_expiry_date', true);
$e_d = !empty($e_d) ? $e_d : calc_listing_expiry_date();
$expiry_date = atbdp_parse_mysql_date($e_d);
$e_d = get_post_meta($post->ID, '_expiry_date', true);
$e_d = !empty($e_d) ? $e_d : calc_listing_expiry_date();
$expiry_date = atbdp_parse_mysql_date($e_d);

$featured = get_post_meta($post->ID, '_featured', true);
$listing_status = get_post_meta($post->ID, '_listing_status', true);
Expand Down
18 changes: 17 additions & 1 deletion includes/classes/class-settings-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,22 @@ function get_listings_form_settings_fields() {
),
),

array(
'type' => 'toggle',
'name' => 'dsiplay_prv_single_page',
'label' => __('Show Preview Image', ATBDP_TEXTDOMAIN),
'description' => __('Hide/show preview image from single listing page.', ATBDP_TEXTDOMAIN),
'default' => 1,
),

array(
'type' => 'toggle',
'name' => 'dsiplay_slider_single_page',
'label' => __('Show Slider Image', ATBDP_TEXTDOMAIN),
'description' => __('Hide/show slider image from single listing page.', ATBDP_TEXTDOMAIN),
'default' => 1,
),

array(
'type' => 'toggle',
'name' => 'gallery_cropping',
Expand Down Expand Up @@ -1976,7 +1992,7 @@ function get_listings_form_settings_fields() {
'min' => '1',
'max' => '10',
'step' => '1',
'default' => '2',
'default' => '3',
'validation' => 'numeric|minlength[1]',
),
array(
Expand Down
2 changes: 1 addition & 1 deletion templates/front-end/add-listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ class="form-control directory_field"
<div class="atbdb_content_module_contents">
<!--Image Uploader-->
<div id="_listing_gallery">
<?php ATBDP()->load_template('media-upload', compact('listing_img', 'listing_prv_img')); ?>
<?php ATBDP()->load_template('front-end/front-media-upload', compact('listing_img', 'listing_prv_img')); ?>
</div>
<?php
$plan_video = true;
Expand Down
75 changes: 75 additions & 0 deletions templates/front-end/front-media-upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
$display_prv_image = get_directorist_option('dsiplay_prv_single_page',1);
$display_slider_image = get_directorist_option('dsiplay_slider_single_page',1);
$display_preview_image = get_directorist_option('display_preview_image',1);
$listing_imgs = (!empty($args['listing_img'])) ? $args['listing_img'] : array();
$listing_prv_img_id = (!empty($args['listing_prv_img'])) ? $args['listing_prv_img'] : '';
$listing_prv_img = wp_get_attachment_image_src($listing_prv_img_id);
$image_links = []; // define a link placeholder variable
foreach ($listing_imgs as $id) {
$image_links[$id] = wp_get_attachment_image_src($id)[0]; // store the attachment id and url
}
// is multiple image upload extension is active ?
$active_mi_ext = is_multiple_images_active(); // default is no
?>
<?php if( !empty($display_prv_image) || !empty($display_preview_image) || !empty($display_slider_image)) {?>
<div class="add_listing_form_wrapper" id="gallery_upload">
<?php if( !empty($display_prv_image) || !empty($display_preview_image)) {?>
<div class="form-group">
<!-- image container, which can be manipulated with js -->
<div class="listing-prv-img-container">
<div class="single_prv_attachment">
<input class="listing_prv_img" name="listing_prv_img" type="hidden"
value="<?php echo $listing_prv_img_id; ?>">
<img style="max-height: 150px;max-width: 150px" class="change_listing_prv_img"
src="<?php echo esc_url($listing_prv_img[0]) ?>">
</div>
<div class="default_img">
</div>
</div>
<!-- add & remove image links -->
<p class="hide-if-no-js">
<a href="#" class="upload-header btn btn-secondary">Upload Preview Image</a>
</p>
</div>
<?php } ?>
<?php if( !empty($display_slider_image) ) {?>
<div class="form-group">
<!-- image container, which can be manipulated with js -->
<div class="listing-img-container">
<?php if (!empty($image_links)) {
foreach ($image_links as $id => $image_link) { ?>
<div class="single_attachment">
<input class="listing_image_attachment" name="listing_img[]" type="hidden"
value="<?= intval($id); ?>">
<img style="width: 100%; height: 100%;"
src="<?= esc_url($image_link) ?>"
alt="<?php esc_attr_e('Listing Image', ATBDP_TEXTDOMAIN); ?>">
<span class="remove_image dashicons dashicons-dismiss"
title="<?= __('Remove it', ATBDP_TEXTDOMAIN); ?>"></span>
</div>
<?php } // ends foreach for looping image
} else { ?>
<img src="<?= esc_url(ATBDP_ADMIN_ASSETS . 'images/no-image.png'); ?>"
alt="<?php esc_attr_e('No Image Found', ATBDP_TEXTDOMAIN); ?>">
<p>No Images</p>
<?php } // ends if statement ?>
</div>
<?php
/* A hidden input to set and post the chosen image id
<input id="listing_image_id" name="listing[listing_img]" type="hidden" value="">*/
?>
<!-- add & remove image links -->
<p class="hide-if-no-js">
<a href="#" id="listing_image_btn" class="btn btn-primary">
<span class="dashicons dashicons-format-image"></span>
<?php _e('Upload Slider Images', ATBDP_TEXTDOMAIN); ?>
</a>
<a id="delete-custom-img" class="btn btn-danger <?= (!empty($image_links)) ? '' : 'hidden' ?>"
href="#"> <?php echo (1 == $active_mi_ext) ? esc_html__('Remove Images') : esc_html__('Remove Image'); ?></a>
</p>
</div>
<?php } ?>
</div> <!--ends add_listing_form_wrapper-->
<?php } ?>

13 changes: 7 additions & 6 deletions templates/single-at_biz_dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
$listing_info['listing_prv_img'] = get_post_meta($post->ID, '_listing_prv_img', true);
$listing_info['hide_contact_info'] = get_post_meta($post->ID, '_hide_contact_info', true);
$listing_info['expiry_date'] = get_post_meta($post->ID, '_expiry_date', true);
$display_prv_image = get_directorist_option('dsiplay_prv_single_page',1);
$display_slider_image = get_directorist_option('dsiplay_slider_single_page',1);
$gallery_cropping = get_directorist_option('gallery_cropping',1);
$custom_gl_width = get_directorist_option('gallery_crop_width', 670);
$custom_gl_height = get_directorist_option('gallery_crop_height', 750);
$disable_contact_info = get_directorist_option('disable_contact_info');
$disable_contact_info = get_directorist_option('disable_contact_info');
extract($listing_info);
/*Prepare Listing Image links*/
$listing_imgs= (!empty($listing_img)) ? $listing_img : array();
$listing_imgs= (!empty($listing_img) && !empty($display_slider_image)) ? $listing_img : array();
$image_links = array(); // define a link placeholder variable
foreach ($listing_imgs as $id){

Expand Down Expand Up @@ -217,7 +219,7 @@ class="btn btn-primary"><?php _e('Submit', ATBDP_TEXTDOMAIN); ?></button>
<?php
$listing_prv_imgurl = wp_get_attachment_image_src($listing_prv_img, 'large')[0];
if (!empty($image_links)) {
if (!empty($listing_prv_img)){
if (!empty($listing_prv_img) && !empty($display_prv_image)){
if(!empty($gallery_cropping)) {
$listing_prv_imgurl = atbdp_image_cropping($listing_prv_img, $custom_gl_width, $custom_gl_height, true, 100)['url'];
} else {
Expand Down Expand Up @@ -249,22 +251,21 @@ class="btn btn-primary"><?php _e('Submit', ATBDP_TEXTDOMAIN); ?></button>
<div class="atbd_directory_image_thumbnail">
<?php
$listing_prv_imgurl_thumb = wp_get_attachment_image_src($listing_prv_img, 'thumbnail')['0'];
if (!empty($listing_prv_imgurl_thumb)){
if (!empty($listing_prv_imgurl_thumb && !empty($display_prv_image))){
array_unshift($image_links_thumbnails, $listing_prv_imgurl_thumb);
}
foreach ($image_links_thumbnails as $image_links_thumbnail) { ?>
<div class="single_thumbnail">
<img src="<?= esc_url($image_links_thumbnail); ?>"
alt="<?php esc_attr_e('Details Image', ATBDP_TEXTDOMAIN); ?>">
</div>

<?php
// do not output more than one image if the MI extension is not active
if (!is_multiple_images_active()) break;
} ?>
</div><!-- end /.atbd_directory_image_wrapper -->
</div>
<?php }else{
<?php }elseif(!empty($display_prv_image)){
?>
<div class="single_image">
<img src="<?= !empty($listing_prv_img) ? esc_url($listing_prv_imgurl) : ATBDP_PUBLIC_ASSETS . 'images/grid.jpg'; ?>"
Expand Down

0 comments on commit 801adef

Please sign in to comment.