Permalink
Browse files

Merge pull request #5 from saper/master

we ain't need no freaking cronjob!
  • Loading branch information...
Holek committed Mar 27, 2012
2 parents e90a081 + 31adaee commit d14bc69c4b9ce3d061edf9435d5e807737ca3309
Showing with 38 additions and 2 deletions.
  1. +18 −0 includes/Functions.php
  2. +1 −1 parsers/ISBN/Nukat.ini
  3. +19 −1 parsers/ISBN/Nukat.php
View
@@ -347,3 +347,21 @@ function debugWrite($message)
global $debug;
$debug .= $message."\n";
}
+
+function handleMetaRedirect($data)
+{
+ $data = preg_replace("$<!--.*-->$", "", $data);
+ $grp = array();
+ if( preg_match('#<meta +http-equiv="refresh" +content="(.*)"#siu', $data, $grp) ) {
+ if( isset( $grp[1] ) ) {
+ $items = explode( ";", $grp[1]);
+ foreach( $items as $item ) {
+ $keyval = explode( "=", $item, 2 );
+ if ( trim( strtolower( $keyval[0] ) ) === "url" ) {
+ return trim($keyval[1]);
+ }
+ }
+ }
+ }
+ return null;
+}
View
@@ -1,4 +1,4 @@
[summary]
title = NUKAT
-url = "http://www.nukat.edu.pl/cgi-bin/gw_2010_1_3_1/chameleon"
+url = "http://www.nukat.edu.pl/"
main_language = pl
View
@@ -10,12 +10,30 @@
class Nukat extends ISBNBaseParser {
+ public function fetchURL( $url, $params ) {
+ if ( strpos( $url, "?" ) > 0 ) {
+ $sep = "&";
+ } else {
+ $sep = "?";
+ }
+ $data = @file_get_contents($address = $url . $sep . $params);
+ return $data;
+ }
+
public function fetch($ISBN)
{
global $debug;
$ini = parse_ini_file('./parsers/ISBN/Nukat.ini');
$u1 = ((strlen($ISBN)==13)?'6000':'7');
- $data = @file_get_contents($address = $ini['url'].'?search=KEYWORD&function=CARDSCR&pos=1&u1='.$u1.'&t1='.$ISBN);
+ $params = "search=KEYWORD&function=CARDSCR&pos=1&u1=" . $u1 . "&t1=" . $ISBN;
+ $url = $ini['url'];
+
+ $data = $this->fetchURL( $url, $params );
+ $redirect = handleMetaRedirect( $data );
+ if( $redirect ) {
+ $data = $this->fetchURL( $redirect, $params );
+ }
+
if (!$data)
{
$this->errors[]= array('base-disabled','NUKAT');

0 comments on commit d14bc69

Please sign in to comment.