From 6ed2c565455ca6cd2c9470ced180bb4a700ae5c8 Mon Sep 17 00:00:00 2001 From: kmorimatsu Date: Tue, 3 Feb 2009 20:18:10 +0000 Subject: [PATCH] NP_PubMed v0.2.2 git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@896 1ca29b6e-896d-4ea0-84a5-967f57386b96 --- NP_PubMed/trunk/NP_PubMed.php | 6 +- NP_PubMed/trunk/pubmed/index.php | 161 +++++++++++++++++++++++++++++++--- NP_PubMed/trunk/pubmed/index.xml | 120 +++++++++++++++++++++++++ NP_PubMed/trunk/spring/sidebar.inc | 6 +- NP_PubMed/trunk/spring/skinbackup.xml | 7 +- 5 files changed, 283 insertions(+), 17 deletions(-) diff --git a/NP_PubMed/trunk/NP_PubMed.php b/NP_PubMed/trunk/NP_PubMed.php index f95451d..f8c63fe 100644 --- a/NP_PubMed/trunk/NP_PubMed.php +++ b/NP_PubMed/trunk/NP_PubMed.php @@ -3,7 +3,7 @@ class NP_PubMed extends NucleusPlugin { function getName() { return 'NP_PubMed'; } function getMinNucleusVersion() { return 330; } function getAuthor() { return 'Katsumi'; } - function getVersion() { return '0.2.1'; } + function getVersion() { return '0.2.2'; } function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:authors:katsumi';} function getDescription() { return $this->getName().' plugin
'. @@ -16,8 +16,9 @@ class NP_PubMed extends NucleusPlugin { function getTableList() { return array(sql_table('plugin_pubmed_references'), sql_table('plugin_pubmed_manuscripts')); } function install(){ global $member; - $this->createOption('droptable','Drop table when uninstall?','yesno','no'); $this->createOption('lastquerytime','hidden option','text','0','access=hidden'); + $this->createOption('lastmanualpmid','hidden option','text','1000000000','access=hidden'); + $this->createOption('droptable','Drop table when uninstall?','yesno','no'); $this->createOption('email','E-mail address to be sent to PubMed search site (set blank if not use):','text',$member->getEmail()); sql_query('CREATE TABLE IF NOT EXISTS '.sql_table('plugin_pubmed_references').' ('. ' id int(11) not null auto_increment,'. @@ -373,6 +374,7 @@ END; htmlspecialchars($text).''; break; case 'edit': + if (!$member->isLoggedIn()) return; $itemid=(int)$item->itemid; $text=$p1?'manuscript management':htmlspecialchars($p1,ENT_QUOTES); $width=(int)$p2; diff --git a/NP_PubMed/trunk/pubmed/index.php b/NP_PubMed/trunk/pubmed/index.php index ab0ca51..ffe7488 100644 --- a/NP_PubMed/trunk/pubmed/index.php +++ b/NP_PubMed/trunk/pubmed/index.php @@ -5,8 +5,8 @@ require('../../../config.php'); // An instance will be created at the end of this file class PubMedAdmin extends BaseActions { - var $oPluginAdmin,$plugin; - var $blogid; + private $oPluginAdmin,$plugin; + private $blogid; function __construct(){ if (method_exists($this,'BaseActions')) $this->BaseActions(); @@ -19,9 +19,15 @@ class PubMedAdmin extends BaseActions { if (!($this->blogid=intPostVar('blogid'))) $this->blogid=intGetVar('blogid'); $CONF['ItemURL']=quickQuery('SELECT burl as result FROM '.sql_table('blog'). ' WHERE bnumber='.(int)$this->blogid); - // Check if there is right to maintain the blog by member. - if (!$member->isLoggedIn() || !$member->teamRights($this->blogid) || !$manager->existsBlogID($this->blogid)) - { + // Check if there is right to maintain the blog or the manuscript. + $ok=true; + if (!$member->isLoggedIn()) $ok=false; + if (!$member->CanLogin()) $ok=false; + if ($this->blogid) { + if (!$member->teamRights($this->blogid)) $ok=false; + if (!$manager->existsBlogID($this->blogid)) $ok=false; + } + if (!$ok) { $this->oPluginAdmin->start(); echo '

' . _ERROR_DISALLOWED . '

'; $this->oPluginAdmin->end(); @@ -30,7 +36,6 @@ class PubMedAdmin extends BaseActions { // If some data is/are posted, check the ticket. // Therefore, POST method must be used to change important parameter(s). - if (!isset($_POST)) $_POST=&$HTTP_POST_VARS; if (count($_POST) && !$manager->checkTicket()) { $this->oPluginAdmin->start(); echo '

Error: ' . _ERROR_BADTICKET . '

'; @@ -49,8 +54,8 @@ class PubMedAdmin extends BaseActions { $this->oPluginAdmin->start(); switch(getVar('action')) { case 'manuscriptlist': - echo '

' . + echo '

' . 'Manuscript management' . "

\n"; break; default: @@ -340,8 +345,7 @@ class PubMedAdmin extends BaseActions { $mname=$this->_checkmanuscriptname(postVar('manuscriptname')); if ($mname) sql_query('INSERT INTO '.sql_table('plugin_pubmed_manuscripts').' SET'. ' userid='.(int)$mid.','. - ' manuscriptname="'.addslashes($mname).'"'. - ' sorttext="authorname"'); + ' manuscriptname="'.addslashes($mname).'"'); return $this->action_manuscriptlist(); } private function _getSortMethod($tempname){ @@ -423,6 +427,143 @@ class PubMedAdmin extends BaseActions { $this->contents=array('mid'=>$manuscriptid,'mname'=>$mname); $this->_showUsingArray('editmanuscript',$array); } + function action_addmanually(){ + global $manager; + if (count($_POST)) { + // Add item with the defined PMID + $pmid=intPostVar('pmid'); + // Determine author list + $author=requestArray('author'); + $authorf=requestArray('authorf'); + $authorm=requestArray('authorm'); + $authors=array(); + foreach($author as $key=>$value){ + if (!strlen($value)) break; + $a=$author[$key]; + $f=$authorf[$key]; + $m=$authorm[$key]; + $i=substr($f,0,1).substr($m,0,1); + $authors[$key]=array( + 'LastName'=>$a, + 'ForeName'=>$f, + 'Initials'=>$i); + } + ksort($authors); + // Construct Article + if (($year=intPostVar('year'))==0) $year='???'; + if (strlen($journalname=postVar('journal'))==0) $journalname='???'; + if (strlen($volume=postVar('volume'))==0) $volume='???'; + if (strlen($pages=postVar('pages'))==0) $pages='???'; + if (strlen($title=postVar('title'))==0) $title='???'; + if (strlen($abstract=postVar('abstract'))==0) $abstract='???'; + $journal=array( + 'ISOAbbreviation'=>$journalname, + 'JournalIssue'=>array( + 'Volume'=>$volume, + 'PubDate'=>array('Year'=>$year) + ) + ); + $article=array( + 'Journal'=>$journal, + 'ArticleTitle'=>$title, + 'Pagination'=>array('MedlinePgn'=>$pages), + 'AuthorList'=>array('Author'=>$authors) + ); + // Construct XML data as more + $medline=array( + 'PMID'=>$pmid, + 'Article'=>$article + ); + $more=''.htmlspecialchars($abstract).''; + $more.="_convert2xml('MedlineCitation',$medline); + $more.=']]>'; + // Construct body + $body="PMID: $pmid\n"; + $body.=''; + $n=count($authors); + for ($i=1;$i<=$n;$i++) { + if (1<$i) { + $body.=', '; + if ($i==$n) $body.='and '; + } + $body.=htmlspecialchars($authors[$i]['LastName']); + } + $body.=" ($year)\n"; + $body.=''.htmlspecialchars($journalname). + ' '.htmlspecialchars($volume). + ' '.htmlspecialchars($pages)."\n"; + $body.=''.htmlspecialchars($title).''; + // Construct title + switch($n){ + case 1: + $title=$authors[1]['LastName']; + break; + case 2: + $title=$authors[1]['LastName'].' and '.$authors[2]['LastName']; + break; + default: + $title=$authors[1]['LastName'].' et al.'; + break; + } + $title=htmlspecialchars($title." ($year) $journalname"); + // Construct category options + $defcatid=(int)cookieVar($CONF['CookiePrefix'] . 'NP_PubMed_defcatid'); + if (!$defcatid) { + $blog=$manager->getBlog($this->blogid); + $defcatid=$blog->getDefaultCategory(); + } + $res=sql_query('SELECT * FROM '.sql_table('category'). + ' WHERE cblog='.(int)$this->blogid.' ORDER BY cname ASC'); + $array=array(); + while($row=mysql_fetch_assoc($res)){ + $row['selected']= ($row['catid']==$defcatid); + $array[]=$row; + } + // parse + $this->contents=array('title'=>$title,'body'=>$body,'more'=>$more); + $this->_showUsingArray('addmanuallyconfirm',$array); + return; + } + // Decide PMID + $pmid=1+$this->plugin->getOption('lastmanualpmid'); + if ($pmid<1000000000) $pmid=1000000001; + $i=1; + while(quickQuery('SELECT count(*) as result from '.sql_table('item'). + ' WHERE iblog='.(int)$this->blogid. + ' AND ibody LIKE "%'.(int)$pmid.'%"') ){ + $this->plugin->setOption('lastmanualpmid',$pmid); + $pmid+=$i; + $i+=rand(1,$i); + } + // Get the number of authors + $numauthor=intGetVar('numauthor'); + if (!$numauthor) $numauthor=3; + $array=array(); + for ($i=1;$i<=$numauthor;$i++) { + $array[]=array('i'=>$i); + } + // parse + $this->contents=array('pmid'=>$pmid,'i'=>$numauthor,'numauthor'=>$numauthor*2); + $this->_showUsingArray('addmanually',$array); + } + function _convert2xml($key,$value,$nest=0){ + if (!preg_match('/^[a-zA-Z0-9_]+$/',$key)) exit; + if (!is_array($value)) { + $value=str_replace(array('<','>'),array('>','<'),$value); + return str_repeat(' ',$nest)."<$key>$value\n"; + } + $xml=''; + foreach ($value as $k=>$v) { + if (is_numeric($k)) $xml.=$this->_convert2xml($key,$v,$nest+1); + else { + if ($xml=='') $xml=str_repeat(' ',$nest)."<$key>\n"; + $xml.=$this->_convert2xml($k,$v,$nest+1); + } + } + if (!is_numeric($k)) $xml.=str_repeat(' ',$nest)."\n"; + return $xml; + } } new PubMedAdmin; diff --git a/NP_PubMed/trunk/pubmed/index.xml b/NP_PubMed/trunk/pubmed/index.xml index ccdf69c..d07376b 100644 --- a/NP_PubMed/trunk/pubmed/index.xml +++ b/NP_PubMed/trunk/pubmed/index.xml @@ -242,4 +242,124 @@ Are you sure?   ]]> + + + + + + + + + diff --git a/NP_PubMed/trunk/spring/sidebar.inc b/NP_PubMed/trunk/spring/sidebar.inc index 6161bb1..787330c 100644 --- a/NP_PubMed/trunk/spring/sidebar.inc +++ b/NP_PubMed/trunk/spring/sidebar.inc @@ -12,8 +12,10 @@
Navigation
NIH PubMed site
-<%if(loggedin)%> +<%if(admin)%>
PubMed search
+<%endif%> +<%if(loggedin)%>
Admin
<%endif%> @@ -24,7 +26,7 @@ diff --git a/NP_PubMed/trunk/spring/skinbackup.xml b/NP_PubMed/trunk/spring/skinbackup.xml index 4b499c6..917fecd 100644 --- a/NP_PubMed/trunk/spring/skinbackup.xml +++ b/NP_PubMed/trunk/spring/skinbackup.xml @@ -7,7 +7,7 @@ - Nucleus CMS spring skin + NP_PubMed spring skin @@ -141,6 +141,7 @@ body { margin: 0px; }
<%PubMed(SearchLink)%>

<%PubMed(CreateNew)%> +Manually add paper <%parsedinclude(paging.inc)%> @@ -293,7 +294,7 @@ onclick="window.open(this.href);return false;"