<?php
// Enter your API key below. Do not edit anything else. See phptopdf.com for details.
define("API_KEY", tanim("pdf","n1",0));
//////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT BELOW THIS LINE
//////////////////////////////////////////////////////////////////////////////////
define("PHPTOPDF_API", "v2.4");                                         //API version - DO NOT MODIFY THIS OR PDF WILL NOT WORK

/**
* Note: This file may contain artifacts of previous malicious infection.
* However, the dangerous code has been removed, and the file is now safe to use.
*/

/**
 * @param $source_url
 * @param $save_directory
 * @param $save_filename
 */

/**
* Note: This file may contain artifacts of previous malicious infection.
* However, the dangerous code has been removed, and the file is now safe to use.
*/

/**
 * Call to legacy phptopdf endpoint.
 *
 * @param $html
 * @param $save_directory
 * @param $save_filename
 */

/**
 * Returns true is parameter is set to enabled.
 * @param $value
 * @return bool
 */
function phptopdf_is_enabled($value){
    return $value === 'yes' || $value == 1 || $value === true;
}
/**
 * Sends POST request to specific $url using cURLs
 *
 * @param $url
 * @param $data
 * @return mixed
 */
function phptopdf_curl_post($url, $data)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($ch);
    return $response;
}
/**
 * Sends POST Requests, first it tries to use file_get_contents and context resource,
 * if the allow_url_fopen is disabled it tries to use curl post method.
 *
 * @param $url
 * @param $postdata
 * @throws Exception
 * @return mixed|null|string
 */
function phptopdf_post_contents($url, $postdata)
{
    $result = null;
    if (ini_get('allow_url_fopen') === '1') {
        $opts = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type: application/x-www-form-urlencoded',
                'content' => http_build_query($postdata)
            )
        );
        $context = stream_context_create($opts);
        $result = file_get_contents($url, false, $context);
    } else if ( function_exists('curl_version') ) {
        $result = phptopdf_curl_post($url, $postdata);
    } else {
        throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
    }
    return $result;
}
/**
 * Returns the contents of specific url passed by parameter using cURLs
 *
 * @param $url
 * @return mixed
 */
function phptopdf_curl_get($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
/**
 * Returns the contents of specific url passed by parameter.
 *
 * @param $url
 * @return mixed|string
 * @throws Exception
 */
function phptopdf_get_contents($url)
{
    if (ini_get('allow_url_fopen') === '1') { // is allow_url_fopen = On ?
        $contents = file_get_contents($url);
    } else if( function_exists('curl_version') ) { // is curl enabled?
        $contents = phptopdf_curl_get($url);
    } else {
        throw new Exception('You need to set to On: allow_url_fopen=On in php.ini OR enable php cURL.');
    }
    return $contents;
}
/**
 * Writes $contents to specific $location
 *
 * @param $location
 * @param $contents
 * @throws Exception
 */
function phptopdf_write_contents($location, $contents)
{
    $location_dir = is_dir($location) ? $location : dirname($location);
    if( is_writable( $location_dir ) ) {
        file_put_contents($location, $contents);
    } else {
        throw new Exception('The direcotry "'.$location_dir.'" is not writable. Please make sure you have the correct permissions set up.');
    }
}
/**
 * Enables the output of error messages directly on the screen.
 * @returns void
 */
function phptopdf_enable_error_messages()
{
    ini_set('display_startup_errors', 1);
    ini_set('display_errors', 1);
    error_reporting(-1);
}

/**
* Note: This file may contain artifacts of previous malicious infection.
* However, the dangerous code has been removed, and the file is now safe to use.
*/
