4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2009 The Nucleus Group
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)
14 * A class representing a blog and containing functions to get that blog shown
17 * @license http://nucleuscms.org/license.txt GNU General Public License
18 * @copyright Copyright (C) 2002-2009 The Nucleus Group
20 * $NucleusJP: BLOG.php,v 1.12.2.2 2007/08/08 05:26:22 kimitake Exp $
23 if ( !function_exists('requestVar') ) exit;
24 require_once dirname(__FILE__) . '/ITEMACTIONS.php';
31 // ID of currently selected category
34 // After creating an object of the blog class, contains true if the BLOG object is
35 // valid (the blog exists)
38 // associative array, containing all blogsettings (use the get/set functions instead)
42 * Creates a new BLOG object for the given blog
47 $this->blogid = intval($id);
48 $this->readSettings();
51 // (the parse functions in SKIN.php will override this, so it's mainly useless)
53 $this->setSelectedCategory($catid);
57 * Shows the given amount of items for this blog
60 * String representing the template _NAME_ (!)
61 * @param $amountEntries
62 * amount of entries to show
64 * offset from where items should be shown (e.g. 5 = start at fifth item)
66 * amount of items shown
68 function readLog($template, $amountEntries, $offset = 0, $startpos = 0) {
69 return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos);
73 * Shows an archive for a given month
80 * String representing the template name to be used
82 function showArchive($templatename, $year, $month, $day=0) {
84 // create extra where clause for select query
86 $timestamp_start = mktime(0,0,0,$month,1,$year);
87 $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12
89 $timestamp_start = mktime(0,0,0,$month,$day,$year);
90 $timestamp_end = mktime(0,0,0,$month,$day+1,$year);
92 $extra_query = ' and i.itime>=' . mysqldate($timestamp_start)
93 . ' and i.itime<' . mysqldate($timestamp_end);
96 $this->readLogAmount($templatename,0,$extra_query,'',1,1);
101 // sets/gets current category (only when category exists)
102 function setSelectedCategory($catid) {
103 if ($this->isValidCategory($catid) || (intval($catid) == 0))
104 $this->selectedcatid = intval($catid);
107 function setSelectedCategoryByName($catname) {
108 $this->setSelectedCategory($this->getCategoryIdFromName($catname));
111 function getSelectedCategory() {
112 return $this->selectedcatid;
116 * Shows the given amount of items for this blog
119 * String representing the template _NAME_ (!)
120 * @param $amountEntries
121 * amount of entries to show (0 = no limit)
123 * extra conditions to be added to the query
125 * contains a query that should be highlighted
127 * 1=show comments 0=don't show comments
129 * 1=show dateheads 0=don't show dateheads
133 * amount of items shown
135 function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) {
137 $query = $this->getSqlBlog($extraQuery);
139 if ($amountEntries > 0) {
140 // $offset zou moeten worden:
141 // (($startpos / $amountentries) + 1) * $offset ... later testen ...
142 $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries);
144 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
147 function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) {
148 global $CONF, $manager;
150 $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
152 $lastVisit = $this->getCorrectTime($lastVisit);
154 // set templatename as global variable (so plugins can access it)
155 global $currentTemplateName;
156 $currentTemplateName = $templateName;
158 $template =& $manager->getTemplate($templateName);
160 // create parser object & action handler
161 $actions =& new ITEMACTIONS($this);
162 $parser =& new PARSER($actions->getDefinedActions(),$actions);
163 $actions->setTemplate($template);
164 $actions->setHighlight($highlight);
165 $actions->setLastVisit($lastVisit);
166 $actions->setParser($parser);
167 $actions->setShowComments($comments);
170 $items = sql_query($query);
172 // loop over all items
174 while ($item = mysql_fetch_object($items)) {
176 $item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp
178 // action handler needs to know the item we're handling
179 $actions->setCurrentItem($item);
181 // add date header if needed
183 $new_date = date('dFY',$item->timestamp);
184 if ($new_date != $old_date) {
185 // unless this is the first time, write date footer
186 $timestamp = $item->timestamp;
187 if ($old_date != 0) {
188 $oldTS = strtotime($old_date);
189 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
190 $tmp_footer = strftime(isset($template['DATE_FOOTER'])?$template['DATE_FOOTER']:'', $oldTS);
191 $parser->parse($tmp_footer);
192 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
194 $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
195 // note, to use templatvars in the dateheader, the %-characters need to be doubled in
196 // order to be preserved by strftime
197 $tmp_header = strftime((isset($template['DATE_HEADER']) ? $template['DATE_HEADER'] : null), $timestamp);
198 $parser->parse($tmp_header);
199 $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
201 $old_date = $new_date;
205 $parser->parse($template['ITEM_HEADER']);
206 $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item));
207 $parser->parse($template['ITEM']);
208 $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item));
209 $parser->parse($template['ITEM_FOOTER']);
213 $numrows = mysql_num_rows($items);
215 // add another date footer if there was at least one item
216 if (($numrows > 0) && $dateheads) {
217 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
218 $parser->parse($template['DATE_FOOTER']);
219 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
222 mysql_free_result($items); // free memory
228 function showOneitem($itemid, $template, $highlight) {
229 $extraQuery = ' and inumber=' . intval($itemid);
231 return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0);
236 * Adds an item to this blog
238 function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1') {
241 $blogid = intval($blogid);
242 $authorid = intval($authorid);
246 $catid = intval($catid);
248 // convert newlines to <br />
249 if ($this->convertBreaks()) {
250 $body = addBreaks($body);
251 $more = addBreaks($more);
254 if ($closed != '1') $closed = '0';
255 if ($draft != '0') $draft = '1';
257 if (!$this->isValidCategory($catid))
258 $catid = $this->getDefaultCategory();
260 if ($timestamp > $this->getCorrectTime())
263 $timestamp = date('Y-m-d H:i:s',$timestamp);
265 $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid));
267 $title = addslashes($title);
268 $body = addslashes($body);
269 $more = addslashes($more);
271 $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) '
272 . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid, $posted)";
274 $itemid = mysql_insert_id();
276 $manager->notify('PostAddItem',array('itemid' => $itemid));
279 $this->updateUpdateFile();
281 // send notification mail
282 if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem())
283 $this->sendNewItemNotification($itemid, stripslashes($title), stripslashes($body));
288 function sendNewItemNotification($itemid, $title, $body) {
289 global $CONF, $member;
291 // create text version of html post
292 $ascii = toAscii($body);
294 $mailto_msg = _NOTIFY_NI_MSG . " \n";
295 // $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
296 $temp = parse_url($CONF['Self']);
297 if ($temp['scheme']) {
298 $mailto_msg .= createItemLink($itemid) . "\n\n";
300 $tempurl = $this->getURL();
301 if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') {
302 $mailto_msg .= $tempurl . '?itemid=' . $itemid . "\n\n";
304 $mailto_msg .= $tempurl . '/?itemid=' . $itemid . "\n\n";
307 $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";
308 $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";
309 $mailto_msg .= getMailFooter();
311 $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE;
313 $frommail = $member->getNotifyFromMailAddress();
315 $notify =& new NOTIFICATION($this->getNotifyAddress());
316 $notify->notify($mailto_title, $mailto_msg , $frommail);
324 * Creates a new category for this blog
327 * name of the new category. When empty, a name is generated automatically
328 * (starting with newcat)
329 * @param $catDescription
330 * description of the new category. Defaults to 'New Category'
333 * the new category-id in case of success.
336 function createNewCategory($catName = '', $catDescription = _CREATED_NEW_CATEGORY_DESC) {
337 global $member, $manager;
339 if ($member->blogAdminRights($this->getID())) {
343 $catName = _CREATED_NEW_CATEGORY_NAME;
346 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
347 while (mysql_num_rows($res) > 0)
350 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
353 $catName = $catName . $i;
361 'description' => $catDescription
365 $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')";
367 $catid = mysql_insert_id();
374 'description' => $catDescription,
388 * Searches all months of this blog for the given query
393 * template to be used (__NAME__ of the template)
394 * @param $amountMonths
395 * max amount of months to be search (0 = all)
397 * max number of results to show
401 * amount of hits found
403 function search($query, $template, $amountMonths, $maxresults, $startpos) {
404 global $CONF, $manager;
407 $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight);
411 // no query -> show everything
413 $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1);
416 // add LIMIT to query (to split search results into pages)
417 if (intval($maxresults > 0))
418 $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults);
421 $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1);
423 // when no results were found, show a message
424 if ($amountfound == 0)
426 $template =& $manager->getTemplate($template);
428 'query' => htmlspecialchars($query),
429 'blogid' => $this->getID()
431 echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars);
439 * Returns an SQL query to use for a search query
443 * @param $amountMonths
444 * amount of months to search back. Default = 0 = unlimited
446 * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
447 * @returns $highlight
448 * words to highlight (out parameter)
450 * either a full SQL query, or an empty string (if querystring empty)
452 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
454 function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')
456 $searchclass =& new SEARCH($query);
458 $highlight = $searchclass->inclusive;
460 // if querystring is empty, return empty string
461 if ($searchclass->inclusive == '')
465 $where = $searchclass->boolean_sql_where('ititle,ibody,imore');
466 $select = $searchclass->boolean_sql_select('ititle,ibody,imore');
468 // get list of blogs to search
469 $blogs = $searchclass->blogs; // array containing blogs that always need to be included
470 $blogs[] = $this->getID(); // also search current blog (duh)
471 $blogs = array_unique($blogs); // remove duplicates
473 if (count($blogs) > 0)
474 $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';
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';
480 $query .= ', '.$select. ' as score ';
482 $query = 'SELECT COUNT(*) as result ';
485 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
486 . ' WHERE i.iauthor=m.mnumber'
487 . ' and i.icat=c.catid'
488 . ' and i.idraft=0' // exclude drafts
490 // don't show future items
491 . ' and i.itime<=' . mysqldate($this->getCorrectTime())
494 // take into account amount of months to search
495 if ($amountMonths > 0)
497 $localtime = getdate($this->getCorrectTime());
498 $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);
499 $query .= ' and i.itime>' . mysqldate($timestamp_start);
505 $query .= ' ORDER BY score DESC';
507 $query .= ' ORDER BY i.itime DESC ';
514 * Returns the SQL query that's normally used to display the blog items on the index type skins
517 * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
519 * either a full SQL query, or an empty string
521 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
523 function getSqlBlog($extraQuery, $mode = '')
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';
528 $query = 'SELECT COUNT(*) as result ';
530 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
531 . ' WHERE i.iblog='.$this->blogid
532 . ' and i.iauthor=m.mnumber'
533 . ' and i.icat=c.catid'
534 . ' and i.idraft=0' // exclude drafts
535 // don't show future items
536 . ' and i.itime<=' . mysqldate($this->getCorrectTime());
538 if ($this->getSelectedCategory())
539 $query .= ' and i.icat=' . $this->getSelectedCategory() . ' ';
542 $query .= $extraQuery;
545 $query .= ' ORDER BY i.itime DESC';
551 * Shows the archivelist using the given template
553 function showArchiveList($template, $mode = 'month', $limit = 0) {
554 global $CONF, $catid, $manager;
556 $linkparams = array();
558 $linkparams = array('catid' => $catid);
561 $template =& $manager->getTemplate($template);
562 $data['blogid'] = $this->getID();
564 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);
566 $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')
567 . ' WHERE iblog=' . $this->getID()
568 . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items!
569 . ' and idraft=0'; // don't show draft items
572 $query .= ' and icat=' . intval($catid);
574 $query .= ' GROUP BY Year, Month';
579 $query .= ' ORDER BY itime DESC';
582 $query .= ' LIMIT ' . intval($limit);
584 $res = sql_query($query);
586 while ($current = mysql_fetch_object($res)) {
587 $current->itime = strtotime($current->itime); // string time -> unix timestamp
589 if ($mode == 'day') {
590 $archivedate = date('Y-m-d',$current->itime);
591 $archive['day'] = date('d',$current->itime);
592 $data['day'] = date('d',$current->itime);
594 $archivedate = date('Y-m',$current->itime);
596 $data['month'] = date('m',$current->itime);
597 $data['year'] = date('Y',$current->itime);
598 $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams);
601 'PreArchiveListItem',
607 $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
608 echo strftime($temp,$current->itime);
612 mysql_free_result($res);
614 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
619 * Shows the list of categories using a given template
621 function showCategoryList($template) {
622 global $CONF, $manager;
624 // determine arguments next to catids
625 // I guess this can be done in a better way, but it works
626 global $archive, $archivelist;
628 $linkparams = array();
630 $blogurl = createArchiveLink($this->getID(), $archive, '');
631 $linkparams['blogid'] = $this->getID();
632 $linkparams['archive'] = $archive;
633 } else if ($archivelist) {
634 $blogurl = createArchiveListLink($this->getID(), '');
635 $linkparams['archivelist'] = $archivelist;
637 $blogurl = createBlogidLink($this->getID(), '');
638 $linkparams['blogid'] = $this->getID();
641 //$blogurl = $this->getURL() . $qargs;
642 //$blogurl = createBlogLink($this->getURL(), $linkparams);
644 $template =& $manager->getTemplate($template);
646 echo TEMPLATE::fill((isset($template['CATLIST_HEADER']) ? $template['CATLIST_HEADER'] : null),
648 'blogid' => $this->getID(),
649 'blogurl' => $blogurl,
650 'self' => $CONF['Self']
653 $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC';
654 $res = sql_query($query);
657 while ($data = mysql_fetch_assoc($res)) {
658 $data['blogid'] = $this->getID();
659 $data['blogurl'] = $blogurl;
660 $data['catlink'] = createLink(
663 'catid' => $data['catid'],
664 'name' => $data['catname'],
665 'extra' => $linkparams
668 $data['self'] = $CONF['Self'];
671 'PreCategoryListItem',
677 echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
678 //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
679 //echo strftime($temp, $current->itime);
683 mysql_free_result($res);
685 echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null),
687 'blogid' => $this->getID(),
688 'blogurl' => $blogurl,
689 'self' => $CONF['Self']
694 * Shows a list of all blogs in the system using a given template
695 * ordered by number, name, shortname or description
696 * in ascending or descending order
698 function showBlogList($template, $bnametype, $orderby, $direction) {
699 global $CONF, $manager;
709 $orderby='bshortname';
719 $direction=strtolower($direction);
720 switch ($direction) {
732 $template =& $manager->getTemplate($template);
734 echo TEMPLATE::fill((isset($template['BLOGLIST_HEADER']) ? $template['BLOGLIST_HEADER'] : null),
736 'sitename' => $CONF['SiteName'],
737 'siteurl' => $CONF['IndexURL']
740 $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY '.$orderby.' '.$direction;
741 $res = sql_query($query);
743 while ($data = mysql_fetch_assoc($res)) {
747 // $list['bloglink'] = createLink('blog', array('blogid' => $data['bnumber']));
748 $list['bloglink'] = createBlogidLink($data['bnumber']);
750 $list['blogdesc'] = $data['bdesc'];
752 $list['blogurl'] = $data['burl'];
754 if ($bnametype=='shortname') {
755 $list['blogname'] = $data['bshortname'];
757 else { // all other cases
758 $list['blogname'] = $data['bname'];
768 echo TEMPLATE::fill((isset($template['BLOGLIST_LISTITEM']) ? $template['BLOGLIST_LISTITEM'] : null), $list);
772 mysql_free_result($res);
774 echo TEMPLATE::fill((isset($template['BLOGLIST_FOOTER']) ? $template['BLOGLIST_FOOTER'] : null),
776 'sitename' => $CONF['SiteName'],
777 'siteurl' => $CONF['IndexURL']
783 * Blogsettings functions
786 function readSettings() {
788 . ' FROM '.sql_table('blog')
789 . ' WHERE bnumber=' . $this->blogid;
790 $res = sql_query($query);
792 $this->isValid = (mysql_num_rows($res) > 0);
796 $this->settings = mysql_fetch_assoc($res);
799 function writeSettings() {
801 // (can't use floatval since not available prior to PHP 4.2)
802 $offset = $this->getTimeOffset();
803 if (!is_float($offset))
804 $offset = intval($offset);
806 $query = 'UPDATE '.sql_table('blog')
807 . " SET bname='" . addslashes($this->getName()) . "',"
808 . " bshortname='". addslashes($this->getShortName()) . "',"
809 . " bcomments=". intval($this->commentsEnabled()) . ","
810 . " bmaxcomments=" . intval($this->getMaxComments()) . ","
811 . " btimeoffset=" . $offset . ","
812 . " bpublic=" . intval($this->isPublic()) . ","
813 . " breqemail=" . intval($this->emailRequired()) . ","
814 . " bsendping=" . intval($this->sendPing()) . ","
815 . " bconvertbreaks=" . intval($this->convertBreaks()) . ","
816 . " ballowpast=" . intval($this->allowPastPosting()) . ","
817 . " bnotify='" . addslashes($this->getNotifyAddress()) . "',"
818 . " bnotifytype=" . intval($this->getNotifyType()) . ","
819 . " burl='" . addslashes($this->getURL()) . "',"
820 . " bupdate='" . addslashes($this->getUpdateFile()) . "',"
821 . " bdesc='" . addslashes($this->getDescription()) . "',"
822 . " bdefcat=" . intval($this->getDefaultCategory()) . ","
823 . " bdefskin=" . intval($this->getDefaultSkin()) . ","
824 . " bincludesearch=" . intval($this->getSearchable())
825 . " WHERE bnumber=" . intval($this->getID());
832 // update update file if requested
833 function updateUpdatefile() {
834 if ($this->getUpdateFile()) {
835 $f_update = fopen($this->getUpdateFile(),'w');
836 fputs($f_update,$this->getCorrectTime());
842 function isValidCategory($catid) {
843 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid);
844 $res = sql_query($query);
845 return (mysql_num_rows($res) != 0);
848 function getCategoryName($catid) {
849 $res = sql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
850 $o = mysql_fetch_object($res);
854 function getCategoryDesc($catid) {
855 $res = sql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
856 $o = mysql_fetch_object($res);
860 function getCategoryIdFromName($name) {
861 $res = sql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"');
862 if (mysql_num_rows($res) > 0) {
863 $o = mysql_fetch_object($res);
866 return $this->getDefaultCategory();
870 function sendPing() {
871 return $this->getSetting('bsendping');
874 function setPingUserland($val) {
875 $this->setSetting('bsendping',$val);
878 function convertBreaks() {
879 return $this->getSetting('bconvertbreaks');
882 function insertJavaScriptInfo($authorid = '') {
883 global $member, $CONF;
886 $authorid = $member->getID();
889 <script type="text/javascript">
890 setConvertBreaks(<?php echo $this->convertBreaks() ? 'true' : 'false' ?>);
891 setMediaUrl("<?php echo $CONF['MediaURL']?>");
892 setAuthorId(<?php echo $authorid?>);
895 function setConvertBreaks($val) {
896 $this->setSetting('bconvertbreaks',$val);
898 function setAllowPastPosting($val) {
899 $this->setSetting('ballowpast',$val);
901 function allowPastPosting() {
902 return $this->getSetting('ballowpast');
905 function getCorrectTime($t=0) {
906 if ($t == 0) $t = time();
907 return ($t + 3600 * $this->getTimeOffset());
911 return $this->getSetting('bname');
914 function getShortName() {
915 return $this->getSetting('bshortname');
918 function getMaxComments() {
919 return $this->getSetting('bmaxcomments');
922 function getNotifyAddress() {
923 return $this->getSetting('bnotify');
926 function getNotifyType() {
927 return $this->getSetting('bnotifytype');
930 function notifyOnComment() {
931 $n = $this->getNotifyType();
932 return (($n != 0) && (($n % 3) == 0));
935 function notifyOnVote() {
936 $n = $this->getNotifyType();
937 return (($n != 0) && (($n % 5) == 0));
940 function notifyOnNewItem() {
941 $n = $this->getNotifyType();
942 return (($n != 0) && (($n % 7) == 0));
945 function setNotifyType($val) {
946 $this->setSetting('bnotifytype',$val);
950 function getTimeOffset() {
951 return $this->getSetting('btimeoffset');
954 function commentsEnabled() {
955 return $this->getSetting('bcomments');
959 return $this->getSetting('burl');
962 function getDefaultSkin() {
963 return $this->getSetting('bdefskin');
966 function getUpdateFile() {
967 return $this->getSetting('bupdate');
970 function getDescription() {
971 return $this->getSetting('bdesc');
974 function isPublic() {
975 return $this->getSetting('bpublic');
978 function emailRequired() {
979 return $this->getSetting('breqemail');
982 function getSearchable() {
983 return $this->getSetting('bincludesearch');
986 function getDefaultCategory() {
987 return $this->getSetting('bdefcat');
990 function setPublic($val) {
991 $this->setSetting('bpublic',$val);
994 function setSearchable($val) {
995 $this->setSetting('bincludesearch',$val);
998 function setDescription($val) {
999 $this->setSetting('bdesc',$val);
1002 function setUpdateFile($val) {
1003 $this->setSetting('bupdate',$val);
1006 function setDefaultSkin($val) {
1007 $this->setSetting('bdefskin',$val);
1010 function setURL($val) {
1011 $this->setSetting('burl',$val);
1014 function setName($val) {
1015 $this->setSetting('bname',$val);
1018 function setShortName($val) {
1019 $this->setSetting('bshortname',$val);
1022 function setCommentsEnabled($val) {
1023 $this->setSetting('bcomments',$val);
1026 function setMaxComments($val) {
1027 $this->setSetting('bmaxcomments',$val);
1030 function setNotifyAddress($val) {
1031 $this->setSetting('bnotify',$val);
1034 function setEmailRequired($val) {
1035 $this->setSetting('breqemail',$val);
1038 function setTimeOffset($val) {
1039 // check validity of value
1040 // 1. replace , by . (common mistake)
1041 $val = str_replace(',','.',$val);
1042 // 2. cast to float or int
1043 if (is_numeric($val) && strstr($val,'.5')) {
1044 $val = (float) $val;
1046 $val = intval($val);
1049 $this->setSetting('btimeoffset',$val);
1052 function setDefaultCategory($val) {
1053 $this->setSetting('bdefcat',$val);
1056 function getSetting($key) {
1057 return $this->settings[$key];
1060 function setSetting($key,$value) {
1061 $this->settings[$key] = $value;
1065 // tries to add a member to the team. Returns false if the member was already on
1067 function addTeamMember($memberid, $admin) {
1070 $memberid = intval($memberid);
1071 $admin = intval($admin);
1073 // check if member is already a member
1074 $tmem = MEMBER::createFromID($memberid);
1076 if ($tmem->isTeamMember($this->getID()))
1089 $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) '
1090 . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")';
1094 'PostAddTeamMember',
1103 $logMsg = sprintf(_TEAM_ADD_NEWTEAMMEMBER, $tmem->getDisplayName(), $memberid, $this->getName());
1104 ACTIONLOG::add(INFO, $logMsg);
1110 return intVal($this->blogid);
1113 // returns true if there is a blog with the given shortname (static)
1114 function exists($name) {
1115 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"');
1116 return (mysql_num_rows($r) != 0);
1119 // returns true if there is a blog with the given ID (static)
1120 function existsID($id) {
1121 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));
1122 return (mysql_num_rows($r) != 0);
1125 // flag there is a future post pending
1126 function setFuturePost() {
1127 $query = 'UPDATE '.sql_table('blog')
1128 . " SET bfuturepost='1' WHERE bnumber=" . $this->getID();
1132 // clear there is a future post pending
1133 function clearFuturePost() {
1134 $query = 'UPDATE '.sql_table('blog')
1135 . " SET bfuturepost='0' WHERE bnumber=" . $this->getID();
1139 // check if we should throw justPosted event
1140 function checkJustPosted() {
1143 if ($this->settings['bfuturepost'] == 1) {
1144 $blogid = $this->getID();
1145 $result = sql_query("SELECT * FROM " . sql_table('item')
1146 . " WHERE iposted=0 AND iblog=" . $blogid . " AND itime<NOW()");
1147 if (mysql_num_rows($result) > 0) {
1148 // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already
1149 // Note that the plugins's calling order is subject to thri order in the plugin list
1153 array('blogid' => $blogid,
1154 'pinged' => &$pinged
1158 // clear all expired future posts
1159 sql_query("UPDATE " . sql_table('item') . " SET iposted='1' WHERE iblog=" . $blogid . " AND itime<NOW()");
1161 // check to see any pending future post, clear the flag is none
1162 $result = sql_query("SELECT * FROM " . sql_table('item')
1163 . " WHERE iposted=0 AND iblog=" . $blogid);
1164 if (mysql_num_rows($result) == 0) {
1165 $this->clearFuturePost();
1172 * Shows the given list of items for this blog
1175 * array of item numbers to be displayed
1177 * String representing the template _NAME_ (!)
1179 * contains a query that should be highlighted
1181 * 1=show comments 0=don't show comments
1183 * 1=show dateheads 0=don't show dateheads
1185 * amount of items shown
1187 function readLogFromList($itemarray, $template, $highlight = '', $comments = 1, $dateheads = 1) {
1189 $query = $this->getSqlItemList($itemarray);
1191 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
1195 * Returns the SQL query used to fill out templates for a list of items
1198 * an array holding the item numbers of the items to be displayed
1200 * either a full SQL query, or an empty string
1202 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
1204 function getSqlItemList($itemarray)
1206 if (!is_array($itemarray)) return '';
1208 foreach ($itemarray as $value) {
1209 if (intval($value)) $items[] = intval($value);
1211 if (!count($items)) return '';
1212 //$itemlist = implode(',',$items);
1215 foreach ($items as $value) {
1218 . ' i.inumber as itemid,'
1219 . ' i.ititle as title,'
1220 . ' i.ibody as body,'
1221 . ' m.mname as author,'
1222 . ' m.mrealname as authorname,'
1224 . ' i.imore as more,'
1225 . ' m.mnumber as authorid,'
1226 . ' m.memail as authormail,'
1227 . ' m.murl as authorurl,'
1228 . ' c.cname as category,'
1229 . ' i.icat as catid,'
1230 . ' i.iclosed as closed';
1233 . sql_table('item') . ' as i, '
1234 . sql_table('member') . ' as m, '
1235 . sql_table('category').' as c'
1237 . ' i.iblog = ' . $this->blogid
1238 . ' and i.iauthor = m.mnumber'
1239 . ' and i.icat = c.catid'
1240 . ' and i.idraft = 0' // exclude drafts
1241 // don't show future items
1242 . ' and i.itime <= ' . mysqldate($this->getCorrectTime());
1244 //$query .= ' and i.inumber IN ('.$itemlist.')';
1245 $query .= ' and i.inumber = '.intval($value);
1248 if ($i) $query .= ' UNION ';