00001 <?php 00002 00003 /* 00004 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 00005 * Copyright (C) 2002-2007 The Nucleus Group 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation; either version 2 00010 * of the License, or (at your option) any later version. 00011 * (see nucleus/documentation/index.html#license for more info) 00012 */ 00023 if ( !function_exists('requestVar') ) exit; 00024 require_once dirname(__FILE__) . '/ITEMACTIONS.php'; 00025 00026 class BLOG { 00027 00028 // blog id 00029 var $blogid; 00030 00031 // ID of currently selected category 00032 var $selectedcatid; 00033 00034 // After creating an object of the blog class, contains true if the BLOG object is 00035 // valid (the blog exists) 00036 var $isValid; 00037 00038 // associative array, containing all blogsettings (use the get/set functions instead) 00039 var $settings; 00040 00046 function BLOG($id) { 00047 $this->blogid = intval($id); 00048 $this->readSettings(); 00049 00050 // try to set catid 00051 // (the parse functions in SKIN.php will override this, so it's mainly useless) 00052 global $catid; 00053 $this->setSelectedCategory($catid); 00054 } 00055 00068 function readLog($template, $amountEntries, $offset = 0, $startpos = 0) { 00069 return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos); 00070 } 00071 00082 function showArchive($templatename, $year, $month, $day=0) { 00083 00084 // create extra where clause for select query 00085 if ($day == 0) { 00086 $timestamp_start = mktime(0,0,0,$month,1,$year); 00087 $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12 00088 } else { 00089 $timestamp_start = mktime(0,0,0,$month,$day,$year); 00090 $timestamp_end = mktime(0,0,0,$month,$day+1,$year); 00091 } 00092 $extra_query = ' and i.itime>=' . mysqldate($timestamp_start) 00093 . ' and i.itime<' . mysqldate($timestamp_end); 00094 00095 00096 $this->readLogAmount($templatename,0,$extra_query,'',1,1); 00097 00098 } 00099 00100 00101 // sets/gets current category (only when category exists) 00102 function setSelectedCategory($catid) { 00103 if ($this->isValidCategory($catid) || (intval($catid) == 0)) 00104 $this->selectedcatid = intval($catid); 00105 } 00106 00107 function setSelectedCategoryByName($catname) { 00108 $this->setSelectedCategory($this->getCategoryIdFromName($catname)); 00109 } 00110 00111 function getSelectedCategory() { 00112 return $this->selectedcatid; 00113 } 00114 00135 function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) { 00136 00137 $query = $this->getSqlBlog($extraQuery); 00138 00139 if ($amountEntries > 0) { 00140 // $offset zou moeten worden: 00141 // (($startpos / $amountentries) + 1) * $offset ... later testen ... 00142 $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries); 00143 } 00144 return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads); 00145 } 00146 00147 function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) { 00148 global $CONF, $manager; 00149 00150 $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit'); 00151 if ($lastVisit != 0) 00152 $lastVisit = $this->getCorrectTime($lastVisit); 00153 00154 // set templatename as global variable (so plugins can access it) 00155 global $currentTemplateName; 00156 $currentTemplateName = $templateName; 00157 00158 $template =& $manager->getTemplate($templateName); 00159 00160 // create parser object & action handler 00161 $actions =& new ITEMACTIONS($this); 00162 $parser =& new PARSER($actions->getDefinedActions(),$actions); 00163 $actions->setTemplate($template); 00164 $actions->setHighlight($highlight); 00165 $actions->setLastVisit($lastVisit); 00166 $actions->setParser($parser); 00167 $actions->setShowComments($comments); 00168 00169 // execute query 00170 $items = sql_query($query); 00171 00172 // loop over all items 00173 $old_date = 0; 00174 while ($item = mysql_fetch_object($items)) { 00175 00176 $item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp 00177 00178 // action handler needs to know the item we're handling 00179 $actions->setCurrentItem($item); 00180 00181 // add date header if needed 00182 if ($dateheads) { 00183 $new_date = date('dFY',$item->timestamp); 00184 if ($new_date != $old_date) { 00185 // unless this is the first time, write date footer 00186 $timestamp = $item->timestamp; 00187 if ($old_date != 0) { 00188 $oldTS = strtotime($old_date); 00189 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS)); 00190 $tmp_footer = strftime($template['DATE_FOOTER'], $oldTS); 00191 $parser->parse($tmp_footer); 00192 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS)); 00193 } 00194 $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp)); 00195 // note, to use templatvars in the dateheader, the %-characters need to be doubled in 00196 // order to be preserved by strftime 00197 $tmp_header = strftime((isset($template['DATE_HEADER']) ? $template['DATE_HEADER'] : null), $timestamp); 00198 $parser->parse($tmp_header); 00199 $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp)); 00200 } 00201 $old_date = $new_date; 00202 } 00203 00204 // parse item 00205 $parser->parse($template['ITEM_HEADER']); 00206 $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item)); 00207 $parser->parse($template['ITEM']); 00208 $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item)); 00209 $parser->parse($template['ITEM_FOOTER']); 00210 00211 } 00212 00213 $numrows = mysql_num_rows($items); 00214 00215 // add another date footer if there was at least one item 00216 if (($numrows > 0) && $dateheads) { 00217 $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date))); 00218 $parser->parse($template['DATE_FOOTER']); 00219 $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date))); 00220 } 00221 00222 mysql_free_result($items); // free memory 00223 00224 return $numrows; 00225 00226 } 00227 00228 function showOneitem($itemid, $template, $highlight) { 00229 $extraQuery = ' and inumber=' . intval($itemid); 00230 00231 return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0); 00232 } 00233 00234 00238 function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft, $posted='1') { 00239 global $manager; 00240 00241 $blogid = intval($blogid); 00242 $authorid = intval($authorid); 00243 $title = $title; 00244 $body = $body; 00245 $more = $more; 00246 $catid = intval($catid); 00247 00248 // convert newlines to <br /> 00249 if ($this->convertBreaks()) { 00250 $body = addBreaks($body); 00251 $more = addBreaks($more); 00252 } 00253 00254 if ($closed != '1') $closed = '0'; 00255 if ($draft != '0') $draft = '1'; 00256 00257 if (!$this->isValidCategory($catid)) 00258 $catid = $this->getDefaultCategory(); 00259 00260 if ($timestamp > $this->getCorrectTime()) 00261 $isFuture = 1; 00262 00263 $timestamp = date('Y-m-d H:i:s',$timestamp); 00264 00265 $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid)); 00266 00267 $title = addslashes($title); 00268 $body = addslashes($body); 00269 $more = addslashes($more); 00270 00271 $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT, IPOSTED) ' 00272 . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid, $posted)"; 00273 sql_query($query); 00274 $itemid = mysql_insert_id(); 00275 00276 $manager->notify('PostAddItem',array('itemid' => $itemid)); 00277 00278 if (!$draft) 00279 $this->updateUpdateFile(); 00280 00281 // send notification mail 00282 if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem()) 00283 $this->sendNewItemNotification($itemid, stripslashes($title), stripslashes($body)); 00284 00285 return $itemid; 00286 } 00287 00288 function sendNewItemNotification($itemid, $title, $body) { 00289 global $CONF, $member; 00290 00291 // create text version of html post 00292 $ascii = toAscii($body); 00293 00294 $mailto_msg = _NOTIFY_NI_MSG . " \n"; 00295 // $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n"; 00296 $temp = parse_url($CONF['Self']); 00297 if ($temp['scheme']) { 00298 $mailto_msg .= createItemLink($itemid) . "\n\n"; 00299 } else { 00300 $tempurl = $this->getURL(); 00301 if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') { 00302 $mailto_msg .= $tempurl . '?itemid=' . $itemid . "\n\n"; 00303 } else { 00304 $mailto_msg .= $tempurl . '/?itemid=' . $itemid . "\n\n"; 00305 } 00306 } 00307 $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n"; 00308 $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n"; 00309 $mailto_msg .= getMailFooter(); 00310 00311 $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE; 00312 00313 $frommail = $member->getNotifyFromMailAddress(); 00314 00315 $notify =& new NOTIFICATION($this->getNotifyAddress()); 00316 $notify->notify($mailto_title, $mailto_msg , $frommail); 00317 00318 00319 00320 } 00321 00322 00336 function createNewCategory($catName = '', $catDescription = 'New category') { 00337 global $member, $manager; 00338 00339 if ($member->blogAdminRights($this->getID())) { 00340 // generate 00341 if ($catName == '') 00342 { 00343 $catName = 'newcat'; 00344 $i = 1; 00345 00346 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID()); 00347 while (mysql_num_rows($res) > 0) 00348 { 00349 $i++; 00350 $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID()); 00351 } 00352 00353 $catName = $catName . $i; 00354 } 00355 00356 $manager->notify( 00357 'PreAddCategory', 00358 array( 00359 'blog' => &$this, 00360 'name' => &$catName, 00361 'description' => $catDescription 00362 ) 00363 ); 00364 00365 $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')"; 00366 sql_query($query); 00367 $catid = mysql_insert_id(); 00368 00369 $manager->notify( 00370 'PostAddCategory', 00371 array( 00372 'blog' => &$this, 00373 'name' => $catName, 00374 'description' => $catDescription, 00375 'catid' => $catid 00376 ) 00377 ); 00378 00379 return $catid; 00380 } else { 00381 return 0; 00382 } 00383 00384 } 00385 00386 00403 function search($query, $template, $amountMonths, $maxresults, $startpos) { 00404 global $CONF, $manager; 00405 00406 $highlight = ''; 00407 $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight); 00408 00409 if ($sqlquery == '') 00410 { 00411 // no query -> show everything 00412 $extraquery = ''; 00413 $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1); 00414 } else { 00415 00416 // add LIMIT to query (to split search results into pages) 00417 if (intval($maxresults > 0)) 00418 $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults); 00419 00420 // show results 00421 $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1); 00422 00423 // when no results were found, show a message 00424 if ($amountfound == 0) 00425 { 00426 $template =& $manager->getTemplate($template); 00427 $vars = array( 00428 'query' => htmlspecialchars($query), 00429 'blogid' => $this->getID() 00430 ); 00431 echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars); 00432 } 00433 } 00434 00435 return $amountfound; 00436 } 00437 00454 function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '') 00455 { 00456 $searchclass =& new SEARCH($query); 00457 00458 $highlight = $searchclass->inclusive; 00459 00460 // if querystring is empty, return empty string 00461 if ($searchclass->inclusive == '') 00462 return ''; 00463 00464 00465 $where = $searchclass->boolean_sql_where('ititle,ibody,imore'); 00466 $select = $searchclass->boolean_sql_select('ititle,ibody,imore'); 00467 00468 // get list of blogs to search 00469 $blogs = $searchclass->blogs; // array containing blogs that always need to be included 00470 $blogs[] = $this->getID(); // also search current blog (duh) 00471 $blogs = array_unique($blogs); // remove duplicates 00472 $selectblogs = ''; 00473 if (count($blogs) > 0) 00474 $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')'; 00475 00476 if ($mode == '') 00477 { 00478 $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'; 00479 if ($select) 00480 $query .= ', '.$select. ' as score '; 00481 } else { 00482 $query = 'SELECT COUNT(*) as result '; 00483 } 00484 00485 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' 00486 . ' WHERE i.iauthor=m.mnumber' 00487 . ' and i.icat=c.catid' 00488 . ' and i.idraft=0' // exclude drafts 00489 . $selectblogs 00490 // don't show future items 00491 . ' and i.itime<=' . mysqldate($this->getCorrectTime()) 00492 . ' and '.$where; 00493 00494 // take into account amount of months to search 00495 if ($amountMonths > 0) 00496 { 00497 $localtime = getdate($this->getCorrectTime()); 00498 $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']); 00499 $query .= ' and i.itime>' . mysqldate($timestamp_start); 00500 } 00501 00502 if ($mode == '') 00503 { 00504 if ($select) 00505 $query .= ' ORDER BY score DESC'; 00506 else 00507 $query .= ' ORDER BY i.itime DESC '; 00508 } 00509 00510 return $query; 00511 } 00512 00523 function getSqlBlog($extraQuery, $mode = '') 00524 { 00525 if ($mode == '') 00526 $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'; 00527 else 00528 $query = 'SELECT COUNT(*) as result '; 00529 00530 $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' 00531 . ' WHERE i.iblog='.$this->blogid 00532 . ' and i.iauthor=m.mnumber' 00533 . ' and i.icat=c.catid' 00534 . ' and i.idraft=0' // exclude drafts 00535 // don't show future items 00536 . ' and i.itime<=' . mysqldate($this->getCorrectTime()); 00537 00538 if ($this->getSelectedCategory()) 00539 $query .= ' and i.icat=' . $this->getSelectedCategory() . ' '; 00540 00541 00542 $query .= $extraQuery; 00543 00544 if ($mode == '') 00545 $query .= ' ORDER BY i.itime DESC'; 00546 00547 return $query; 00548 } 00549 00553 function showArchiveList($template, $mode = 'month', $limit = 0) { 00554 global $CONF, $catid, $manager; 00555 00556 if ($catid) 00557 $linkparams = array('catid' => $catid); 00558 00559 $template =& $manager->getTemplate($template); 00560 $data['blogid'] = $this->getID(); 00561 00562 echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data); 00563 00564 $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') 00565 . ' WHERE iblog=' . $this->getID() 00566 . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items! 00567 . ' and idraft=0'; // don't show draft items 00568 00569 if ($catid) 00570 $query .= ' and icat=' . intval($catid); 00571 00572 $query .= ' GROUP BY Year, Month'; 00573 if ($mode == 'day') 00574 $query .= ', Day'; 00575 00576 00577 $query .= ' ORDER BY itime DESC'; 00578 00579 if ($limit > 0) 00580 $query .= ' LIMIT ' . intval($limit); 00581 00582 $res = sql_query($query); 00583 00584 while ($current = mysql_fetch_object($res)) { 00585 $current->itime = strtotime($current->itime); // string time -> unix timestamp 00586 00587 if ($mode == 'day') { 00588 $archivedate = date('Y-m-d',$current->itime); 00589 $archive['day'] = date('d',$current->itime); 00590 } else { 00591 $archivedate = date('Y-m',$current->itime); 00592 } 00593 $data['month'] = date('m',$current->itime); 00594 $data['year'] = date('Y',$current->itime); 00595 $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams); 00596 00597 $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data); 00598 echo strftime($temp,$current->itime); 00599 00600 } 00601 00602 mysql_free_result($res); 00603 00604 echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data); 00605 } 00606 00607 00611 function showCategoryList($template) { 00612 global $CONF, $manager; 00613 00614 // determine arguments next to catids 00615 // I guess this can be done in a better way, but it works 00616 global $archive, $archivelist; 00617 00618 $linkparams = array(); 00619 if ($archive) { 00620 $blogurl = createArchiveLink($this->getID(), $archive, ''); 00621 $linkparams['blogid'] = $this->getID(); 00622 $linkparams['archive'] = $archive; 00623 } else if ($archivelist) { 00624 $blogurl = createArchiveListLink($this->getID(), ''); 00625 $linkparams['archivelist'] = $archivelist; 00626 } else { 00627 $blogurl = createBlogidLink($this->getID(), ''); 00628 $linkparams['blogid'] = $this->getID(); 00629 } 00630 00631 //$blogurl = $this->getURL() . $qargs; 00632 //$blogurl = createBlogLink($this->getURL(), $linkparams); 00633 00634 $template =& $manager->getTemplate($template); 00635 00636 echo TEMPLATE::fill((isset($template['CATLIST_HEADER']) ? $template['CATLIST_HEADER'] : null), 00637 array( 00638 'blogid' => $this->getID(), 00639 'blogurl' => $blogurl, 00640 'self' => $CONF['Self'] 00641 )); 00642 00643 $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC'; 00644 $res = sql_query($query); 00645 00646 00647 while ($data = mysql_fetch_assoc($res)) { 00648 $data['blogid'] = $this->getID(); 00649 $data['blogurl'] = $blogurl; 00650 $data['catlink'] = createLink( 00651 'category', 00652 array( 00653 'catid' => $data['catid'], 00654 'name' => $data['catname'], 00655 'extra' => $linkparams 00656 ) 00657 ); 00658 $data['self'] = $CONF['Self']; 00659 00660 echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data); 00661 //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data); 00662 //echo strftime($temp, $current->itime); 00663 00664 } 00665 00666 mysql_free_result($res); 00667 00668 echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null), 00669 array( 00670 'blogid' => $this->getID(), 00671 'blogurl' => $blogurl, 00672 'self' => $CONF['Self'] 00673 )); 00674 } 00675 00679 function showBlogList($template, $bnametype) { 00680 global $CONF, $manager; 00681 00682 $template =& $manager->getTemplate($template); 00683 00684 echo TEMPLATE::fill((isset($template['BLOGLIST_HEADER']) ? $template['BLOGLIST_HEADER'] : null), 00685 array( 00686 'sitename' => $CONF['SiteName'], 00687 'siteurl' => $CONF['IndexURL'] 00688 )); 00689 00690 $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY bnumber ASC'; 00691 $res = sql_query($query); 00692 00693 while ($data = mysql_fetch_assoc($res)) { 00694 00695 $list = array(); 00696 00697 // $list['bloglink'] = createLink('blog', array('blogid' => $data['bnumber'])); 00698 $list['bloglink'] = createBlogidLink($data['bnumber']); 00699 00700 $list['blogdesc'] = $data['bdesc']; 00701 00702 if ($bnametype=='shortname') { 00703 $list['blogname'] = $data['bshortname']; 00704 } 00705 else { // all other cases 00706 $list['blogname'] = $data['bname']; 00707 } 00708 00709 echo TEMPLATE::fill((isset($template['BLOGLIST_LISTITEM']) ? $template['BLOGLIST_LISTITEM'] : null), $list); 00710 00711 } 00712 00713 mysql_free_result($res); 00714 00715 echo TEMPLATE::fill((isset($template['BLOGLIST_FOOTER']) ? $template['BLOGLIST_FOOTER'] : null), 00716 array( 00717 'sitename' => $CONF['SiteName'], 00718 'siteurl' => $CONF['IndexURL'] 00719 )); 00720 00721 } 00722 00727 function readSettings() { 00728 $query = 'SELECT *' 00729 . ' FROM '.sql_table('blog') 00730 . ' WHERE bnumber=' . $this->blogid; 00731 $res = sql_query($query); 00732 00733 $this->isValid = (mysql_num_rows($res) > 0); 00734 if (!$this->isValid) 00735 return; 00736 00737 $this->settings = mysql_fetch_assoc($res); 00738 } 00739 00740 function writeSettings() { 00741 00742 // (can't use floatval since not available prior to PHP 4.2) 00743 $offset = $this->getTimeOffset(); 00744 if (!is_float($offset)) 00745 $offset = intval($offset); 00746 00747 $query = 'UPDATE '.sql_table('blog') 00748 . " SET bname='" . addslashes($this->getName()) . "'," 00749 . " bshortname='". addslashes($this->getShortName()) . "'," 00750 . " bcomments=". intval($this->commentsEnabled()) . "," 00751 . " bmaxcomments=" . intval($this->getMaxComments()) . "," 00752 . " btimeoffset=" . $offset . "," 00753 . " bpublic=" . intval($this->isPublic()) . "," 00754 . " breqemail=" . intval($this->emailRequired()) . "," 00755 . " bsendping=" . intval($this->sendPing()) . "," 00756 . " bconvertbreaks=" . intval($this->convertBreaks()) . "," 00757 . " ballowpast=" . intval($this->allowPastPosting()) . "," 00758 . " bnotify='" . addslashes($this->getNotifyAddress()) . "'," 00759 . " bnotifytype=" . intval($this->getNotifyType()) . "," 00760 . " burl='" . addslashes($this->getURL()) . "'," 00761 . " bupdate='" . addslashes($this->getUpdateFile()) . "'," 00762 . " bdesc='" . addslashes($this->getDescription()) . "'," 00763 . " bdefcat=" . intval($this->getDefaultCategory()) . "," 00764 . " bdefskin=" . intval($this->getDefaultSkin()) . "," 00765 . " bincludesearch=" . intval($this->getSearchable()) 00766 . " WHERE bnumber=" . intval($this->getID()); 00767 sql_query($query); 00768 00769 } 00770 00771 00772 00773 // update update file if requested 00774 function updateUpdatefile() { 00775 if ($this->getUpdateFile()) { 00776 $f_update = fopen($this->getUpdateFile(),'w'); 00777 fputs($f_update,$this->getCorrectTime()); 00778 fclose($f_update); 00779 } 00780 00781 } 00782 00783 function isValidCategory($catid) { 00784 $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid); 00785 $res = sql_query($query); 00786 return (mysql_num_rows($res) != 0); 00787 } 00788 00789 function getCategoryName($catid) { 00790 $res = sql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid)); 00791 $o = mysql_fetch_object($res); 00792 return $o->cname; 00793 } 00794 00795 function getCategoryDesc($catid) { 00796 $res = sql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid)); 00797 $o = mysql_fetch_object($res); 00798 return $o->cdesc; 00799 } 00800 00801 function getCategoryIdFromName($name) { 00802 $res = sql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"'); 00803 if (mysql_num_rows($res) > 0) { 00804 $o = mysql_fetch_object($res); 00805 return $o->catid; 00806 } else { 00807 return $this->getDefaultCategory(); 00808 } 00809 } 00810 00811 function sendPing() { 00812 return $this->getSetting('bsendping'); 00813 } 00814 00815 function setPingUserland($val) { 00816 $this->setSetting('bsendping',$val); 00817 } 00818 00819 function convertBreaks() { 00820 return $this->getSetting('bconvertbreaks'); 00821 } 00822 00823 function insertJavaScriptInfo($authorid = '') { 00824 global $member, $CONF; 00825 00826 if ($authorid == '') 00827 $authorid = $member->getID(); 00828 00829 ?> 00830 <script type="text/javascript"> 00831 setConvertBreaks(<?php echo $this->convertBreaks() ? 'true' : 'false' ?>); 00832 setMediaUrl("<?php echo $CONF['MediaURL']?>"); 00833 setAuthorId(<?php echo $authorid?>); 00834 </script><?php } 00835 00836 function setConvertBreaks($val) { 00837 $this->setSetting('bconvertbreaks',$val); 00838 } 00839 function setAllowPastPosting($val) { 00840 $this->setSetting('ballowpast',$val); 00841 } 00842 function allowPastPosting() { 00843 return $this->getSetting('ballowpast'); 00844 } 00845 00846 function getCorrectTime($t=0) { 00847 if ($t == 0) $t = time(); 00848 return ($t + 3600 * $this->getTimeOffset()); 00849 } 00850 00851 function getName() { 00852 return $this->getSetting('bname'); 00853 } 00854 00855 function getShortName() { 00856 return $this->getSetting('bshortname'); 00857 } 00858 00859 function getMaxComments() { 00860 return $this->getSetting('bmaxcomments'); 00861 } 00862 00863 function getNotifyAddress() { 00864 return $this->getSetting('bnotify'); 00865 } 00866 00867 function getNotifyType() { 00868 return $this->getSetting('bnotifytype'); 00869 } 00870 00871 function notifyOnComment() { 00872 $n = $this->getNotifyType(); 00873 return (($n != 0) && (($n % 3) == 0)); 00874 } 00875 00876 function notifyOnVote() { 00877 $n = $this->getNotifyType(); 00878 return (($n != 0) && (($n % 5) == 0)); 00879 } 00880 00881 function notifyOnNewItem() { 00882 $n = $this->getNotifyType(); 00883 return (($n != 0) && (($n % 7) == 0)); 00884 } 00885 00886 function setNotifyType($val) { 00887 $this->setSetting('bnotifytype',$val); 00888 } 00889 00890 00891 function getTimeOffset() { 00892 return $this->getSetting('btimeoffset'); 00893 } 00894 00895 function commentsEnabled() { 00896 return $this->getSetting('bcomments'); 00897 } 00898 00899 function getURL() { 00900 return $this->getSetting('burl'); 00901 } 00902 00903 function getDefaultSkin() { 00904 return $this->getSetting('bdefskin'); 00905 } 00906 00907 function getUpdateFile() { 00908 return $this->getSetting('bupdate'); 00909 } 00910 00911 function getDescription() { 00912 return $this->getSetting('bdesc'); 00913 } 00914 00915 function isPublic() { 00916 return $this->getSetting('bpublic'); 00917 } 00918 00919 function emailRequired() { 00920 return $this->getSetting('breqemail'); 00921 } 00922 00923 function getSearchable() { 00924 return $this->getSetting('bincludesearch'); 00925 } 00926 00927 function getDefaultCategory() { 00928 return $this->getSetting('bdefcat'); 00929 } 00930 00931 function setPublic($val) { 00932 $this->setSetting('bpublic',$val); 00933 } 00934 00935 function setSearchable($val) { 00936 $this->setSetting('bincludesearch',$val); 00937 } 00938 00939 function setDescription($val) { 00940 $this->setSetting('bdesc',$val); 00941 } 00942 00943 function setUpdateFile($val) { 00944 $this->setSetting('bupdate',$val); 00945 } 00946 00947 function setDefaultSkin($val) { 00948 $this->setSetting('bdefskin',$val); 00949 } 00950 00951 function setURL($val) { 00952 $this->setSetting('burl',$val); 00953 } 00954 00955 function setName($val) { 00956 $this->setSetting('bname',$val); 00957 } 00958 00959 function setShortName($val) { 00960 $this->setSetting('bshortname',$val); 00961 } 00962 00963 function setCommentsEnabled($val) { 00964 $this->setSetting('bcomments',$val); 00965 } 00966 00967 function setMaxComments($val) { 00968 $this->setSetting('bmaxcomments',$val); 00969 } 00970 00971 function setNotifyAddress($val) { 00972 $this->setSetting('bnotify',$val); 00973 } 00974 00975 function setEmailRequired($val) { 00976 $this->setSetting('breqemail',$val); 00977 } 00978 00979 function setTimeOffset($val) { 00980 // check validity of value 00981 // 1. replace , by . (common mistake) 00982 $val = str_replace(',','.',$val); 00983 // 2. cast to float or int 00984 if (is_numeric($val) && strstr($val,'.5')) { 00985 $val = (float) $val; 00986 } else { 00987 $val = intval($val); 00988 } 00989 00990 $this->setSetting('btimeoffset',$val); 00991 } 00992 00993 function setDefaultCategory($val) { 00994 $this->setSetting('bdefcat',$val); 00995 } 00996 00997 function getSetting($key) { 00998 return $this->settings[$key]; 00999 } 01000 01001 function setSetting($key,$value) { 01002 $this->settings[$key] = $value; 01003 } 01004 01005 01006 // tries to add a member to the team. Returns false if the member was already on 01007 // the team 01008 function addTeamMember($memberid, $admin) { 01009 global $manager; 01010 01011 $memberid = intval($memberid); 01012 $admin = intval($admin); 01013 01014 // check if member is already a member 01015 $tmem = MEMBER::createFromID($memberid); 01016 01017 if ($tmem->isTeamMember($this->getID())) 01018 return 0; 01019 01020 $manager->notify( 01021 'PreAddTeamMember', 01022 array( 01023 'blog' => &$this, 01024 'member' => &$tmem, 01025 'admin' => &$admin 01026 ) 01027 ); 01028 01029 // add to team 01030 $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) ' 01031 . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")'; 01032 sql_query($query); 01033 01034 $manager->notify( 01035 'PostAddTeamMember', 01036 array( 01037 'blog' => &$this, 01038 'member' => &$tmem, 01039 'admin' => $admin 01040 ) 01041 01042 ); 01043 01044 ACTIONLOG::add(INFO, 'Added ' . $tmem->getDisplayName() . ' (ID=' . 01045 $memberid .') to the team of blog "' . $this->getName() . '"'); 01046 01047 return 1; 01048 } 01049 01050 function getID() { 01051 return intVal($this->blogid); 01052 } 01053 01054 // returns true if there is a blog with the given shortname (static) 01055 function exists($name) { 01056 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"'); 01057 return (mysql_num_rows($r) != 0); 01058 } 01059 01060 // returns true if there is a blog with the given ID (static) 01061 function existsID($id) { 01062 $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id)); 01063 return (mysql_num_rows($r) != 0); 01064 } 01065 01066 // flag there is a future post pending 01067 function setFuturePost() { 01068 $query = 'UPDATE '.sql_table('blog') 01069 . " SET bfuturepost='1' WHERE bnumber=" . $this->getID(); 01070 sql_query($query); 01071 } 01072 01073 // clear there is a future post pending 01074 function clearFuturePost() { 01075 $query = 'UPDATE '.sql_table('blog') 01076 . " SET bfuturepost='0' WHERE bnumber=" . $this->getID(); 01077 sql_query($query); 01078 } 01079 01080 // check if we should throw justPosted event 01081 function checkJustPosted() { 01082 global $manager; 01083 01084 if ($this->settings['bfuturepost'] == 1) { 01085 $blogid = $this->getID(); 01086 $result = sql_query("SELECT * FROM " . sql_table('item') 01087 . " WHERE iposted=0 AND iblog=" . $blogid . " AND itime<NOW()"); 01088 if (mysql_num_rows($result) > 0) { 01089 // This $pinged is allow a plugin to tell other hook to the event that a ping is sent already 01090 // Note that the plugins's calling order is subject to thri order in the plugin list 01091 $pinged = false; 01092 $manager->notify( 01093 'JustPosted', 01094 array('blogid' => $blogid, 01095 'pinged' => &$pinged 01096 ) 01097 ); 01098 01099 // clear all expired future posts 01100 sql_query("UPDATE " . sql_table('item') . " SET iposted='1' WHERE iblog=" . $blogid . " AND itime<NOW()"); 01101 01102 // check to see any pending future post, clear the flag is none 01103 $result = sql_query("SELECT * FROM " . sql_table('item') 01104 . " WHERE iposted=0 AND iblog=" . $blogid); 01105 if (mysql_num_rows($result) == 0) { 01106 $this->clearFuturePost(); 01107 } 01108 } 01109 } 01110 } 01111 01112 } 01113 01114 ?>