PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-rest-api
/
classes
<?php add_action( 'rest_api_init', 'dwt_listing_profile_reviews_api_hooks_get', 0 ); function dwt_listing_profile_reviews_api_hooks_get() { register_rest_route( 'downtown/app', '/reviews/', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'dwt_listing_get_my_reviews', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); register_rest_route( 'downtown/app', '/reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_my_reviews', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_get_my_reviews')) { function dwt_listing_get_my_reviews($request) { global $dwt_listing_api; $user = wp_get_current_user(); $user_id = $user->ID; //submitted reviews //return dwt_listing_text('dwt_listing_review_enable_stars'); $review_array['submitted_reviews'] = dwt_listing_fetch_my_submitted_reviewz($user_id,'submitted'); $review_array['received_reviews'] = dwt_listing_fetch_my_received_reviewz($user_id,'received'); $review_array['profile_data'] = dwt_listing_basic_profile_data(); $extra_arr['received_txt'] = __("Received Reviews", "dwt-listing-api"); $extra_arr['submitted_txt'] = __("Submitted Reviews", "dwt-listing-api"); $extra_arr['btn_txt'] = __("Submit Reply", "dwt-listing-api"); $extra_arr['replybox_txt'] = __("Reply to this review", "dwt-listing-api"); $extra_arr['placeholder_txt'] = __("Write a reply to this review", "dwt-listing-api"); $extra_arr['btn_txt'] = __("Submit Reply", "dwt-listing-api"); $extra_arr['stars_enabled'] = dwt_listing_text('dwt_listing_review_enable_stars'); $extra_arr['gallery_enabled'] = dwt_listing_text('dwt_listing_review_enable_gallery'); $extra_arr['for_title_placeholder'] = __("Place attractive title here", "dwt-listing-api"); $extra_arr['for_area_placeholder'] = __("Your comments, suggestions or experience at this place.", "dwt-listing-api"); $response = rest_ensure_response(array( 'success' => true, "extra_text" => $extra_arr, 'data' => $review_array, "message" => "")); return $response; } } /*DWT Listing Reply Of Review */ add_action( 'rest_api_init', 'dwt_listing_profile_reviews_reply', 0 ); function dwt_listing_profile_reviews_reply() { register_rest_route( 'downtown/app', '/received-reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_reply_of_review', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_reply_of_review')) { function dwt_listing_reply_of_review($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $listing_id = (isset($json_data['listing_id'])) ? sanitize_text_field($json_data['listing_id']) : ''; $comment_id = (isset($json_data['comment_id'])) ? sanitize_text_field($json_data['comment_id']) : ''; $review_msg_reply = (isset($json_data['comment'])) ? sanitize_text_field($json_data['comment']) : ''; $reply_review_id = (isset($json_data['replyed_comment_id'])) ? sanitize_text_field($json_data['replyed_comment_id']) : ''; //if comment esists if(isset($comment_id) && $comment_id !="" && $listing_id !="") { if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } //if user exists $user_infoz = get_userdata($user_id); if($user_infoz) { $replier_id = $user_id; $replier_email = $user_infoz->user_email; $replier_name = $user_infoz->display_name; if(isset($reply_review_id) && $reply_review_id !="") { $commentarr['comment_post_ID'] = $listing_id; $commentarr['comment_ID'] = $reply_review_id; $commentarr['comment_approved'] = 1; $commentarr['comment_content'] = $review_msg_reply; wp_update_comment( $commentarr ); return rest_ensure_response(array( 'success' => true, 'data' => '', 'message' => __( "Reply Updated Successfully.", 'dwt-listing-api' ))); } else { $time = current_time('mysql'); $data = array( 'comment_post_ID' => $listing_id, 'comment_author' => $replier_name, 'comment_author_email' => $replier_email, 'comment_content' => $review_msg_reply, 'comment_type' => 'listing', 'user_id' => $replier_id, 'comment_date' => $time, 'comment_approved' => 1, 'comment_parent' =>$comment_id, ); $comment_id = wp_insert_comment($data); if($comment_id) { // send email if( isset( $dwt_listing_options['dwt_listing_review_reply_email'] ) && $dwt_listing_options['dwt_listing_review_reply_email'] == "1") { // Sending email to listing owner $listing_owner_email = dwt_listing_listing_owner($listing_id,'email'); $listing_owner_name = dwt_listing_listing_owner($listing_id,'name'); $to = $listing_owner_email; $subject = __('Listing Review Reply', 'dwt-listing-api'); $body = '<html><body><p>'.__('You received a new reply, please check it. ','dwt-listing-api').'<a href="'.get_the_permalink( $listing_id ).'">' . get_the_title( $listing_id ) . '</a></p></body></html>'; $from = get_bloginfo( 'name' ); if( isset( $dwt_listing_options['downtwon_review_reply_email_from'] ) && $dwt_listing_options['downtwon_review_reply_email_from'] != "" ) { $from = $dwt_listing_options['downtwon_review_reply_email_from']; } $headers = array('Content-Type: text/html; charset=UTF-8',"From: $from" ); if( isset( $dwt_listing_options['downtwon_review_reply_email_message'] ) && $dwt_listing_options['downtwon_review_reply_email_message'] != "" ) { $subject_keywords = array('%site_name%', '%ad_title%'); $subject_replaces = array(get_bloginfo( 'name' ), get_the_title($listing_id)); $subject = str_replace($subject_keywords, $subject_replaces, $dwt_listing_options['downtwon_review_reply_email_change']); $author_id = get_post_field ('post_author', $listing_id); $user_info = get_userdata($author_id); $msg_keywords = array('%listing_owner_name%', '%ad_title%', '%ad_link%', '%replier_comment%' , '%replier_name%'); $msg_replaces = array($listing_owner_name, get_the_title($listing_id), get_the_permalink($listing_id), $review_msg_reply , $replier_name); $body = str_replace($msg_keywords, $msg_replaces, $dwt_listing_options['downtwon_review_reply_email_message']); } wp_mail( $to, $subject, $body, $headers ); } return rest_ensure_response(array( 'success' => true, 'data' => '', 'message' => __( "Reply Posted Successfully.", 'dwt-listing-api' ))); } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Reply not sent, please try again later.", 'dwt-listing-api' ))); } } } else { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "User don't exisits.", 'dwt-listing-api' ))); } } } } /*DWT Listing Reply Of Review */ add_action( 'rest_api_init', 'dwt_listing_profile_reviews_submit', 0 ); function dwt_listing_profile_reviews_submit() { register_rest_route( 'downtown/app', '/submitted-reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_my_reviews_submitted', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } //Submitted Reviews Post Service if (!function_exists('dwt_listing_my_reviews_submitted')) { function dwt_listing_my_reviews_submitted($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $comment_id = (isset($json_data['comment_id'])) ? sanitize_text_field($json_data['comment_id']) : ''; $comment_title = (isset($json_data['comment_title'])) ? sanitize_text_field($json_data['comment_title']) : ''; $comment_desc = (isset($json_data['comment_desc'])) ? sanitize_text_field($json_data['comment_desc']) : ''; $comment_stars = (isset($json_data['comment_stars'])) ? sanitize_text_field($json_data['comment_stars']) : ''; $listing_id = (isset($json_data['listing_id'])) ? sanitize_text_field($json_data['listing_id']) : ''; if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } //update comment $my_comment_id = $comment_id; $commentarr['comment_post_ID'] = $listing_id; $commentarr['comment_ID'] = $my_comment_id; $commentarr['comment_approved'] = 1; $commentarr['comment_content'] = $comment_desc; wp_update_comment( $commentarr ); update_comment_meta($my_comment_id, 'review_stars', $comment_stars); update_comment_meta($my_comment_id, 'review_main_title', $comment_title); return rest_ensure_response(array( 'success' => true, 'data' => '', 'message' => __( "Review Updated Successfully.", 'dwt-listing-api' ))); die(); } } /*Submited Review Images */ add_action( 'rest_api_init', 'dwt_listing_profile_reviews_gallery_up', 0 ); function dwt_listing_profile_reviews_gallery_up() { register_rest_route( 'downtown/app', '/upload-gallery-imgz/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_comments_gallery_app', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if ( ! function_exists( 'dwt_listing_comments_gallery_app' ) ) { function dwt_listing_comments_gallery_app($request) { $displayMaxSize = ''; if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { $displayMaxSize = ini_get('post_max_size'); switch ( substr($displayMaxSize,-1) ) { case 'G': $displayMaxSize = (int)$displayMaxSize * 1024; case 'M': $displayMaxSize = (int)$displayMaxSize * 1024; case 'K': $displayMaxSize = (int) $displayMaxSize * 1024; } return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => sprintf( __( 'Posted data is too large %s bytes exceeds the maximum size of %d bytes.', 'dwt-listing-api' ), $_SERVER['CONTENT_LENGTH'], $displayMaxSize))); } global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $comment_id = (isset($_POST['comment_id'])) ? $_POST['comment_id'] : ''; $gallery_limit = $dwt_listing_options['dwt_listing_review_upload_limit']; require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; $actual_size = $display_size = $size_arr = ''; $file_size = $file_extension = $tmp = $file_name = ''; $attachment_id = ''; $uploaded_file_size = $actual_size = $display_size = $size_arr = $allowed_file_types = $uploaded_file_type = ''; $size_arr = explode( '-', $dwt_listing_options['dwt_listing_review_images_size'] ); $display_size = $size_arr[1]; $actual_size = $size_arr[0]; if($_FILES) { $files = $_FILES["review_imgz"]; $gallery_link = array(); $data = array(); if(!empty($files) && count($files) > 0) { foreach ($files['name'] as $key => $value) { if ($files['name'][$key]) { $file = array( 'name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'error' => $files['error'][$key], 'size' => $files['size'][$key] ); $uploaded_file_type = $files['type'][$key]; $uploaded_file_size = $files['size'][$key]; $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/png'); if(!in_array($uploaded_file_type, $allowed_file_types)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Sorry, only JPG, JPEG, and PNG files are allowed.",'dwt-listing-api' ))); } if ($uploaded_file_size > $actual_size){ return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => esc_html__( "Max allowed image size is", 'dwt-listing-api' ) . " " . $display_size)); } $_FILES = array ("review_imgz" => $file); foreach ($_FILES as $file => $array) { //now check comments if(!empty($comment_id)) { //for comment edit if(dwt_listing_text('dwt_listing_review_enable_gallery') == 1) { //check if images already exit $comment_images = get_comment_meta($comment_id, 'review_images_idz', true); if( $comment_images != "" ) { $media = explode( ',', $comment_images ); if( count( $media ) >= $gallery_limit ) { $msg = esc_html__("Sorry you can't upload more than ",'dwt-listing-api'); $images_l = esc_html__(" images ",'dwt-listing-api'); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg . $gallery_limit . $images_l)); } } $attachment_id = media_handle_upload('review_imgz', $comment_id); if ( is_wp_error( $attachment_id ) ) { //return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $attachment_id->get_error_messages())); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => esc_html__("Sorry, this file type is not permitted for security reason. ",'dwt-listing-api'))); } else { $comment_images_up = get_comment_meta($comment_id, 'review_images_idz', true); if( $comment_images_up != "" ) { $comment_images_up = $comment_images_up .',' . $attachment_id; update_comment_meta($comment_id, 'review_images_idz', $comment_images_up); } else { update_comment_meta($comment_id, 'review_images_idz', $attachment_id); } } } } else { $ms2 = __( "Something went wrong! Please try again later", 'dwt-listing-api' ); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $ms2)); } } } } $comment_images_up = get_comment_meta($comment_id, 'review_images_idz', true); if( $comment_images_up != "" ) { $media = explode( ',', $comment_images_up ); foreach( $media as $m ) { if ( isset( $m->ID ) ) { $mid = $m->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $m; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } } } $data['comment_media'] = $gallery_link; return $response = rest_ensure_response(array( 'success' => true, 'data' => $data)); } } } } /*Submited Review Delete */ add_action( 'rest_api_init', 'dwt_listing_profile_reviews_gallery_delete', 0 ); function dwt_listing_profile_reviews_gallery_delete() { register_rest_route( 'downtown/app', '/delete-review-img/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_comments_gallery_delete', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if ( ! function_exists( 'dwt_listing_comments_gallery_delete' ) ) { function dwt_listing_comments_gallery_delete($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $deleted_image_id = (isset($json_data['image_id'])) ? sanitize_text_field($json_data['image_id']) : ''; $comment_id = (isset($json_data['comment_id'])) ? sanitize_text_field($json_data['comment_id']) : ''; $attachmentid = $deleted_image_id; $data = $gallery_link = array(); if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } if($comment_id == '') { $msg = __( "Whoops Comment ID is required", 'dwt-listing-api' ); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg)); } if($deleted_image_id == '') { $msg = __( "Whoops Image ID is required", 'dwt-listing-api' ); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg)); } if ( wp_attachment_is_image($attachmentid ) ) { wp_delete_attachment( $attachmentid, true ); if(get_comment_meta($comment_id, 'review_images_idz', true) != "") { $comment_images_up = get_comment_meta($comment_id, 'review_images_idz', true); $res = str_replace($attachmentid, "", $comment_images_up); $res = str_replace(',,', ",", $res); $img_ids= trim($res,','); update_comment_meta($comment_id, 'review_images_idz', $img_ids); } if(get_comment_meta($comment_id, 'review_images_idz', true) != "") { $comment_images_up = get_comment_meta($comment_id, 'review_images_idz', true); // return remainng images if($comment_images_up !="") { $media = explode( ',', $comment_images_up ); foreach( $media as $m ) { if ( isset( $m->ID ) ) { $mid = $m->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $m; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } } $data['comment_media'] = $gallery_link; return $response = rest_ensure_response(array( 'success' => true, 'data' => $data)); } } else { $data['comment_media'] = []; return $response = rest_ensure_response(array( 'success' => true, 'data' => $data)); } } else { $msg = __( "Selected images is already deleted or not found on server", 'dwt-listing-api' ); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg)); } } } //Fetch more submitted reviews add_action( 'rest_api_init', 'dwt_listing_load_more_my_reviews', 0 ); function dwt_listing_load_more_my_reviews() { register_rest_route( 'downtown/app', '/get-my-reviews/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_my_personal_reviews', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_get_my_personal_reviews')) { function dwt_listing_get_my_personal_reviews($request) { $lists = $data = array(); global $dwt_listing_api; $param = $request->get_json_params(); $next_page = (isset($param['next_page'])) ? trim($param['next_page']) : '1'; $review_type = $param['review_type']; $limit = 10; $user = wp_get_current_user(); $user_id = $user->ID; if(isset($review_type) && $review_type == 'received') { if(isset($dwt_listing_api['app_received_rev_limit'] ) && $dwt_listing_api['app_received_rev_limit'] != "" ) { $limit = $dwt_listing_api['app_received_rev_limit']; } $page = $next_page; $offset = ($page * $limit) - $limit; $param = array('status'=>'approve','post_type' => 'listing', 'post_author__in' => array($user_id), 'orderby' => 'post_date' ,'order' => 'DESC','number'=>$limit, 'offset'=>$offset); $comments = get_comments($param); $has_comments = false; if(count((array) $comments) > 0 ) { $has_reply = ''; $has_comments = true; foreach($comments as $comment) { $reply_comment_id = ''; $replier_msg = ''; $comment_id = $comment->comment_ID; $listing_id = $comment->comment_post_ID; $commenter_dp = dwt_listing_fetch_comment_poster($comment->user_id,'dp'); $rated = get_comment_meta($comment_id, 'review_stars', true); $main_title = get_comment_meta( $comment_id, 'review_main_title', true ); //fetch replies of that post $replies = get_comments( array('parent' => $comment_id, 'status' => 'approve', 'orderby' => 'comment_date' , 'order' => 'DESC')); $has_reply = false; $reply_comment = array(); if(count((array) $replies) > 0) { $has_reply = true; foreach($replies as $reply) { $reply_comment_id = $reply->comment_ID; $replier_msg = dwt_listing_convert_uniText(esc_attr($reply->comment_content)); $reply_comment[] = array("replyer_message" => $replier_msg); } } $statement = __(' posted a review on','dwt-listing-api'); $received_cmntz[] = array( "comment_id" => $comment_id, "listing_id" => $listing_id, "commenter_name" => esc_attr($comment->comment_author), "commenter_dp" => $commenter_dp, "user_id" => $comment->user_id, "listing_title" => dwt_listing_convert_uniText(get_the_title($listing_id)) , "statement" => dwt_listing_convert_uniText($statement), "rating_stars" => $rated, "total_rating" => ($rated.'/'.'5'), "comment_desc" => dwt_listing_convert_uniText(esc_attr($comment->comment_content)), "comment_time" => date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ), "has_reply" => $has_reply, "replyed_comment_id" => $reply_comment_id, "reply_comment" => $reply_comment ); } $data['review_type'] = $review_type; $data['commnets'] = $received_cmntz; //pagination $has_next_page = $lastpage = $next = $total_comments = ''; $total_comments = dwt_listing_received_reviews($user_id); $next = $page + 1; $lastpage = ceil($total_comments/$limit); $has_next_page = ($next <= (int)$lastpage) ? true : false; $data[$review_type.'_pagination'] = array("totalreceived_reviews" => $total_comments, "current_page" => (int)$page, "next_page" => (int)$next, "has_next_page" => $has_next_page ); return $response = array( 'success' => true, 'data' => $data , 'message' => ''); } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("Recent activities about your listings will be here!", "dwt-listing-api") ); return $response; } } if(isset($review_type) && $review_type == 'submitted') { if(isset($dwt_listing_api['app_received_subb_limit'] ) && $dwt_listing_api['app_received_subb_limit'] != "" ) { $limit = $dwt_listing_api['app_received_subb_limit']; } $page_s = $next_page; $offsets = ($page_s * $limit) - $limit; $paramz = array('status'=>'approve','user_id'=>$user_id,'post_type' => 'listing', 'orderby' => 'post_date' ,'order' => 'DESC','number'=>$limit, 'offset'=>$offsets); $commentz = get_comments($paramz); $has_commentz = false; if(count((array) $commentz) > 0 ) { foreach($commentz as $comment) { $has_comments = true; $comment_id = $comment->comment_ID; $listing_id = $comment->comment_post_ID; $commenter_dp = dwt_listing_fetch_comment_poster($comment->user_id,'dp'); $rated = get_comment_meta($comment_id, 'review_stars', true); $main_title = get_comment_meta( $comment_id, 'review_main_title', true ); $main_desc = esc_attr($comment->comment_content); //comments gallery $has_media = false; $gallery_link = array(); if(get_comment_meta($comment_id, 'review_images_idz', true ) !="") { $has_media = true; $comment_images = get_comment_meta($comment_id, 'review_images_idz', true); if($comment_images !="") { $media = explode( ',', $comment_images ); foreach( $media as $m ) { if ( isset( $m->ID ) ) { $mid = $m->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $m; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } } } } $statement = __(' submitted a review on','dwt-listing-api'); $submitted_cmntz[] = array( "comment_id" => $comment_id, "listing_id" => $listing_id, "commenter_name" => dwt_listing_convert_uniText(esc_attr($comment->comment_author)), "commenter_dp" => $commenter_dp, "user_id" => $comment->user_id, "listing_title" => dwt_listing_convert_uniText(get_the_title($listing_id)) , "statement" => $statement, "rating_stars" => $rated, "total_rating" => ($rated.'/'.'5'), "comment_desc" => dwt_listing_convert_uniText(esc_attr($comment->comment_content)), "comment_time" => date_i18n( 'j F, Y', strtotime( get_the_time($comment->comment_date) ) ), "comment_form_title" => $main_title, "comment_form_desc" => dwt_listing_convert_uniText(esc_attr($comment->comment_content)), "has_media" => $has_media, "comment_media" => $gallery_link, ); } $lists['has_comments'] = $has_comments; $lists['review_type'] = $review_type; $lists['commnets'] = $submitted_cmntz; //pagination $has_next_pagez = $lastpage = $next = $total_commentz = ''; $total_commentz = dwt_listing_submitted_reviews($user_id); $next = $page_s + 1; $lastpage = ceil($total_commentz/$limit); $has_next_pagez = ($next <= (int)$lastpage) ? true : false; $lists[$review_type.'_pagination'] = array("totalsubmitted_reviews" => $total_commentz, "current_page" => (int)$page_s, "next_page" => (int)$next, "has_next_page" => $has_next_pagez ); return $response = array( 'success' => true, 'data' => $lists , 'message' => ''); } else { $response = array( 'success' => false, 'data' => '' , 'message' => __("You don't have more reviews!", "dwt-listing-api") ); return $response; } } } } /*Submited Review Images */ add_action( 'rest_api_init', 'dwt_listing_s_reviewzz', 0 ); function dwt_listing_s_reviewzz() { register_rest_route( 'downtown/app', '/list-review-imgz/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_s_images', 'permission_callback' => function () {return dwt_listing_basic_auth(); }, ) ); } if ( ! function_exists( 'dwt_listing_s_images' ) ) { function dwt_listing_s_images($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $gallery_limit = $dwt_listing_options['dwt_listing_review_upload_limit']; if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin($user_id)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } $displayMaxSize = ''; if ( $_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && $_SERVER['CONTENT_LENGTH'] > 0) { $displayMaxSize = ini_get('post_max_size'); switch ( substr($displayMaxSize,-1) ) { case 'G': $displayMaxSize = (int)$displayMaxSize * 1024; case 'M': $displayMaxSize = (int)$displayMaxSize * 1024; case 'K': $displayMaxSize = (int) $displayMaxSize * 1024; } return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => sprintf( __( 'Posted data is too large %s bytes exceeds the maximum size of %d bytes.', 'dwt-listing-api' ), $_SERVER['CONTENT_LENGTH'], $displayMaxSize))); } $listing_id = (isset($_POST['listing_id'])) ? $_POST['listing_id'] : ''; require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; if(!empty($listing_id)) { //owner cant post rating if( get_post_field('post_author', $listing_id) == $user_id) { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => __("Listing author can't post review.", "dwt-listing-api"))); } else { $actual_size = $display_size = $size_arr = ''; $file_size = $file_extension = $tmp = $file_name = ''; $attachment_id = ''; $uploaded_file_size = $actual_size = $display_size = $size_arr = $allowed_file_types = $uploaded_file_type = ''; $size_arr = explode( '-', $dwt_listing_options['dwt_listing_review_images_size'] ); $display_size = $size_arr[1]; $actual_size = $size_arr[0]; if($_FILES) { $files = $_FILES["comment_reviews"]; $gallery_link = array(); $data = array(); if(!empty($files) && count($files) > 0) { foreach($files['name'] as $key => $value) { if ($files['name'][$key]) { $file = array( 'name' => $files['name'][$key], 'type' => $files['type'][$key], 'tmp_name' => $files['tmp_name'][$key], 'error' => $files['error'][$key], 'size' => $files['size'][$key] ); $uploaded_file_type = $files['type'][$key]; $uploaded_file_size = $files['size'][$key]; $allowed_file_types = array('image/jpg', 'image/jpeg', 'image/png'); if(!in_array($uploaded_file_type, $allowed_file_types)) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Sorry, only JPG, JPEG, and PNG files are allowed.",'dwt-listing-api' ))); } if ($uploaded_file_size > $actual_size) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => esc_html__( "Max allowed image size is", 'dwt-listing-api' ) . " " . $display_size)); } $_FILES = array ("comment_reviews" => $file); foreach ($_FILES as $file => $array) { $review_images_count = get_user_meta($user_id, 'reviews_comments_images', true); if( $review_images_count != "" ) { $media = explode( ',', $review_images_count ); if( count($media ) >= $gallery_limit ) { $msg = esc_html__("Sorry you can't upload more than ",'dwt-listing-api'); $images_l = esc_html__(" images ",'dwt-listing-api'); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg . $gallery_limit . $images_l)); } } $attachment_id = media_handle_upload('comment_reviews',$user_id); if ( is_wp_error( $attachment_id ) ) { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => esc_html__("Sorry, this file type is not permitted for security reason. ",'dwt-listing-api'))); } else { $review_images = get_user_meta($user_id, 'reviews_comments_images', true); if( $review_images != "" ) { $review_images = $review_images .',' . $attachment_id; update_user_meta($user_id, 'reviews_comments_images', $review_images ); } else { update_user_meta($user_id, 'reviews_comments_images', $attachment_id ); } } } } } $comment_images_up = get_user_meta($user_id, 'reviews_comments_images', true); if( $comment_images_up != "" ) { $media = explode( ',', $comment_images_up ); foreach( $media as $m ) { if ( isset( $m->ID ) ) { $mid = $m->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $m; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } } } $data['comment_media'] = $gallery_link; return rest_ensure_response(array( 'success' => true, 'data' => $data)); } } else { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => __("No file selected.", "dwt-listing-api"))); } } } else { return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => __("Listing Id is required.", "dwt-listing-api"))); } } } /*Submited Review Delete */ add_action( 'rest_api_init', 'dwt_listing_detail_gallery_delete', 0 ); function dwt_listing_detail_gallery_delete() { register_rest_route( 'downtown/app', '/del-rev-img/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_detail_gallery_delete_single', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if ( ! function_exists( 'dwt_listing_detail_gallery_delete_single' ) ) { function dwt_listing_detail_gallery_delete_single($request) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->ID; $json_data = $request->get_json_params(); $deleted_image_id = (isset($json_data['image_id'])) ? sanitize_text_field($json_data['image_id']) : ''; $attachmentid = $deleted_image_id; $data = $gallery_link = array(); if( dwt_listing_text('dwt_listing_disable_edit') == '1' && !is_super_admin( get_current_user_id())) { return rest_ensure_response(array( 'success' => false, 'data' => '', 'message' => __( "Disable for Demo.", 'dwt-listing-api'))); } if($deleted_image_id == '') { $msg = __( "Whoops Image ID is required", 'dwt-listing-api' ); return rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg)); } if ( wp_attachment_is_image($attachmentid ) ) { wp_delete_attachment( $attachmentid, true ); if(get_user_meta($user_id, 'reviews_comments_images', true) != "" ) { $ids = get_user_meta($user_id, 'reviews_comments_images', true); $res = str_replace($attachmentid, "", $ids); $res = str_replace(',,', ",", $res); $img_ids= trim($res,','); update_user_meta( $user_id, 'reviews_comments_images', $img_ids ); } if(get_user_meta($user_id, 'reviews_comments_images', true) != "") { $comment_images_up = get_user_meta($user_id, 'reviews_comments_images', true); // return remainng images if($comment_images_up !="") { $gallery_link = array(); $media = explode( ',', $comment_images_up ); foreach( $media as $m ) { if ( isset( $m->ID ) ) { $mid = $m->ID; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } else { $mid = $m; $source = wp_get_attachment_image_src( $mid, 'dwt_listing_user-dp'); $gallery_link[] = array("urlz" => $source[0], "image_id" => $mid); } } $data['comment_media'] = $gallery_link; return $response = rest_ensure_response(array( 'success' => true, 'data' => $data)); } else { $data['comment_media'] = []; return $response = rest_ensure_response(array( 'success' => true, 'data' => $data)); } } else { $data['comment_media'] = []; return $response = rest_ensure_response(array( 'success' => true, 'data' => $data)); } } else { $msg = __( "Selected images is already deleted or not found on server", 'dwt-listing-api' ); return $response = rest_ensure_response(array( 'success' => false, 'data' => '' , 'message' => $msg)); } } }
[+]
..
[-] events.php
[edit]
[-] author-listings.php
[edit]
[-] fetch_data.php
[edit]
[-] forget.php
[edit]
[-] categories.php
[edit]
[-] listing-detail.php
[edit]
[-] packages.php
[edit]
[-] home.php
[edit]
[+]
packages
[-] reviews.php
[edit]
[+]
submit-listing
[-] profile.php
[edit]
[-] register.php
[edit]
[-] settings.php
[edit]
[-] events-search.php
[edit]
[-] listing-search.php
[edit]
[+]
profile
[-] event-detail.php
[edit]
[-] login.php
[edit]
[+]
payments
[-] blog.php
[edit]