Solved

SITEMAP FROM FOLDERS and HTML files

Posted on 2004-04-25
6
186 Views
Last Modified: 2009-07-29
How can I make a sitemap based on the folder stucture. The contents should be down the screen and split across multiple pages if posssible. HTML ouput strictly.

TITLE DESCRIPTION AND METATAGS should be included if at all possible %TAGS% with str_replace would be good. So its easier on layout.

best regards

PS if yer need the templates preped for yer and some snippets of code to cut yer time down thats not a prob.

$fp=fopen('sitemap.html');
        $sitemap=fread($fp,filesize ('sitemap.html'));
        fclose($fp);

if yer can use explode split by 20 links per page that output be most useful I have then numbering code below for you

$template = explode('<!--BEGIN-->',$sitemap);
$template = explode('<!--END-->',$tmp[1]);

add a count with that use a STR_replace for the above code should be fine
for($=1 $i<$pages; $i++){

$template=str_replace('%SITE%',$pages,$sitemap); or along those lines
fwrite($fpsitemap,stripslashes($tmp));

I think thats most of it might need to obstart it ob_ end_clean it with include the actual sitemap code itself keep them seperate if you can. One is for the reading and writing the other is the generation part.  Same for pagenumebering bottom of page for code

If yer need more info on layouts or design

index.html/folder/name-1.html-------- then lots of html pages here thats the site structure through out. around a couple of hundered foldres so spilting it over many pages would be ideal )
                               ) they will be linked together
                               )
sitemap.html/sitemap/then all files etc but must link to the above structure actual direct links with domain would have to be needed www.domain.com/index.html/folder/ etc etc (or maybe theres a better way)

index numrbering below

<?php

$start=$i;

echo "page $start of $nindexes<br>\n";
$prev = $start-1;
$range = $start-3;
$next = $start+1;

if($start > 1) {
    echo "<a href=\"$name-1.html\">First</a> <a href=\"$name-$prev.html\">Prev</a> ";
     if($start > 3){
          echo "[<a href=\"$name-$range.html\">$range</a>] ";
     }
     $range += 1;
     if($start > 2){
          echo "[<a href=\"$name-$range.html\">$range</a>] ";
     }
     echo "[<a href=\"$name-$prev.html\">$prev</a>] ";
}
echo "<strong>[$start]</strong> ";
if($start < $nindexes) {
    echo "[<a href=\"$name-$next.html\">$next</a>] ";
    $range = $next+1;
    if($start < ($nindexes-2)){
         echo "[<a href=\"$name-$range.html\">$range</a>] ";
    }
    $range += 1;
    if($start < ($nindexes-3)){
         echo "[<a href=\"$name-$range.html\">$range</a>] ";
    }
    echo "<a href=\"$name-$next.html\">Next</a> <a href=\"$name-$nindexes.html\">Last</a>";
}
?>

best regards
0
Comment
Question by:playstat
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
eeBlueShadow earned 500 total points
ID: 10911626
OK, I'll start this off by trying code for collecting the information, rather than formatting it in any way.

The following code will take a text file containing one URL per line, and scan each of those files for <title> and <meta> tags.
At the moment, the code puts everything in an array for you to do what you want with it, let me know if you need more help after that:

<!--START CODE-->
<pre>
<?php
// this is the name of the file with the list of URLs
$pagesFile = "files.txt";

// Collect the list of URLs into a list
$pages = file($pagesFile);
// and strip the newline character from each of them
foreach($pages as $i=>$v) $pages[$i] = rtrim($v);

$sitemap = array();
foreach($pages as $page)
{
    $thisPage = array();
    $thisPage['url'] = $page;
    // This is the line which grabe the text of each page
    $content = file_get_contents($page);

    // Grab the page title
    if(preg_match("#<title>(.*)</title>#i", $content, $titleMatch))
      $thisPage['title'] = $titleMatch[1];
    else
      $thisPage['title'] = "[No Title]";

    // Grab the meta tags
    if(preg_match_all("#<meta.+(name|http-equiv)=['\"]([^'\"]*)['\"].+content=['\"]([^'\"]*)['\"][^>]*>#i", $content, $metaMatch,PREG_SET_ORDER))

    // Collate the meta tags into the new page array
    foreach($metaMatch as $m)
    {
      $thisPage['meta'][$m[2]] = $m[3];
    }

    $sitemap[] = $thisPage;
}

print_r($sitemap);

?>
</pre>
<!--END CODE-->

At the moment, this code does nothing in the way of writing anything pretty to screen or making other files, let me know if it's the kind of direction you want though...
0
 
LVL 10

Expert Comment

by:eeBlueShadow
ID: 10911628
One thing to mention is that tat code may take a while to run, it may have to load a number of files which is a time consuming task
0
 

Author Comment

by:playstat
ID: 10927793
yer thats perfect eeblueshadow.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:playstat
ID: 10927804
If yer can output it with %tags% i think i can put the rest together and integrate it with the script
0
 
LVL 10

Expert Comment

by:eeBlueShadow
ID: 10928589
Well now all of the information you need is sat in the array, everything from here on is presentation, and that depends on how your site works.

What you can do with this script will be that it writes to static files (which are the files you will link to as sitemap.html).
The %tags% you keep referring to seem to hint about a template system or similar, which probably refers to custom written code that isn't standard to PHP. So, without knowing the format of the code there isn't that much I can do.

If you can give me an example of how you want the final sitemap.html to look then I can probably sort this. If I'm right in guessing that the HTML from sitemap.html is read into another page and altered to make your final output, just give me an example of the original page before it is altered.

Otherwise if I'm way off the mark, let me know

_Blue
0
 

Author Comment

by:playstat
ID: 10935024
yer its a basic html page ive added the tags on the page where ever. read it str_replace it then fwrite it to whatever format if looped over many pages / the content text files. Its all down to this simple system but all files are written in HTML or and php. I havent used smarty to keep it lean as possible. And html only as no code resides on the server or/and on the pages if they fail. (they are all encrypted with 24levels of scrambled code. the fastest php scripts going to. Ive managed to take 15gig of php files down to 6gig. Approx 60 percent. and the lowest server overhead I can get.

by the way blue if yer want your files protected I can help you there after all the effort you have done :0)

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now