From aca061a853a8f0e9dbd828a8c02457aa695bff42 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 2 Dec 2011 09:32:27 +0000 Subject: [PATCH] =?UTF-8?q?heiheview=E4=B8=AD=E5=A2=9E=E5=8A=A0=E4=BA=86go?= =?UTF-8?q?ogle=20scholar=20=E6=90=9C=E7=B4=A2=EF=BC=8C=E5=88=86=E7=A6=BB?= =?UTF-8?q?=E4=BA=86=E2=80=9C=E7=BB=99=E6=88=91=E6=8E=A8=E8=8D=90=E2=80=9D?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=95=B4=E7=90=86=E2=80=9C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=95=B0=E6=8D=AE=E2=80=9D=E2=80=9C=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=96=87=E7=8C=AE=E2=80=9D=E2=80=9C=E7=BB=99=E6=88=91=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E2=80=9D=E5=88=B0service=20controller=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/DataController.php | 76 ---------- .../default/controllers/ServiceController.php | 130 ++++++++++++++++-- .../scripts/data/pagination_recommend.phtml | 26 ++++ .../default/views/scripts/heihe/view.phtml | 48 ++++--- 4 files changed, 173 insertions(+), 107 deletions(-) create mode 100644 application/default/views/scripts/data/pagination_recommend.phtml diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 40b3d2f6..0216c782 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -625,82 +625,6 @@ class DataController extends Zend_Controller_Action } } //viewAction - function relatedAction(){ - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid = $this->_request->getParam('uuid'); - - $sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid - left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where "; - $where=$this->db->quoteInto('m.uuid = ?',$uuid); - $sql.=$where; - $row=$this->db->fetchRow($sql); - if (!$row) exit("读取信息错误"); - $id=$row['id']; - - //相关元数据,根据同名关键词实现 - $sql="select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>?"; - $rows=$this->db->fetchAll($sql,array($id,$id)); - - $paginator = Zend_Paginator::factory($rows); - $paginator->setCurrentPageNumber($this->_getParam('page')); - $paginator->setItemCountPerPage(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_related.phtml'); - $this->config = Zend_Registry::get('config'); - if ($paginator) - { - foreach($paginator as $c) - { - print '
  • '.$c['title']."
  • \r\n"; - } - echo '
    '.$paginator.'
    '; - } - } //相关数据 - - function literatureAction(){ - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - $uuid = $this->_request->getParam('uuid'); - $sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid - left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where "; - $where=$this->db->quoteInto('m.uuid = ?',$uuid); - $sql.=$where; - $row=$this->db->fetchRow($sql); - if (!$row) exit("读取信息错误"); - $id=$row['id']; - - $keys=$this->db->fetchAll("select * from keyword where id=? order by keytype,ts_created",array($id)); - - $wheresql = array(); - foreach ($keys as $k=>$v) - { - if($v['keytype']=="theme") - $wheresql[] = " a.title like '%".$v['keyword']."%' "; - } - $wheresql[] = " 1<>1 "; - $wheresql = join(" or ",$wheresql); - $sql="select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ($wheresql) order by a.ts_created desc"; - $rows = $this->db->fetchAll($sql); - - $paginator = Zend_Paginator::factory($rows); - $paginator->setCurrentPageNumber($this->_getParam('page')); - $paginator->setItemCountPerPage(10); - $paginator->setView($this->view); - Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_literature.phtml'); - $this->config = Zend_Registry::get('config'); - if ($paginator) - { - foreach($paginator as $c) - { - $u=parse_url($c['url']); - if (@$u['host']=='hdl.handle.net') $c['url'] = $this->config->seekspace->handleurl.$u['path']; - print '
  • '.$c['title'].'【'.$c['author'].' '.$c['publisher'].' '.$c['ts_issued']."】
  • "; - } - echo '
    '.$paginator.'
    '; - } - }//相关文献 - function replace($string){ $patterns = array("/\"/i","/\'/i"); $replacements = array("“","‘"); diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 0b8be8cc..aec57f47 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1008,40 +1008,142 @@ class ServiceController extends Zend_Controller_Action function scholar_search($keyword , $referer = 'http://westdc.westgis.ac.cn/'){ $keyword = urlencode($keyword); $url = "http://scholar.google.com/scholar?q=$keyword"; - $url .= "&hl=zh-CN&btnG=搜索&lr="; + $url .= "&hl=en&btnG=搜索&lr="; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, $referer); - $body = curl_exec($ch); + $html = curl_exec($ch); curl_close($ch); $rev = array(); $max = 5; $error=''; - if(preg_match_all("#(.+?)<\/a>#im",$body,$matchs,PREG_PATTERN_ORDER)) + + if(preg_match_all("#

    (.+?)<\/h3>#im",$html,$matchs,PREG_PATTERN_ORDER)) { - foreach ($matchs[2] as $k=>$v){ - if($k < $max) $rev[$k]['title']=$v; - } - foreach ($matchs[1] as $k=>$v){ - if($k < $max) $rev[$k]['url']=$v; + foreach ($matchs[0] as $k=>$v){ + if($k < $max) $rev[$k]['title']=utf8_encode($v); } }else{ $error = "无搜索结果"; } - if(preg_match_all("#(.+?)<\/span>#im",$body,$matchs,PREG_PATTERN_ORDER)) + if(preg_match_all("#<\/span>(.*)
    (.+?)#im",$html,$matchs,PREG_PATTERN_ORDER)) { - foreach ($matchs[1] as $k=>$v){ - if($k < $max) $rev[$k]['content']=$v; + foreach ($matchs[0] as $k=>$v){ + if($k < $max) $rev[$k]['content']=utf8_encode($v); } } - - $response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword,"error"=>$error); + + //var_dump($rev); + //exit(); + $response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://scholar.google.com/scholar?hl=zh-CN&btnG=搜索&lr=&q='.$keyword,"error"=>$error); $rev = Zend_Json::encode($response); return $rev; - }//cnki 搜索 + }//scholar 搜索 + + function recommendAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid = $this->_request->getParam('uuid'); + + $sql = "select d.uuid,count(distinct(d.userid)) as downtimes,m.title from dataorder d left join metadata m on d.uuid=m.uuid where d.userid in ( + select distinct(userid) from dataorder where uuid=? and status in (0,5) + ) and d.uuid<>? and length(m.title)>2 group by d.uuid,m.title order by count(distinct(d.userid)) desc"; + $rows = $this->db->fetchAll($sql,array($uuid,$uuid)); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_recommend.phtml'); + $this->config = Zend_Registry::get('config'); + if ($paginator) + { + foreach($paginator as $c) + { + print '
  • '.$c['title']." [下载人数:".$c['downtimes']."]
  • \r\n"; + } + echo '
    '.$paginator.'
    '; + } + }//相关下载 + + function relatedAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid = $this->_request->getParam('uuid'); + + $sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid + left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where "; + $where=$this->db->quoteInto('m.uuid = ?',$uuid); + $sql.=$where; + $row=$this->db->fetchRow($sql); + if (!$row) exit("读取信息错误"); + $id=$row['id']; + + //相关元数据,根据同名关键词实现 + $sql="select distinct(md.uuid),md.title from keyword kw left join normalmetadata md on kw.id=md.id where kw.keyword in (select k.keyword from keyword k left join metadata m on k.id=m.id where m.id=? and k.keytype='theme') and kw.id<>?"; + $rows=$this->db->fetchAll($sql,array($id,$id)); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_related.phtml'); + $this->config = Zend_Registry::get('config'); + if ($paginator) + { + foreach($paginator as $c) + { + print '
  • '.$c['title']."
  • \r\n"; + } + echo '
    '.$paginator.'
    '; + } + } //相关数据 + + function literatureAction(){ + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid = $this->_request->getParam('uuid'); + $sql="select m.id from normalmetadata m left join mdstatus s on m.uuid=s.uuid + left join thumbnail t on t.id=m.id left join geonetworkmetadata g on m.uuid=g.uuid where "; + $where=$this->db->quoteInto('m.uuid = ?',$uuid); + $sql.=$where; + $row=$this->db->fetchRow($sql); + if (!$row) exit("读取信息错误"); + $id=$row['id']; + + $keys=$this->db->fetchAll("select * from keyword where id=? order by keytype,ts_created",array($id)); + + $wheresql = array(); + foreach ($keys as $k=>$v) + { + if($v['keytype']=="theme") + $wheresql[] = " a.title like '%".$v['keyword']."%' "; + } + $wheresql[] = " 1<>1 "; + $wheresql = join(" or ",$wheresql); + $sql="select a.*,array_to_string(array(select author from knl_author t where t.item_id=a.item_id order by place asc),'; ') as author from knl_article a where ($wheresql) order by a.ts_created desc"; + $rows = $this->db->fetchAll($sql); + + $paginator = Zend_Paginator::factory($rows); + $paginator->setCurrentPageNumber($this->_getParam('page')); + $paginator->setItemCountPerPage(10); + $paginator->setView($this->view); + Zend_View_Helper_PaginationControl::setDefaultViewPartial('data/pagination_literature.phtml'); + $this->config = Zend_Registry::get('config'); + if ($paginator) + { + foreach($paginator as $c) + { + $u=parse_url($c['url']); + if (@$u['host']=='hdl.handle.net') $c['url'] = $this->config->seekspace->handleurl.$u['path']; + print '
  • '.$c['title'].'【'.$c['author'].' '.$c['publisher'].' '.$c['ts_issued']."】
  • "; + } + echo '
    '.$paginator.'
    '; + } + }//相关文献 } diff --git a/application/default/views/scripts/data/pagination_recommend.phtml b/application/default/views/scripts/data/pagination_recommend.phtml new file mode 100644 index 00000000..f93d00e2 --- /dev/null +++ b/application/default/views/scripts/data/pagination_recommend.phtml @@ -0,0 +1,26 @@ +pageCount): ?> +
    + +previous)): ?> + < Previous + + < Previous + + + +pagesInRange as $page): ?> + current): ?> + + + + + + + +next)): ?> + Next > + + Next > + +
    + \ No newline at end of file diff --git a/application/default/views/scripts/heihe/view.phtml b/application/default/views/scripts/heihe/view.phtml index 73988f96..0e2a5ce8 100755 --- a/application/default/views/scripts/heihe/view.phtml +++ b/application/default/views/scripts/heihe/view.phtml @@ -230,11 +230,11 @@ endforeach; $ev = join(" ",$keywords); ?> @@ -375,14 +375,21 @@ function postcomment(){ $.ajax({'type':"POST",'url':"/data/postcomment",'data':$ 'success':function(html){$('#postcomment').html('提交');setTimeout("$('#postcomment').removeAttr('disabled');",3000); $('#returninfo').html(html);ajaxpage(0);}, 'beforeSend':function(){$('#postcomment').attr('disabled','disabled');$('#postcomment').html('正在提交...'); }});} +$('#literature_t').click(function(){literature(1);}); //ajax literature -function literature(page){$.ajax({type:"GET",url:"/data/literature/uuid/uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('
      '+html+'
    ');}, -beforeSend:function(){$('#literature').html('加载中');}});};literature(1); +function literature(page){$.ajax({type:"GET",url:"/service/literature/uuid/uuid; ?>",data:'page='+page,success:function(html){$('#literature').html('
      '+html+'
    ');}, +beforeSend:function(){$('#literature').html('加载中');}});} +$('#related_t').click(function(){related(1);}); //ajax related -function related(page){$.ajax({type:"GET",url:"/data/related/uuid/uuid; ?>",data:'page='+page,success:function(html){$('#related').html('
      '+html+'
    ');}, +function related(page){$.ajax({type:"GET",url:"/service/related/uuid/uuid; ?>",data:'page='+page,success:function(html){$('#related').html('
      '+html+'
    ');}, beforeSend:function(){$('#related').html('加载中');}});};related(1); +$('#recommend_t').click(function(){recommend(1);}); +//ajax recommend +function recommend(page){$.ajax({type:"GET",url:"/service/recommend/uuid/uuid; ?>",data:'page='+page,success:function(html){$('#recommend').html('
      '+html+'
    ');}, +beforeSend:function(){$('#related').html('加载中');}});} + function getFileList(){ var tw = ($(window).width() - $('#window-outter').width())/2; $('#window-outter').css({'right':tw}); @@ -440,7 +447,7 @@ function getSubFileList(uuid,id,depth){ $('.googlesearch').click(function(){googleSearch('');}); $('.bingsearch').click(function(){bingSearch('');}); $('.cnkiSearch').click(function(){cnkiSearch('');}); -$('.scholar')click(function(){}); +$('.scholar').click(function(){scholarSearch('');}); function googleSearch(keyword){ $.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword, @@ -465,16 +472,23 @@ function googleSearch(keyword){ function scholarSearch(keyword){ $.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword, success:function(html){ - var items = []; + //$('#searchlist').html(html); + var items = []; var obj = jQuery.parseJSON(html); - $.each(obj.responseData.results, function(key, val) { - var html = '

    '+val['title']+'

    ' - +val['url'].replace(/%(.*)/i,"") +'

    ' - +val['content'] - +'

    '; - items.push('
  • ' + html + '
  • '); - }); - items.push('
  • 查看更多搜索结果(约'+obj.responseData.cursor.estimatedResultCount+'条)'); + if(obj.error != '') + { + items.push('
  • ' + obj.error + '
  • '); + }else{ + $.each(obj.result, function(key, val) { + var html = '

    '+val['title']+'

    ' + +'

    ' + +val['content'] + +'

    '; + + items.push('
  • ' + html + '
  • '); + }); + } + items.push('
  • 查看更多搜索结果'); $('#searchlist').html(items.join('')); $('html, body').animate({scrollTop:$('html').height()}, 'slow'); }, @@ -512,7 +526,7 @@ function cnkiSearch(keyword){ items.push('
  • ' + obj.error + '
  • '); }else{ $.each(obj.result, function(key, val) { - var html = '

    '+val['title']+'

    ' + var html = '

    '+val['title']+'

    ' +val['url'].replace(/%(.*)/i,"") +'

    ' +val['content'] +'

    ';