• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revisionac1bbf0bc4a835f7afe9150b30eb30153cc8a330 (tree)
Time2008-12-22 17:45:48
Authorkmorimatsu <kmorimatsu@1ca2...>
Commiterkmorimatsu

Log Message

NP_PubMed v0.1.8
template engine constructed.
Now supports Cell!

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@756 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- a/NP_PubMed/trunk/NP_PubMed.php
+++ b/NP_PubMed/trunk/NP_PubMed.php
@@ -3,8 +3,8 @@ class NP_PubMed extends NucleusPlugin {
33 function getName() { return 'NP_PubMed'; }
44 function getMinNucleusVersion() { return 330; }
55 function getAuthor() { return 'Katsumi'; }
6- function getVersion() { return '0.1.7'; }
7- function getURL() {return 'http://hp.vector.co.jp/authors/VA016157/';}
6+ function getVersion() { return '0.1.8'; }
7+ function getURL() {return 'http://japan.nucleuscms.org/wiki/plugins:authors:katsumi';}
88 function getDescription() {
99 return $this->getName().' plugin<br />'.
1010 'This plugin uses the query service of "Entrez Programming Utilities".<br />'.
@@ -31,8 +31,8 @@ class NP_PubMed extends NucleusPlugin {
3131 ' manuscriptid int(11) not null auto_increment,'.
3232 ' userid int(11) not null default 0,'.
3333 ' manuscriptname varchar(200) not null default "New Manuscript",'.
34- ' templatename varchar(200) not null default "default.template",'.
35- ' sortmethod varchar(40) not null default "author",'.
34+ ' templatename varchar(200) not null default "default",'.
35+ ' sortdata text not null default "",'.
3636 ' PRIMARY KEY manuscriptid(manuscriptid) '.
3737 ') TYPE=MyISAM;');
3838 }
@@ -64,7 +64,7 @@ class NP_PubMed extends NucleusPlugin {
6464 );
6565 }
6666 function event_PreUpdateItem(&$data){
67- $ret=$this->event_PreAddItem(&$data);
67+ $ret=$this->event_PreAddItem($data);
6868 $this->_updateManuscriptData($data['itemid']);
6969 return $ret;
7070 }
@@ -188,6 +188,12 @@ class NP_PubMed extends NucleusPlugin {
188188 global $CONF,$manager,$blog,$member;
189189 $mid=$member->getID();
190190 switch($mode=strtolower($mode)){
191+ case 'getvar':
192+ echo htmlspecialchars(getVar($p1),ENT_QUOTES);
193+ break;
194+ case 'postvar':
195+ echo htmlspecialchars(postVar($p1),ENT_QUOTES);
196+ break;
191197 case 'searchlink':
192198 if (!$this->isAdmin()) return;
193199 if (!$blog) return;
@@ -231,30 +237,50 @@ class NP_PubMed extends NucleusPlugin {
231237 echo '<a href="http://www.ncbi.nlm.nih.gov/PubMed/" onclick="window.open(this.href,\'PubMed\');return false;">'.
232238 htmlspecialchars(strlen($p1)?$p1:'PubMed',ENT_QUOTES).'</a>';
233239 break;
234- case 'parse': case 'pageswitch':
240+ case 'parse':
241+ if (!$mid) return;
235242 if (!$blog) return;
236- global $startpos;
237- $startpos=(int)$startpos;
238- $limit=(int)$p2;
239- $template=addslashes($p1);
240- $query=$blog->getSqlBlog('');
241- $query=preg_replace('/ORDER[\s]+BY[\s][\s\.a-z0-9_]*(ASC|DESC)$/i','ORDER BY i.ititle ASC',$query);
242- switch($mode){
243- case 'pageswitch':
244- $ps=&$manager->getPlugin('NP_PageSwitch');
245- $ps->setQuery($query);
246- break;
247- case 'parse':
248- default:
249- $blog->showUsingQuery($template, $query.' LIMIT '.$startpos.','.$limit, '', 1, 1);
243+ $msid=intGetVar('manuscriptid');
244+ if (!$msid) return;
245+ $query='SELECT i.ibody as body, i.ititle as title, i.imore as more'.
246+ ' FROM '.sql_table('item').' as i, '.
247+ sql_table('plugin_pubmed_references').' as r,'.
248+ sql_table('plugin_pubmed_manuscripts').' as m'.
249+ ' WHERE i.inumber=r.itemid'.
250+ ' AND r.manuscriptid='.(int)$msid.
251+ ' AND m.manuscriptid='.(int)$msid.
252+ ' AND m.userid='.(int)$mid.
253+ ' ORDER BY i.ititle ASC';
254+
255+ // Construct template object.
256+ require_once($this->getDirectory().'template.php');
257+ $res=sql_query('SELECT *'.
258+ ' FROM '.sql_table('plugin_pubmed_manuscripts').
259+ ' WHERE manuscriptid='.(int)$msid.
260+ ' AND userid='.(int)$mid);
261+ $row=mysql_fetch_assoc($res);
262+ if (!$row) return;
263+ $tobj=PUBMED_TEMPLATE_BASE::getTemplate($row['templatename'],$row['sortdata']);
264+ if (!$tobj) {
265+ echo 'The template, "'.htmlspecialchars($row['templatename']).'" cannot be found';
250266 break;
251267 }
268+ // Set all the data.
269+ $res=sql_query($query);
270+ while($row=mysql_fetch_assoc($res)){
271+ $tobj->setData($row['more']);
272+ }
273+ // Sort the papers
274+ $tobj->sortPapers();
275+ // Let's parse, finally.
276+ $tobj->parse_all();
277+ break;
252278 case 'manuscriptlist':
279+
253280 if (!$mid) return;
254281 if (!$blog) return;
255282 $blogid=$blog->getID();
256283 $template =& $manager->getTemplate($p1);
257- //print_r($template['CATLIST_LISTITEM']);exit;
258284 $res=sql_query('SELECT manuscriptname as name, manuscriptid as id'.
259285 ' FROM '.sql_table('plugin_pubmed_manuscripts').
260286 ' WHERE userid='.(int)$mid);
--- a/NP_PubMed/trunk/pubmed/index.php
+++ b/NP_PubMed/trunk/pubmed/index.php
@@ -269,14 +269,13 @@ class PubMedAdmin {
269269 global $member,$manager;
270270 $mid=$member->getID();
271271 echo '<a href="'.$this->oPluginAdmin->plugin->getAdminURL().'?blogid='.(int)$this->blogid.'&amp;action=manuscriptlist">Refresh</a><br />';
272- echo '<table><tr><th>manuscript</th><th>template</th><th>sort method</th><th colspan="2">&nbsp;</th></tr>';
272+ echo '<table><tr><th>manuscript</th><th>template</th><th colspan="2">&nbsp;</th></tr>';
273273 $res=sql_query('SELECT * FROM '.sql_table('plugin_pubmed_manuscripts').
274274 ' WHERE userid='.(int)$mid);
275275 while($row=mysql_fetch_assoc($res)){
276276 echo '<tr>';
277277 echo '<td>'.htmlspecialchars($row['manuscriptname']).'</td>';
278278 echo '<td>'.htmlspecialchars($row['templatename']).'</td>';
279- echo '<td>'.htmlspecialchars($row['sortmethod']).'</td>';
280279 ?>
281280 <td><form method="post" action="">
282281 <input type="hidden" name="action" value="deletemanuscript" />
@@ -379,24 +378,26 @@ Are you sure?&nbsp;&nbsp;
379378 if (!$mname) $mname=$row['manuscriptname'];
380379 $mname=$this->_checkmanuscriptname($mname,$manuscriptid);
381380 if (!$mname) return $this->manuscriptlist();
382- switch($sort=postVar('sortmethod')){
383- case 'author':
384- case 'manual':
385- break;
386- default:
387- $sort=$row['sortmethod'];
388- }
389- $template='default.template';
381+ $template=$row['templatename'];
390382 if (postVar('sure')=='yes') {
383+ $template=postVar('templatename');
391384 sql_query('UPDATE '.sql_table('plugin_pubmed_manuscripts').' SET'.
392385 ' manuscriptname="'.addslashes($mname).'",'.
393- ' templatename="'.addslashes($template).'",'.
394- ' sortmethod="'.addslashes($sort).'"'.
386+ ' templatename="'.addslashes($template).'"'.
395387 ' WHERE manuscriptid='.(int)$manuscriptid.
396388 ' AND userid='.(int)$mid);
397389 return $this->manuscriptlist();
398390 }
399-
391+ // Get template files
392+ $templates=array();
393+ $d=dir(dirname(__FILE__).'/templates/');
394+ while (false !== ($entry = $d->read())) {
395+ if (!preg_match('/^(.+)\.php$/',$entry,$m)) continue;
396+ if ($m[1]!='default') $templates[]=$m[1];
397+ }
398+ sort($templates);
399+ array_unshift($templates,'default');
400+$d->close();
400401 ?>
401402 <form method="post" action="">
402403 <input type="hidden" name="action" value="editmanuscript" />
@@ -408,13 +409,19 @@ Are you sure?&nbsp;&nbsp;
408409 <tr><td>Manuscript name:</td>
409410 <td><input type="text" name="manuscriptname" value="<?php echo htmlspecialchars($mname); ?>" /></td></tr>
410411 <tr><td>Template:</td>
411-<td><input type="text" name="tamplatename" value="<?php echo htmlspecialchars($template); ?>" /></td></tr>
412-<tr><td>Sort method:</td>
413-<td><select name="sortmethod">
414-<option value="author" <?php if ($sort=='author') echo 'selected="selected"'; ?> >author</option>
415-<option value="manual" <?php if ($sort=='manual') echo 'selected="selected"'; ?> >manual</option>
412+<!-- td><input type="text" name="templatename" value="<?php echo htmlspecialchars($template); ?>" /></td></tr -->
413+<td><select name="templatename">
414+<?php
415+ foreach($templates as $temp){
416+ $temp=htmlspecialchars($temp,ENT_QUOTES);
417+ echo '<option value="'.$temp.'"'.
418+ ($template==$temp ? ' selected="selected"' : '').
419+ '>'.$temp."</option>\n";
420+ }
421+?>
416422 </select></td>
417-</tr></table>
423+</tr>
424+</table>
418425 <input type="submit" value="Edit" />
419426 </form>
420427 <?php
--- /dev/null
+++ b/NP_PubMed/trunk/pubmed/template.php
@@ -0,0 +1,205 @@
1+<?php
2+
3+class PUBMED_TEMPLATE_BASE {
4+ /*
5+ * This class must be inhelited by PUBMED_TEMPLATE class.
6+ * Note that PHP 5 is needed.
7+ */
8+ /*
9+ * Default methods follow.
10+ * These methods will be overrided in PUBMED_TEMPLATE class.
11+ */
12+ public function sortPapers(){
13+ $this->sortByAuthorName();
14+ }
15+ public function parse_header(){
16+ return '<br />';
17+ }
18+ public function parse_footer(){
19+ return '<br />';
20+ }
21+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){
22+ return <<<END
23+
24+{$this->parse_authors($authors)} ({$year})<br />
25+<i>{$journal}</i> <b>{$volume}</b>, {$pages}<br />
26+{$title}<br />
27+<br />
28+END;
29+ }
30+ public function parse_authors($authors, $and=', and '){
31+ $num=count($authors);
32+ switch($num){
33+ case 1:
34+ $result=$this->parse_author($authors[0]);
35+ break;
36+ case 2:
37+ $result=$this->parse_author($authors[0]).$and.$this->parse_author($authors[1]);
38+ break;
39+ default:
40+ $result=$this->parse_author($authors[0]);
41+ for($i=1;$i<$num;$i++){
42+ if ($i==1) $result.=', ';
43+ elseif ($i==$num-1) $result.=$and;
44+ $result.=$this->parse_author($authors[$i]);
45+ }
46+ break;
47+ }
48+ return htmlspecialchars($result);
49+ }
50+ public function parse_author($author){
51+ $result=$author->LastName.', ';
52+ $initials=$author->Initials;
53+ for($i=0;$i<strlen($initials);$i++) $result.=substr($initials,$i,1).'.';
54+ return $result;
55+ }
56+ /*
57+ * Following methods shouldn't be overrided.
58+ */
59+ protected $sorttext='',$sortdata=array(),$data=array();
60+ public static function getTemplate($template,$sorttext){
61+ // Static method.
62+ // Define PUBLED_TEMPLATE class
63+ if (!preg_match('/^[a-z0-9A-Z_]+$/',$template)) exit('Bad template name!');
64+ $file=dirname(__FILE__)."/templates/{$template}.php";
65+ if (!file_exists($file)) return false;
66+ require_once($file);
67+ $obj = new PUBMED_TEMPLATE;
68+ $obj->sorttext=$sorttext;
69+ return $obj;
70+ }
71+ public final function setData($more){
72+ // $more is the $item->more.
73+ if (!preg_match('#<MedlineCitation[^>]*>([\s\S]*?)</MedlineCitation>#',$more,$m)) return;
74+ $xml="<?xml version='1.0'?>\r\n<document>\r\n$m[1]\r\n</document>";
75+ $xml=simplexml_load_string($xml);
76+ $pmid=(int)$xml->PMID;
77+ $this->data[$pmid]=$xml;
78+ //echo $xml->Article->AuthorList->Author[0]->LastName;
79+ //echo "<br />\n";
80+ }
81+ public final function parse_all(){
82+ echo $this->parse_header();
83+ $num=0;
84+ foreach($this->sortdata as $pmid) {
85+ $xml=$this->data[$pmid];
86+ $num++;
87+ // Get year
88+ $year=$xml->Article->Journal->JournalIssue->PubDate->Year;
89+ // Get journal name
90+ $journal=$xml->Article->Journal->ISOAbbreviation;
91+ // Get volume
92+ $volume=$xml->Article->Journal->JournalIssue->Volume;
93+ // Get paper title
94+ $title=$xml->Article->ArticleTitle;
95+ if (substr($title,-1,1)!=='.') $title.='.';
96+ // Get the start and end pages
97+ $pages=explode('-',(string)$xml->Article->Pagination->MedlinePgn);
98+ $pages=$pages[0].'-'.substr($pages[0],0,strlen($pages[0])-strlen($pages[1])).$pages[1];
99+ // Let's parse the citation
100+ echo $this->parse( (int)$num,(int)$pmid,$xml,$xml->Article->AuthorList->Author
101+ ,htmlspecialchars($year) // Don't use (int) because it may be like 2008a
102+ ,htmlspecialchars($journal)
103+ ,(int)$volume
104+ ,htmlspecialchars($pages)
105+ ,htmlspecialchars($title)
106+ );
107+ }
108+ echo $this->parse_footer();
109+ }
110+ /* Sort methods follow.
111+ * note that these methods will be called from "sortPapers" method
112+ */
113+ public final function manualSort(){
114+ // Set the sortdata array.
115+ $lines=preg_split('/[\r\n]/',$this->sorttext,-1);
116+ $result=array();
117+ foreach($lines as $line){
118+ if (!preg_match('/^[\s]*PMID:[\s]*([0-9]+)/',$line,$m)) continue;
119+ $result[]=$m[1];
120+ }
121+ $this->sortdata=$result;
122+ }
123+ public final function sortByAuthorName(){
124+ $citations=array();
125+ $papers=array();
126+ $i=0;
127+ foreach($this->data as $pmid=>&$xml){
128+ $i++;
129+ // Get date
130+ $year=(int)$xml->Article->Journal->JournalIssue->PubDate->Year;
131+ $month=(string)$xml->Article->Journal->JournalIssue->PubDate->Month;
132+ $month=$this->month($month);
133+ $month=$month<10 ? "0$month" : "$month";
134+ $day=(int)$xml->Article->Journal->JournalIssue->PubDate->Day;
135+ $day=$day<10 ? "0$day" : "$day";
136+ $date="$year-$month-$day";
137+ // Get Authors
138+ $authors=$xml->Article->AuthorList->Author;
139+ $firstauthor=$authors[0]->LastName.', '.$authors[0]->Initials;
140+ $authornum=count($authors);
141+ switch($authornum){
142+ case 1:
143+ $citation=$authors[0]->LastName.", $year";
144+ break;
145+ case 2:
146+ $citation=$authors[0]->LastName.' and '.$authors[1]->LastName.", $year";
147+ break;
148+ default:
149+ $citation=$authors[0]->LastName." et al., $year";
150+ break;
151+ }
152+ if (!isset($citations[$citation])) $citations[$citation]=array();
153+ $citations[$citation][]=$pmid;
154+ // Construct the sort key and cache data
155+ $key="$firstauthor $year $citation $date $i";
156+ $papers[$key]=$pmid;
157+ }
158+ // Modify Year (for example, 2008 => 2008a, 2008b, etc.
159+ $abc='abcdefghijklmnopqrstuvwxyz';
160+ foreach($citations as $key=>$value){
161+ if (count($value)<2) continue;
162+ for ($i=0;$i<count($value);$i++){
163+ $pmid=$value[$i];
164+ $year=(int)$this->data[$pmid]->Article->Journal->JournalIssue->PubDate->Year;
165+ $this->data[$pmid]->Article->Journal->JournalIssue->PubDate->Year=(string)$year.substr($abc,$i,1);
166+ }
167+ }
168+ // Sort the data
169+ ksort($papers);
170+ // Let's get the result.
171+ $result=array();
172+ foreach($papers as $pmid) $result[]=$pmid;
173+ $this->sortdata=$result;
174+ }
175+ protected final function month($month){
176+ if (is_numeric($month)) return (int)$month;
177+ switch(strtolower($month)){
178+ case 'january':
179+ case 'jan': return 1;
180+ case 'february':
181+ case 'feb': return 2;
182+ case 'march':
183+ case 'mar': return 3;
184+ case 'april':
185+ case 'apr': return 4;
186+ case 'may': return 5;
187+ case 'june':
188+ case 'jun': return 6;
189+ case 'july':
190+ case 'jul': return 7;
191+ case 'august':
192+ case 'aug': return 8;
193+ case 'september':
194+ case 'sep': return 9;
195+ case 'october':
196+ case 'oct': return 10;
197+ case 'november':
198+ case 'nov': return 11;
199+ case 'december':
200+ case 'dec': return 12;
201+ default: return 0;
202+ }
203+ }
204+
205+}
\ No newline at end of file
--- /dev/null
+++ b/NP_PubMed/trunk/pubmed/templates/Cell.php
@@ -0,0 +1,12 @@
1+<?php
2+
3+class PUBMED_TEMPLATE extends PUBMED_TEMPLATE_BASE {
4+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){
5+ return <<<END
6+
7+{$this->parse_authors($authors)} ({$year}). {$title} {$journal} <i>{$volume}</i>, {$pages}<br />
8+<br />
9+
10+END;
11+ }
12+}
\ No newline at end of file
--- /dev/null
+++ b/NP_PubMed/trunk/pubmed/templates/PNAS.php
@@ -0,0 +1,19 @@
1+<?php
2+
3+class PUBMED_TEMPLATE extends PUBMED_TEMPLATE_BASE {
4+ public function parse($num,$pmid,$xml,$authors,$year,$journal,$volume,$pages,$title){
5+ $year=(int)$year;
6+ return <<<END
7+
8+{$this->parse_authors($authors,', & ')} ({$year}). {$journal} <b>{$volume}</b>, {$pages}<br />
9+<br />
10+
11+END;
12+ }
13+ public function parse_author($author){
14+ $result=$author->LastName.', ';
15+ $initials=$author->Initials;
16+ for($i=0;$i<strlen($initials);$i++) $result.=substr($initials,$i,1).'. ';
17+ return substr($result,0,strlen($result)-1);
18+ }
19+}
\ No newline at end of file
--- /dev/null
+++ b/NP_PubMed/trunk/pubmed/templates/default.php
@@ -0,0 +1,5 @@
1+<?php
2+
3+class PUBMED_TEMPLATE extends PUBMED_TEMPLATE_BASE {
4+ /* the default template uses everything from BASE class */
5+}
\ No newline at end of file
--- a/NP_PubMed/trunk/spring/skinbackup.xml
+++ b/NP_PubMed/trunk/spring/skinbackup.xml
@@ -209,18 +209,9 @@ Website: <a href="<%member(url)%>"><%member(url)%></a>
209209 <div id="container">
210210 <div class="content">
211211
212-<%PubMed(PageSwitch,,50)%>
213-<%if(PageSwitch,limit,50)%>
214-<div style="text-align:right;">Pages:
215-<%PageSwitch(prev,prev)%>
216-<%PageSwitch(index,2)%>
217-<%PageSwitch(next,next)%>
218-Page <%PageSwitch(num)%> of <%PageSwitch(total)%>
219-</div>
220-<%endif%>
221-
222-<%PubMed(parse,spring/index,50)%>
212+<%PubMed(parse)%>
223213
214+<%endif%>
224215 </div>
225216 </div>
226217
Show on old repository browser