From 4b5afe8ed98e1a00df3321888136d3513160c179 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Mon, 14 Nov 2011 02:30:23 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=9A=84google=20ajax=E6=90=9C=E7=B4=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/ServiceController.php | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 2fed1b05..47be8453 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -741,21 +741,49 @@ class ServiceController extends Zend_Controller_Action throw new Exception('发生严重意外!您确认链接正确?'); } - } - + } + function mdjsonAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); - $num=(int)$this->_request->getParam('num'); - $source=$this->_request->getParam('source'); - if (empty($num)) $num=3; - $sql="select m.uuid,m.title,m.id,substring(m.description from 0 for 200) as description from normalmetadata m left join thumbnail t on m.id=t.id where "; - if (!empty($source)) - $sql.=$this->db->quoteInto(" m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code=?) and ",$source); + $num=(int)$this->_request->getParam('num'); + $source=$this->_request->getParam('source'); + if (empty($num)) $num=3; + $sql="select m.uuid,m.title,m.id,substring(m.description from 0 for 200) as description from normalmetadata m left join thumbnail t on m.id=t.id where "; + if (!empty($source)) + $sql.=$this->db->quoteInto(" m.uuid in (select d.uuid from datasource d left join source s on d.sourceid=s.id where s.code=?) and ",$source); $sql.=" length(t.data)>2 order by random() limit $num"; - $rows=$this->db->fetchAll($sql); + $rows=$this->db->fetchAll($sql); echo Zend_Json::encode($rows); - } + } + + function googlesearchAction(){ + + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $q = $this->_request->getParam('q'); + $rez = $this->google_search_api(array( + 'q' => $q, // 查询内容 + 'key' => $this->config->google->maps->api, + 'userip' => $_SERVER['REMOTE_ADDR'], + )); + print_r($rez); + exit(); + } + + function google_search_api($args, $referer = 'http://westdc.westgis.ac.cn/', $endpoint = 'web'){ + $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint; + if ( !array_key_exists('v', $args) ) + $args['v'] = '1.0'; + $url .= '?'.http_build_query($args, '', '&'); + $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); + curl_close($ch); + return $body; + } }