OSDN Git Service

NP_PubMed v0.2.2
authorkmorimatsu <kmorimatsu@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Tue, 3 Feb 2009 20:18:10 +0000 (20:18 +0000)
committerkmorimatsu <kmorimatsu@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Tue, 3 Feb 2009 20:18:10 +0000 (20:18 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@896 1ca29b6e-896d-4ea0-84a5-967f57386b96

NP_PubMed/trunk/NP_PubMed.php
NP_PubMed/trunk/pubmed/index.php
NP_PubMed/trunk/pubmed/index.xml
NP_PubMed/trunk/spring/sidebar.inc
NP_PubMed/trunk/spring/skinbackup.xml

index f95451d..f8c63fe 100644 (file)
@@ -3,7 +3,7 @@ class NP_PubMed extends NucleusPlugin {
        function getName() { return 'NP_PubMed'; }\r
        function getMinNucleusVersion() { return 330; }\r
        function getAuthor()  { return 'Katsumi'; }\r
-       function getVersion() { return '0.2.1'; }\r
+       function getVersion() { return '0.2.2'; }\r
        function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:authors:katsumi';}\r
        function getDescription() {\r
                return $this->getName().' plugin<br />'.\r
@@ -16,8 +16,9 @@ class NP_PubMed extends NucleusPlugin {
        function getTableList() { return array(sql_table('plugin_pubmed_references'), sql_table('plugin_pubmed_manuscripts')); }\r
        function install(){\r
                global $member;\r
-               $this->createOption('droptable','Drop table when uninstall?','yesno','no');\r
                $this->createOption('lastquerytime','hidden option','text','0','access=hidden');\r
+               $this->createOption('lastmanualpmid','hidden option','text','1000000000','access=hidden');\r
+               $this->createOption('droptable','Drop table when uninstall?','yesno','no');\r
                $this->createOption('email','E-mail address to be sent to PubMed search site (set blank if not use):','text',$member->getEmail());\r
                sql_query('CREATE TABLE IF NOT EXISTS '.sql_table('plugin_pubmed_references').' ('.\r
                        ' id int(11) not null auto_increment,'.\r
@@ -373,6 +374,7 @@ END;
                                        htmlspecialchars($text).'</a>';\r
                                break;\r
                        case 'edit':\r
+                               if (!$member->isLoggedIn()) return;\r
                                $itemid=(int)$item->itemid;\r
                                $text=$p1?'manuscript management':htmlspecialchars($p1,ENT_QUOTES);\r
                                $width=(int)$p2;\r
index ab0ca51..ffe7488 100644 (file)
@@ -5,8 +5,8 @@ require('../../../config.php');
 // An instance will be created at the end of this file\r
 \r
 class PubMedAdmin extends BaseActions {\r
-       var $oPluginAdmin,$plugin;\r
-       var $blogid;\r
+       private $oPluginAdmin,$plugin;\r
+       private $blogid;\r
        function __construct(){\r
                if (method_exists($this,'BaseActions')) $this->BaseActions();\r
        \r
@@ -19,9 +19,15 @@ class PubMedAdmin extends BaseActions {
                if (!($this->blogid=intPostVar('blogid'))) $this->blogid=intGetVar('blogid');\r
                $CONF['ItemURL']=quickQuery('SELECT burl as result FROM '.sql_table('blog'). ' WHERE bnumber='.(int)$this->blogid);\r
                \r
-               // Check if there is right to maintain the blog by member.\r
-               if (!$member->isLoggedIn() || !$member->teamRights($this->blogid) || !$manager->existsBlogID($this->blogid))\r
-               {\r
+               // Check if there is right to maintain the blog or the manuscript.\r
+               $ok=true;\r
+               if (!$member->isLoggedIn()) $ok=false;\r
+               if (!$member->CanLogin()) $ok=false;\r
+               if ($this->blogid) {\r
+                       if (!$member->teamRights($this->blogid)) $ok=false;\r
+                       if (!$manager->existsBlogID($this->blogid)) $ok=false;\r
+               }\r
+               if (!$ok) {\r
                        $this->oPluginAdmin->start();\r
                        echo '<p>' . _ERROR_DISALLOWED . '</p>';\r
                        $this->oPluginAdmin->end();\r
@@ -30,7 +36,6 @@ class PubMedAdmin extends BaseActions {
                \r
                // If some data is/are posted, check the ticket.\r
                // Therefore, POST method must be used to change important parameter(s).\r
-               if (!isset($_POST)) $_POST=&$HTTP_POST_VARS;\r
                if (count($_POST) && !$manager->checkTicket()) {\r
                        $this->oPluginAdmin->start();\r
                        echo '<p class="error">Error: ' . _ERROR_BADTICKET . '</p>';\r
@@ -49,8 +54,8 @@ class PubMedAdmin extends BaseActions {
                $this->oPluginAdmin->start();\r
                switch(getVar('action')) {\r
                        case 'manuscriptlist':\r
-                               echo '<h2><a href="'.$this->plugin->getAdminURL().'?blogid='.\r
-                                       (int)$this->blogid.'&amp;action=manuscriptlist">' . \r
+                               echo '<h2><a href="'.$this->plugin->getAdminURL().\r
+                                       '?action=manuscriptlist">' . \r
                                        'Manuscript management' . "</a></h2>\n";\r
                                break;\r
                        default:\r
@@ -340,8 +345,7 @@ class PubMedAdmin extends BaseActions {
                $mname=$this->_checkmanuscriptname(postVar('manuscriptname'));\r
                if ($mname) sql_query('INSERT INTO '.sql_table('plugin_pubmed_manuscripts').' SET'.\r
                                ' userid='.(int)$mid.','.\r
-                               ' manuscriptname="'.addslashes($mname).'"'.\r
-                               ' sorttext="authorname"');\r
+                               ' manuscriptname="'.addslashes($mname).'"');\r
                return $this->action_manuscriptlist();\r
        }\r
        private function _getSortMethod($tempname){\r
@@ -423,6 +427,143 @@ class PubMedAdmin extends BaseActions {
                $this->contents=array('mid'=>$manuscriptid,'mname'=>$mname);\r
                $this->_showUsingArray('editmanuscript',$array);\r
        }\r
+       function action_addmanually(){\r
+               global $manager;\r
+               if (count($_POST)) {\r
+                       // Add item with the defined PMID\r
+                       $pmid=intPostVar('pmid');\r
+                       // Determine author list\r
+                       $author=requestArray('author');\r
+                       $authorf=requestArray('authorf');\r
+                       $authorm=requestArray('authorm');\r
+                       $authors=array();\r
+                       foreach($author as $key=>$value){\r
+                               if (!strlen($value)) break;\r
+                               $a=$author[$key];\r
+                               $f=$authorf[$key];\r
+                               $m=$authorm[$key];\r
+                               $i=substr($f,0,1).substr($m,0,1);\r
+                               $authors[$key]=array(\r
+                                       'LastName'=>$a,\r
+                                       'ForeName'=>$f,\r
+                                       'Initials'=>$i);\r
+                       }\r
+                       ksort($authors);\r
+                       // Construct Article\r
+                       if (($year=intPostVar('year'))==0) $year='???';\r
+                       if (strlen($journalname=postVar('journal'))==0) $journalname='???';\r
+                       if (strlen($volume=postVar('volume'))==0) $volume='???';\r
+                       if (strlen($pages=postVar('pages'))==0) $pages='???';\r
+                       if (strlen($title=postVar('title'))==0) $title='???';\r
+                       if (strlen($abstract=postVar('abstract'))==0) $abstract='???';\r
+                       $journal=array(\r
+                               'ISOAbbreviation'=>$journalname,\r
+                               'JournalIssue'=>array(\r
+                                       'Volume'=>$volume,\r
+                                       'PubDate'=>array('Year'=>$year)\r
+                                       )\r
+                               );\r
+                       $article=array(\r
+                               'Journal'=>$journal,\r
+                               'ArticleTitle'=>$title,\r
+                               'Pagination'=>array('MedlinePgn'=>$pages),\r
+                               'AuthorList'=>array('Author'=>$authors)\r
+                               );\r
+                       // Construct XML data as more\r
+                       $medline=array(\r
+                               'PMID'=>$pmid,\r
+                               'Article'=>$article\r
+                               );\r
+                       $more='<span class="np_pubmed_abstract">'.htmlspecialchars($abstract).'</span>';\r
+                       $more.="<span style=\"display:none;\"><![CDATA[\n";\r
+                       $more.=$this->_convert2xml('MedlineCitation',$medline);\r
+                       $more.=']]></span>';\r
+                       // Construct body\r
+                       $body="<!--$year--><!--PMID: $pmid-->PMID: $pmid\n";\r
+                       $body.='<span class="np_pubmed_authors">';\r
+                       $n=count($authors);\r
+                       for ($i=1;$i<=$n;$i++) {\r
+                               if (1<$i) {\r
+                                       $body.=', ';\r
+                                       if ($i==$n) $body.='and ';\r
+                               }\r
+                               $body.=htmlspecialchars($authors[$i]['LastName']);\r
+                       }\r
+                       $body.=" ($year)</span>\n";\r
+                       $body.='<span class="np_pubmed_article"><i>'.htmlspecialchars($journalname).\r
+                               '</i> <b>'.htmlspecialchars($volume).\r
+                               '</b> '.htmlspecialchars($pages)."</span>\n";\r
+                       $body.='<span class="np_pubmed_title">'.htmlspecialchars($title).'</span>';\r
+                       // Construct title\r
+                       switch($n){\r
+                               case 1:\r
+                                       $title=$authors[1]['LastName'];\r
+                                       break;\r
+                               case 2:\r
+                                       $title=$authors[1]['LastName'].' and '.$authors[2]['LastName'];\r
+                                       break;\r
+                               default:\r
+                                       $title=$authors[1]['LastName'].' et al.';\r
+                                       break;\r
+                       }\r
+                       $title=htmlspecialchars($title." ($year) $journalname");\r
+                       // Construct category options\r
+                       $defcatid=(int)cookieVar($CONF['CookiePrefix'] . 'NP_PubMed_defcatid');\r
+                       if (!$defcatid) {\r
+                               $blog=$manager->getBlog($this->blogid);\r
+                               $defcatid=$blog->getDefaultCategory();\r
+                       }\r
+                       $res=sql_query('SELECT * FROM '.sql_table('category').\r
+                               ' WHERE cblog='.(int)$this->blogid.' ORDER BY cname ASC');\r
+                       $array=array();\r
+                       while($row=mysql_fetch_assoc($res)){\r
+                               $row['selected']= ($row['catid']==$defcatid);\r
+                               $array[]=$row;\r
+                       }\r
+                       // parse\r
+                       $this->contents=array('title'=>$title,'body'=>$body,'more'=>$more);\r
+                       $this->_showUsingArray('addmanuallyconfirm',$array);\r
+                       return;\r
+               }\r
+               // Decide PMID\r
+               $pmid=1+$this->plugin->getOption('lastmanualpmid');\r
+               if ($pmid<1000000000) $pmid=1000000001;\r
+               $i=1;\r
+               while(quickQuery('SELECT count(*) as result from '.sql_table('item').\r
+                               ' WHERE iblog='.(int)$this->blogid.\r
+                               ' AND ibody LIKE "%'.(int)$pmid.'%"') ){\r
+                       $this->plugin->setOption('lastmanualpmid',$pmid);\r
+                       $pmid+=$i;\r
+                       $i+=rand(1,$i);\r
+               }\r
+               // Get the number of authors\r
+               $numauthor=intGetVar('numauthor');\r
+               if (!$numauthor) $numauthor=3;\r
+               $array=array();\r
+               for ($i=1;$i<=$numauthor;$i++) {\r
+                       $array[]=array('i'=>$i);\r
+               }\r
+               // parse\r
+               $this->contents=array('pmid'=>$pmid,'i'=>$numauthor,'numauthor'=>$numauthor*2);\r
+               $this->_showUsingArray('addmanually',$array);\r
+       }\r
+       function _convert2xml($key,$value,$nest=0){\r
+               if (!preg_match('/^[a-zA-Z0-9_]+$/',$key)) exit;\r
+               if (!is_array($value)) {\r
+                       $value=str_replace(array('<','>'),array('&gt;','&lt;'),$value);\r
+                       return str_repeat('  ',$nest)."<$key>$value</$key>\n";\r
+               }\r
+               $xml='';\r
+               foreach ($value as $k=>$v) {\r
+                       if (is_numeric($k)) $xml.=$this->_convert2xml($key,$v,$nest+1);\r
+                       else {\r
+                               if ($xml=='') $xml=str_repeat('  ',$nest)."<$key>\n";\r
+                               $xml.=$this->_convert2xml($k,$v,$nest+1);\r
+                       }\r
+               }\r
+               if (!is_numeric($k)) $xml.=str_repeat('  ',$nest)."</$key>\n";\r
+               return $xml;\r
+       }\r
 }\r
 \r
 new PubMedAdmin;\r
index ccdf69c..d07376b 100644 (file)
@@ -242,4 +242,124 @@ Are you sure?&nbsp;&nbsp;
     ]]></foot>\r
   </template>\r
 \r
+\r
+\r
+  <template>\r
+    <name>addmanually</name>\r
+    <head><![CDATA[\r
+\r
+<p>Add a paper that does not have PMID.</p>\r
+\r
+<form method="post" action="">\r
+<%ticket(hidden)%>\r
+<table>\r
+<tr>\r
+  <td>PMID:</td>\r
+  <td><input type="text" name="pmid" size="20" value="<%int(pmid)%>"/></td>\r
+  <td>year:</td>\r
+  <td colspan="3"><input type="text" name="year" size="10" value=""/></td>\r
+</tr><tr>\r
+  <td>title:</td>\r
+  <td colspan="5"><input type="text" name="title" size="100" value=""/></td>\r
+</tr><tr>\r
+  <td>journal name:</td>\r
+  <td><input type="text" name="journal" size="20" value=""/></td>\r
+  <td>volume:</td>\r
+  <td><input type="text" name="volume" size="10" value=""/></td>\r
+  <td>pages:</td>\r
+  <td><input type="text" name="pages" size="10" value=""/></td>\r
+</tr>\r
+<tr>\r
+  <td>author(s)</td>\r
+  <td colspan="5">\r
+\r
+    ]]></head>\r
+    <body><![CDATA[\r
+\r
+    <%int(i)%>:\r
+    <input type="text" name="author[<%int(i)%>]" size="20" value=""/>,\r
+    <input type="text" name="authorf[<%int(i)%>]" size="20" value=""/>\r
+    <input type="text" name="authorm[<%int(i)%>]" size="2" value=""/>.\r
+    <br />\r
+\r
+    ]]></body>\r
+    <foot><![CDATA[\r
+\r
+    <span id="np_pubmed_author<%int(i)%>">\r
+      <a href="<%self%>?blogid=<%blogid%>&amp;action=addmanually&amp;numauthor=<%int(numauthor)%>" onclick="np_pubmed_author(<%int(i)%>); return false;">more authors</a>\r
+    </span>\r
+  </td>\r
+</tr><tr>\r
+  <td>abstract:</td>\r
+  <td colspan="5"><textarea name="abstract" cols="100" rows="10"></textarea></td>\r
+</tr>\r
+</table>\r
+<input type="submit" value="Add this paper"/>\r
+</form>\r
+<script type="text/javascript">\r
+//<![CDATA[\r
+function np_pubmed_author(i){\r
+  var obj=document.getElementById('np_pubmed_author'+i);\r
+  i++;\r
+  var t=''+i+': ';\r
+  t+='<input type="text" name="author['+i+']" size="20" value=""/>, ';\r
+  t+='<input type="text" name="authorf['+i+']" size="20" value=""/> ';\r
+  t+='<input type="text" name="authorm['+i+']" size="2" value=""/>. ';\r
+  t+='<br />';\r
+  t+='<span id="np_pubmed_author'+i+'"><a href="" onclick="np_pubmed_author('+i+'); return false;">more authors</a></span>';\r
+  obj.innerHTML=t;\r
+}\r
+//]]>]]<![CDATA[>\r
+</script>\r
+\r
+    ]]></foot>\r
+\r
+  </template>\r
+\r
+\r
+\r
+  <template>\r
+    <name>addmanuallyconfirm</name>\r
+    <head><![CDATA[\r
+\r
+<form method="post" action="<%conf(AdminURL)%>">\r
+<%ticket(hidden)%>\r
+<input name="action" value="additem" type="hidden">\r
+<input name="blogid" value="<%blogid%>" type="hidden">\r
+<input name="draftid" value="0" type="hidden">\r
+<input name="closed" value="0" type="hidden">\r
+<input name="actiontype" value="addnow" type="hidden">\r
+<input value="Add this:" type="submit">\r
+<input name="title" value="<%hsc(title)%>" class="np_pubmed_form" type="hidden">\r
+<input name="body" value="<%hsc(body)%>" class="np_pubmed_form" type="hidden">\r
+<input name="more" value="<%hsc(more)%>" class="np_pubmed_form" type="hidden">\r
+\r
+<select name="catid" class="np_pubmed_form">\r
+<option value="newcat-<%blogid%>">New category</option>\r
+\r
+    ]]></head>\r
+    <body><![CDATA[\r
+\r
+<%if(selected)%>\r
+  <option value="<%int(catid)%>" selected="selected"><%stg(cname)%></option>\r
+<%else%>\r
+  <option value="<%int(catid)%>"><%stg(cname)%></option>\r
+<%endif%>\r
+\r
+    ]]></body>\r
+    <foot><![CDATA[\r
+\r
+</select>\r
+&nbsp;\r
+(<a href="<%self%>?blogid=<%blogid%>&amp;action=addmanually" onclick="history.go(-1); return false;">go back</a>)\r
+</form>\r
+\r
+<pre><%hsc(title)%></pre>\r
+<pre><%hsc(body)%></pre>\r
+<pre><%hsc(more)%></pre>\r
+\r
+    ]]></foot>\r
+  </template>\r
+\r
+\r
 </document>\r
index 6161bb1..787330c 100644 (file)
 <dt>Navigation</dt>\r
 <dd><a href="http://www.ncbi.nlm.nih.gov/sites/entrez?db=PubMed" onclick="window.open(this.href);return false;">NIH PubMed site</a></dd>\r
 <!-- admin link, only visible if logged in -->\r
-<%if(loggedin)%>\r
+<%if(admin)%>\r
 <dd><a href="<%adminurl%>plugins/pubmed/?blogid=<%blogsetting(id)%>">PubMed search</a></dd>\r
+<%endif%>\r
+<%if(loggedin)%>\r
 <dd><a href="<%adminurl%>" title="Admin Area">Admin</a></dd>\r
 <%endif%>\r
 </dl>\r
@@ -24,7 +26,7 @@
 <div class="sidebar">\r
 <dl class="sidebardl">\r
 <dt>Manuscripts</dt>\r
-<dd><a href="<%adminurl%>plugins/pubmed/?blogid=<%blogsetting(id)%>&amp;action=manuscriptlist">(manegement)</a></dd>\r
+<dd><a href="<%adminurl%>plugins/pubmed/?action=manuscriptlist">(manegement)</a></dd>\r
 <%PubMed(manuscriptlist,spring/item)%>\r
 </dl>\r
 </div>\r
index 4b499c6..917fecd 100644 (file)
@@ -7,7 +7,7 @@
 
 
        <skin name="spring" type="text/html" includeMode="skindir" includePrefix="spring/">
-               <description>Nucleus CMS spring skin</description>
+               <description>NP_PubMed spring skin</description>
                <part name="archive"><![CDATA[<%parsedinclude(head.inc)%>\r
 \r
 <!-- page header -->\r
@@ -141,6 +141,7 @@ body { margin: 0px; }
 <div class="content">\r
 <%PubMed(SearchLink)%><br /><br />\r
 <%PubMed(CreateNew)%>\r
+<a href="<%adminurl%>plugins/pubmed/?blogid=<%blogsetting(id)%>&amp;action=addmanually">Manually add paper</a>\r
 \r
 <%parsedinclude(paging.inc)%>\r
 \r
@@ -293,7 +294,7 @@ onclick="window.open(this.href);return false;"
 
 
        <template name="spring/index">
-               <description>Nucleus CMS spring index template</description>
+               <description>NP_PubMed spring index template</description>
                <part name="ARCHIVELIST_LISTITEM"><![CDATA[<dd>\r
 <a href="<%archivelink%>" title="Archive for %B, %Y">%Y-%m</a>\r
 </dd>]]></part>
@@ -387,7 +388,7 @@ return false;
 
 
        <template name="spring/item">
-               <description>Nucleus CMS spring item template</description>
+               <description>NP_PubMed spring item template</description>
                <part name="CATLIST_LISTITEM"><![CDATA[<dd>\r
 <a href="<%catlink%>" title="Manuscript: <%catname%>"><%catname%></a>\r
 </dd>]]></part>