/**
	 * @see	wcf\system\ICronjob::execute()
	 */
	public function execute(Cronjob $cronjob) {
		$filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
		$xml = new XML();
		$xml->load($filename);
		
		$xpath = $xml->xpath();
		
		// fetch spiders
		$spiders = $xpath->query('/spiderlist/spider');
		
		if (!empty($spiders)) {
			// delete old entries
			$sql = "DELETE FROM wcf".WCF_N."_spider";
			$statement = WCF::getDB()->prepareStatement($sql);
			$statement->execute();
			
			$statementParameters = array();
			foreach ($spiders as $spider) {
				$identifier = StringUtil::toLowerCase($spider->getAttribute('ident'));
				$name = $xpath->query('name', $spider)->item(0);
				$info = $xpath->query('info', $spider)->item(0);
				
				$statementParameters[$identifier] = array(
					'spiderIdentifier' => $identifier,
					'spiderName' => $name->nodeValue,
					'spiderURL' => $info ? $info->nodeValue : ''
				);
			}
			
			if (!empty($statementParameters)) {
				$sql = "INSERT INTO	wcf".WCF_N."_spider
							(spiderIdentifier, spiderName, spiderURL)
					VALUES		(?, ?, ?)";
				$statement = WCF::getDB()->prepareStatement($sql);
				
				foreach ($statementParameters as $parameters) {
					$statement->execute(array(
						$parameters['spiderIdentifier'],
						$parameters['spiderName'],
						$parameters['spiderURL']
					));
				}
			}
			
			// clear spider cache
			SpiderCacheBuilder::getInstance()->reset();
		}
		
		// delete tmp file
		@unlink($filename);
	}
 /**
  * @see	\wcf\system\ICronjob::execute()
  */
 public function execute(Cronjob $cronjob)
 {
     $filename = FileUtil::downloadFileFromHttp('http://assets.woltlab.com/spiderlist/typhoon/list.xml', 'spiders');
     $xml = new XML();
     $xml->load($filename);
     $xpath = $xml->xpath();
     // fetch spiders
     $spiders = $xpath->query('/ns:data/ns:spider');
     if (!empty($spiders)) {
         $existingSpiders = SpiderCacheBuilder::getInstance()->getData();
         $statementParameters = array();
         foreach ($spiders as $spider) {
             $identifier = mb_strtolower($spider->getAttribute('ident'));
             $name = $xpath->query('ns:name', $spider)->item(0);
             $info = $xpath->query('ns:url', $spider)->item(0);
             $statementParameters[$identifier] = array('spiderIdentifier' => $identifier, 'spiderName' => $name->nodeValue, 'spiderURL' => $info ? $info->nodeValue : '');
         }
         if (!empty($statementParameters)) {
             $sql = "INSERT INTO\t\t\twcf" . WCF_N . "_spider\n\t\t\t\t\t\t\t\t\t(spiderIdentifier, spiderName, spiderURL)\n\t\t\t\t\tVALUES\t\t\t\t(?, ?, ?)\n\t\t\t\t\tON DUPLICATE KEY UPDATE\t\tspiderName = VALUES(spiderName),\n\t\t\t\t\t\t\t\t\tspiderURL = VALUES(spiderURL)";
             $statement = WCF::getDB()->prepareStatement($sql);
             WCF::getDB()->beginTransaction();
             foreach ($statementParameters as $parameters) {
                 $statement->execute(array($parameters['spiderIdentifier'], $parameters['spiderName'], $parameters['spiderURL']));
             }
             WCF::getDB()->commitTransaction();
         }
         // delete obsolete entries
         $sql = "DELETE FROM wcf" . WCF_N . "_spider WHERE spiderIdentifier = ?";
         $statement = WCF::getDB()->prepareStatement($sql);
         foreach ($existingSpiders as $spider) {
             if (!isset($statementParameters[$spider->spiderIdentifier])) {
                 $statement->execute(array($spider->spiderIdentifier));
             }
         }
         // clear spider cache
         SpiderCacheBuilder::getInstance()->reset();
     }
     // delete tmp file
     @unlink($filename);
 }
Пример #3
0
 /**
  * Returns the spider object
  * 
  * @return	\wcf\data\spider\Spider
  */
 public function getSpider()
 {
     if (!$this->spiderID) {
         return null;
     }
     if ($this->spider === null) {
         $spiderList = SpiderCacheBuilder::getInstance()->getData();
         $this->spider = $spiderList[$this->spiderID];
     }
     return $this->spider;
 }
Пример #4
0
 /**
  * Returns the spider id for given user agent.
  * 
  * @param	string		$userAgent
  * @return	mixed
  */
 protected function getSpiderID($userAgent)
 {
     $spiderList = SpiderCacheBuilder::getInstance()->getData();
     $userAgent = strtolower($userAgent);
     foreach ($spiderList as $spider) {
         if (strpos($userAgent, $spider->spiderIdentifier) !== false) {
             return $spider->spiderID;
         }
     }
     return null;
 }