/**
  * Replace each [codepeople-post-map] shortcode by the map
  */
 function replace_shortcode($atts)
 {
     global $post, $id, $cpm_objs, $cpm_in_loop;
     // Load the plugin resources
     $this->load_resources();
     $cpm_obj = new CPM();
     $cpm_objs[] = $cpm_obj;
     if (is_array($atts)) {
         $cpm_obj->extended = $atts;
     }
     if (!empty($atts['defaultpost'])) {
         $cpm_obj->defaultpost = str_replace(' ', '', $atts['defaultpost']);
     }
     if (isset($id) && (is_singular() || !empty($cpm_in_loop))) {
         $cpm_map = get_post_meta($id, 'cpm_map', TRUE);
     }
     if (empty($cpm_map)) {
         $cpm_map = $cpm_obj->get_configuration_option();
     }
     if (!empty($cpm_map['points'])) {
         $cpm_obj->limit = $cpm_map['points'];
     }
     if (!empty($atts['points'])) {
         $atts['points'] = trim($atts['points']);
         if (is_numeric($atts['points']) && $atts['points'] > 0) {
             $cpm_obj->limit = $atts['points'];
         }
     }
     if (isset($id) && (is_singular() || !empty($cpm_in_loop))) {
         // For maps in a post or page
         // Set the actual post only to avoid duplicates
         $posts = array($id);
         $query_arg = array('meta_key' => 'cpm_point', 'post_status' => 'publish', 'orderby' => 'post_date', 'order' => 'DESC', 'cache_results' => false, 'fields' => 'ids', 'post__not_in' => array($id));
         if (!empty($cpm_obj->limit)) {
             $query_arg['numberposts'] = $cpm_obj->limit - 1;
         }
         // Get POSTs in the same category
         $categories = get_the_category();
         $categories_ids = array();
         foreach ($categories as $category) {
             array_push($categories_ids, $category->term_id);
         }
         if (!empty($categories_ids)) {
             $query_arg['category'] = implode(',', $categories_ids);
         }
         $posts = array_merge($posts, get_posts($query_arg));
         foreach ($posts as $_post) {
             $cpm_obj->populate_points($_post, true);
         }
     } else {
         $cpm_obj->multiple = true;
     }
     $output = $cpm_obj->_set_map_tag($cpm_map);
     $output .= $cpm_obj->_set_map_config($cpm_map);
     $output .= "<noscript>\r\n                        codepeople-post-map require JavaScript\r\n                    </noscript>\r\n                    ";
     if (!empty($atts['print'])) {
         print $output;
         $cpm_obj->print_points();
         return '';
     }
     return $output;
 }
 function codepeople_post_map_regiter()
 {
     $cpm_master_obj = new CPM();
     $cpm_master_obj->set_default_configuration(true);
 }