- 论坛徽章:
- 0
|
小弟有一段代码看不明 ,望大虾们指点 谢谢
代码如下:
<?
class SpiderConfig
{
var $saveRootDirectory = ".";
var $mailtoLogFile = "mailto.txt";
var $refreshHTMLs = true;
var $refreshImages = false;
var $refreshOthers = false;
var $htmlExtensions = array("htm","html","shtml","php","asp","jsp","net","aspx") ;
var $imageExtensions = array("jpg","gif","png");
var $startLocation;
var $urlMatch = "";
var $interestingURLSubstrings = array();
var $boringURLSubstings = array();
var $depthFirst = false;
var $maxDepth = 0;
var $userAgent = "Weblech Spider ";
var $basicAuthUser = "";
var $basicAuthUserPassworc = "";
var $checkPointInterval = 0;
function SpiderConfig($props)
{
$this->saveRootDirectory = $props->getItem("saveRootDirectory");
if(!is_dir($this->saveRootDirectory))
{
if(!mkdir($this->saveRootDirectory))
{
echo "<br>Couldn't create root directory:"+$this->saveRootDirectory;
$this->saveRootDirectory = ".";
}
}
$mailtoFileStr = $props->getItem("mailtoLogFile");
if(strstr($mailtoFileStr,":")!=false||substr($mailtoFileStr,0,1)=="/"||substr($mailtoFileStr,0,1)=="\\")
{
echo "<br>Using absolute file name ".$mailtoFileStr;
$fp = fopen($mailtoFileStr,"w");
fclose($fp);
}
else
{
echo "<br>Construction relative file name ".$this->saveRootDirectory."/".$mailtoFileStr;
$fp = fopen($this->saveRootDirectory."/".$mailtoFileStr,"w");
fclose($fp);
}
$this->refreshHTMLs = ($props->getItem("refreshHTMLs"));
$this->refreshImages = ($props->getItem("refreshImages"));
$this->refreshOthers = ($props->getItem("refreshOthers"));
$this->htmExtensions = $this->parseSet($props->getItem("htmlExtensions"));
$this->imageExtensions = $this->parseSet($props->getItem("imageExtensions"));
$startLocStr = $props->getItem("startLocation");
if($startLocStr)
{
$this->startLocation = $startLocStr;
}
else
{
echo "<br>startLocation not found in properities";
}
$this->urlMatch = $props->getItem("urlMatch");
$this->interestingURLSubstrings = $this->parsePropCommaSepareted($props->getItem("interestingURLs"));
$this->boringURLSubstrings = $this->parsePropCommaSepareted($props->getItem("boringURLs"));
$this->depthFirst = $props->getItem("depthFirst");
$this->maxDepth = $props->getItem("maxDepth");
$this->userAgent = $props->getItem("userAgent");
$this->basicAuthUser = $props->getItem("basicAuthUser");
$this->basicAuthPassword = $props->getItem("basicAuthPassword");
$this->checkpointInterval = $props->getItem("checkpointInterval");
}
function parsePropCommaSepareted($str)
{
$result = array();
if($str!=""&&strlen($str))
{
$result = explode(",",$str);
}
return $result;
}
function setRefreshHTMLs($refreshHTMLs)
{
$this->refreshHTMLs= $refreshHTMLs;
}
function refreshHTMLs()
{
return $this->refreshHTMLs;
}
function setRefreshImages($refreshImages)
{
$this->refreshImages = $refreshImages;
}
function refreshImages()
{
return $this->refreshImages;
}
function setRefreshOthers($refreshOthers)
{
$this->refreshOthers = $refreshOthers;
}
function refreshOthers()
{
return $this->refreshOthers;
}
function setSaveRootDirectory($saveRootDirectory)
{
$this->saveRootDirectory = $saveRootDirectory;
}
function getSaveRootDirectory()
{
return $this->saveRootDirectory;
}
function setMailtoLogFile($mailtoLogFile)
{
$this->mailtoLogFile = $mailtoLogFile;
}
function getMailtoLogFile()
{
return $this->mailtoLogFile;
}
function setStartLocation($startLocation)
{
$this->startLocation = $startLocation;
}
function getStartLocation()
{
return $this->startLocation;
}
function setURLMatch($urlMatch)
{
$this->urlMatch = $urlMatch;
}
function getURLMatch()
{
return $this->urlMatch;
}
function getInterestingURLSubstrings()
{
return $this->interestingURLSubstrings;
}
function setInterestingURLSubstings($interestingURLSubstrings)
{
$this->interestingURLSubstrings = $interestingURLSubstrings;
}
function getBoringURLSubstrings()
{
return $this->boringURLSubstrings;
}
function setBoringURLSubstings($boringURLSubstrings)
{
$this->boringURLSubstrings = $boringURLSubstrings;
}
function isInteresting($u)
{
return $this->matchURL($u,$this->interestingURLSubstrings);
}
function isBoring($u)
{
return $this->matchURL($u,$this->boringURLSubstrings);
}
function matchURL($u,$substrings)
{
$url = $u->getURL();
foreach($substrings as $value)
{
if(strstr($url,$value)!=false)
{
return true;
}
}
return false;
}
function setDepthFirstSearch($depthFirst)
{
$this->depthFirst = $depthFirst;
}
function isDepthFirstSearch()
{
return $this->depthFirst;
}
function setMaxDepth($maxDepth)
{
$this->maxDepth = $maxDepth;
}
function getMaxDepth()
{
return $this->maxDepth;
}
function setUserAgent($userAgent)
{
$this->userAgent = $userAgent;
}
function getUserAgent()
{
return $this->userAgent;
}
function setBasicAuthUser($basicAuthUser)
{
$this->basicAuthUser = $basicAuthUser;
}
function getBasicAuthUser()
{
return $this->basicAuthUser;
}
function setBasicAuthPassword($basicAuthPassword)
{
$this->basicAuthPassword = $basicAuthPassword;
}
function getBasicAuthPassword()
{
return $this->basicAuthPassword;
}
function setCheckpointInterval($checkpointInterval)
{
$this->checkpointInterval = $checkpointInterval;
}
function getCheckpointInterval()
{
return $this->checkpointInterval;
}
function toString()
{
return ;
}
function parseSet($str)
{
echo "<br>parseSet(".$str.")";
$result =explode($str,",");
return $result;
}
function fromSet($s)
{
if(is_array($s))
{
return implode(",",$s);
}
return "";
}
}
?> |
|