function ftp_sync_callback($data)
{
    global $ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, $local_media_dir, $remote_media_dir, $local_theme_dir, $remote_theme_dir, $local_plugin_dir, $remote_plugin_dir;
    // start session
    session_start();
    $type = sanitize_text_field($_POST['type']);
    switch ($type) {
        case "theme":
            $name = "Theme";
            $local_dir = $local_theme_dir;
            $remote_dir = $remote_theme_dir;
            break;
        case "media":
            $name = "Media";
            $local_dir = $local_media_dir;
            $remote_dir = $remote_media_dir;
            break;
        case "plugin":
            $name = "Plugin";
            $local_dir = $local_plugin_dir;
            $remote_dir = $remote_plugin_dir;
            break;
        default:
            break;
    }
    $step = sanitize_text_field($_POST['step']);
    switch ($step) {
        case 1:
            $html = "<p><strong>{$name} Files</strong></p>Testing FTP Connection... ";
            $step++;
            break;
        case 2:
            $result = get_ftp_connection($ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, true);
            $html = $result[1];
            if ($result[0]) {
                $step++;
            } else {
                $step = false;
            }
            break;
        case 3:
            $html = "Verifying remote {$type} directory... ";
            $step++;
            break;
        case 4:
            $verified = verify_remote_dir($remote_dir);
            if ($verified) {
                $html = "OK<br/>";
                $step++;
                $step = 7;
            } else {
                $html = "<br/>ERROR: <strong>{$remote_dir}</strong> does not exist on the server<br/>";
                $step = false;
            }
            break;
        case 5:
            // this is being skipped for now
            $html = "Syncing Timezones... ";
            $step++;
            break;
        case 6:
            // this is being skipped for now
            $ftp = get_ftp_connection($ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, false);
            $html = sync_timezones($ftp, $local_dir, $remote_dir);
            ftp_close($ftp);
            $step++;
            break;
        case 7:
            $html = "Scanning local {$type} files... ";
            $step++;
            break;
        case 8:
            $html = scan_local_files($local_dir . "/");
            $step++;
            break;
        case 9:
            $html = "Scanning remote {$type} files... ";
            $step++;
            break;
        case 10:
            $ftp = get_ftp_connection($ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, false);
            $html = scan_remote_files($ftp, $remote_dir);
            ftp_close($ftp);
            $step++;
            break;
        case 11:
            $html = "Comparing {$type} files... ";
            $step++;
            break;
        case 12:
            $html = compare_files($local_dir, $remote_dir);
            $step++;
            break;
        case 13:
            $local_files = $_SESSION['local_files_to_upload'];
            if ($local_files) {
                $total = 0;
                foreach ($local_files as $file) {
                    $total += filesize($file);
                }
                $html = "Uploading " . ceil(count($local_files)) . " newer {$type} files (" . round($total / 1024 / 1024, 2) . " MB)... \r\n\t\t\t\t\t<span id='upload'>(est. <span>\r\n\t\t\t\t\t\t<script type='text/javascript'>\r\n\t\t\t\t\t\t\tvar sec = " . ceil($total / 1024 / 15) . "\r\n\t\t\t\t\t\t\tvar timer = setInterval(function() { \r\n\t\t\t\t\t\t\t   jQuery('#upload span').text(sec--);\r\n\t\t\t\t\t\t\t   if (sec === -1) {\r\n\t\t\t\t\t\t\t      clearInterval(timer);\r\n\t\t\t\t\t\t\t   } \r\n\t\t\t\t\t\t\t}, 1000);\r\n\t\t\t\t\t\t</script>\r\n\t\t\t\t\t</span> seconds)... </span> ";
                $step++;
            } else {
                $html = "No local {$type} files to upload.<br/>";
                $step = 15;
            }
            break;
        case 14:
            $local_files = $_SESSION['local_files_to_upload'];
            $ftp = get_ftp_connection($ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, false);
            $html = upload_files($ftp, $remote_dir, $local_dir, $local_files, $activeMode);
            ftp_close($ftp);
            $html = "OK<br/>";
            $step++;
            break;
        case 15:
            $html = "<script type='text/javascript'>jQuery('#upload').fadeOut('fast');</script>";
            $remote_files = $_SESSION['remote_files_to_download'];
            if ($remote_files) {
                $total = 0;
                $ftp = get_ftp_connection($ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, false);
                foreach ($remote_files as $file) {
                    $total += ftp_size($ftp, $file);
                }
                ftp_close($ftp);
                $html .= "Downloading " . ceil(count($remote_files)) . " newer {$type} files (" . round($total / 1024 / 1024, 2) . " MB)... \r\n\t\t\t\t\t<span id='download'>(est. <span>\r\n\t\t\t\t\t\t<script type='text/javascript'>\r\n\t\t\t\t\t\t\tvar sec2 = " . ceil($total / 1024 / 64) . "\r\n\t\t\t\t\t\t\tvar timer2 = setInterval(function() { \r\n\t\t\t\t\t\t\t   jQuery('#download span').text(sec2--);\r\n\t\t\t\t\t\t\t   if (sec2 === -1) {\r\n\t\t\t\t\t\t\t      clearInterval(timer2);\r\n\t\t\t\t\t\t\t   } \r\n\t\t\t\t\t\t\t}, 1000);\r\n\t\t\t\t\t\t</script>\r\n\t\t\t\t\t</span> seconds)... </span> ";
                $step++;
            } else {
                $html .= "No remote {$type} files to download.<br/>";
                $step = 17;
                // all done
            }
            break;
        case 16:
            $remote_files = $_SESSION['remote_files_to_download'];
            $local_dir_fixed = str_replace('/', '\\', $local_dir);
            // correct slashes in localRoot
            $ftp = get_ftp_connection($ftpHost, $ftpPort, $ftpUser, $ftpPass, $activeMode, false);
            $html = download($ftp, $remote_dir, $local_dir, $remote_files, $activeMode);
            ftp_close($ftp);
            $html = "OK<br/>";
            $step++;
            break;
        case 17:
            $html = "<script type='text/javascript'>jQuery('#download').fadeOut('fast');</script>";
            $step++;
            break;
        default:
            $_SESSION = array();
            // get rid of all session data for next sync
            $step = false;
            break;
    }
    echo json_encode(array('step' => $step, 'html' => $html, 'type' => $type));
    die;
    // this is required to return a proper result
}
示例#2
0
#! /usr/local/bin/php
<?php 
include_once "init.inc";
clean_api();
run_api_test();
compare_files("foobar", "ta_correct_f");
clean_api();
?>

示例#3
0
    fwrite(STDERR, "Error: No matching files to check\n");
    exit(1);
}
sort($o_list);
# Process each result file:
foreach ($o_list as $filename) {
    $srcname = $outdir . DIRECTORY_SEPARATOR . $filename;
    $refname = $refdir . DIRECTORY_SEPARATOR . $filename;
    if (!file_exists($refname)) {
        $n_new++;
        $s_new[] = $filename;
        echo "+ {$filename}: No reference to compare with (new test)\n";
        if ($view_all || $view_new) {
            view_file($srcname);
        }
    } elseif (compare_files($srcname, $refname)) {
        $n_same++;
        if (!$be_quiet) {
            echo "  {$filename}: Matches\n";
        }
        if ($view_all) {
            view_file($srcname);
        }
    } else {
        $n_diff++;
        $s_diff[] = $filename;
        echo "! {$filename}: Output differs\n";
        if ($view_all || $view_dif) {
            view_files($srcname, $refname);
        }
    }