Ejemplo n.º 1
0
/**
 * Make a list of all images in folder and subfolder
 *
 * @param type $path
 * @return type
 */
function unc_tools_import_enumerate($path)
{
    global $UNC_GALLERY;
    if ($UNC_GALLERY['debug']) {
        XMPP_ERROR_trace(__FUNCTION__, func_get_args());
    }
    if (!current_user_can('manage_options')) {
        return false;
    }
    foreach (glob($path . "/*") as $file) {
        if (is_dir($file)) {
            // recurse lower directory
            unc_tools_import_enumerate($file);
        } else {
            $UNC_GALLERY['import']['tmp_name'][] = $file;
            $UNC_GALLERY['import']['type'][] = mime_content_type($file);
            $UNC_GALLERY['import']['name'][] = basename($file);
            $UNC_GALLERY['import']['error'][] = 0;
        }
    }
}
Ejemplo n.º 2
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();
}