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;
\r
24 require_once dirname(__FILE__) . '/ITEMACTIONS.php';
\r
31 // ID of currently selected category
\r
34 // After creating an object of the blog class, contains true if the BLOG object is
\r
35 // valid (the blog exists)
\r
38 // associative array, containing all blogsettings (use the get/set functions instead)
\r
42 * Creates a new BLOG object for the given blog
\r
46 function BLOG($id) {
\r
47 $this->blogid = intval($id);
\r
48 $this->readSettings();
\r
51 // (the parse functions in SKIN.php will override this, so it's mainly useless)
\r
53 $this->setSelectedCategory($catid);
\r
57 * Shows the given amount of items for this blog
\r
60 * String representing the template _NAME_ (!)
\r
61 * @param $amountEntries
\r
62 * amount of entries to show
\r
64 * offset from where items should be shown (e.g. 5 = start at fifth item)
\r
66 * amount of items shown
\r
68 function readLog($template, $amountEntries, $offset = 0, $startpos = 0) {
\r
69 return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos);
\r
73 * Shows an archive for a given month
\r
80 * String representing the template name to be used
\r
82 function showArchive($templatename, $year, $month, $day=0) {
\r
84 // create extra where clause for select query
\r
86 $timestamp_start = mktime(0,0,0,$month,1,$year);
\r
87 $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12
\r
89 $timestamp_start = mktime(0,0,0,$month,$day,$year);
\r
90 $timestamp_end = mktime(0,0,0,$month,$day+1,$year);
\r
92 $extra_query = ' and i.itime>=' . mysqldate($timestamp_start)
\r
93 . ' and i.itime<' . mysqldate($timestamp_end);
\r
96 $this->readLogAmount($templatename,0,$extra_query,'',1,1);
\r
101 // sets/gets current category (only when category exists)
\r
102 function setSelectedCategory($catid) {
\r
103 if ($this->isValidCategory($catid) || (intval($catid) == 0))
\r
104 $this->selectedcatid = intval($catid);
\r
107 function setSelectedCategoryByName($catname) {
\r
108 $this->setSelectedCategory($this->getCategoryIdFromName($catname));
\r
111 function getSelectedCategory() {
\r
112 return $this->selectedcatid;
\r
116 * Shows the given amount of items for this blog
\r
119 * String representing the template _NAME_ (!)
\r
120 * @param $amountEntries
\r
121 * amount of entries to show (0 = no limit)
\r
122 * @param $extraQuery
\r
123 * extra conditions to be added to the query
\r
124 * @param $highlight
\r
125 * contains a query that should be highlighted
\r
127 * 1=show comments 0=don't show comments
\r
128 * @param $dateheads
\r
129 * 1=show dateheads 0=don't show dateheads
\r
133 * amount of items shown
\r
135 function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) {
\r
137 $query = $this->getSqlBlog($extraQuery);
\r
139 if ($amountEntries > 0) {
\r
140 // $offset zou moeten worden:
\r
141 // (($startpos / $amountentries) + 1) * $offset ... later testen ...
\r
142 $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries);
\r
144 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
\r
147 function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) {
\r
148 global $CONF, $manager;
\r
150 $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit');
\r
151 if ($lastVisit != 0)
\r
152 $lastVisit = $this->getCorrectTime($lastVisit);
\r
154 // set templatename as global variable (so plugins can access it)
\r
155 global $currentTemplateName;
\r
156 $currentTemplateName = $templateName;
\r
158 $template =& $manager->getTemplate($templateName);
\r
160 // create parser object & action handler
\r
161 $actions =& new ITEMACTIONS($this);
\r
162 $parser =& new PARSER($actions->getDefinedActions(),$actions);
\r
163 $actions->setTemplate($template);
\r
164 $actions->setHighlight($highlight);
\r
165 $actions->setLastVisit($lastVisit);
\r
166 $actions->setParser($parser);
\r
167 $actions->setShowComments($comments);
\r
170 $items = sql_query($query);
\r
172 // loop over all items
\r
174 while ($item = mysql_fetch_object($items)) {
\r
176 $item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp
\r
178 // action handler needs to know the item we're handling
\r
179 $actions->setCurrentItem($item);
\r
181 // add date header if needed
\r
183 $new_date = date('dFY',$item->timestamp);
\r
184 if ($new_date != $old_date) {
\r
185 // unless this is the first time, write date footer
\r
186 $timestamp = $item->timestamp;
\r
187 if ($old_date != 0) {
\r
188 $oldTS = strtotime($old_date);
\r
189 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
\r
190 $tmp_footer = strftime($template['DATE_FOOTER'], $oldTS);
\r
191 $parser->parse($tmp_footer);
\r
192 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS));
\r
194 $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
\r
195 // note, to use templatvars in the dateheader, the %-characters need to be doubled in
\r
196 // order to be preserved by strftime
\r
197 $tmp_header = strftime((isset($template['DATE_HEADER']) ? $template['DATE_HEADER'] : null), $timestamp);
\r
198 $parser->parse($tmp_header);
\r
199 $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp));
\r
201 $old_date = $new_date;
\r
205 $parser->parse($template['ITEM_HEADER']);
\r
206 $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item));
\r
207 $parser->parse($template['ITEM']);
\r
208 $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item));
\r
209 $parser->parse($template['ITEM_FOOTER']);
\r
213 $numrows = mysql_num_rows($items);
\r
215 // add another date footer if there was at least one item
\r
216 if (($numrows > 0) && $dateheads) {
\r
217 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
\r
218 $parser->parse($template['DATE_FOOTER']);
\r
219 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date)));
\r
222 mysql_free_result($items); // free memory
\r
228 function showOneitem($itemid, $template, $highlight) {
\r
229 $extraQuery = ' and inumber=' . intval($itemid);
\r
231 return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0);
\r
236 * Adds an item to this blog
\r
238 function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1') {
\r
241 $blogid = intval($blogid);
\r
242 $authorid = intval($authorid);
\r
246 $catid = intval($catid);
\r
248 // convert newlines to <br />
\r
249 if ($this->convertBreaks()) {
\r
250 $body = addBreaks($body);
\r
251 $more = addBreaks($more);
\r
254 if ($closed != '1') $closed = '0';
\r
255 if ($draft != '0') $draft = '1';
\r
257 if (!$this->isValidCategory($catid))
\r
258 $catid = $this->getDefaultCategory();
\r
260 if ($timestamp > $this->getCorrectTime())
\r
263 $timestamp = date('Y-m-d H:i:s',$timestamp);
\r
265 $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid));
\r
267 $title = addslashes($title);
\r
268 $body = addslashes($body);
\r
269 $more = addslashes($more);
\r
271 $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) '
\r
272 . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid, $posted)";
\r
274 $itemid = mysql_insert_id();
\r
276 $manager->notify('PostAddItem',array('itemid' => $itemid));
\r
279 $this->updateUpdateFile();
\r
281 // send notification mail
\r
282 if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem())
\r
283 $this->sendNewItemNotification($itemid, stripslashes($title), stripslashes($body));
\r
288 function sendNewItemNotification($itemid, $title, $body) {
\r
289 global $CONF, $member;
\r
291 // create text version of html post
\r
292 $ascii = toAscii($body);
\r
294 $mailto_msg = _NOTIFY_NI_MSG . " \n";
\r
295 // $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n";
\r
296 $temp = parse_url($CONF['Self']);
\r
297 if ($temp['scheme']) {
\r
298 $mailto_msg .= createItemLink($itemid) . "\n\n";
\r
300 $tempurl = $this->getURL();
\r
301 if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') {
\r
302 $mailto_msg .= $tempurl . '?itemid=' . $itemid . "\n\n";
\r
304 $mailto_msg .= $tempurl . '/?itemid=' . $itemid . "\n\n";
\r
307 $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n";
\r
308 $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n";
\r
309 $mailto_msg .= getMailFooter();
\r
311 $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE;
\r
313 $frommail = $member->getNotifyFromMailAddress();
\r
315 $notify =& new NOTIFICATION($this->getNotifyAddress());
\r
316 $notify->notify($mailto_title, $mailto_msg , $frommail);
\r
324 * Creates a new category for this blog
\r
327 * name of the new category. When empty, a name is generated automatically
\r
328 * (starting with newcat)
\r
329 * @param $catDescription
\r
330 * description of the new category. Defaults to 'New Category'
\r
333 * the new category-id in case of success.
\r
336 function createNewCategory($catName = '', $catDescription = _CREATED_NEW_CATEGORY_DESC) {
\r
337 global $member, $manager;
\r
339 if ($member->blogAdminRights($this->getID())) {
\r
341 if ($catName == '')
\r
343 $catName = _CREATED_NEW_CATEGORY_NAME;
\r
346 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
\r
347 while (mysql_num_rows($res) > 0)
\r
350 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID());
\r
353 $catName = $catName . $i;
\r
360 'name' => &$catName,
\r
361 'description' => $catDescription
\r
365 $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')";
\r
367 $catid = mysql_insert_id();
\r
373 'name' => $catName,
\r
374 'description' => $catDescription,
\r
388 * Searches all months of this blog for the given query
\r
393 * template to be used (__NAME__ of the template)
\r
394 * @param $amountMonths
\r
395 * max amount of months to be search (0 = all)
\r
396 * @param $maxresults
\r
397 * max number of results to show
\r
401 * amount of hits found
\r
403 function search($query, $template, $amountMonths, $maxresults, $startpos) {
\r
404 global $CONF, $manager;
\r
407 $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight);
\r
409 if ($sqlquery == '')
\r
411 // no query -> show everything
\r
413 $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1);
\r
416 // add LIMIT to query (to split search results into pages)
\r
417 if (intval($maxresults > 0))
\r
418 $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults);
\r
421 $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1);
\r
423 // when no results were found, show a message
\r
424 if ($amountfound == 0)
\r
426 $template =& $manager->getTemplate($template);
\r
428 'query' => htmlspecialchars($query),
\r
429 'blogid' => $this->getID()
\r
431 echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars);
\r
435 return $amountfound;
\r
439 * Returns an SQL query to use for a search query
\r
443 * @param $amountMonths
\r
444 * amount of months to search back. Default = 0 = unlimited
\r
446 * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
\r
447 * @returns $highlight
\r
448 * words to highlight (out parameter)
\r
450 * either a full SQL query, or an empty string (if querystring empty)
\r
452 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
\r
454 function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '')
\r
456 $searchclass =& new SEARCH($query);
\r
458 $highlight = $searchclass->inclusive;
\r
460 // if querystring is empty, return empty string
\r
461 if ($searchclass->inclusive == '')
\r
465 $where = $searchclass->boolean_sql_where('ititle,ibody,imore');
\r
466 $select = $searchclass->boolean_sql_select('ititle,ibody,imore');
\r
468 // get list of blogs to search
\r
469 $blogs = $searchclass->blogs; // array containing blogs that always need to be included
\r
470 $blogs[] = $this->getID(); // also search current blog (duh)
\r
471 $blogs = array_unique($blogs); // remove duplicates
\r
473 if (count($blogs) > 0)
\r
474 $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')';
\r
478 $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';
\r
480 $query .= ', '.$select. ' as score ';
\r
482 $query = 'SELECT COUNT(*) as result ';
\r
485 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
\r
486 . ' WHERE i.iauthor=m.mnumber'
\r
487 . ' and i.icat=c.catid'
\r
488 . ' and i.idraft=0' // exclude drafts
\r
490 // don't show future items
\r
491 . ' and i.itime<=' . mysqldate($this->getCorrectTime())
\r
494 // take into account amount of months to search
\r
495 if ($amountMonths > 0)
\r
497 $localtime = getdate($this->getCorrectTime());
\r
498 $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']);
\r
499 $query .= ' and i.itime>' . mysqldate($timestamp_start);
\r
505 $query .= ' ORDER BY score DESC';
\r
507 $query .= ' ORDER BY i.itime DESC ';
\r
514 * Returns the SQL query that's normally used to display the blog items on the index type skins
\r
517 * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query
\r
519 * either a full SQL query, or an empty string
\r
521 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
\r
523 function getSqlBlog($extraQuery, $mode = '')
\r
526 $query = 'SELECT i.inumber as itemid, i.ititle as title, i.ibody as body, m.mname as author, m.mrealname as authorname, i.itime, i.imore as more, m.mnumber as authorid, m.memail as authormail, m.murl as authorurl, c.cname as category, i.icat as catid, i.iclosed as closed';
\r
528 $query = 'SELECT COUNT(*) as result ';
\r
530 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
\r
531 . ' WHERE i.iblog='.$this->blogid
\r
532 . ' and i.iauthor=m.mnumber'
\r
533 . ' and i.icat=c.catid'
\r
534 . ' and i.idraft=0' // exclude drafts
\r
535 // don't show future items
\r
536 . ' and i.itime<=' . mysqldate($this->getCorrectTime());
\r
538 if ($this->getSelectedCategory())
\r
539 $query .= ' and i.icat=' . $this->getSelectedCategory() . ' ';
\r
542 $query .= $extraQuery;
\r
545 $query .= ' ORDER BY i.itime DESC';
\r
551 * Shows the archivelist using the given template
\r
553 function showArchiveList($template, $mode = 'month', $limit = 0) {
\r
554 global $CONF, $catid, $manager;
\r
557 $linkparams = array('catid' => $catid);
\r
559 $template =& $manager->getTemplate($template);
\r
560 $data['blogid'] = $this->getID();
\r
562 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data);
\r
564 $query = 'SELECT itime, SUBSTRING(itime,1,4) AS Year, SUBSTRING(itime,6,2) AS Month, SUBSTRING(itime,9,2) as Day FROM '.sql_table('item')
\r
565 . ' WHERE iblog=' . $this->getID()
\r
566 . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items!
\r
567 . ' and idraft=0'; // don't show draft items
\r
570 $query .= ' and icat=' . intval($catid);
\r
572 $query .= ' GROUP BY Year, Month';
\r
573 if ($mode == 'day')
\r
577 $query .= ' ORDER BY itime DESC';
\r
580 $query .= ' LIMIT ' . intval($limit);
\r
582 $res = sql_query($query);
\r
584 while ($current = mysql_fetch_object($res)) {
\r
585 $current->itime = strtotime($current->itime); // string time -> unix timestamp
\r
587 if ($mode == 'day') {
\r
588 $archivedate = date('Y-m-d',$current->itime);
\r
589 $archive['day'] = date('d',$current->itime);
\r
590 $data['day'] = date('d',$current->itime);
\r
592 $archivedate = date('Y-m',$current->itime);
\r
594 $data['month'] = date('m',$current->itime);
\r
595 $data['year'] = date('Y',$current->itime);
\r
596 $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams);
\r
599 'PreArchiveListItem',
\r
601 'listitem' => &$data
\r
605 $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data);
\r
606 echo strftime($temp,$current->itime);
\r
610 mysql_free_result($res);
\r
612 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data);
\r
617 * Shows the list of categories using a given template
\r
619 function showCategoryList($template) {
\r
620 global $CONF, $manager;
\r
622 // determine arguments next to catids
\r
623 // I guess this can be done in a better way, but it works
\r
624 global $archive, $archivelist;
\r
626 $linkparams = array();
\r
628 $blogurl = createArchiveLink($this->getID(), $archive, '');
\r
629 $linkparams['blogid'] = $this->getID();
\r
630 $linkparams['archive'] = $archive;
\r
631 } else if ($archivelist) {
\r
632 $blogurl = createArchiveListLink($this->getID(), '');
\r
633 $linkparams['archivelist'] = $archivelist;
\r
635 $blogurl = createBlogidLink($this->getID(), '');
\r
636 $linkparams['blogid'] = $this->getID();
\r
639 //$blogurl = $this->getURL() . $qargs;
\r
640 //$blogurl = createBlogLink($this->getURL(), $linkparams);
\r
642 $template =& $manager->getTemplate($template);
\r
644 echo TEMPLATE::fill((isset($template['CATLIST_HEADER']) ? $template['CATLIST_HEADER'] : null),
\r
646 'blogid' => $this->getID(),
\r
647 'blogurl' => $blogurl,
\r
648 'self' => $CONF['Self']
\r
651 $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC';
\r
652 $res = sql_query($query);
\r
655 while ($data = mysql_fetch_assoc($res)) {
\r
656 $data['blogid'] = $this->getID();
\r
657 $data['blogurl'] = $blogurl;
\r
658 $data['catlink'] = createLink(
\r
661 'catid' => $data['catid'],
\r
662 'name' => $data['catname'],
\r
663 'extra' => $linkparams
\r
666 $data['self'] = $CONF['Self'];
\r
669 'PreCategoryListItem',
\r
671 'listitem' => &$data
\r
675 echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
\r
676 //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data);
\r
677 //echo strftime($temp, $current->itime);
\r
681 mysql_free_result($res);
\r
683 echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null),
\r
685 'blogid' => $this->getID(),
\r
686 'blogurl' => $blogurl,
\r
687 'self' => $CONF['Self']
\r
692 * Shows a list of all blogs in the system using a given template
\r
693 * ordered by number, name, shortname or description
\r
694 * in ascending or descending order
\r
696 function showBlogList($template, $bnametype, $orderby, $direction) {
\r
697 global $CONF, $manager;
\r
699 switch ($orderby) {
\r
701 $orderby='bnumber';
\r
707 $orderby='bshortname';
\r
709 case 'description':
\r
713 $orderby='bnumber';
\r
717 $direction=strtolower($direction);
\r
718 switch ($direction) {
\r
730 $template =& $manager->getTemplate($template);
\r
732 echo TEMPLATE::fill((isset($template['BLOGLIST_HEADER']) ? $template['BLOGLIST_HEADER'] : null),
\r
734 'sitename' => $CONF['SiteName'],
\r
735 'siteurl' => $CONF['IndexURL']
\r
738 $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY '.$orderby.' '.$direction;
\r
739 $res = sql_query($query);
\r
741 while ($data = mysql_fetch_assoc($res)) {
\r
745 // $list['bloglink'] = createLink('blog', array('blogid' => $data['bnumber']));
\r
746 $list['bloglink'] = createBlogidLink($data['bnumber']);
\r
748 $list['blogdesc'] = $data['bdesc'];
\r
750 $list['blogurl'] = $data['burl'];
\r
752 if ($bnametype=='shortname') {
\r
753 $list['blogname'] = $data['bshortname'];
\r
755 else { // all other cases
\r
756 $list['blogname'] = $data['bname'];
\r
762 'listitem' => &$list
\r
766 echo TEMPLATE::fill((isset($template['BLOGLIST_LISTITEM']) ? $template['BLOGLIST_LISTITEM'] : null), $list);
\r
770 mysql_free_result($res);
\r
772 echo TEMPLATE::fill((isset($template['BLOGLIST_FOOTER']) ? $template['BLOGLIST_FOOTER'] : null),
\r
774 'sitename' => $CONF['SiteName'],
\r
775 'siteurl' => $CONF['IndexURL']
\r
781 * Blogsettings functions
\r
784 function readSettings() {
\r
785 $query = 'SELECT *'
\r
786 . ' FROM '.sql_table('blog')
\r
787 . ' WHERE bnumber=' . $this->blogid;
\r
788 $res = sql_query($query);
\r
790 $this->isValid = (mysql_num_rows($res) > 0);
\r
791 if (!$this->isValid)
\r
794 $this->settings = mysql_fetch_assoc($res);
\r
797 function writeSettings() {
\r
799 // (can't use floatval since not available prior to PHP 4.2)
\r
800 $offset = $this->getTimeOffset();
\r
801 if (!is_float($offset))
\r
802 $offset = intval($offset);
\r
804 $query = 'UPDATE '.sql_table('blog')
\r
805 . " SET bname='" . addslashes($this->getName()) . "',"
\r
806 . " bshortname='". addslashes($this->getShortName()) . "',"
\r
807 . " bcomments=". intval($this->commentsEnabled()) . ","
\r
808 . " bmaxcomments=" . intval($this->getMaxComments()) . ","
\r
809 . " btimeoffset=" . $offset . ","
\r
810 . " bpublic=" . intval($this->isPublic()) . ","
\r
811 . " breqemail=" . intval($this->emailRequired()) . ","
\r
812 . " bsendping=" . intval($this->sendPing()) . ","
\r
813 . " bconvertbreaks=" . intval($this->convertBreaks()) . ","
\r
814 . " ballowpast=" . intval($this->allowPastPosting()) . ","
\r
815 . " bnotify='" . addslashes($this->getNotifyAddress()) . "',"
\r
816 . " bnotifytype=" . intval($this->getNotifyType()) . ","
\r
817 . " burl='" . addslashes($this->getURL()) . "',"
\r
818 . " bupdate='" . addslashes($this->getUpdateFile()) . "',"
\r
819 . " bdesc='" . addslashes($this->getDescription()) . "',"
\r
820 . " bdefcat=" . intval($this->getDefaultCategory()) . ","
\r
821 . " bdefskin=" . intval($this->getDefaultSkin()) . ","
\r
822 . " bincludesearch=" . intval($this->getSearchable())
\r
823 . " WHERE bnumber=" . intval($this->getID());
\r
830 // update update file if requested
\r
831 function updateUpdatefile() {
\r
832 if ($this->getUpdateFile()) {
\r
833 $f_update = fopen($this->getUpdateFile(),'w');
\r
834 fputs($f_update,$this->getCorrectTime());
\r
840 function isValidCategory($catid) {
\r
841 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid);
\r
842 $res = sql_query($query);
\r
843 return (mysql_num_rows($res) != 0);
\r
846 function getCategoryName($catid) {
\r
847 $res = sql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
\r
848 $o = mysql_fetch_object($res);
\r
852 function getCategoryDesc($catid) {
\r
853 $res = sql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid));
\r
854 $o = mysql_fetch_object($res);
\r
858 function getCategoryIdFromName($name) {
\r
859 $res = sql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"');
\r
860 if (mysql_num_rows($res) > 0) {
\r
861 $o = mysql_fetch_object($res);
\r
864 return $this->getDefaultCategory();
\r
868 function sendPing() {
\r
869 return $this->getSetting('bsendping');
\r
872 function setPingUserland($val) {
\r
873 $this->setSetting('bsendping',$val);
\r
876 function convertBreaks() {
\r
877 return $this->getSetting('bconvertbreaks');
\r
880 function insertJavaScriptInfo($authorid = '') {
\r
881 global $member, $CONF;
\r
883 if ($authorid == '')
\r
884 $authorid = $member->getID();
\r
887 <script type="text/javascript">
\r
888 setConvertBreaks(<?php echo $this->convertBreaks() ? 'true' : 'false' ?>);
\r
889 setMediaUrl("<?php echo $CONF['MediaURL']?>");
\r
890 setAuthorId(<?php echo $authorid?>);
\r
893 function setConvertBreaks($val) {
\r
894 $this->setSetting('bconvertbreaks',$val);
\r
896 function setAllowPastPosting($val) {
\r
897 $this->setSetting('ballowpast',$val);
\r
899 function allowPastPosting() {
\r
900 return $this->getSetting('ballowpast');
\r
903 function getCorrectTime($t=0) {
\r
904 if ($t == 0) $t = time();
\r
905 return ($t + 3600 * $this->getTimeOffset());
\r
908 function getName() {
\r
909 return $this->getSetting('bname');
\r
912 function getShortName() {
\r
913 return $this->getSetting('bshortname');
\r
916 function getMaxComments() {
\r
917 return $this->getSetting('bmaxcomments');
\r
920 function getNotifyAddress() {
\r
921 return $this->getSetting('bnotify');
\r
924 function getNotifyType() {
\r
925 return $this->getSetting('bnotifytype');
\r
928 function notifyOnComment() {
\r
929 $n = $this->getNotifyType();
\r
930 return (($n != 0) && (($n % 3) == 0));
\r
933 function notifyOnVote() {
\r
934 $n = $this->getNotifyType();
\r
935 return (($n != 0) && (($n % 5) == 0));
\r
938 function notifyOnNewItem() {
\r
939 $n = $this->getNotifyType();
\r
940 return (($n != 0) && (($n % 7) == 0));
\r
943 function setNotifyType($val) {
\r
944 $this->setSetting('bnotifytype',$val);
\r
948 function getTimeOffset() {
\r
949 return $this->getSetting('btimeoffset');
\r
952 function commentsEnabled() {
\r
953 return $this->getSetting('bcomments');
\r
956 function getURL() {
\r
957 return $this->getSetting('burl');
\r
960 function getDefaultSkin() {
\r
961 return $this->getSetting('bdefskin');
\r
964 function getUpdateFile() {
\r
965 return $this->getSetting('bupdate');
\r
968 function getDescription() {
\r
969 return $this->getSetting('bdesc');
\r
972 function isPublic() {
\r
973 return $this->getSetting('bpublic');
\r
976 function emailRequired() {
\r
977 return $this->getSetting('breqemail');
\r
980 function getSearchable() {
\r
981 return $this->getSetting('bincludesearch');
\r
984 function getDefaultCategory() {
\r
985 return $this->getSetting('bdefcat');
\r
988 function setPublic($val) {
\r
989 $this->setSetting('bpublic',$val);
\r
992 function setSearchable($val) {
\r
993 $this->setSetting('bincludesearch',$val);
\r
996 function setDescription($val) {
\r
997 $this->setSetting('bdesc',$val);
\r
1000 function setUpdateFile($val) {
\r
1001 $this->setSetting('bupdate',$val);
\r
1004 function setDefaultSkin($val) {
\r
1005 $this->setSetting('bdefskin',$val);
\r
1008 function setURL($val) {
\r
1009 $this->setSetting('burl',$val);
\r
1012 function setName($val) {
\r
1013 $this->setSetting('bname',$val);
\r
1016 function setShortName($val) {
\r
1017 $this->setSetting('bshortname',$val);
\r
1020 function setCommentsEnabled($val) {
\r
1021 $this->setSetting('bcomments',$val);
\r
1024 function setMaxComments($val) {
\r
1025 $this->setSetting('bmaxcomments',$val);
\r
1028 function setNotifyAddress($val) {
\r
1029 $this->setSetting('bnotify',$val);
\r
1032 function setEmailRequired($val) {
\r
1033 $this->setSetting('breqemail',$val);
\r
1036 function setTimeOffset($val) {
\r
1037 // check validity of value
\r
1038 // 1. replace , by . (common mistake)
\r
1039 $val = str_replace(',','.',$val);
\r
1040 // 2. cast to float or int
\r
1041 if (is_numeric($val) && strstr($val,'.5')) {
\r
1042 $val = (float) $val;
\r
1044 $val = intval($val);
\r
1047 $this->setSetting('btimeoffset',$val);
\r
1050 function setDefaultCategory($val) {
\r
1051 $this->setSetting('bdefcat',$val);
\r
1054 function getSetting($key) {
\r
1055 return $this->settings[$key];
\r
1058 function setSetting($key,$value) {
\r
1059 $this->settings[$key] = $value;
\r
1063 // tries to add a member to the team. Returns false if the member was already on
\r
1065 function addTeamMember($memberid, $admin) {
\r
1068 $memberid = intval($memberid);
\r
1069 $admin = intval($admin);
\r
1071 // check if member is already a member
\r
1072 $tmem = MEMBER::createFromID($memberid);
\r
1074 if ($tmem->isTeamMember($this->getID()))
\r
1078 'PreAddTeamMember',
\r
1081 'member' => &$tmem,
\r
1082 'admin' => &$admin
\r
1087 $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) '
\r
1088 . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")';
\r
1089 sql_query($query);
\r
1092 'PostAddTeamMember',
\r
1095 'member' => &$tmem,
\r
1101 $logMsg = sprintf(_TEAM_ADD_NEWTEAMMEMBER, $tmem->getDisplayName(), $memberid, $this->getName());
\r
1102 ACTIONLOG::add(INFO, $logMsg);
\r
1107 function getID() {
\r
1108 return intVal($this->blogid);
\r
1111 // returns true if there is a blog with the given shortname (static)
\r
1112 function exists($name) {
\r
1113 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"');
\r
1114 return (mysql_num_rows($r) != 0);
\r
1117 // returns true if there is a blog with the given ID (static)
\r
1118 function existsID($id) {
\r
1119 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id));
\r
1120 return (mysql_num_rows($r) != 0);
\r
1123 // flag there is a future post pending
\r
1124 function setFuturePost() {
\r
1125 $query = 'UPDATE '.sql_table('blog')
\r
1126 . " SET bfuturepost='1' WHERE bnumber=" . $this->getID();
\r
1127 sql_query($query);
\r
1130 // clear there is a future post pending
\r
1131 function clearFuturePost() {
\r
1132 $query = 'UPDATE '.sql_table('blog')
\r
1133 . " SET bfuturepost='0' WHERE bnumber=" . $this->getID();
\r
1134 sql_query($query);
\r
1137 // check if we should throw justPosted event
\r
1138 function checkJustPosted() {
\r
1141 if ($this->settings['bfuturepost'] == 1) {
\r
1142 $blogid = $this->getID();
\r
1143 $result = sql_query("SELECT * FROM " . sql_table('item')
\r
1144 . " WHERE iposted=0 AND iblog=" . $blogid . " AND itime<NOW()");
\r
1145 if (mysql_num_rows($result) > 0) {
\r
1146 // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already
\r
1147 // Note that the plugins's calling order is subject to thri order in the plugin list
\r
1151 array('blogid' => $blogid,
\r
1152 'pinged' => &$pinged
\r
1156 // clear all expired future posts
\r
1157 sql_query("UPDATE " . sql_table('item') . " SET iposted='1' WHERE iblog=" . $blogid . " AND itime<NOW()");
\r
1159 // check to see any pending future post, clear the flag is none
\r
1160 $result = sql_query("SELECT * FROM " . sql_table('item')
\r
1161 . " WHERE iposted=0 AND iblog=" . $blogid);
\r
1162 if (mysql_num_rows($result) == 0) {
\r
1163 $this->clearFuturePost();
\r
1170 * Shows the given list of items for this blog
\r
1172 * @param $itemarray
\r
1173 * array of item numbers to be displayed
\r
1174 * @param $template
\r
1175 * String representing the template _NAME_ (!)
\r
1176 * @param $highlight
\r
1177 * contains a query that should be highlighted
\r
1178 * @param $comments
\r
1179 * 1=show comments 0=don't show comments
\r
1180 * @param $dateheads
\r
1181 * 1=show dateheads 0=don't show dateheads
\r
1183 * amount of items shown
\r
1185 function readLogFromList($itemarray, $template, $highlight = '', $comments = 1, $dateheads = 1) {
\r
1187 $query = $this->getSqlItemList($itemarray);
\r
1189 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads);
\r
1193 * Returns the SQL query used to fill out templates for a list of items
\r
1195 * @param $itemarray
\r
1196 * an array holding the item numbers of the items to be displayed
\r
1198 * either a full SQL query, or an empty string
\r
1200 * No LIMIT clause is added. (caller should add this if multiple pages are requested)
\r
1202 function getSqlItemList($itemarray)
\r
1204 if (!is_array($itemarray)) return '';
\r
1206 foreach ($itemarray as $value) {
\r
1207 if (intval($value)) $items[] = intval($value);
\r
1209 if (!count($items)) return '';
\r
1210 //$itemlist = implode(',',$items);
\r
1211 $i = count($items);
\r
1213 foreach ($items as $value) {
\r
1216 . ' i.inumber as itemid,'
\r
1217 . ' i.ititle as title,'
\r
1218 . ' i.ibody as body,'
\r
1219 . ' m.mname as author,'
\r
1220 . ' m.mrealname as authorname,'
\r
1222 . ' i.imore as more,'
\r
1223 . ' m.mnumber as authorid,'
\r
1224 . ' m.memail as authormail,'
\r
1225 . ' m.murl as authorurl,'
\r
1226 . ' c.cname as category,'
\r
1227 . ' i.icat as catid,'
\r
1228 . ' i.iclosed as closed';
\r
1230 $query .= ' FROM '
\r
1231 . sql_table('item') . ' as i, '
\r
1232 . sql_table('member') . ' as m, '
\r
1233 . sql_table('category').' as c'
\r
1235 . ' i.iblog = ' . $this->blogid
\r
1236 . ' and i.iauthor = m.mnumber'
\r
1237 . ' and i.icat = c.catid'
\r
1238 . ' and i.idraft = 0' // exclude drafts
\r
1239 // don't show future items
\r
1240 . ' and i.itime <= ' . mysqldate($this->getCorrectTime());
\r
1242 //$query .= ' and i.inumber IN ('.$itemlist.')';
\r
1243 $query .= ' and i.inumber = '.intval($value);
\r
1246 if ($i) $query .= ' UNION ';
\r