PATH:
home
/
letacommog
/
laindinois
/
OLD
/
wp-content
/
plugins
/
dwt-listing-rest-api
/
classes
<?php add_action( 'rest_api_init', 'dwt_listing_blogs_app', 0 ); function dwt_listing_blogs_app() { register_rest_route( 'downtown/app', '/blog/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_blogs', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_get_blogs')) { function dwt_listing_get_blogs($request) { global $dwt_listing_api; $has_next_page = $lastpage = $next_page = $img_array = ''; $data = $all_posts = array(); $params = $request->get_json_params(); $limit = 10; if(isset($dwt_listing_api['app_listing_blog_limit']) && $dwt_listing_api['app_listing_blog_limit'] !="") { $limit = $dwt_listing_api['app_listing_blog_limit']; } $current_page = 1; if(!empty($params['next_page'])) { $current_page = $params['next_page']; } //Get Blogs $args = array ( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $limit, 'order'=> 'DESC', 'orderby' => 'date', 'paged' => $current_page, ); $my_blogs = new WP_Query($args); if ($my_blogs->have_posts()) { $data['total_articles'] = $my_blogs->found_posts . esc_html__(" Result Found", "dwt-listing-api"); while($my_blogs->have_posts()) { $my_blogs->the_post(); $blog_id = get_the_ID(); $img_url = esc_url('https://www.acendas.com/wp-content/uploads/2015/01/200x200-white-placeholder.png'); if ( has_post_thumbnail() ) { $img_array = dwt_listing_get_feature_image($blog_id, 'dwt_listing_blogpost-thumb'); $img_url = esc_url($img_array[0]); } $final_title = $limited_title = ''; global $dwt_listing_api; if(isset($dwt_listing_api['app_title_limit']) && $dwt_listing_api['app_title_limit'] !="") { $limited_title = dwt_listing_words_count(get_the_title($blog_id), $dwt_listing_api['app_title_limit']); $final_title = stripslashes_deep(wp_strip_all_tags(str_replace("|"," ",$limited_title))); } else { $final_title = get_the_title($blog_id); } $all_posts[] = array( 'blog_id' => $blog_id, 'blog_title' => dwt_listing_convert_uniText($final_title), 'blog_img' => $img_url, 'short_desc' => dwt_listing_convert_uniText(dwt_listing_words_count(get_the_excerpt(), 90)), 'posted_date' =>human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . esc_html__(" ago", "dwt-listing-api"), 'more_btn' => esc_html__("Read More", "dwt-listing-api"), ); } $data['blogs'] = $all_posts; wp_reset_postdata(); //pagination $next_page = $current_page + 1; $lastpage = ceil($my_blogs->found_posts/$limit); $has_next_page = ($next_page <= (int)$lastpage) ? true : false; $data['pagination'] = array("total_blogs" => $my_blogs->found_posts, "current_page" => (int)$current_page, "next_page" => (int)$next_page, "has_next_page" => $has_next_page ); return $response = array( 'success' => true, 'data' => $data, 'message' => ''); } else { $msg = esc_html__("No result found.", "dwt-listing-api"); return $response = array( 'success' => false, 'data' => '', 'message' => $msg ); } } } add_action( 'rest_api_init', 'dwt_listing_blog_detail', 0 ); function dwt_listing_blog_detail() { register_rest_route( 'downtown/app', '/blog-detail/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_get_b_detail', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_get_b_detail')) { function dwt_listing_get_b_detail($request) { global $dwt_listing_api; $data = array(); $data['screen_txt'] = esc_html__("Blog Detial", "dwt-listing-api"); $params = $request->get_json_params(); if(!empty($params['blog_id'])) { $no_comments = ''; $blog_id = $params['blog_id']; $blog_detial = get_post($blog_id); //$post_author_id = $blog_detial->post_author; $img_url = esc_url('https://www.acendas.com/wp-content/uploads/2015/01/200x200-white-placeholder.png'); if ( has_post_thumbnail() ) { $img_array = dwt_listing_get_feature_image($blog_id, 'dwt_listing_blogpost-thumb'); $img_url = esc_url($img_array[0]); } //comments $comments = wp_count_comments( $blog_id ); $comments_status = false; $status_msg = esc_html__("Comment are closed.", "dwt-listing-api"); if($blog_detial->comment_status == "open") { $comments_status = true; $status_msg = ''; } $has_comments = false; if($comments->approved > 0) { $has_comments = true; } else { $no_comments = esc_html__("No Comment Found.", "dwt-listing-api"); } $page_num = (isset( $params['next_page'] ) && $params['next_page'] != "" ) ? $params['next_page'] : 1; $logged_in = false; $logged_in_msg = esc_html__("You must be logged in to post a comment.", "dwt-listing-api"); if (is_user_logged_in()) { $logged_in = true; } //array dwt_listing_youtube_url_to_iframe(); $author_id = $blog_detial->post_author; $data['blog_id'] = $blog_id; $data['blog_title'] = get_the_title($blog_id); $data['blog_img'] = $img_url; $data['desc'] = $blog_detial->post_content; $data['read_more'] = esc_html__("Read More", "dwt-listing-api"); $data['blog_author_id'] = $author_id; $data['blog_author_name'] = get_the_author_meta( 'display_name', $author_id) ; $data['posted_date'] = human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . esc_html__(" ago", "dwt-listing-api"); $data['comment_status'] = $comments_status; $data['status_msg'] = $status_msg; $data['total_comments'] = sprintf( esc_html__( '%s Comments', 'dwt-listing-api' ), $comments->approved ); $data['has_comments'] = $has_comments; $data['no_comments'] = $no_comments; $data['is_user_logged_in'] = $logged_in; $data['not_logged_in_msg'] = $logged_in_msg; $data['comments'] = dwt_listing_fetch_comments_app( $blog_id,'',$page_num ); $data['comment_form']['heading'] = esc_html__("leave your comment", "dwt-listing-api" ); $data['comment_form']['textarea'] = esc_html__("Your comment here", "dwt-listing-api" ); $data['comment_form']['btn_submit'] = esc_html__("Post Comment", "dwt-listing-api" ); return $response = array( 'success' => true, 'data' => $data, 'message' => $msg ); } else { $msg = esc_html__("No result found.", "dwt-listing-api"); return $response = array( 'success' => false, 'data' => '', 'message' => $msg ); } } } // Listing Reviews Reactions add_action( 'rest_api_init', 'dwt_listing_post_comments', 0 ); function dwt_listing_post_comments() { register_rest_route( 'downtown/app', '/blog-comments/', array( 'methods' => WP_REST_Server::EDITABLE, 'callback' => 'dwt_listing_post_signle_comment', 'permission_callback' => function () { return dwt_listing_basic_auth(); }, ) ); } if (!function_exists('dwt_listing_post_signle_comment')) { function dwt_listing_post_signle_comment($request) { $message_s = $message = $msg = $blog_id = ''; $param = $request->get_json_params(); if ( !is_user_logged_in() ) { return $response = array( 'success' => false, 'data' => '', 'message' => __("You need to logged in", "dwt-listing-api") ); } if(!empty($param['blog_id'])) { if(isset($param['message_content']) && $param['message_content'] !="") { $blog_id = $param['blog_id']; $message = $param['message_content']; $user = wp_get_current_user(); $user_id = $user->data->ID; $display_name = $user->data->display_name; $user_email = $user->data->user_email; // save comment now $save_comments = array( 'comment_post_ID' => $blog_id, 'comment_author' => $display_name, 'comment_author_email' => $user_email, 'comment_content' => $message, 'comment_author_url' => $user->user_url, 'comment_type' => 'comments', 'comment_parent' => '0', 'user_id' => $user_id, ); /*Insert new comment and get the comment ID*/ $comment_id = wp_new_comment($save_comments); if($comment_id) { $data['comments'] = dwt_listing_latest_comment($blog_id); $status = wp_get_comment_status( $comment_id ); if ($status == "approved") { $message_s = __("Comment Posted Successfully.", "dwt-listing-api"); } else { $message_s = __("Waiting for admin approval." , "dwt-listing-api"); } } // Get the new response code //var_dump(http_response_code()); return $response = array( 'success' => true, 'data' => $data, 'message' => $message_s ); } else { $msg = esc_html__("Please type a comment.", "dwt-listing-api"); return $response = array( 'success' => false, 'data' => '', 'message' => $msg ); } } else { $msg = esc_html__("Blog ID is required to post comments.", "dwt-listing-api"); return $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]