';
if ($comment_meta == true){
$output .='
'.get_comments_number().'';
}
if ($deal_score == true) {
$output .= '
';
$output .=''.__('Deal Score', 'rehub-theme').'';
$output .='';
if ($temp > 0) {
$output .= '+';
}
$output .= $temp.'
';
}
$onlyuser_class = rehub_option('thumb_only_users');
$loginurl = '';
if($onlyuser_class == 1){
if (is_user_logged_in()){
$onlyuser_class = '';
}
else{
if(rehub_option('custom_login_url')){
$urllogin = rehub_option('custom_login_url');
$loginurl = ' data-type="url" data-customurl="'.esc_url($urllogin).'"';
}
$onlyuser_class = ' act-rehub-login-popup restrict_for_guests';
}
}else{
$onlyuser_class = '';
}
$outputtext = $wishlistpage = $wishlisted = '';
if (rehub_option('wishlistpage') !=''){
$wishlistpage = esc_url(get_the_permalink((int)rehub_option('wishlistpage')));
$wishlisted = ' wishlisted';
}
if ($wishlistadd) {
$outputtext .= '
';
$outputtext .= $wishlistadd.'';
}
if ($wishlistadded) {
$outputtext .= '
';
$outputtext .= $wishlistadded.'';
}
if ($wishlistremoved) {
$outputtext .= '
';
$outputtext .= $wishlistremoved.' ';
}
$output .= '
';
if ($onlyone == false) {
if ( AlreadyHot( $post_id ) ) { // already liked, set up unlike addon
$output .= ''.$outputtext.'';
} else {
$output .= ''.$outputtext.'';
}
}
if ( AlreadyHot( $post_id ) ) { // already liked, set up unlike addon
$output .= ''.$outputtext.'';
} else {
$output .= ''.$outputtext.'';
}
$output .= '';
if ($deal_score == false) {
$output .= '
'.$temp.' ';
}
$output .= '
';
return $output;
}
}
if (!function_exists('RH_get_wishlist')){
function RH_get_wishlist( $post_id, $wishlistadd = '',$wishlistadded = '', $wishlistremoved = '' ) {
if(rehub_option('wishlist_disable') == 1){return;}
wp_enqueue_script('rhwishcount');
$like_count = get_post_meta( $post_id, "post_wish_count", true ); // get post likes
if ( ( !$like_count ) || ( $like_count && $like_count == "0" ) ) { // no votes, set up empty variable
$temp = '0';
} elseif ( $like_count && $like_count != "0" ) { // there are votes!
$temp = esc_attr( $like_count );
}
$alreadyclass = ( AlreadyWish( $post_id ) ) ? ' alreadyhot' : '';
$output = '';
$onlyuser_class = rehub_option('wish_only_users');
$loginurl = '';
if($onlyuser_class == 1){
if (is_user_logged_in()){
$onlyuser_class = '';
}
else{
if(rehub_option('custom_login_url')){
$urllogin = rehub_option('custom_login_url');
$loginurl = ' data-type="url" data-customurl="'.esc_url($urllogin).'"';
}
$onlyuser_class = ' act-rehub-login-popup restrict_for_guests';
}
}else{
$onlyuser_class = '';
}
$outputtext = $wishlistpage = $wishlisted = '';
if (rehub_option('wishlistpage') !=''){
$wishlistpage = esc_url(get_the_permalink((int)rehub_option('wishlistpage')));
$wishlisted = ' wishlisted';
}
if ($wishlistadd) {
$outputtext .= '';
$outputtext .= $wishlistadd.'';
}
if ($wishlistadded) {
$outputtext .= '';
$outputtext .= $wishlistadded.'';
}
if ($wishlistremoved) {
$outputtext .= '';
$outputtext .= $wishlistremoved.' ';
}
$output .= '';
if ( AlreadyWish( $post_id ) ) { // already liked, set up unlike addon
$output .= ''.$outputtext.'';
} else {
$output .= ''.$outputtext.'';
}
$output .= '';
$output .= ''.$temp.' ';
$output .= '
';
return $output;
}
}
if(!function_exists('rh_hot_shortcode')){
function rh_hot_shortcode($atts , $content = null ){
$atts = shortcode_atts(
array(
'post_id' => '',
'comment_meta' => false,
'deal_score' => false,
'onlyone' => false,
'wishlistadd' => '',
'wishlistadded' => '',
'wishlistremoved' => '',
'as_btn'=> '',
'hotline' => ''
),
$atts,
'getHotThumb'
);
extract($atts);
if(empty($post_id)){
global $post;
$post_id = $post->ID;
}
$out = '';
if($as_btn){
$out .= '';
echo '';
while ($wp_query->have_posts()) : $wp_query->the_post();
global $post;
$posttype = $post->post_type;
?>
';
}
wp_reset_query();
if (function_exists('rehub_social_share')){
echo '
'.rehub_social_share('row', '', '', '', implode(',', $wishlistids)).'
';
}
}
}else{
esc_html_e('There is nothing in your wishlist', 'rehub-theme');
}
$output = ob_get_contents();
ob_end_clean();
return $output;
}
}
//////USER LIKES - USE IT FOR WC VENDORS//////
add_action( 'wp_ajax_nopriv_rh-user-favor-shop', 'rh_user_favorite_shop');
add_action( 'wp_ajax_rh-user-favor-shop', 'rh_user_favorite_shop' );
if (!function_exists('rh_user_favorite_shop')){
function rh_user_favorite_shop() {
$nonce = sanitize_text_field($_POST['favornonce']);
if ( ! wp_verify_nonce( $nonce, 'favornonce' ) )
die ( 'Nope!' );
if ( isset( $_POST['rh_user_favorite_shop'] ) ) {
$user_id = intval($_POST['user_id']); // post id
$rh_user_favorite_shop_count = get_user_meta( $user_id, "_rh_user_favorite_shop_count", true ); // post like count
if ( is_user_logged_in() ) { // user is logged in
global $current_user;
$currentuserID = $current_user->ID; // current user
$ilike_users = get_user_meta( $currentuserID, "_i_liked_users" ); // user ids which were liked by user
$who_like_me = get_user_meta( $user_id, "_users_who_like_me" ); // user ids which make like for user
$ilike_USERS = ""; // setup array variable
$users_like_ME = ""; // setup array variable
if ( count( $ilike_users ) != 0 ) { // meta exists, set up values
$ilike_USERS = $ilike_users[0];
}
if ( !is_array( $ilike_USERS ) ) // make array just in case
$ilike_USERS = array();
if ( count( $who_like_me ) != 0 ) { // meta exists, set up values
$users_like_ME = $who_like_me[0];
}
if ( !is_array( $users_like_ME ) ) // make array just in case
$users_like_ME = array();
$ilike_USERS['user-'.$user_id] = $user_id; // Add user id to user meta array of your likes
$users_like_ME['user-'.$currentuserID] = $currentuserID; // add user id to user meta array of who liked user
if ( !AlreadylikedShop($user_id) ) { // like the post
update_user_meta( $user_id, "_users_who_like_me", $users_like_ME ); // Add current user ID array who likes
update_user_meta( $user_id, "_rh_user_favorite_shop_count", ++$rh_user_favorite_shop_count ); // +1 count of likes
update_user_meta( $currentuserID, "_i_liked_users", $ilike_USERS ); // Add user ID to user meta
echo ''.$rh_user_favorite_shop_count; // update count on front end
} else { // unlike the post
$pid_key = array_search( $user_id, $ilike_USERS ); // find the key
$uid_key = array_search( $currentuserID, $users_like_ME ); // find the key
unset( $ilike_USERS[$pid_key] ); // remove from array
unset( $users_like_ME[$uid_key] ); // remove from array
update_user_meta( $user_id, "_users_who_like_me", $users_like_ME ); // Add current user ID array who likes
update_user_meta( $user_id, "_rh_user_favorite_shop_count", --$rh_user_favorite_shop_count ); // -1 count of likes
update_user_meta( $currentuserID, "_i_liked_users", $ilike_USERS ); // Add post ID to user meta
echo "already".$rh_user_favorite_shop_count; // update count on front end
}
}
}
exit;
}
}
if (!function_exists('AlreadylikedShop')){
function AlreadylikedShop( $user_id ) { // test if user liked before
if ( is_user_logged_in() ) { // user is logged in
global $current_user;
$currentuserID = $current_user->ID; // current user
$who_like_me = get_user_meta($currentuserID, "_i_liked_users" ); // user ids from post meta
$users_like_ME = ""; // set up array variable
if ( count( $who_like_me ) != 0 ) { // meta exists, set up values
$users_like_ME = $who_like_me[0];
}
if( !is_array( $users_like_ME ) ) // make array just in case
$users_like_ME = array();
if ( in_array( $user_id, $users_like_ME ) ) { // True if User ID in array
return true;
}
return false;
}
}
}
if (!function_exists('getShopLikeButton')){
function getShopLikeButton( $user_id ) {
wp_enqueue_script('rhshoplike', get_template_directory_uri() . '/js/shoplike.js', array('jquery', 'rehub'), '1.0', true);
$wooscriptvars = array(
'favornonce' => wp_create_nonce('favornonce'),
);
wp_localize_script( 'rhshoplike', 'wooscriptvars', $wooscriptvars );
$like_count = get_user_meta( $user_id, "_rh_user_favorite_shop_count", true ); // get post likes
if ( ( !$like_count ) || ( $like_count && $like_count == "0" ) ) { // no votes, set up empty variable
$likes = '0';
} elseif ( $like_count && $like_count != "0" ) { // there are votes!
$likes = esc_attr( $like_count );
}
$alreadyclass = ( AlreadylikedShop( $user_id ) ) ? ' alreadyinfavor' : '';
$output = '
';
if ( AlreadylikedShop( $user_id ) ) { // already liked, set up unlike addon
$output .= '';
$output .= ' '.$likes.'';
} else { // normal like button
$output .= '
';
$output .= '
'.$likes.'';
}
if (rehub_option('exclude_rh_user_favorite_shop') !='1') {
return $output;
}
else {
return false;
}
}
}
if (!function_exists('RhGetUserFavoriteShops')){
function RhGetUserFavoriteShops() {
if ( is_user_logged_in() ) { // user is logged in
global $current_user;
$user_id = $current_user->ID; // current user
$likedposts = get_user_meta( $user_id, "_i_liked_users", true);
}
if (!empty($likedposts)){
$likedposts = implode(',', $likedposts);
return do_shortcode('[wpsm_vendorlist per_page=50 user_id='.$likedposts.']');
}
else{
return esc_html__('You don\'t have any favorite store.', 'rehub-theme');
}
}
}