Beispiel #1
0
<?php

/**
 * Required PHP extension list.
 */
$reqd_ext = array('curl', 'openssl');
/**
 * Checks.
 */
if ($err = validate_php_env($reqd_ext)) {
    error_message('One or more required PHP extensions is missing: ' . $err);
    exit(1);
}
require_once 'docs/README_AP.html';
function validate_php_env($required_extensions)
{
    // Exit-code style - empty string == succeeded.
    $result = '';
    $php_ext = get_loaded_extensions();
    foreach ($required_extensions as $ext) {
        if (!in_array($ext, $php_ext)) {
            $result .= " {$ext}";
        }
    }
    return trim($result);
}
function error_message($msg)
{
    echo "INSTALLATION ERROR:\n{$msg}\n";
}
Beispiel #2
0
/**
 * Do the install to a remote FTP server.
 */
function install_remote()
{
    echo "\nProceeding with remote installation.\n\n";
    // validate_php_env returns a string on error, empty string on
    // success, so be careful with logic.
    if (validate_php_env(array('ftp')) && validate_php_env(array('sockets'))) {
        error_message('You must have either FTP or Sockets support in PHP to use the remote installer.');
        exit(1);
    }
    echo "Enter the FTP server to install on: ";
    $host = trim(fgets(STDIN));
    echo "Username for FTP: ";
    $user = trim(fgets(STDIN));
    echo "Password for FTP: ";
    $pass = trim(fgets(STDIN));
    echo "Please enter the path (relative to your FTP root) for the paypal-php-sdk directory: ";
    $installdir = trim(fgets(STDIN));
    echo "Please enter the path (relative to your FTP root) for the paypal-sdk-samples directory: ";
    $sampledir = trim(fgets(STDIN));
    $ftp = ftp_connect($host);
    if (!is_resource($ftp)) {
        error_message('Unable to connect to FTP server: ' . $host);
        exit(1);
    }
    if (!ftp_login($ftp, $user, $pass)) {
        error_message('Unable to authenticate to FTP server as ' . $user);
        exit(1);
    }
    // Install the libraries.
    echo "\nInstalling SDK libraries...\n";
    if (!@ftp_chdir($ftp, $installdir)) {
        if (!ftp_mkdir($ftp, $installdir)) {
            error_message('Libraries install directory does not exist and I can\'t create it.');
            exit(1);
        }
        ftp_chdir($ftp, $installdir);
    }
    if (!@ftp_chdir($ftp, 'paypal-php-sdk')) {
        if (!ftp_mkdir($ftp, 'paypal-php-sdk')) {
            error_message('Unable to create libraries directory.');
            exit(1);
        }
        ftp_chdir($ftp, 'paypal-php-sdk');
    }
    ftp_r($ftp, '.');
    ftp_cdup($ftp);
    // Install the samples.
    echo "Installing SDK samples...\n";
    if (!@ftp_chdir($ftp, $sampledir)) {
        if (!ftp_mkdir($ftp, $sampledir)) {
            error_message('Samples install directory does not exist and I can\'t create it.');
            exit(1);
        }
        ftp_chdir($ftp, $sampledir);
    }
    if (!@ftp_chdir($ftp, 'paypal-sdk-samples')) {
        if (!ftp_mkdir($ftp, 'paypal-sdk-samples')) {
            error_message('Unable to create samples directory.');
            exit(1);
        }
        ftp_chdir($ftp, 'paypal-sdk-samples');
    }
    ftp_r($ftp, 'samples/php');
    // Generate and upload the ppsdk_include_path file.
    generate_ini_set($installdir, './ppsdk_include_path.inc', "paypal-php-sdk' . DIRECTORY_SEPARATOR . 'lib");
    ftp_put($ftp, 'ppsdk_include_path.inc', './ppsdk_include_path.inc', FTP_ASCII);
    unlink('./ppsdk_include_path.inc');
    ftp_close($ftp);
}