示例#1
0
/**
 * Get post points form the post custom field 'google-map-sc'
 */
function gmshc_get_points($post_id)
{
    // check for old custom google-map-sc
    $post_data = get_post_meta($post_id, 'google-map-sc', true);
    $post_points = array();
    if ($post_data != "") {
        $points = json_decode(urldecode($post_data), true);
        if (is_array($points)) {
            foreach ($points as $point) {
                $point_obj = new GMSHC_Point();
                if ($point_obj->create_point("", $point['address'], $point['ltlg'], $point['title'], $point['description'], $point['icon'], $point['thumbnail'], $post_id)) {
                    gmshc_insert_db_point($point_obj);
                }
            }
        }
    }
    /**  checking for old custom fields google-map-sc-address **/
    $post_data_address = get_post_meta($post_id, 'google-map-sc-address');
    $options = get_gmshc_options();
    $default_icon = $options['default_icon'];
    $post_title = get_the_title($post_id);
    if (count($post_data_address) > 0) {
        foreach ($post_data_address as $point_address) {
            $point_obj_address = new GMSHC_Point();
            if ($point_obj_address->create_point("", gmshc_clean_string($point_address), "", $post_title, "", $default_icon, "", $post_id, true)) {
                gmshc_insert_db_point($point_obj_address);
            }
        }
    }
    /**  checking for old custom fields google-map-sc-latlng **/
    $post_data_ltlg = get_post_meta($post_id, 'google-map-sc-latlng');
    if (count($post_data_ltlg) > 0) {
        foreach ($post_data_ltlg as $point_ltlg) {
            $point_obj_ltlg = new GMSHC_Point();
            if ($point_obj_ltlg->create_point("", "", $point_ltlg, $post_title, "", $default_icon, "", $post_id)) {
                gmshc_insert_db_point($point_obj_ltlg);
            }
        }
    }
    $db_points = gmshc_get_bd_points($post_id);
    if (count($db_points) > 0) {
        foreach ($db_points as $point) {
            $point_obj = new GMSHC_Point();
            if ($point_obj->create_point($point['id'], $point['address'], $point['ltlg'], $point['title'], $point['description'], $point['icon'], $point['thumbnail'], $post_id)) {
                array_push($post_points, $point_obj);
            }
        }
    }
    return $post_points;
}
 function add_point($point)
 {
     return gmshc_insert_db_point($point);
 }