| 1 |
<?php |
| 2 |
/** |
| 3 |
* GeoDirectory plugin related functions |
| 4 |
* |
| 5 |
* This class defines all code necessary for GeoDirectory plugin. |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @author GeoDirectory Team <info@wpgeodirectory.com> |
| 9 |
*/ |
| 10 |
class UsersWP_GeoDirectory_Plugin { |
| 11 |
private static $instance; |
| 12 |
|
| 13 |
public static function get_instance() { |
| 14 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof UsersWP_GeoDirectory_Plugin ) ) { |
| 15 |
self::$instance = new UsersWP_GeoDirectory_Plugin; |
| 16 |
self::$instance->setup_globals(); |
| 17 |
self::$instance->includes(); |
| 18 |
self::$instance->setup_actions(); |
| 19 |
} |
| 20 |
|
| 21 |
return self::$instance; |
| 22 |
} |
| 23 |
|
| 24 |
private function __construct() { |
| 25 |
self::$instance = $this; |
| 26 |
} |
| 27 |
|
| 28 |
private function setup_globals() { |
| 29 |
|
| 30 |
} |
| 31 |
|
| 32 |
private function setup_actions() { |
| 33 |
if ( is_admin() ) { |
| 34 |
add_filter( 'uwp_display_form_title', array( $this, 'display_form_title' ), 10, 3 ); |
| 35 |
add_action( 'uwp_geodirectory_settings_main_tab_content', array( $this, 'main_tab_content' ), 10, 1 ); |
| 36 |
add_action( 'uwp_admin_sub_menus', array( $this, 'add_admin_gd_sub_menu' ), 10, 1 ); |
| 37 |
add_filter( 'uwp_settings_tabs', array( $this, 'add_gd_tab' ) ); |
| 38 |
add_filter( 'uwp_registered_settings', array( $this, 'add_gd_settings' ) ); |
| 39 |
add_filter( 'uwp_available_tab_items', array( $this, 'available_tab_items' ) ); |
| 40 |
} else { |
| 41 |
add_filter( 'uwp_profile_tabs', array( $this, 'add_profile_gd_tabs' ), 10, 3 ); |
| 42 |
add_action( 'uwp_profile_listings_tab_content', array( $this, 'add_profile_listings_tab_content' ) ); |
| 43 |
add_action( 'uwp_profile_reviews_tab_content', array( $this, 'add_profile_reviews_tab_content' ) ); |
| 44 |
add_action( 'uwp_profile_favorites_tab_content', array( $this, 'add_profile_favorites_tab_content' ) ); |
| 45 |
add_action( 'uwp_profile_gd_listings_subtab_content', array( $this, 'gd_get_listings' ), 10, 2 ); |
| 46 |
add_action( 'uwp_profile_gd_reviews_subtab_content', array( $this, 'gd_get_reviews' ), 10, 2 ); |
| 47 |
add_action( 'uwp_profile_gd_favorites_subtab_content', array( $this, 'gd_get_favorites' ), 10, 2 ); |
| 48 |
add_action( 'geodir_after_edit_post_link_on_listing', array( $this, 'geodir_add_post_status_author_page' ), 11 ); |
| 49 |
} |
| 50 |
add_filter( 'geodir_login_url', array( $this, 'get_gd_login_url' ), 10, 2 ); |
| 51 |
add_action( 'wp', array( $this, 'geodir_uwp_author_redirect' ) ); |
| 52 |
add_filter( 'geodir_post_status_is_author_page', array( $this, 'geodir_post_status_is_author_page' ) ); |
| 53 |
add_filter( 'gd_login_wid_login_placeholder', array( $this, 'gd_login_wid_login_placeholder' ) ); |
| 54 |
add_filter( 'gd_login_wid_login_name', array( $this, 'gd_login_wid_login_name' ) ); |
| 55 |
add_filter( 'gd_login_wid_login_pwd', array( $this, 'gd_login_wid_login_pwd' ) ); |
| 56 |
add_action( 'login_form', array( $this, 'gd_login_inject_nonce' ) ); |
| 57 |
add_filter( 'uwp_check_redirect_author_page', array( $this, 'check_redirect_author_page' ), 10, 1 ); |
| 58 |
add_filter( 'uwp_use_author_page_content', array( $this, 'skip_uwp_author_page' ), 10, 1 ); |
| 59 |
|
| 60 |
do_action( 'uwp_gd_setup_actions', $this ); |
| 61 |
} |
| 62 |
|
| 63 |
private function includes() { |
| 64 |
do_action( 'uwp_gd_include_files' ); |
| 65 |
|
| 66 |
if ( is_admin() ) { |
| 67 |
do_action( 'uwp_gd_include_admin_files' ); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Modifies the settings form title. |
| 73 |
* |
| 74 |
* @since 1.0.0 |
| 75 |
* @package userswp |
| 76 |
* |
| 77 |
* @param string $title Original title. |
| 78 |
* @param string $page admin.php?page=uwp_xxx. |
| 79 |
* @param string $active_tab active tab in that settings page. |
| 80 |
* |
| 81 |
* @return string Form title. |
| 82 |
*/ |
| 83 |
public function display_form_title( $title, $page, $active_tab ) { |
| 84 |
if ( $page == 'uwp_geodirectory' && $active_tab == 'main' ) { |
| 85 |
$title = __( 'GeoDirectory Settings', 'userswp' ); |
| 86 |
} |
| 87 |
return $title; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Prints the settings form. |
| 92 |
* |
| 93 |
* @since 1.0.0 |
| 94 |
* @package userswp |
| 95 |
* |
| 96 |
* @param string $form Setting form html. |
| 97 |
* |
| 98 |
* @return void |
| 99 |
*/ |
| 100 |
public function main_tab_content( $form ) { |
| 101 |
echo $form; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Adds the current userswp addon settings page menu as submenu. |
| 106 |
* |
| 107 |
* @since 1.0.0 |
| 108 |
* @package userswp |
| 109 |
* |
| 110 |
* @param callable $settings_page The function to be called to output the content for this page. |
| 111 |
* |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
public function add_admin_gd_sub_menu( $settings_page ) { |
| 115 |
add_submenu_page( |
| 116 |
"userswp", |
| 117 |
__( 'GeoDirectory', 'userswp' ), |
| 118 |
__( 'GeoDirectory', 'userswp' ), |
| 119 |
'manage_options', |
| 120 |
'uwp_geodirectory', |
| 121 |
$settings_page |
| 122 |
); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Adds settings tabs for the current userswp addon. |
| 127 |
* |
| 128 |
* @since 1.0.0 |
| 129 |
* @package userswp |
| 130 |
* |
| 131 |
* @param array $tabs Existing tabs array. |
| 132 |
* |
| 133 |
* @return array Tabs array. |
| 134 |
*/ |
| 135 |
public function add_gd_tab( $tabs ) { |
| 136 |
$tabs['uwp_geodirectory'] = array( |
| 137 |
'main' => __( 'GeoDirectory', 'userswp' ), |
| 138 |
); |
| 139 |
return $tabs; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Registers form fields for the current userswp addon settings page. |
| 144 |
* |
| 145 |
* @since 1.0.0 |
| 146 |
* @package userswp |
| 147 |
* |
| 148 |
* @param array $uwp_settings Existing settings array. |
| 149 |
* |
| 150 |
* @return array Settings array. |
| 151 |
*/ |
| 152 |
public function add_gd_settings( $uwp_settings ) { |
| 153 |
$gd_posttypes = $this->get_gd_posttypes(); |
| 154 |
|
| 155 |
$options = array( |
| 156 |
'gd_settings_info' => array( |
| 157 |
'id' => 'woo_settings_info', |
| 158 |
'name' => __( 'Info', 'userswp' ), |
| 159 |
'desc' => __( 'You can now add Listings, Reviews and Favorites tabs under UsersWP > Profile > Choose the tabs to display in Profile', 'userswp' ), |
| 160 |
'type' => 'info', |
| 161 |
'std' => '1', |
| 162 |
'class' => 'uwp_label_inline', |
| 163 |
), |
| 164 |
'gd_profile_listings' => array( |
| 165 |
'id' => 'gd_profile_listings', |
| 166 |
'name' => __( 'CPT listings in Profile', 'userswp' ), |
| 167 |
'desc' => __( 'Choose the post types to show listings tab in UsersWP Profile', 'userswp' ), |
| 168 |
'multiple' => true, |
| 169 |
'chosen' => true, |
| 170 |
'type' => 'select', |
| 171 |
'options' => $gd_posttypes, |
| 172 |
'placeholder' => __( 'Select Post Types', 'userswp' ) |
| 173 |
), |
| 174 |
'gd_profile_reviews' => array( |
| 175 |
'id' => 'gd_profile_reviews', |
| 176 |
'name' => __( 'CPT reviews in Profile', 'userswp' ), |
| 177 |
'desc' => __( 'Choose the post types to show reviews tab in UsersWP Profile', 'userswp' ), |
| 178 |
'multiple' => true, |
| 179 |
'chosen' => true, |
| 180 |
'type' => 'select', |
| 181 |
'options' => $gd_posttypes, |
| 182 |
'placeholder' => __( 'Select Post Types', 'userswp' ) |
| 183 |
), |
| 184 |
'gd_profile_favorites' => array( |
| 185 |
'id' => 'gd_profile_favorites', |
| 186 |
'name' => __( 'CPT favorites in Profile', 'userswp' ), |
| 187 |
'desc' => __( 'Choose the post types to show favorites tab in UsersWP Profile', 'userswp' ), |
| 188 |
'multiple' => true, |
| 189 |
'chosen' => true, |
| 190 |
'type' => 'select', |
| 191 |
'options' => $gd_posttypes, |
| 192 |
'placeholder' => __( 'Select Post Types', 'userswp' ) |
| 193 |
), |
| 194 |
'geodir_uwp_link_listing' => array( |
| 195 |
'id' => 'geodir_uwp_link_listing', |
| 196 |
'name' => __( 'Redirect my listing link from GD loginbox to UsersWP profile', 'userswp' ), |
| 197 |
'desc' => __( 'If this option is selected, the my listing link from GD loginbox will redirect to listings tab of UsersWP profile.', 'userswp' ), |
| 198 |
'type' => 'checkbox', |
| 199 |
'std' => '0', |
| 200 |
'class' => 'uwp_label_inline', |
| 201 |
), |
| 202 |
'geodir_uwp_link_favorite' => array( |
| 203 |
'id' => 'geodir_uwp_link_favorite', |
| 204 |
'name' => __( 'Redirect favorite link from GD loginbox to UsersWP profile', 'userswp' ), |
| 205 |
'desc' => __( 'If this option is selected, the favorite link from GD loginbox will redirect to favorites tab of UsersWP profile.', 'userswp' ), |
| 206 |
'type' => 'checkbox', |
| 207 |
'std' => '0', |
| 208 |
'class' => 'uwp_label_inline', |
| 209 |
), |
| 210 |
); |
| 211 |
|
| 212 |
$uwp_settings['uwp_geodirectory'] = array( |
| 213 |
'main' => apply_filters( 'uwp_settings_geodirectory', $options ), |
| 214 |
); |
| 215 |
|
| 216 |
return $uwp_settings; |
| 217 |
} |
| 218 |
|
| 219 |
public function get_gd_posttypes() { |
| 220 |
$post_type_arr = array(); |
| 221 |
$post_types = geodir_get_posttypes( 'object' ); |
| 222 |
|
| 223 |
foreach ( $post_types as $key => $post_types_obj ) { |
| 224 |
$post_type_arr[$key] = $post_types_obj->labels->singular_name; |
| 225 |
} |
| 226 |
return $post_type_arr; |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Registers the current addon tab items in "Choose the tabs to display in UsersWP Profile" setting. |
| 231 |
* |
| 232 |
* @since 1.0.0 |
| 233 |
* @package userswp |
| 234 |
* |
| 235 |
* @param array $tabs_arr Existing tabs array. |
| 236 |
* |
| 237 |
* @return array Tabs array. |
| 238 |
*/ |
| 239 |
public function available_tab_items( $tabs_arr ) { |
| 240 |
$tabs_arr['listings'] = __( 'Listings', 'userswp' ); |
| 241 |
$tabs_arr['reviews'] = __( 'Reviews', 'userswp' ); |
| 242 |
$tabs_arr['favorites'] = __( 'Favorites', 'userswp' ); |
| 243 |
|
| 244 |
return $tabs_arr; |
| 245 |
} |
| 246 |
|
| 247 |
public function geodir_get_reviews_by_user_id($post_type = 'gd_place', $user_id, $count_only = false, $offset = 0, $limit = 20) { |
| 248 |
global $wpdb; |
| 249 |
|
| 250 |
if ($count_only) { |
| 251 |
if($this->uwp_is_gdv2()) { |
| 252 |
$results = $wpdb->get_var( |
| 253 |
$wpdb->prepare( |
| 254 |
"SELECT COUNT(reviews.rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.rating > 0 AND posts.post_status = 'publish'", |
| 255 |
array($user_id, $post_type) |
| 256 |
) |
| 257 |
); |
| 258 |
} else { |
| 259 |
$results = $wpdb->get_var( |
| 260 |
$wpdb->prepare( |
| 261 |
"SELECT COUNT(reviews.overall_rating) FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish'", |
| 262 |
array($user_id, $post_type) |
| 263 |
) |
| 264 |
); |
| 265 |
} |
| 266 |
} else { |
| 267 |
if($this->uwp_is_gdv2()) { |
| 268 |
$results = $wpdb->get_results( |
| 269 |
$wpdb->prepare( |
| 270 |
"SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d", |
| 271 |
array($user_id, $post_type, $limit, $offset ) |
| 272 |
) |
| 273 |
); |
| 274 |
} else { |
| 275 |
$results = $wpdb->get_results( |
| 276 |
$wpdb->prepare( |
| 277 |
"SELECT reviews.* FROM " . GEODIR_REVIEW_TABLE . " reviews JOIN " . $wpdb->posts . " posts ON reviews.post_id = posts.id WHERE reviews.user_id = %d AND reviews.post_type = %s AND reviews.status=1 AND reviews.overall_rating>0 AND posts.post_status = 'publish' LIMIT %d OFFSET %d", |
| 278 |
array($user_id, $post_type, $limit, $offset ) |
| 279 |
) |
| 280 |
); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
if (!empty($results)) |
| 285 |
return $results; |
| 286 |
else |
| 287 |
return false; |
| 288 |
} |
| 289 |
|
| 290 |
public function geodir_count_favorite( $post_type, $user_id = 0 ) { |
| 291 |
global $wpdb; |
| 292 |
|
| 293 |
$post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : ''; |
| 294 |
if ( $user_id && $user_id == get_current_user_id() ) { |
| 295 |
$post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'gd-closed' OR " . $wpdb->posts . ".post_status = 'gd-expired'"; |
| 296 |
} |
| 297 |
|
| 298 |
$user_fav_posts = geodir_get_user_favourites( (int)$user_id ); |
| 299 |
$user_fav_posts = !empty( $user_fav_posts ) ? implode( "','", $user_fav_posts ) : "-1"; |
| 300 |
|
| 301 |
$count = (int)$wpdb->get_var( "SELECT count( ID ) FROM ".$wpdb->posts." WHERE " . $wpdb->posts . ".ID IN ('" . $user_fav_posts . "') AND post_type='" . $post_type . "' AND ( post_status = 'publish' " . $post_status . " )" ); |
| 302 |
|
| 303 |
return apply_filters( 'uwp_geodir_count_favorite', $count, $user_id ); |
| 304 |
} |
| 305 |
|
| 306 |
public function get_listings_count($post_type, $user_id = 0) { |
| 307 |
global $wpdb; |
| 308 |
if (empty($user_id)) { |
| 309 |
return 0; |
| 310 |
} |
| 311 |
|
| 312 |
$post_status = is_super_admin() ? " OR " . $wpdb->posts . ".post_status = 'private'" : ''; |
| 313 |
if ($user_id && $user_id == get_current_user_id()) { |
| 314 |
$post_status .= " OR " . $wpdb->posts . ".post_status = 'draft' OR " . $wpdb->posts . ".post_status = 'private' OR " . $wpdb->posts . ".post_status = 'pending' OR " . $wpdb->posts . ".post_status = 'gd-closed' OR " . $wpdb->posts . ".post_status = 'gd-expired'"; |
| 315 |
} |
| 316 |
|
| 317 |
$count = (int)$wpdb->get_var("SELECT count( ID ) FROM " . $wpdb->prefix . "posts WHERE post_author=" . (int)$user_id . " AND post_type='" . $post_type . "' AND ( post_status = 'publish' " . $post_status . " )"); |
| 318 |
|
| 319 |
return apply_filters('geodir_uwp_count_total', $count, $user_id); |
| 320 |
} |
| 321 |
|
| 322 |
public function get_total_listings_count($user_id = 0) { |
| 323 |
if (empty($user_id)) { |
| 324 |
return 0; |
| 325 |
} |
| 326 |
|
| 327 |
$gd_post_types = geodir_get_posttypes('array'); |
| 328 |
|
| 329 |
if (empty($gd_post_types)) { |
| 330 |
return 0; |
| 331 |
} |
| 332 |
|
| 333 |
|
| 334 |
// allowed post types |
| 335 |
$listing_post_types = uwp_get_option('gd_profile_listings', array()); |
| 336 |
|
| 337 |
if (!is_array($listing_post_types)) { |
| 338 |
$listing_post_types = array(); |
| 339 |
} |
| 340 |
|
| 341 |
$count = 0; |
| 342 |
$total_count = 0; |
| 343 |
foreach ($listing_post_types as $post_type) { |
| 344 |
if (array_key_exists($post_type, $gd_post_types)) { |
| 345 |
|
| 346 |
// get listing count |
| 347 |
$listing_count = $this->get_listings_count($post_type, $user_id); |
| 348 |
$total_count += $listing_count; |
| 349 |
|
| 350 |
$count++; |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
return $total_count; |
| 355 |
} |
| 356 |
|
| 357 |
public function get_total_reviews_count($user_id = 0) { |
| 358 |
if (empty($user_id)) { |
| 359 |
return 0; |
| 360 |
} |
| 361 |
|
| 362 |
$gd_post_types = geodir_get_posttypes('array'); |
| 363 |
|
| 364 |
if (empty($gd_post_types)) { |
| 365 |
return 0; |
| 366 |
} |
| 367 |
|
| 368 |
// allowed post types |
| 369 |
$listing_post_types = uwp_get_option('gd_profile_reviews', array()); |
| 370 |
|
| 371 |
if (!is_array($listing_post_types)) { |
| 372 |
$listing_post_types = array(); |
| 373 |
} |
| 374 |
|
| 375 |
$count = 0; |
| 376 |
$total_count = 0; |
| 377 |
foreach ($listing_post_types as $post_type) { |
| 378 |
if (array_key_exists($post_type, $gd_post_types)) { |
| 379 |
|
| 380 |
// get listing count |
| 381 |
$listing_count = $this->geodir_get_reviews_by_user_id($post_type, $user_id, true); |
| 382 |
$total_count += $listing_count; |
| 383 |
|
| 384 |
$count++; |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
return $total_count; |
| 389 |
} |
| 390 |
|
| 391 |
public function get_total_favorites_count($user_id = 0) { |
| 392 |
if (empty($user_id)) { |
| 393 |
return 0; |
| 394 |
} |
| 395 |
|
| 396 |
$gd_post_types = geodir_get_posttypes('array'); |
| 397 |
|
| 398 |
if (empty($gd_post_types)) { |
| 399 |
return 0; |
| 400 |
} |
| 401 |
|
| 402 |
// allowed post types |
| 403 |
$listing_post_types = uwp_get_option('gd_profile_favorites', array()); |
| 404 |
|
| 405 |
if (!is_array($listing_post_types)) { |
| 406 |
$listing_post_types = array(); |
| 407 |
} |
| 408 |
|
| 409 |
$count = 0; |
| 410 |
$total_count = 0; |
| 411 |
foreach ($listing_post_types as $post_type) { |
| 412 |
if (array_key_exists($post_type, $gd_post_types)) { |
| 413 |
|
| 414 |
// get listing count |
| 415 |
$listing_count = $this->geodir_count_favorite($post_type, $user_id); |
| 416 |
$total_count += $listing_count; |
| 417 |
|
| 418 |
$count++; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
return $total_count; |
| 423 |
} |
| 424 |
|
| 425 |
/** |
| 426 |
* Adds tab in user profile page. |
| 427 |
* |
| 428 |
* @since 1.0.0 |
| 429 |
* @package userswp |
| 430 |
* |
| 431 |
* @param array $tabs Existing tabs array. |
| 432 |
* @param object $user User object. |
| 433 |
* @param array $allowed_tabs Allowed tabs array. |
| 434 |
* |
| 435 |
* @return array Tabs array. |
| 436 |
*/ |
| 437 |
function add_profile_gd_tabs($tabs, $user,$allowed_tabs) { |
| 438 |
// allowed post types |
| 439 |
$listing_post_types = uwp_get_option('gd_profile_listings', array()); |
| 440 |
$l_counts = $this->get_total_listings_count($user->ID); |
| 441 |
if (!empty($listing_post_types) && in_array('listings', $allowed_tabs) && $l_counts > 0) { |
| 442 |
$tabs['listings'] = array( |
| 443 |
'title' => __('Listings', 'userswp'), |
| 444 |
'count' => $l_counts |
| 445 |
); |
| 446 |
} |
| 447 |
|
| 448 |
$listing_post_types = uwp_get_option('gd_profile_reviews', array()); |
| 449 |
$r_counts = $this->get_total_reviews_count($user->ID); |
| 450 |
if (!empty($listing_post_types) && in_array('reviews', $allowed_tabs) && $r_counts > 0) { |
| 451 |
$tabs['reviews'] = array( |
| 452 |
'title' => __('Reviews', 'userswp'), |
| 453 |
'count' => $r_counts |
| 454 |
); |
| 455 |
} |
| 456 |
|
| 457 |
$listing_post_types = uwp_get_option('gd_profile_favorites', array()); |
| 458 |
$f_counts = $this->get_total_favorites_count($user->ID); |
| 459 |
if (!empty($listing_post_types) && in_array('favorites', $allowed_tabs) && (get_current_user_id() == $user->ID) && $f_counts > 0) { |
| 460 |
$tabs['favorites'] = array( |
| 461 |
'title' => __('Favorites', 'userswp'), |
| 462 |
'count' => $f_counts |
| 463 |
); |
| 464 |
} |
| 465 |
|
| 466 |
return $tabs; |
| 467 |
} |
| 468 |
|
| 469 |
/** |
| 470 |
* Adds GD listings tab content. |
| 471 |
* |
| 472 |
* @since 1.0.0 |
| 473 |
* @package userswp |
| 474 |
* |
| 475 |
* @param object $user User object. |
| 476 |
* |
| 477 |
* @return void |
| 478 |
*/ |
| 479 |
public function add_profile_listings_tab_content($user) { |
| 480 |
$this->profile_gd_subtabs_content($user, 'listings'); |
| 481 |
} |
| 482 |
|
| 483 |
/** |
| 484 |
* Adds GD reviews tab content. |
| 485 |
* |
| 486 |
* @since 1.0.0 |
| 487 |
* @package userswp |
| 488 |
* |
| 489 |
* @param object $user User object. |
| 490 |
* |
| 491 |
* @return void |
| 492 |
*/ |
| 493 |
public function add_profile_reviews_tab_content($user) { |
| 494 |
$this->profile_gd_subtabs_content($user, 'reviews'); |
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* Adds GD Favorites tab content. |
| 499 |
* |
| 500 |
* @since 1.0.0 |
| 501 |
* @package userswp |
| 502 |
* |
| 503 |
* @param object $user User object. |
| 504 |
* |
| 505 |
* @return void |
| 506 |
*/ |
| 507 |
public function add_profile_favorites_tab_content($user) { |
| 508 |
$this->profile_gd_subtabs_content($user, 'favorites'); |
| 509 |
} |
| 510 |
|
| 511 |
public function profile_gd_subtabs($user, $type = 'listings') { |
| 512 |
$tabs = array(); |
| 513 |
|
| 514 |
$gd_post_types = geodir_get_posttypes('array'); |
| 515 |
|
| 516 |
if (empty($gd_post_types)) { |
| 517 |
return $tabs; |
| 518 |
} |
| 519 |
|
| 520 |
// allowed post types |
| 521 |
if ($type == 'listings') { |
| 522 |
$listing_post_types = uwp_get_option('gd_profile_listings', array()); |
| 523 |
} elseif ($type == 'reviews') { |
| 524 |
$listing_post_types = uwp_get_option('gd_profile_reviews', array()); |
| 525 |
} elseif ($type == 'favorites') { |
| 526 |
$listing_post_types = uwp_get_option('gd_profile_favorites', array()); |
| 527 |
} else { |
| 528 |
$listing_post_types = array(); |
| 529 |
} |
| 530 |
|
| 531 |
if (!is_array($listing_post_types)) { |
| 532 |
$listing_post_types = array(); |
| 533 |
} |
| 534 |
|
| 535 |
foreach ($gd_post_types as $post_type_id => $post_type) { |
| 536 |
if (in_array($post_type_id, $listing_post_types)) { |
| 537 |
$post_type_slug = $gd_post_types[$post_type_id]['has_archive']; |
| 538 |
|
| 539 |
if($this->uwp_is_gdv2()) { |
| 540 |
if ($type == 'favorites' && geodir_cpt_has_favourite_disabled($post_type_id)) { |
| 541 |
continue; |
| 542 |
} elseif ($type == 'reviews' && geodir_cpt_has_rating_disabled($post_type_id)) { |
| 543 |
continue; |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
if ($type == 'listings') { |
| 548 |
$all_count = geodir_user_post_listing_count($user->ID, true); |
| 549 |
$count = $all_count[$post_type_id]; |
| 550 |
} elseif ($type == 'reviews') { |
| 551 |
$count = $this->geodir_get_reviews_by_user_id($post_type_id, $user->ID, true); |
| 552 |
} elseif ($type == 'favorites') { |
| 553 |
$count = $this->geodir_count_favorite($post_type_id, $user->ID); |
| 554 |
} else { |
| 555 |
$count = 0; |
| 556 |
} |
| 557 |
|
| 558 |
if (empty($count)) { |
| 559 |
$count = 0; |
| 560 |
} |
| 561 |
$tabs[$post_type_slug] = array( |
| 562 |
'title' => $gd_post_types[$post_type_id]['labels']['name'], |
| 563 |
'count' => $count, |
| 564 |
'ptype' => $post_type_id |
| 565 |
); |
| 566 |
} |
| 567 |
} |
| 568 |
|
| 569 |
return apply_filters('uwp_profile_gd_tabs', $tabs, $user, $type); |
| 570 |
} |
| 571 |
|
| 572 |
public function profile_gd_subtabs_content($user, $type = 'listings') { |
| 573 |
$subtab = get_query_var('uwp_subtab'); |
| 574 |
$subtabs = $this->profile_gd_subtabs($user, $type); |
| 575 |
$default_tab = apply_filters('uwp_default_listing_subtab', 'places', $user, $type); |
| 576 |
$active_tab = !empty($subtab) && array_key_exists($subtab, $subtabs) ? $subtab : $default_tab; |
| 577 |
if (!empty($subtabs)) { |
| 578 |
$subtab_keys = array_keys($subtabs); |
| 579 |
$post_type = $subtabs[$subtab_keys[0]]['ptype']; |
| 580 |
} else { |
| 581 |
$post_type = false; |
| 582 |
} |
| 583 |
?> |
| 584 |
<div class="uwp-profile-subcontent"> |
| 585 |
<div class="uwp-profile-subnav"> |
| 586 |
<?php if ($subtabs) { ?> |
| 587 |
<ul class="item-list-subtabs-ul"> |
| 588 |
<?php |
| 589 |
foreach ($this->profile_gd_subtabs($user, $type) as $tab_id => $tab) { |
| 590 |
|
| 591 |
$tab_url = uwp_build_profile_tab_url($user->ID, $type, $tab_id); |
| 592 |
|
| 593 |
$active = $active_tab == $tab_id ? ' active' : ''; |
| 594 |
$post_type = $active_tab == $tab_id ? $tab['ptype'] : $post_type; |
| 595 |
?> |
| 596 |
<li id="uwp-profile-gd-<?php echo $tab_id; ?>" class="<?php echo $active; ?>"> |
| 597 |
<a href="<?php echo esc_url($tab_url); ?>"> |
| 598 |
<span class="uwp-profile-tab-label uwp-profile-gd-<?php echo $tab_id; ?>-label "><span |
| 599 |
class="uwp-profile-tab-sub-ul-count uwp-profile-sub-ul-gd-<?php echo $tab_id; ?>-count"><?php echo $tab['count']; ?></span> <?php echo esc_html($tab['title']); ?></span> |
| 600 |
</a> |
| 601 |
</li> |
| 602 |
<?php |
| 603 |
} |
| 604 |
?> |
| 605 |
</ul> |
| 606 |
<?php } ?> |
| 607 |
</div> |
| 608 |
|
| 609 |
<div class="uwp-profile-subtab-entries"> |
| 610 |
<?php |
| 611 |
do_action('uwp_profile_gd_' . $type . '_subtab_content', $user, $post_type); |
| 612 |
?> |
| 613 |
</div> |
| 614 |
</div> |
| 615 |
<?php |
| 616 |
} |
| 617 |
|
| 618 |
function gd_get_listings($user, $post_type) { |
| 619 |
$gd_post_types = geodir_get_posttypes('array'); |
| 620 |
?> |
| 621 |
<h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3> |
| 622 |
|
| 623 |
<div class="uwp-profile-item-block"> |
| 624 |
<?php |
| 625 |
|
| 626 |
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1; |
| 627 |
|
| 628 |
$args = array( |
| 629 |
'post_type' => $post_type, |
| 630 |
'post_status' => array('publish'), |
| 631 |
'posts_per_page' => uwp_get_option('profile_no_of_items', 10), |
| 632 |
'author' => $user->ID, |
| 633 |
'paged' => $paged, |
| 634 |
); |
| 635 |
|
| 636 |
if (get_current_user_id() == $user->ID) { |
| 637 |
$args['post_status'] = array('publish', 'draft', 'private', 'pending', 'gd-closed', 'gd-expired'); |
| 638 |
} |
| 639 |
// The Query |
| 640 |
$the_query = new WP_Query($args); |
| 641 |
|
| 642 |
do_action('uwp_before_profile_listing_items', $user, $post_type); |
| 643 |
// The Loop |
| 644 |
if ($the_query->have_posts()) { |
| 645 |
echo '<ul class="uwp-profile-item-ul">'; |
| 646 |
while ($the_query->have_posts()) { |
| 647 |
$the_query->the_post(); |
| 648 |
$post_id = get_the_ID(); |
| 649 |
global $post; |
| 650 |
$post = geodir_get_post_info($post_id); |
| 651 |
setup_postdata($post); |
| 652 |
$post_avgratings = geodir_get_post_rating($post->ID); |
| 653 |
$post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID); |
| 654 |
ob_start(); |
| 655 |
geodir_comments_number($post->rating_count); |
| 656 |
$n_comments = ob_get_contents(); |
| 657 |
ob_end_clean(); |
| 658 |
|
| 659 |
do_action('uwp_before_profile_listing_item', $post_id, $user, $post_type); |
| 660 |
?> |
| 661 |
<li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-'.$post_type; ?>"> |
| 662 |
<a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>"> |
| 663 |
<?php |
| 664 |
if (has_post_thumbnail()) { |
| 665 |
$thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80)); |
| 666 |
} else { |
| 667 |
$thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png"; |
| 668 |
} |
| 669 |
?> |
| 670 |
<img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>"> |
| 671 |
</a> |
| 672 |
|
| 673 |
<?php do_action('uwp_before_profile_listing_title', $post_id, $user, $post_type); ?> |
| 674 |
<h3 class="uwp-profile-item-title"> |
| 675 |
<a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a> |
| 676 |
</h3> |
| 677 |
<?php do_action('uwp_after_profile_listing_title', $post_id, $user, $post_type); ?> |
| 678 |
|
| 679 |
<div class="uwp-time-ratings-wrap"> |
| 680 |
<?php do_action('uwp_before_profile_listing_ratings', $post_id, $user, $post_type); ?> |
| 681 |
<time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>"> |
| 682 |
<?php echo get_the_date(); ?> |
| 683 |
</time> |
| 684 |
<?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?> |
| 685 |
<?php |
| 686 |
if (!is_user_logged_in()) { |
| 687 |
do_action( 'geodir_after_favorite_html', $post->ID, 'listing' ); |
| 688 |
} |
| 689 |
?> |
| 690 |
<?php do_action('uwp_after_profile_listing_ratings', $post_id, $user, $post_type); ?> |
| 691 |
</div> |
| 692 |
|
| 693 |
<div class="uwp-profile-item-summary"> |
| 694 |
<?php |
| 695 |
do_action('uwp_before_profile_listing_summary', $post_id, $user, $post_type); |
| 696 |
$excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...')); |
| 697 |
echo $excerpt; |
| 698 |
do_action('uwp_after_profile_listing_summary', $post_id, $user, $post_type); |
| 699 |
?> |
| 700 |
</div> |
| 701 |
|
| 702 |
<div class="uwp-item-actions"> |
| 703 |
<?php |
| 704 |
if (is_user_logged_in()) { |
| 705 |
geodir_favourite_html( '', $post->ID ); |
| 706 |
} |
| 707 |
if ($post->post_author == get_current_user_id()) { |
| 708 |
if($this->uwp_is_gdv2()) { |
| 709 |
$href = 'javascript:void(0);'; |
| 710 |
$class = ''; |
| 711 |
$editlink = geodir_edit_post_link($post_id); |
| 712 |
$extra = 'onclick="gd_delete_post('.$post_id.');"'; |
| 713 |
} else { |
| 714 |
$ajaxlink = geodir_get_ajax_url(); |
| 715 |
$href = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false); |
| 716 |
$class = 'geodir-delete'; |
| 717 |
$addplacelink = get_permalink(geodir_add_listing_page_id()); |
| 718 |
$editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false); |
| 719 |
$extra = ''; |
| 720 |
} |
| 721 |
?> |
| 722 |
|
| 723 |
<span class="geodir-authorlink clearfix"> |
| 724 |
|
| 725 |
<?php do_action('geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type); ?> |
| 726 |
|
| 727 |
<a href="<?php echo esc_url($editlink); ?>" class="geodir-edit" |
| 728 |
title="<?php _e('Edit Listing', 'userswp'); ?>"> |
| 729 |
<?php |
| 730 |
$geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fas fa-edit'); |
| 731 |
echo '<i class="' . $geodir_listing_edit_icon . '"></i>'; |
| 732 |
?> |
| 733 |
<?php _e('Edit', 'userswp'); ?> |
| 734 |
</a> |
| 735 |
<a href="<?php echo $href; ?>" <?php echo $extra; ?>class="<?php echo $class; ?>" |
| 736 |
title="<?php _e('Delete Listing', 'userswp'); ?>"> |
| 737 |
<?php |
| 738 |
$geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fas fa-times', $post_id, $user, $post_type); |
| 739 |
echo '<i class="' . $geodir_listing_delete_icon . '"></i>'; |
| 740 |
?> |
| 741 |
<?php _e('Delete', 'userswp'); ?> |
| 742 |
</a> |
| 743 |
<?php do_action('geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type); ?> |
| 744 |
|
| 745 |
</span> |
| 746 |
|
| 747 |
<?php } ?> |
| 748 |
</div> |
| 749 |
</li> |
| 750 |
<?php |
| 751 |
do_action('uwp_after_profile_listing_item', $post_id, $user, $post_type); |
| 752 |
} |
| 753 |
echo '</ul>'; |
| 754 |
/* Restore original Post Data */ |
| 755 |
wp_reset_postdata(); |
| 756 |
} else { |
| 757 |
echo sprintf( __( "No %s found.", 'userswp' ), $gd_post_types[$post_type]['labels']['name']); |
| 758 |
} |
| 759 |
do_action('uwp_after_profile_listing_items', $user, $post_type); |
| 760 |
|
| 761 |
do_action('uwp_profile_pagination', $the_query->max_num_pages); |
| 762 |
?> |
| 763 |
</div> |
| 764 |
<?php |
| 765 |
} |
| 766 |
|
| 767 |
public function gd_get_reviews($user, $post_type) { |
| 768 |
$gd_post_types = geodir_get_posttypes('array'); |
| 769 |
?> |
| 770 |
<h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3> |
| 771 |
|
| 772 |
<div class="uwp-profile-item-block"> |
| 773 |
<?php |
| 774 |
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1; |
| 775 |
$limit = uwp_get_option('profile_no_of_items', 10); |
| 776 |
$offset = ($paged - 1) * $limit; |
| 777 |
|
| 778 |
$total_reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, true, $offset, $limit); |
| 779 |
$maximum_pages = ceil($total_reviews / $limit); |
| 780 |
|
| 781 |
$reviews = $this->geodir_get_reviews_by_user_id($post_type, $user->ID, false, $offset, $limit); |
| 782 |
|
| 783 |
do_action('uwp_before_profile_reviews_items', $user, $post_type); |
| 784 |
// The Loop |
| 785 |
if ($reviews) { |
| 786 |
echo '<ul class="uwp-profile-item-ul">'; |
| 787 |
foreach ($reviews as $review) { |
| 788 |
$rating = 0; |
| 789 |
if (!empty($review)) |
| 790 |
$rating = geodir_get_post_rating($review->post_id); |
| 791 |
do_action('uwp_before_profile_reviews_item', $review->comment_id, $user, $post_type); |
| 792 |
?> |
| 793 |
<li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-'.$post_type; ?>"> |
| 794 |
<a class="uwp-profile-item-img" href="<?php echo get_comment_link($review->comment_id); ?>"> |
| 795 |
<?php |
| 796 |
if ( has_post_thumbnail($review->post_id) ) { |
| 797 |
$thumb_url = get_the_post_thumbnail_url($review->post_id, array(80, 80)); |
| 798 |
} else { |
| 799 |
$thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png"; |
| 800 |
} |
| 801 |
?> |
| 802 |
<img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>"> |
| 803 |
</a> |
| 804 |
|
| 805 |
<?php do_action('uwp_before_profile_reviews_title', $review->comment_id, $user, $post_type); ?> |
| 806 |
<h3 class="uwp-profile-item-title"> |
| 807 |
<a href="<?php echo get_comment_link($review->comment_id); ?>"><?php echo get_the_title($review->post_id); ?></a> |
| 808 |
</h3> |
| 809 |
<?php do_action('uwp_after_profile_reviews_title', $review->comment_id, $user, $post_type); ?> |
| 810 |
|
| 811 |
<div class="uwp-time-ratings-wrap"> |
| 812 |
<?php do_action('uwp_before_profile_reviews_ratings', $review->comment_id, $user, $post_type); ?> |
| 813 |
<time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>"> |
| 814 |
<?php echo date_i18n(get_option('date_format'), strtotime(get_comment_date("", $review->comment_id))); ?> |
| 815 |
</time> |
| 816 |
<?php echo '<div class="uwp-ratings">' . geodir_get_rating_stars($rating, $review->comment_id) . '</div>'; ?> |
| 817 |
<?php do_action('uwp_after_profile_reviews_ratings', $review->comment_id, $user, $post_type); ?> |
| 818 |
</div> |
| 819 |
<div class="uwp-profile-item-summary"> |
| 820 |
<?php |
| 821 |
do_action('uwp_before_profile_reviews_summary', $review->comment_id, $user, $post_type); |
| 822 |
$excerpt = strip_shortcodes(wp_trim_words(get_comment_excerpt($review->comment_id), 15, '...')); |
| 823 |
echo $excerpt; |
| 824 |
do_action('uwp_after_profile_reviews_summary', $review->comment_id, $user, $post_type); |
| 825 |
?> |
| 826 |
</div> |
| 827 |
</li> |
| 828 |
<?php |
| 829 |
do_action('uwp_after_profile_reviews_item', $review->comment_id, $user, $post_type); |
| 830 |
} |
| 831 |
echo '</ul>'; |
| 832 |
/* Restore original Post Data */ |
| 833 |
wp_reset_postdata(); |
| 834 |
} else { |
| 835 |
echo sprintf( __( "No %s found.", 'userswp' ), $gd_post_types[$post_type]['labels']['name']); |
| 836 |
} |
| 837 |
|
| 838 |
do_action('uwp_after_profile_reviews_items', $user, $post_type); |
| 839 |
|
| 840 |
do_action('uwp_profile_pagination', $maximum_pages); |
| 841 |
?> |
| 842 |
</div> |
| 843 |
<?php |
| 844 |
} |
| 845 |
|
| 846 |
public function gd_get_favorites($user, $post_type) { |
| 847 |
$gd_post_types = geodir_get_posttypes('array'); |
| 848 |
?> |
| 849 |
<h3><?php echo __($gd_post_types[$post_type]['labels']['name'], 'userswp') ?></h3> |
| 850 |
|
| 851 |
<div class="uwp-profile-item-block"> |
| 852 |
<?php |
| 853 |
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1; |
| 854 |
|
| 855 |
$user_fav_posts = geodir_get_user_favourites($user->ID); |
| 856 |
|
| 857 |
if ($user_fav_posts) { |
| 858 |
$args = array( |
| 859 |
'post_type' => $post_type, |
| 860 |
'post_status' => array('publish'), |
| 861 |
'posts_per_page' => uwp_get_option('profile_no_of_items', 10), |
| 862 |
'post__in' => $user_fav_posts, |
| 863 |
'paged' => $paged, |
| 864 |
); |
| 865 |
|
| 866 |
if (get_current_user_id() == $user->ID) { |
| 867 |
$args['post_status'] = array('publish', 'draft', 'private', 'pending', 'gd-closed', 'gd-expired'); |
| 868 |
} |
| 869 |
|
| 870 |
// The Query |
| 871 |
$the_query = new WP_Query($args); |
| 872 |
|
| 873 |
do_action('uwp_before_profile_favourite_items', $user, $post_type); |
| 874 |
// The Loop |
| 875 |
if ($the_query->have_posts()) { |
| 876 |
echo '<ul class="uwp-profile-item-ul">'; |
| 877 |
while ($the_query->have_posts()) { |
| 878 |
$the_query->the_post(); |
| 879 |
$post_id = get_the_ID(); |
| 880 |
global $post; |
| 881 |
$post = geodir_get_post_info($post_id); |
| 882 |
setup_postdata($post); |
| 883 |
$post_avgratings = geodir_get_post_rating($post->ID); |
| 884 |
$post_ratings = geodir_get_rating_stars($post_avgratings, $post->ID); |
| 885 |
ob_start(); |
| 886 |
geodir_comments_number($post->rating_count); |
| 887 |
$n_comments = ob_get_contents(); |
| 888 |
ob_end_clean(); |
| 889 |
do_action('uwp_before_profile_favourite_item', $post_id, $user, $post_type); |
| 890 |
?> |
| 891 |
<li class="uwp-profile-item-li uwp-profile-item-clearfix <?php echo 'gd-post-'.$post_type; ?>"> |
| 892 |
<a class="uwp-profile-item-img" href="<?php echo get_the_permalink(); ?>"> |
| 893 |
<?php |
| 894 |
if (has_post_thumbnail()) { |
| 895 |
$thumb_url = get_the_post_thumbnail_url(get_the_ID(), array(80, 80)); |
| 896 |
} else { |
| 897 |
$thumb_url = USERSWP_PLUGIN_URL."/public/assets/images/no_thumb.png"; |
| 898 |
} |
| 899 |
?> |
| 900 |
<img class="uwp-profile-item-alignleft uwp-profile-item-thumb" src="<?php echo $thumb_url; ?>"> |
| 901 |
</a> |
| 902 |
|
| 903 |
<?php do_action('uwp_before_profile_favourite_title', $post_id, $user, $post_type); ?> |
| 904 |
<h3 class="uwp-profile-item-title"> |
| 905 |
<a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a> |
| 906 |
</h3> |
| 907 |
<?php do_action('uwp_after_profile_favourite_title', $post_id, $user, $post_type); ?> |
| 908 |
|
| 909 |
<div class="uwp-time-ratings-wrap"> |
| 910 |
<?php do_action('uwp_before_profile_favourite_ratings', $post_id, $user, $post_type); ?> |
| 911 |
<time class="uwp-profile-item-time published" datetime="<?php echo get_the_time('c'); ?>"> |
| 912 |
<?php echo get_the_date(); ?> |
| 913 |
</time> |
| 914 |
<?php echo '<div class="uwp-ratings">' . $post_ratings . ' <a href="' . get_comments_link() . '" class="uwp-num-comments">' . $n_comments . '</a></div>'; ?> |
| 915 |
<?php |
| 916 |
if (!is_user_logged_in()) { |
| 917 |
do_action( 'geodir_after_favorite_html', $post->ID, 'listing' ); |
| 918 |
} |
| 919 |
?> |
| 920 |
<?php do_action('uwp_after_profile_favourite_ratings', $post_id, $user, $post_type); ?> |
| 921 |
</div> |
| 922 |
|
| 923 |
<div class="uwp-profile-item-summary"> |
| 924 |
<?php |
| 925 |
do_action('uwp_before_profile_favourite_summary', $post_id, $user, $post_type); |
| 926 |
$excerpt = strip_shortcodes(wp_trim_words(get_the_excerpt(), 15, '...')); |
| 927 |
echo $excerpt; |
| 928 |
do_action('uwp_after_profile_favourite_summary', $post_id, $user, $post_type); |
| 929 |
?> |
| 930 |
</div> |
| 931 |
|
| 932 |
<div class="uwp-item-actions"> |
| 933 |
<?php |
| 934 |
if (is_user_logged_in()) { |
| 935 |
geodir_favourite_html( '', $post->ID ); |
| 936 |
} |
| 937 |
if ($post->post_author == get_current_user_id()) { |
| 938 |
if($this->uwp_is_gdv2()) { |
| 939 |
$href = 'javascript:void(0);'; |
| 940 |
$class = ''; |
| 941 |
$editlink = geodir_edit_post_link($post_id); |
| 942 |
$extra = 'onclick="gd_delete_post('.$post_id.');"'; |
| 943 |
} else { |
| 944 |
$ajaxlink = geodir_get_ajax_url(); |
| 945 |
$href = geodir_getlink($ajaxlink, array('geodir_ajax' => 'add_listing', 'ajax_action' => 'delete', 'pid' => $post->ID), false); |
| 946 |
$class = 'geodir-delete'; |
| 947 |
$addplacelink = get_permalink(geodir_add_listing_page_id()); |
| 948 |
$editlink = geodir_getlink($addplacelink, array('pid' => $post->ID), false); |
| 949 |
$extra = ''; |
| 950 |
} |
| 951 |
?> |
| 952 |
|
| 953 |
<span class="geodir-authorlink clearfix"> |
| 954 |
|
| 955 |
<?php do_action('geodir_before_edit_post_link_on_listing', $post_id, $user, $post_type); ?> |
| 956 |
|
| 957 |
<a href="<?php echo esc_url($editlink); ?>" class="geodir-edit" |
| 958 |
title="<?php _e('Edit Listing', 'userswp'); ?>"> |
| 959 |
<?php |
| 960 |
$geodir_listing_edit_icon = apply_filters('geodir_listing_edit_icon', 'fas fa-edit'); |
| 961 |
echo '<i class="' . $geodir_listing_edit_icon . '"></i>'; |
| 962 |
?> |
| 963 |
<?php _e('Edit', 'userswp'); ?> |
| 964 |
</a> |
| 965 |
<a href="<?php echo $href; ?>" <?php echo $extra; ?> class="<?php echo $class; ?>" |
| 966 |
title="<?php _e('Delete Listing', 'userswp'); ?>"> |
| 967 |
<?php |
| 968 |
$geodir_listing_delete_icon = apply_filters('geodir_listing_delete_icon', 'fas fa-times'); |
| 969 |
echo '<i class="' . $geodir_listing_delete_icon . '"></i>'; |
| 970 |
?> |
| 971 |
<?php _e('Delete', 'userswp'); ?> |
| 972 |
</a> |
| 973 |
|
| 974 |
<?php do_action('geodir_after_edit_post_link_on_listing', $post_id, $user, $post_type); ?> |
| 975 |
|
| 976 |
</span> |
| 977 |
|
| 978 |
<?php } ?> |
| 979 |
</div> |
| 980 |
</li> |
| 981 |
<?php |
| 982 |
do_action('uwp_after_profile_favourite_item', $post_id, $user, $post_type); |
| 983 |
} |
| 984 |
echo '</ul>'; |
| 985 |
/* Restore original Post Data */ |
| 986 |
wp_reset_postdata(); |
| 987 |
} else { |
| 988 |
echo sprintf( __( "No %s found", 'userswp' ), $gd_post_types[$post_type]['labels']['name']); |
| 989 |
} |
| 990 |
|
| 991 |
do_action('uwp_after_profile_favourite_items', $user, $post_type); |
| 992 |
|
| 993 |
do_action('uwp_profile_pagination', $the_query->max_num_pages); |
| 994 |
} else { |
| 995 |
echo sprintf( __( "No %s found.", 'userswp' ), $gd_post_types[$post_type]['labels']['name']); |
| 996 |
} |
| 997 |
?> |
| 998 |
</div> |
| 999 |
<?php |
| 1000 |
} |
| 1001 |
|
| 1002 |
public function get_gd_login_url($url, $args) { |
| 1003 |
$register_page = uwp_get_page_id('register_page', false); |
| 1004 |
$login_page = uwp_get_page_id('login_page', false); |
| 1005 |
$forgot_page = uwp_get_page_id('forgot_page', false); |
| 1006 |
$reset_page = uwp_get_page_id('reset_page', false); |
| 1007 |
|
| 1008 |
if (!empty($args)) { |
| 1009 |
if (isset($args['signup']) && $args['signup']) { |
| 1010 |
$page_id = $register_page; |
| 1011 |
} elseif (isset($args['forgot']) && $args['forgot']) { |
| 1012 |
$page_id = $forgot_page; |
| 1013 |
} elseif (isset($args['reset']) && $args['reset']) { |
| 1014 |
$page_id = $reset_page; |
| 1015 |
} else { |
| 1016 |
$page_id = $login_page; |
| 1017 |
} |
| 1018 |
} else { |
| 1019 |
$page_id = $login_page; |
| 1020 |
} |
| 1021 |
if ($page_id) { |
| 1022 |
$uwp_url = get_permalink($page_id); |
| 1023 |
|
| 1024 |
if (strpos($url, 'redirect_add_listing') !== false) { |
| 1025 |
$parsed = wp_parse_url($url); |
| 1026 |
parse_str($parsed['query'], $query); |
| 1027 |
$uwp_url = add_query_arg( array( |
| 1028 |
'redirect_to' => $query['redirect_add_listing'], |
| 1029 |
), $uwp_url ); |
| 1030 |
} |
| 1031 |
|
| 1032 |
if(isset($args['redirect_to']) && !empty($args['redirect_to'])){ |
| 1033 |
$uwp_url = add_query_arg( array( |
| 1034 |
'redirect_to' => $args['redirect_to'], |
| 1035 |
), $uwp_url ); |
| 1036 |
} |
| 1037 |
|
| 1038 |
$url = $uwp_url; |
| 1039 |
} |
| 1040 |
return $url; |
| 1041 |
} |
| 1042 |
|
| 1043 |
public function geodir_uwp_author_redirect() { |
| 1044 |
if ( ! empty( $_REQUEST['geodir_dashbord'] ) ) { |
| 1045 |
$author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); |
| 1046 |
|
| 1047 |
if ( !empty( $author ) && ! empty( $author->ID ) ) { |
| 1048 |
$favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false; |
| 1049 |
$post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL; |
| 1050 |
|
| 1051 |
$author_id = $author->ID; |
| 1052 |
$author_link = uwp_build_profile_tab_url( $author_id ); |
| 1053 |
$gd_post_types = geodir_get_posttypes( 'array' ); |
| 1054 |
|
| 1055 |
if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) { |
| 1056 |
if ( $favourite ) { |
| 1057 |
$profile_favorites = uwp_get_option( 'gd_profile_favorites', array() ); |
| 1058 |
|
| 1059 |
if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) { |
| 1060 |
$author_link = uwp_build_profile_tab_url( $author_id, 'favorites', $gd_post_types[ $post_type ]['has_archive'] ); |
| 1061 |
} else { |
| 1062 |
return; // Do not redirect to dashboard CPT favorites. |
| 1063 |
} |
| 1064 |
} else { |
| 1065 |
$profile_listings = uwp_get_option( 'gd_profile_listings', array() ); |
| 1066 |
|
| 1067 |
if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) { |
| 1068 |
$author_link = uwp_build_profile_tab_url( $author_id, 'listings', $gd_post_types[ $post_type ]['has_archive'] ); |
| 1069 |
} else { |
| 1070 |
return; // Do not redirect to dashboard CPT listings. |
| 1071 |
} |
| 1072 |
} |
| 1073 |
} |
| 1074 |
|
| 1075 |
wp_redirect($author_link); |
| 1076 |
exit; |
| 1077 |
} |
| 1078 |
} |
| 1079 |
return; |
| 1080 |
} |
| 1081 |
|
| 1082 |
public function gd_is_listings_tab() { |
| 1083 |
global $wp_query; |
| 1084 |
if (is_page() && class_exists('UsersWP')) { |
| 1085 |
$profile_page = uwp_get_page_id('profile_page', false); |
| 1086 |
if ($profile_page) { |
| 1087 |
if (isset($wp_query->query_vars['uwp_profile']) |
| 1088 |
&& isset($wp_query->query_vars['uwp_tab']) |
| 1089 |
&& ($wp_query->query_vars['uwp_tab'] == 'listings' || $wp_query->query_vars['uwp_tab'] == 'favorites') |
| 1090 |
) { |
| 1091 |
|
| 1092 |
return true; |
| 1093 |
|
| 1094 |
} |
| 1095 |
} |
| 1096 |
} |
| 1097 |
return false; |
| 1098 |
} |
| 1099 |
|
| 1100 |
public function geodir_post_status_is_author_page($value) { |
| 1101 |
return $value || $this->gd_is_listings_tab(); |
| 1102 |
} |
| 1103 |
|
| 1104 |
public function geodir_add_post_status_author_page() { |
| 1105 |
global $wpdb, $post; |
| 1106 |
|
| 1107 |
$html = ''; |
| 1108 |
if (get_current_user_id()) { |
| 1109 |
if ($this->gd_is_listings_tab() && !empty($post) && isset($post->post_author) && $post->post_author == get_current_user_id()) { |
| 1110 |
|
| 1111 |
// we need to query real status direct as we dynamically change the status for author on author page so even non author status can view them. |
| 1112 |
$real_status = $wpdb->get_var("SELECT post_status from $wpdb->posts WHERE ID=$post->ID"); |
| 1113 |
$status = "<strong>("; |
| 1114 |
$status_icon = '<i class="fas fa-play"></i>'; |
| 1115 |
switch ($real_status){ |
| 1116 |
case 'publish' : |
| 1117 |
$status .= __('Published', 'userswp'); |
| 1118 |
break; |
| 1119 |
case 'pending' : |
| 1120 |
$status .= __('Pending', 'userswp'); |
| 1121 |
break; |
| 1122 |
case 'gd-closed' : |
| 1123 |
$status .= __('Closed', 'userswp'); |
| 1124 |
break; |
| 1125 |
case 'gd-expired' : |
| 1126 |
$status .= __('Expired', 'userswp'); |
| 1127 |
break; |
| 1128 |
default : |
| 1129 |
$status .= __('Not published', 'userswp'); |
| 1130 |
break; |
| 1131 |
} |
| 1132 |
$status .= ")</strong>"; |
| 1133 |
|
| 1134 |
$html = '<span class="geodir-post-status">' . $status_icon . ' <font class="geodir-status-label">' . __('Status: ', 'userswp') . '</font>' . $status . '</span>'; |
| 1135 |
} |
| 1136 |
} |
| 1137 |
|
| 1138 |
if ($html != '') { |
| 1139 |
echo apply_filters('geodir_filter_status_text_on_author_page', $html); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
|
| 1143 |
public function gd_login_wid_login_placeholder() { |
| 1144 |
return __( 'Username', 'userswp' ); |
| 1145 |
} |
| 1146 |
|
| 1147 |
public function gd_login_wid_login_name() { |
| 1148 |
return "uwp_login_username"; |
| 1149 |
} |
| 1150 |
|
| 1151 |
public function gd_login_wid_login_pwd() { |
| 1152 |
return "uwp_login_password"; |
| 1153 |
} |
| 1154 |
|
| 1155 |
public function gd_login_inject_nonce() { |
| 1156 |
?> |
| 1157 |
<input type="hidden" name="uwp_login_nonce" value="<?php echo wp_create_nonce( 'uwp-login-nonce' ); ?>" /> |
| 1158 |
<?php |
| 1159 |
} |
| 1160 |
|
| 1161 |
public function check_redirect_author_page( $redirect = false ) { |
| 1162 |
if ( $redirect && ! empty( $_REQUEST['geodir_dashbord'] ) ) { |
| 1163 |
$author = get_query_var( 'author_name' ) ? get_user_by( 'slug', get_query_var( 'author_name' ) ) : get_userdata( get_query_var( 'author' ) ); |
| 1164 |
|
| 1165 |
if ( !empty( $author ) && ! empty( $author->ID ) ) { |
| 1166 |
$favourite = isset($_REQUEST['list']) && $_REQUEST['list'] == 'favourite' ? true : false; |
| 1167 |
$post_type = isset( $_REQUEST['stype'] ) ? sanitize_text_field( $_REQUEST['stype'] ) : NULL; |
| 1168 |
|
| 1169 |
$author_id = $author->ID; |
| 1170 |
$author_link = uwp_build_profile_tab_url( $author_id ); |
| 1171 |
$gd_post_types = geodir_get_posttypes( 'array' ); |
| 1172 |
|
| 1173 |
if ( !empty( $gd_post_types ) && array_key_exists( $post_type, $gd_post_types ) ) { |
| 1174 |
if ( $favourite ) { |
| 1175 |
$profile_favorites = uwp_get_option( 'gd_profile_favorites', array() ); |
| 1176 |
|
| 1177 |
if ( uwp_get_option( 'geodir_uwp_link_favorite', '0' ) && ! empty( $profile_favorites ) && in_array( $post_type, $profile_favorites ) ) { |
| 1178 |
// Redirect to dashboard CPT favorites. |
| 1179 |
} else { |
| 1180 |
$redirect = false; // Do not redirect to dashboard CPT favorites. |
| 1181 |
} |
| 1182 |
} else { |
| 1183 |
$profile_listings = uwp_get_option( 'gd_profile_listings', array() ); |
| 1184 |
|
| 1185 |
if ( uwp_get_option( 'geodir_uwp_link_listing', '0' ) && ! empty( $profile_listings ) && in_array( $post_type, $profile_listings ) ) { |
| 1186 |
// Redirect to dashboard CPT listings. |
| 1187 |
} else { |
| 1188 |
$redirect =false; // Do not redirect to dashboard CPT listings. |
| 1189 |
} |
| 1190 |
} |
| 1191 |
} |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
return $redirect; |
| 1196 |
} |
| 1197 |
|
| 1198 |
public function skip_uwp_author_page( $uwp_author = true ) { |
| 1199 |
if ( geodir_is_page( 'author' ) ) { |
| 1200 |
$uwp_author = false; |
| 1201 |
} |
| 1202 |
|
| 1203 |
return $uwp_author; |
| 1204 |
} |
| 1205 |
|
| 1206 |
public function uwp_is_gdv2(){ |
| 1207 |
|
| 1208 |
if(version_compare(GEODIRECTORY_VERSION,'2.0.0.0', '>=') ) { |
| 1209 |
return true; |
| 1210 |
} |
| 1211 |
|
| 1212 |
return false; |
| 1213 |
} |
| 1214 |
} |
| 1215 |
$userswp_geodirectory = UsersWP_GeoDirectory_Plugin::get_instance(); |