Plugin Directory

Changeset 2600478


Ignore:
Timestamp:
09/17/2021 11:15:11 AM (5 years ago)
Author:
leadgenerated
Message:

Fixes for typeform

Location:
lead-generated
Files:
29 added
5 edited

Legend:

Unmodified
Added
Removed
  • lead-generated/trunk/includes/class-wsl-api.php

    r2286317 r2600478  
    9393    }
    9494   
     95        public function callTypeFormAuth($url, $authorization, $method = 'POST'){
     96        $headers = array();
     97        $headers['Accept'] = "application/json";
     98        $headers['Content-Type'] = "application/json";
     99        $headers['Authorization'] = $authorization;
     100       
     101        $args = array(
     102            'headers' => $headers,
     103            'timeout' => '30',
     104            'redirection' => '5',
     105            'httpversion' => '1.0',
     106            'blocking' => true,
     107        );
     108       
     109        if($method == 'GET'){
     110            $response = wp_remote_get( $url,  $args);
     111        }elseif($method == 'POST'){
     112            $args['body'] = json_encode($post_data);
     113            $response = wp_remote_post( $url, $args );
     114        }else{
     115            $args['method'] = $method;
     116            $response = wp_remote_request( $url, $args );
     117        }
     118       
     119        $body = wp_remote_retrieve_body( $response );
     120        return json_decode($body);
     121    }
     122   
    95123}
    96124
  • lead-generated/trunk/includes/class-wsl-typeform-api.php

    r2415131 r2600478  
    256256        foreach($formData[0]["answers"] as $k=>$v){
    257257            if($v["type"] != "email"){
    258                 $type = $v["field"]["ref"];
     258
     259                $tags = explode('-' , $v["field"]["ref"]);
     260               
     261                if(count($tags) > 4){
     262                    $type = $v["type"];
     263                }else{
     264                    $type = $v["field"]["ref"];
     265                }
    259266            }else{
    260267                $type = $v["type"];
     
    268275            );
    269276        }
    270 
    271277        return $fields;
    272278    }
  • lead-generated/trunk/includes/helpers.php

    r2415582 r2600478  
    1818function wsl_get_cf7_post_settings($post_id){
    1919    $meta = get_post_meta($post_id,'_wsl_settings',TRUE);
     20    //var_dump($meta);
    2021    if(!is_array($meta)){
    2122        return wsl_get_default_cf7_post_settings();
     
    6970
    7071function typeform_script() {
    71     wp_register_script( "my_custom_script", plugin_dir_url( __FILE__ ).'assets/custom.js', array('jquery') );
     72    wp_register_script( "my_custom_script", plugin_dir_url( __FILE__ ).'assets/custom.js', array('jquery'), NULL, TRUE );
    7273    wp_localize_script( 'my_custom_script', 'localize', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
    7374
     
    7576    wp_enqueue_script( 'my_custom_script' );
    7677}
    77 add_action( 'admin_enqueue_scripts', 'typeform_script' );
     78add_action( 'wp_enqueue_scripts', 'typeform_script' );
    7879
    7980function typeform_api($response_id){
     
    8283    $token = $get_settings["typeform_api_key"];
    8384
    84     //setup the request, you can also use CURLOPT_URL
    85     $ret_form = curl_init('https://api.typeform.com/forms');
    86     sleep(30);
    87     curl_setopt($ret_form, CURLOPT_RETURNTRANSFER, true);
    88     curl_setopt($ret_form, CURLOPT_HTTPHEADER, array(
    89         'Content-Type: application/json',
    90         'Authorization: Bearer ' . $token
    91     ));
    92     $data_form = curl_exec($ret_form);
    93     $strip = stripslashes($data_form);
    94     $decode_obj = json_decode($strip, true);
    95     foreach($decode_obj["items"] as $key=>$v){
    96         $ch = curl_init('https://api.typeform.com/forms/'.$v["id"].'/responses?included_response_ids='.$response_id);
    97         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    98         curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    99             'Content-Type: application/json',
    100             'Authorization: Bearer ' . $token
    101         ));
     85    $api_obj = new Wsl_Api();
     86    $call_init = $api_obj->callTypeFormAuth('https://api.typeform.com/forms', 'Bearer ' . $token, $method = 'GET');
    10287
    103         $data = curl_exec($ch);
    104         $strip_data = stripslashes($data);
    105         $decode_obj_data = json_decode($strip_data, true);
    106         if($decode_obj_data["total_items"] > 0){
    107             $data_items = $decode_obj_data["items"];
     88    $getItems = json_decode(json_encode($call_init), true);
     89
     90    foreach($getItems["items"] as $key=>$v){
     91        $ch = $api_obj->callTypeFormAuth('https://api.typeform.com/forms/'.$v["id"].'/responses?included_response_ids='.$response_id, 'Bearer ' . $token, $method = 'GET');
     92        $totalItems = json_decode(json_encode($ch), true);
     93        if($totalItems["total_items"] > 0){
     94            $data_items = $totalItems["items"];
    10895            return $data_items;
    10996        }else{
    11097            return 'Response: false';
    11198        }
    112 
    113         $info = curl_getinfo($ch);
    114         curl_close($ch);
    11599    }
    116 
    117     $info_form = curl_getinfo($ret_form);
    118     curl_close($ret_form);
    119100}
    120101
  • lead-generated/trunk/lead-generated.php

    r2600388 r2600478  
    55 * Plugin URI: https://www.leadgenerated.com/
    66 * Description: Save the leads to Lead Generated system generated by various form plugins. We currently support CF7, Ninja Forms, WP Forms, Gravity Forms and Elementor Builder.
    7  * Version: 1.17
     7 * Version: 1.18
    88 * Author: Lead Generated
    99 * Author URI: https://profiles.wordpress.org/leadgenerated/
  • lead-generated/trunk/readme.txt

    r2600388 r2600478  
    44Requires at least: 2.0
    55Tested up to: 5.6
    6 Stable tag: 1.17
     6Stable tag: 1.18
    77Requires PHP: 5.2.4
    88License: GPLv2 or later
     
    8787= 1.17 =
    8888* Fluent Form Fixes
     89
     90= 1.18 =
     91* Typeform Fixes
Note: See TracChangeset for help on using the changeset viewer.