OSDN Git Service

MySQL5.0.x以降にも対応
authorshizuki <shizuki@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Tue, 31 Oct 2006 01:25:18 +0000 (01:25 +0000)
committershizuki <shizuki@1ca29b6e-896d-4ea0-84a5-967f57386b96>
Tue, 31 Oct 2006 01:25:18 +0000 (01:25 +0000)
git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@468 1ca29b6e-896d-4ea0-84a5-967f57386b96

trunk/NP_RecentItems/NP_RecentItems.php

index ae1025d..e9ae1f9 100644 (file)
 <?
-
+/**
+  *
+  * SHOW RECENT ITEMS PLUG-IN FOR NucleusCMS
+  * PHP versions 4 and 5
+  *
+  * This program is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU General Public License
+  * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+  * (see nucleus/documentation/index.html#license for more info)
+  *
+  * @author        Original Author nakahara21
+  * @copyright    2005-2006 nakahara21
+  * @license        http://www.gnu.org/licenses/gpl.txt  GNU GENERAL PUBLIC LICENSE Version 2, June 1991
+  * @version       0.51
+  * @link          http://nakahara21.com
+  *
+  */
+/**
+  * HISTORY
+  * 0.51 add BLOGID mode 
+  */
 class NP_RecentItems extends NucleusPlugin
 {
-       function getName()
-       {
-               return 'RecentItems';
-       }
-
-       function getAuthor()
-       {
-               return 'nakahara21';
-       }
+    function getName()
+    {
+        return 'RecentItems';
+    }
 
-       function getURL()
-       {
-               return 'http://nakahara21.com';
-       }
+    function getAuthor()
+    {
+        return 'nakahara21';
+    }
 
-       function getVersion()
-       {
-               return '0.5';
-       }
+    function getURL()
+    {
+        return 'http://nakahara21.com';
+    }
 
-       function getDescription()
-       {
-               return 'Display Recent Items. Usage: &lt;%RecentItems(blogname,templatename,5)%&gt;';
-       }
+    function getVersion()
+    {
+        return '0.51';
+    }
 
-       function supportsFeature($what)
+    function getDescription()
        {
-               switch ($what) {
-                       case 'SqlTablePrefix':
-                               return 1;
-                       default:
-                               return 0;
-               }
-       }
-       function doSkinVar($skinType, $blogName = '', $templateName = '', $amountEntries = 5)
-       { 
-               global $manager;
+        return 'Display Recent Items. Usage: &lt;%RecentItems(blogname,templatename,5)%&gt;';
+    }
 
+    function supportsFeature($what)
+    {
+        switch ($what) {
+            case 'SqlTablePrefix':
+                return 1;
+            default:
+                return 0;
+        }
+    }
+    function doSkinVar($skinType, $blogName = '', $templateName = '', $amountEntries = 5)
+    { 
+        global $manager;
 
-               if (!BLOG::exists($blogName)) return;
-               if (!TEMPLATE::exists($templateName)) return;
-               if ($amountEntries=='') $amountEntries = 5;
+        if (is_numeric($blogName)) {
+            $query = 'SELECT bshortname as result FROM %s WHERE bnumber = %d';
+            $blogname = quickQuery(sprintf($query, sql_table('blog'), intval($blogName)));
+        }
+        if (!BLOG::exists($blogName)) return;
+        if (!TEMPLATE::exists($templateName)) return;
+        if ($amountEntries=='') $amountEntries = 5;
 
-               $tempBid = getBlogIDFromName($blogName);
-               $b =& $manager->getBlog($tempBid); 
+        $tempBid = getBlogIDFromName($blogName);
+        $b =& $manager->getBlog($tempBid); 
 
-               $query = $this->_getsqlquery($b, $amountEntries, '');
-               $b->showUsingQuery($templateName, $query, 0, 1, 0);
-       }
+        $query = $this->_getsqlquery($b, $amountEntries, '');
+        $b->showUsingQuery($templateName, $query, 0, 1, 0);
+    }
 
-       function _getsqlquery($blogObj, $amountEntries, $extraQuery)
-       {
-               $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body,' .
-                               ' m.mname as author, m.mrealname as authorname, i.itime, i.imore as more,' .
-                               ' m.mnumber as authorid, m.memail as authormail, m.murl as authorurl,' .
-                               ' c.cname as category, i.icat as catid, i.iclosed as closed';
+    function _getsqlquery($blogObj, $amountEntries, $extraQuery)
+    {
+        $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body,' .
+                ' m.mname as author, m.mrealname as authorname, i.itime, i.imore as more,' .
+                ' m.mnumber as authorid, m.memail as authormail, m.murl as authorurl,' .
+                ' c.cname as category, i.icat as catid, i.iclosed as closed';
                
-               $query .= ' FROM '                      // <mod by shizuki />
-                               . sql_table('member') . ' as m, '
-                               . sql_table('category') . ' as c,'
-                               . sql_table('item') . ' as i'
-                       . ' WHERE i.iblog = ' . intval($blogObj->getID())
-                       . ' AND i.iauthor = m.mnumber'
-                       . ' AND i.icat = c.catid'
-                       . ' AND i.idraft = 0'   // exclude drafts
-                                       // don't show future items
-                       . ' AND i.itime <= ' . mysqldate($blogObj->getCorrectTime());
+        $query .= ' FROM ' .                        // <mod by shizuki corresponds MySQL 5.0.x or later />
+                sql_table('member') . ' as m, ' .
+                sql_table('category') . ' as c,' .
+                sql_table('item') . ' as i' .
+                ' WHERE i.iblog = ' . intval($blogObj->getID()) .
+                ' AND i.iauthor = m.mnumber' .
+                ' AND i.icat = c.catid' .
+                ' AND i.idraft = 0' .             // exclude drafts
+                // don't show future items
+                ' AND i.itime <= ' . mysqldate($blogObj->getCorrectTime());
 
-//             if ($blogObj->getSelectedCategory())
-//                     $query .= ' and i.icat=' . $blogObj->getSelectedCategory() . ' ';
+//        if ($blogObj->getSelectedCategory())
+//            $query .= ' and i.icat=' . $blogObj->getSelectedCategory() . ' ';
 
-               $query .= $extraQuery;
-               
-               $query .= ' ORDER BY i.itime DESC';
-               $query .= ' LIMIT ' . $amountEntries;
-               
-               return $query;
-       }
+        $query .= $extraQuery;
+
+        $query .= ' ORDER BY i.itime DESC';
+        $query .= ' LIMIT ' . intval($amountEntries);
+
+        return $query;
+    }
 }
 ?>
\ No newline at end of file