OSDN Git Service

CHANGE: NOTIFICATIONクラスの整備。i18nのメール送信メソッドを移植
[nucleus-jp/nucleus-next.git] / nucleus / libs / BLOG.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2009 The Nucleus Group
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 /**
14  * A class representing a blog and containing functions to get that blog shown
15  * on the screen
16  *
17  * @license http://nucleuscms.org/license.txt GNU General Public License
18  * @copyright Copyright (C) 2002-2009 The Nucleus Group
19  * @version $Id: BLOG.php 1624 2012-01-09 11:36:20Z sakamocchi $
20  */
21
22 if ( !function_exists('requestVar') ) exit;
23 require_once dirname(__FILE__) . '/ITEMACTIONS.php';
24
25 class BLOG {
26
27         // blog id
28         var $blogid;
29
30         // ID of currently selected category
31         var $selectedcatid;
32
33         // After creating an object of the blog class, contains true if the BLOG object is
34         // valid (the blog exists)
35         var $isValid;
36
37         // associative array, containing all blogsettings (use the get/set functions instead)
38         var $settings;
39
40         /**
41          * Creates a new BLOG object for the given blog
42          *
43          * @param $id blogid
44          */
45         function BLOG($id) {
46                 $this->blogid = intval($id);
47                 $this->readSettings();
48
49                 // try to set catid
50                 // (the parse functions in SKIN.php will override this, so it's mainly useless)
51                 global $catid;
52                 $this->setSelectedCategory($catid);
53         }
54
55         /**
56          * Shows the given amount of items for this blog
57          *
58          * @param $template
59          *              String representing the template _NAME_ (!)
60          * @param $amountEntries
61          *              amount of entries to show
62          * @param $startpos
63          *              offset from where items should be shown (e.g. 5 = start at fifth item)
64          * @returns int
65          *              amount of items shown
66          */
67         function readLog($template, $amountEntries, $offset = 0, $startpos = 0) {
68                 return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos);
69         }
70
71         /**
72          * Shows an archive for a given month
73          *
74          * @param $year
75          *              year
76          * @param $month
77          *              month
78          * @param $template
79          *              String representing the template name to be used
80          */
81         function showArchive($templatename, $year, $month=0, $day=0) {
82
83                 // create extra where clause for select query
84                 if ($day == 0 && $month != 0) {
85                         $timestamp_start = mktime(0,0,0,$month,1,$year);
86                         $timestamp_end = mktime(0,0,0,$month+1,1,$year);  // also works when $month==12
87                 } elseif ($month == 0) {
88                         $timestamp_start = mktime(0,0,0,1,1,$year);
89                         $timestamp_end = mktime(0,0,0,12,31,$year);  // also works when $month==12
90                 } else {
91                         $timestamp_start = mktime(0,0,0,$month,$day,$year);
92                         $timestamp_end = mktime(0,0,0,$month,$day+1,$year);
93                 }
94                 $extra_query = ' and i.itime>=' . mysqldate($timestamp_start)
95                                          . ' and i.itime<' . mysqldate($timestamp_end);
96
97
98                 $this->readLogAmount($templatename,0,$extra_query,'',1,1);
99
100         }
101
102         /**
103          * Sets the selected category by id (only when category exists)
104          */
105         function setSelectedCategory($catid) {
106                 if ($this->isValidCategory($catid) || (intval($catid) == 0))
107                         $this->selectedcatid = intval($catid);
108         }
109
110         /**
111          * Sets the selected category by name
112          */
113         function setSelectedCategoryByName($catname) {
114                 $this->setSelectedCategory($this->getCategoryIdFromName($catname));
115         }
116
117         /**
118          * Returns the selected category
119          */
120         function getSelectedCategory() {
121                 return $this->selectedcatid;
122         }
123
124         /**
125          * Shows the given amount of items for this blog
126          *
127          * @param $template
128          *              String representing the template _NAME_ (!)
129          * @param $amountEntries
130          *              amount of entries to show (0 = no limit)
131          * @param $extraQuery
132          *              extra conditions to be added to the query
133          * @param $highlight
134          *              contains a query that should be highlighted
135          * @param $comments
136          *              1=show comments 0=don't show comments
137          * @param $dateheads
138          *              1=show dateheads 0=don't show dateheads
139          * @param $offset
140          *              offset
141          * @returns int
142          *              amount of items shown
143          */
144         function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) {
145
146                 $query = $this->getSqlBlog($extraQuery);
147
148                 if ($amountEntries > 0) {
149                                 // $offset zou moeten worden:
150                                 // (($startpos / $amountentries) + 1) * $offset ... later testen ...
151                            $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries);
152                 }
153                 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
154         }
155
156         /**
157          * Do the job for readLogAmmount
158          */     
159         function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) {
160                 global $CONF, $manager;
161
162                 $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
163                 if ($lastVisit != 0)
164                         $lastVisit = $this->getCorrectTime($lastVisit);
165
166                 // set templatename as global variable (so plugins can access it)
167                 global $currentTemplateName;
168                 $currentTemplateName = $templateName;
169
170                 $template =& $manager->getTemplate($templateName);
171
172                 // create parser object & action handler
173                 $actions = new ITEMACTIONS($this);
174                 $parser = new PARSER($actions->getDefinedActions(),$actions);
175                 $actions->setTemplate($template);
176                 $actions->setHighlight($highlight);
177                 $actions->setLastVisit($lastVisit);
178                 $actions->setParser($parser);
179                 $actions->setShowComments($comments);
180
181                 // execute query
182                 $items = sql_query($query);
183
184                 // loop over all items
185                 $old_date = 0;
186                 while ($item = sql_fetch_object($items)) {
187
188                         $item->timestamp = strtotime($item->itime);     // string timestamp -> unix timestamp
189
190                         // action handler needs to know the item we're handling
191                         $actions->setCurrentItem($item);
192
193                         // add date header if needed
194                         if ($dateheads) {
195                                 $new_date = date('dFY',$item->timestamp);
196                                 if ($new_date != $old_date) {
197                                         // unless this is the first time, write date footer
198                                         $timestamp = $item->timestamp;
199                                         if ($old_date != 0) {
200                                                 $oldTS = strtotime($old_date);
201                                                 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
202                                                 $tmp_footer = i18n::strftime(isset($template['DATE_FOOTER'])?$template['DATE_FOOTER']:'', $oldTS);
203                                                 $parser->parse($tmp_footer);
204                                                 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
205                                         }
206                                         $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
207                                         // note, to use templatvars in the dateheader, the %-characters need to be doubled in
208                                         // order to be preserved by strftime
209                                         $tmp_header = i18n::strftime((isset($template['DATE_HEADER']) ? $template['DATE_HEADER'] : null), $timestamp);
210                                         $parser->parse($tmp_header);
211                                         $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
212                                 }
213                                 $old_date = $new_date;
214                         }
215
216                         // parse item
217                         $parser->parse($template['ITEM_HEADER']);
218                         $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item));
219                         $parser->parse($template['ITEM']);
220                         $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item));
221                         $parser->parse($template['ITEM_FOOTER']);
222
223                 }
224
225                 $numrows = sql_num_rows($items);
226
227                 // add another date footer if there was at least one item
228                 if (($numrows > 0) && $dateheads) {
229                         $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
230                         $parser->parse($template['DATE_FOOTER']);
231                         $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
232                 }
233
234                 sql_free_result($items);        // free memory
235
236                 return $numrows;
237
238         }
239
240         /**
241          * Simplified function for showing only one item
242          */
243         function showOneitem($itemid, $template, $highlight) {
244                 $extraQuery = ' and inumber=' . intval($itemid);
245
246                 return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0);
247         }
248
249
250         /**
251           * Adds an item to this blog
252           */
253         function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1') {
254                 global $manager;
255
256                 $blogid         = intval($blogid);
257                 $authorid       = intval($authorid);
258                 $title          = $title;
259                 $body           = $body;
260                 $more           = $more;
261                 $catid          = intval($catid);
262
263                 // convert newlines to <br />
264                 if ($this->convertBreaks()) {
265                         $body = addBreaks($body);
266                         $more = addBreaks($more);
267                 }
268
269                 if ($closed != '1') $closed = '0';
270                 if ($draft != '0') $draft = '1';
271
272                 if (!$this->isValidCategory($catid))
273                         $catid = $this->getDefaultCategory();
274
275                 if ($timestamp > $this->getCorrectTime())
276                         $isFuture = 1;
277
278                 $timestamp = date('Y-m-d H:i:s',$timestamp);
279
280                 $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid));
281
282                 $ititle = sql_real_escape_string($title);
283                 $ibody = sql_real_escape_string($body);
284                 $imore = sql_real_escape_string($more);
285
286                 $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) '
287                            . "VALUES ('$ititle', '$ibody', '$imore', $blogid, $authorid, '$timestamp', $closed, $draft, $catid, $posted)";
288                 sql_query($query);
289                 $itemid = sql_insert_id();
290
291                 $manager->notify('PostAddItem',array('itemid' => $itemid));
292
293                 if (!$draft)
294                         $this->updateUpdateFile();
295
296                 // send notification mail
297                 if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem())
298                         $this->sendNewItemNotification($itemid, $title, $body);
299
300                 return $itemid;
301         }
302
303         /**
304          * BLOG::sendNewItemNotification()
305          * Send a new item notification to the notification list
306          * 
307          * @param String        $itemid ID of the item
308          * @param String        $title  title of the item
309          * @param String        $body   body of the item
310          * @return      Void
311          */
312         function sendNewItemNotification($itemid, $title, $body)
313         {
314                 global $CONF, $member;
315                 
316                 // FIXME: create text version of html post. this seems to be needless...
317                 $ascii = toAscii($body);
318                 
319                 $message = _NOTIFY_NI_MSG . " \n";
320                 $temp = parse_url($CONF['Self']);
321                 if ( $temp['scheme'] )
322                 {
323                         $message .= createItemLink($itemid) . "\n\n";
324                 }
325                 else
326                 {
327                         $tempurl = $this->getURL();
328                         if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' )
329                         {
330                                 $message .= $tempurl . '?itemid=' . $itemid . "\n\n";
331                         }
332                         else
333                         {
334                                 $message .= $tempurl . '/?itemid=' . $itemid . "\n\n";
335                         }
336                 }
337                 $message .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";
338                 $message .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";
339                 $message .= NOTIFICATION::get_mail_footer();
340                 
341                 $subject = $this->getName() . ': ' . _NOTIFY_NI_TITLE;
342                 
343                 $from = $member->getNotifyFromMailAddress();
344                 
345                 NOTIFICATION::mail($this->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset());
346                 return;
347         }
348
349
350         /**
351           * Creates a new category for this blog
352           *
353           * @param $catName
354           *             name of the new category. When empty, a name is generated automatically
355           *             (starting with newcat)
356           * @param $catDescription
357           *             description of the new category. Defaults to 'New Category'
358           *
359           * @returns
360           *             the new category-id in case of success.
361           *             0 on failure
362           */
363         function createNewCategory($catName = '', $catDescription = _CREATED_NEW_CATEGORY_DESC) {
364                 global $member, $manager;
365
366                 if ($member->blogAdminRights($this->getID())) {
367                         // generate
368                         if ($catName == '')
369                         {
370                                 $catName = _CREATED_NEW_CATEGORY_NAME;
371                                 $i = 1;
372
373                                 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
374                                 while (sql_num_rows($res) > 0)
375                                 {
376                                         $i++;
377                                         $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
378                                 }
379
380                                 $catName = $catName . $i;
381                         }
382
383                         $manager->notify(
384                                 'PreAddCategory',
385                                 array(
386                                         'blog' => &$this,
387                                         'name' => &$catName,
388                                         'description' => $catDescription
389                                 )
390                         );
391
392                         $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . sql_real_escape_string($catName) . "', '" . sql_real_escape_string($catDescription) . "')";
393                         sql_query($query);
394                         $catid = sql_insert_id();
395
396                         $manager->notify(
397                                 'PostAddCategory',
398                                 array(
399                                         'blog' => &$this,
400                                         'name' => $catName,
401                                         'description' => $catDescription,
402                                         'catid' => $catid
403                                 )
404                         );
405
406                         return $catid;
407                 } else {
408                         return 0;
409                 }
410
411         }
412
413
414         /**
415          * Searches all months of this blog for the given query
416          *
417          * @param $query
418          *              search query
419          * @param $template
420          *              template to be used (__NAME__ of the template)
421          * @param $amountMonths
422          *              max amount of months to be search (0 = all)
423          * @param $maxresults
424          *              max number of results to show
425          * @param $startpos
426          *              offset
427          * @returns
428          *              amount of hits found
429          */
430         function search($query, $template, $amountMonths, $maxresults, $startpos) {
431                 global $CONF, $manager;
432
433                 $highlight      = '';
434                 $sqlquery       = $this->getSqlSearch($query, $amountMonths, $highlight);
435
436                 if ($sqlquery == '')
437                 {
438                         // no query -> show everything
439                         $extraquery = '';
440                         $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1);
441                 } else {
442
443                         // add LIMIT to query (to split search results into pages)
444                         if (intval($maxresults > 0))
445                                 $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults);
446
447                         // show results
448                         $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1);
449
450                         // when no results were found, show a message
451                         if ($amountfound == 0)
452                         {
453                                 $template =& $manager->getTemplate($template);
454                                 $vars = array(
455                                         'query'         => i18n::hsc($query),
456                                         'blogid'        => $this->getID()
457                                 );
458                                 echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars);
459                         }
460                 }
461
462                 return $amountfound;
463         }
464
465         /**
466          * Returns an SQL query to use for a search query
467          *
468          * @param $query
469          *              search query
470          * @param $amountMonths
471          *              amount of months to search back. Default = 0 = unlimited
472          * @param $mode
473          *              either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
474          * @returns $highlight
475          *              words to highlight (out parameter)
476          * @returns
477          *              either a full SQL query, or an empty string (if querystring empty)
478          * @note
479          *              No LIMIT clause is added. (caller should add this if multiple pages are requested)
480          */
481         function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')
482         {
483                 $searchclass = new SEARCH($query);
484
485                 $highlight        = $searchclass->inclusive;
486
487                 // if querystring is empty, return empty string
488                 if ($searchclass->inclusive == '')
489                         return '';
490
491
492                 $where  = $searchclass->boolean_sql_where('ititle,ibody,imore');
493                 $select = $searchclass->boolean_sql_select('ititle,ibody,imore');
494
495                 // get list of blogs to search
496                 $blogs          = $searchclass->blogs;          // array containing blogs that always need to be included
497                 $blogs[]        = $this->getID();                       // also search current blog (duh)
498                 $blogs          = array_unique($blogs);         // remove duplicates
499                 $selectblogs = '';
500                 if (count($blogs) > 0)
501                         $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';
502
503                 if ($mode == '')
504                 {
505                         $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';
506                         if ($select)
507                                 $query .= ', '.$select. ' as score ';
508                 } else {
509                         $query = 'SELECT COUNT(*) as result ';
510                 }
511
512                 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
513                            . ' WHERE i.iauthor=m.mnumber'
514                            . ' and i.icat=c.catid'
515                            . ' and i.idraft=0'  // exclude drafts
516                            . $selectblogs
517                                         // don't show future items
518                            . ' and i.itime<=' . mysqldate($this->getCorrectTime())
519                            . ' and '.$where;
520
521                 // take into account amount of months to search
522                 if ($amountMonths > 0)
523                 {
524                         $localtime = getdate($this->getCorrectTime());
525                         $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);
526                         $query .= ' and i.itime>' . mysqldate($timestamp_start);
527                 }
528
529                 if ($mode == '')
530                 {
531                         if ($select)
532                                 $query .= ' ORDER BY score DESC';
533                         else
534                                 $query .= ' ORDER BY i.itime DESC ';
535                 }
536
537                 return $query;
538         }
539
540         /**
541          * Returns the SQL query that's normally used to display the blog items on the index type skins
542          *
543          * @param $mode
544          *              either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
545          * @returns
546          *              either a full SQL query, or an empty string
547          * @note
548          *              No LIMIT clause is added. (caller should add this if multiple pages are requested)
549          */
550         function getSqlBlog($extraQuery, $mode = '')
551         {
552                 if ($mode == '')
553                         $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';
554                 else
555                         $query = 'SELECT COUNT(*) as result ';
556
557                 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
558                            . ' WHERE i.iblog='.$this->blogid
559                            . ' and i.iauthor=m.mnumber'
560                            . ' and i.icat=c.catid'
561                            . ' and i.idraft=0'  // exclude drafts
562                                         // don't show future items
563                            . ' and i.itime<=' . mysqldate($this->getCorrectTime());
564
565                 if ($this->getSelectedCategory())
566                         $query .= ' and i.icat=' . $this->getSelectedCategory() . ' ';
567
568
569                 $query .= $extraQuery;
570
571                 if ($mode == '')
572                         $query .= ' ORDER BY i.itime DESC';
573
574                 return $query;
575         }
576
577         /**
578           * Shows the archivelist using the given template
579           */
580         function showArchiveList($template, $mode = 'month', $limit = 0) {
581                 global $CONF, $catid, $manager;
582
583                 if (!isset ($linkparams)) {
584                         $linkparams = array();
585                 }
586                 
587                 if ($catid) {
588                         $linkparams = array('catid' => $catid);
589                 }
590
591                 $template =& $manager->getTemplate($template);
592                 $data['blogid'] = $this->getID();
593
594                 $tplt = isset($template['ARCHIVELIST_HEADER']) ? $template['ARCHIVELIST_HEADER']
595                                                                : '';
596                 echo TEMPLATE::fill($tplt, $data);
597
598                 $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) as Day FROM '.sql_table('item')
599                 . ' WHERE iblog=' . $this->getID()
600                 . ' and itime <=' . mysqldate($this->getCorrectTime())  // don't show future items!
601                 . ' and idraft=0'; // don't show draft items
602
603                 if ($catid)
604                         $query .= ' and icat=' . intval($catid);
605
606                 $query .= ' GROUP BY Year';
607                 if ($mode == 'month' || $mode == 'day')
608                         $query .= ', Month';
609                 if ($mode == 'day')
610                         $query .= ', Day';
611
612                 $query .= ' ORDER BY itime DESC';
613
614                 if ($limit > 0)
615                         $query .= ' LIMIT ' . intval($limit);
616
617                 $res = sql_query($query);
618
619                 while ($current = sql_fetch_object($res)) {
620                         $current->itime = strtotime($current->itime);   // string time -> unix timestamp
621
622                         if ($mode == 'day') {
623                                 $archivedate = date('Y-m-d',$current->itime);
624                                 $archive['day'] = date('d',$current->itime);
625                                 $data['day'] = date('d',$current->itime);
626                                 $data['month'] = date('m',$current->itime);
627                                 $archive['month'] = $data['month'];
628                         } elseif ($mode == 'year') {
629                                 $archivedate = date('Y',$current->itime);
630                                 $data['day'] = '';
631                                 $data['month'] = '';
632                                 $archive['day'] = '';
633                                 $archive['month'] = '';
634                         } else {
635                                 $archivedate = date('Y-m',$current->itime);
636                                 $data['month'] = date('m',$current->itime);
637                                 $archive['month'] = $data['month'];
638                                 $data['day'] = '';
639                                 $archive['day'] = '';
640                         }
641
642                         $data['year'] = date('Y',$current->itime);
643                         $archive['year'] = $data['year'];
644                         $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams);
645
646                         $manager->notify(
647                                 'PreArchiveListItem',
648                                 array(
649                                         'listitem' => &$data
650                                 )
651                         );
652
653                         $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
654                         echo i18n::strftime($temp,$current->itime);
655
656                 }
657
658                 sql_free_result($res);
659
660                 $tplt = isset($template['ARCHIVELIST_FOOTER']) ? $template['ARCHIVELIST_FOOTER']
661                                                                : '';
662                 echo TEMPLATE::fill($tplt, $data);
663         }
664
665
666         /**
667           * Shows the list of categories using a given template
668           */
669         function showCategoryList($template) {
670                 global $CONF, $manager;
671
672                 // determine arguments next to catids
673                 // I guess this can be done in a better way, but it works
674                 global $archive, $archivelist;
675
676                 $linkparams = array();
677                 if ($archive) {
678                         $blogurl = createArchiveLink($this->getID(), $archive, '');
679                         $linkparams['blogid'] = $this->getID();
680                         $linkparams['archive'] = $archive;
681                 } else if ($archivelist) {
682                         $blogurl = createArchiveListLink($this->getID(), '');
683                         $linkparams['archivelist'] = $archivelist;
684                 } else {
685                         $blogurl = createBlogidLink($this->getID(), '');
686                         $linkparams['blogid'] = $this->getID();
687                 }
688
689                 //$blogurl = $this->getURL() . $qargs;
690                 //$blogurl = createBlogLink($this->getURL(), $linkparams);
691
692                 $template =& $manager->getTemplate($template);
693                 
694                 //: Change: Set nocatselected variable
695                 if ($this->getSelectedCategory()) {
696                         $nocatselected = 'no';
697                 }
698                 else {
699                         $nocatselected = 'yes';
700                 } 
701
702                 echo TEMPLATE::fill((isset($template['CATLIST_HEADER']) ? $template['CATLIST_HEADER'] : null),
703                                                         array(
704                                                                 'blogid' => $this->getID(),
705                                                                 'blogurl' => $blogurl,
706                                                                 'self' => $CONF['Self'],
707                                                                 //: Change: Set catiscurrent template variable for header
708                                                                 'catiscurrent' => $nocatselected,
709                                                                 'currentcat' => $nocatselected 
710                                                         ));
711
712                 $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC';
713                 $res = sql_query($query);
714
715
716                 while ($data = sql_fetch_assoc($res)) {
717                         $data['blogid'] = $this->getID();
718                         $data['blogurl'] = $blogurl;
719                         $data['catlink'] = createLink(
720                                                                 'category',
721                                                                 array(
722                                                                         'catid' => $data['catid'],
723                                                                         'name' => $data['catname'],
724                                                                         'extra' => $linkparams
725                                                                 )
726                                                            );
727                         $data['self'] = $CONF['Self'];
728                         
729                         //catiscurrent
730                         //: Change: Bugfix for catiscurrent logic so it gives catiscurrent = no when no category is selected.
731                         $data['catiscurrent'] = 'no';
732                         $data['currentcat'] = 'no'; 
733                         if ($this->getSelectedCategory()) {
734                                 if ($this->getSelectedCategory() == $data['catid']) {
735                                         $data['catiscurrent'] = 'yes';
736                                         $data['currentcat'] = 'yes';
737                                 }
738                                 /*else {
739                                         $data['catiscurrent'] = 'no';
740                                         $data['currentcat'] = 'no';
741                                 }*/
742                         }
743                         else {
744                                 global $itemid;
745                                 if (intval($itemid) && $manager->existsItem(intval($itemid),0,0)) {
746                                         $iobj =& $manager->getItem(intval($itemid),0,0);
747                                         $cid = $iobj['catid'];
748                                         if ($cid == $data['catid']) {
749                                                 $data['catiscurrent'] = 'yes';
750                                                 $data['currentcat'] = 'yes';
751                                         }
752                                         /*else {
753                                                 $data['catiscurrent'] = 'no';
754                                                 $data['currentcat'] = 'no';
755                                         }*/
756                                 }
757                         }
758
759                         $manager->notify(
760                                 'PreCategoryListItem',
761                                 array(
762                                         'listitem' => &$data
763                                 )
764                         );
765
766                         echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
767                         //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
768                         //echo strftime($temp, $current->itime);
769
770                 }
771
772                 sql_free_result($res);
773
774                 echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null),
775                                                         array(
776                                                                 'blogid' => $this->getID(),
777                                                                 'blogurl' => $blogurl,
778                                                                 'self' => $CONF['Self'],
779                                                                 //: Change: Set catiscurrent template variable for footer
780                                                                 'catiscurrent' => $nocatselected,
781                                                                 'currentcat' => $nocatselected  
782                                                         ));
783         }
784
785         /**
786           * Shows a list of all blogs in the system using a given template
787           * ordered by number, name, shortname or description
788           * in ascending or descending order
789           */
790         function showBlogList($template, $bnametype, $orderby, $direction) {
791                 global $CONF, $manager;
792
793                 switch ($orderby) {
794                         case 'number':
795                                 $orderby='bnumber';
796                                 break;
797                         case 'name':
798                                 $orderby='bname';
799                                 break;
800                         case 'shortname':
801                                 $orderby='bshortname';
802                                 break;
803                         case 'description':
804                                 $orderby='bdesc';
805                                 break;
806                         default:
807                                 $orderby='bnumber';
808                                 break;
809                 }
810
811                 $direction=strtolower($direction);
812                 switch ($direction) {
813                         case 'asc':
814                                 $direction='ASC';
815                                 break;
816                         case 'desc':
817                                 $direction='DESC';
818                                 break;
819                         default:
820                                 $direction='ASC';
821                                 break;
822                 }
823
824                 $template =& $manager->getTemplate($template);
825
826                 echo TEMPLATE::fill((isset($template['BLOGLIST_HEADER']) ? $template['BLOGLIST_HEADER'] : null),
827                                                         array(
828                                                                 'sitename' => $CONF['SiteName'],
829                                                                 'siteurl' => $CONF['IndexURL']
830                                                         ));
831
832                 $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY '.$orderby.' '.$direction;
833                 $res = sql_query($query);
834
835                 while ($data = sql_fetch_assoc($res)) {
836
837                         $list = array();
838
839 //                      $list['bloglink'] = createLink('blog', array('blogid' => $data['bnumber']));
840                         $list['bloglink'] = createBlogidLink($data['bnumber']);
841
842                         $list['blogdesc'] = $data['bdesc'];
843
844                         $list['blogurl'] = $data['burl'];
845
846                         if ($bnametype=='shortname') {
847                                 $list['blogname'] = $data['bshortname'];
848                         }
849                         else { // all other cases
850                                 $list['blogname'] = $data['bname'];
851                         }
852
853                         $manager->notify(
854                                 'PreBlogListItem',
855                                 array(
856                                         'listitem' => &$list
857                                 )
858                         );
859
860                         echo TEMPLATE::fill((isset($template['BLOGLIST_LISTITEM']) ? $template['BLOGLIST_LISTITEM'] : null), $list);
861
862                 }
863
864                 sql_free_result($res);
865
866                 echo TEMPLATE::fill((isset($template['BLOGLIST_FOOTER']) ? $template['BLOGLIST_FOOTER'] : null),
867                                                         array(
868                                                                 'sitename' => $CONF['SiteName'],
869                                                                 'siteurl' => $CONF['IndexURL']
870                                                         ));
871
872         }
873
874         /**
875           * Read the blog settings
876           */
877         function readSettings() {
878                 $query =  'SELECT *'
879                            . ' FROM '.sql_table('blog')
880                            . ' WHERE bnumber=' . $this->blogid;
881                 $res = sql_query($query);
882
883                 $this->isValid = (sql_num_rows($res) > 0);
884                 if (!$this->isValid)
885                         return;
886
887                 $this->settings = sql_fetch_assoc($res);
888         }
889
890         /**
891           * Write the blog settings
892           */
893         function writeSettings() {
894
895                 // (can't use floatval since not available prior to PHP 4.2)
896                 $offset = $this->getTimeOffset();
897                 if (!is_float($offset))
898                         $offset = intval($offset);
899
900                 $query =  'UPDATE '.sql_table('blog')
901                            . " SET bname='" . sql_real_escape_string($this->getName()) . "',"
902                            . "     bshortname='". sql_real_escape_string($this->getShortName()) . "',"
903                            . "     bcomments=". intval($this->commentsEnabled()) . ","
904                            . "     bmaxcomments=" . intval($this->getMaxComments()) . ","
905                            . "     btimeoffset=" . $offset . ","
906                            . "     bpublic=" . intval($this->isPublic()) . ","
907                            . "     breqemail=" . intval($this->emailRequired()) . ","
908                            . "     bconvertbreaks=" . intval($this->convertBreaks()) . ","
909                            . "     ballowpast=" . intval($this->allowPastPosting()) . ","
910                            . "     bnotify='" . sql_real_escape_string($this->getNotifyAddress()) . "',"
911                            . "     bnotifytype=" . intval($this->getNotifyType()) . ","
912                            . "     burl='" . sql_real_escape_string($this->getURL()) . "',"
913                            . "     bupdate='" . sql_real_escape_string($this->getUpdateFile()) . "',"
914                            . "     bdesc='" . sql_real_escape_string($this->getDescription()) . "',"
915                            . "     bdefcat=" . intval($this->getDefaultCategory()) . ","
916                            . "     bdefskin=" . intval($this->getDefaultSkin()) . ","
917                            . "     bincludesearch=" . intval($this->getSearchable())
918                            . " WHERE bnumber=" . intval($this->getID());
919                 sql_query($query);
920
921         }
922
923         /**
924           * Update the update file if requested
925           */    
926         function updateUpdatefile() {
927                  if ($this->getUpdateFile()) {
928                         $f_update = fopen($this->getUpdateFile(),'w');
929                         fputs($f_update,$this->getCorrectTime());
930                         fclose($f_update);
931                  }
932
933         }
934
935         /**
936           * Check if a category with a given catid is valid
937           * 
938           * @param $catid
939           *     category id
940           */
941         function isValidCategory($catid) {
942                 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid);
943                 $res = sql_query($query);
944                 return (sql_num_rows($res) != 0);
945         }
946
947         /**
948           * Get the category name for a given catid
949           * 
950           * @param $catid
951           *     category id
952           */
953         function getCategoryName($catid) {
954                 $res = sql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
955                 $o = sql_fetch_object($res);
956                 return $o->cname;
957         }
958
959         /**
960           * Get the category description for a given catid
961           * 
962           * @param $catid
963           *     category id
964           */
965         function getCategoryDesc($catid) {
966                 $res = sql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
967                 $o = sql_fetch_object($res);
968                 return $o->cdesc;
969         }
970
971         /**
972           * Get the category id for a given category name
973           * 
974           * @param $name
975           *     category name
976           */
977         function getCategoryIdFromName($name) {
978                 $res = sql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . sql_real_escape_string($name) . '"');
979                 if (sql_num_rows($res) > 0) {
980                         $o = sql_fetch_object($res);
981                         return $o->catid;
982                 } else {
983                         return $this->getDefaultCategory();
984                 }
985         }
986
987         /**
988           * Get the the setting for the line break handling
989           * [should be named as getConvertBreaks()]
990           */
991         function convertBreaks() {
992                 return $this->getSetting('bconvertbreaks');
993         }
994         
995         /**
996           * Set the the setting for the line break handling
997           * 
998           * @param $val
999           *     new value for bconvertbreaks
1000           */
1001         function setConvertBreaks($val) {
1002                 $this->setSetting('bconvertbreaks',$val);
1003         }
1004
1005         /**
1006           * Insert a javascript that includes information about the settings
1007           * of an author:  ConvertBreaks, MediaUrl and AuthorId
1008           * 
1009           * @param $authorid
1010           *     id of the author
1011           */    
1012         function insertJavaScriptInfo($authorid = '') {
1013                 global $member, $CONF;
1014
1015                 if ($authorid == '')
1016                         $authorid = $member->getID();
1017
1018                 ?>
1019                 <script type="text/javascript">
1020                         setConvertBreaks(<?php echo  $this->convertBreaks() ? 'true' : 'false' ?>);
1021                         setMediaUrl("<?php echo $CONF['MediaURL']?>");
1022                         setAuthorId(<?php echo $authorid?>);
1023                 </script><?php  
1024         }
1025
1026         /**
1027           * Set the the setting for allowing to publish postings in the past
1028           * 
1029           * @param $val
1030           *     new value for ballowpast
1031           */
1032         function setAllowPastPosting($val) {
1033                 $this->setSetting('ballowpast',$val);
1034         }
1035         
1036         /**
1037           * Get the the setting if it is allowed to publish postings in the past
1038           * [should be named as getAllowPastPosting()]
1039           */
1040         function allowPastPosting() {
1041                 return $this->getSetting('ballowpast');
1042         }
1043
1044         function getCorrectTime($t=0) {
1045                 if ($t == 0) $t = time();
1046                 return ($t + 3600 * $this->getTimeOffset());
1047         }
1048
1049         function getName() {
1050                 return $this->getSetting('bname');
1051         }
1052
1053         function getShortName() {
1054                 return $this->getSetting('bshortname');
1055         }
1056
1057         function getMaxComments() {
1058                 return $this->getSetting('bmaxcomments');
1059         }
1060
1061         function getNotifyAddress() {
1062                 return $this->getSetting('bnotify');
1063         }
1064
1065         function getNotifyType() {
1066                 return $this->getSetting('bnotifytype');
1067         }
1068
1069         function notifyOnComment() {
1070                 $n = $this->getNotifyType();
1071                 return (($n != 0) && (($n % 3) == 0));
1072         }
1073
1074         function notifyOnVote() {
1075                 $n = $this->getNotifyType();
1076                 return (($n != 0) && (($n % 5) == 0));
1077         }
1078
1079         function notifyOnNewItem() {
1080                 $n = $this->getNotifyType();
1081                 return (($n != 0) && (($n % 7) == 0));
1082         }
1083
1084         function setNotifyType($val) {
1085                 $this->setSetting('bnotifytype',$val);
1086         }
1087
1088
1089         function getTimeOffset() {
1090                 return $this->getSetting('btimeoffset');
1091         }
1092
1093         function commentsEnabled() {
1094                 return $this->getSetting('bcomments');
1095         }
1096
1097         function getURL() {
1098                 return $this->getSetting('burl');
1099         }
1100
1101         function getDefaultSkin() {
1102                 return $this->getSetting('bdefskin');
1103         }
1104
1105         function getUpdateFile() {
1106                 return $this->getSetting('bupdate');
1107         }
1108
1109         function getDescription() {
1110                 return $this->getSetting('bdesc');
1111         }
1112
1113         function isPublic() {
1114                 return $this->getSetting('bpublic');
1115         }
1116
1117         function emailRequired() {
1118                 return $this->getSetting('breqemail');
1119         }
1120
1121         function getSearchable() {
1122                 return $this->getSetting('bincludesearch');
1123         }
1124
1125         function getDefaultCategory() {
1126                 return $this->getSetting('bdefcat');
1127         }
1128
1129         function setPublic($val) {
1130                 $this->setSetting('bpublic',$val);
1131         }
1132
1133         function setSearchable($val) {
1134                 $this->setSetting('bincludesearch',$val);
1135         }
1136
1137         function setDescription($val) {
1138                 $this->setSetting('bdesc',$val);
1139         }
1140
1141         function setUpdateFile($val) {
1142                 $this->setSetting('bupdate',$val);
1143         }
1144
1145         function setDefaultSkin($val) {
1146                 $this->setSetting('bdefskin',$val);
1147         }
1148
1149         function setURL($val) {
1150                 $this->setSetting('burl',$val);
1151         }
1152
1153         function setName($val) {
1154                 $this->setSetting('bname',$val);
1155         }
1156
1157         function setShortName($val) {
1158                 $this->setSetting('bshortname',$val);
1159         }
1160
1161         function setCommentsEnabled($val) {
1162                 $this->setSetting('bcomments',$val);
1163         }
1164
1165         function setMaxComments($val) {
1166                 $this->setSetting('bmaxcomments',$val);
1167         }
1168
1169         function setNotifyAddress($val) {
1170                 $this->setSetting('bnotify',$val);
1171         }
1172
1173         function setEmailRequired($val) {
1174                 $this->setSetting('breqemail',$val);
1175         }
1176
1177         function setTimeOffset($val) {
1178                 // check validity of value
1179                 // 1. replace , by . (common mistake)
1180                 $val = str_replace(',','.',$val);
1181                 // 2. cast to float or int
1182                 if (is_numeric($val) && strstr($val,'.5')) {
1183                         $val = (float) $val;
1184                 } else {
1185                         $val = intval($val);
1186                 }
1187
1188                 $this->setSetting('btimeoffset',$val);
1189         }
1190
1191         function setDefaultCategory($val) {
1192                 $this->setSetting('bdefcat',$val);
1193         }
1194
1195         function getSetting($key) {
1196                 return $this->settings[$key];
1197         }
1198
1199         function setSetting($key,$value) {
1200                 $this->settings[$key] = $value;
1201         }
1202
1203         /**
1204           * Tries to add a member to the team. 
1205           * Returns false if the member was already on the team
1206           */
1207         function addTeamMember($memberid, $admin) {
1208                 global $manager;
1209
1210                 $memberid = intval($memberid);
1211                 $admin = intval($admin);
1212
1213                 // check if member is already a member
1214                 $tmem = MEMBER::createFromID($memberid);
1215
1216                 if ($tmem->isTeamMember($this->getID()))
1217                         return 0;
1218
1219                 $manager->notify(
1220                         'PreAddTeamMember',
1221                         array(
1222                                 'blog' => &$this,
1223                                 'member' => &$tmem,
1224                                 'admin' => &$admin
1225                         )
1226                 );
1227
1228                 // add to team
1229                 $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) '
1230                            . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")';
1231                 sql_query($query);
1232
1233                 $manager->notify(
1234                         'PostAddTeamMember',
1235                         array(
1236                                 'blog' => &$this,
1237                                 'member' => &$tmem,
1238                                 'admin' => $admin
1239                         )
1240
1241                 );
1242
1243                 $logMsg = sprintf(_TEAM_ADD_NEWTEAMMEMBER, $tmem->getDisplayName(), $memberid, $this->getName());
1244                 ACTIONLOG::add(INFO, $logMsg);
1245
1246                 return 1;
1247         }
1248
1249         function getID() {
1250                 return intval($this->blogid);
1251         }
1252
1253         /**
1254           * Checks if a blog with a given shortname exists 
1255           * Returns true if there is a blog with the given shortname (static)
1256           * 
1257           * @param $name
1258           *     blog shortname
1259           */
1260         function exists($name) {
1261                 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.sql_real_escape_string($name).'"');
1262                 return (sql_num_rows($r) != 0);
1263         }
1264
1265         /**
1266           * Checks if a blog with a given id exists 
1267           * Returns true if there is a blog with the given ID (static)
1268           * 
1269           * @param $id
1270           *     blog id
1271           */
1272         function existsID($id) {
1273                 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));
1274                 return (sql_num_rows($r) != 0);
1275         }
1276
1277         /**
1278           * flag there is a future post pending 
1279           */
1280         function setFuturePost() {
1281                 $query =  'UPDATE '.sql_table('blog')
1282                             . " SET bfuturepost='1' WHERE bnumber=" . $this->getID();
1283                 sql_query($query);
1284         }
1285
1286         /**
1287           * clear there is a future post pending 
1288           */
1289         function clearFuturePost() {
1290                 $query =  'UPDATE '.sql_table('blog')
1291                            . " SET bfuturepost='0' WHERE bnumber=" . $this->getID();
1292                 sql_query($query);
1293         }
1294
1295         /**
1296           * check if we should throw justPosted event 
1297           */
1298         function checkJustPosted() {
1299                 global $manager;
1300
1301                 if ($this->settings['bfuturepost'] == 1) {
1302                         $blogid = $this->getID();
1303                         $result = sql_query("SELECT * FROM " . sql_table('item')
1304                                   . " WHERE iposted=0 AND iblog=" . $blogid . " AND itime<NOW()");
1305                         if (sql_num_rows($result) > 0) {
1306                                 // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already
1307                                 // Note that the plugins's calling order is subject to thri order in the plugin list
1308                                 $pinged = false;
1309                                 $manager->notify(
1310                                                 'JustPosted',
1311                                                 array('blogid' => $blogid,
1312                                                 'pinged' => &$pinged
1313                                                 )
1314                                 );
1315
1316                                 // clear all expired future posts
1317                                 sql_query("UPDATE " . sql_table('item') . " SET iposted='1' WHERE iblog=" . $blogid . " AND itime<NOW()");
1318
1319                                 // check to see any pending future post, clear the flag is none
1320                                 $result = sql_query("SELECT * FROM " . sql_table('item')
1321                                           . " WHERE iposted=0 AND iblog=" . $blogid);
1322                                 if (sql_num_rows($result) == 0) {
1323                                         $this->clearFuturePost();
1324                                 }
1325                         }
1326                 }
1327         }
1328
1329         /**
1330          * Shows the given list of items for this blog
1331          *
1332          * @param $itemarray
1333          *              array of item numbers to be displayed
1334          * @param $template
1335          *              String representing the template _NAME_ (!)
1336          * @param $highlight
1337          *              contains a query that should be highlighted
1338          * @param $comments
1339          *              1=show comments 0=don't show comments
1340          * @param $dateheads
1341          *              1=show dateheads 0=don't show dateheads
1342          * @param $showDrafts
1343          *              0=do not show drafts 1=show drafts
1344          * @param $showFuture
1345          *              0=do not show future posts 1=show future posts
1346          * @returns int
1347          *              amount of items shown
1348          */
1349         function readLogFromList($itemarray, $template, $highlight = '', $comments = 1, $dateheads = 1,$showDrafts = 0, $showFuture = 0) {
1350
1351                 $query = $this->getSqlItemList($itemarray,$showDrafts,$showFuture);
1352
1353                 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
1354         }
1355
1356         /**
1357          * Returns the SQL query used to fill out templates for a list of items
1358          *
1359          * @param $itemarray
1360          *              an array holding the item numbers of the items to be displayed
1361          * @param $showDrafts
1362          *              0=do not show drafts 1=show drafts
1363          * @param $showFuture
1364          *              0=do not show future posts 1=show future posts
1365          * @returns
1366          *              either a full SQL query, or an empty string
1367          * @note
1368          *              No LIMIT clause is added. (caller should add this if multiple pages are requested)
1369          */
1370         function getSqlItemList($itemarray,$showDrafts = 0,$showFuture = 0)
1371         {
1372                 if (!is_array($itemarray)) return '';
1373                 $showDrafts = intval($showDrafts);
1374                 $showFuture = intval($showFuture);
1375                 $items = array();
1376                 foreach ($itemarray as $value) {
1377                         if (intval($value)) $items[] = intval($value);
1378                 }
1379                 if (!count($items)) return '';
1380                 //$itemlist = implode(',',$items);
1381                 $i = count($items);
1382                 $query = '';
1383                 foreach ($items as $value) {
1384                         $query .= '('
1385                                         .       'SELECT'
1386                                         .       ' i.inumber as itemid,'
1387                                         .       ' i.ititle as title,'
1388                                         .       ' i.ibody as body,'
1389                                         .       ' m.mname as author,'
1390                                         .       ' m.mrealname as authorname,'
1391                                         .       ' i.itime,'
1392                                         .       ' i.imore as more,'
1393                                         .       ' m.mnumber as authorid,'
1394                                         .       ' m.memail as authormail,'
1395                                         .       ' m.murl as authorurl,'
1396                                         .       ' c.cname as category,'
1397                                         .       ' i.icat as catid,'
1398                                         .       ' i.iclosed as closed';
1399
1400                         $query .= ' FROM '
1401                                         . sql_table('item') . ' as i, '
1402                                         . sql_table('member') . ' as m, '
1403                                         . sql_table('category') . ' as c'
1404                                         . ' WHERE'
1405                                     .    ' i.iblog='.$this->blogid
1406                                    . ' and i.iauthor=m.mnumber'
1407                                    . ' and i.icat=c.catid';
1408                         if (!$showDrafts) $query .= ' and i.idraft=0';  // exclude drafts                                               
1409                         if (!$showFuture) $query .= ' and i.itime<=' . mysqldate($this->getCorrectTime()); // don't show future items
1410
1411                         //$query .= ' and i.inumber IN ('.$itemlist.')';
1412                         $query .= ' and i.inumber='.intval($value);
1413                         $query .= ')';
1414                         $i--;
1415                         if ($i) $query .= ' UNION ';
1416                 }
1417
1418                 return $query;
1419         }
1420
1421 }
1422
1423 ?>