4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
5 * Copyright (C) 2002-2012 The Nucleus Group
\r
7 * This program is free software; you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation; either version 2
\r
10 * of the License, or (at your option) any later version.
\r
11 * (see nucleus/documentation/index.html#license for more info)
\r
14 * A class representing a blog and containing functions to get that blog shown
\r
17 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
18 * @copyright Copyright (C) 2002-2009 The Nucleus Group
\r
19 * @version $Id: BLOG.php 1624 2012-01-09 11:36:20Z sakamocchi $
\r
22 if ( !function_exists('requestVar') ) exit;
\r
23 require_once dirname(__FILE__) . '/ITEMACTIONS.php';
\r
30 // After creating an object of the blog class, contains true if the BLOG object is
\r
31 // valid (the blog exists)
\r
34 // associative array, containing all blogsettings (use the get/set functions instead)
\r
37 // ID of currently selected category
\r
38 private $selectedcatid;
\r
41 * Blog::_\construct()
\r
42 * Creates a new BLOG object for the given blog
\r
44 * @param integer $id blogid
\r
47 public function __construct($id)
\r
51 $this->blogid = (integer) $id;
\r
52 $this->readSettings();
\r
53 $this->setSelectedCategory($catid);
\r
59 * Shows the given amount of items for this blog
\r
61 * @param string $template String representing the template _NAME_ (!)
\r
62 * @param integer $amountEntries amount of entries to show
\r
63 * @param integer $startpos offset from where items should be shown (e.g. 5 = start at fifth item)
\r
64 * @return integer amount of items shown
\r
66 public function readLog($template, $amountEntries, $offset = 0, $startpos = 0)
\r
68 return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos);
\r
72 * Blog::showArchive()
\r
73 * Shows an archive for a given month
\r
75 * @param integer $year year
\r
76 * @param integer $month month
\r
77 * @param string $template String representing the template name to be used
\r
80 public function showArchive($templatename, $year, $month=0, $day=0)
\r
82 // create extra where clause for select query
\r
83 if ( $day == 0 && $month != 0 )
\r
85 $timestamp_start = mktime(0,0,0,$month,1,$year);
\r
86 // also works when $month==12
\r
87 $timestamp_end = mktime(0,0,0,$month+1,1,$year);
\r
89 elseif ( $month == 0 )
\r
91 $timestamp_start = mktime(0,0,0,1,1,$year);
\r
92 // also works when $month==12
\r
93 $timestamp_end = mktime(0,0,0,12,31,$year);
\r
97 $timestamp_start = mktime(0,0,0,$month,$day,$year);
\r
98 $timestamp_end = mktime(0,0,0,$month,$day+1,$year);
\r
100 $extra_query = " and i.itime>=%s and i.itime<%s";
\r
101 $extra_query = sprintf($extra_query, DB::formatDateTime($timestamp_start), DB::formatDateTime($timestamp_end));
\r
103 $this->readLogAmount($templatename,0,$extra_query,'',1,1);
\r
108 * Blog::setSelectedCategory()
\r
109 * Sets the selected category by id (only when category exists)
\r
111 * @param integer $catid ID for category
\r
114 public function setSelectedCategory($catid)
\r
116 if ( $this->isValidCategory($catid) || (intval($catid) == 0) )
\r
118 $this->selectedcatid = intval($catid);
\r
124 * Blog::setSelectedCategoryByName()
\r
125 * Sets the selected category by name
\r
127 * @param string $catname name of category
\r
130 public function setSelectedCategoryByName($catname)
\r
132 $this->setSelectedCategory($this->getCategoryIdFromName($catname));
\r
137 * Blog::getSelectedCategory()
\r
138 * Returns the selected category
\r
143 public function getSelectedCategory()
\r
145 return $this->selectedcatid;
\r
149 * Shows the given amount of items for this blog
\r
151 * @param string $template string representing the template _NAME_ (!)
\r
152 * @param integer $amountEntries amount of entries to show (0 = no limit)
\r
153 * @param string $extraQuery extra conditions to be added to the query
\r
154 * @param string $highlight contains a query that should be highlighted
\r
155 * @param integer $comments 1=show comments 0=don't show comments
\r
156 * @param integer $dateheads 1=show dateheads 0=don't show dateheads
\r
157 * @param integer $offset offset
\r
158 * @return integer amount of items shown
\r
160 private function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0)
\r
162 $query = $this->getSqlBlog($extraQuery);
\r
164 if ( $amountEntries > 0 )
\r
166 // $offset zou moeten worden:
\r
167 // (($startpos / $amountentries) + 1) * $offset ... later testen ...
\r
168 $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries);
\r
170 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
\r
174 * Blog::showUsingQuery()
\r
175 * Do the job for readLogAmmount
\r
177 * @param string $templateName template name
\r
178 * @param string $query string for query
\r
179 * @param string $highlight string to be highlighted
\r
180 * @param integer $comments the number of comments
\r
181 * @param boolean $dateheads date header is needed or not
\r
182 * @return integer the number of rows as a result of mysql query
\r
184 private function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1)
\r
186 global $CONF, $manager, $currentTemplateName;
\r
188 $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
\r
189 if ( $lastVisit != 0 )
\r
191 $lastVisit = $this->getCorrectTime($lastVisit);
\r
194 // set templatename as global variable (so plugins can access it)
\r
195 $currentTemplateName = $templateName;
\r
196 $template =& $manager->getTemplate($templateName);
\r
198 // create parser object & action handler
\r
199 $handler = new ItemActions($this);
\r
200 $handler->setTemplate($template);
\r
201 $handler->setHighlight($highlight);
\r
202 $handler->setLastVisit($lastVisit);
\r
203 $handler->setShowComments($comments);
\r
205 $parser = new Parser($handler);
\r
208 $items = DB::getResult($query);
\r
210 // loop over all items
\r
212 foreach ( $items as $item )
\r
214 // string timestamp -> unix timestamp
\r
215 $item['timestamp'] = strtotime($item['itime']);
\r
217 // action handler needs to know the item we're handling
\r
218 $handler->setCurrentItem($item);
\r
220 // add date header if needed
\r
223 $new_date = date('dFY', $item['timestamp']);
\r
224 if ( $new_date != $old_date )
\r
226 // unless this is the first time, write date footer
\r
227 $timestamp = $item['timestamp'];
\r
228 if ( $old_date != 0 )
\r
230 $oldTS = strtotime($old_date);
\r
231 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
\r
233 if ( !in_array('DATE_FOOTER', $template) || empty($template['DATE_FOOTER']) )
\r
239 $tmp_footer = i18n::formatted_datetime($template['DATE_FOOTER'], $oldTS);
\r
241 $parser->parse($tmp_footer);
\r
242 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
\r
245 $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
\r
247 // note, to use templatvars in the dateheader, the %-characters need to be doubled in
\r
248 // order to be preserved by strftime
\r
249 if ( !in_array('DATE_HEADER', $template) || empty($template['DATE_HEADER']) )
\r
255 $tmp_header = i18n::formatted_datetime($template['DATE_HEADER'], $timestamp);
\r
257 $parser->parse($tmp_header);
\r
258 $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
\r
260 $old_date = $new_date;
\r
264 $parser->parse($template['ITEM_HEADER']);
\r
265 $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item));
\r
266 $parser->parse($template['ITEM']);
\r
267 $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item));
\r
268 $parser->parse($template['ITEM_FOOTER']);
\r
271 $numrows = $items->rowCount();
\r
273 // add another date footer if there was at least one item
\r
274 if ( ($numrows > 0) && $dateheads )
\r
276 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
\r
277 $parser->parse($template['DATE_FOOTER']);
\r
278 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
\r
281 $items->closeCursor();
\r
286 * Blog::showOneitem()
\r
287 * Simplified function for showing only one item
\r
289 * @param integer $itemid ID for item
\r
290 * @param array $template template for item
\r
291 * @param string $highlight string for highlight
\r
292 * @return integer 1
\r
294 public function showOneitem($itemid, $template, $highlight)
\r
296 $extraQuery = ' and inumber=' . intval($itemid);
\r
298 return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0);
\r
303 * Adds an item to this blog
\r
305 * @param integer $catid ID for category
\r
306 * @param string $title ID for
\r
307 * @param string $body text for body
\r
308 * @param string $more text for more
\r
309 * @param integer $blogid ID for blog
\r
310 * @param integer $authorid ID for author
\r
311 * @param timestamp $timestamp UNIX timestamp for post
\r
312 * @param boolean $closed opened or closed
\r
313 * @param boolean $draft draft or not
\r
314 * @param boolean $posted posted or not
\r
315 * @return integer ID for added item
\r
317 function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1')
\r
321 $blogid = (integer) $blogid;
\r
322 $authorid = (integer) $authorid;
\r
326 $catid = intval($catid);
\r
328 // convert newlines to <br />
\r
329 if ( $this->convertBreaks() )
\r
331 $body = addBreaks($body);
\r
332 $more = addBreaks($more);
\r
335 if ( $closed != '1' )
\r
339 if ( $draft != '0' )
\r
344 if ( !$this->isValidCategory($catid) )
\r
346 $catid = $this->getDefaultCategory();
\r
350 if ( $timestamp > $this->getCorrectTime() )
\r
355 $timestamp = date('Y-m-d H:i:s',$timestamp);
\r
357 $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid));
\r
359 $ititle = DB::quoteValue($title);
\r
360 $ibody = DB::quoteValue($body);
\r
361 $imore = DB::quoteValue($more);
\r
362 $timestamp = DB::formatDateTime(strtotime($timestamp));
\r
364 $query = "INSERT INTO %s (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) VALUES (%s, %s, %s, %d, %d, %s, %s, %s, %s, %s)";
\r
365 $query = sprintf($query, sql_table('item'), $ititle, $ibody, $imore, $blogid, $authorid, $timestamp, $closed, $draft, $catid, $posted);
\r
366 DB::execute($query);
\r
367 $itemid = DB::getInsertId();
\r
369 $manager->notify('PostAddItem',array('itemid' => $itemid));
\r
373 $this->updateUpdateFile();
\r
375 // send notification mail
\r
376 if ( !$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem() )
\r
378 $this->sendNewItemNotification($itemid, $title, $body);
\r
384 * Blog::sendNewItemNotification()
\r
385 * Send a new item notification to the notification list
\r
387 * @param string $itemid ID of the item
\r
388 * @param string $title title of the item
\r
389 * @param string $body body of the item
\r
392 public function sendNewItemNotification($itemid, $title, $body)
\r
394 global $CONF, $member;
\r
396 $ascii = Entity::anchor_footnoting($body);
\r
398 $message = _NOTIFY_NI_MSG . " \n";
\r
399 $temp = parse_url($CONF['Self']);
\r
400 if ( $temp['scheme'] )
\r
402 $message .= Link::create_item_link($itemid) . "\n\n";
\r
406 $tempurl = $this->getURL();
\r
407 if ( i18n::substr($tempurl, -1) == '/' || i18n::substr($tempurl, -4) == '.php' )
\r
409 $message .= $tempurl . '?itemid=' . $itemid . "\n\n";
\r
413 $message .= $tempurl . '/?itemid=' . $itemid . "\n\n";
\r
416 $message .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";
\r
417 $message .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";
\r
418 $message .= NOTIFICATION::get_mail_footer();
\r
420 $subject = $this->getName() . ': ' . _NOTIFY_NI_TITLE;
\r
422 $from = $member->getNotifyFromMailAddress();
\r
424 NOTIFICATION::mail($this->getNotifyAddress(), $subject, $message, $from, i18n::get_current_charset());
\r
429 * Blog::createNewCategory()
\r
430 * Creates a new category for this blog
\r
432 * @param string $catName name of the new category. When empty, a name is generated automatically (starting with newcat)
\r
433 * @param string $catDescription description of the new category. Defaults to 'New Category'
\r
434 * @return integer ID for new category on success. 0 on failure
\r
436 public function createNewCategory($catName = '', $catDescription = _CREATED_NEW_CATEGORY_DESC)
\r
438 global $member, $manager;
\r
440 if ( !$member->blogAdminRights($this->blogid) )
\r
446 if ( $catName == '' )
\r
448 $catName = _CREATED_NEW_CATEGORY_NAME;
\r
451 $res = DB::getResult('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->blogid);
\r
452 while ( $res->rowCount() > 0 )
\r
455 $res = DB::getResult('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->blogid);
\r
458 $catName = $catName . $i;
\r
463 'name' => &$catName,
\r
464 'description' => $catDescription
\r
466 $manager->notify('PreAddCategory', $data);
\r
468 $query = "INSERT INTO %s (cblog, cname, cdesc) VALUES (%d, %s, %s)";
\r
469 $query = sprintf($query, sql_table('category'), (integer) $this->blogid, DB::quoteValue($catName), DB::quoteValue($catDescription));
\r
470 DB::execute($query);
\r
471 $catid = DB::getInsertId();
\r
475 'name' => $catName,
\r
476 'description' => $catDescription,
\r
479 $manager->notify('PostAddCategory', $data);
\r
486 * Searches all months of this blog for the given query
\r
488 * @param string $query search query
\r
489 * @param array $template template to be used (__NAME__ of the template)
\r
490 * @param integer $amountMonths max amount of months to be search (0 = all)
\r
491 * @param integer $maxresults max number of results to show
\r
492 * @param integer $startpos offset
\r
493 * @return amount of hits found
\r
495 public function search($query, $template, $amountMonths, $maxresults, $startpos) {
\r
496 global $CONF, $manager;
\r
499 $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight);
\r
501 if ( $sqlquery == '' )
\r
503 // no query -> show everything
\r
505 $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1);
\r
509 // add LIMIT to query (to split search results into pages)
\r
510 if ( intval($maxresults > 0) )
\r
512 $sqlquery .= ' LIMIT ' . intval($startpos) . ',' . intval($maxresults);
\r
516 $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1);
\r
518 // when no results were found, show a message
\r
519 if ( $amountfound == 0 )
\r
521 $template =& $manager->getTemplate($template);
\r
523 'query' => Entity::hsc($query),
\r
524 'blogid' => $this->blogid
\r
526 echo Template::fill($template['SEARCH_NOTHINGFOUND'], $vars);
\r
529 return $amountfound;
\r
533 * Blog::getSqlSearch()
\r
534 * Returns an SQL query to use for a search query
\r
535 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
\r
537 * @param string $query search query
\r
538 * @param integer $amountMonths amount of months to search back. Default = 0 = unlimited
\r
539 * @param string $mode either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
\r
540 * @return string $highlight words to highlight (out parameter)
\r
541 * @return string either a full SQL query, or an empty string (if querystring empty)
\r
543 public function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')
\r
545 $searchclass = new Search($query);
\r
547 $highlight = $searchclass->inclusive;
\r
549 // if querystring is empty, return empty string
\r
550 if ( $searchclass->inclusive == '' )
\r
555 $where = $searchclass->boolean_sql_where('ititle,ibody,imore');
\r
556 $select = $searchclass->boolean_sql_select('ititle,ibody,imore');
\r
558 // get list of blogs to search
\r
559 $blogs = $searchclass->blogs; // array containing blogs that always need to be included
\r
560 $blogs[] = $this->blogid; // also search current blog (duh)
\r
561 $blogs = array_unique($blogs); // remove duplicates
\r
563 if ( count($blogs) > 0 )
\r
565 $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';
\r
570 $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, i.itime, i.imore as more, i.icat as catid, i.iclosed as closed,
\r
571 m.mname as author, m.mrealname as authorname, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl,
\r
572 c.cname as category';
\r
576 $query .= ', '.$select. ' as score ';
\r
581 $query = 'SELECT COUNT(*) as result ';
\r
584 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
\r
585 . ' WHERE i.iauthor=m.mnumber'
\r
586 . ' and i.icat=c.catid'
\r
588 . ' and i.idraft=0'
\r
590 // don't show future items
\r
591 . ' and i.itime<=' . DB::formatDateTime($this->getCorrectTime())
\r
594 // take into account amount of months to search
\r
595 if ( $amountMonths > 0 )
\r
597 $localtime = getdate($this->getCorrectTime());
\r
598 $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);
\r
599 $query .= ' and i.itime>' . DB::formatDateTime($timestamp_start);
\r
606 $query .= ' ORDER BY score DESC';
\r
610 $query .= ' ORDER BY i.itime DESC ';
\r
618 * Blog::getSqlBlog()
\r
619 * Returns the SQL query that's normally used to display the blog items on the index type skins
\r
620 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
\r
622 * @param string $extraQuery extra query string
\r
623 * @param string $mode either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
\r
624 * @return string either a full SQL query, or an empty string
\r
626 public function getSqlBlog($extraQuery, $mode = '')
\r
630 $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author,
\r
631 m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail,
\r
632 m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';
\r
636 $query = 'SELECT COUNT(*) as result ';
\r
639 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
\r
640 . ' WHERE i.iblog='.$this->blogid
\r
641 . ' and i.iauthor=m.mnumber'
\r
642 . ' and i.icat=c.catid'
\r
643 . ' and i.idraft=0' // exclude drafts
\r
644 . ' and i.itime<=' . DB::formatDateTime($this->getCorrectTime()); // don't show future items
\r
646 if ( $this->selectedcatid )
\r
648 $query .= ' and i.icat=' . $this->selectedcatid . ' ';
\r
651 $query .= $extraQuery;
\r
655 $query .= ' ORDER BY i.itime DESC';
\r
661 * Blog::showArchiveList()
\r
662 * Shows the archivelist using the given template
\r
664 * @param string $template template name
\r
665 * @param string $mode year/month/day
\r
666 * @param integer $limit limit of record count
\r
669 public function showArchiveList($template, $mode = 'month', $limit = 0)
\r
671 global $CONF, $catid, $manager;
\r
673 if ( !isset ($linkparams) )
\r
675 $linkparams = array();
\r
680 $linkparams = array('catid' => $catid);
\r
683 $template =& $manager->getTemplate($template);
\r
684 $data['blogid'] = $this->blogid;
\r
686 if ( !array_key_exists('ARCHIVELIST_HEADER', $template) || !$template['ARCHIVELIST_HEADER'] )
\r
692 $tplt = $template['ARCHIVELIST_HEADER'];
\r
695 echo Template::fill($tplt, $data);
\r
697 $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) AS Day'
\r
698 . ' FROM '.sql_table('item')
\r
699 . ' WHERE iblog=' . $this->blogid
\r
700 . ' AND itime <=' . DB::formatDateTime($this->getCorrectTime()) // don't show future items!
\r
701 . ' AND idraft=0'; // don't show draft items
\r
705 $query .= ' and icat=' . intval($catid);
\r
708 $query .= ' GROUP BY Year';
\r
709 if ( $mode == 'month' || $mode == 'day' )
\r
711 $query .= ', Month';
\r
713 if ( $mode == 'day' )
\r
718 $query .= ' ORDER BY itime DESC';
\r
722 $query .= ' LIMIT ' . intval($limit);
\r
725 $res = DB::getResult($query);
\r
726 foreach ( $res as $current )
\r
728 /* string time -> unix timestamp */
\r
729 $current['itime'] = strtotime($current['itime']);
\r
731 if ( $mode == 'day' )
\r
733 $archivedate = date('Y-m-d',$current['itime']);
\r
734 $archive['day'] = date('d',$current['itime']);
\r
735 $data['day'] = date('d',$current['itime']);
\r
736 $data['month'] = date('m',$current['itime']);
\r
737 $archive['month'] = $data['month'];
\r
739 elseif ( $mode == 'year' )
\r
741 $archivedate = date('Y',$current['itime']);
\r
743 $data['month'] = '';
\r
744 $archive['day'] = '';
\r
745 $archive['month'] = '';
\r
749 $archivedate = date('Y-m',$current['itime']);
\r
750 $data['month'] = date('m',$current['itime']);
\r
751 $archive['month'] = $data['month'];
\r
753 $archive['day'] = '';
\r
756 $data['year'] = date('Y',$current['itime']);
\r
757 $archive['year'] = $data['year'];
\r
758 $data['archivelink'] = Link::create_archive_link($this->blogid,$archivedate,$linkparams);
\r
760 $manager->notify('PreArchiveListItem', array('listitem' => &$data));
\r
762 $temp = Template::fill($template['ARCHIVELIST_LISTITEM'],$data);
\r
763 echo i18n::formatted_datetime($temp, $current['itime']);
\r
767 $res->closeCursor();
\r
769 if ( !array_key_exists('ARCHIVELIST_FOOTER', $template) || !$template['ARCHIVELIST_FOOTER'] )
\r
775 $tplt = $template['ARCHIVELIST_FOOTER'];
\r
778 echo Template::fill($tplt, $data);
\r
783 * Blog::showCategoryList()
\r
784 * Shows the list of categories using a given template
\r
786 * @param string $template Template Name
\r
789 public function showCategoryList($template)
\r
791 global $CONF, $archive, $archivelist, $manager;
\r
794 * determine arguments next to catids
\r
795 * I guess this can be done in a better way, but it works
\r
797 $linkparams = array();
\r
800 $blogurl = Link::create_archive_link($this->blogid, $archive, '');
\r
801 $linkparams['blogid'] = $this->blogid;
\r
802 $linkparams['archive'] = $archive;
\r
804 else if ( $archivelist )
\r
806 $blogurl = Link::create_archivelist_link($this->blogid, '');
\r
807 $linkparams['archivelist'] = $archivelist;
\r
811 $blogurl = Link::create_blogid_link($this->blogid, '');
\r
812 $linkparams['blogid'] = $this->blogid;
\r
815 $template =& $manager->getTemplate($template);
\r
817 //: Change: Set nocatselected variable
\r
818 if ( $this->selectedcatid )
\r
820 $nocatselected = 'no';
\r
824 $nocatselected = 'yes';
\r
828 'blogid' => $this->blogid,
\r
829 'blogurl' => $blogurl,
\r
830 'self' => $CONF['Self'],
\r
831 'catiscurrent' => $nocatselected, // Change: Set catiscurrent template variable for header
\r
832 'currentcat' => $nocatselected
\r
835 /* output header of category list item */
\r
836 if ( !array_key_exists('CATLIST_HEADER', $template) || empty($template['CATLIST_HEADER']) )
\r
838 echo Template::fill(NULL, $args);
\r
842 echo Template::fill($template['CATLIST_HEADER'], $args);
\r
845 $query = "SELECT catid, cdesc as catdesc, cname as catname FROM %s WHERE cblog=%d ORDER BY cname ASC;";
\r
846 $query = sprintf($query, sql_table('category'), (integer) $this->blogid);
\r
847 $res = DB::getResult($query);
\r
849 foreach ( $res as $data )
\r
852 'catid' => $data['catid'],
\r
853 'name' => $data['catname'],
\r
854 'extra' => $linkparams
\r
857 $data['blogid'] = $this->blogid;
\r
858 $data['blogurl'] = $blogurl;
\r
859 $data['catlink'] = Link::create_link('category', $args);
\r
860 $data['self'] = $CONF['Self'];
\r
862 // this gives catiscurrent = no when no category is selected.
\r
863 $data['catiscurrent'] = 'no';
\r
864 $data['currentcat'] = 'no';
\r
866 if ( $this->selectedcatid )
\r
868 if ( $this->selectedcatid == $data['catid'] )
\r
870 $data['catiscurrent'] = 'yes';
\r
871 $data['currentcat'] = 'yes';
\r
877 if ( (integer) $itemid && $manager->existsItem((integer) $itemid, 0, 0) )
\r
879 $iobj =& $manager->getItem($itemid, 0, 0);
\r
880 $cid = $iobj['catid'];
\r
882 if ( $cid == $data['catid'] )
\r
884 $data['catiscurrent'] = 'yes';
\r
885 $data['currentcat'] = 'yes';
\r
890 $manager->notify('PreCategoryListItem', array('listitem' => &$data));
\r
892 if ( !array_key_exists('CATLIST_LISTITEM', $template) || empty($template['CATLIST_LISTITEM']))
\r
894 echo Template::fill(NULL, $data);
\r
898 echo Template::fill($template['CATLIST_LISTITEM'], $data);
\r
902 $res->closeCursor();
\r
905 'blogid' => $this->blogid,
\r
906 'blogurl' => $blogurl,
\r
907 'self' => $CONF['Self'],
\r
908 'catiscurrent' => $nocatselected, //: Change: Set catiscurrent template variable for footer
\r
909 'currentcat' => $nocatselected
\r
912 if ( !array_key_exists('CATLIST_FOOTER', $template) || empty($template['CATLIST_FOOTER']))
\r
914 echo Template::fill(NULL, $args);
\r
918 echo Template::fill($template['CATLIST_FOOTER'], $args);
\r
925 * Blog::showBlogList()
\r
926 * Shows a list of all blogs in the system using a given template
\r
927 * ordered by number, name, shortname or description
\r
928 * in ascending or descending order
\r
930 * @param string $template tempalte name
\r
931 * @param string $bnametype bname/bshortname
\r
932 * @param string $orderby string for 'ORDER BY' SQL
\r
933 * @param string $direction ASC/DESC
\r
936 public function showBlogList($template, $bnametype, $orderby, $direction)
\r
938 global $CONF, $manager;
\r
940 switch ( $orderby )
\r
943 $orderby='bnumber';
\r
949 $orderby='bshortname';
\r
951 case 'description':
\r
955 $orderby='bnumber';
\r
959 $direction=strtolower($direction);
\r
960 switch ( $direction )
\r
973 $template =& $manager->getTemplate($template);
\r
975 if ( array_key_exists('BLOGLIST_HEADER', $template) && !empty($template['BLOGLIST_HEADER']) )
\r
978 'sitename' => $CONF['SiteName'],
\r
979 'siteurl' => $CONF['IndexURL']
\r
982 echo Template::fill($template['BLOGLIST_HEADER'], $vars);
\r
985 if ( array_key_exists('BLOGLIST_LISTITEM', $template) && !empty($template['BLOGLIST_LISTITEM']) )
\r
987 $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY '.$orderby.' '.$direction;
\r
988 $res = DB::getResult($query);
\r
990 foreach ( $res as $data )
\r
993 $list['bloglink'] = Link::create_blogid_link($data['bnumber']);
\r
994 $list['blogdesc'] = $data['bdesc'];
\r
995 $list['blogurl'] = $data['burl'];
\r
997 if ( $bnametype == 'shortname' )
\r
999 $list['blogname'] = $data['bshortname'];
\r
1003 /* all other cases */
\r
1004 $list['blogname'] = $data['bname'];
\r
1007 $manager->notify('PreBlogListItem',array('listitem' => &$list));
\r
1009 echo Template::fill($template['BLOGLIST_LISTITEM'], $list);
\r
1012 $res->closeCursor();
\r
1016 if ( array_key_exists('BLOGLIST_FOOTER', $template) && !empty($template['BLOGLIST_FOOTER']) )
\r
1019 'sitename' => $CONF['SiteName'],
\r
1020 'siteurl' => $CONF['IndexURL']
\r
1022 echo Template::fill($template['BLOGLIST_FOOTER']);
\r
1028 * Blog::readSettings()
\r
1029 * Read the blog settings
\r
1034 public function readSettings()
\r
1036 $query = 'SELECT * FROM %s WHERE bnumber=%d;';
\r
1037 $query = sprintf($query, sql_table('blog'), (integer) $this->blogid);
\r
1038 $res = DB::getResult($query);
\r
1040 $this->isValid = ($res->rowCount() > 0);
\r
1041 if ( $this->isValid )
\r
1043 $this->settings = $res->fetch(PDO::FETCH_ASSOC);
\r
1049 * Blog::writeSettings()
\r
1050 * Write the blog settings
\r
1052 public function writeSettings()
\r
1054 // (can't use floatval since not available prior to PHP 4.2)
\r
1055 $offset = $this->getTimeOffset();
\r
1056 if ( !is_float($offset) )
\r
1058 $offset = (integer) $offset;
\r
1061 $query = 'UPDATE '.sql_table('blog')
\r
1062 . ' SET bname=' . DB::quoteValue($this->getName()) . ','
\r
1063 . ' bshortname='. DB::quoteValue($this->getShortName()) . ','
\r
1064 . ' bcomments='. intval($this->commentsEnabled()) . ','
\r
1065 . ' bmaxcomments=' . intval($this->getMaxComments()) . ','
\r
1066 . ' btimeoffset=' . $offset . ','
\r
1067 . ' bpublic=' . intval($this->isPublic()) . ','
\r
1068 . ' breqemail=' . intval($this->emailRequired()) . ','
\r
1069 . ' bconvertbreaks=' . intval($this->convertBreaks()) . ','
\r
1070 . ' ballowpast=' . intval($this->allowPastPosting()) . ','
\r
1071 . ' bnotify=' . DB::quoteValue($this->getNotifyAddress()) . ','
\r
1072 . ' bnotifytype=' . intval($this->getNotifyType()) . ','
\r
1073 . ' burl=' . DB::quoteValue($this->getURL()) . ','
\r
1074 . ' bupdate=' . DB::quoteValue($this->getUpdateFile()) . ','
\r
1075 . ' bdesc=' . DB::quoteValue($this->getDescription()) . ','
\r
1076 . ' bdefcat=' . intval($this->getDefaultCategory()) . ','
\r
1077 . ' bdefskin=' . intval($this->getDefaultSkin()) . ','
\r
1078 . ' bincludesearch=' . intval($this->getSearchable())
\r
1079 . ' WHERE bnumber=' . intval($this->blogid);
\r
1080 DB::execute($query);
\r
1085 * Blog::updateUpdatefile()
\r
1086 * Update the update file if requested
\r
1091 public function updateUpdatefile()
\r
1093 if ( $this->getUpdateFile() )
\r
1095 $f_update = fopen($this->getUpdateFile(), 'w');
\r
1096 fputs($f_update,$this->getCorrectTime());
\r
1097 fclose($f_update);
\r
1103 * Blog::isValidCategory()
\r
1104 * Check if a category with a given catid is valid
\r
1106 * @param integer $catid ID for category
\r
1107 * @return boolean exists or not
\r
1109 public function isValidCategory($catid)
\r
1111 $query = 'SELECT * FROM %s WHERE cblog=%d and catid=%d;';
\r
1112 $query = sprintf($query, sql_table('category'), (integer) $this->blogid, (integer) $catid);
\r
1113 $res = DB::getResult($query);
\r
1114 return ($res->rowCount() != 0);
\r
1118 * Blog::getCategoryName()
\r
1119 * Get the category name for a given catid
\r
1121 * @param integer $catid ID for category
\r
1122 * @return string name of category
\r
1124 public function getCategoryName($catid)
\r
1126 $query = 'SELECT cname FROM %s WHERE cblog=%d and catid=%d;';
\r
1127 $query = sprintf($query, sql_table('category'), (integer) $this->blogid, (integer) $catid);
\r
1128 $res = DB::getValue($query);
\r
1133 * Blog::getCategoryDesc()
\r
1134 * Get the category description for a given catid
\r
1139 public function getCategoryDesc($catid)
\r
1141 $query = 'SELECT cdesc FROM %s WHERE cblog=%d and catid=%d;';
\r
1142 $query = sprintf($querym, sql_table('category'), (integer) $this->blogid, (integer) $catid);
\r
1143 $res = DB::getValue();
\r
1148 * Blog::getCategoryIdFromName
\r
1149 * Get the category id for a given category name
\r
1151 * @param string $name category name
\r
1152 * @return ID for category
\r
1154 public function getCategoryIdFromName($name)
\r
1156 $query = 'SELECT catid FROM %s WHERE cblog=%d and cname=%s;';
\r
1157 $query = sprintf($query, sql_table('category'), (integer) $this->blogid, DB::quoteValue($name));
\r
1159 $res = DB::getValue();
\r
1162 return $this->getDefaultCategory();
\r
1168 * Blog::insertJavaScriptInfo()
\r
1169 * Insert a javascript that includes information about the settings
\r
1170 * of an author: ConvertBreaks, MediaUrl and AuthorId
\r
1172 * @param $authorid id of the author
\r
1174 public function insertJavaScriptInfo($authorid = '')
\r
1176 global $member, $CONF;
\r
1178 if ( $authorid == '' )
\r
1180 $authorid = $member->getID();
\r
1183 echo "<script type=\"text/javascript\">\n";
\r
1185 if ( !$this->convertBreaks() )
\r
1187 echo "setConvertBreaks(false);\n";
\r
1191 echo "setConvertBreaks(true);\n";
\r
1193 echo "setMediaUrl('{$CONF['MediaURL']}');\n";
\r
1194 echo "setAuthorId('{$authorid}');\n";
\r
1195 echo "</script>\n";
\r
1200 * Blog::setAllowPastPosting()
\r
1201 * Set the the setting for allowing to publish postings in the past
\r
1203 * @param boolean $val new value for ballowpast
\r
1206 public function setAllowPastPosting($val)
\r
1208 $this->setSetting('ballowpast', $val);
\r
1213 * Blog::allowPastPosting()
\r
1214 * Get the the setting if it is allowed to publish postings in the past
\r
1215 * [should be named as getAllowPastPosting()]
\r
1220 public function allowPastPosting()
\r
1222 return $this->getSetting('ballowpast');
\r
1226 * Blog::getCorrectTime()
\r
1228 * @param integer $t
\r
1231 public function getCorrectTime($t=0)
\r
1237 return ($t + 3600 * $this->getTimeOffset());
\r
1244 * @return string name of this weblog
\r
1246 public function getName()
\r
1248 return $this->getSetting('bname');
\r
1252 * Blog::getShortName()
\r
1255 * @return string short name of this weblog
\r
1257 public function getShortName()
\r
1259 return $this->getSetting('bshortname');
\r
1263 * Blog::getMaxComments()
\r
1266 * @return integer maximum number of comments
\r
1268 public function getMaxComments()
\r
1270 return $this->getSetting('bmaxcomments');
\r
1274 * Blog::getNotifyAddress()
\r
1277 * @return string mail address for notifying
\r
1279 public function getNotifyAddress()
\r
1281 return $this->getSetting('bnotify');
\r
1285 * Blog::getNotifyType()
\r
1288 * @return integer notifycation type
\r
1290 public function getNotifyType()
\r
1292 return $this->getSetting('bnotifytype');
\r
1296 * Blog::notifyOnComment()
\r
1301 public function notifyOnComment()
\r
1303 $n = $this->getNotifyType();
\r
1304 return (($n != 0) && (($n % 3) == 0));
\r
1308 * Blog::notifyOnVote()
\r
1313 public function notifyOnVote()
\r
1315 $n = $this->getNotifyType();
\r
1316 return (($n != 0) && (($n % 5) == 0));
\r
1320 * Blog::notifyOnNewItem()
\r
1325 public function notifyOnNewItem()
\r
1327 $n = $this->getNotifyType();
\r
1328 return (($n != 0) && (($n % 7) == 0));
\r
1332 * Blog::setNotifyType()
\r
1334 * @param integer $val
\r
1337 public function setNotifyType($val)
\r
1339 $this->setSetting('bnotifytype',$val);
\r
1344 * Blog::getTimeOffset()
\r
1348 public function getTimeOffset()
\r
1350 return $this->getSetting('btimeoffset');
\r
1354 * Blog::commentsEnabled()
\r
1356 * @return integer enabled or not
\r
1358 public function commentsEnabled()
\r
1360 return $this->getSetting('bcomments');
\r
1366 * @return string URI for this weblog
\r
1368 public function getURL()
\r
1370 return $this->getSetting('burl');
\r
1374 * Blog::getDefaultSkin()
\r
1376 * @return name of skin as default for this weblog
\r
1378 public function getDefaultSkin()
\r
1380 return $this->getSetting('bdefskin');
\r
1384 * Blog::getUpdateFile()
\r
1386 * @return string name of file to be updated when weblog is updated
\r
1388 public function getUpdateFile()
\r
1390 return $this->getSetting('bupdate');
\r
1394 * Blog::getDescription()
\r
1396 * @return string description for this weblog
\r
1398 public function getDescription()
\r
1400 return $this->getSetting('bdesc');
\r
1404 * Blog::isPublic()
\r
1406 * @return integer publlic or not
\r
1408 public function isPublic()
\r
1410 return $this->getSetting('bpublic');
\r
1414 * Blog::emailRequired()
\r
1416 * @return integer email is required when posting comment or not
\r
1418 public function emailRequired()
\r
1420 return $this->getSetting('breqemail');
\r
1424 * Blog::getSearchable()
\r
1426 * @return integer searchable or not
\r
1428 public function getSearchable()
\r
1430 return $this->getSetting('bincludesearch');
\r
1434 * Blog::getDefaultCategory()
\r
1436 * @return ID for category as a default
\r
1438 public function getDefaultCategory()
\r
1440 return $this->getSetting('bdefcat');
\r
1444 * Blog::setPublic()
\r
1445 * @param integer $val allow comments by non-registered members or not
\r
1448 public function setPublic($val)
\r
1450 $this->setSetting('bpublic', $val);
\r
1455 * Blog::setSearchable()
\r
1456 * @param integer $val searchable from the other blogs or not
\r
1459 public function setSearchable($val)
\r
1461 $this->setSetting('bincludesearch', $val);
\r
1466 * Blog::setDescription
\r
1467 * @param string $val description for this weblog
\r
1470 public function setDescription($val)
\r
1472 $this->setSetting('bdesc',$val);
\r
1477 * Blog::setUpdateFile()
\r
1478 * @param string $val name of file to beupdated when weblog is updated
\r
1481 public function setUpdateFile($val)
\r
1483 $this->setSetting('bupdate',$val);
\r
1488 * Blog::setDefaultSkin()
\r
1489 * @param integer $val ID for default skin to use when displaying this weblog
\r
1492 public function setDefaultSkin($val)
\r
1494 $this->setSetting('bdefskin', $val);
\r
1500 * @param string $val URI for this weblog
\r
1503 public function setURL($val)
\r
1505 $this->setSetting('burl', $val);
\r
1511 * @param string $val name of this weblog
\r
1514 public function setName($val)
\r
1516 $this->setSetting('bname', $val);
\r
1521 * Blog::setShortName()
\r
1522 * @param string $val short name for this weblog
\r
1525 public function setShortName($val)
\r
1527 $this->setSetting('bshortname', $val);
\r
1532 * Blog::setCommentsEnabled()
\r
1533 * @param integer $val enabling posting comment or not
\r
1536 public function setCommentsEnabled($val)
\r
1538 $this->setSetting('bcomments',$val);
\r
1543 * Blog::setMaxComments()
\r
1544 * @param integer $val maximum number of comments for this weblog
\r
1547 public function setMaxComments($val)
\r
1549 $this->setSetting('bmaxcomments', $val);
\r
1554 * Blog::setNotifyAddress()
\r
1555 * @param string $val email to be notified if weblog updated
\r
1558 public function setNotifyAddress($val)
\r
1560 $this->setSetting('bnotify', $val);
\r
1565 * Blog::setEmailRequired()
\r
1566 * @param string requiring comments with email or not from non member
\r
1569 public function setEmailRequired($val)
\r
1571 $this->setSetting('breqemail', $val);
\r
1576 * Blog::setTimeOffset()
\r
1577 * @param integer $val time offset
\r
1580 public function setTimeOffset($val)
\r
1582 // check validity of value
\r
1583 // 1. replace , by . (common mistake)
\r
1584 $val = str_replace(',','.',$val);
\r
1586 // 2. cast to float or int
\r
1587 if ( is_numeric($val) && (i18n::strpos($val, '.5') === (i18n::strlen($val) - 2)) )
\r
1589 $val = (float) $val;
\r
1593 $val = (integer) $val;
\r
1596 $this->setSetting('btimeoffset',$val);
\r
1601 * Blog::setDefaultCategory()
\r
1602 * @param integer $val ID for default category for this weblog
\r
1605 public function setDefaultCategory($val)
\r
1607 $this->setSetting('bdefcat',$val);
\r
1612 * Blog::getSetting()
\r
1613 * @param string $key key for setting of this weblog
\r
1614 * @return mixed value for the setting
\r
1616 public function getSetting($key)
\r
1618 return $this->settings[$key];
\r
1622 * Blog::setSetting()
\r
1623 * @param string $key key for setting of this weblog
\r
1624 * @param mixed $value value for the key
\r
1627 public function setSetting($key, $value)
\r
1629 $this->settings[$key] = $value;
\r
1634 * Blog::addTeamMember()
\r
1635 * Tries to add a member to the team.
\r
1636 * Returns false if the member was already on the team
\r
1638 * @param integer $memberid id for member
\r
1639 * @param boolean $admin super-admin or not
\r
1640 * @return boolean Success/Fail
\r
1642 public function addTeamMember($memberid, $admin)
\r
1646 $memberid = intval($memberid);
\r
1647 $admin = intval($admin);
\r
1649 // check if member is already a member
\r
1650 $tmem =& $manager->getMember($memberid);
\r
1652 if ( $tmem->isTeamMember($this->blogid) )
\r
1659 'member' => &$tmem,
\r
1660 'admin' => &$admin
\r
1662 $manager->notify('PreAddTeamMember', $data);
\r
1665 $query = "INSERT INTO %s (TMEMBER, TBLOG, TADMIN) VALUES (%d, %d, %d);";
\r
1666 $query = sprintf($query, sql_table('team'), (integer) $memberid, (integer) $this->blogid, (integer) $admin);
\r
1667 DB::execute($query);
\r
1671 'member' => &$tmem,
\r
1674 $manager->notify('PostAddTeamMember', $data);
\r
1676 $logMsg = sprintf(_TEAM_ADD_NEWTEAMMEMBER, $tmem->getDisplayName(), $memberid, $this->getName());
\r
1677 ActionLog::add(INFO, $logMsg);
\r
1685 * @return integer ID for this weblog
\r
1687 public function getID()
\r
1689 return (integer) $this->blogid;
\r
1693 * Checks if a blog with a given shortname exists
\r
1694 * Returns true if there is a blog with the given shortname (static)
\r
1696 * @param string $name blog shortname
\r
1697 * @return boolean exists or not
\r
1699 public function exists($name)
\r
1701 $r = DB::getResult('SELECT * FROM '.sql_table('blog').' WHERE bshortname='. DB::quoteValue($name));
\r
1702 return ($r->rowCount() != 0);
\r
1706 * Checks if a blog with a given id exists
\r
1707 * Returns true if there is a blog with the given ID (static)
\r
1709 * @param integer $id ID for searched weblog
\r
1710 * @return boolean exists or not
\r
1712 public function existsID($id)
\r
1714 $r = DB::getResult('SELECT * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));
\r
1715 return ($r->rowCount() != 0);
\r
1719 * Blog::setFuturePost()
\r
1720 * flag there is a future post pending
\r
1725 public function setFuturePost()
\r
1727 $query = "UPDATE %s SET bfuturepost='1' WHERE bnumber=%d;";
\r
1728 $query = sprintf($query, sql_table('blog'), (integer) $this->blogid);
\r
1729 DB::execute($query);
\r
1734 * Blog::clearFuturePost()
\r
1735 * clear there is a future post pending
\r
1740 public function clearFuturePost()
\r
1742 $query = "UPDATE %s SET bfuturepost='0' WHERE bnumber=%d;";
\r
1743 $query = sprintf($query, sql_table('blog'), (integer) $this->blogid);
\r
1744 DB::execute($query);
\r
1749 * Blog::checkJustPosted()
\r
1750 * check if we should throw justPosted event
\r
1755 public function checkJustPosted()
\r
1759 if ( $this->settings['bfuturepost'] == 1 )
\r
1761 $query = "SELECT * FROM %s WHERE iposted=0 AND iblog=%d AND itime < NOW();";
\r
1762 $query = sprintf($query, sql_table('item'), (integer) $this->blogid);
\r
1764 $result = DB::getResult($query);
\r
1765 if ( $result->rowCount() > 0 )
\r
1767 // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already
\r
1768 // Note that the plugins's calling order is subject to thri order in the plugin list
\r
1770 $manager->notify('JustPosted', array('blogid' => $this->blogid, 'pinged' => &$pinged));
\r
1772 // clear all expired future posts
\r
1773 $query = "UPDATE %s SET iposted='1' WHERE iblog=%d AND itime < NOW();";
\r
1774 $query = spriintf($query, sql_table('item'), (integer) $this->blogid);
\r
1775 DB::execute($query);
\r
1777 // check to see any pending future post, clear the flag is none
\r
1778 $query = "SELECT * FROM %s WHERE iposted=0 AND iblog=%d;";
\r
1779 $query = sprintf($query, sql_table('item'), (integer) $this->blogid);
\r
1781 $result = DB::getResult($query);
\r
1782 if ( $result->rowCount() == 0 )
\r
1784 $this->clearFuturePost();
\r
1792 * Blog::readLogFromList()
\r
1793 * Shows the given list of items for this blog
\r
1795 * @param array $itemarray array of item numbers to be displayed
\r
1796 * @param string $template string representing the template _NAME_ (!)
\r
1797 * @param string $highlight contains a query that should be highlighted
\r
1798 * @param boolean $comments 1=show comments 0=don't show comments
\r
1799 * @param boolean $dateheads 1=show dateheads 0=don't show dateheads
\r
1800 * @param boolean $showDrafts 0=do not show drafts 1=show drafts
\r
1801 * @param boolean $showFuture 0=do not show future posts 1=show future posts
\r
1802 * @return integer amount of items shown
\r
1804 public function readLogFromList($itemarray, $template, $highlight = '', $comments = 1, $dateheads = 1,$showDrafts = 0, $showFuture = 0)
\r
1806 $query = $this->getSqlItemList($itemarray,$showDrafts,$showFuture);
\r
1807 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
\r
1811 * Blog::getSqlItemList()
\r
1812 * Returns the SQL query used to fill out templates for a list of items
\r
1813 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
\r
1815 * @param array $itemarray an array holding the item numbers of the items to be displayed
\r
1816 * @param integer $showDrafts 0=do not show drafts 1=show drafts
\r
1817 * @param integer $showFuture 0=do not show future posts 1=show future posts
\r
1818 * @return string either a full SQL query, or an empty string
\r
1820 public function getSqlItemList($itemarray,$showDrafts = 0,$showFuture = 0)
\r
1822 if ( !is_array($itemarray) )
\r
1827 $showDrafts = intval($showDrafts);
\r
1828 $showFuture = intval($showFuture);
\r
1831 foreach ( $itemarray as $value )
\r
1833 if ( intval($value) )
\r
1835 $items[] = intval($value);
\r
1838 if ( !count($items) )
\r
1843 $i = count($items);
\r
1845 foreach ( $items as $value )
\r
1849 . ' i.inumber as itemid,'
\r
1850 . ' i.ititle as title,'
\r
1851 . ' i.ibody as body,'
\r
1852 . ' m.mname as author,'
\r
1853 . ' m.mrealname as authorname,'
\r
1855 . ' i.imore as more,'
\r
1856 . ' m.mnumber as authorid,'
\r
1857 . ' m.memail as authormail,'
\r
1858 . ' m.murl as authorurl,'
\r
1859 . ' c.cname as category,'
\r
1860 . ' i.icat as catid,'
\r
1861 . ' i.iclosed as closed';
\r
1863 $query .= ' FROM '
\r
1864 . sql_table('item') . ' as i, '
\r
1865 . sql_table('member') . ' as m, '
\r
1866 . sql_table('category') . ' as c'
\r
1868 . ' i.iblog='.$this->blogid
\r
1869 . ' and i.iauthor=m.mnumber'
\r
1870 . ' and i.icat=c.catid';
\r
1872 // exclude drafts
\r
1873 if ( !$showDrafts )
\r
1875 $query .= ' and i.idraft=0';
\r
1877 if ( !$showFuture )
\r
1879 // don't show future items
\r
1880 $query .= ' and i.itime<=' . DB::formatDateTime($this->getCorrectTime());
\r
1883 $query .= ' and i.inumber='.intval($value);
\r
1886 if ($i) $query .= ' UNION ';
\r
1893 * Blog::convertBreaks()
\r
1894 * Get the the setting for the line break handling
\r
1895 * [should be named as getConvertBreaks()]
\r
1901 public function convertBreaks()
\r
1903 return $this->getSetting('bconvertbreaks');
\r
1907 * Set the the setting for the line break handling
\r
1910 * @param boolean $val new value for bconvertbreaks
\r
1913 public function setConvertBreaks($val)
\r
1915 $this->setSetting('bconvertbreaks', $val);
\r