OSDN Git Service

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@869 1ca29b6e-896d...
[nucleus-jp/nucleus-plugins.git] / NP_RecentItems / trunk / NP_RecentItems.php
1 <?php
2 /**
3   *
4   * SHOW RECENT ITEMS PLUG-IN FOR NucleusCMS
5   * PHP versions 4 and 5
6   *
7   * This program is free software; you can redistribute it and/or
8   * modify it under the terms of the GNU General Public License
9   * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.
11   * (see nucleus/documentation/index.html#license for more info)
12   *
13   * @author        Original Author nakahara21
14   * @copyright    2005-2006 nakahara21
15   * @license        http://www.gnu.org/licenses/gpl.txt  GNU GENERAL PUBLIC LICENSE Version 2, June 1991
16   * @version       0.51
17   * @link          http://nakahara21.com
18   *
19   */
20 /**
21   * HISTORY
22   * 0.51 add BLOGID mode 
23   */
24 class NP_RecentItems extends NucleusPlugin
25 {
26     function getName()
27     {
28         return 'RecentItems';
29     }
30
31     function getAuthor()
32     {
33         return 'nakahara21';
34     }
35
36     function getURL()
37     {
38         return 'http://nakahara21.com';
39     }
40
41     function getVersion()
42     {
43         return '0.51';
44     }
45
46     function getDescription()
47         {
48         return 'Display Recent Items. Usage: &lt;%RecentItems(blogname,templatename,5)%&gt;';
49     }
50
51     function supportsFeature($what)
52     {
53         switch ($what) {
54             case 'SqlTablePrefix':
55                 return 1;
56             default:
57                 return 0;
58         }
59     }
60     function doSkinVar($skinType, $blogName = '', $templateName = '', $amountEntries = 5)
61     { 
62         global $manager;
63
64         if (is_numeric($blogName)) {
65             $query = 'SELECT bshortname as result FROM %s WHERE bnumber = %d';
66             $blogname = quickQuery(sprintf($query, sql_table('blog'), intval($blogName)));
67         }
68         if (!BLOG::exists($blogName)) {
69             return;
70         }
71         if (!TEMPLATE::exists($templateName)) {
72             return;
73         }
74         if ($amountEntries=='') {
75             $amountEntries = 5;
76         }
77
78         $tempBid =  getBlogIDFromName($blogName);
79         $b       =& $manager->getBlog($tempBid); 
80         $query   =  $this->_getsqlquery($b, $amountEntries, '');
81         $b->showUsingQuery($templateName, $query, 0, 1, 0);
82     }
83
84     function _getsqlquery($blogObj, $amountEntries, $extraQuery)
85     {
86         $query = 'SELECT'
87                . ' i.inumber as itemid,'
88                . ' i.ititle as title,'
89                . ' i.ibody as body,'
90                . ' m.mname as author,'
91                . ' m.mrealname as authorname,'
92                . ' i.itime,'
93                . ' i.imore as more,'
94                . ' m.mnumber as authorid,'
95                . ' m.memail as authormail,'
96                . ' m.murl as authorurl,'
97                . ' c.cname as category,'
98                . ' i.icat as catid,'
99                . ' i.iclosed as closed'
100                . ' FROM '                        // <mod by shizuki corresponds MySQL 5.0.x or later />
101                . sql_table('member') . ' as m, '
102                . sql_table('category') . ' as c,'
103                . sql_table('item') . ' as i'
104                . ' WHERE i.iblog = ' . intval($blogObj->getID())
105                . ' AND i.iauthor = m.mnumber'
106                . ' AND i.icat = c.catid'
107                . ' AND i.idraft = 0'             // exclude drafts
108                 // don't show future items
109                . ' AND i.itime <= ' . mysqldate($blogObj->getCorrectTime());
110
111 //        if ($blogObj->getSelectedCategory())
112 //            $query .= ' and i.icat=' . $blogObj->getSelectedCategory() . ' ';
113
114         $query .= $extraQuery
115                 . ' ORDER BY i.itime DESC'
116                 . ' LIMIT ' . intval($amountEntries);
117         return $query;
118     }
119 }