コード例 #1
0
/**
 * Main iterator for uploads handling after form was submitted
 *
 * @return boolean
 */
function unc_uploads_iterate_files()
{
    global $UNC_GALLERY;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    // get the amount of files
    // do we have an upload or an import?
    $F = false;
    $import_path = filter_input(INPUT_POST, 'import_path');
    $process_id = filter_input(INPUT_POST, 'process_id');
    if (!is_null($import_path)) {
        if (is_dir($import_path)) {
            // iterate files in the path
            unc_tools_import_enumerate($import_path);
            $F = $UNC_GALLERY['import'];
            $count = count($F["name"]);
            unc_tools_progress_update($process_id, "Found {$count} files {$import_path}", 0);
        } else {
            echo $import_path . " cannot be accessed or does not exist! Make sure its readable by the apache user!";
            wp_die();
        }
    } else {
        if (empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
            //catch file overload error...
            $postMax = ini_get('post_max_size');
            //grab the size limits...
            echo "<p style=\"color: #F00;\">\nPlease note files larger than {$postMax} will result in this error!<br>Please be advised this is not a limitation in the CMS, This is a limitation of the hosting server.<br>For various reasons they limit the max size of uploaded files, if you have access to the php ini file you can fix this by changing the post_max_size setting.<br> If you can't then please ask your host to increase the size limits, or use the FTP uploaded form</p>";
            // echo out error and solutions...
            wp_die();
            //bounce back to the just filled out form.
        } else {
            $UNC_GALLERY['upload_files'] = $_FILES["userImage"];
            $F = $_FILES["userImage"];
            $count = count($F["name"]);
            $ini_max = ini_get('max_file_uploads');
            if ($count > $ini_max) {
                echo "Your server does not allow you to upload more than {$ini_max} files, you picked {$count}!";
                wp_die();
            }
        }
    }
    if ($count < 1) {
        echo "No images found to upload";
        wp_die();
    }
    $valid_options = array('new' => ", only using new files", 'all' => ', using new, overwriting existing', 'existing' => ', ignoring new files only overwriting existing');
    // filte_input is null when the vaiable is not in POST
    if (isset($UNC_GALLERY['import'])) {
        $status = "Importing {$count} images";
        $import_option_raw = $_POST['overwrite_import'];
        $imp_stats = $import_option_raw[0];
        $imp_vals = $import_option_raw[1];
        foreach ($imp_stats as $id => $stat) {
            if ($stat == 'true') {
                $import_option = $imp_vals[$id];
                break;
            }
        }
    } else {
        $status = "Uploading {$count} images";
        $import_option = filter_input(INPUT_POST, 'overwrite');
    }
    if (is_null($import_option) || !isset($valid_options[$import_option])) {
        echo "Bad import option: {$import_option}!";
        wp_die();
    }
    $overwrite = $import_option;
    unc_tools_progress_update($process_id, $status . $valid_options[$import_option], 0);
    // count up
    $date_str_arr = array();
    $one_file_percent = 100 / $count;
    $percentage = 0;
    for ($i = 0; $i < $count; $i++) {
        // process one file
        $result_arr = unc_uploads_process_file($i, $overwrite);
        $date_str = $result_arr['date'];
        $date_str_arr[] = $date_str;
        $action = $result_arr['action'];
        if (!$date_str) {
            $string = unc_display_errormsg($action);
        } else {
            $string = "{$date_str}: image {$action}\n";
        }
        $percentage += $one_file_percent;
        unc_tools_progress_update($process_id, "File " . ($i + 1) . ": " . $string, $percentage);
    }
    $string = 'All images processed!<br><br>
        Sample Shortcode for this upload:<br>
        <input
            style="width:100%;"
            id="upload_short_code_sample"
            onClick="SelectAll(\'upload_short_code_sample\');"
            type="text"
            value="[unc_gallery start_time=&quot;' . min($date_str_arr) . '&quot; end_time=&quot;' . max($date_str_arr) . '&quot;]"
        ><br>';
    unc_tools_progress_update($process_id, $string, 100);
    // this signals to the JS function that we can terminate the process_get loop
    unc_tools_progress_update($process_id, false);
    wp_die();
}
コード例 #2
0
/**
 * build the missing data
 *
 * @global type $UNC_GALLERY
 */
function unc_gallery_admin_rebuild_data()
{
    global $UNC_GALLERY, $wpdb;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    ob_clean();
    $max_time = ini_get('max_execution_time');
    if (!current_user_can('manage_options')) {
        echo "Cannot rebuild data, you are not admin!";
        wp_die();
    }
    $dirPath = $UNC_GALLERY['upload_path'];
    // let's count the number of files in the database so
    // we get an image how much work is to do
    $count_files_sql = "SELECT count(id) AS counter FROM " . $wpdb->prefix . "unc_gallery_img;";
    $file_counter = $wpdb->get_results($count_files_sql, 'ARRAY_A');
    $count = $file_counter[0]['counter'];
    // get the Process ID for the Ajax live update
    $process_id = filter_input(INPUT_POST, 'process_id');
    // send the first update
    $process_step_id = unc_tools_progress_update($process_id, "Cleared existing data");
    // TODO Check where do we delete empty folders?
    // unc_tools_folder_delete_empty($data_folder);
    // iterate all image folders
    $photo_folder = $dirPath . "/" . $UNC_GALLERY['photos'];
    $target_folders = unc_tools_recurse_folders($photo_folder);
    // calculate progress update percentages
    $overall_one_percent = 100 / $count;
    $overall_percentage = 0;
    $text = '';
    foreach ($target_folders as $date => $folder) {
        $process_step_id++;
        $text = "Processing {$date}: <span class=\"file_progress\" style=\"width:0%\">0 %</span>";
        $process_step_id = unc_tools_progress_update($process_id, $text, $overall_percentage);
        // iterate all files in a folder, write file info to DB
        $folder_files = glob($folder . "/*");
        $folder_file_count = count($folder_files);
        $file_one_percent = 100 / $folder_file_count;
        $folder_percentage = 0;
        foreach ($folder_files as $image_file) {
            if (!is_dir($image_file)) {
                // TODO: ERror in case the info cannot be written
                unc_image_info_write($image_file);
                $folder_percentage += $file_one_percent;
                $overall_percentage += $overall_one_percent;
            }
            $folder_percentage_text = intval($folder_percentage);
            $text = "Processing {$date}: <span class=\"file_progress\" style=\"width:{$folder_percentage_text}%\">{$folder_percentage_text} %</span>";
            unc_tools_progress_update($process_id, $text, $overall_percentage, $process_step_id);
        }
        $text = "Processing {$date}: <span class=\"file_progress\" style=\"width:100%\">100 %</span>";
        unc_tools_progress_update($process_id, $text, $overall_percentage, $process_step_id);
    }
    unc_tools_progress_update($process_id, "Done!", 100);
    // this signals to the JS function that we can terminate the process_get loop
    unc_tools_progress_update($process_id, false);
    wp_die();
}