PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
downtown-rest-api
/
classes
<?php /*Downtown Get Reviews Data */ 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(); }, ) ); } if (!function_exists('dwt_listing_get_my_reviews')) { function dwt_listing_get_my_reviews() { global $dwt_listing_api; $user = wp_get_current_user(); $user_id = $user->ID; //get listings that having comments //received reviews $user_comments['received_reviews'] = dwt_listing_fetch_my_reviewz($user_id); $review_array['reviews_types'] = $user_comments; $review_array['profile_data'] = dwt_listing_basic_profile_data(); $extra_arr['screen_txt'] = __(" Received Reviews", "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"); $response = array( 'success' => true, 'data' => $review_array, "message" => "" , "extra_text" => $extra_arr); 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', '/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->data->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['comments_review_reply'])) ? sanitize_text_field($json_data['comments_review_reply']) : ''; $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 !="") { //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_ID'] = $reply_review_id; $commentarr['comment_approved'] = 1; $commentarr['comment_content'] = $review_msg_reply; wp_update_comment( $commentarr ); return array( 'success' => true, 'data' => '', 'message' => __( "Reply Updated Successfully.", 'dwt-listing-api' )); } else { $time = current_time('mysql'); $data = array( '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-framework'); $body = '<html><body><p>'.__('You received a new reply, please check it. ','dwt-listing-framework').'<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 array( 'success' => true, 'data' => '', 'message' => __( "Reply Posted Successfully.", 'dwt-listing-api' )); } else { return array( 'success' => false, 'data' => '', 'message' => __( "Reply not sent, please try again later.", 'dwt-listing-api' )); } } } else { return array( 'success' => false, 'data' => '', 'message' => __( "user don't exisits.", 'dwt-listing-api' )); } } } } add_action( 'rest_api_init', 'dwt_listing_profile_submitted_reviews_api_hooks_get', 0 ); function dwt_listing_profile_submitted_reviews_api_hooks_get() { register_rest_route( 'downtown/app', '/submitted-reviews/', array( 'methods' => WP_REST_Server::READABLE, 'callback' => 'dwt_listing_get_my_submitted_reviews', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_get_my_submitted_reviews')) { function dwt_listing_get_my_submitted_reviews() { global $dwt_listing_api; $user = wp_get_current_user(); $user_id = $user->ID; //received reviews $user_comments['submitted_reviews'] = dwt_listing_fetch_my_submitted_reviewz($user_id); $review_array['reviews_types'] = $user_comments; //enbaled options $starz_enabled = false; $gallery_enabled = false; if( dwt_listing_text('dwt_listing_review_enable_stars') == 1) { $starz_enabled = true; } if( dwt_listing_text('dwt_listing_review_enable_gallery') == '1') { $gallery_enabled = true; } $gallery_limit = dwt_listing_text('dwt_listing_review_upload_limit'); $max_up_size = dwt_listing_text('dwt_listing_review_images_size'); $enabled_options['is_rating_stars'] = $starz_enabled; $enabled_options['is_rating_gallery'] = $gallery_enabled; $enabled_options['gallery_limit'] = (int)$gallery_limit; $enabled_options['max_up_size'] = $max_up_size; $extra_arr = ''; $response = array( 'success' => true, 'data' => $review_array, "global_options" => $enabled_options , "extra_text" => $extra_arr, "message" => "", ); return $response; } } /*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->data->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']) : ''; //update comment $my_comment_id = $comment_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 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) { global $dwt_listing_options; $user = wp_get_current_user(); $user_id = $user->data->ID; $gallery_limit_val = (isset($_POST['gallery_limit'])) ? sanitize_text_field($_POST['gallery_limit']) : ''; $imgz_size = (isset($_POST['max_up_size'])) ? $_POST['max_up_size'] : ''; $comment_id = (isset($_POST['comment_id'])) ? $_POST['comment_id'] : ''; $gallery_limit = $gallery_limit_val; require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; // check size of uploaded images $size_arr = explode( '-', $imgz_size); $display_size = $size_arr[1]; $actual_size = $size_arr[0]; // Allow certain file formats $file_size = $file_extension = $tmp = $file_name = ''; $attachment_id = ''; 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] ); $_FILES = array ("review_imgz" => $file); foreach ($_FILES as $file => $array) { //size if ($array['size'] > $actual_size) { $ms1 = __( "Max allowed image size is", 'dwt-listing' ) . " " . $display_size; return $response = array( 'success' => false, 'data' => '' , 'message' => $ms1); } //file extension $file_name = $array['name']; $tmp = explode('.', $file_name); $file_extension = strtolower(end($tmp)); if($file_extension != "jpg" && $file_extension != "png" && $file_extension != "jpeg" && $file_extension != "gif" ) { $ms = __( "Sorry, only JPG, JPEG, PNG & GIF files are allowed.", 'dwt-listing' ); return $response = array( 'success' => false, 'data' => '' , 'message' => $ms); } //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'); $images_l = esc_html__(" images ",'dwt-listing'); return $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 = array( 'success' => false, 'data' => '' , 'message' => $attachment_id->get_error_messages()); } 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); } /*$gallery_link = array(); 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); } } }*/ //$source = wp_get_attachment_image_src($attachment_id, 'dwt_listing_user-dp'); //$gallery_link[] = $source[0]; //$gallery_link[] = array("urlz" => $source[0], "image_id" => $attachment_id); } } } else { $ms2 = __( "Something went wrong! Please try again later", 'dwt-listing' ); return $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['urlz'] = $gallery_link; return $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', '/gallery-delete/', 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->data->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($comment_id == '') { $msg = __( "Whoops Comment ID is required", 'dwt-listing' ); return $response = array( 'success' => false, 'data' => '' , 'message' => $msg); } if($deleted_image_id == '') { $msg = __( "Whoops Image ID is required", 'dwt-listing' ); return $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 = array( 'success' => true, 'data' => $data); } } else { $data['comment_media'] =[]; return $response = array( 'success' => true, 'data' => $data); } } else { $msg = __( "Selected images is already deleted or not found on server", 'dwt-listing' ); return $response = array( 'success' => false, 'data' => '' , 'message' => $msg); } } }
[+]
..
[-] profile.php
[edit]
[-] listing-search.php
[edit]
[-] register.php
[edit]
[-] blog.php
[edit]
[-] reviews.php
[edit]
[-] login.php
[edit]
[+]
payments
[-] event-detail.php
[edit]
[-] author-listings.php
[edit]
[-] packages.php
[edit]
[-] categories.php
[edit]
[+]
packages
[-] events-search.php
[edit]
[-] fetch_data.php
[edit]
[-] home.php
[edit]
[-] listing-detail.php
[edit]
[+]
submit-listing
[+]
profile
[-] forget.php
[edit]
[-] settings.php
[edit]
[-] events.php
[edit]