Changeset 6806

Show
Ignore:
Timestamp:
10/10/08 14:58:00 (17 months ago)
Author:
inureyes
Message:

refs #895

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.7/lib/model/blog.trackback.php

    r6805 r6806  
    621621    } 
    622622 
    623     preg_match_all('/(\S+?)=(["\']?)(.*?)\2/', $match[1], $attribs, PREG_SET_ORDER); 
    624     $namespace = array('rdf' => 'rdf', 'dc' => 'dc', 'trackback' => 'trackback'); 
    625  
    626     //print_r($attribs); 
    627  
    628     foreach ($attribs as $attrib) { 
    629         if (substr(strtolower($attrib[1]), 0, 6) == 'xmlns:') { 
    630             $name = substr($attrib[1], 6); 
    631  
    632             switch (trim($attrib[3])) { 
    633                 case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#': 
    634                     $namespace['rdf'] = $name; 
     623    if (class_exists('DOMDocument')) { 
     624        $doc = DOMDocument::loadXML($match[0]); 
     625        if (!$doc) { 
     626            return false; 
     627        } 
     628        $desc = $doc->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description')->item(0); 
     629        if ($desc === null) { 
     630            return false; 
     631        } 
     632        return array( 
     633            'title' => $desc->getAttributeNS('http://purl.org/dc/elements/1.1/', 'title'), 
     634            'url' => $desc->getAttributeNS('http://purl.org/dc/elements/1.1/', 'identifier'), 
     635            'trackbackURL' => $desc->getAttributeNS('http://madskills.com/public/xml/rss/module/trackback/', 'ping') 
     636        ); 
     637    } else { 
     638        preg_match_all('/(\S+?)=(["\']?)(.*?)\2/', $match[1], $attribs, PREG_SET_ORDER); 
     639        $namespace = array('rdf' => 'rdf', 'dc' => 'dc', 'trackback' => 'trackback'); 
     640 
     641        print_r($attribs); 
     642 
     643        foreach ($attribs as $attrib) { 
     644            if (substr(strtolower($attrib[1]), 0, 6) == 'xmlns:') { 
     645                $name = substr($attrib[1], 6); 
     646 
     647                switch (trim($attrib[3])) { 
     648                    case 'http://www.w3.org/1999/02/22-rdf-syntax-ns#': 
     649                        $namespace['rdf'] = $name; 
     650                        break; 
     651                    case 'http://purl.org/dc/elements/1.1/': 
     652                        $namespace['dc'] = $name; 
     653                        break; 
     654                    case 'http://madskills.com/public/xml/rss/module/trackback/': 
     655                        $namespace['trackback'] = $name; 
     656                        break; 
     657                } 
     658            } 
     659        } 
     660 
     661        preg_match_all('/(\S+?)=(["\']?)(.*?)\2/', $match[2], $attribs, PREG_SET_ORDER); 
     662        $result = array('title' => null, 'url' => null, 'trackbackURL' => null); 
     663 
     664        foreach ($attribs as $attrib) { 
     665            switch ($attrib[1]) { 
     666                case $namespace['dc'].':title': 
     667                    $result['title'] = $attrib[3]; 
    635668                    break; 
    636                 case 'http://purl.org/dc/elements/1.1/': 
    637                     $namespace['dc'] = $name; 
     669                case $namespace['dc'].':identifier': 
     670                    $result['url'] = $attrib[3]; 
    638671                    break; 
    639                 case 'http://madskills.com/public/xml/rss/module/trackback/': 
    640                     $namespace['trackback'] = $name; 
    641                     break; 
     672                case $namespace['trackback'].':ping': 
     673                    $result['trackbackURL'] = $attrib[3]; 
    642674            } 
    643675        } 
    644     } 
    645  
    646     preg_match_all('/(\S+?)=(["\']?)(.*?)\2/', $match[2], $attribs, PREG_SET_ORDER); 
    647     $result = array('title' => null, 'url' => null, 'trackbackURL' => null); 
    648  
    649     foreach ($attribs as $attrib) { 
    650         switch ($attrib[1]) { 
    651             case $namespace['dc'].':title': 
    652                 $result['title'] = $attrib[3]; 
    653                 break; 
    654             case $namespace['dc'].':identifier': 
    655                 $result['url'] = $attrib[3]; 
    656                 break; 
    657             case $namespace['trackback'].':ping': 
    658                 $result['trackbackURL'] = $attrib[3]; 
    659         } 
    660     } 
    661  
    662     return (isset($result['trackbackURL'])) ? $result : false; 
     676 
     677        return (isset($result['trackbackURL'])) ? $result : false; 
     678    } 
    663679} 
    664680?>