GeoMashup
[ class tree: GeoMashup ] [ index: GeoMashup ] [ all elements ]

Source for file geo-query.php

Documentation is available at geo-query.php

  1. <?php
  2. /**
  3.  * Respond to Geo Mashup AJAX requests for object locations.
  4.  *
  5.  * @since 1.0
  6.  * @package GeoMashup
  7.  */
  8.  
  9. if ( ( isset$_GET['output'and 'json' == $_GET['output'or empty$_GET['object_ids') ) {
  10. else {
  11. }
  12.  
  13. /**
  14.  * Class for query handling namespace
  15.  *
  16.  * @since 1.2
  17.  * @package GeoMashup
  18.  * @access public
  19.  * @static
  20.  */
  21. class GeoMashupQuery {
  22.  
  23.     /**
  24.      * Strip content in square brackets.
  25.      *
  26.      * Shortcodes are not registered in the bare-bones query environments,
  27.      * but we can strip all bracketed content.
  28.      *
  29.      * @since 1.3
  30.      *
  31.      * @param string $content Content to strip square brackets from
  32.      * @return string Content minus square brackets
  33.      */
  34.     public static function strip_brackets$content {
  35.         return preg_replace'/\[.*?\]/'''$content );
  36.     }
  37.  
  38.     /**
  39.      * Strip map shortcodes.
  40.      * 
  41.      * @since 1.3
  42.      *
  43.      * @param string $content 
  44.      * @return string Content without map shortcodes.
  45.      */
  46.     public static function strip_map_shortcodes$content {
  47.         return preg_replace'/\[geo_mashup_map.*?\]/'''$content );
  48.     }
  49.  
  50.     /**
  51.      * Use templates to output content for objects.
  52.      * 
  53.      * @since 1.3
  54.      */
  55.     public static function generate_object_html{
  56.         global $geo_mashup_options$geo_mashup_custom$comments$users;
  57.  
  58.         $object_ids $_GET['object_ids'];
  59.         if !is_array$object_ids ) ) {
  60.             $object_ids split','$object_ids );
  61.         }
  62.         $object_name isset$_GET['object_name') ) $_GET['object_name''post';
  63.         $template_base isset$_GET['template') ) $_GET['template''';
  64.  
  65.         switch $object_name {
  66.             case 'post':
  67.                 $query_vars array'post__in' => $object_ids'post_type' => 'any''post_status' => 'publish,future' );
  68.                 // Don't filter this query through other plugins (e.g. event-calendar)
  69.                 $query_vars['suppress_filters'true;
  70.                 // No sticky posts please
  71.                 if function_exists'get_queried_object' ) )
  72.                     $query_vars['ignore_sticky_posts'true;
  73.                 else
  74.                     $query_vars['caller_get_posts'true// Necessary only for WP 3.0 support
  75.                 // Don't limit the number of results
  76.                 $query_vars['posts_per_page'= -1;
  77.  
  78.                 query_posts$query_vars );
  79.                 
  80.                 if have_posts() ) {
  81.                     status_header(200);
  82.                 }
  83.                 $template_base empty$template_base ) ) 'info-window' $template_base;
  84.                 break;
  85.  
  86.             case 'comment':
  87.                 $comments GeoMashupDB::get_comment_inarray'comment__in' => $object_ids ) );
  88.                 if !empty$comments ) ) {
  89.                     status_header(200);
  90.                 }
  91.                 $template_base empty$template_base ) ) 'comment' $template_base;
  92.                 break;
  93.  
  94.             case 'user':
  95.                 $users GeoMashupDB::get_user_inarray'user__in' => $object_ids ) );
  96.                 if (!empty$users ) ) {
  97.                     status_header(200);
  98.                 }
  99.                 $template_base empty$template_base ) ) 'user' $template_base;
  100.                 break;
  101.         }
  102.  
  103.         load_templateGeoMashup::locate_template$template_base ) );
  104.     }
  105.  
  106.     /** 
  107.      * Set the comment global.
  108.      *
  109.      * Not sure why WP 2.7 comment templating requires this for callbacks, but it does.
  110.      *
  111.      * @since 1.3
  112.      *
  113.      * @param object $comment The comment object to make global.
  114.      */
  115.     public static function set_the_comment$comment {
  116.         $GLOBALS['comment'$comment;
  117.     }
  118.  
  119.     /** 
  120.      * Wrap access to comments global.
  121.      *
  122.      * @since 1.3
  123.      *
  124.      * @return bool Whether there are any comments to be listed.
  125.      */
  126.     public static function have_comments{
  127.         global $comments;
  128.  
  129.         return !empty$comments ) );
  130.     }
  131.  
  132.     /**
  133.      * A wrapper for wp_list_comments when it exists,
  134.      * otherwise a simple comment loop.
  135.      *
  136.      * @since 1.3
  137.      * @see wp_list_comments()
  138.      *
  139.      * @param string|array$args Formatting options
  140.      */
  141.     public static function list_comments$args '' {
  142.         global $wp_query$comments$in_comment_loop;
  143.  
  144.         if function_exists'wp_list_comments' ) ) {
  145.             wp_list_comments$args$comments );
  146.         else {
  147.             if empty$comments ) ) {
  148.                 return;
  149.             }
  150.             $args wp_parse_args$args );
  151.             $in_comment_loop true;
  152.             foreach$comments as $comment{
  153.                 if !empty$args['callback') ) {
  154.                     call_user_func$args['callback']$comment$args);
  155.                 else {
  156.                     echo '<p>' esc_html$comment->comment_author ':<br/>' esc_html$comment->comment_content '</p>';
  157.                 }
  158.             }
  159.             $in_comment_loop false;
  160.         }
  161.     }
  162.  
  163.     /** 
  164.      * Set the user global.
  165.      *
  166.      * Probably only Geo Mashup using it here for a templated list of users.
  167.      *
  168.      * @since 1.3
  169.      *
  170.      * @param object $user The user object to make global.
  171.      */
  172.     public static function set_the_user$user {
  173.         $GLOBALS['user'$user;
  174.     }
  175.  
  176.     /** 
  177.      * Wrap access to users global.
  178.      *
  179.      * Probably only Geo Mashup using it here for a templated list of users.
  180.      *
  181.      * @since 1.3
  182.      *
  183.      * @returns bool Whether there are any users to be listed.
  184.      */
  185.     public static function have_users{
  186.         global $users;
  187.  
  188.         return !empty$users ) );
  189.     }
  190.  
  191.     /**
  192.      * A simple user loop that takes a callback option for formatting.
  193.      *
  194.      * @since 1.3
  195.      *
  196.      * @param string|array$args Formatting options
  197.      */
  198.     public static function list_users$args '' {
  199.         global $wp_query$users$in_user_loop;
  200.  
  201.         if empty$users ) ) {
  202.             return;
  203.         }
  204.         $defaults array'callback' => '' );
  205.         $args wp_parse_args$args$defaults );
  206.         $in_user_loop true;
  207.         foreach$users as $user{
  208.             if !empty$args['callback') ) {
  209.                 call_user_func$args['callback']$user$args );
  210.             else {
  211.                 echo '<p>' esc_html$user->display_name .
  212.                     empty$user->user_url '' ' - ' $user->url '</p>';
  213.             }
  214.         }
  215.         $in_user_loop false;
  216.     }
  217.  
  218.  
  219.     /**
  220.      * Run a query for object locations from GET parameters and print JSON results.
  221.      * 
  222.      * @since 1.2
  223.      */
  224.     public static function generate_location_json{
  225.         /* TODO: Try to track modification?
  226.         if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
  227.             $http_time = strtotime( $_SERVER['HTTP_IF_MODIFIED_SINCE'] );
  228.             $mod_time = strtotime( $post->post_modified_gmt . ' GMT' );
  229.             if ($mod_time <= $http_time) {
  230.                 return status_header(304); // Not modified
  231.             }
  232.         }
  233.  
  234.         status_header(200);
  235.         header( 'Last-Modified: ' . mysql2date( 'D, d M Y H:i:s', $post->post_modified_gmt, false ) . ' GMT' );
  236.         header( 'Content-type: text/xml; charset='.get_settings('blog_charset'), true);
  237.         header( 'Cache-control: max-age=300, must-revalidate', true);
  238.         header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', time() + 300 ) . " GMT" );
  239.         header( 'Pragma:' );
  240.          */
  241.         status_header(200);
  242.         header('Content-type: application/json; charset='.get_option('blog_charset')true);
  243.         header('Cache-Control: no-cache;'true);
  244.         header('Expires: -1;'true);
  245.  
  246.         $json GeoMashup::get_locations_json($_REQUEST);
  247.         if isset$_REQUEST['callback') )
  248.             $json $_REQUEST['callback''(' $json ')';
  249.         echo $json;
  250.     }
  251. }

Documentation generated on Sat, 09 Jul 2011 21:54:54 -0700 by phpDocumentor 1.4.3