103 $this->itemStartTag = $itemTag;
108 $this->cache_path =
'./files/cache/importer/'.$this->key;
109 $this->cache_index_file = $this->cache_path.
'/index';
123 $this->index_fd = fopen($this->cache_index_file,
"a");
125 if(strncasecmp(
'http://', $this->filename, 7) !== 0)
127 if(!file_exists($this->filename))
return new BaseObject(-1,
'msg_no_xml_file');
128 $this->fd = fopen($this->filename,
"r");
133 $url_info = parse_url($this->filename);
134 if(!$url_info[
'port']) $url_info[
'port'] = 80;
135 if(!$url_info[
'path']) $url_info[
'path'] =
'/';
137 $this->fd = @fsockopen($url_info[
'host'], $url_info[
'port']);
138 if(!$this->fd)
return new BaseObject(-1,
'msg_no_xml_file');
140 $path = $url_info[
'path'];
141 if(preg_match(
'/[\xEA-\xED][\x80-\xFF]{2}/', $path)&&function_exists(
'iconv'))
143 $path_list = explode(
'/',$path);
144 $cnt = count($path_list);
148 $path = implode(
'/',$path_list);
149 $url_info[
'path'] = $path;
152 $header = sprintf(
"GET %s?%s HTTP/1.0\r\nHost: %s\r\nReferer: %s://%s\r\nConnection: Close\r\n\r\n", $url_info[
'path'], $url_info[
'query'], $url_info[
'host'], $url_info[
'scheme'], $url_info[
'host']);
153 @fwrite($this->fd, $header);
155 while(!feof($this->fd))
157 $buff .= $str = fgets($this->fd, 1024);
158 if(!trim($str))
break;
160 if(preg_match(
'/404 Not Found/i',
$buff))
return new BaseObject(-1,
'msg_no_xml_file');
165 while(!feof($this->fd))
167 $str = fgets($this->fd, 1024);
168 $pos = strpos($str, $this->startTag);
171 $this->buff = substr($this->buff, $pos+strlen($this->startTag));
172 $this->isStarted =
true;
180 $this->isStarted =
true;
195 fclose($this->index_fd);
200 return $this->
isFinished || !$this->fd || feof($this->fd);
227 $index_fd = fopen($this->cache_index_file,
"r");
230 fwrite(
$fd,
'<items>');
233 $target_file = trim(fgets(
$index_fd,1024));
234 if(!file_exists($target_file))
continue;
240 fwrite(
$fd,
'</items>');
252 while(!feof($this->fd))
254 $startPos = strpos($this->buff, $this->itemStartTag);
255 if($startPos !==
false)
257 $this->buff = substr($this->buff, $startPos);
258 $this->buff = preg_replace(
"/>/",
">\r\n",$this->buff,1);
261 elseif($this->endTag)
263 $endPos = strpos($this->buff, $this->endTag);
264 if($endPos !==
false)
270 $this->buff .= fgets($this->fd, 1024);
273 $startPos = strpos($this->buff, $this->itemStartTag);
274 if($startPos ===
false)
280 $filename = sprintf(
'%s/%s.xml',$this->cache_path, $this->index++);
281 fwrite($this->index_fd,
$filename.
"\r\n");
285 while(!feof($this->fd))
287 $endPos = strpos($this->buff, $this->itemEndTag);
288 if($endPos !==
false)
290 $endPos += strlen($this->itemEndTag);
291 $buff = substr($this->buff, 0, $endPos);
294 $this->buff = substr($this->buff, $endPos);
299 $this->buff = fgets($this->fd, 1024);
314 $str = preg_replace(
'/<\/([^>]*)></i',
"</$1>\r\n<", $str);