OSDN Git Service

PDO対応
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / BLOG.php
index cf1ce66..d2de922 100755 (executable)
@@ -2,7 +2,7 @@
 
 /*
  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
- * Copyright (C) 2002-2006 The Nucleus Group
+ * Copyright (C) 2002-2009 The Nucleus Group
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * on the screen
  *
  * @license http://nucleuscms.org/license.txt GNU General Public License
- * @copyright Copyright (C) 2002-2006 The Nucleus Group
- * @version $Id: BLOG.php,v 1.6 2006-08-31 20:58:50 kimitake Exp $
- * $NucleusJP: BLOG.php,v 1.5 2006/07/17 20:03:44 kimitake Exp $
+ * @copyright Copyright (C) 2002-2009 The Nucleus Group
+ * @version $Id$
+ * $NucleusJP: BLOG.php,v 1.12.2.2 2007/08/08 05:26:22 kimitake Exp $
  */
 
-// temporary: dirt way to separe class ITEMACTIONS from BLOG
-require_once $DIR_LIBS . 'ITEMACTIONS.php';
+if ( !function_exists('requestVar') ) exit;
+require_once dirname(__FILE__) . '/ITEMACTIONS.php';
 
 class BLOG {
 
@@ -170,7 +170,8 @@ class BLOG {
                $items = sql_query($query);
 
                // loop over all items
-               while ($item = mysql_fetch_object($items)) {
+               $old_date = 0;
+               while ($item = sql_fetch_object($items)) {
 
                        $item->timestamp = strtotime($item->itime);     // string timestamp -> unix timestamp
 
@@ -178,7 +179,6 @@ class BLOG {
                        $actions->setCurrentItem($item);
 
                        // add date header if needed
-                       $old_date = 0;
                        if ($dateheads) {
                                $new_date = date('dFY',$item->timestamp);
                                if ($new_date != $old_date) {
@@ -187,7 +187,7 @@ class BLOG {
                                        if ($old_date != 0) {
                                                $oldTS = strtotime($old_date);
                                                $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
-                                               $tmp_footer = strftime($template['DATE_FOOTER'], $oldTS);
+                                               $tmp_footer = strftime(isset($template['DATE_FOOTER'])?$template['DATE_FOOTER']:'', $oldTS);
                                                $parser->parse($tmp_footer);
                                                $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
                                        }
@@ -210,7 +210,7 @@ class BLOG {
 
                }
 
-               $numrows = mysql_num_rows($items);
+               $numrows = sql_num_rows($items);
 
                // add another date footer if there was at least one item
                if (($numrows > 0) && $dateheads) {
@@ -219,7 +219,7 @@ class BLOG {
                        $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
                }
 
-               mysql_free_result($items);      // free memory
+               sql_free_result($items);        // free memory
 
                return $numrows;
 
@@ -235,7 +235,7 @@ class BLOG {
        /**
          * Adds an item to this blog
          */
-       function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft) {
+       function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1') {
                global $manager;
 
                $blogid         = intval($blogid);
@@ -251,7 +251,7 @@ class BLOG {
                        $more = addBreaks($more);
                }
 
-               if ($closed != '1')     $closed = '0';
+               if ($closed != '1') $closed = '0';
                if ($draft != '0') $draft = '1';
 
                if (!$this->isValidCategory($catid))
@@ -268,10 +268,10 @@ class BLOG {
                $body = addslashes($body);
                $more = addslashes($more);
 
-               $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT) '
-                          . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid)";
+               $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) '
+                          . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid, $posted)";
                sql_query($query);
-               $itemid = mysql_insert_id();
+               $itemid = sql_insert_id();
 
                $manager->notify('PostAddItem',array('itemid' => $itemid));
 
@@ -292,7 +292,18 @@ class BLOG {
                $ascii = toAscii($body);
 
                $mailto_msg = _NOTIFY_NI_MSG . " \n";
-               $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
+//             $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
+               $temp = parse_url($CONF['Self']);
+               if ($temp['scheme']) {
+                       $mailto_msg .= createItemLink($itemid) . "\n\n";
+               } else {
+                       $tempurl = $this->getURL();
+                       if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') {
+                               $mailto_msg .= $tempurl . '?itemid=' . $itemid . "\n\n";
+                       } else {
+                               $mailto_msg .= $tempurl . '/?itemid=' . $itemid . "\n\n";
+                       }
+               }
                $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";
                $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";
                $mailto_msg .= getMailFooter();
@@ -322,18 +333,18 @@ class BLOG {
          *             the new category-id in case of success.
          *             0 on failure
          */
-       function createNewCategory($catName = '', $catDescription = 'New category') {
+       function createNewCategory($catName = '', $catDescription = _CREATED_NEW_CATEGORY_DESC) {
                global $member, $manager;
 
                if ($member->blogAdminRights($this->getID())) {
                        // generate
                        if ($catName == '')
                        {
-                               $catName = 'newcat';
+                               $catName = _CREATED_NEW_CATEGORY_NAME;
                                $i = 1;
 
                                $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
-                               while (mysql_num_rows($res) > 0)
+                               while (sql_num_rows($res) > 0)
                                {
                                        $i++;
                                        $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
@@ -353,7 +364,7 @@ class BLOG {
 
                        $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')";
                        sql_query($query);
-                       $catid = mysql_insert_id();
+                       $catid = sql_insert_id();
 
                        $manager->notify(
                                'PostAddCategory',
@@ -542,8 +553,13 @@ class BLOG {
        function showArchiveList($template, $mode = 'month', $limit = 0) {
                global $CONF, $catid, $manager;
 
-               if ($catid)
+               if (!isset ($linkparams)) {
+               $linkparams = array();
+               }
+
+               if ($catid) {
                        $linkparams = array('catid' => $catid);
+               }
 
                $template =& $manager->getTemplate($template);
                $data['blogid'] = $this->getID();
@@ -558,7 +574,9 @@ class BLOG {
                if ($catid)
                        $query .= ' and icat=' . intval($catid);
 
-               $query .= ' GROUP BY Year, Month';
+               $query .= ' GROUP BY Year';
+               if ($mode == 'month' || $mode == 'day')
+                       $query .= ', Month';
                if ($mode == 'day')
                        $query .= ', Day';
 
@@ -570,25 +588,45 @@ class BLOG {
 
                $res = sql_query($query);
 
-               while ($current = mysql_fetch_object($res)) {
+               while ($current = sql_fetch_object($res)) {
                        $current->itime = strtotime($current->itime);   // string time -> unix timestamp
 
                        if ($mode == 'day') {
-                               $archivedate = date('Y-m-d',$current->itime);
-                               $archive['day'] = date('d',$current->itime);
+                               $archivedate      = date('Y-m-d',$current->itime);
+                               $archive['day']   = date('d',$current->itime);
+                               $data['day']      = date('d',$current->itime);
+                               $data['month']    = date('m',$current->itime);
+                               $archive['month'] = $data['month'];
+                       } elseif ($mode == 'year') {
+                               $archivedate      = date('Y',$current->itime);
+                               $data['day']      = '';
+                               $data['month']    = '';
+                               $archive['day']   = '';
+                               $archive['month'] = '';
                        } else {
                                $archivedate = date('Y-m',$current->itime);
+                               $data['month'] = date('m',$current->itime);
+                               $archive['month'] = $data['month'];
+                               $data['day'] = '';
+                               $archive['day'] = '';
                        }
-                       $data['month'] = date('m',$current->itime);
                        $data['year'] = date('Y',$current->itime);
+                       $archive['year'] = $data['year'];
                        $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams);
 
+                       $manager->notify(
+                               'PreArchiveListItem',
+                               array(
+                                       'listitem' => &$data
+                               )
+                       );
+
                        $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
                        echo strftime($temp,$current->itime);
 
                }
 
-               mysql_free_result($res);
+               sql_free_result($res);
 
                echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
        }
@@ -618,7 +656,7 @@ class BLOG {
                }
 
                //$blogurl = $this->getURL() . $qargs;
-               $blogurl = createBlogLink($this->getURL(), $linkparams);
+               //$blogurl = createBlogLink($this->getURL(), $linkparams);
 
                $template =& $manager->getTemplate($template);
 
@@ -633,7 +671,7 @@ class BLOG {
                $res = sql_query($query);
 
 
-               while ($data = mysql_fetch_assoc($res)) {
+               while ($data = sql_fetch_assoc($res)) {
                        $data['blogid'] = $this->getID();
                        $data['blogurl'] = $blogurl;
                        $data['catlink'] = createLink(
@@ -646,13 +684,20 @@ class BLOG {
                                                           );
                        $data['self'] = $CONF['Self'];
 
+                       $manager->notify(
+                               'PreCategoryListItem',
+                               array(
+                                       'listitem' => &$data
+                               )
+                       );
+
                        echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
                        //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
                        //echo strftime($temp, $current->itime);
 
                }
 
-               mysql_free_result($res);
+               sql_free_result($res);
 
                echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null),
                                                        array(
@@ -663,6 +708,95 @@ class BLOG {
        }
 
        /**
+         * Shows a list of all blogs in the system using a given template
+         * ordered by  number, name, shortname or description
+         * in ascending or descending order
+         */
+       function showBlogList($template, $bnametype, $orderby, $direction) {
+               global $CONF, $manager;
+
+               switch ($orderby) {
+                       case 'number':
+                               $orderby='bnumber';
+                               break;
+                       case 'name':
+                               $orderby='bname';
+                               break;
+                       case 'shortname':
+                               $orderby='bshortname';
+                               break;
+                       case 'description':
+                               $orderby='bdesc';
+                               break;
+                       default:
+                               $orderby='bnumber';
+                               break;
+               }
+
+               $direction=strtolower($direction);
+               switch ($direction) {
+                       case 'asc':
+                               $direction='ASC';
+                               break;
+                       case 'desc':
+                               $direction='DESC';
+                               break;
+                       default:
+                               $direction='ASC';
+                               break;
+               }
+
+               $template =& $manager->getTemplate($template);
+
+               echo TEMPLATE::fill((isset($template['BLOGLIST_HEADER']) ? $template['BLOGLIST_HEADER'] : null),
+                                                       array(
+                                                               'sitename' => $CONF['SiteName'],
+                                                               'siteurl' => $CONF['IndexURL']
+                                                       ));
+
+               $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY '.$orderby.' '.$direction;
+               $res = sql_query($query);
+
+               while ($data = sql_fetch_assoc($res)) {
+
+                       $list = array();
+
+//                     $list['bloglink'] = createLink('blog', array('blogid' => $data['bnumber']));
+                       $list['bloglink'] = createBlogidLink($data['bnumber']);
+
+                       $list['blogdesc'] = $data['bdesc'];
+
+                       $list['blogurl'] = $data['burl'];
+
+                       if ($bnametype=='shortname') {
+                               $list['blogname'] = $data['bshortname'];
+                       }
+                       else { // all other cases
+                               $list['blogname'] = $data['bname'];
+                       }
+
+                       $manager->notify(
+                               'PreBlogListItem',
+                               array(
+                                       'listitem' => &$list
+                               )
+                       );
+
+                       echo TEMPLATE::fill((isset($template['BLOGLIST_LISTITEM']) ? $template['BLOGLIST_LISTITEM'] : null), $list);
+
+               }
+
+               sql_free_result($res);
+
+               echo TEMPLATE::fill((isset($template['BLOGLIST_FOOTER']) ? $template['BLOGLIST_FOOTER'] : null),
+                                                       array(
+                                                               'sitename' => $CONF['SiteName'],
+                                                               'siteurl' => $CONF['IndexURL']
+                                                       ));
+
+       }
+
+       /**
          * Blogsettings functions
          */
 
@@ -672,11 +806,11 @@ class BLOG {
                           . ' WHERE bnumber=' . $this->blogid;
                $res = sql_query($query);
 
-               $this->isValid = (mysql_num_rows($res) > 0);
+               $this->isValid = (sql_num_rows($res) > 0);
                if (!$this->isValid)
                        return;
 
-               $this->settings = mysql_fetch_assoc($res);
+               $this->settings = sql_fetch_assoc($res);
        }
 
        function writeSettings() {
@@ -694,7 +828,7 @@ class BLOG {
                           . "     btimeoffset=" . $offset . ","
                           . "     bpublic=" . intval($this->isPublic()) . ","
                           . "     breqemail=" . intval($this->emailRequired()) . ","
-                          . "     bsendping=" . intval($this->pingUserland()) . ","
+                          . "     bsendping=" . intval($this->sendPing()) . ","
                           . "     bconvertbreaks=" . intval($this->convertBreaks()) . ","
                           . "     ballowpast=" . intval($this->allowPastPosting()) . ","
                           . "     bnotify='" . addslashes($this->getNotifyAddress()) . "',"
@@ -722,81 +856,35 @@ class BLOG {
 
        }
 
-       /**
-         * Sends a XML-RPC ping message to Userland, so the weblog can
-         * show up in the weblogs.com updates-list
-         */
-       function sendUserlandPing() {
-               global $php_errormsg;
-
-                if ($this->pingUserland()) {
-                         // testmessage for adding an item
-                         $message = new xmlrpcmsg('weblogUpdates.ping',array(
-                                       new xmlrpcval($this->getName(),'string'),
-                                       new xmlrpcval($this->getURL(),'string')
-                         ));
-
-                         $c = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80);
-
-                         // $c->setDebug(1);
-
-                         $r = $c->send($message,15); // 15 seconds timeout...
-
-                         if (($r == 0) && ($r->errno || $r->errstring)) {
-                               return 'Error ' . $r->errno . ' : ' . $r->errstring;
-                         } elseif (($r == 0) && ($php_errormsg)) {
-                               return 'PHP Error: ' . $php_errormsg;
-                         } elseif ($r == 0) {
-                               return 'Error while trying to send ping. Sorry about that.';
-                         } elseif ($r->faultCode() != 0) {
-                               return 'Error: ' . $r->faultString();
-                         } else {
-                                 $r = $r->value();     // get response struct
-                                 // get values
-                                 $flerror = $r->structmem('flerror');
-                                 $flerror = $flerror->scalarval();
-
-
-                                 $message = $r->structmem('message');
-                                 $message = $message->scalarval();
-
-                                 if ($flerror != 0)
-                                       return 'Error (flerror=1): ' . $message;
-                                 else
-                                       return 'Success: ' . $message;
-                         }
-                }
-       }
-
        function isValidCategory($catid) {
                $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid);
-               $res = mysql_query($query);
-               return (mysql_num_rows($res) != 0);
+               $res = sql_query($query);
+               return (sql_num_rows($res) != 0);
        }
 
        function getCategoryName($catid) {
-               $res = mysql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
-               $o = mysql_fetch_object($res);
+               $res = sql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
+               $o = sql_fetch_object($res);
                return $o->cname;
        }
 
        function getCategoryDesc($catid) {
-               $res = mysql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
-               $o = mysql_fetch_object($res);
+               $res = sql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
+               $o = sql_fetch_object($res);
                return $o->cdesc;
        }
 
        function getCategoryIdFromName($name) {
-               $res = mysql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"');
-               if (mysql_num_rows($res) > 0) {
-                       $o = mysql_fetch_object($res);
+               $res = sql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"');
+               if (sql_num_rows($res) > 0) {
+                       $o = sql_fetch_object($res);
                        return $o->catid;
                } else {
                        return $this->getDefaultCategory();
                }
        }
 
-       function pingUserland() {
+       function sendPing() {
                return $this->getSetting('bsendping');
        }
 
@@ -1029,8 +1117,8 @@ class BLOG {
 
                );
 
-               ACTIONLOG::add(INFO, 'Added ' . $tmem->getDisplayName() . ' (ID=' .
-                                          $memberid .') to the team of blog "' . $this->getName() . '"');
+               $logMsg = sprintf(_TEAM_ADD_NEWTEAMMEMBER, $tmem->getDisplayName(), $memberid, $this->getName());
+               ACTIONLOG::add(INFO, $logMsg);
 
                return 1;
        }
@@ -1042,16 +1130,144 @@ class BLOG {
        // returns true if there is a blog with the given shortname (static)
        function exists($name) {
                $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"');
-               return (mysql_num_rows($r) != 0);
+               return (sql_num_rows($r) != 0);
        }
 
        // returns true if there is a blog with the given ID (static)
        function existsID($id) {
                $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));
-               return (mysql_num_rows($r) != 0);
+               return (sql_num_rows($r) != 0);
+       }
+
+        // flag there is a future post pending
+        function setFuturePost() {
+               $query =  'UPDATE '.sql_table('blog')
+                          . " SET bfuturepost='1' WHERE bnumber=" . $this->getID();
+               sql_query($query);
+        }
+
+       // clear there is a future post pending
+       function clearFuturePost() {
+               $query =  'UPDATE '.sql_table('blog')
+                          . " SET bfuturepost='0' WHERE bnumber=" . $this->getID();
+               sql_query($query);
        }
 
+       // check if we should throw justPosted event
+       function checkJustPosted() {
+               global $manager;
+
+               if ($this->settings['bfuturepost'] == 1) {
+                       $blogid = $this->getID();
+                       $result = sql_query("SELECT * FROM " . sql_table('item')
+                                 . " WHERE iposted=0 AND iblog=" . $blogid . " AND itime<NOW()");
+                       if (sql_num_rows($result) > 0) {
+                               // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already
+                               // Note that the plugins's calling order is subject to thri order in the plugin list
+                               $pinged = false;
+                               $manager->notify(
+                                               'JustPosted',
+                                               array('blogid' => $blogid,
+                                               'pinged' => &$pinged
+                                               )
+                               );
+
+                               // clear all expired future posts
+                               sql_query("UPDATE " . sql_table('item') . " SET iposted='1' WHERE iblog=" . $blogid . " AND itime<NOW()");
+
+                               // check to see any pending future post, clear the flag is none
+                               $result = sql_query("SELECT * FROM " . sql_table('item')
+                                         . " WHERE iposted=0 AND iblog=" . $blogid);
+                               if (sql_num_rows($result) == 0) {
+                                       $this->clearFuturePost();
+                               }
+                       }
+               }
+       }
+
+       /**
+        * Shows the given list of items for this blog
+        *
+        * @param $itemarray
+        *              array of item numbers to be displayed
+        * @param $template
+        *              String representing the template _NAME_ (!)
+        * @param $highlight
+        *              contains a query that should be highlighted
+        * @param $comments
+        *              1=show comments 0=don't show comments
+        * @param $dateheads
+        *              1=show dateheads 0=don't show dateheads
+        * @returns int
+        *              amount of items shown
+        */
+       function readLogFromList($itemarray, $template, $highlight = '', $comments = 1, $dateheads = 1) {
+
+               $query = $this->getSqlItemList($itemarray);
+
+               return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
+       }
+
+       /**
+        * Returns the SQL query used to fill out templates for a list of items
+        *
+        * @param $itemarray
+        *              an array holding the item numbers of the items to be displayed
+        * @returns
+        *              either a full SQL query, or an empty string
+        * @note
+        *              No LIMIT clause is added. (caller should add this if multiple pages are requested)
+        */
+       function getSqlItemList($itemarray)
+       {
+               if (!is_array($itemarray)) return '';
+               $items = array();
+               foreach ($itemarray as $value) {
+                       if (intval($value)) $items[] = intval($value);
+               }
+               if (!count($items)) return '';
+               //$itemlist = implode(',',$items);
+               $i = count($items);
+               $query = '';
+               foreach ($items as $value) {
+                       $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 '
+                                       . sql_table('item') . ' as i, '
+                                       . sql_table('member') . ' as m, '
+                                       . sql_table('category').' as c'
+                                   . ' WHERE'
+                                       .     ' i.iblog   = ' . $this->blogid
+                                   . ' 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($this->getCorrectTime());
+
+                       //$query .= ' and i.inumber IN ('.$itemlist.')';
+                       $query .= ' and i.inumber = '.intval($value);
+                       $query .= ')';
+                       $i--;
+                       if ($i) $query .= ' UNION ';
+               }
+
+               return $query;
+       }
 
 }
 
-?>
+?>
\ No newline at end of file