PDA

View Full Version : How do I create "Site Index" using PHPDig ?


jimfletcher
03-21-2004, 09:30 PM
I notice in the /admin section that the script creates a hierarchical tree of the pages on the site.

Is it possible that someone has a method of doing something similar with the Page Title and URL to make a "Site Index" page? Either in a hierarchical tree, or alphabetical something like:
http://www.law.uga.edu/siteindex/index.html
would be great.

Jim

Charter
03-22-2004, 11:18 PM
Hi. Perhaps try a query like the following:

SELECT sites.site_url,spider.path,spider.file,spider.first_words FROM sites,spider WHERE sites.site_id = spider.site_id ORDER BY spider.first_words;

jimfletcher
03-23-2004, 07:58 PM
I wrote this script to create a hierarchy site index from a database that has fields for the URL and the Page Title

What is the best query to get just the URL and the Page Title from the PHPDig database?


<?
#Hierarchy Site Map
#siteindex.php
#3/23/2004

$myisserver="localhost";
$myisusername="your-mysql-db-username";
$myispassword="your-mysql-db-password";
$myisdb="your-mysql-db-name";

#DATABASE INITIALIZATION
$db = mysql_connect($myisserver,$myisusername,$myispassword); # Get Connection Settings From Config File
mysql_select_db($myisdb,$db); # Get Connection Settings From Config File
$sql = "SELECT url,pagetitle FROM sometable GROUP BY url ORDER by url";
# This script assumes urls stored as something like: /some/directory/structure
$result_id = mysql_query($sql);
$num = mysql_num_rows($result_id);
#
print "<ul>"; #Start the bullet list
for ($n = 0; $n<$num; $n++) {
list($path_name,$title)=mysql_fetch_row($result_id); #grab the URL and title from the MySQL result
$paths = explode('/',rawurldecode(rtrim($path_name, "/"))); #Trims any trailing slash. Then creates array of URL
$num_levels = count($paths); #counts directory levels in URL
if ($path_name=="") {
$num_levels = 1; #Kluge for the homepage so it shows up on same bullet level as main categories
}
if ($title!="") { #you can exempt something from the list by not giving it a title
$title = "<li>" . "<a href='".$urlroot . $path_name."'>" . $title . "</a></li>"; #set up the link
for ($a = 1; $a<$num_levels; $a++) {
$title = "<ul>" . $title . "</ul>"; #for every additional directory level down this link is, indent again
}
$title .= "\n"; #add a carriage return to keep the output neat
print $title; #show this bullet
}
}
print "</ul>"; #Close out the bullet list
?>

Charter
03-24-2004, 11:27 PM
Hi. TMTOWTDI, but here's one way to make a sitemap using info in the PhpDig tables.

<?php

define('PHPDIG_DB_PREFIX','prefix');
define('PHPDIG_DB_HOST','localhost');
define('PHPDIG_DB_USER','username');
define('PHPDIG_DB_PASS','password');
define('PHPDIG_DB_NAME','database');

$id_connect = mysql_connect(PHPDIG_DB_HOST,PHPDIG_DB_USER,PHPDIG_DB_PASS);
if (!$id_connect) {
die("Unable to connect to database.\n");
}

$db_select = mysql_select_db(PHPDIG_DB_NAME,$id_connect);
if (!$db_select) {
die("Unable to select the database.\n");
}

$query = mysql_query("SELECT ".PHPDIG_DB_PREFIX."sites.site_url,".
PHPDIG_DB_PREFIX."spider.path,".PHPDIG_DB_PREFIX."spider.file,".
PHPDIG_DB_PREFIX."spider.first_words FROM ".
PHPDIG_DB_PREFIX."sites,".PHPDIG_DB_PREFIX."spider WHERE ".
PHPDIG_DB_PREFIX."sites.site_id = ".PHPDIG_DB_PREFIX."spider.site_id ".
"ORDER BY ".PHPDIG_DB_PREFIX."sites.site_url,".
PHPDIG_DB_PREFIX."spider.path,".PHPDIG_DB_PREFIX."spider.first_words;");

$num = mysql_num_rows($query);
echo "<html><body><b>Sitemap</b><br><br>";
list($url,$path,$file,$words) = mysql_fetch_row($query);
$one_url = $url;
$one_path = $path;
echo $one_url.$one_path."<ul>";

for ($i=0; $i<$num; $i++) {
if (($one_url != $url) || ($one_path != $path)) {
$one_url = $url;
$one_path = $path;
echo "</ul>".$one_url.$one_path."<ul>";
}
$full_url = $url.$path.$file;
$words = explode("\n",$words);
if (strlen($words[0]) > 20) {
$part_words = substr($words[0],0,17)."...";
}
else {
$part_words = $words[0];
}
echo "<li><a href=\"$full_url\">$part_words</a>";
if ($i != $num-1) {
list($url,$path,$file,$words) = mysql_fetch_row($query);
}
}

echo "</ul></body></html>";

?>

Remember to remove any "word" wrapping in the above code.

majestique
04-16-2004, 03:14 PM
jimfletcher's code didn't work for me.. but charter's did

zaartix
07-14-2004, 05:56 AM
workink perfect for me :) thanks