EDIT THIS + edit the files in /includes/ to change its look! * If you have questions visit http://www.bie.no/forum and post them in the phpODP support forum! * */ $show_thumbnails = false; // set this to true if you want to show thumbnails $browse_cache = true; // cache user browsing? (will speed up your directory much) - keep this enabled, as it will take a huge load off dmoz's servers. $search_cache = true; // cache user searches as well? - disk space usage will increase $cache_timeout = 0; // seconds passed before updating cache .. 60*60*24*7 = 604800 = 7 days before cache is updated .. // set cache_timeout to 0 if you do not want the cache to be updated ever (or when you delete the files manually) $cache_folder = "cache"; // if you don't want users to be able to browse your cache, change this to something .. strange :) $use_portal_page = true; // set this to true if you want to make all links in your directory to go through go.php $adult_filter = true; // block the /Adult/ category and searches listed below? (remember, the open directory contains lots of adult material!) $illegalwords = array("xxx", // if adult_filter (above) is true, then the search words in this array will be blocked "porn", "pussy", "tgp"); // English users set this to "en" to show amazon.com link // German users set it to "de" to show amazon.de link // If you do not want to show the amazon table just leave them blank ("") $show_search_sponsor = ""; $show_browse_sponsor = ""; /** * ODP root URL - this is the url the data will be retreived from. * * Note; some people say they need to change this do http://www.dmoz.org/ to make it work on their php config */ $rooturl = "http://www.dmoz.org"; // If you want so use a certain category at the root .. // eg. $rootcategory = "/World/Deutsch/"; to show German pages, or "/World/Franais/" to start in the French category $rootcategory = ""; /* * STOP --- > EDITING BELOW SHOULD NOT BE NECESSARY (but could be if externals are changed) */ // This is the string that shows when dmoz is under heavy load. The script will know not to cache this since the original page should be retrieved later on. $donotcache = "The Open Directory search is currently under a heavy load. Please try back later."; global $myrooturl,$searchstring,$filename,$donotcache; $filename = $HTTP_SERVER_VARS['PHP_SELF']; ?> "; // end str to search for on the main page $startbrws = "
"; // start str to search for when browsing $endbrws = '= 128 && $unicode < 2048) { $binVal = str_pad (decbin ($unicode), 11, "0", STR_PAD_LEFT); $binPart1 = substr ($binVal, 0, 5); $binPart2 = substr ($binVal, 5); $char1 = chr (192 + bindec ($binPart1)); $char2 = chr (128 + bindec ($binPart2)); $utf8Substring = $char1 . $char2; } else if ($unicode >= 2048 && $unicode < 65536) { $binVal = str_pad (decbin ($unicode), 16, "0", STR_PAD_LEFT); $binPart1 = substr ($binVal, 0, 4); $binPart2 = substr ($binVal, 4, 6); $binPart3 = substr ($binVal, 10); $char1 = chr (224 + bindec ($binPart1)); $char2 = chr (128 + bindec ($binPart2)); $char3 = chr (128 + bindec ($binPart3)); $utf8Substring = $char1 . $char2 . $char3; } else { $binVal = str_pad (decbin ($unicode), 21, "0", STR_PAD_LEFT); $binPart1 = substr ($binVal, 0, 3); $binPart2 = substr ($binVal, 3, 6); $binPart3 = substr ($binVal, 9, 6); $binPart4 = substr ($binVal, 15); $char1 = chr (240 + bindec ($binPart1)); $char2 = chr (128 + bindec ($binPart2)); $char3 = chr (128 + bindec ($binPart3)); $char4 = chr (128 + bindec ($binPart4)); $utf8Substring = $char1 . $char2 . $char3 . $char4; } if (strlen ($nonEntity) > 1) $nonEntity = substr ($nonEntity, 1); // chop the first char (';') else $nonEntity = ''; $utf8Str .= $utf8Substring . $nonEntity; } else { $utf8Str .= $subStr; } } return $utf8Str; } /** * urlencode the link */ function linkencode($url) { $odpurl = urlencode($url); return str_replace ( array("%2F", "%26","%3A", "%3F", "%3D", "%2C"), array("/","&",":","?","=",",") , $odpurl); } /** * Make sure incomming $browse variable is 'clean' */ function cleanBrowse($browse) { if($browse == "/") return ""; else if($browse[0] != "/") return ""; // browse variable should always start with a slash else { if(get_magic_quotes_gpc()) { return htmlspecialchars(stripslashes($browse)); } else { return htmlspecialchars($browse); } } } /** * Make sure incomming search variable is 'clean' */ function cleanSearch($search) { return strip_tags($search); } /** * Will display an error message to the webmaster */ function errorMsg( $msg ) { echo "
"; echo "
Attention webmaster:

