Exemplo n.º 1
0
function search()
{
    global $final_result;
    global $random_result;
    $files = glob(EXTRACTED_DATA_DIR . '*.revnews');
    foreach ($files as $file) {
        $content = load_json_data($file);
        search_in_file($content);
    }
    if ($random_result) {
        $rand_keys = array_rand($final_result, 10);
        $result = array();
        foreach ($rand_keys as $rand_key) {
            array_push($result, $final_result[$rand_key]);
        }
        print json_encode($result);
    } else {
        $final_result = array_slice($final_result, 0, 10);
        print json_encode($final_result);
    }
}
    if (!isset($_GET['dirs']) || !is_array($_GET['dirs'])) {
        $dirs = array();
    } else {
        $dirs = array_map('trim', $_GET['dirs']);
    }
    if ($dirs && count($dirs) != count($directories)) {
        $files_array = array();
        foreach ($dirs as $dir) {
            $files_array += dir_to_array($dir);
        }
    } else {
        $files_array = dir_to_array($current_dir);
    }
    $keyword = $_GET['keyword'];
    foreach ($files_array as $file) {
        $occurrences = search_in_file($file, $keyword);
        if (!$occurrences) {
            continue;
        }
        $found_in_files[] = array('filename' => basename($file), 'dirname' => str_replace($current_dir, '', dirname($file)), 'occurrences' => $occurrences, 'filesize' => filesize($file));
    }
}
# allowed sections
$sections = array('home', 'options', 'download');
if (!isset($_GET['section']) || !in_array($_GET['section'], $sections) || $_GET['section'] == 'home') {
    if (!isset($_GET['dirs']) || !is_array($_GET['dirs'])) {
        $dirs = array();
    } else {
        $dirs = array_map('trim', $_GET['dirs']);
    }
    $directories = array(-1 => '.') + $directories;