Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit c0e0a8c7d59a358863d1038035a3c30da43e9887 0 parents
Administrator authored
Showing with 341 additions and 0 deletions.
  1. +253 −0 GDUT.php
  2. 0  README
  3. +88 −0 douban4GDUT.js
253 GDUT.php
@@ -0,0 +1,253 @@
+<?php
+@header("Content-type: text/html; charset=UTF-8");
+
+
+//在xdebug装之前的必备秒杀变量工具,我勒个去呀
+//echo ;exit;
+
+global $title; //声明全局变量,思考更好的方式
+
+
+//截取华图的isbn数据
+if($_GET[isbn]||$_GET[title]){
+
+//转换标题要提前,不然后面的修改比较麻烦
+
+//方案一
+ $GLOBALS["title"]=iconv("UTF-8","GBK//IGNORE",$_GET[title]);
+// echo $GLOBALS["title"];
+// exit;
+
+//方案二
+// $title=iconv("GBK","UTF-8//IGNORE",$_GET[title]);
+// echo $GLOBALS["title"];
+// exit;
+
+ $GLOBALS["title"]=urlencode($GLOBALS["title"]);
+ if(!$GLOBALS["title"]){
+ erro();
+ }
+
+//这里写华图的匹配
+ $isbn_formated=search_hust($_GET[isbn]);
+
+//这里写广图的第一次查询,获得书籍的详细地址,长征开始!
+ $book_link=search_gdut_first($isbn_formated);
+
+//这里写广图第二次长征,获取详细内容
+ $final_content=search_gdut_second($book_link);
+
+//返回json格式的数据
+ echo $final_content."\"title\":\"".$title."\"}";
+
+}else{
+ //出现多种情况的故障
+ erro();
+}
+
+//查无此书,返回空对象
+function nobook($title){
+ echo "{\"ok\":\"0\",\"title\":\"".$title."\"}";
+ exit;
+}
+
+//错误处理
+function erro(){
+ echo "{\"ok\":\"0\"},{\"title\":\"".$title."\"}";
+ exit;
+}
+
+//查询华图的数据,获得格式化的isbn
+function search_hust($isbn){
+ $hust_url="http://202.114.9.29/search*chx/i?SEARCH=".$isbn; //php的字符串操作啊~
+ $hust_content=getHttp($hust_url);
+// echo $hust_content;
+// exit;
+ //必须对内容有个转换的过程,太多地雷了,暂时不用了,应该是php的两个正则匹配本身有些问题,风格不一样差很远
+ //正则和字符转义操作
+ //正则写得太弱了,有些情况没考虑进去啊,好在调试容易点,囧啊
+ $pattern="/\<td class\=\"bibInfoData\"\>([\s\r\n]*)([\d\w-]+\s)(.*)\<\/td\>\<\/tr\>[\r\n\s]*\<\/table\>/sU";
+// $pattern="/^[\d\w-]+(.*)(?=\<\/td\>)/Us";
+ //看看这里能不能抽离出来做成函数,或者对象
+ preg_match($pattern,$hust_content, $rg);
+ $rg=html2text($rg[0]);
+ $rg=preg_split("/\s/",$rg);
+ if(!$rg[0]){
+ nobook($GLOBALS["title"]);//全局数组就是关联数组,也就是对象
+ }
+ return $rg[0];
+}
+
+//查找其他靠谱的图书馆,下个版本再改进吧
+function search_others($isbn){
+ $url="http://210.72.4.33/interlib/websearch/bookSearch?filter=%28isbn%3A".$isbn."%29+AND+%28hasholding%3Ay%29&cmdACT=list&xsl=BOOK_list.xsl";
+ $formated_isbn=getHttp($url);
+ echo $formated_isbn;
+ exit;
+}
+
+////转换标题编码的函数
+//function enCode($final_content,$title=''){
+// $title=iconv("UTF-8","GB2312//IGNORE",$title);
+// return $final_content."\"title\":\"$title\"}";
+//
+//}
+
+//接收华图的isbn,查询广工图书馆
+function search_gdut_first($isbn){
+ $GDUT_url="http://222.200.98.171:81/searchresult.aspx?anywords=".$isbn; //php的字符串操作啊~
+ $GDUT_content=getHttp($GDUT_url);
+ //必须对内容有个转换的过程,太多地雷了,暂时不用了,应该是php的两个正则匹配本身有些问题,风格不一样差很远
+ //正则和字符转义操作
+ $pattern="/bookinfo\.aspx\?ctrlno\=[\d]{1,}/s";
+ //看看这里能不能抽离出来做成函数,或者对象
+ preg_match($pattern,$GDUT_content,$rg);
+ $rg=implode("", $rg);
+ $rg=html2text($rg,"<a>"); //把a也拿走了,显然写得不够健壮的代码
+ if(!$rg){
+ nobook($GLOBALS["title"]);
+ }
+ return $rg;
+}
+
+//接收广图的a链接,准备广图第2次越狱
+function search_gdut_second($aLink){
+ $GDUT_url="http://222.200.98.171:81/".$aLink; //php的字符串操作啊~
+ $GDUT_content=getHttp($GDUT_url);
+ $pattern="/\<tr\>(.*)\<\/tr\>/sU";
+ preg_match_all($pattern,$GDUT_content,$rg);
+ array_shift($rg[0]);//去掉不需要的tr数据
+ $num=0;
+ $new_values=array();
+ foreach ($rg[0] as $key=>$value){
+ $value=html2text($value,"");
+ $values=split("\n", $value);
+ foreach($values as $member=>$cost){
+ $cost=trim($cost);
+ if(strlen($cost)){
+ $new_values[$member]=$cost;
+ }
+ }
+ $rg[0][$key]=array_values($new_values);//对索引重排序
+ $num++;
+ }
+ //生成地址、索引和状态3个数组
+ //$i_value、$s_value、$place_value
+ $i_value=array();
+ $s_value=array();
+ $place_value=array();
+ $jsonText="{\"ok\":$num,\"data\":[";
+ for($k=0;$k<$num;$k++){
+ $jsonText.="{\"i\":\"".$rg[0][$k][1]."\",\"s\":\"".$rg[0][$k][3]."\",\"place\":\"".$rg[0][$k][0]."\"},";
+ }
+ $jsonText.="],";
+ return $jsonText;
+// list($i_value[],$s_value[],$place_value[])=$rg[0][$k];
+// }
+// print_r($rg[0]);
+// exit;
+
+// return $rg;
+}
+
+
+//长征
+//function catchtable(){
+// $jsonText="{\"ok\":\"".$num."\",\"data\":[";
+// {\"i\":\"".$i_value."\",\"s\":\"".$s_value."\",\"place\":\"".$place_value."\"}".
+//",{\"i\":\"".$i_value."\",\"s\":\"".$s_value."\",\"place\":\"".$place_value."\"}]}";
+//}
+
+//抽取网页内容,进行匹配,并返回数据
+function getcontent($url,$pattern){
+}
+
+
+//原样输出html代码
+function orginalHtml($sourceCode){
+ $html_mask =$sourceCode;
+ $html_mask_entity = htmlentities($html_mask,ENT_QUOTES,"utf-8");
+ return $html_mask_entity;
+}
+
+
+//正则抽取的过程中出现一些不必要的错误,清除掉不必要的数据
+function html2text($content,$allow_var=''){
+ $content=strip_tags($content,$allow_var);
+ return trim($content);
+}
+
+
+
+
+
+//测试用的
+//$t = getHttp("http://222.200.98.171:81/searchresult.aspx?anywords=7-5086-0546-2"); //对中文支持不好,后面要改进下
+
+//对$t进行匹配,
+//print_r($t);
+//exit;
+
+
+function getHttp($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
+ $return = '';
+ $matches = parse_url($url); //把url拆分成有用的数据
+
+ //防止null或未定义
+ !isset($matches['host']) && $matches['host'] = '';
+ !isset($matches['path']) && $matches['path'] = '';
+ !isset($matches['query']) && $matches['query'] = '';
+ !isset($matches['port']) && $matches['port'] = '';
+
+ //
+ $host = $matches['host'];
+ $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
+
+ //
+ $port = !empty($matches['port']) ? $matches['port'] : 80;
+
+ //为什么这里会有$path变量
+ $out = "GET $path HTTP/1.0\r\n";
+ $out .= "Accept: */*\r\n";
+ //$out .= "Referer: $boardurl\r\n";
+ $out .= "Accept-Language: zh-cn\r\n";
+ $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
+ $out .= "Host: $host\r\n";
+ $out .= "Connection: Close\r\n";
+ $out .= "Cookie: $cookie\r\n\r\n";
+
+
+ $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
+ if(!$fp) {
+ return '';//note $errstr : $errno \r\n
+ } else {
+ stream_set_blocking($fp, $block);
+ stream_set_timeout($fp, $timeout);
+ @fwrite($fp, $out);
+ $status = stream_get_meta_data($fp);
+ if(!$status['timed_out']) {
+// while (!feof($fp)) {
+// if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
+// break;
+// }
+// }
+
+ $stop = false;
+ while(!feof($fp) && !$stop) {
+ $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));//限制读取的大小
+ $return .= $data;
+ if($limit) {
+ $limit -= strlen($data);
+ $stop = $limit <= 0;
+ }
+ }
+ }
+ @fclose($fp);
+ return $return;
+ }
+}
+
+//}
+
+
+?>
0  README
No changes.
88 douban4GDUT.js
@@ -0,0 +1,88 @@
+// ==UserScript==
+// @name douban_whu
+// @namespace douban_whu
+// @require http://userscript-autoupdate-helper.googlecode.com/svn/trunk/autoupdatehelper.js
+// @version v5.0
+/* @reason
+ 为豆瓣FOR武大申请了一个UserScript.org的账号
+@end*/
+// @include http://book.douban.com/subject/*
+// @include http://book.douban.com/isbn/*
+// @author freefcw@gmail.com
+// @thankto zhx@xmulib.org
+// 2009-01-04 Adds Ajax to get book info.
+//
+// ==/UserScript==
+if(typeof unsafeWindow.jQuery !== "undefined") {
+ var jQuery = unsafeWindow.jQuery;
+ var $ = jQuery;
+}
+
+if(typeof unsafeWindow.jQuery !== "undefined") {
+ var jQuery = unsafeWindow.jQuery;
+ var $ = jQuery;
+}
+
+var thisScript = {
+name: "douban_WHU",
+id: "75179",
+version:"5.0"
+}
+var updater = new Updater(thisScript); // 用thisScript对象创建一个更新器对象
+updater.check(24); //检查是否有更新
+
+$(document).ready(function(){
+ // get book title
+ var title = $('h1').text();
+ //title = encodeURI(title);
+ // get book isbn
+ $("#info .obmo .pl").each(function(i){
+ if ($(this).text() == 'ISBN:'){
+ var isbn = $(this)[0].nextSibling.nodeValue;
+ isbn = isbn.substr(1,13);
+
+ setTimeout(function(){GM_xmlhttpRequest({
+ method: 'GET',
+ url: 'http://210.42.106.193/whu.php?isbn='+isbn,
+ headers: {
+ 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
+ 'Accept': 'application/atom+xml,application/xml,text/xml',
+ },
+ onload: function(res) {
+ //GM_log('ajax finished!status:'+ res.status+res.statusText);
+ var json = eval('('+res.responseText+')');
+
+ if (json.ok > 0 ){
+ var openLink = json.href;
+ var htmlStr = '<h2>在武大借这本书 · · · · · · </h2>';
+ htmlStr += '<div class="indent"><h4 style="margin-bottom: 0px;"><a href="'+openLink+'" target="_blank">武汉大学图书馆馆藏</a><span style="margin-left: 20px">索书号 : '+json.index+'<span></h4>';
+
+ htmlStr += '<ul class="bs">';
+ try
+ {
+ for (i=0;i<json.ok;i++)
+ {
+ htmlStr += '<li><span style="float:left">'+json.data[i].place+'</span><span style="float:right">'+json.data[i].s+'</span><br style="clear:both"/></li>';
+ }
+ }
+ catch (e)
+ {
+ }
+
+ htmlStr += '</ul></div></br>';
+
+ $(".aside").prepend(htmlStr);
+ }
+ else{
+ //GM_log('no such book');
+ var openLink = 'http://202.114.65.63/index.html';
+ var htmlStr = '<h2>在武大借这本书 · · · · · · </h2>';
+ htmlStr += '<div class="indent"><a href='+openLink+' target="_blank">前往武汉大学图书馆</a></div>';
+ $(".aside").prepend(htmlStr);
+ }
+ }
+ })},500);
+ }
+ });
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.