[geeklog-cvs] Geeklog-1.x/plugins/links functions.inc,1.100,1.101

Dirk Haun dhaun at qs1489.pair.com
Tue Jan 1 11:18:14 EST 2008


Update of /cvsroot/geeklog/Geeklog-1.x/plugins/links
In directory qs1489.pair.com:/tmp/cvs-serv98197/plugins/links

Modified Files:
	functions.inc 
Log Message:
Rewrote links_validateUrl() to use PEAR::HTTP_Request


Index: functions.inc
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/plugins/links/functions.inc,v
retrieving revision 1.100
retrieving revision 1.101
diff -C2 -d -r1.100 -r1.101
*** functions.inc	1 Jan 2008 16:01:39 -0000	1.100
--- functions.inc	1 Jan 2008 16:18:12 -0000	1.101
***************
*** 1275,1306 ****
      global $LANG_LINKS_STATUS;
  
!     $header_str = '';
!     $url_arr = parse_url($url);
!     $socket = @fsockopen($url_arr['host'], 80, $err_no, $err_txt, 10);
!     if ($socket) {
!         if (empty($url_arr['path'])) {
!             $url_arr['path'] = "/";
!         }
!         $query = '';
!         if (isset($url_arr['query'])) {
!             $query = "?{$url_arr['query']}";
!         }
!         $send_header = "HEAD {$url_arr['path']} HTTP/1.1\r\n"
!             . "User-Agent: Geeklog Link Checker\r\n"
!             . "Host: {$url_arr['host']}\r\n"
!             . "Connection: close\r\n\r\n";
!         fputs($socket, $send_header);
!         while($str = fgets($socket, 1024)) {
!             if (eregi("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", $str)) {
!                 $status_code = trim(eregi_replace("^http/[0-9]+.[0-9]+ ([0-9]{3}) [a-z ]*", "\\1", $str));
!             }
          }
-         fclose($socket);
-         $status_code = $status_code . ": " . $LANG_LINKS_STATUS[$status_code];
      }
!     if (!isset($status_code)) {
!         $status_code = $LANG_LINKS_STATUS[999];
!     }
!     return $status_code;
  }
  
--- 1275,1299 ----
      global $LANG_LINKS_STATUS;
  
!     require_once 'HTTP/Request.php';
! 
!     $retval = '';
! 
!     $req = new HTTP_Request($url);
!     $req->setMethod(HTTP_REQUEST_METHOD_HEAD);
!     $req->addHeader('User-Agent', 'Geeklog/' . VERSION);
! 
!     $response = $req->sendRequest();
!     if (PEAR::isError($response)) {
!         $retval = $response->getMessage();
!     } else {
!         $status_code = $req->getResponseCode();
!         if (isset($LANG_LINKS_STATUS[$status_code])) {
!             $retval = $status_code . ": " . $LANG_LINKS_STATUS[$status_code];
!         } else {
!             $retval = $LANG_LINKS_STATUS[999];
          }
      }
! 
!     return $retval;
  }
  




More information about the geeklog-cvs mailing list