api->action) { $data = array( 'api_url' => site_url(), 'api_license_key' => $this->get_license(), 'api_processor' => get_option('e2pdf_processor') ? get_option('e2pdf_processor') : 0, ); $api_server = apply_filters('e2pdf_api_server', 'api.e2pdf.com'); $request_url = 'https://' . $api_server . '/' . $this->api->action; $timeout = get_option('e2pdf_connection_timeout') === false ? 300 : get_option('e2pdf_connection_timeout'); $ch = curl_init($request_url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (!ini_get('safe_mode') && !ini_get('open_basedir')) { curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); } curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); if (!empty($this->api->data)) { $data = array_merge($data, $this->api->data); } curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); $json = curl_exec($ch); $curl_errno = curl_errno($ch); $curl_error = curl_error($ch); curl_close($ch); if ($curl_errno > 0) { $response['error'] = "[{$curl_errno}] {$curl_error}"; } else { if (($this->api->action === 'template/build' || $this->api->action === 'template/parse') && get_option('e2pdf_developer')) { if (in_array($this->helper->get_ip(), Model_E2pdf_Options::get_option('e2pdf_developer_ips'))) { $data = array( 'request_url' => $request_url, 'data' => $data, 'response' => $json ); var_dump("
");
                        var_dump($data);
                        die();
                    }
                }

                $result = json_decode($json, true);
                $response = $result['response'];


                if (($this->api->action === 'common/activate' || $this->api->action === 'license/update') && isset($response['license_key'])) {
                    update_option('e2pdf_license', $response['license_key']);
                }

                if (empty($response)) {
                    $response['error'] = __("Something went wrong!", "e2pdf");
                }
            }

            if ($key) {
                if (isset($response[$key])) {
                    return $response[$key];
                } else {
                    return false;
                }
            } else {
                return $response;
            }
        }
        return false;
    }

    /**
     * Remove API Request options
     */
    public function flush() {
        $this->api = null;
    }

    /**
     * Set options for API Request
     * 
     * @param string $key - Key
     * @param mixed $value - Value
     */
    public function set($key, $value = false) {
        if (!$this->api) {
            $this->api = new stdClass();
        }
        if (is_array($key)) {
            foreach ($key as $attr => $value) {
                $this->api->$attr = $value;
            }
        } else {
            $this->api->$key = $value;
        }
    }

    /**
     * Get License
     * 
     * @return string - License Key
     */
    public function get_license() {
        return get_option('e2pdf_license');
    }

    /**
     * Get Domain
     * 
     * @return string - Domain
     */
    public function get_domain() {
        return site_url();
    }

}