From 753963a83987730e37c8c4b91a3a49d7030a19d2 Mon Sep 17 00:00:00 2001 From: wlx Date: Tue, 14 May 2013 10:03:27 +0000 Subject: [PATCH] #453, add bibtex citation support --- .../default/controllers/ServiceController.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/application/default/controllers/ServiceController.php b/application/default/controllers/ServiceController.php index 0a93ec39..1ba63469 100644 --- a/application/default/controllers/ServiceController.php +++ b/application/default/controllers/ServiceController.php @@ -1434,4 +1434,50 @@ class ServiceController extends Zend_Controller_Action ->setBody($ris); } } + + //Bibtex format convert + function bibtexAction() + { + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + $uuid=$this->_request->getParam('uuid'); + $lang=$this->_request->getParam('lang'); + $bib=''; + if ($lang=='cn' && !empty($uuid)) + { + $sql="select d.*,m.description from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; + $row=$this->db->fetchRow($sql); + $bib.='@article{'.$row['doi'].",\r\n"; + $bib.=' author = '.str_replace('"','',$row['authors']).",\r\n"; + $bib.=' journal = {'.$row['publisher']."},\r\n"; + $bib.=' publisher = {'.$row['publisher']."},\r\n"; + $bib.=' title = {'.$row['title']."},\r\n"; + $bib.=' year = {'.date('Y',strtotime($row['ts_published']))."},\r\n"; + $bib.=' month = {'.date('m',strtotime($row['ts_published']))."},\r\n"; + $bib.=' url = {http://dx.doi.org/'.$row['doi']."},\r\n"; + $bib.=' doi = {'.$row['doi']."}\r\n"; + $bib.="}\r\n"; + } + else if ($lang=='en' && !empty($uuid)) + { + $sql="select d.*,m.description from datadoi d left join metadata m on d.uuid=m.uuid where d.uuid='$uuid' and d.ts_published is not null"; + $row=$this->db->fetchRow($sql); + $bib.='@article{'.$row['doi'].",\r\n"; + $bib.=' author = '.str_replace('"','',$row['author_en']).",\r\n"; + $bib.=' journal = {'.$row['publisher_en']."},\r\n"; + $bib.=' publisher = {'.$row['publisher_en']."},\r\n"; + $bib.=' title = {'.$row['title']."},\r\n"; + $bib.=' year = {'.date('Y',strtotime($row['ts_published']))."},\r\n"; + $bib.=' month = {'.date('m',strtotime($row['ts_published']))."},\r\n"; + $bib.=' url = {http://dx.doi.org/'.$row['doi']."},\r\n"; + $bib.=' doi = {'.$row['doi']."}\r\n"; + $bib.="}\r\n"; + } + if (!empty($bib)) + { + $this->getResponse()->setHeader('Content-Type', 'application/x-Bibtex')->setHeader('Content-Disposition','attachment; filename="'.$uuid.'.bib"') + //->setHeader('Content-Type','application/force-download') + ->setBody($bib); + } + } }