Skip to content

Commit

Permalink
Merge pull request #439 from kprajapatii/master
Browse files Browse the repository at this point in the history
Fix affiliate links for GeoDirectory CPTs listing pages - FIXED
  • Loading branch information
Stiofan authored Sep 14, 2017
2 parents 026a783 + 11eb913 commit 23f747f
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 42 deletions.
7 changes: 7 additions & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v1.6.24
Fix affiliate links for GeoDirectory CPTs listing pages - FIXED
Broken term links on details page if region removed from details links - FIXED
GD login link throwing to 404 page for already logged user - FIXED
Show validation message for empty review/reply text - CHANGED
Listing edited notification should be sent after listing data saved - CHANGED

v1.6.23
"All" string is not translated in popular post widget title - FIXED
Fix post name for autosaved listing from backend - FIXED
Expand Down
14 changes: 12 additions & 2 deletions geodirectory-assets/js/geodirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,15 +526,25 @@ jQuery(document).ready(function() {

if (!geodir_all_js_msg.multirating) {
$frm_obj.find('input[name="submit"]').click(function(e) {
var $comment = jQuery('textarea[name="comment"]', $frm_obj);
jQuery('#err_no_comment', $frm_obj).remove();
$frm_obj.find('#err_no_rating').remove();

var is_review = parseInt($frm_obj.find('#comment_parent').val());
is_review = is_review == 0 ? true : false;

if (jQuery.trim($comment.val()) == '') {
var $err = is_review ? geodir_all_js_msg.err_empty_review : geodir_all_js_msg.err_empty_review;
$comment.before('<div id="err_no_comment" class="err-no-rating">' + $err + '</div>');
$comment.focus();
return false;
}

// skip rating stars validation if rating stars disabled
if (typeof geodir_all_js_msg.gd_cmt_disable_rating != 'undefined' && geodir_all_js_msg.gd_cmt_disable_rating) {
return true;
}
//
var is_review = parseInt($frm_obj.find('#comment_parent').val());
is_review = is_review == 0 ? true : false;

if (is_review) {
var btn_obj = this;
Expand Down
44 changes: 43 additions & 1 deletion geodirectory-assets/js/geodirectory.min.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions geodirectory-functions/custom_taxonomy_hooks_actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,3 +929,32 @@ function geodir_wpseo_taxonomy_meta( $value, $option = '' ) {
return $value;
}
add_filter( 'option_wpseo_taxonomy_meta', 'geodir_wpseo_taxonomy_meta', 10, 2 );

/**
* Fix affiliate links for GeoDirectory CPTs listing pages.
*
* @since 1.6.24
*
*/
function geodir_affiliate_wp_rewrite_fix() {
if ( !class_exists( 'Affiliate_WP' ) ) {
return;
}

$gd_post_types = geodir_get_posttypes( 'array' );

if ( !empty( $gd_post_types ) ) {
$ref = affiliate_wp()->tracking->get_referral_var();
if ( empty( $ref ) ) {
return;
}

foreach ( $gd_post_types as $key => $post_type ) {
if ( !empty( $key ) && !empty( $post_type['rewrite']['slug'] ) ) {
add_rewrite_rule( $post_type['rewrite']['slug'] . '/' . $ref . '(/(.*))?/page/([0-9]{1,})/?$', 'index.php?post_type=' . $key . '&' . $ref . '=$matches[1]&paged=$matches[3]', 'top');
add_rewrite_rule( $post_type['rewrite']['slug'] . '/' . $ref . '(/(.*))?/?$', 'index.php?post_type=' . $key . '&' . $ref . '=$matches[1]', 'top');
}
}
}
}
add_action( 'init', 'geodir_affiliate_wp_rewrite_fix', 99999 );
79 changes: 53 additions & 26 deletions geodirectory-functions/general_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5008,20 +5008,21 @@ function geodir_remove_location_terms( $location_terms = array() ) {
}

/**
* Send notification when a listing has been edited by it's author.
* Cache the listings which are edited by it's author.
*
* @since 1.5.9
* @since 1.6.18 Some times it sends email twice when listing edited - FIXED
* @since 1.6.24 See geodir_send_listing_edited_notification()
* @package GeoDirectory
*
* @global array $gd_notified_edited Array of post ID which has post edited notification set.
* @global array $gd_set_listing_edited Array of post ID which needs to notify admin on post edited.
*
* @param int $post_ID Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing listing being updated or not.
*/
function geodir_on_wp_insert_post( $post_ID, $post, $update ) {
global $gd_notified_edited;
global $gd_set_listing_edited;

if ( ! $update ) {
return;
Expand All @@ -5044,30 +5045,11 @@ function geodir_on_wp_insert_post( $post_ID, $post, $update ) {
if ( $user_id > 0 && get_option( 'geodir_notify_post_edited' ) && ! wp_is_post_revision( $post_ID ) && in_array( $post->post_type, geodir_get_posttypes() ) ) {
$author_id = ! empty( $post->post_author ) ? $post->post_author : 0;

if ( $user_id == $author_id && ! is_super_admin() && empty( $gd_notified_edited[$post_ID] ) ) {
if ( !empty( $gd_notified_edited ) ) {
$gd_notified_edited = array();
if ( $user_id == $author_id && ! is_super_admin() && empty( $gd_set_listing_edited[$post_ID] ) ) {
if ( !empty( $gd_set_listing_edited ) ) {
$gd_set_listing_edited = array();
}
$gd_notified_edited[$post_ID] = true;

$from_email = get_option( 'site_email' );
$from_name = get_site_emailName();
$to_email = get_option( 'admin_email' );
$to_name = get_option( 'name' );
$message_type = 'listing_edited';

$notify_edited = true;
/**
* Send notification when listing edited by author?
*
* @since 1.6.0
*
* @param bool $notify_edited Notify on listing edited by author?
* @param object $post The current post object.
*/
$notify_edited = apply_filters( 'geodir_notify_on_listing_edited', $notify_edited, $post );

geodir_sendEmail( $from_email, $from_name, $to_email, $to_name, '', '', '', $message_type, $post_ID );
$gd_set_listing_edited[$post_ID] = true;
}
}
}
Expand Down Expand Up @@ -5270,3 +5252,48 @@ function geodir_wpml_register_string( $string, $domain = 'geodirectory', $name =
function geodir_wpml_translate_string( $string, $domain = 'geodirectory', $name = '', $language_code = NULL ) {
return apply_filters( 'wpml_translate_single_string', $string, $domain, $name, $language_code );
}

/**
* Send notification when a listing has been edited by it's author.
*
* @since 1.6.24
* @package GeoDirectory
*
* @global array $gd_notified_edited Array of post ID which has post edited notification set.
* @global array $gd_set_listing_edited Array of post ID which needs to notify admin on post edited.
*
* @param int $post_ID Post ID.
* @param array $data Post data.
*/
function geodir_send_listing_edited_notification( $post_ID, $data ) {
global $gd_notified_edited, $gd_set_listing_edited;

if ( !empty( $gd_set_listing_edited[ $post_ID ] ) && empty( $gd_notified_edited[ $post_ID ] ) ) {
if ( !empty( $gd_notified_edited ) ) {
$gd_notified_edited = array();
}
$gd_notified_edited[ $post_ID ] = true;

$from_email = get_option( 'site_email' );
$from_name = get_site_emailName();
$to_email = get_option( 'admin_email' );
$to_name = get_option( 'name' );
$message_type = 'listing_edited';

$notify_edited = true;
/**
* Send notification when listing edited by author?
*
* @since 1.6.0
*
* @param bool $notify_edited Notify on listing edited by author?
* @param object $post The current post object.
*/
$notify_edited = apply_filters( 'geodir_notify_on_listing_edited', $notify_edited, $post_ID );

if ( $notify_edited ) {
geodir_sendEmail( $from_email, $from_name, $to_email, $to_name, '', '', '', $message_type, $post_ID );
}
}
}
add_action( 'geodir_after_save_listing', 'geodir_send_listing_edited_notification', 1000, 2 );
2 changes: 1 addition & 1 deletion geodirectory-functions/reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class="nav-next"><?php next_comments_link(__('Newer Reviews &rarr;', 'geodirecto
$args = apply_filters('geodir_review_form_args', array(
'title_reply' => __('Leave a Review', 'geodirectory'),
'label_submit' => __('Post Review', 'geodirectory'),
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . __('Review text', 'geodirectory') . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . __('Review text', 'geodirectory') . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>',
'must_log_in' => '<p class="must-log-in">' . sprintf(__('You must be <a href="%s">logged in</a> to post a comment.', 'geodirectory'), geodir_login_url()) . '</p>'
));
comment_form($args);
Expand Down
18 changes: 16 additions & 2 deletions geodirectory-functions/signup_function.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,23 @@ function geodir_user_signup()

if (!isset($_REQUEST['redirect_to']) || $_REQUEST['redirect_to'] == '') {
if (is_user_logged_in()) :
$user_ID = isset($user->ID) ? $user->ID : '';
$user_ID = !empty($user->ID) ? $user->ID : get_current_user_id();
$post_types = geodir_get_posttypes();

if ( !empty( $_REQUEST['stype'] ) ) {
$dashboard_post_type = sanitize_text_field($_REQUEST['stype']);
} else {
$user_listings = geodir_user_post_listing_count( $user_ID );
if ( !empty( $user_listings ) && $dashboard_post_types = array_keys( $user_listings ) ) {
$dashboard_post_type = $dashboard_post_types[0];
}
}
if ( !( !empty( $dashboard_post_type ) && in_array( $dashboard_post_type, $post_types ) ) ) {
$dashboard_post_type = $post_types[0];
}

$author_link = get_author_posts_url($user_ID);
$default_author_link = geodir_getlink($author_link, array('geodir_dashbord' => 'true', 'stype' => 'gd_place'), false);
$default_author_link = geodir_getlink($author_link, array('geodir_dashbord' => 'true', 'stype' => $dashboard_post_type), false);

/**
* Filter the author link.
Expand Down
38 changes: 28 additions & 10 deletions geodirectory-functions/taxonomy_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1740,20 +1740,38 @@ function geodir_term_link($termlink, $term, $taxonomy) {

if ($include_location) {
global $post;
$location_terms = array();

$neighbourhood_active = $location_manager && get_option('location_neighbourhoods') ? true : false;

if (geodir_is_page('detail') && isset($post->country_slug)) {
$location_terms = array(
'gd_country' => $post->country_slug,
'gd_region' => $post->region_slug,
'gd_city' => $post->city_slug
);

if ($neighbourhood_active && !empty($location_terms['gd_city']) && $gd_ses_neighbourhood = $gd_session->get('gd_neighbourhood')) {
$location_terms['gd_neighbourhood'] = $gd_ses_neighbourhood;
if (geodir_is_page('detail')) {
if (!isset($post->country_slug) && !empty($post->post_locations)) {
$post_locations = explode(',', $post->post_locations);

if (count($post_locations) == 3) {
$post->city_slug = str_replace('[', '', $post_locations[0]);
$post->city_slug = str_replace(']', '', $post->city_slug);
$post->region_slug = str_replace('[', '', $post_locations[1]);
$post->region_slug = str_replace(']', '', $post->region_slug);
$post->country_slug = str_replace('[', '', $post_locations[2]);
$post->country_slug = str_replace(']', '', $post->country_slug);
}
}
} else {

if (isset($post->country_slug)) {
$location_terms = array(
'gd_country' => $post->country_slug,
'gd_region' => $post->region_slug,
'gd_city' => $post->city_slug
);

if ($neighbourhood_active && !empty($location_terms['gd_city']) && $gd_ses_neighbourhood = $gd_session->get('gd_neighbourhood')) {
$location_terms['gd_neighbourhood'] = $gd_ses_neighbourhood;
}
}
}

if (empty($location_terms)) {
$location_terms = geodir_get_current_location_terms('query_vars');
}

Expand Down
2 changes: 2 additions & 0 deletions geodirectory_hooks_actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,8 @@ function geodir_localize_all_js_msg()
'gd_cmt_btn_post_review' => __('Post Review', 'geodirectory'),
'gd_cmt_btn_review_text' => __('Review text', 'geodirectory'),
'gd_cmt_err_no_rating' => __("Please select star rating, you can't leave a review without stars.", 'geodirectory'),
'err_empty_review' => __('Please type a review.', 'geodirectory'),
'err_empty_reply' => __('Please type a reply.', 'geodirectory'),
/* on/off dragging for phone devices */
'geodir_onoff_dragging' => get_option('geodir_map_onoff_dragging') ? true : false,
'geodir_is_mobile' => wp_is_mobile() ? true : false,
Expand Down

0 comments on commit 23f747f

Please sign in to comment.