-Implemented the use of the new XML API
authorOliver Kliebisch <oliver@kliebisch.net>
Mon, 29 Aug 2011 12:02:44 +0000 (14:02 +0200)
committerOliver Kliebisch <oliver@kliebisch.net>
Mon, 29 Aug 2011 12:02:44 +0000 (14:02 +0200)
-ToDo: The spiderlist doesn't use a XSD and no namespaces

wcfsetup/install/files/lib/system/cronjob/RefreshSearchRobotsCronjob.class.php

index a3873a3aa5dd0056fa77b2d50033c8ada0b6d37b..727feadda71791992ad5088e0e24def29fea54a4 100644 (file)
@@ -10,7 +10,7 @@ use wcf\util\XML;
 /**
  * Refreshes list of search robots.
  * 
- * @todo       Use new XML-API
+ * @todo       Add xsd to spiderlist on server
  * 
  * @author     Marcel Werk
  * @copyright  2001-2011 WoltLab GmbH
@@ -24,33 +24,31 @@ class RefreshSearchRobotsCronjob implements ICronjob {
         * @see wcf\system\ICronjob::execute()
         */
        public function execute(Cronjob $cronjob) {
-               /* $filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
-               $xml = new XML($filename);
-               $spiders = $xml->getElementTree('spiderlist');
+               $filename = FileUtil::downloadFileFromHttp('http://www.woltlab.com/spiderlist/spiderlist.xml', 'spiders');
+               $xml = new XML();
+               $xml->load($filename);
                
-               if (count($spiders['children'])) {
+               $xpath = $xml->xpath();
+               
+               // fetch spiders
+               $spiders = $xpath->query('/spiderlist/spider');         
+               
+               if (count($spiders)) {
                        // delete old entries
                        $sql = "DELETE FROM wcf".WCF_N."_spider";
                        $statement = WCF::getDB()->prepareStatement($sql);
                        $statement->execute();
                        
                        $statementParameters = array();
-                       foreach ($spiders['children'] as $spider) {
-                               $identifier = $spider['attrs']['ident'];
-                               
-                               // get attributes
-                               foreach ($spider['children'] as $values) {
-                                       $spider[$values['name']] = $values['cdata'];
-                               }
-                               
-                               $name = $spider['name'];
-                               $info = '';
-                               if (isset($spider['info'])) $info = $spider['info'];
+                       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[] = array(
-                                       'spiderIdentifier' => StringUtil::toLowerCase($identifier),
-                                       'spiderName' => $name,
-                                       'spiderURL' => $info
+                               $statementParameters[$identifier] = array(
+                                       'spiderIdentifier' => $identifier,
+                                       'spiderName' => $name->nodeValue,
+                                       'spiderURL' => $info ? $info->nodeValue : ''
                                );
                        }
                        
@@ -74,6 +72,6 @@ class RefreshSearchRobotsCronjob implements ICronjob {
                }
                
                // delete tmp file
-               @unlink($filename);*/
+               @unlink($filename);
        }
 }