OSDN Git Service

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