4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5 * Copyright (C) 2002-2006 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-2006 The Nucleus Group
19 * @version $Id: BLOG.php,v 1.5 2006-07-17 20:03:44 kimitake Exp $
20 * $NucleusJP: BLOG.php,v 1.4 2005/08/13 07:31:04 kimitake Exp $
23 // temporary: dirt way to separe class ITEMACTIONS from BLOG
24 require_once $DIR_LIBS . '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
173 while ($item = mysql_fetch_object($items)) {
175 $item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp
177 // action handler needs to know the item we're handling
178 $actions->setCurrentItem($item);
180 // 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($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) {
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) '
272 . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid)";
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 $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";
297 $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";
298 $mailto_msg .= getMailFooter();
300 $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE;
302 $frommail = $member->getNotifyFromMailAddress();
304 $notify =& new NOTIFICATION($this->getNotifyAddress());
305 $notify->notify($mailto_title, $mailto_msg , $frommail);
313 * Creates a new category for this blog
316 * name of the new category. When empty, a name is generated automatically
317 * (starting with newcat)
318 * @param $catDescription
319 * description of the new category. Defaults to 'New Category'
322 * the new category-id in case of success.
325 function createNewCategory($catName = '', $catDescription = 'New category') {
326 global $member, $manager;
328 if ($member->blogAdminRights($this->getID())) {
335 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
336 while (mysql_num_rows($res) > 0)
339 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
342 $catName = $catName . $i;
350 'description' => $catDescription
354 $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')";
356 $catid = mysql_insert_id();
363 'description' => $catDescription,
377 * Searches all months of this blog for the given query
382 * template to be used (__NAME__ of the template)
383 * @param $amountMonths
384 * max amount of months to be search (0 = all)
386 * max number of results to show
390 * amount of hits found
392 function search($query, $template, $amountMonths, $maxresults, $startpos) {
393 global $CONF, $manager;
396 $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight);
400 // no query -> show everything
402 $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1);
405 // add LIMIT to query (to split search results into pages)
406 if (intval($maxresults > 0))
407 $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults);
410 $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1);
412 // when no results were found, show a message
413 if ($amountfound == 0)
415 $template =& $manager->getTemplate($template);
417 'query' => htmlspecialchars($query),
418 'blogid' => $this->getID()
420 echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars);
428 * Returns an SQL query to use for a search query
432 * @param $amountMonths
433 * amount of months to search back. Default = 0 = unlimited
435 * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
436 * @returns $highlight
437 * words to highlight (out parameter)
439 * either a full SQL query, or an empty string (if querystring empty)
441 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
443 function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')
445 $searchclass =& new SEARCH($query);
447 $highlight = $searchclass->inclusive;
449 // if querystring is empty, return empty string
450 if ($searchclass->inclusive == '')
454 $where = $searchclass->boolean_sql_where('ititle,ibody,imore');
455 $select = $searchclass->boolean_sql_select('ititle,ibody,imore');
457 // get list of blogs to search
458 $blogs = $searchclass->blogs; // array containing blogs that always need to be included
459 $blogs[] = $this->getID(); // also search current blog (duh)
460 $blogs = array_unique($blogs); // remove duplicates
462 if (count($blogs) > 0)
463 $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';
467 $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';
469 $query .= ', '.$select. ' as score ';
471 $query = 'SELECT COUNT(*) as result ';
474 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
475 . ' WHERE i.iauthor=m.mnumber'
476 . ' and i.icat=c.catid'
477 . ' and i.idraft=0' // exclude drafts
479 // don't show future items
480 . ' and i.itime<=' . mysqldate($this->getCorrectTime())
483 // take into account amount of months to search
484 if ($amountMonths > 0)
486 $localtime = getdate($this->getCorrectTime());
487 $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);
488 $query .= ' and i.itime>' . mysqldate($timestamp_start);
494 $query .= ' ORDER BY score DESC';
496 $query .= ' ORDER BY i.itime DESC ';
503 * Returns the SQL query that's normally used to display the blog items on the index type skins
506 * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
508 * either a full SQL query, or an empty string
510 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
512 function getSqlBlog($extraQuery, $mode = '')
515 $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';
517 $query = 'SELECT COUNT(*) as result ';
519 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
520 . ' WHERE i.iblog='.$this->blogid
521 . ' and i.iauthor=m.mnumber'
522 . ' and i.icat=c.catid'
523 . ' and i.idraft=0' // exclude drafts
524 // don't show future items
525 . ' and i.itime<=' . mysqldate($this->getCorrectTime());
527 if ($this->getSelectedCategory())
528 $query .= ' and i.icat=' . $this->getSelectedCategory() . ' ';
531 $query .= $extraQuery;
534 $query .= ' ORDER BY i.itime DESC';
540 * Shows the archivelist using the given template
542 function showArchiveList($template, $mode = 'month', $limit = 0) {
543 global $CONF, $catid, $manager;
546 $linkparams = array('catid' => $catid);
548 $template =& $manager->getTemplate($template);
549 $data['blogid'] = $this->getID();
551 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);
553 $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')
554 . ' WHERE iblog=' . $this->getID()
555 . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items!
556 . ' and idraft=0'; // don't show draft items
559 $query .= ' and icat=' . intval($catid);
561 $query .= ' GROUP BY Year, Month';
566 $query .= ' ORDER BY itime DESC';
569 $query .= ' LIMIT ' . intval($limit);
571 $res = sql_query($query);
573 while ($current = mysql_fetch_object($res)) {
574 $current->itime = strtotime($current->itime); // string time -> unix timestamp
576 if ($mode == 'day') {
577 $archivedate = date('Y-m-d',$current->itime);
578 $archive['day'] = date('d',$current->itime);
580 $archivedate = date('Y-m',$current->itime);
582 $data['month'] = date('m',$current->itime);
583 $data['year'] = date('Y',$current->itime);
584 $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams);
586 $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
587 echo strftime($temp,$current->itime);
591 mysql_free_result($res);
593 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
598 * Shows the list of categories using a given template
600 function showCategoryList($template) {
601 global $CONF, $manager;
603 // determine arguments next to catids
604 // I guess this can be done in a better way, but it works
605 global $archive, $archivelist;
607 $linkparams = array();
609 $blogurl = createArchiveLink($this->getID(), $archive, '');
610 $linkparams['blogid'] = $this->getID();
611 $linkparams['archive'] = $archive;
612 } else if ($archivelist) {
613 $blogurl = createArchiveListLink($this->getID(), '');
614 $linkparams['archivelist'] = $archivelist;
616 $blogurl = createBlogidLink($this->getID(), '');
617 $linkparams['blogid'] = $this->getID();
620 //$blogurl = $this->getURL() . $qargs;
621 $blogurl = createBlogLink($this->getURL(), $linkparams);
623 $template =& $manager->getTemplate($template);
625 echo TEMPLATE::fill((isset($template['CATLIST_HEADER']) ? $template['CATLIST_HEADER'] : null),
627 'blogid' => $this->getID(),
628 'blogurl' => $blogurl,
629 'self' => $CONF['Self']
632 $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC';
633 $res = sql_query($query);
636 while ($data = mysql_fetch_assoc($res)) {
637 $data['blogid'] = $this->getID();
638 $data['blogurl'] = $blogurl;
639 $data['catlink'] = createLink(
642 'catid' => $data['catid'],
643 'name' => $data['catname'],
644 'extra' => $linkparams
647 $data['self'] = $CONF['Self'];
649 echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
650 //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
651 //echo strftime($temp, $current->itime);
655 mysql_free_result($res);
657 echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null),
659 'blogid' => $this->getID(),
660 'blogurl' => $blogurl,
661 'self' => $CONF['Self']
666 * Blogsettings functions
669 function readSettings() {
671 . ' FROM '.sql_table('blog')
672 . ' WHERE bnumber=' . $this->blogid;
673 $res = sql_query($query);
675 $this->isValid = (mysql_num_rows($res) > 0);
679 $this->settings = mysql_fetch_assoc($res);
682 function writeSettings() {
684 // (can't use floatval since not available prior to PHP 4.2)
685 $offset = $this->getTimeOffset();
686 if (!is_float($offset))
687 $offset = intval($offset);
689 $query = 'UPDATE '.sql_table('blog')
690 . " SET bname='" . addslashes($this->getName()) . "',"
691 . " bshortname='". addslashes($this->getShortName()) . "',"
692 . " bcomments=". intval($this->commentsEnabled()) . ","
693 . " bmaxcomments=" . intval($this->getMaxComments()) . ","
694 . " btimeoffset=" . $offset . ","
695 . " bpublic=" . intval($this->isPublic()) . ","
696 . " breqemail=" . intval($this->emailRequired()) . ","
697 . " bsendping=" . intval($this->pingUserland()) . ","
698 . " bconvertbreaks=" . intval($this->convertBreaks()) . ","
699 . " ballowpast=" . intval($this->allowPastPosting()) . ","
700 . " bnotify='" . addslashes($this->getNotifyAddress()) . "',"
701 . " bnotifytype=" . intval($this->getNotifyType()) . ","
702 . " burl='" . addslashes($this->getURL()) . "',"
703 . " bupdate='" . addslashes($this->getUpdateFile()) . "',"
704 . " bdesc='" . addslashes($this->getDescription()) . "',"
705 . " bdefcat=" . intval($this->getDefaultCategory()) . ","
706 . " bdefskin=" . intval($this->getDefaultSkin()) . ","
707 . " bincludesearch=" . intval($this->getSearchable())
708 . " WHERE bnumber=" . intval($this->getID());
715 // update update file if requested
716 function updateUpdatefile() {
717 if ($this->getUpdateFile()) {
718 $f_update = fopen($this->getUpdateFile(),'w');
719 fputs($f_update,$this->getCorrectTime());
726 * Sends a XML-RPC ping message to Userland, so the weblog can
727 * show up in the weblogs.com updates-list
729 function sendUserlandPing() {
730 global $php_errormsg;
732 if ($this->pingUserland()) {
733 // testmessage for adding an item
734 $message = new xmlrpcmsg('weblogUpdates.ping',array(
735 new xmlrpcval($this->getName(),'string'),
736 new xmlrpcval($this->getURL(),'string')
739 $c = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80);
743 $r = $c->send($message,15); // 15 seconds timeout...
745 if (($r == 0) && ($r->errno || $r->errstring)) {
746 return 'Error ' . $r->errno . ' : ' . $r->errstring;
747 } elseif (($r == 0) && ($php_errormsg)) {
748 return 'PHP Error: ' . $php_errormsg;
750 return 'Error while trying to send ping. Sorry about that.';
751 } elseif ($r->faultCode() != 0) {
752 return 'Error: ' . $r->faultString();
754 $r = $r->value(); // get response struct
756 $flerror = $r->structmem('flerror');
757 $flerror = $flerror->scalarval();
760 $message = $r->structmem('message');
761 $message = $message->scalarval();
764 return 'Error (flerror=1): ' . $message;
766 return 'Success: ' . $message;
771 function isValidCategory($catid) {
772 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid);
773 $res = mysql_query($query);
774 return (mysql_num_rows($res) != 0);
777 function getCategoryName($catid) {
778 $res = mysql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
779 $o = mysql_fetch_object($res);
783 function getCategoryDesc($catid) {
784 $res = mysql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
785 $o = mysql_fetch_object($res);
789 function getCategoryIdFromName($name) {
790 $res = mysql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"');
791 if (mysql_num_rows($res) > 0) {
792 $o = mysql_fetch_object($res);
795 return $this->getDefaultCategory();
799 function pingUserland() {
800 return $this->getSetting('bsendping');
803 function setPingUserland($val) {
804 $this->setSetting('bsendping',$val);
807 function convertBreaks() {
808 return $this->getSetting('bconvertbreaks');
811 function insertJavaScriptInfo($authorid = '') {
812 global $member, $CONF;
815 $authorid = $member->getID();
818 <script type="text/javascript">
819 setConvertBreaks(<?php echo $this->convertBreaks() ? 'true' : 'false' ?>);
820 setMediaUrl("<?php echo $CONF['MediaURL']?>");
821 setAuthorId(<?php echo $authorid?>);
824 function setConvertBreaks($val) {
825 $this->setSetting('bconvertbreaks',$val);
827 function setAllowPastPosting($val) {
828 $this->setSetting('ballowpast',$val);
830 function allowPastPosting() {
831 return $this->getSetting('ballowpast');
834 function getCorrectTime($t=0) {
835 if ($t == 0) $t = time();
836 return ($t + 3600 * $this->getTimeOffset());
840 return $this->getSetting('bname');
843 function getShortName() {
844 return $this->getSetting('bshortname');
847 function getMaxComments() {
848 return $this->getSetting('bmaxcomments');
851 function getNotifyAddress() {
852 return $this->getSetting('bnotify');
855 function getNotifyType() {
856 return $this->getSetting('bnotifytype');
859 function notifyOnComment() {
860 $n = $this->getNotifyType();
861 return (($n != 0) && (($n % 3) == 0));
864 function notifyOnVote() {
865 $n = $this->getNotifyType();
866 return (($n != 0) && (($n % 5) == 0));
869 function notifyOnNewItem() {
870 $n = $this->getNotifyType();
871 return (($n != 0) && (($n % 7) == 0));
874 function setNotifyType($val) {
875 $this->setSetting('bnotifytype',$val);
879 function getTimeOffset() {
880 return $this->getSetting('btimeoffset');
883 function commentsEnabled() {
884 return $this->getSetting('bcomments');
888 return $this->getSetting('burl');
891 function getDefaultSkin() {
892 return $this->getSetting('bdefskin');
895 function getUpdateFile() {
896 return $this->getSetting('bupdate');
899 function getDescription() {
900 return $this->getSetting('bdesc');
903 function isPublic() {
904 return $this->getSetting('bpublic');
907 function emailRequired() {
908 return $this->getSetting('breqemail');
911 function getSearchable() {
912 return $this->getSetting('bincludesearch');
915 function getDefaultCategory() {
916 return $this->getSetting('bdefcat');
919 function setPublic($val) {
920 $this->setSetting('bpublic',$val);
923 function setSearchable($val) {
924 $this->setSetting('bincludesearch',$val);
927 function setDescription($val) {
928 $this->setSetting('bdesc',$val);
931 function setUpdateFile($val) {
932 $this->setSetting('bupdate',$val);
935 function setDefaultSkin($val) {
936 $this->setSetting('bdefskin',$val);
939 function setURL($val) {
940 $this->setSetting('burl',$val);
943 function setName($val) {
944 $this->setSetting('bname',$val);
947 function setShortName($val) {
948 $this->setSetting('bshortname',$val);
951 function setCommentsEnabled($val) {
952 $this->setSetting('bcomments',$val);
955 function setMaxComments($val) {
956 $this->setSetting('bmaxcomments',$val);
959 function setNotifyAddress($val) {
960 $this->setSetting('bnotify',$val);
963 function setEmailRequired($val) {
964 $this->setSetting('breqemail',$val);
967 function setTimeOffset($val) {
968 // check validity of value
969 // 1. replace , by . (common mistake)
970 $val = str_replace(',','.',$val);
971 // 2. cast to float or int
972 if (is_numeric($val) && strstr($val,'.5')) {
978 $this->setSetting('btimeoffset',$val);
981 function setDefaultCategory($val) {
982 $this->setSetting('bdefcat',$val);
985 function getSetting($key) {
986 return $this->settings[$key];
989 function setSetting($key,$value) {
990 $this->settings[$key] = $value;
994 // tries to add a member to the team. Returns false if the member was already on
996 function addTeamMember($memberid, $admin) {
999 $memberid = intval($memberid);
1000 $admin = intval($admin);
1002 // check if member is already a member
1003 $tmem = MEMBER::createFromID($memberid);
1005 if ($tmem->isTeamMember($this->getID()))
1018 $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) '
1019 . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")';
1023 'PostAddTeamMember',
1032 ACTIONLOG::add(INFO, 'Added ' . $tmem->getDisplayName() . ' (ID=' .
1033 $memberid .') to the team of blog "' . $this->getName() . '"');
1039 return $this->blogid;
1042 // returns true if there is a blog with the given shortname (static)
1043 function exists($name) {
1044 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"');
1045 return (mysql_num_rows($r) != 0);
1048 // returns true if there is a blog with the given ID (static)
1049 function existsID($id) {
1050 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));
1051 return (mysql_num_rows($r) != 0);