function getName() { return 'NP_PubMed'; }\r
function getMinNucleusVersion() { return 330; }\r
function getAuthor() { return 'Katsumi'; }\r
- function getVersion() { return '0.1.7'; }\r
- function getURL() {return 'http://hp.vector.co.jp/authors/VA016157/';}\r
+ function getVersion() { return '0.1.8'; }\r
+ function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:authors:katsumi';}\r
function getDescription() {\r
return $this->getName().' plugin<br />'.\r
'This plugin uses the query service of "Entrez Programming Utilities".<br />'.\r
' manuscriptid int(11) not null auto_increment,'.\r
' userid int(11) not null default 0,'.\r
' manuscriptname varchar(200) not null default "New Manuscript",'.\r
- ' templatename varchar(200) not null default "default.template",'.\r
- ' sortmethod varchar(40) not null default "author",'.\r
+ ' templatename varchar(200) not null default "default",'.\r
+ ' sortdata text not null default "",'.\r
' PRIMARY KEY manuscriptid(manuscriptid) '.\r
') TYPE=MyISAM;');\r
}\r
);\r
}\r
function event_PreUpdateItem(&$data){\r
- $ret=$this->event_PreAddItem(&$data);\r
+ $ret=$this->event_PreAddItem($data);\r
$this->_updateManuscriptData($data['itemid']);\r
return $ret;\r
}\r
global $CONF,$manager,$blog,$member;\r
$mid=$member->getID();\r
switch($mode=strtolower($mode)){\r
+ case 'getvar':\r
+ echo htmlspecialchars(getVar($p1),ENT_QUOTES);\r
+ break;\r
+ case 'postvar':\r
+ echo htmlspecialchars(postVar($p1),ENT_QUOTES);\r
+ break;\r
case 'searchlink':\r
if (!$this->isAdmin()) return;\r
if (!$blog) return;\r
echo '<a href="http://www.ncbi.nlm.nih.gov/PubMed/" onclick="window.open(this.href,\'PubMed\');return false;">'.\r
htmlspecialchars(strlen($p1)?$p1:'PubMed',ENT_QUOTES).'</a>';\r
break;\r
- case 'parse': case 'pageswitch':\r
+ case 'parse':\r
+ if (!$mid) return;\r
if (!$blog) return;\r
- global $startpos;\r
- $startpos=(int)$startpos;\r
- $limit=(int)$p2;\r
- $template=addslashes($p1);\r
- $query=$blog->getSqlBlog('');\r
- $query=preg_replace('/ORDER[\s]+BY[\s][\s\.a-z0-9_]*(ASC|DESC)$/i','ORDER BY i.ititle ASC',$query);\r
- switch($mode){\r
- case 'pageswitch':\r
- $ps=&$manager->getPlugin('NP_PageSwitch');\r
- $ps->setQuery($query);\r
- break;\r
- case 'parse':\r
- default:\r
- $blog->showUsingQuery($template, $query.' LIMIT '.$startpos.','.$limit, '', 1, 1);\r
+ $msid=intGetVar('manuscriptid');\r
+ if (!$msid) return;\r
+ $query='SELECT i.ibody as body, i.ititle as title, i.imore as more'.\r
+ ' FROM '.sql_table('item').' as i, '.\r
+ sql_table('plugin_pubmed_references').' as r,'.\r
+ sql_table('plugin_pubmed_manuscripts').' as m'.\r
+ ' WHERE i.inumber=r.itemid'.\r
+ ' AND r.manuscriptid='.(int)$msid.\r
+ ' AND m.manuscriptid='.(int)$msid.\r
+ ' AND m.userid='.(int)$mid.\r
+ ' ORDER BY i.ititle ASC';\r
+ \r
+ // Construct template object.\r
+ require_once($this->getDirectory().'template.php');\r
+ $res=sql_query('SELECT *'.\r
+ ' FROM '.sql_table('plugin_pubmed_manuscripts').\r
+ ' WHERE manuscriptid='.(int)$msid.\r
+ ' AND userid='.(int)$mid);\r
+ $row=mysql_fetch_assoc($res);\r
+ if (!$row) return;\r
+ $tobj=PUBMED_TEMPLATE_BASE::getTemplate($row['templatename'],$row['sortdata']);\r
+ if (!$tobj) {\r
+ echo 'The template, "'.htmlspecialchars($row['templatename']).'" cannot be found';\r
break;\r
}\r
+ // Set all the data.\r
+ $res=sql_query($query);\r
+ while($row=mysql_fetch_assoc($res)){\r
+ $tobj->setData($row['more']);\r
+ }\r
+ // Sort the papers\r
+ $tobj->sortPapers();\r
+ // Let's parse, finally.\r
+ $tobj->parse_all();\r
+ break;\r
case 'manuscriptlist':\r
+ \r
if (!$mid) return;\r
if (!$blog) return;\r
$blogid=$blog->getID();\r
$template =& $manager->getTemplate($p1);\r
- //print_r($template['CATLIST_LISTITEM']);exit;\r
$res=sql_query('SELECT manuscriptname as name, manuscriptid as id'.\r
' FROM '.sql_table('plugin_pubmed_manuscripts').\r
' WHERE userid='.(int)$mid);\r
global $member,$manager;\r
$mid=$member->getID();\r
echo '<a href="'.$this->oPluginAdmin->plugin->getAdminURL().'?blogid='.(int)$this->blogid.'&action=manuscriptlist">Refresh</a><br />';\r
- echo '<table><tr><th>manuscript</th><th>template</th><th>sort method</th><th colspan="2"> </th></tr>';\r
+ echo '<table><tr><th>manuscript</th><th>template</th><th colspan="2"> </th></tr>';\r
$res=sql_query('SELECT * FROM '.sql_table('plugin_pubmed_manuscripts').\r
' WHERE userid='.(int)$mid);\r
while($row=mysql_fetch_assoc($res)){\r
echo '<tr>';\r
echo '<td>'.htmlspecialchars($row['manuscriptname']).'</td>';\r
echo '<td>'.htmlspecialchars($row['templatename']).'</td>';\r
- echo '<td>'.htmlspecialchars($row['sortmethod']).'</td>';\r
?>\r
<td><form method="post" action="">\r
<input type="hidden" name="action" value="deletemanuscript" />\r
if (!$mname) $mname=$row['manuscriptname'];\r
$mname=$this->_checkmanuscriptname($mname,$manuscriptid);\r
if (!$mname) return $this->manuscriptlist();\r
- switch($sort=postVar('sortmethod')){\r
- case 'author':\r
- case 'manual':\r
- break;\r
- default:\r
- $sort=$row['sortmethod'];\r
- }\r
- $template='default.template';\r
+ $template=$row['templatename'];\r
if (postVar('sure')=='yes') {\r
+ $template=postVar('templatename');\r
sql_query('UPDATE '.sql_table('plugin_pubmed_manuscripts').' SET'.\r
' manuscriptname="'.addslashes($mname).'",'.\r
- ' templatename="'.addslashes($template).'",'.\r
- ' sortmethod="'.addslashes($sort).'"'.\r
+ ' templatename="'.addslashes($template).'"'.\r
' WHERE manuscriptid='.(int)$manuscriptid.\r
' AND userid='.(int)$mid);\r
return $this->manuscriptlist();\r
}\r
- \r
+ // Get template files\r
+ $templates=array();\r
+ $d=dir(dirname(__FILE__).'/templates/');\r
+ while (false !== ($entry = $d->read())) {\r
+ if (!preg_match('/^(.+)\.php$/',$entry,$m)) continue;\r
+ if ($m[1]!='default') $templates[]=$m[1];\r
+ }\r
+ sort($templates);\r
+ array_unshift($templates,'default');\r
+$d->close(); \r
?>\r
<form method="post" action="">\r
<input type="hidden" name="action" value="editmanuscript" />\r
<tr><td>Manuscript name:</td>\r
<td><input type="text" name="manuscriptname" value="<?php echo htmlspecialchars($mname); ?>" /></td></tr>\r
<tr><td>Template:</td>\r
-<td><input type="text" name="tamplatename" value="<?php echo htmlspecialchars($template); ?>" /></td></tr>\r
-<tr><td>Sort method:</td>\r
-<td><select name="sortmethod">\r
-<option value="author" <?php if ($sort=='author') echo 'selected="selected"'; ?> >author</option>\r
-<option value="manual" <?php if ($sort=='manual') echo 'selected="selected"'; ?> >manual</option>\r
+<!-- td><input type="text" name="templatename" value="<?php echo htmlspecialchars($template); ?>" /></td></tr -->\r
+<td><select name="templatename">\r
+<?php\r
+ foreach($templates as $temp){\r
+ $temp=htmlspecialchars($temp,ENT_QUOTES);\r
+ echo '<option value="'.$temp.'"'.\r
+ ($template==$temp ? ' selected="selected"' : '').\r
+ '>'.$temp."</option>\n";\r
+ }\r
+?>\r
</select></td>\r
-</tr></table>\r
+</tr>\r
+</table>\r
<input type="submit" value="Edit" />\r
</form>\r
<?php\r
--- /dev/null
+<?php\r
+\r
+class PUBMED_TEMPLATE_BASE {\r
+ /*\r
+ * This class must be inhelited by PUBMED_TEMPLATE class.\r
+ * Note that PHP 5 is needed.\r
+ */\r
+ /* \r
+ * Default methods follow.\r
+ * These methods will be overrided in PUBMED_TEMPLATE class.\r
+ */\r
+ public function sortPapers(){\r
+ $this->sortByAuthorName();\r
+ }\r
+ public function parse_header(){\r
+ return '<br />';\r
+ }\r
+ public function parse_footer(){\r
+ return '<br />';\r
+ }\r
+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){\r
+ return <<<END\r
+\r
+{$this->parse_authors($authors)} ({$year})<br />\r
+<i>{$journal}</i> <b>{$volume}</b>, {$pages}<br />\r
+{$title}<br />\r
+<br />\r
+END;\r
+ }\r
+ public function parse_authors($authors, $and=', and '){\r
+ $num=count($authors);\r
+ switch($num){\r
+ case 1:\r
+ $result=$this->parse_author($authors[0]);\r
+ break;\r
+ case 2:\r
+ $result=$this->parse_author($authors[0]).$and.$this->parse_author($authors[1]);\r
+ break;\r
+ default:\r
+ $result=$this->parse_author($authors[0]);\r
+ for($i=1;$i<$num;$i++){\r
+ if ($i==1) $result.=', ';\r
+ elseif ($i==$num-1) $result.=$and;\r
+ $result.=$this->parse_author($authors[$i]);\r
+ }\r
+ break;\r
+ }\r
+ return htmlspecialchars($result);\r
+ }\r
+ public function parse_author($author){\r
+ $result=$author->LastName.', ';\r
+ $initials=$author->Initials;\r
+ for($i=0;$i<strlen($initials);$i++) $result.=substr($initials,$i,1).'.';\r
+ return $result;\r
+ }\r
+ /*\r
+ * Following methods shouldn't be overrided.\r
+ */\r
+ protected $sorttext='',$sortdata=array(),$data=array();\r
+ public static function getTemplate($template,$sorttext){\r
+ // Static method.\r
+ // Define PUBLED_TEMPLATE class\r
+ if (!preg_match('/^[a-z0-9A-Z_]+$/',$template)) exit('Bad template name!');\r
+ $file=dirname(__FILE__)."/templates/{$template}.php";\r
+ if (!file_exists($file)) return false;\r
+ require_once($file);\r
+ $obj = new PUBMED_TEMPLATE;\r
+ $obj->sorttext=$sorttext;\r
+ return $obj;\r
+ }\r
+ public final function setData($more){\r
+ // $more is the $item->more.\r
+ if (!preg_match('#<MedlineCitation[^>]*>([\s\S]*?)</MedlineCitation>#',$more,$m)) return;\r
+ $xml="<?xml version='1.0'?>\r\n<document>\r\n$m[1]\r\n</document>";\r
+ $xml=simplexml_load_string($xml);\r
+ $pmid=(int)$xml->PMID;\r
+ $this->data[$pmid]=$xml;\r
+ //echo $xml->Article->AuthorList->Author[0]->LastName;\r
+ //echo "<br />\n";\r
+ }\r
+ public final function parse_all(){\r
+ echo $this->parse_header();\r
+ $num=0;\r
+ foreach($this->sortdata as $pmid) {\r
+ $xml=$this->data[$pmid];\r
+ $num++;\r
+ // Get year\r
+ $year=$xml->Article->Journal->JournalIssue->PubDate->Year;\r
+ // Get journal name\r
+ $journal=$xml->Article->Journal->ISOAbbreviation;\r
+ // Get volume\r
+ $volume=$xml->Article->Journal->JournalIssue->Volume;\r
+ // Get paper title\r
+ $title=$xml->Article->ArticleTitle;\r
+ if (substr($title,-1,1)!=='.') $title.='.';\r
+ // Get the start and end pages\r
+ $pages=explode('-',(string)$xml->Article->Pagination->MedlinePgn);\r
+ $pages=$pages[0].'-'.substr($pages[0],0,strlen($pages[0])-strlen($pages[1])).$pages[1];\r
+ // Let's parse the citation\r
+ echo $this->parse( (int)$num,(int)$pmid,$xml,$xml->Article->AuthorList->Author\r
+ ,htmlspecialchars($year) // Don't use (int) because it may be like 2008a\r
+ ,htmlspecialchars($journal)\r
+ ,(int)$volume\r
+ ,htmlspecialchars($pages)\r
+ ,htmlspecialchars($title)\r
+ );\r
+ }\r
+ echo $this->parse_footer();\r
+ }\r
+ /* Sort methods follow.\r
+ * note that these methods will be called from "sortPapers" method\r
+ */\r
+ public final function manualSort(){\r
+ // Set the sortdata array.\r
+ $lines=preg_split('/[\r\n]/',$this->sorttext,-1);\r
+ $result=array();\r
+ foreach($lines as $line){\r
+ if (!preg_match('/^[\s]*PMID:[\s]*([0-9]+)/',$line,$m)) continue;\r
+ $result[]=$m[1];\r
+ }\r
+ $this->sortdata=$result;\r
+ }\r
+ public final function sortByAuthorName(){\r
+ $citations=array();\r
+ $papers=array();\r
+ $i=0;\r
+ foreach($this->data as $pmid=>&$xml){\r
+ $i++;\r
+ // Get date\r
+ $year=(int)$xml->Article->Journal->JournalIssue->PubDate->Year;\r
+ $month=(string)$xml->Article->Journal->JournalIssue->PubDate->Month;\r
+ $month=$this->month($month);\r
+ $month=$month<10 ? "0$month" : "$month";\r
+ $day=(int)$xml->Article->Journal->JournalIssue->PubDate->Day;\r
+ $day=$day<10 ? "0$day" : "$day";\r
+ $date="$year-$month-$day";\r
+ // Get Authors\r
+ $authors=$xml->Article->AuthorList->Author;\r
+ $firstauthor=$authors[0]->LastName.', '.$authors[0]->Initials;\r
+ $authornum=count($authors);\r
+ switch($authornum){\r
+ case 1:\r
+ $citation=$authors[0]->LastName.", $year";\r
+ break;\r
+ case 2:\r
+ $citation=$authors[0]->LastName.' and '.$authors[1]->LastName.", $year";\r
+ break;\r
+ default:\r
+ $citation=$authors[0]->LastName." et al., $year";\r
+ break;\r
+ }\r
+ if (!isset($citations[$citation])) $citations[$citation]=array();\r
+ $citations[$citation][]=$pmid;\r
+ // Construct the sort key and cache data\r
+ $key="$firstauthor $year $citation $date $i";\r
+ $papers[$key]=$pmid;\r
+ }\r
+ // Modify Year (for example, 2008 => 2008a, 2008b, etc.\r
+ $abc='abcdefghijklmnopqrstuvwxyz';\r
+ foreach($citations as $key=>$value){\r
+ if (count($value)<2) continue;\r
+ for ($i=0;$i<count($value);$i++){\r
+ $pmid=$value[$i];\r
+ $year=(int)$this->data[$pmid]->Article->Journal->JournalIssue->PubDate->Year;\r
+ $this->data[$pmid]->Article->Journal->JournalIssue->PubDate->Year=(string)$year.substr($abc,$i,1);\r
+ }\r
+ }\r
+ // Sort the data\r
+ ksort($papers);\r
+ // Let's get the result.\r
+ $result=array();\r
+ foreach($papers as $pmid) $result[]=$pmid;\r
+ $this->sortdata=$result;\r
+ }\r
+ protected final function month($month){\r
+ if (is_numeric($month)) return (int)$month;\r
+ switch(strtolower($month)){\r
+ case 'january':\r
+ case 'jan': return 1;\r
+ case 'february':\r
+ case 'feb': return 2;\r
+ case 'march':\r
+ case 'mar': return 3;\r
+ case 'april':\r
+ case 'apr': return 4;\r
+ case 'may': return 5;\r
+ case 'june':\r
+ case 'jun': return 6;\r
+ case 'july':\r
+ case 'jul': return 7;\r
+ case 'august':\r
+ case 'aug': return 8;\r
+ case 'september':\r
+ case 'sep': return 9;\r
+ case 'october':\r
+ case 'oct': return 10;\r
+ case 'november':\r
+ case 'nov': return 11;\r
+ case 'december':\r
+ case 'dec': return 12;\r
+ default: return 0;\r
+ }\r
+ }\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+class PUBMED_TEMPLATE extends PUBMED_TEMPLATE_BASE {\r
+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){\r
+ return <<<END\r
+\r
+{$this->parse_authors($authors)} ({$year}). {$title} {$journal} <i>{$volume}</i>, {$pages}<br />\r
+<br />\r
+\r
+END;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+class PUBMED_TEMPLATE extends PUBMED_TEMPLATE_BASE {\r
+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){\r
+ $year=(int)$year;\r
+ return <<<END\r
+\r
+{$this->parse_authors($authors,', & ')} ({$year}). {$journal} <b>{$volume}</b>, {$pages}<br />\r
+<br />\r
+\r
+END;\r
+ }\r
+ public function parse_author($author){\r
+ $result=$author->LastName.', ';\r
+ $initials=$author->Initials;\r
+ for($i=0;$i<strlen($initials);$i++) $result.=substr($initials,$i,1).'. ';\r
+ return substr($result,0,strlen($result)-1);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+<?php\r
+\r
+class PUBMED_TEMPLATE extends PUBMED_TEMPLATE_BASE {\r
+ /* the default template uses everything from BASE class */\r
+}
\ No newline at end of file
<div id="container">\r
<div class="content">\r
\r
-<%PubMed(PageSwitch,,50)%>\r
-<%if(PageSwitch,limit,50)%>\r
-<div style="text-align:right;">Pages:\r
-<%PageSwitch(prev,prev)%>\r
-<%PageSwitch(index,2)%>\r
-<%PageSwitch(next,next)%>\r
-Page <%PageSwitch(num)%> of <%PageSwitch(total)%>\r
-</div>\r
-<%endif%>\r
-\r
-<%PubMed(parse,spring/index,50)%>\r
+<%PubMed(parse)%>\r
\r
+<%endif%>\r
</div>\r
</div>\r
\r