Beispiel #1
0
function list_directory($display_name, $path)
{
    global $localconfig;
    // Allow local configuration file to override any of these globals.
    global $mimetype, $disposition, $cacheable, $ignore, $recurse, $indexfile;
    // And these locals.
    $title = '';
    $annotation = '';
    if (file_exists("{$path}/{$localconfig}")) {
        include "{$path}/{$localconfig}";
    }
    $handle = @opendir($path) or die("Directory {$display_name} not found.");
    $files = array();
    $subdirs = array();
    while ($entry = readdir($handle)) {
        if (is_indexfile($entry)) {
            closedir($handle);
            send_file("{$path}/{$entry}");
            return;
        } elseif ($entry != '..' && $entry != '.' && !is_ignored($entry)) {
            if (!is_dir("{$path}/{$entry}")) {
                $files[] = $entry;
            } elseif ($recurse) {
                $subdirs[] = $entry;
            }
        }
    }
    closedir($handle);
    sort_array($files);
    sort_array($subdirs);
    open_doc($title);
    announce_directory($display_name, $title, $annotation);
    print "<table width=\"100%\" border=0 cellspacing=1 cellpadding=2>\n";
    for ($s = reset($subdirs); $s; $s = next($subdirs)) {
        print_entry("{$s}/", '(dir)', '&nbsp');
    }
    for ($s = reset($files); $s; $s = next($files)) {
        print_entry($s, solidify(pretty_size(filesize("{$path}/{$s}"))), solidify(pretty_date(filemtime("{$path}/{$s}"))));
    }
    print "</table>\n";
    close_doc();
}
Beispiel #2
0
function analyze_essay($essay)
{
    $parsed = array();
    $wordbuff = "";
    $tot_lines = 0;
    $tot_letters = 0;
    $tot_str = 0;
    $tot_wt = 0;
    $newline = false;
    for ($i = 0; $i < strlen($essay); $i++) {
        $chr = ord($essay[$i]);
        if ($chr == 10) {
            // is the character a newline?
            if (!$newline) {
                $tot_lines++;
            }
            // count successive newlines as a single newline
            $newline = true;
        } else {
            $newline = false;
        }
        if (is_word_separator($chr)) {
            if (strlen($wordbuff) > 0) {
                $parsed[] = new wordProcessor($wordbuff);
            }
            $wordbuff = "";
        } else {
            if (!is_ignored($chr)) {
                $wordbuff .= $essay[$i];
            }
        }
    }
    // housekeeping if the essay does not end with a word separator
    if (strlen($wordbuff)) {
        $parsed[] = new wordProcessor($wordbuff);
        $tot_lines++;
    }
    $tot_words = count($parsed);
    if ($tot_words == 0) {
        echo "0|0|0|0|0|0|0";
        return;
    }
    foreach ($parsed as $word) {
        $tot_letters += $word->getLength();
        $tot_str += $word->getWordStrength();
        $tot_wt += $word->getWordWeight();
    }
    usort($parsed, "len_lex_sort");
    $analysis = "";
    $current = $parsed[0];
    $word_num = 1;
    $freq = 1;
    for ($i = 1; $i < count($parsed); $i++) {
        if ($parsed[$i]->getWord() != $current->getWord()) {
            $analysis .= "|" . $word_num . "," . $current->getWord() . "," . $current->getLength() . "," . $freq;
            $current = $parsed[$i];
            $word_num++;
            $freq = 1;
        } else {
            $freq++;
        }
    }
    $analysis .= "|" . $word_num . "," . $current->getWord() . "," . $current->getLength() . "," . $freq;
    // words|letters|lines|strength|weight|avg strength|avg weight
    echo $tot_words . "|" . $tot_letters . "|" . $tot_lines;
    echo "|" . $tot_str . "|" . $tot_wt;
    echo "|" . $tot_str / $tot_words . "|" . $tot_wt / $tot_words;
    echo $analysis;
}