Пример #1
0
 /**
  * Get a list of maps attached to the post
  *
  * @param int $postid Post for which to get the list
  * @return an array of all maps for the post or FALSE if no maps
  */
 static function get_post_map_list($postid)
 {
     global $wpdb;
     $posts_table = $wpdb->prefix . 'mappress_posts';
     $results = $wpdb->get_results($wpdb->prepare("SELECT postid, mapid FROM {$posts_table} WHERE postid = %d", $postid));
     if ($results === false) {
         return false;
     }
     // Get all of the maps
     $maps = array();
     foreach ($results as $key => $result) {
         $map = Mappress_Map::get($result->mapid);
         if ($map) {
             $maps[] = $map;
         }
     }
     return $maps;
 }
Пример #2
0
 /**
  * Map a shortcode in a post.
  *
  * @param mixed $atts - shortcode attributes
  */
 function shortcode_map($atts = '')
 {
     global $post;
     // No feeds
     if (is_feed()) {
         return;
     }
     // Try to protect against calls to do_shortcode() in the post editor...
     if (is_admin()) {
         return;
     }
     $atts = $this->scrub_atts($atts);
     // Determine what to show
     $mapid = isset($atts['mapid']) ? $atts['mapid'] : null;
     if ($mapid) {
         // Show map by mapid
         $map = Mappress_Map::get($mapid);
     } else {
         // Get the first map attached to the post
         $maps = Mappress_Map::get_post_map_list($post->ID);
         $map = isset($maps[0]) ? $maps[0] : false;
     }
     if (!$map) {
         return;
     }
     return $map->display($atts);
 }