Example #1
0
function decode_file($filename)
{
    if (file_exists($filename)) {
        return jsonp_decode(file_get_contents($filename));
    } else {
        throw new Exception("File " . htmlspecialchars($filename) . " not found");
    }
}
Example #2
0
function decode_file($filename)
{
    if (file_exists($filename)) {
        return jsonp_decode(file_get_contents($filename));
    } else {
        throw new Exception("File {$filename} not found");
    }
}
Example #3
0
}
function jsonp_decode($jsonp, $assoc = false)
{
    // PHP 5.3 adds depth as third parameter to json_decode
    if ($jsonp[0] !== '[' && $jsonp[0] !== '{') {
        // we have JSONP
        $jsonp = substr($jsonp, strpos($jsonp, '('));
    }
    return json_decode(trim($jsonp, '();'), $assoc);
}
if ($_POST['form'] == 'volunteers') {
    $json = file_get_contents('https://docs.google.com/spreadsheets/d/SHEET-TOKEN-GOES-HERE/gviz/tq?tq=' . $query . '&tqx=responseHandler:a');
} elseif ($_POST['form'] == 'venues') {
    $json = file_get_contents('https://docs.google.com/spreadsheets/d/SHEET-TOKEN-GOES-HERE/gviz/tq?tq=' . $query . '&tqx=responseHandler:a');
}
$array = jsonp_decode($json, true);
$api_email_address = $array['table']['rows']['0']['c']['3']['v'];
$api_name = $array['table']['rows']['0']['c']['1']['v'] . " " . $array['table']['rows']['0']['c']['2']['v'];
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
//$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();
// Set mailer to use SMTP
$mail->Host = 'SMTP-SERVER-GOES-HERE';
// Specify main and backup SMTP servers
$mail->SMTPAuth = true;
// Enable SMTP authentication
$mail->Username = '******';
// SMTP username
$mail->Password = '******';
// SMTP password
Example #4
0
 function cgmp_export_to_api($shortcodes = array(), $api_key, $sig, $expires)
 {
     if (!empty($shortcodes)) {
         global $current_user;
         get_currentuserinfo();
         $results = array();
         $layers = array();
         $markers = array();
         $layer_count = 0;
         $marker_count = 0;
         $results_count = 0;
         $mashup_maps = array();
         foreach ($shortcodes as $shortcode) {
             $results_count++;
             $mark = array();
             $markerlist = explode('|', $shortcode['attributes']['addmarkerlist']);
             $addmarkerlist = is_array($markerlist) && !empty($markerlist) ? $markerlist : array($shortcode['attributes']['addmarkerlist']);
             // Calculate the boundbox
             if (is_array($addmarkerlist) && !empty($addmarkerlist)) {
                 $lats = array();
                 $lons = array();
                 foreach ($addmarkerlist as $marker) {
                     $marker = explode('{}', $marker);
                     $address = cgmp_analyse_address($marker[0]);
                     if (isset($address['lat'])) {
                         $lats[] = $address['lat'];
                     }
                     if (isset($address['lon'])) {
                         $lons[] = $address['lon'];
                     }
                 }
                 if (class_exists('LatLngBounds')) {
                     if (!empty($lats) && !empty($lons)) {
                         $LatLngSw = new LatLng(min($lats), min($lons));
                         $LatLngNe = new LatLng(max($lats), max($lons));
                         $layercenter = new LatLngBounds($LatLngSw, $LatLngNe);
                         $layerviewlat = $layercenter->getCenter()->getLat();
                         $layerviewlon = $layercenter->getCenter()->getLng();
                         $zoomlevel = getBoundsZoomLevel(array('width' => $shortcode['attributes']['width'], 'height' => $shortcode['attributes']['height']), $LatLngSw, $LatLngNe);
                     }
                 }
             }
             // if addmarkerlist contains more than 1 value in, an according entry in layers.csv has to be created.
             if (is_array($addmarkerlist) && count($addmarkerlist) > 1 or $shortcode['attributes']['addmarkermashup'] == 'true') {
                 $geocode = '';
                 if (!is_null($address['address'])) {
                     // use the caching before geocoding
                     //
                     if (in_array($shortcode['post_type'], array('cgmp_widget', 'text_widget'))) {
                         $post_type = 'widget_map';
                         $shortcode_id = $shortcode['widget_type'] . '-' . $shortcode['widget_id'];
                     } else {
                         $post_type = get_post_type($shortcode['post_id']);
                         $shortcode_id = $shortcode['post_id'];
                     }
                     if (!in_array($post_type, array('page', 'post', 'widget_map'))) {
                         $post_type = 'custom_map';
                     }
                     if ($shortcode['attributes']['addmarkermashup'] == 'true') {
                         $post_type = 'mashup_map';
                     }
                     if ($post_type != false) {
                         $cached_address = get_option('cgmp_cache_' . $post_type . '_' . $shortcode_id . ($shortcode['attributes']['shortcodeid'] == '' ? '' : '_' . $shortcode['attributes']['shortcodeid']));
                         if ($cached_address !== FALSE) {
                             $cached_address = explode('{}', $cached_address);
                             $latlon = explode(',', $cached_address[3]);
                             if (is_numeric(trim($latlon[0]))) {
                                 //use the cached
                                 $address['lat'] = trim($latlon[0]);
                                 $address['lon'] = trim($latlon[1]);
                                 $cache_used = true;
                             } else {
                                 // use geocoding
                                 $geocode = $address['address'];
                             }
                         }
                     }
                 }
                 $layers[$layer_count] = array('id' => '', 'name' => $shortcode['attributes']['shortcodeid'] == 'TO_BE_GENERATED' ? '' : $shortcode['attributes']['shortcodeid'], 'address' => '', 'geocode' => cgmp_accent_folding($geocode), 'layerviewlat' => $layerviewlat, 'layerviewlon' => $layerviewlon, 'layerzoom' => $zoomlevel ? $zoomlevel : 12, 'mapwidth' => $shortcode['attributes']['width'], 'mapwidthunit' => strpos($shortcode['attributes']['width'], '%') === FALSE ? 'px' : '%', 'mapheight' => $shortcode['attributes']['height'], 'basemap' => cgmp_get_the_basemap($shortcode['attributes']['maptype']), 'panel' => 1, 'clustering' => $shortcode['attributes']['enablemarkerclustering'] == 'true' ? 1 : 0, 'listmarkers' => 0, 'multi_layer_map' => 0, 'multi_layer_map_list' => 0, 'controlbox' => 1, 'createdby' => $current_user->user_login, 'createdon' => current_time('mysql', 0), 'updatedby' => $current_user->user_login, 'updatedon' => current_time('mysql', 0), 'overlays_custom' => 0, 'overlays_custom2' => 0, 'overlays_custom3' => 0, 'overlays_custom4' => 0, 'wms' => 0, 'wms2' => 0, 'wms3' => 0, 'wms4' => 0, 'wms5' => 0, 'wms6' => 0, 'wms7' => 0, 'wms8' => 0, 'wms9' => 0, 'wms10' => 0, 'gpx_url' => strpos(strtolower($shortcode['attributes']['kml']), 'gpx') === FALSE ? '' : $shortcode['attributes']['kml'], 'gpx_panel' => 0);
                 // ADD THE MASHUP LAYER
                 if ($shortcode['attributes']['addmarkermashup'] == 'true') {
                     $layers[$layer_count]['mashup'] = true;
                     $mashup_maps[$results_count] = $shortcode['attributes'];
                 } else {
                     // send the layer to the API
                     $response = wp_remote_get(MMP_API_URL . '?key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&action=add&type=layer&' . http_build_query($layers[$layer_count]));
                     if (is_array($response)) {
                         $layer_response = jsonp_decode($response['body']);
                     } else {
                         if ($shortcode['attributes']['addmarkermashup'] != 'true') {
                             $layers[$layer_count]['geolocation_failed'] = true;
                         }
                     }
                 }
                 if (isset($lats) and isset($shortcode['attributes']['addmarkerlist']) and count($lats) < count($addmarkerlist)) {
                     $layers[$layer_count]['mixed_addresses'] = true;
                 }
                 $layers[$layer_count]['new_id'] = $layer_response->data->id;
                 $layers[$layer_count]['post_id'] = $shortcode['post_id'];
                 $layers[$layer_count]['shortcode_type'] = $shortcode['post_type'] ? $shortcode['post_type'] : 'post';
                 $layers[$layer_count]['widget_type'] = $shortcode['widget_type'] ? $shortcode['widget_type'] : '';
                 $layers[$layer_count]['widget_id'] = $shortcode['widget_id'];
                 $layers[$layer_count]['has_styles'] = $shortcode['attributes']['styles'] != '' ? true : false;
                 $layers[$layer_count]['has_kml'] = (strpos(strtolower($shortcode['attributes']['kml']), 'gpx') === FALSE and $shortcode['attributes']['kml'] != '') ? true : false;
                 if ($layer_response->success == false) {
                     if ($shortcode['attributes']['addmarkermashup'] != 'true') {
                         $layers[$layer_count]['geolocation_failed'] = true;
                     }
                 }
                 $results[$results_count]['layer'] = $layers[$layer_count];
                 $layer_count++;
             }
             if (is_array($addmarkerlist) && !empty($addmarkerlist) && $shortcode['attributes']['addmarkermashup'] != 'true') {
                 $newlats = array();
                 $markers_counter = 0;
                 foreach ($addmarkerlist as $marker) {
                     $marker = explode('{}', $marker);
                     $address = cgmp_analyse_address($marker[0]);
                     $geocode = '';
                     if (!is_null($address['address'])) {
                         // use the caching before geocoding
                         $p_type = isset($shortcode['post_type']) ? $shortcode['post_type'] : '';
                         if (in_array($p_type, array('cgmp_widget', 'text_widget'))) {
                             $post_type = 'widget_map';
                             $shortcode_id = $shortcode['widget_type'] . '-' . $shortcode['widget_id'];
                         } else {
                             $post_type = get_post_type($shortcode['post_id']);
                             $shortcode_id = $shortcode['post_id'];
                         }
                         if (!in_array($post_type, array('page', 'post', 'widget_map'))) {
                             $post_type = 'custom_map';
                         }
                         if ($shortcode['attributes']['addmarkermashup'] == 'true') {
                             $post_type = 'mashup_map';
                         }
                         if ($post_type != '') {
                             $cached_address = get_option('cgmp_cache_' . $post_type . '_' . $shortcode_id . ($shortcode['attributes']['shortcodeid'] == '' ? '' : '_' . $shortcode['attributes']['shortcodeid']));
                             if ($cached_address !== FALSE) {
                                 $temp_cached_address = explode('|', $cached_address);
                                 $cached_address = explode('{}', $temp_cached_address[$markers_counter]);
                                 $markers_counter++;
                                 $latlon = explode(',', $cached_address[3]);
                                 if (is_numeric(trim($latlon[0]))) {
                                     //use the cached
                                     $address['lat'] = trim($latlon[0]);
                                     $address['lon'] = trim($latlon[1]);
                                     $newlats[] = 1;
                                     $cache_used = true;
                                     $geocode = '';
                                 } else {
                                     // use geocoding
                                     $geocode = $address['address'];
                                 }
                             } else {
                                 $geocode = $address['address'];
                             }
                         }
                     }
                     $markers[] = array('id' => '', 'markername' => is_null($address['address']) ? '' : $address['address'], 'popuptext' => isset($marker[2]) ? $marker[2] : '', 'openpopup' => 0, 'address' => is_null($address['address']) ? '' : $address['address'], 'geocode' => cgmp_accent_folding($geocode), 'lat' => isset($address['lat']) ? $address['lat'] : '', 'lon' => isset($address['lon']) ? $address['lon'] : '', 'layer' => count($addmarkerlist) == 1 ? 0 : $layer_response->data->id, 'zoom' => 12, 'icon' => $marker[1], 'mapwidth' => $shortcode['attributes']['width'], 'mapwidthunit' => strpos($shortcode['attributes']['width'], '%') === FALSE ? 'px' : '%', 'mapheight' => $shortcode['attributes']['height'], 'basemap' => cgmp_get_the_basemap($shortcode['attributes']['maptype']), 'panel' => 1, 'controlbox' => 1, 'createdby' => $current_user->user_login, 'createdon' => current_time('mysql', 0), 'updatedby' => $current_user->user_login, 'updatedon' => current_time('mysql', 0), 'kml_timestamp' => '', 'overlays_custom' => 0, 'overlays_custom2' => 0, 'overlays_custom3' => 0, 'overlays_custom4' => 0, 'wms' => 0, 'wms2' => 0, 'wms3' => 0, 'wms4' => 0, 'wms5' => 0, 'wms6' => 0, 'wms7' => 0, 'wms8' => 0, 'wms9' => 0, 'wms10' => 0, 'gpx_url' => strpos(strtolower(isset($shortcode['attributes']['kml']) ? $shortcode['attributes']['kml'] : ''), 'gpx') === FALSE ? '' : $shortcode['attributes']['kml'], 'gpx_panel' => 0);
                     // ADD THE MASHUP LAYER
                     //  if ($shortcode['attributes']['addmarkermashup'] == 'true') {
                     // $markers[$marker_count]['mashup'] = true;
                     // array_push($mashup_maps, $shortcode['attributes']);
                     //  } else {
                     // send the marker to the API
                     $response = wp_remote_get(MMP_API_URL . '?key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&action=add&type=marker&' . http_build_query($markers[$marker_count]));
                     if (is_array($response)) {
                         $marker_response = jsonp_decode($response['body']);
                     } else {
                         $markers[$marker_count]['geolocation_failed'] = true;
                     }
                     if ($marker_response->success == false) {
                         $markers[$marker_count]['geolocation_failed'] = true;
                     }
                     //}
                     $markers[$marker_count]['new_id'] = isset($marker_response->data->id) ? $marker_response->data->id : '';
                     $markers[$marker_count]['post_id'] = $shortcode['post_id'];
                     $markers[$marker_count]['shortcode_type'] = isset($shortcode['post_type']) ? $shortcode['post_type'] : 'post';
                     $markers[$marker_count]['widget_type'] = isset($shortcode['widget_type']) ? $shortcode['widget_type'] : '';
                     $markers[$marker_count]['widget_id'] = isset($shortcode['widget_id']) ? $shortcode['widget_id'] : '';
                     $markers[$marker_count]['has_styles'] = (isset($shortcode['attributes']['styles']) and $shortcode['attributes']['styles'] != '') ? true : false;
                     $markers[$marker_count]['has_kml'] = (strpos(strtolower(isset($shortcode['attributes']['kml']) ? $shortcode['attributes']['kml'] : ''), 'gpx') === FALSE and (isset($shortcode['attributes']['kml']) and $shortcode['attributes']['kml'] != '')) ? true : false;
                     $results[$results_count]['markers'][] = $markers[$marker_count];
                     $marker_count++;
                 }
                 if (count($newlats) + count($lats) == count($addmarkerlist) or count($newlats) == 0) {
                     unset($results[$results_count]['layer']['mixed_addresses']);
                 }
             }
             // increment layer_id by 1 just if there is more than marker in the shortcode
             if (count($addmarkerlist) > 1 or $shortcode['attributes']['addmarkermashup'] == 'true') {
                 $layer_id++;
             }
         }
     }
     // Process the mashup layers
     if (!empty($mashup_maps)) {
         foreach ($mashup_maps as $key => $mashup) {
             $boundbox = cgmp_calculate_boundbox_from_db($mashup['width'], $mashup['height']);
             $mashup_layer['name'] = 'Marker Geo Mashup';
             $mashup_layer['layerzoom'] = $boundbox['layerzoom'] ? $boundbox['layerzoom'] : '2';
             $mashup_layer['layerviewlat'] = $boundbox['layerviewlat'] ? $boundbox['layerviewlat'] : '26';
             $mashup_layer['layerviewlon'] = $boundbox['layerviewlon'] ? $boundbox['layerviewlon'] : '-2';
             $mashup_layer['mapwidth'] = $mashup['width'];
             $mashup_layer['mapheight'] = $mashup['height'];
             $mashup_layer['mapwidthunit'] = strpos($mashup['width'], '%') === FALSE ? 'px' : '%';
             $mashup_layer['clustering'] = $mashup['enablemarkerclustering'] == 'true' ? 1 : 0;
             $mashup_layer['multi_layer_map'] = '1';
             $mashup_layer['multi_layer_map_list'] = 'all';
             $mashup_layer['overlays_custom'] = '0';
             $mashup_layer['overlays_custom2'] = '0';
             $mashup_layer['overlays_custom3'] = '0';
             $mashup_layer['overlays_custom4'] = '0';
             $mashup_layer['wms'] = '0';
             $mashup_layer['wms2'] = '0';
             $mashup_layer['wms3'] = '0';
             $mashup_layer['wms4'] = '0';
             $mashup_layer['wms5'] = '0';
             $mashup_layer['wms6'] = '0';
             $mashup_layer['wms7'] = '0';
             $mashup_layer['wms8'] = '0';
             $mashup_layer['wms9'] = '0';
             $mashup_layer['wms10'] = '0';
             $response = wp_remote_get(MMP_API_URL . '?key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires . '&action=add&type=layer&' . http_build_query($mashup_layer));
             if (is_array($response)) {
                 $mashup_response = jsonp_decode($response['body']);
                 //$layers[$key]['new_id'] = $mashup_response->data->id;
                 $results[$key]['layer']['new_id'] = $mashup_response->data->id;
             }
         }
     }
     // Disable the API after the transfere
     $mapsmarkerapi_options = get_option('leafletmapsmarker_options');
     $mapsmarkerapi_options['api_status'] = 'disabled';
     $mapsmarkerapi_options['api_key'] = '';
     $mapsmarkerapi_options['api_key_private'] = '';
     update_option('leafletmapsmarker_options', $mapsmarkerapi_options);
     foreach ($layers as $layer) {
         //calculate the boundbox from the database
         if ($layer['layerviewlat'] == '' and $layer['layerviewlon'] == '' and !isset($layer['mashup'])) {
             $boundbox = cgmp_calculate_boundbox_from_db($layer['mapwidth'], $layer['mapheight'], $layer['new_id']);
             global $wpdb;
             $wpdb->update($wpdb->prefix . 'leafletmapsmarker_layers', $boundbox, array('id' => $layer['new_id']));
         }
     }
     return $results;
 }