hallo,
ich lese mittels nachfolgendem php-skript inhalte einer wikipedia-datei aus.
Es soll der Inhalt z.B. "Studium" ausgegeben werden. Soweit wird auch alles angezeigt. die externen Links innerhalb der ausgelesenen Datei funktionieren nicht - sie haben meine Domain und $default_title, sie gehen auf meine index..
Wie bekomme ich default_title in die Links?
	
Danke für ne Hilfe
							
						
					ich lese mittels nachfolgendem php-skript inhalte einer wikipedia-datei aus.
Es soll der Inhalt z.B. "Studium" ausgegeben werden. Soweit wird auch alles angezeigt. die externen Links innerhalb der ausgelesenen Datei funktionieren nicht - sie haben meine Domain und $default_title, sie gehen auf meine index..
Wie bekomme ich default_title in die Links?
PHP-Code:
	
	
$default_title = 'Studium'; # If you do not specify a title, this will be your default page.
$sourceurl = 'http://de.wikipedia.org/wiki/'; # This URL needs adjusting sometimes.
$pathfromroot = substr( $_SERVER['REQUEST_URI'], 0, strpos( $_SERVER['REQUEST_URI'], "?" ) );
$title_wiki = $default_title;
$nicetitle = str_replace( "_", " ", stripslashes( $title_wiki ) );
function callback( $buffer ) {
         global $nicetitle;
         global $title_wiki;
         global $sourceurl;
         # Separate the article content
           $buffer = substr( $buffer, strpos( $buffer, '<!-- start content -->' ) );
           $buffer = substr( $buffer, 0, strpos( $buffer, '<div class="printfooter">' ) );
         # Replace relative links (use another wiki server)
           $buffer = str_replace( '"/w/skin', '"http://de.wikipedia.org/w/skin', $buffer );
           $buffer = str_replace( '"/skins', '"http://de.wikipedia.org/skins', $buffer );
         # Replace relative links (use this server)
           $buffer = str_replace( '"/wiki/', '"' . $pathfromroot . '?title=', $buffer );
         # Remove edit links
           $buffer = str_replace( ">Bearbeiten<", "><", $buffer );
           $buffer = str_replace( "[<", "<", $buffer );
           $buffer = str_replace( ">]", ">", $buffer );
         $buffer = utf8_decode ($buffer);
         $buffer = str_replace( 'href="/w/index.php?', 'target="_blank" href="http://de.wikipedia.org/w/index.php?', $buffer ); # These are typically links to non-existent pages, so the Wikipedia edit page has to open.
         if ( $buffer <> '' ) {
              $buffer = '<table width=100% cellspacing=0 cellpadding=1 bgcolor="#EEEEEE" border=0><tr><td>
                         
 <small>Hinweis: Text und Bilder dieses Beitrags stammen aus dem Artikel 
        <a href="http://de.wikipedia.org/wiki/'.$title.'" title="http://de.wikipedia.org/wiki/'.$title.'" target="_blank">'.$title.'</a>
 der freien Enzyklopädie 
    <a title="http://de.wikipedia.org" target="_blank" href="http://de.wikipedia.org/wiki/Hauptseite">Wikipedia</a> 
        und stehen unter der <a href="http://www.gnu.org/licenses/fdl.txt" target="_blank">GNU Free Documentation License</a>.
 Die Liste der Autoren ist in der Wikipedia unter
    <a target="_blank" title="http://de.wikipedia.org/w/wiki.phtml?title='.$title.'&action=history" href="http://de.wikipedia.org/w/index.php?title=Studium&action=history">dieser Seite</a> verfügbar, der Original-Artikel lässt sich
 <a target="_blank" title="http://de.wikipedia.org/w/wiki.phtml?title='.$title.'&action=edit" href="http://de.wikipedia.org/w/index.php?title=Studium&action=edit">hier</a>
 bearbeiten.
                      
</tr></td><table><p>' . $buffer;
                     
            } else {
              $buffer = '<p>Unfortunately, no content could be extracted!
                         <p><a href="javascript:history.go(-1)">Return to the previous page</a> or consult the <a target="_blank" href="' . $sourceurl . $title_wiki . '">Wikipedia article on "' . $nicetitle . '"</a>.';
            }
         return $buffer;
       }
# Your page header comes here...'
ob_start("callback");
#include $sourceurl . $title_wiki;
$cuu = new CURL;
echo $cuu -> get( $sourceurl . $title_wiki );
ob_end_flush();
# Your page footer comes here...'
# Define the cURL class:
  class CURL {
     var $callback = false;
     function setCallback($func_name) {
        $this->callback = $func_name;
     }
     function doRequest($method, $url, $vars) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        #curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        #curl_setopt($ch, CURLOPT_USERAGENT, 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
        }
        $data = curl_exec($ch);
        curl_close($ch);
        if ($data) {
            if ($this->callback)
            {
                $callback = $this->callback;
                $this->callback = false;
                return call_user_func($callback, $data);
            } else {
                return $data;
            }
        } else {
            return curl_error($ch);
        }
     }
     function get($url) {
        return $this->doRequest('GET', $url, 'NULL');
     }
     function post($url, $vars) {
        return $this->doRequest('POST', $url, $vars);
     }
  } 
 
          

Kommentar