Author Topic: MOD WIKIPEDIA  (Read 147705 times)

0 Members and 1 Guest are viewing this topic.

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: MOD WIKIPEDIA
« Reply #120 on: June 04, 2010, 08:20:21 PM »
Rembrandt,
                      Thanks for your modified code..

rinaldos ,
                        The wrapper is not removing the links .. The below line in the function actually removes the links..
Code: [Select]
     $summary = ereg_replace('href="/wiki/', '', $summary);

    but the issue is it's not removing the links completely. Its only removing the " href="/wiki/" part and not the </a> part. For this reason it still looks like a link but not clickable..

I just found one more function to get the pure text as the output by removing all the html tags..Here I have posted the complete  code.

Code: [Select]
<?php
/**
 * Remove HTML tags, including invisible text such as style and
 * script code, and embedded objects.  Add line breaks around
 * block-level tags to prevent word joining after tag removal.
 */
function strip_html_tags$text )
{
    
$text preg_replace(
        array(
          
// Remove invisible content
            
'@<head[^>]*?>
.*?</head>@siu',
            '@<style[^>]*?>.*?</style>@siu',
            '@<script[^>]*?.*?</script>@siu',
            '@<object[^>]*?.*?</object>@siu',
            '@<embed[^>]*?.*?</embed>@siu',
            '@<applet[^>]*?.*?</applet>@siu',
            '@<noframes[^>]*?.*?</noframes>@siu',
            '@<noscript[^>]*?.*?</noscript>@siu',
            '@<noembed[^>]*?.*?</noembed>@siu',
          // Add line breaks before and after blocks
            '@</?((address)|(blockquote)|(center)|(del))@iu',
            '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
            '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
            '@</?((table)|(th)|(td)|(caption))@iu',
            '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
            '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
            '@</?((frameset)|(frame)|(iframe))@iu',
        ),
        array(
            ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
            "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
            "\n\$0", "\n\$0",
        ),
        $text );
    return strip_tags( $text );
}

function get_wiki_cat($cat_name) {
  global $user_info, $site_db, $session_info, $config;
  ini_set('user_agent', '(Windows; U; Windows NT 6.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6');
    $sign = array('#', '?', '§', '$', '%', '&', '/', '(', ')', '=', '^', '°', '*', '@', ' ');
    $cat_name = str_replace($sign,"_",$cat_name);
    if(!$cat_name) return false;
    //The whole test from the API take Wiki

if (!ini_get('allow_url_fopen') && !ini_get('allow_url_include'))
{
# Force allow_url_fopen=on and allow_url_include=off
stream_wrapper_unregister('http');
require('http_wrapper.php');
stream_wrapper_register('http', 'moo_stream_wrapper_http');
}
    $url = "http://en.wikipedia.org/w/api.php?format=xml&action=parse&page=".$cat_name;
    $xml = simplexml_load_file($url);
    $text = $xml->parse->text;
    if(!$text) return false;
    //Search summary
    $reg_exp = '/<p>(.*?)<\/p>/s';
    preg_match_all($reg_exp, $text, $match);
    $summary = $match[0][0];
    $summary .= $match[0][1];
    $summary .= $match[0][2];
    $summary .= $match[0][3];
    $summary .= $match[0][4];
    $summary .= $match[0][5];
    $summary .= $match[0][6];
    $summary = utf8_decode($summary);
$summary = strip_html_tags( $summary );
    $summary .= "<a href = 'http://en.wikipedia.org/wiki/$cat_name'>Source: Wikipedia</a>";
    //If item is not available
    if($summary == "<p><b>Article content ??</b></p>") return false;
    //Links to internal pages

//     $summary = ereg_replace('href="/wiki/', '', $summary);
    return $summary;
}

?>

Please let me know if anyone have a better/efficient code ...


Thanks,
batu544

Offline Jan-Lukas

  • Addicted member
  • ******
  • Posts: 1.289
    • View Profile
    • Discover the New World of Kindersurprise
Re: MOD WIKIPEDIA
« Reply #121 on: June 29, 2010, 11:58:01 PM »
Gibt es eine Lösung auch Stichworte in Klammern anzeigen zu lassen ??
z.B. BP (Konzern), leider wird dann kein Text angezeigt, und Wiki bietet nur das eine an.

LG
Danke Harald




Offline osnapicture

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: MOD WIKIPEDIA
« Reply #122 on: February 28, 2011, 07:34:37 PM »
Ich habe überlegt den MOD zu installieren und mich durch alle Seiten in diesem Thread gelesen. Aber da sich ja hier lange nichts getan hat und alle angegebenen Demo-Seiten nicht funktionieren, kann ich mir die Mühe wohl sparen, oder? Kann jemand sagen, ob der Mod noch bzw. wider läuft?

Rembrandt

  • Guest
Re: MOD WIKIPEDIA
« Reply #123 on: February 28, 2011, 07:38:47 PM »
.. Kann jemand sagen, ob der Mod noch bzw. wider läuft?
der läuft und läuft und läuft...
unten auf dem bild auf "bildinformation"
oder bei den bild
mfg Andi

Offline batu544

  • Sr. Member
  • ****
  • Posts: 336
    • View Profile
    • Free Celebrity wallpapers
Re: MOD WIKIPEDIA
« Reply #124 on: March 01, 2011, 12:39:09 PM »
Hi osnapicture,
                         It works.. You can see the demo here also ==> http://www.bhwallpapers.com/k-louise-glover-114.htm   ( at the bottom of the page "About Louise Glover.." section )


Thanks
batu544

Offline osnapicture

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: MOD WIKIPEDIA
« Reply #125 on: March 01, 2011, 05:55:02 PM »
Genial! Vielen Dank!

Habe gleich damit begonnen das zu installieren. Allerdings habe ich ein Problem: Bei der Detailansich der Fotos taucht folgende Fehlermeldung auf:

Warningsimplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration in /meinedomain/includes/functions.php on line 1937
Warning
simplexml_load_file(http://de.wikipedia.org/w/api.php?format=xml&action=parse&page=Karin%20Dor) [function.simplexml-load-file]: failed to open stream: no suitable wrapper could be found in /meinedomain/includes/functions.php on line 1937
Warningsimplexml_load_file() [function.simplexml-load-file]: I/O warning failed to load external entity "http://de.wikipedia.org/w/api.php?format=xml&action=parse&page=Karin%20Dor" in /meinedomain/includes/functions.php on line 193


Wenn ich Schritt 9 aus der Anleitung rückgängig mache und folgende Zeilen aus der includes/db_field_definitions.php entferne, ist der Fehler weg:
$additional_image_fields['image_allow_wiki'] = array($lang['image_allow_wiki'], "radio"0);
$additional_image_fields['image_wiki'] = array($lang['image_wiki'], "text"0);


Allerdings ist das ja nicht Sinn der Sache, weil der MOD dann nicht funktioniert.

Kann mir vielleicht jemand helfen und sagen, wo der Fehler liegen könnte?
« Last Edit: March 01, 2011, 07:20:40 PM by osnapicture »

Rembrandt

  • Guest
Re: MOD WIKIPEDIA
« Reply #126 on: March 01, 2011, 07:46:35 PM »
....Habe gleich damit begonnen das zu installieren. Allerdings habe ich ein Problem: Bei der Detailansich der Fotos taucht folgende Fehlermeldung auf:
....
wenn man einen mod installiert sollte man wenigsten die ersten 3 zeilen lesen.   :)
Quote
Funktion "simplexml_load_file" steht erst ab PHP5 zur Verfügung


abhilfe:  http://www.4homepages.de/forum/index.php?topic=24975.msg136738#msg136738
meine persönliche empfehlung wechsel den provider wenn der jetzt noch immer auf php4 herrumgurkt.

mfg Andi

Offline osnapicture

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: MOD WIKIPEDIA
« Reply #127 on: March 01, 2011, 10:13:49 PM »
Danke für die schnelle Antwort.

Bin eigentlich davon ausgegangen, dass simplexml_load_file bei mir funktioniert. Ich bin bei 1&1. In der php Info steht: PHP Version 5.2.17

Habe Deinen Beitrag zur Abhilfe schon gelesen. Mir ist aber nicht ganz klar in welche Datei und an welche Stelle ich den Code dort kopieren muss. Auch weiß ich nicht welche Datei aus der Zip-Datei ich in den includes-Ordner kopieren muss. Alle Dateien darin oder nur die xml-line.php?

Für eine Antwort wäre ich sehr dankbar.

Rembrandt

  • Guest
Re: MOD WIKIPEDIA
« Reply #128 on: March 02, 2011, 05:19:25 AM »
...Bin eigentlich davon ausgegangen, dass simplexml_load_file bei mir funktioniert.....
....
das kannst du in der der phpinfo.php im ACP nachlesen.
du brauchst nur die "xml-line.php" in den includes ordner kopieren.

.... Mir ist aber nicht ganz klar in welche Datei und an welche Stelle ich den Code dort kopieren muss. ....
jetzt ist mir nicht klar was du damit meinst?

mfg Andi

Offline osnapicture

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: MOD WIKIPEDIA
« Reply #129 on: March 02, 2011, 08:18:00 AM »
Super, jetzt dürfte ich der Lösung näher kommen. Die xml-line.php habe ich jetzt in den Include-Ordner kopiert.

Jetzt muss ich nur noch wissen, wo der folgende Code aus Deinem Lösungsansatz hin muss:

require_once("xml-line.php");
 function 
get_wiki_cat($cat_name) {
  global 
$user_info$site_db$session_info$config;
//    $image_name = preg_replace('/\\W/', '',$image_name);
    
$zeichen = array('#''?''§''$''%''&''/''('')''=''^''°''*''@');
    
$cat_name str_replace($zeichen,"",$cat_name);
    if(!
$cat_name) return false;
    
//Gesamter Text aus der Wiki-API nehmen
    
$xmlfile "http://de.wikipedia.org/w/api.php?format=xml&action=parse&page=$cat_name";
	
	
$xml = new xml_line($xmlfile,"xml");
	
	
$xml->get_record(1,"text");
	
	
$xml->xml_stream();
	
	
$text 
	
$xml->table_result[1][1]['text'];
	
	
$text =  $xml->get_output();

	
	
$reg_exp '/<p>(.*?)<\/p>/s';
    
preg_match_all($reg_exp$text$match);
    
$summary $match[0][0];
    
$summary .= $match[0][1];
    
$summary .= $match[0][2];
    
$summary .= $match[0][3];
	
	
$summary .= $match[0][4];
	

	
	
$summary .= "<a href = 'http://de.wikipedia.org/wiki/$cat_name'>Quelle: Wikipedia</a>";
	
	
$summary utf8_decode($summary);
	
	

	
	
 
//wenn Artikel nicht vorhanden
    
if($summary == "<p><b>Artikel verschwunden?</b></p>") return false;
    
//Links auf interne Seite Ã¤ndern
     
$summary ereg_replace('href="/wiki/'''$summary);
    return 
$summary;


Rembrandt

  • Guest
Re: MOD WIKIPEDIA
« Reply #130 on: March 02, 2011, 08:35:50 AM »

Offline osnapicture

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: MOD WIKIPEDIA
« Reply #131 on: March 02, 2011, 09:24:53 AM »
Irgendwie stehe ich gerade auf dem Schlauch.

Ich habe alle Schritte der Installationsanleitung am Anfang ausgeführt, dann habe ich die Datei xml-line.php in den includes-ordner kopiert und zuletzt den folgenden Code ans Ende der functions.php kopiert

function get_wiki($image_wiki) {
  global 
$user_info$site_db$session_info$config;
   
ini_set('user_agent''(Windows; U; Windows NT 6.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6');
//    $image_wiki = preg_replace('/\\W/', '',$image_wiki);
    
$zeichen = array('#''?''§''$''%''&''/''('')''=''^''°''*''@');
    
$image_wiki str_replace($zeichen,"",$image_wiki);
    if(!
$image_wiki) return false;
    
//Gesamter Test aus der Wiki-API nehmen
    
$url "http://de.wikipedia.org/w/api.php?format=xml&action=parse&page=".$image_wiki;
    
$xml simplexml_load_file($url);
    
$text $xml->parse->text;
    if(!
$text) return false;
    
//Zusammenfassung suchen
    
$reg_exp '/<p>(.*?)<\/p>/s';
    
preg_match_all($reg_exp$text$match);
    
$summary $match[0][0];
    
$summary .= $match[0][1];
    
$summary .= $match[0][2];
    
$summary .= $match[0][3];
    
$summary .= $match[0][4];    
    
$summary .= $match[0][5];
    
$summary .= $match[0][6];
    
$summary utf8_decode($summary);
    
//wenn Artikel nicht vorhanden
    
if($summary == "<p><b>Artikel verschwunden?</b></p>") return false;
    
//Links auf interne Seite Ã¤ndern
     
$summary ereg_replace('href="/wiki/'''$summary);
    return 
$summary;
}

require_once(
"xml-line.php");
 function 
get_wiki_cat($cat_name) {
  global 
$user_info$site_db$session_info$config;
//    $image_name = preg_replace('/\\W/', '',$image_name);
    
$zeichen = array('#''?''§''$''%''&''/''('')''=''^''°''*''@');
    
$cat_name str_replace($zeichen,"",$cat_name);
    if(!
$cat_name) return false;
    
//Gesamter Text aus der Wiki-API nehmen
    
$xmlfile "http://de.wikipedia.org/w/api.php?format=xml&action=parse&page=$cat_name";
	
	
$xml = new xml_line($xmlfile,"xml");
	
	
$xml->get_record(1,"text");
	
	
$xml->xml_stream();
	
	
$text 
	
$xml->table_result[1][1]['text'];
	
	
$text =  $xml->get_output();

	
	
$reg_exp '/<p>(.*?)<\/p>/s';
    
preg_match_all($reg_exp$text$match);
    
$summary $match[0][0];
    
$summary .= $match[0][1];
    
$summary .= $match[0][2];
    
$summary .= $match[0][3];
	
	
$summary .= $match[0][4];
	

	
	
$summary .= "<a href = 'http://de.wikipedia.org/wiki/$cat_name'>Quelle: Wikipedia</a>";
	
	
$summary utf8_decode($summary);
	
	

	
	
 
//wenn Artikel nicht vorhanden
    
if($summary == "<p><b>Artikel verschwunden?</b></p>") return false;
    
//Links auf interne Seite Ã¤ndern
     
$summary ereg_replace('href="/wiki/'''$summary);
    return 
$summary;
 

}


War das alles so richtig? Wahrscheinlich nicht. Die eingangs beschriebene Fehlermeldung bleibt trotzdem. Was habe ich falsch gemacht?

Rembrandt

  • Guest
Re: MOD WIKIPEDIA
« Reply #132 on: March 02, 2011, 01:44:58 PM »
du hast ja wieder die function get_wiki aus dem @TO genommen,das ist klar das die nicht funktioniert.
du hättest meine nehmen sollen.
versuche mal das:

require_once("xml-line.php");
 function 
get_wiki($image_wiki) {
  global 
$user_info$site_db$session_info$config;
  
ini_set('user_agent''(Windows; U; Windows NT 6.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6');

  
$zeichen = array('#''?''§''$''%''&''/''=''^''°''*''@');
  
$image_wiki str_replace($zeichen,"",$image_wiki);
  if(!
$image_wiki) return false
  
//Gesamter Test aus der Wiki-API nehmen
  
$xmlfile "http://de.wikipedia.org/w/api.php?format=xml&action=parse&page=$cat_name";
  
$xml = new xml_line($xmlfile);
  
$xml->get_record(0,"item");
  
$result $xml->xml_stream();
    
  
$text$xml->table_result;
    
  
$text $xml->parse->text;
  if(!
$text) return false;
  
//Zusammenfassung suchen
  
$reg_exp '/<p>(.*?)<\/p>/s';
  
preg_match_all($reg_exp$text$match);
  
$summary $match[0][0];
  
$summary .= $match[0][1];
  
$summary .= $match[0][2];
  
$summary .= $match[0][3];
  
$summary .= $match[0][4]; 
  
$summary utf8_decode($summary);
  
$image_wiki str_replace(' ','_'$image_wiki);

  
$summary .= "<a href='http://de.wikipedia.org/wiki/$image_wiki' onclick=\"void(window.open(this.href, '', '')); return false;\" >Quelle:Wikipedia</a>";
  
//wenn Artikel nicht vorhanden
  
if($summary == "<p><b>Artikel verschwunden?</b></p>") return false;
  
//Links auf interne Seite Ã¤ndern
  
$summary str_replace('href="#',"href=\"http://de.wikipedia.org/wiki/$image_wiki#"$summary);
  
$summary str_replace('href="/wiki/''href="http://de.wikipedia.org/wiki/'$summary);
  
$summary str_replace('href="/w/''href="http://de.wikipedia.org/w/'$summary);
  return 
$summary;
}

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: MOD WIKIPEDIA
« Reply #133 on: March 02, 2011, 01:53:40 PM »
hallo!
ich habe den mod eigentlich erfolgreich eingebaut.
nur wird es in der detailseite etwas merkwürdig ausgelesen:
zB.

Quote
Seeadler kann bedeuten:

Quelle:Wikipedia

weiter nichts. ich kann nur ein paar worte auslesen. woran kann es liegen?

Rembrandt

  • Guest
Re: MOD WIKIPEDIA
« Reply #134 on: March 02, 2011, 01:57:52 PM »
...
weiter nichts. ich kann nur ein paar worte auslesen. woran kann es liegen?
welchen suchbegriff hast du verwendet?
sehe schon du hast "seeadler" verwendet, da findet wiki nichts.

das kannst du ja selber überprüfen in dem du den begriff bei wiki eingibst und die genaue schreibweise in den wikiartikel übernimmst b.z.w. von dort rauskopierst.
mit "Seeadler (Art)" findet er das was du möchtest.