Пример #1
0
function recursiveScan($path, $query)
{
    global $WOTD_IMAGE_DIR, $EXTENSIONS, $IGNORED_DIRS;
    $files = scandir($path);
    $results = array();
    foreach ($files as $file) {
        if (in_array($file, $IGNORED_DIRS)) {
            continue;
        }
        $full = "{$path}/{$file}";
        if (is_dir($full)) {
            $results = array_merge($results, recursiveScan($full, $query));
        } else {
            $extension = pathinfo(strtolower($full), PATHINFO_EXTENSION);
            if (in_array($extension, $EXTENSIONS)) {
                $candidate = substr($full, strlen($WOTD_IMAGE_DIR) + 1);
                $regexp = '/' . str_replace('/', "\\/", $query) . '/i';
                if (preg_match($regexp, $candidate)) {
                    $results[] = $candidate;
                }
            }
        }
    }
    return $results;
}
Пример #2
0
function recursiveScan($dir)
{
    global $cfg;
    $entries = @scandir($dir) or exit('Failed to open directory:<br>' . htmlentities($dir));
    foreach ($entries as $entry) {
        if ($entry[0] != '.' && !in_array($entry, array($cfg['exclude_script'], 'lost+found', 'Temporary Items', 'Network Trash Folder', 'System Volume Information', 'RECYCLER', '$RECYCLE.BIN'))) {
            if (is_dir($dir . $entry . '/')) {
                recursiveScan($dir . $entry . '/');
            } else {
                $extension = substr(strrchr($entry, '.'), 1);
                $extension = strtolower($extension);
                if (in_array($extension, $cfg['script'])) {
                    $file = $dir . $entry;
                    $input_script = file_get_contents($file);
                    $output_script = str_replace($cfg['input_line_break'], $cfg['output_line_break'], $input_script);
                    if ($input_script != $output_script) {
                        echo '<strong>Convert:</strong> ' . htmlentities($file) . '<br>';
                        file_put_contents($file, $output_script);
                    } else {
                        echo '<strong>No convertion needed:</strong> ' . htmlentities($file) . '<br>';
                    }
                    @ob_flush();
                    flush();
                }
            }
        }
    }
}
Пример #3
0
function recursiveScan($path, $logFile)
{
    global $IGNORED_DIRS, $EXTENSIONS, $beforeBytes, $afterBytes;
    $files = scandir($path);
    foreach ($files as $file) {
        if (in_array($file, $IGNORED_DIRS)) {
            continue;
        }
        $full = "{$path}/{$file}";
        if (is_dir($full)) {
            recursiveScan($full, $logFile);
        } else {
            $extension = pathinfo(strtolower($full), PATHINFO_EXTENSION);
            $fullNoExt = substr($full, 0, strlen($full) - strlen($extension) - 1);
            // Strip the dot as well
            if (in_array($extension, $EXTENSIONS)) {
                OS::executeAndAssert("convert -strip '{$full}' '" . Config::get('global.tempDir') . "/fileNoExif.{$extension}'");
                OS::executeAndAssert("convert '" . Config::get('global.tempDir') . "/fileNoExif.{$extension}' '/fileNoExifPng.png'");
                OS::executeAndAssert("optipng '" . Config::get('global.tempDir') . "/fileNoExifPng.png'");
                $fs1 = filesize($full);
                $fs2 = filesize(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
                $fs3 = filesize(Config::get('global.tempDir') . '/fileNoExifPng.png');
                $beforeBytes += $fs1;
                if ($fs3 < $fs1 && $fs3 < $fs2) {
                    $compression = 100.0 * (1 - $fs3 / $fs1);
                    $afterBytes += $fs3;
                    fprintf($logFile, "%s -- Strip EXIF, convert to PNG and optimize: %d/%d bytes, %.2f%% saved\n", $full, $fs3, $fs1, $compression);
                    unlink($full);
                    unlink(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
                    rename(Config::get('global.tempDir') . '/fileNoExifPng.png', "{$fullNoExt}.png");
                } else {
                    if ($fs2 < $fs1) {
                        $compression = 100.0 * (1 - $fs2 / $fs1);
                        $afterBytes += $fs2;
                        fprintf($logFile, "%s -- Strip EXIF: %d/%d bytes, %.2f%% saved\n", $full, $fs2, $fs1, $compression);
                        unlink($full);
                        rename(Config::get('global.tempDir') . "/fileNoExif.{$extension}", $full);
                        unlink(Config::get('global.tempDir') . '/fileNoExifPng.png');
                    } else {
                        $afterBytes += $fs1;
                        fprintf($logFile, "{$full} -- leave unchanged\n");
                        unlink(Config::get('global.tempDir') . "/fileNoExif.{$extension}");
                        unlink(Config::get('global.tempDir') . '/fileNoExifPng.png');
                    }
                }
            }
        }
    }
}
Пример #4
0
function recursiveScan($dir)
{
    global $cfg, $db;
    $album_id = '';
    $file = array();
    $filename = array();
    $entries = @scandir($dir) or message(__FILE__, __LINE__, 'error', '[b]Failed to open directory:[/b][br]' . $dir . '[list][*]Check media_dir value in the config.inc.php file[*]Check file permission[/list]');
    foreach ($entries as $entry) {
        if ($entry[0] != '.' && !in_array($entry, array('lost+found', 'Temporary Items', 'Network Trash Folder', 'System Volume Information', 'RECYCLER', '$RECYCLE.BIN'))) {
            if (is_dir($dir . $entry . '/')) {
                recursiveScan($dir . $entry . '/');
            } else {
                $extension = substr(strrchr($entry, '.'), 1);
                $extension = strtolower($extension);
                if (in_array($extension, $cfg['media_extension'])) {
                    $file[] = $dir . $entry;
                    $filename[] = substr($entry, 0, -strlen($extension) - 1);
                } elseif ($extension == 'id') {
                    $album_id = substr($entry, 0, -3);
                }
            }
        }
    }
    if (count($file) > 0) {
        mysql_query("UPDATE album_id SET \n\t\tupdated\t\t= '1'\n\t\tWHERE \n\t\tpath\t\t= '" . mysql_real_escape_string($dir) . "'\n\t\tLIMIT 1");
        if (mysql_affected_rows($db) == 0) {
            if ($album_id == '') {
                $album_id = base_convert(uniqid(), 16, 36);
            }
            $album_add_time = time();
            mysql_query("INSERT INTO album_id (album_id, path, album_add_time, updated) VALUES\n\t\t\t('" . mysql_real_escape_string($album_id) . "','" . mysql_real_escape_string($dir) . "','" . $album_add_time . "','1')");
        } else {
            $ids = mysql_query("SELECT album_id, album_add_time FROM album_id WHERE\n\t\t\tpath = '" . mysql_real_escape_string($dir) . "' LIMIT 1");
            $row = mysql_fetch_assoc($ids);
            $album_id = $row["album_id"];
            $album_add_time = $row["album_add_time"];
        }
        fileStructure($dir, $file, $filename, $album_id, $album_add_time);
    }
}