Esempio n. 1
0
function call_api($data)
{
    $api_key = '84ed801ad4';
    $private_key = 'cacff8d71d9cc6e';
    $method = 'POST';
    $domain = $_SERVER['HTTP_HOST'];
    if ($domain == 'localhost') {
        $domain .= '/makerfaire';
    }
    //    $endpoint = 'http://makerfaire.staging.wpengine.com/gravityformsapi/';
    //$endpoint = 'http://makerfaire.com/gravityformsapi/';
    $endpoint = $domain . '/gravityformsapi/';
    echo 'sending to ' . $endpoint . '<br/>';
    //$route = 'entries';
    $route = 'forms/25/entries';
    $expires = strtotime('+60 mins');
    $string_to_sign = sprintf('%s:%s:%s:%s', $api_key, $method, $route, $expires);
    $sig = calculate_signature($string_to_sign, $private_key);
    $api_call = $endpoint . $route . '?api_key=' . $api_key . '&signature=' . $sig . '&expires=' . $expires;
    //print_r(json_encode($data));
    $ch = curl_init($api_call);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    $result = curl_exec($ch);
    $returnedData = json_decode($result);
    //201 status indicates it inserted the entry. Should return id of the entry.
    if ($returnedData->status == 201 || $returnedData->status == 200) {
        return $returnedData->response;
    } else {
        echo 'There was an error in the call to ' . $api_call . '<br/><br/>';
        var_dump($result);
        echo '<Br/><br/>';
        var_dump($returnedData);
        die;
    }
}
    $template_values['EXPORTED_MSG'] = '';
    // Check if the user requests the Export Function and process it.
    if (isset($_POST['cgmp-export-maps']) && !empty($shortcodes_data['shortcodes'])) {
        // Enable the MMP API
        $mapsmarkerapi_options = get_option('leafletmapsmarker_options');
        $mapsmarkerapi_options['api_status'] = 'enabled';
        $mapsmarkerapi_options['api_key'] = 'cgmptransfer';
        $mapsmarkerapi_options['api_key_private'] = 'cgmptransferprivatekey';
        update_option('leafletmapsmarker_options', $mapsmarkerapi_options);
        // Calculate the signature
        $api_key = $mapsmarkerapi_options['api_key'];
        $private_key = $mapsmarkerapi_options['api_key_private'];
        $expires = strtotime("+60 mins");
        $string_to_sign = sprintf("%s:%s", $api_key, $expires);
        $string_to_sign = $api_key . ":" . $expires;
        $sig = calculate_signature($string_to_sign, $private_key);
        $export = cgmp_export_to_api($shortcodes_data['shortcodes'], $api_key, $sig, $expires);
        //passing the generated markers
        $shortcodes_data = cgmp_get_posts_shortcodes($export);
        if ($export !== FALSE) {
            //save the generated data to prevent duplication
            set_transient('cgmp_layers_markers_export', $export, 60 * 60 * 24 * 7);
            $template_values['EXPORTED_MSG'] = '
                         <div id="message" class="updated"><p><strong>
Your maps have been successfully created in "Maps Marker Pro"!</strong><br/>
As next step it is recommended to review those maps and replace the old shortcode in your content with the new one.
<br/><br/>
You can also automatically replace all existing shortcodes by clicking the button "step 2/2: replace existing CGMP shortcodes".
<br/>

<strong>Anyway it is strongly advised to check your maps before and make a database backup or at least an export of your current content from <a style="text-decoration:underline;" href="' . admin_url() . 'export.php">(tools->export)</a>,  as the CGMP shortcodes can only be restored from a a backup!</strong>