+ Reply to Thread
Results 1 to 7 of 7

Thread: Map of the site.

  1. #1
    Newbie SW-Demon is on a distinguished road
    Join Date
    Jun 2004
    Location
    Russia\\N.Novgorod
    Posts
    3

    Map of the site.

    It's userfull to add a special page to your site, called "the map of the site". It should contain hiperlinks to all pages of this site. Your visitors will be abble to see the whole contence of your site in the one place.

    The easiest way to make this page is to write an ordinary htm file. But it’s borring to add links to this page every time you update your site. Another way (that actually I’ve chossen for my site) is to write a php scritpt, that will list all files on your site and display titles of htm files and hyperlinks to them. I’m going to give ypur my script.

    My script has the following features:
    1. For htm files it displays the title (text between <title> and </title>) and give hyperlink.
    2. For zip, rar and exe it displays filename, size and gives hyperlink.
    3. Separates files into groups, how they are separated into directories
    4. Put “index.htm” of each directory in the top of the list.

    Here is the code:

    PHP Code:
    <?php

    //This function lists files in dir, specified by $path,
    //displays, what is supposed to be displayed,
    //and calls Work for $path’s subdirectories
    //(This function is recursive)
    //$depth==0 for the root directory, 1 for root’s
    //subdirectories, ect.

    function Work($path$depth)
    {
    //We are opening this dir
    if ( !($h opendir($path)) ) return 0;

    //Adding slash if it’s necessary
    if (substr($pathstrlen($path), 1)!="/"$path="${path}/";

    //Arrays, that will contain filenames
    //$fa – for files, $da – directories (folders)
    //$nf and $nd – number of items
    $fa=array(); $da=array();
    $nf=0$nd=0;

    //LISTING FILES AND FILLING THEM INTO $da AND $fa
    while (false !== ($name readdir($h)))
      {
       
    //Extra spacebars will do nothing good.
       
    $name=trim($name);
       
       
    //readdir will return “.” and “..” among
       //other directories. We don’t need them.
       
    if (($name!=".")&&($name!=".."))
         {
          
    $fullname="$path$name";
          
          
    //Is it directory?
          
    if (is_dir($fullname))
             {
    $da[$nd]=$fullname$nd++;}
          else
            {
             
    //And if it’s file, does it have
             //the proper extension?
             
    if(($ext=strtolower(strstr($name,".")))!=false)
                if ((
    $ext==".htm")||($ext==".html")||
                 (
    $ext==".php")||($ext==".asp")||
                 (
    $ext==".shtml")||($ext==".rar")||
                 (
    $ext==".zip")||($ext==".exe"))
                   {
    $fa[$nf]=$fullname$nf++;}
            }
         }
      }
    closedir($h);

    //DISPLAYING INFORMATION FOR FILES:
    //Putting “index.htm” to the first position.
    //$j – it’s current position
    //$j==1 no “index.htm”
    $j=-1;
    for (
    $i=0$i<$nf$i++)
      {
       
    $t=substr(strtolower(trim($fa[$i])),strlen($fa[$i])-9,9);
       if ( (
    $t=="index.htm") || ($t=="index.php")
        || (
    $t=="ndex.html") ) $j=$i;
      }
    if (
    $j>0) {$t=$fa[0]; $fa[0]=$fa[$j]; $fa[$j]=$t;}

    //Displaying...
    for ($i=0$i<$nf$i++)
      {
       
    //We’ll put spaces before the text,
       //depending on the $depth parametr
       
    for ($j=0$j<$depth$j++) echo("&nbsp&nbsp&nbsp");
       
       
    //is this file arhive of hipertext?
       
    $ext=strtolower(substr($fa[$i],strlen($fa[i])-3,3));
       if ((
    $ext=="zip")||($ext=="rar")||($ext=="exe"))
         {
          if ((
    $fsz=filesize($fa[$i]))!=false)
            {
             
    $fszk=round($fsz/"1024"); //it’s size
             
    echo("<a href=$fa[$i]$fa[$i] </a> - $fszk K <br>\r\n");
            }
         }
       else
         {
          
    //”index” should be bold
          //We’ll set $v param (bool)
          
    $t=substr(strtolower(trim($fa[$i])),
          
    strlen($fa[$i])-9,9);
          
    $v=( ($t=="index.htm") || ($t=="index.php") || ($t=="ndex.html") );
          
          
    //The key feature:
          //EXTRACTING TITLE FROM HTML
          //We’re going to look at each simbol one-by-one
          
          //Opening this file
          
    while ((file_exists($fa[$i]))&&(!is_readable($fa[$i])))
            {
             
    clearstatcache();
             
    sleep);
            }
          if (
    file_exists($fa[$i]))
            {
             
    $f=fopen($fa[$i],"r");
             
             
    $title=""$a=0;
             
    //$a==0 in regular text
             //$a==1 in tags (after '<')
             //$a==2 between <title> </title>
             //$title keeps title
             //$text (apears later) keeps the tag’s text
             
             //Let’s go!
             
    while (!feof($f))
               {
                
    //Working with simbol $s
                
    $s=fread($f,1);
                
                
    $b=$a;
                
    //$b keeps new value of $a
                
                
    if ($a==0//regular text
                  
    {
                   if (
    $s=="<"
                     {
                      
    //tag has started
                      
    $b=1$text="";
                     }
                  }
                if (
    $a==1//tag
                  
    {
                   if (
    $s==">")
                     {
                      
    //tag has ended
                      
    $temp=trimstrtolower($text) );
                      if (
    $temp=="title")
                        
    //it was <title>
                        
    {$title=""$b=2;}
                      else
                        {
                         if (
    $temp=="/title")
                            break; 
    //it was </title>
                         
    else $b=0// smth other
                        
    }
                     }
                      
    //$s isn’t ‘>’
                      //it should be added to $text
                      
    else {$text="$text$s";}
                  }
                if (
    $a==2//title
                  
    {
                   if (
    $s=="<") {$b=1$text="";}
                   else 
    $title="$title$s"
                  }
                
                
    $a=$b;
               }
              
    fclose($f); //at last!
              
              //if file has no title
              //we’ll write it’s name
              
    if (trim($title)==""$title=$fa[$i];
              
              
    //writing this f...ing title
              
    if ($v) echo ("<b> <font size=\"+1\">\r\n");
              echo(
    "<a href=$fa[$i]>$title</a> <br>\r\n");
              if (
    $v) echo ("</font> </b>\r\n");
             }
          }
       }

    if (
    $nf>0) echo ("<br>\r\n");

    if (
    $depth<20// we don’t need any endless loops
      
    {
       
    $d=$depth+1;
       for (
    $i=0$i<$nd$i++) Work($da[$i],$d);
      }

    //Work function has finished !!!

    //MAIN PROCEDURE:
    Work(".",0);

    //THE END.
    ?>
    Sorry, that it’s so complicated…

    Possible upgrades of this script:
    (it will we good to do, but I’m not so enthusiastic)
    1. Sorting files by titles.
    2. Special configuration files to hide some paths from listing
    3. Config files with commes for zip-s.

    You can see, how it works, here: http://x-and-s.km.ru/map.php But there everything is in Russian, sorry.

    That’s all. Your questions?

    P.S. Sorry for my poor english. I hope my teacher aren’t interested in PHP and will never read this. :-]

  2. #2
    Active Member the illest is on a distinguished road
    Join Date
    Jun 2004
    Posts
    152
    Works good.

    Another example.. in English.. www.theillest.net/map.php

    You should also make it where you can select subdirectores/pages that aren't included in the map.

  3. #3
    Full Member dzone is on a distinguished road
    Join Date
    Dec 2003
    Posts
    75
    That is a very nice script, but you should consider using remote fopen or curl to get the files' contents. This way your script will get the pages exactly as they are presented to the site visitors. Otherwise, your script is crawling plain source code. The problem is that most of sites features dynamic content, such as PHP/ASP/JSP/... and not only static HTML.

    Sure that'll be slower, but you can reindex the site manually, or, say put it to crontab.

  4. #4
    Newbie SW-Demon is on a distinguished road
    Join Date
    Jun 2004
    Location
    Russia\\N.Novgorod
    Posts
    3
    It also works correct if site contains PHP pages, specialy if your php pages contain <title> </title> outside <?php ?>.

  5. #5
    Newbie v3x0rg is on a distinguished road
    Join Date
    Jun 2004
    Posts
    4
    Yea, it might be a possible security risk.

  6. #6
    Full Member Neo Soul is on a distinguished road
    Join Date
    Oct 2004
    Posts
    6
    Ok i got it to work but it shows everything in my ftp, is there a way to stop it from showing everything?
    Last edited by Neo Soul; October 17th, 2004 at 08:53 PM.

  7. #7
    Full Member Neo Soul is on a distinguished road
    Join Date
    Oct 2004
    Posts
    6
    Hey i was able to munipulate the code a little to get it to show pictures. www.rappinlounge.com/images/map.php thats a test of it. Right now I'm trying to figure out how to get it to work in a table of 3 across and three down
    Hmmm.....Me Hungie

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts