Comparing revisions for WikipediaAction
- [12109] 2005-12-05 23:35:35 by RolandStens (unregistered user)
- [12600] 2006-01-10 23:05:23 by RolandStens (unregistered user)
Deletions:
// wikipedia action
// This action will insert the content of the supplied topic in your page.
// Usage examples: {{wikipedia topic="Workflow"}}
// {{wikipedia topic="Madrid" lang="es"}}
function fetchUrlWithoutHanging($url)
{
// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
$numberOfSeconds=4;
// Suppress error reporting so Web site visitors are unaware if the feed fails
error_reporting(0);
// Extract resource path and domain from URL ready for fsockopen
$url = str_replace("http://","",$url);
$urlComponents = explode("/",$url);
$domain = $urlComponents[0];
$resourcePath = str_replace($domain,"",$url);
// Establish a connection
$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);
if (!$socketConnection)
{
// You may wish to remove the following debugging line on a live Web site
print("WikiPedia Error: ");
} // end if
else {
$xml = '';
fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
// Loop until end of file
while (!feof($socketConnection))
{
$xml .= fgets($socketConnection, 128);
} // end while
fclose ($socketConnection);
} // end else
return($xml);
} // end function
if (!isset($vars['lang'])) $lang = 'en';
else $lang = $vars['lang'];
if ($file = fetchUrlWithoutHanging('http://'.$lang.'.wikipedia.org/wiki/'.$topic))
{
$file = str_replace('href="/', 'href="http://'.$lang.'.wikipedia.org/', $file);
preg_match_all('#<!-- start content -->(.*?)<!-- end content -->#es', $file, $ar);
unset($file);
if (is_array($ar[1])) echo $ar[1][0];
else echo '';
}
else
{
echo 'http://'.$lang.'.wikipedia.org/wiki/'.$topic.' could not be found!';
}
CategoryUserContributions