Jump to content

PHP Script to make directory


solicion

Recommended Posts

Dear @ll:

I'm desperatellt looking for a php script that assembles a directory/inventory of all the html documents that I have in the main folder. All documents hava a title and would like to appear in alphabetical order all documents (by title). Can anyone help me or mail me a suitable script please.

Best wishes,
Ivan from Chile
ivan_garcia@123mail.cl
Link to comment
Share on other sites

#!/usr/bin/perl
############################################################################
# Inhaltsverzeichnis ARE Erstellung: 24.02.98
# (c)1997 Update    : 22.04.98
############################################################################

############################################################################
# Variablen, ggf. anpassen
############################################################################
@referers = ('http://www.skagen.cl/are/','http://skagen.cl/are/');

$basedir = '/public_html/are/';
$baseurl = 'http://www.skagen.cl/are/';
$title = "ARE";
$title_url = 'http://skagen.cl/are/';

############################################################################
# Host checken
############################################################################
&check_url;
############################################################################
# Daten von Formular parsen
############################################################################
&parse_form;

############################################################################
# Dateien ermitteln
############################################################################
@files = ('*.html');


############################################################################
# Dateien lesen
############################################################################
&get_files;
############################################################################
# Suche starten
############################################################################
&search;
############################################################################
# HTML-Seite ausgeben
############################################################################
&return_html;
exit(0);


############################################################################
# Parsen der uebergebenen Daten aus Formular
############################################################################
sub parse_form {

$buffer = 'boolean=OR&case=Insensitive&terms=META';

  #read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  @pairs = split(/&/, $buffer);

  foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $FORM{$name} = $value;
  }
}


############################################################################
# Dateien einlesen
############################################################################
sub get_files {

  chdir($basedir);
  foreach $file (@files) {
      $ls = `ls $file`;
      @ls = split(/\s+/,$ls);
      foreach $temp_file (@ls) {
        if (-d $file) {
            $filename = "$file$temp_file";
                push(@FILES,$filename);
        }
        elsif (-T $temp_file) {
            push(@FILES,$temp_file);
        }
      }
  }
}


############################################################################
# Suche nach Vorgaben
############################################################################
sub search {

  @terms = split(/\s+/, $FORM{'terms'});

  foreach $FILE (@FILES) {

      open(FILE,"$FILE");
      @LINES = <FILE>;
      close(FILE);

      $string = join(' ',@LINES);
      $string =~ s/\n//g;
      if ($FORM{'boolean'} eq 'AND') {
        foreach $term (@terms) {
            if ($FORM{'case'} eq 'Insensitive') {
              if (!($string =~ /$term/i)) {
                  $include{$FILE} = 'no';
    last;
              }
              else {
                  $include{$FILE} = 'yes';
              }
            }
            elsif ($FORM{'case'} eq 'Sensitive') {
              if (!($string =~ /$term/)) {
                  $include{$FILE} = 'no';
                  last;
              }
              else {
                  $include{$FILE} = 'yes';
              }
            }
        }
      }
      elsif ($FORM{'boolean'} eq 'OR') {
        foreach $term (@terms) {
            if ($FORM{'case'} eq 'Insensitive') {
              if ($string =~ /$term/i) {
                  $include{$FILE} = 'yes';
                  last;
              }
              else {
                  $include{$FILE} = 'no';
              }
            }
            elsif ($FORM{'case'} eq 'Sensitive') {
              if ($string =~ /$term/) {
  $include{$FILE} = 'yes';
                  last;
              }
              else {
                  $include{$FILE} = 'no';
              }
            }
        }
      }
      if ($string =~ /<title>(.*)<\/title>/i) {
        $titles{$FILE} = "$1";
      }
  }
}



############################################################################
# HTML-Seite mit Daten ausgeben
############################################################################     
sub return_html {

    $gef = 0;

    print "Content-Type: text/html\n\n";
    $ausg1 = 'Sie finden hier eine alphabetische Auflistung aller ';
    $ausg1 .= 'Seiten. ';
    $ausg1 .= 'Dieses ist ein automatisch erstelltes Inhaltsverzeichnis. Ein ';
    $ausg1 .= 'erneutes Laden dieser Seite (Reload) ist daher nicht notwendig! ';
    $ausg .= "<UL>";
    $links = "";

    foreach $key (sort keys %include) {
if($titles{$key}) {
$gef++;
@liste[$gef] = substr($titles{$key},0,10)." <A HREF=\"$baseurl$key\">$titles{$key}</A>";
}
    }

    $i = 0;

    foreach $auslesen (sort @liste) {
if (! (substr($auslesen,0,1) eq $alphabet) ) {
$ausg .= '</UL><B>';
$links .= ' | <A HREF="#'.substr($auslesen,0,1);
$links .= '"><B>'.substr($auslesen,0,1);
$links .= '</B></A> ';
$ausg .= '<A NAME="'.substr($auslesen,0,1);
$ausg .='"><H4>'.substr($auslesen,0,1).'</H4></A>';
$ausg .= '</B>';
# $ausg .= '<A HREF="JavaScript:history.back()">Zurück zur vorhergehenden Seite</A>';
$ausg .= '<UL>';
$alphabet = substr($auslesen,0,1);
}

$ausg .= substr($auslesen,10).'<BR>';

    }

    $ausg .= '</UL><BR>';
    $ausg1 .= 'Es wurden '.$gef.' Seiten gefunden.<BR>';
    $ausg .= '<A HREF="JavaScript:history.back()">Zurück zur vorhergehenden Seite</A>';
    # $ausg .= '<HR></FONT>';
    print $ausg1;
    print "<HR>".$links."<BR><HR>";
    print $ausg;

}



############################################################################
# Pruefung auf Host der Anfrage
############################################################################
sub check_url {

  $check_referer = '0';

  if ($ENV{'HTTP_REFERER'}) {
      foreach $referer (@referers) {
        if ($ENV{'HTTP_REFERER'} =~ /$referer/i) {
            $check_referer = '1';
    last;
        }
      }
  }
  else {
      $check_referer = '1';
  }

  if ($check_referer != '1') {
      print "Content-type: ","text/html\n\n";
      print "<HTML><HEAD><TITLE>FEHLER</TITLE></HEAD><BODY>";
      print "<h2>Keine Zugangsberechtigung zur Suchfunktion!</h2><BR><BR><BR>";
      print "Dieser Service kann nur von skagen.cl/are aufgerufen werden - sorry...<BR>";
      print "</BODY></HTML>";
      exit(0);
  }

}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.