<?php /*
phod.php3 version 1.0 - a PHP version of Personal Open Directory
by Angus D Madden of IMEXIS LLC (adm@imexis.com)
[see a working demo at http://ekilat.com/clean-phod.php3]
[source code is available at http://imexis.com/phod.php3.txt]
This software was created and is copyrighted 2000 by Angus D Madden of IMEXIS LLC
It is open source, meaning you should feel free to use it and modify it as you wish,
with the stipulation that the copyright message remains intact. Credit should be given to
J. Grohol http://www.grohol.com/ ,
R. Chiswell http://www.beebware.com/ and
R. Faulds http://www.computer-mentors.co.uk/download.html
whose POD script was the inspiration for this.
(POD + _extreme_ annoyance with Perl => phod.php3)
This software comes as is, with no warranties specified or implied. USE AT YOUR OWN RISK!
(read: if it works, cheers. if it doesn't, don't look at me.)
Security issues - All tags (PHP and HTML) are stripped from search input.
Validation - only one point here. depending on what version of PHP you
are using, it may add slashes to user input automatically. you will have
to strip not strip these accordingly.
Action - parse requesting url
send request to dmoz
make changes to page format
print results with header & footer
Requirements - This works with Apache and PHP 3.0.14. It didn't work
on a win98/onmiHTTPd/php 3.0.14 box. It didn't work with Apache and 3.0.12.
I guarantee it will not work for 3.0.6 or below.
(strip_tags() is really buggy - I've had this work on some machines and fail on others. ?)
Notes - As I am not a real programmer, I don't know if this is a resource
hog or not. If anyone has any tips or suggestions, let me know. I'd
be really happy if you sent me streamlined / more robust version of this script.
Wishlist - Maxcomm?
Logging of searches (not really necessary as they should be in your server logs)
The ability to drop the ? from the url (apparently apache should have no problems,
but I tried it and no luck)
When it's in original search mode, I defaulted the search box back to
the new search. It'd be nice if it could stay in original search mode.
*/
//******************************************************************************//
//CONFIGURATION VARIABLES! YOU CAN CHANGE THESE FREELY! $phod_title = "PHOD"; //what will you name your PHOD? $phod_header = ""; //this is the relative file path to a header file e.g. "header.html".
//control colors, fonts, etc, using this file and css.
//HEADER FILE MUST CONTAIN AT LEAST: <HTML><HEAD><TITLE></title></head><BODY>
$phod_footer = ""; //this is the relative file path to a footer file e.g. "footer.html".
//FOOTER FILE MUST CONTAIN AT LEAST: </body></html>
//if you leave the header and footer blank it will default to standard PHOD
$phod_table_color = "#dddddd"; //This replaces DMOZ's green color $phod_table2_color = "#eeeeee"; //THis replaces DMOZ's grey color
//******************************************************************************//
//ADVANCED CONFIGURATION. THINK TWICE BEFORE CHANGING THESE! $phod_url = $PHP_SELF; //this should be ok. If not, use the URL to your script. $debug = 0; //this is for debugging. 1 = On, 0 = Off. $odp_base = "http://dmoz.org/"; //the base url of the ODP (keep trailing slash)
$odp_search = "http://search.dmoz.org/cgi-bin/search"; //The url of ODP's search engine $odp_orig_search = "http://search.dmoz.org/cgi-bin/osearch"; //the url of ODP original search.
//NOW we're not playing around. Meddle below only if you know what you're doing
//***********************************************************************************// $REQUEST_URI = strip_tags($REQUEST_URI); $res = explode("phod.php3?", $REQUEST_URI); $odp_cat = $res[1];
if (substr($odp_cat,0,1) == "/") $odp_cat = substr($odp_cat,1);
else if (strstr($odp_cat, "asearch")) {
$requesturl = $odp_orig_search;
$requesturl .= strstr($REQUEST_URI,"?");
$requesturl = str_replace("?asearch","?a.x=0",$requesturl);
$cat = "search";
} else if (strstr($odp_cat, "osearch=")) {
$requesturl = $odp_orig_search;
$requesturl .= strstr($REQUEST_URI,"?");
$requesturl = str_replace("?osearch=","?search=",$requesturl);
$cat = "search";
} else if (strstr($odp_cat, "search=")) {
$requesturl = $odp_search;
$requesturl .= strstr($REQUEST_URI,"?");
$cat = "search";
}
if(!$cat) {
if (strstr($odp_cat, "where=")){
$cat = str_replace("where=","",strstr($odp_cat,"where="));
} else {
$cat = $odp_cat;
}
}
function top_of_page() {
global $HTTP_USER_AGENT;
global $cat;
global $phod_title;
global $phod_header;
if ($phod_header) {
include($phod_header);
} else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $phod_title;?> <? if($cat) echo " : ".str_replace("/"," : ",$cat);?></title>
</head>
<body>
<?php
}
}
function bot_of_page() {
global $phod_footer;
if ($phod_footer) {
include($phod_footer);
} else {
?> </body>
</html>
<?php
}
}
function body_of_page() {
//first, define all of our variables.
global $debug;
if($debug) echo "<h2 align=center>phod Debugging Mode</h2>n";
$phod_ver = "v1.0";
if($debug) echo '$phod_ver: '.$phod_ver."<br>n";
global $phod_table_color;
if($debug) echo '$phod_table_color: '.$phod_table_color."<br>n";
global $phod_table2_color;
if($debug) echo '$phod_table2_color: '.$phod_table2_color."<br>n";
$phod_copy = '<b><font face="verdana" size="1" color="#000077"><a href="http://imexis.com/phod.php3.txt">phod</a></b> '.$phod_ver.' is copyright © 2000 <a href="http://imexis.com/">angus d madden</a></font>';
if($debug) echo '$phod_copy: '.htmlspecialchars($phod_copy)."<br>n";
global $PHP_SELF;
if ($debug) echo '$PHP_SELF: '.$PHP_SELF."<br>n";
global $REQUEST_URI;
if($debug) echo '$REQUEST_URI: '.$REQUEST_URI."<br>n";
$allowed_tags = "<meta>,<a>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>,<br>,<ol>,<i>,<b>,<table>,<tr>,<td>,<form>,<p>,<center>,<small>,<input>,<select>,<option>,<ul>,<li>,<blockquote>";
if ($debug) echo '$allowed_tags: '.htmlspecialchars($allowed_tags)."<br>n";
global $phod_url;
if ($debug) echo '$phod_url: '.$phod_url."<br>n";
global $odp_base;
if ($debug) echo '$odp_base: '.$odp_base."<br>n";
global $odp_search;
if ($debug) echo '$odp_search: '.$odp_search."<br>n";
global $odp_orig_search;
if ($debug) echo '$odp_orig_search: '.$odp_orig_search."<br>n";
global $odp_cat;
if ($debug) echo '$odp_cat: '.$odp_cat."<br>n";
global $cat;
if ($debug) echo '$cat: '.$cat."<br>n";
global $requesturl;
if ($debug) echo '$requesturl: '.$requesturl."<br>";
//next, we call the appropriate page ay DMOZ
if (!$requesturl) $requesturl = $odp_base.$odp_cat;
if ($debug) echo '$requesturl: '.$requesturl."<br>";
if ($requesturl) {
$fp = fopen("$requesturl", "r");
if(!$fp) {
echo "error: could not open the url: $requesturl<br>n";
} else {
//fputs($fp,"$requesturl");
$line = "";
while(!feof($fp)) {
$line .= fgets($fp,256);
}
fclose($fp);
//first, take out the newlines - this way we don't get crossed tags.
$line = str_replace("n"," ",$line);
//take out the title
$line = eregi_replace("<title>.*</title>","",$line);
//Insert our copyright message
$line = ereg_replace("Copyright © [0-9]{4} Netscape",$phod_copy, $line);
//change <p> tags to <br>
$line = str_replace("<p>","<br><br>",$line);
$line = str_replace("<P>","<br><br>",$line);
//change <hr> to <br> as well
$line = str_replace("<hr>","<br><br>",$line);
$line = str_replace("<HR>","<br><br>",$line);
//remove all unwanted tags!
$line = strip_tags($line, $allowed_tags);
//customize colors
$line = str_replace("#669933",$phod_table_color,$line);
$line = str_replace("#cccccc",$phod_table2_color,$line);
//put the newlines back so I can see what's up
if ($debug) $line = str_replace("<br>","<br>n",$line);
//map urls back to our script (use ereg_replace ?);
//this is the only tricky part. some of the urls I mapped
//back to DMOZ to avoid the hassle.
$line = str_replace('href="/',"href="$phod_url?/", $line);
$line = str_replace($odp_base,"$phod_url?/",$line);
$line = str_replace('href="http://search.dmoz.org/cgi-bin/search?a.x=0"',"href="$phod_url?asearch"",$line);
$line = str_replace($odp_search."?search=","$phod_url?search=",$line);
$line = str_replace($odp_search,"$phod_url",$line);
$line = str_replace($odp_orig_search."?search=","$phod_url?osearch=",$line);
$line = str_replace($odp_orig_search,"$phod_url",$line);
$line = str_replace('ACTION="search"',"action="$phod_url"",$line);
$line = str_replace('href="search',"href="$phod_url",$line);
$line = str_replace('HREF="/cgi-bin/search?search=',"href="$phod_url?search=",$line);
$line = str_replace('HREF="osearch?search=',"href="$phod_url?osearch=",$line);
$line = str_replace('ACTION="osearch"',"action="$phod_url"",$line);
$line = str_replace('action="add2.cgi"',"action="".$odp_base."cgi-bin/add2.cgi"",$line);
$line = str_replace('action="update2.cgi"',"action="".$odp_base."cgi-bin/update2.cgi"",$line);
$line = str_replace('action="apply2.cgi"',"action="".$odp_base."cgi-bin/apply2.cgi"",$line);
$line = str_replace('action="forgot.cgi"',"action="".$odp_base."cgi-bin/forgot.cgi"",$line);
$line = str_replace('action="/cgi-bin/feedback2.cgi"',"action="".$odp_base."cgi-bin/feedback2.cgi"",$line);
$line = str_replace('href="desc.html"','href="'.$phod_url."?/".$odp_cat.'desc.html"',$line);
$line = str_replace('href="faq.html"','href="'.$phod_url."?/".$odp_cat.'faq.html"',$line);
$line = str_replace('HREF="/searchguide.html"','href="'.$phod_url.'?/searchguide.html"',$line);
$line = str_replace('HREF="searchguide.html"','href="'.$phod_url.'?/searchguide.html"',$line);
if ($debug) echo "<br>ODP output starts here---------------<br>nn";
echo $line;
if ($debug) echo "<br>ODP output ends here---------------<br>nn";
//add html required by licence of ODP DO NOT REMOVE!
?> <center>
<p><table border="0" bgcolor="#336600" cellpadding="3" cellspacing="0">
<tr>
<td>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr align="center">
<td><font face="sans-serif, Arial, Helvetica" size="2"
color="#FFFFFF">Help build the largest human-edited
directory on the web.</font></td></tr>
<tr bgcolor="#CCCCCC" align="center">
<td><font face="sans-serif, Arial, Helvetica" size="2"> <a
href="http://dmoz.org/cgi-bin/add.cgi?where=<?php echo $cat;?>">Submit
a Site</a> - <a href="http://dmoz.org/about.html"><b>Open Directory
Project</b></a> -
<a href="http://dmoz.org/cgi-bin/apply.cgi?where=<?php echo $cat;?>">Become
an Editor</a> </font>
</td></tr>
</table>
</td>
</tr>
</table>
</center>
<?
}
}
}
//include header top_of_page();
//send body body_of_page();
//close bot_of_page(); ?>
|
|