/var/www/html_uk/wp-content/plugins/automatewoo/includes/Integrations/Mad_Mimi.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

if ( ! 
defined'ABSPATH' ) ) exit;

/**
 * @class Integration_Mad_Mimi
 * @since 2.7
 */
class Integration_Mad_Mimi extends Integration {

    
/** @var string */
    
public $integration_id 'mad-mimi';

    
/** @var string */
    
private $username;

    
/** @var string */
    
private $api_key;

    
/** @var string  */
    
private $api_root 'https://api.madmimi.com';

    
/**
     * @param $username
     * @param $api_key
     */
    
function __construct$username$api_key ) {
        
$this->username $username;
        
$this->api_key $api_key;
    }

    
/**
     * The API details are not stored in the same way as other integrations as they are
     * supplied in the Action settings so we do not need to test the integration at this point.
     *
     * @return bool True
     */
    
public function test_integration(): bool {
        return 
true;
    }

    
/**
     * The Mad Mimi Integration does not have a settings page and does not
     * need to be enabled in order to use the related Actions
     *
     * @return bool True
     */
    
public function is_enabled(): bool {
        return 
true;
    }

    
/**
     * Automatically logs errors
     *
     * @param $method
     * @param $endpoint
     * @param $args
     *
     * @return Remote_Request
     */
    
function request$method$endpoint$args = [] ) {
        
$args['username'] = $this->username;
        
$args['api_key'] = $this->api_key;

        
$request_args = [
            
'headers' => [
                
'Accept' => 'application/json'
            
],
            
'timeout' => 10,
            
'method' => $method,
            
'sslverify' => false
        
];

        
$url $this->api_root $endpoint;
        
// SEMGREP WARNING EXPLANATION
        // This is escaped with esc_url_raw, but semgrep only takes into consideration esc_url.
        
$url esc_url_rawadd_query_arg$args$url ) );

        
$request = new Remote_Request$url$request_args );

        
$this->maybe_log_request_errors$request );

        return 
$request;
    }


    function 
build_csv($arr) {
        
$csv "";
        
$keys array_keys($arr);
        foreach (
$keys as $key => $value) {
            
$value esc_attr($value);
            
$csv .= $value ",";
        }
        
$csv substr($csv0, -1);
        
$csv .= "\n";
        foreach (
$arr as $key => $value) {
            
$value esc_attr($value);
            
$csv .= $value ",";
        }
        
$csv substr($csv0, -1);
        
$csv .= "\n";
        return 
$csv;
    }


}