"; echo "$msg"; echo "
"; } /** * Will read data from dmoz, or the local cache (if enabled) */ function readData( $odpurl, $enable_cache ) { global $cache_folder, $cache_timeout; if($enable_cache) { $filename = md5($odpurl); $fullpath = $cache_folder."/".$filename; if(file_exists($fullpath)) { // already cached if($cache_timeout == 0) { $odpurl = $fullpath; } else { $diff = time()-filemtime($fullpath); if($diff > $cache_timeout) { $savecache = true; } else { $odpurl = $fullpath; } } } else { $savecache = true; } } if((@$fp = fopen( $odpurl, "r" )) != false) { $html = join( "", file( $odpurl ) ); fclose ( $fp ); if($html != "" && $savecache) { if(strpos($html, $donotcache) === false) { // don't cache if this is the 'ODP under heavy load' message if((@$cf = fopen( $fullpath, "w" )) != false) { fwrite($cf, $html); fclose( $cf ); } else { errorMsg("Error writing to cache!
Make sure the cache folder exists and is writeable by this script (you may also disable the cache)"); } } } } else { errorMsg("Error reading data from dmoz. This may be caused by the fact that you do not have access to use fopen() in this way.
Or it may be because the dmoz url is incorrect.

See discussion here for more info!"); } return $html; } /**************************************************************************** * Main script start ****************************************************************************/ set_error_handler("error_handler"); $browse = cleanBrowse($HTTP_GET_VARS["browse"]); if($rootcategory != "" && $browse == "" && $search == "") $browse = $rootcategory; $ver = $HTTP_GET_VARS["ver"]; $searchstring = $HTTP_POST_VARS["search"]; if($searchstring == "") $searchstring = $HTTP_GET_VARS["search"]; $searchstring = cleanSearch($searchstring); $start = intval($HTTP_GET_VARS["start"]); $morecat = htmlspecialchars($HTTP_GET_VARS["morecat"]); /** * Check for adult content ?? */ if($adult_filter) { if( $browse != "") { $catarr = explode("/", $browse); $i=0; while($catarr[$i] == "") $i++; if(strtolower($catarr[$i]) == "adult") { include("includes/blocked.php"); die(); } } else if($searchstring != "") { if(in_array(strtolower($searchstring), $illegalwords)) { include("includes/blocked.php"); die(); } } } if( $browse != "" ) { // the user is browsing the categories include("includes/browse_header.php"); if($show_browse_sponsor != "") include("includes/" . $sponsor_file_browse); $browselink = linkencode($rooturl.$browse); $html = readData($browselink, $browse_cache); if($html != "") { $startpos = strpos( $html, "[ (.*)(.*).$", $curline, $info)) { $url = $info[1]; $title = $info[2]; $desc = $info[3]; if(eregi("(.*)" ."
  • $title - $desc." .""; } else { echo $curline; } } else { echo $curline; } } } else { echo $html; } } else { // open failed include("includes/404.php"); } include("includes/browse_footer.php"); } else if( $searchstring != "" ) { // the user is searching $all = $HTTP_POST_VARS["all"]; $cat = $HTTP_POST_VARS["cat"]; include("includes/search_header.php"); if($show_search_sponsor != "" ) include("includes/" . $sponsor_file_search); $searchurl = linkencode($searchurl . $searchstring . "&all=$all&cat=$cat" . ($start == "" ? "" : "&start=" . $start ) . ($morecat == "" ? "" : "&morecat=" . $morecat)); $html = readData( $searchurl, $search_cache ); if( strpos( $html, $noresult) != FALSE ) { // no results found include("includes/search_no_result.php"); } else { $startpos = strpos( $html, $startsrch ); $html = substr( $html, $startpos, strlen($html)); $endpos = strpos( $html, $endsrch ); $html = substr( $html, 0, $endpos ); $html = str_replace( $linkstr . "/", $linkstr . $replace . "/", $html ); $html = str_replace( "http://dmoz.org", "$filename?browse=", $html ); $html = str_replace( $search_next, $search_next_replace, $html ); $html = str_replace( $filename . '?browse=search?', $filename . '?', $html ); $html = str_replace( '(.*) - (.*)", $curline, $info)) { $url = $info[1]; $title = $info[2]; $desc = $info[3]; if(eregi("(.*)" ."
  • $title - $desc." .""; } else { echo $curline; } } else { echo $curline; } } } else { echo $html; } } include("includes/search_footer.php"); } else { // show main page include("includes/main_header.php"); $html = readData($rooturl, $browse_cache); $startpos = strpos( $html, $startstr ); $html = substr( $html, $startpos, strlen($html)); $endpos = strpos( $html, $endstr ); $html = substr( $html, 0, $endpos ); $html = str_replace( $linkstr , $linkstr . $replace, $html ); $html = str_replace( '