From: kimitake Date: Thu, 22 Mar 2007 09:24:07 +0000 (+0000) Subject: sync with UTF-8 X-Git-Tag: release-3-3~49 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=929760acf97e0c2746af7d93e19baad9b04071a6;hp=5f51158f1d82f4f7262a7252fca74511070e1b47;p=nucleus-jp%2Fnucleus-jp-ancient.git sync with UTF-8 git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/nucleus-jp/trunk@241 1ca29b6e-896d-4ea0-84a5-967f57386b96 --- diff --git a/euc/action.php b/euc/action.php index 9c1572e..e403243 100755 --- a/euc/action.php +++ b/euc/action.php @@ -1,32 +1,36 @@ doAction($action); -if ($errorInfo) -{ - doError($errorInfo['message'], new SKIN($errorInfo['skinid'])); +if ($errorInfo) { + doError($errorInfo['message'], new SKIN($errorInfo['skinid']) ); } ?> \ No newline at end of file diff --git a/euc/atom.php b/euc/atom.php index f4e9c35..9786f16 100755 --- a/euc/atom.php +++ b/euc/atom.php @@ -1,19 +1,24 @@ +?> \ No newline at end of file diff --git a/euc/config.php b/euc/config.php index f21b3ec..300d9db 100755 --- a/euc/config.php +++ b/euc/config.php @@ -1,38 +1,38 @@ - \ No newline at end of file diff --git a/euc/createaccount.html b/euc/createaccount.html index 9ca959b..a5575da 100755 --- a/euc/createaccount.html +++ b/euc/createaccount.html @@ -37,4 +37,4 @@ - + \ No newline at end of file diff --git a/euc/nucleus/libs/ACTIONS.php b/euc/nucleus/libs/ACTIONS.php index d54ada3..cdb3624 100644 --- a/euc/nucleus/libs/ACTIONS.php +++ b/euc/nucleus/libs/ACTIONS.php @@ -18,8 +18,8 @@ * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2007 The Nucleus Group - * @version $Id: ACTIONS.php,v 1.1 2007-03-22 08:36:52 kimitake Exp $ - * @version $NucleusJP: ACTIONS.php,v 1.6 2007/03/13 05:17:37 shizuki Exp $ + * @version $Id: ACTIONS.php,v 1.2 2007-03-22 09:23:58 kimitake Exp $ + * @version $NucleusJP: ACTIONS.php,v 1.1 2007/03/22 08:36:52 kimitake Exp $ */ class ACTIONS extends BaseActions { @@ -389,7 +389,7 @@ class ACTIONS extends BaseActions { function parse_additemform() { global $blog, $CONF; $this->formdata = array( - 'adminurl' => htmlspecialchars($CONF['AdminURL']), + 'adminurl' => htmlspecialchars($CONF['AdminURL'],ENT_QUOTES), 'catid' => $blog->getDefaultCategory() ); $blog->InsertJavaScriptInfo(); @@ -518,19 +518,19 @@ class ACTIONS extends BaseActions { global $blog; switch($which) { case 'id': - echo htmlspecialchars($blog->getID()); + echo htmlspecialchars($blog->getID(),ENT_QUOTES); break; case 'url': - echo htmlspecialchars($blog->getURL()); + echo htmlspecialchars($blog->getURL(),ENT_QUOTES); break; case 'name': - echo htmlspecialchars($blog->getName()); + echo htmlspecialchars($blog->getName(),ENT_QUOTES); break; case 'desc': - echo htmlspecialchars($blog->getDescription()); + echo htmlspecialchars($blog->getDescription(),ENT_QUOTES); break; case 'short': - echo htmlspecialchars($blog->getShortName()); + echo htmlspecialchars($blog->getShortName(),ENT_QUOTES); break; } } @@ -627,7 +627,7 @@ class ACTIONS extends BaseActions { // note: createLink returns an HTML encoded URL } else { // HTML encode URL - $destinationurl = htmlspecialchars($destinationurl); + $destinationurl = htmlspecialchars($destinationurl,ENT_QUOTES); } // values to prefill @@ -643,12 +643,12 @@ class ACTIONS extends BaseActions { $this->formdata = array( 'destinationurl' => $destinationurl, // url is already HTML encoded - 'actionurl' => htmlspecialchars($actionurl), + 'actionurl' => htmlspecialchars($actionurl,ENT_QUOTES), 'itemid' => $itemid, - 'user' => htmlspecialchars($user), - 'userid' => htmlspecialchars($userid), - 'email' => htmlspecialchars($email), - 'body' => htmlspecialchars($body), + 'user' => htmlspecialchars($user,ENT_QUOTES), + 'userid' => htmlspecialchars($userid,ENT_QUOTES), + 'email' => htmlspecialchars($email,ENT_QUOTES), + 'body' => htmlspecialchars($body,ENT_QUOTES), 'membername' => $member->getDisplayName(), 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':'' ); @@ -758,7 +758,7 @@ class ACTIONS extends BaseActions { * Parse skinvar imagetext */ function parse_imagetext() { - echo htmlspecialchars(requestVar('imagetext')); + echo htmlspecialchars(requestVar('imagetext'),ENT_QUOTES); } /** @@ -809,7 +809,7 @@ class ACTIONS extends BaseActions { echo $item['title']; break; default: - echo htmlspecialchars(strip_tags($item['title'])); + echo htmlspecialchars(strip_tags($item['title']),ENT_QUOTES); break; } } @@ -843,22 +843,22 @@ class ACTIONS extends BaseActions { switch($what) { case 'name': - echo htmlspecialchars($memberinfo->getDisplayName()); + echo htmlspecialchars($memberinfo->getDisplayName(),ENT_QUOTES); break; case 'realname': - echo htmlspecialchars($memberinfo->getRealName()); + echo htmlspecialchars($memberinfo->getRealName(),ENT_QUOTES); break; case 'notes': - echo htmlspecialchars($memberinfo->getNotes()); + echo htmlspecialchars($memberinfo->getNotes(),ENT_QUOTES); break; case 'url': - echo htmlspecialchars($memberinfo->getURL()); + echo htmlspecialchars($memberinfo->getURL(),ENT_QUOTES); break; case 'email': - echo htmlspecialchars($memberinfo->getEmail()); + echo htmlspecialchars($memberinfo->getEmail(),ENT_QUOTES); break; case 'id': - echo htmlspecialchars($memberinfo->getID()); + echo htmlspecialchars($memberinfo->getID(),ENT_QUOTES); break; } } @@ -908,12 +908,12 @@ class ACTIONS extends BaseActions { $this->formdata = array( 'url' => htmlspecialchars($desturl), - 'actionurl' => htmlspecialchars($CONF['ActionURL']), + 'actionurl' => htmlspecialchars($CONF['ActionURL'],ENT_QUOTES), 'memberid' => $memberid, 'rows' => $rows, 'cols' => $cols, - 'message' => htmlspecialchars($message), - 'frommail' => htmlspecialchars($frommail) + 'message' => htmlspecialchars($message,ENT_QUOTES), + 'frommail' => htmlspecialchars($frommail,ENT_QUOTES) ); if ($member->isLoggedIn()) { $this->doForm('membermailform-loggedin'); @@ -939,7 +939,7 @@ class ACTIONS extends BaseActions { */ function parse_nextitem() { global $itemidnext; - echo $itemidnext; + if (isset($itemidnext)) echo (int)$itemidnext; } /** @@ -960,7 +960,7 @@ class ACTIONS extends BaseActions { echo $itemtitlenext; break; default: - echo htmlspecialchars($itemtitlenext); + echo htmlspecialchars($itemtitlenext,ENT_QUOTES); break; } } @@ -1126,7 +1126,7 @@ class ACTIONS extends BaseActions { */ function parse_previtem() { global $itemidprev; - echo $itemidprev; + if (isset($itemidprev)) echo (int)$itemidprev; } /** @@ -1147,7 +1147,7 @@ class ACTIONS extends BaseActions { echo $itemtitleprev; break; default: - echo htmlspecialchars($itemtitleprev); + echo htmlspecialchars($itemtitleprev,ENT_QUOTES); break; } } @@ -1172,14 +1172,14 @@ class ACTIONS extends BaseActions { */ function parse_query() { global $query; - echo htmlspecialchars($query); + echo htmlspecialchars($query,ENT_QUOTES); } /** * Parse skinvar referer */ function parse_referer() { - echo htmlspecialchars(serverVar('HTTP_REFERER')); + echo htmlspecialchars(serverVar('HTTP_REFERER'),ENT_QUOTES); } /** @@ -1195,7 +1195,7 @@ class ACTIONS extends BaseActions { // use default blog when no blog is selected $this->formdata = array( 'id' => $blog?$blog->getID():$CONF['DefaultBlog'], - 'query' => htmlspecialchars(getVar('query')), + 'query' => htmlspecialchars(getVar('query'),ENT_QUOTES), ); $this->doForm('searchform'); } diff --git a/euc/nucleus/libs/BAN.php b/euc/nucleus/libs/BAN.php index f1cd322..343b97d 100755 --- a/euc/nucleus/libs/BAN.php +++ b/euc/nucleus/libs/BAN.php @@ -1,104 +1,107 @@ -iprange); - if (!($found === false)) - // found a match! - return new BANINFO($obj->iprange, $obj->reason); - } - return 0; - } - - /** - * Adds a new ban to the banlist. Returns 1 on success, 0 on error - */ - function addBan($blogid, $iprange, $reason) { - global $manager; - - $blogid = intval($blogid); - - $manager->notify( - 'PreAddBan', - array( - 'blogid' => $blogid, - 'iprange' => &$iprange, - 'reason' => &$reason - ) - ); - - $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES " - . "($blogid,'".addslashes($iprange)."','".addslashes($reason)."')"; - $res = sql_query($query); - - $manager->notify( - 'PostAddBan', - array( - 'blogid' => $blogid, - 'iprange' => $iprange, - 'reason' => $reason - ) - ); - - return $res ? 1 : 0; - } - - /** - * Removes a ban from the banlist (correct iprange is needed as argument) - * Returns 1 on success, 0 on error - */ - function removeBan($blogid, $iprange) { - global $manager; - $blogid = intval($blogid); - - $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange)); - - $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'"; - sql_query($query); - - $result = (mysql_affected_rows() > 0); - - $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange)); - - return $result; - } -} - -class BANINFO { - var $iprange; - var $message; - - function BANINFO($iprange, $message) { - $this->iprange = $iprange; - $this->message = $message; - } -} - - -?> +iprange); + if (!($found === false)) + // found a match! + return new BANINFO($obj->iprange, $obj->reason); + } + return 0; + } + + /** + * Adds a new ban to the banlist. Returns 1 on success, 0 on error + */ + function addBan($blogid, $iprange, $reason) { + global $manager; + + $blogid = intval($blogid); + + $manager->notify( + 'PreAddBan', + array( + 'blogid' => $blogid, + 'iprange' => &$iprange, + 'reason' => &$reason + ) + ); + + $query = 'INSERT INTO '.sql_table('ban')." (blogid, iprange, reason) VALUES " + . "($blogid,'".addslashes($iprange)."','".addslashes($reason)."')"; + $res = sql_query($query); + + $manager->notify( + 'PostAddBan', + array( + 'blogid' => $blogid, + 'iprange' => $iprange, + 'reason' => $reason + ) + ); + + return $res ? 1 : 0; + } + + /** + * Removes a ban from the banlist (correct iprange is needed as argument) + * Returns 1 on success, 0 on error + */ + function removeBan($blogid, $iprange) { + global $manager; + $blogid = intval($blogid); + + $manager->notify('PreDeleteBan', array('blogid' => $blogid, 'range' => $iprange)); + + $query = 'DELETE FROM '.sql_table('ban')." WHERE blogid=$blogid and iprange='" .addslashes($iprange). "'"; + sql_query($query); + + $result = (mysql_affected_rows() > 0); + + $manager->notify('PostDeleteBan', array('blogid' => $blogid, 'range' => $iprange)); + + return $result; + } +} + +class BANINFO { + var $iprange; + var $message; + + function BANINFO($iprange, $message) { + $this->iprange = $iprange; + $this->message = $message; + } +} + + +?> \ No newline at end of file diff --git a/euc/nucleus/libs/BLOG.php b/euc/nucleus/libs/BLOG.php index 27ae0b5..44bdc7d 100755 --- a/euc/nucleus/libs/BLOG.php +++ b/euc/nucleus/libs/BLOG.php @@ -1,1444 +1,1114 @@ -blogid = intval($id); - $this->readSettings(); - - // try to set catid - // (the parse functions in SKIN.php will override this, so it's mainly useless) - global $catid; - $this->setSelectedCategory($catid); - } - - /** - * Shows the given amount of items for this blog - * - * @param $template - * String representing the template _NAME_ (!) - * @param $amountEntries - * amount of entries to show - * @param $startpos - * offset from where items should be shown (e.g. 5 = start at fifth item) - * @returns int - * amount of items shown - */ - function readLog($template, $amountEntries, $offset = 0, $startpos = 0) { - return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos); - } - - /** - * Shows an archive for a given month - * - * @param $year - * year - * @param $month - * month - * @param $template - * String representing the template name to be used - */ - function showArchive($templatename, $year, $month, $day=0) { - - // create extra where clause for select query - if ($day == 0) { - $timestamp_start = mktime(0,0,0,$month,1,$year); - $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12 - } else { - $timestamp_start = mktime(0,0,0,$month,$day,$year); - $timestamp_end = mktime(0,0,0,$month,$day+1,$year); - } - $extra_query = ' and i.itime>=' . mysqldate($timestamp_start) - . ' and i.itime<' . mysqldate($timestamp_end); - - - $this->readLogAmount($templatename,0,$extra_query,'',1,1); - - } - - - // sets/gets current category (only when category exists) - function setSelectedCategory($catid) { - if ($this->isValidCategory($catid) || (intval($catid) == 0)) - $this->selectedcatid = intval($catid); - } - - function setSelectedCategoryByName($catname) { - $this->setSelectedCategory($this->getCategoryIdFromName($catname)); - } - - function getSelectedCategory() { - return $this->selectedcatid; - } - - /** - * Shows the given amount of items for this blog - * - * @param $template - * String representing the template _NAME_ (!) - * @param $amountEntries - * amount of entries to show (0 = no limit) - * @param $extraQuery - * extra conditions to be added to the query - * @param $highlight - * contains a query that should be highlighted - * @param $comments - * 1=show comments 0=don't show comments - * @param $dateheads - * 1=show dateheads 0=don't show dateheads - * @param $offset - * offset - * @returns int - * amount of items shown - */ - function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) { - - $query = $this->getSqlBlog($extraQuery); - - if ($amountEntries > 0) { - // $offset zou moeten worden: - // (($startpos / $amountentries) + 1) * $offset ... later testen ... - $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries); - } - return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads); - } - - function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) { - global $CONF, $manager; - - $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit'); - if ($lastVisit != 0) - $lastVisit = $this->getCorrectTime($lastVisit); - - // set templatename as global variable (so plugins can access it) - global $currentTemplateName; - $currentTemplateName = $templateName; - - $template =& $manager->getTemplate($templateName); - - // create parser object & action handler - $actions =& new ITEMACTIONS($this); - $parser =& new PARSER($actions->getDefinedActions(),$actions); - $actions->setTemplate($template); - $actions->setHighlight($highlight); - $actions->setLastVisit($lastVisit); - $actions->setParser($parser); - $actions->setShowComments($comments); - - // execute query - $items = sql_query($query); - - // loop over all items - while ($item = mysql_fetch_object($items)) { - - $item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp - - // action handler needs to know the item we're handling - $actions->setCurrentItem($item); - - // add date header if needed - if ($dateheads) { - $new_date = date('dFY',$item->timestamp); - if ($new_date != $old_date) { - // unless this is the first time, write date footer - $timestamp = $item->timestamp; - if ($old_date != 0) { - $oldTS = strtotime($old_date); - $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS)); - $parser->parse(strftime($template['DATE_FOOTER'], $oldTS)); - $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS)); - } - $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp)); - // note, to use templatvars in the dateheader, the %-characters need to be doubled in - // order to be preserved by strftime - $parser->parse(strftime($template['DATE_HEADER'],$timestamp)); - $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp)); - } - $old_date = $new_date; - } - - // parse item - $parser->parse($template['ITEM_HEADER']); - $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item)); - $parser->parse($template['ITEM']); - $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item)); - $parser->parse($template['ITEM_FOOTER']); - - } - - $numrows = mysql_num_rows($items); - - // add another date footer if there was at least one item - if (($numrows > 0) && $dateheads) { - $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date))); - $parser->parse($template['DATE_FOOTER']); - $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date))); - } - - mysql_free_result($items); // free memory - - return $numrows; - - } - - function showOneitem($itemid, $template, $highlight) { - $extraQuery = ' and inumber=' . intval($itemid); - - return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0); - } - - - /** - * Adds an item to this blog - */ - function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft) { - global $manager; - - $blogid = intval($blogid); - $authorid = intval($authorid); - $title = $title; - $body = $body; - $more = $more; - $catid = intval($catid); - - // convert newlines to
- if ($this->convertBreaks()) { - $body = addBreaks($body); - $more = addBreaks($more); - } - - if ($closed != '1') $closed = '0'; - if ($draft != '0') $draft = '1'; - - if (!$this->isValidCategory($catid)) - $catid = $this->getDefaultCategory(); - - if ($timestamp > $this->getCorrectTime()) - $isFuture = 1; - - $timestamp = date('Y-m-d H:i:s',$timestamp); - - $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid)); - - $title = addslashes($title); - $body = addslashes($body); - $more = addslashes($more); - - $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT) ' - . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid)"; - sql_query($query); - $itemid = mysql_insert_id(); - - $manager->notify('PostAddItem',array('itemid' => $itemid)); - - if (!$draft) - $this->updateUpdateFile(); - - // send notification mail - if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem()) - $this->sendNewItemNotification($itemid, stripslashes($title), stripslashes($body)); - - return $itemid; - } - - function sendNewItemNotification($itemid, $title, $body) { - global $CONF, $member; - - // create text version of html post - $ascii = toAscii($body); - - $mailto_msg = _NOTIFY_NI_MSG . " \n"; - $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n"; - $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n"; - $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n"; - $mailto_msg .= getMailFooter(); - - $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE; - - $frommail = $member->getNotifyFromMailAddress(); - - $notify =& new NOTIFICATION($this->getNotifyAddress()); - $notify->notify($mailto_title, $mailto_msg , $frommail); - - - - } - - - /** - * Creates a new category for this blog - * - * @param $catName - * name of the new category. When empty, a name is generated automatically - * (starting with newcat) - * @param $catDescription - * description of the new category. Defaults to 'New Category' - * - * @returns - * the new category-id in case of success. - * 0 on failure - */ - function createNewCategory($catName = '', $catDescription = 'New category') { - global $member, $manager; - - if ($member->blogAdminRights($this->getID())) { - // generate - if ($catName == '') - { - $catName = 'newcat'; - $i = 1; - while(mysql_num_rows(sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID())) > 0) - $i++; - $catName = $catName . $i; - } - - $manager->notify( - 'PreAddCategory', - array( - 'blog' => &$this, - 'name' => &$catName, - 'description' => $catDescription - ) - ); - - $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')"; - sql_query($query); - $catid = mysql_insert_id(); - - $manager->notify( - 'PostAddCategory', - array( - 'blog' => &$this, - 'name' => $catName, - 'description' => $catDescription, - 'catid' => $catid - ) - ); - - return $catid; - } else { - return 0; - } - - } - - - /** - * Searches all months of this blog for the given query - * - * @param $query - * search query - * @param $template - * template to be used (__NAME__ of the template) - * @param $amountMonths - * max amount of months to be search (0 = all) - * @param $maxresults - * max number of results to show - * @param $startpos - * offset - * @returns - * amount of hits found - */ - function search($query, $template, $amountMonths, $maxresults, $startpos) { - global $CONF, $manager; - - $highlight = ''; - $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight); - - if ($sqlquery == '') - { - // no query -> show everything - $extraquery = ''; - $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1); - } else { - - // add LIMIT to query (to split search results into pages) - if (intval($maxresults > 0)) - $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults); - - // show results - $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1); - - // when no results were found, show a message - if ($amountfound == 0) - { - $template =& $manager->getTemplate($template); - $vars = array( - 'query' => htmlspecialchars($query), - 'blogid' => $this->getID() - ); - echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars); - } - } - - return $amountfound; - } - - /** - * Returns an SQL query to use for a search query - * - * @param $query - * search query - * @param $amountMonths - * amount of months to search back. Default = 0 = unlimited - * @param $mode - * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query - * @returns $highlight - * words to highlight (out parameter) - * @returns - * either a full SQL query, or an empty string (if querystring empty) - * @note - * No LIMIT clause is added. (caller should add this if multiple pages are requested) - */ - function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '') - { - $searchclass =& new SEARCH($query); - - $highlight = $searchclass->inclusive; - - // if querystring is empty, return empty string - if ($searchclass->inclusive == '') - return ''; - - - $where = $searchclass->boolean_sql_where('ititle,ibody,imore'); - $select = $searchclass->boolean_sql_select('ititle,ibody,imore'); - - // get list of blogs to search - $blogs = $searchclass->blogs; // array containing blogs that always need to be included - $blogs[] = $this->getID(); // also search current blog (duh) - $blogs = array_unique($blogs); // remove duplicates - $selectblogs = ''; - if (count($blogs) > 0) - $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')'; - - if ($mode == '') - { - $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'; - if ($select) - $query .= ', '.$select. ' as score '; - } else { - $query = 'SELECT COUNT(*) as result '; - } - - $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' - . ' WHERE i.iauthor=m.mnumber' - . ' and i.icat=c.catid' - . ' and i.idraft=0' // exclude drafts - . $selectblogs - // don't show future items - . ' and i.itime<=' . mysqldate($this->getCorrectTime()) - . ' and '.$where; - - // take into account amount of months to search - if ($amountMonths > 0) - { - $localtime = getdate($this->getCorrectTime()); - $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']); - $query .= ' and i.itime>' . mysqldate($timestamp_start); - } - - if ($mode == '') - { - if ($select) - $query .= ' ORDER BY score DESC'; - else - $query .= ' ORDER BY i.itime DESC '; - } - - return $query; - } - - /** - * Returns the SQL query that's normally used to display the blog items on the index type skins - * - * @param $mode - * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query - * @returns - * either a full SQL query, or an empty string - * @note - * No LIMIT clause is added. (caller should add this if multiple pages are requested) - */ - function getSqlBlog($extraQuery, $mode = '') - { - if ($mode == '') - $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'; - else - $query = 'SELECT COUNT(*) as result '; - - $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' - . ' WHERE i.iblog='.$this->blogid - . ' and i.iauthor=m.mnumber' - . ' and i.icat=c.catid' - . ' and i.idraft=0' // exclude drafts - // don't show future items - . ' and i.itime<=' . mysqldate($this->getCorrectTime()); - - if ($this->getSelectedCategory()) - $query .= ' and i.icat=' . $this->getSelectedCategory() . ' '; - - - $query .= $extraQuery; - - if ($mode == '') - $query .= ' ORDER BY i.itime DESC'; - - return $query; - } - - /** - * Shows the archivelist using the given template - */ - function showArchiveList($template, $mode = 'month', $limit = 0) { - global $CONF, $catid, $manager; - - if ($catid) - $linkparams = array('catid' => $catid); - - $template =& $manager->getTemplate($template); - $data['blogid'] = $this->getID(); - - echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data); - - $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') - . ' WHERE iblog=' . $this->getID() - . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items! - . ' and idraft=0'; // don't show draft items - - if ($catid) - $query .= ' and icat=' . intval($catid); - - $query .= ' GROUP BY Year, Month'; - if ($mode == 'day') - $query .= ', Day'; - - - $query .= ' ORDER BY itime DESC'; - - if ($limit > 0) - $query .= ' LIMIT ' . intval($limit); - - $res = sql_query($query); - - while ($current = mysql_fetch_object($res)) { - $current->itime = strtotime($current->itime); // string time -> unix timestamp - - if ($mode == 'day') { - $archivedate = date('Y-m-d',$current->itime); - $archive['day'] = date('d',$current->itime); - } else { - $archivedate = date('Y-m',$current->itime); - } - $data['month'] = date('m',$current->itime); - $data['year'] = date('Y',$current->itime); - $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams); - - $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data); - echo strftime($temp,$current->itime); - - } - - mysql_free_result($res); - - echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data); - } - - - /** - * Shows the list of categories using a given template - */ - function showCategoryList($template) { - global $CONF, $manager; - - // determine arguments next to catids - // I guess this can be done in a better way, but it works - global $archive, $archivelist; - - $linkparams = array(); - if ($archive) { - $blogurl = createArchiveLink($this->getID(), $archive, ''); - $linkparams['blogid'] = $this->getID(); - $linkparams['archive'] = $archive; - } else if ($archivelist) { - $blogurl = createArchiveListLink($this->getID(), ''); - $linkparams['archivelist'] = $archivelist; - } else { - $blogurl = createBlogidLink($this->getID(), ''); - $linkparams['blogid'] = $this->getID(); - } - - //$blogurl = $this->getURL() . $qargs; - $blogurl = createBlogLink($this->getURL(), $linkparams); - - $template =& $manager->getTemplate($template); - - echo TEMPLATE::fill($template['CATLIST_HEADER'], - array( - 'blogid' => $this->getID(), - 'blogurl' => $blogurl, - 'self' => $CONF['Self'] - )); - - $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC'; - $res = sql_query($query); - - - while ($data = mysql_fetch_assoc($res)) { - $data['blogid'] = $this->getID(); - $data['blogurl'] = $blogurl; - $data['catlink'] = createCategoryLink($data['catid'], $linkparams); - $data['self'] = $CONF['Self']; - - $temp = TEMPLATE::fill($template['CATLIST_LISTITEM'],$data); - echo strftime($temp,$current->itime); - - } - - mysql_free_result($res); - - echo TEMPLATE::fill($template['CATLIST_FOOTER'], - array( - 'blogid' => $this->getID(), - 'blogurl' => $blogurl, - 'self' => $CONF['Self'] - )); - } - - /** - * Blogsettings functions - */ - - function readSettings() { - $query = 'SELECT *' - . ' FROM '.sql_table('blog') - . ' WHERE bnumber=' . $this->blogid; - $res = sql_query($query); - - $this->isValid = (mysql_num_rows($res) > 0); - if (!$this->isValid) - return; - - $this->settings = mysql_fetch_assoc($res); - } - - function writeSettings() { - - // (can't use floatval since not available prior to PHP 4.2) - $offset = $this->getTimeOffset(); - if (!is_float($offset)) - $offset = intval($offset); - - $query = 'UPDATE '.sql_table('blog') - . " SET bname='" . addslashes($this->getName()) . "'," - . " bshortname='". addslashes($this->getShortName()) . "'," - . " bcomments=". intval($this->commentsEnabled()) . "," - . " bmaxcomments=" . intval($this->getMaxComments()) . "," - . " btimeoffset=" . $offset . "," - . " bpublic=" . intval($this->isPublic()) . "," - . " bsendping=" . intval($this->pingUserland()) . "," - . " bconvertbreaks=" . intval($this->convertBreaks()) . "," - . " ballowpast=" . intval($this->allowPastPosting()) . "," - . " bnotify='" . addslashes($this->getNotifyAddress()) . "'," - . " bnotifytype=" . intval($this->getNotifyType()) . "," - . " burl='" . addslashes($this->getURL()) . "'," - . " bupdate='" . addslashes($this->getUpdateFile()) . "'," - . " bdesc='" . addslashes($this->getDescription()) . "'," - . " bdefcat=" . intval($this->getDefaultCategory()) . "," - . " bdefskin=" . intval($this->getDefaultSkin()) . "," - . " bincludesearch=" . intval($this->getSearchable()) - . " WHERE bnumber=" . intval($this->getID()); - sql_query($query); - - } - - - - // update update file if requested - function updateUpdatefile() { - if ($this->getUpdateFile()) { - $f_update = fopen($this->getUpdateFile(),'w'); - fputs($f_update,$this->getCorrectTime()); - fclose($f_update); - } - - } - - /** - * Sends a XML-RPC ping message to Userland, so the weblog can - * show up in the weblogs.com updates-list - */ - function sendUserlandPing() { - global $php_errormsg; - - if ($this->pingUserland()) { - // testmessage for adding an item - $message = new xmlrpcmsg('weblogUpdates.ping',array( - new xmlrpcval($this->getName(),'string'), - new xmlrpcval($this->getURL(),'string') - )); - - $c = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80); - - // $c->setDebug(1); - - $r = $c->send($message,15); // 15 seconds timeout... - - if (($r == 0) && ($r->errno || $r->errstring)) { - return 'Error ' . $r->errno . ' : ' . $r->errstring; - } elseif (($r == 0) && ($php_errormsg)) { - return 'PHP Error: ' . $php_errormsg; - } elseif ($r == 0) { - return 'Error while trying to send ping. Sorry about that.'; - } elseif ($r->faultCode() != 0) { - return 'Error: ' . $r->faultString(); - } else { - $r = $r->value(); // get response struct - // get values - $flerror = $r->structmem('flerror'); - $flerror = $flerror->scalarval(); - - - $message = $r->structmem('message'); - $message = $message->scalarval(); - - if ($flerror != 0) - return 'Error (flerror=1): ' . $message; - else - return 'Success: ' . $message; - } - } - } - - function isValidCategory($catid) { - $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid); - return (mysql_num_rows(mysql_query($query)) != 0); - } - - function getCategoryName($catid) { - $res = mysql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid)); - $o = mysql_fetch_object($res); - return $o->cname; - } - - function getCategoryDesc($catid) { - $res = mysql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid)); - $o = mysql_fetch_object($res); - return $o->cdesc; - } - - function getCategoryIdFromName($name) { - $res = mysql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"'); - if (mysql_num_rows($res) > 0) { - $o = mysql_fetch_object($res); - return $o->catid; - } else { - return $this->getDefaultCategory(); - } - } - - function pingUserland() { - return $this->getSetting('bsendping'); - } - - function setPingUserland($val) { - $this->setSetting('bsendping',$val); - } - - function convertBreaks() { - return $this->getSetting('bconvertbreaks'); - } - - function insertJavaScriptInfo($authorid = '') { - global $member, $CONF; - - if ($authorid == '') - $authorid = $member->getID(); - - ?> - setSetting('bconvertbreaks',$val); - } - function setAllowPastPosting($val) { - $this->setSetting('ballowpast',$val); - } - function allowPastPosting() { - return $this->getSetting('ballowpast'); - } - - function getCorrectTime($t=0) { - if ($t == 0) $t = time(); - return ($t + 3600 * $this->getTimeOffset()); - } - - function getName() { - return $this->getSetting('bname'); - } - - function getShortName() { - return $this->getSetting('bshortname'); - } - - function getMaxComments() { - return $this->getSetting('bmaxcomments'); - } - - function getNotifyAddress() { - return $this->getSetting('bnotify'); - } - - function getNotifyType() { - return $this->getSetting('bnotifytype'); - } - - function notifyOnComment() { - $n = $this->getNotifyType(); - return (($n != 0) && (($n % 3) == 0)); - } - - function notifyOnVote() { - $n = $this->getNotifyType(); - return (($n != 0) && (($n % 5) == 0)); - } - - function notifyOnNewItem() { - $n = $this->getNotifyType(); - return (($n != 0) && (($n % 7) == 0)); - } - - function setNotifyType($val) { - $this->setSetting('bnotifytype',$val); - } - - - function getTimeOffset() { - return $this->getSetting('btimeoffset'); - } - - function commentsEnabled() { - return $this->getSetting('bcomments'); - } - - function getURL() { - return $this->getSetting('burl'); - } - - function getDefaultSkin() { - return $this->getSetting('bdefskin'); - } - - function getUpdateFile() { - return $this->getSetting('bupdate'); - } - - function getDescription() { - return $this->getSetting('bdesc'); - } - - function isPublic() { - return $this->getSetting('bpublic'); - } - - function getSearchable() { - return $this->getSetting('bincludesearch'); - } - - function getDefaultCategory() { - return $this->getSetting('bdefcat'); - } - - function setPublic($val) { - $this->setSetting('bpublic',$val); - } - - function setSearchable($val) { - $this->setSetting('bincludesearch',$val); - } - - function setDescription($val) { - $this->setSetting('bdesc',$val); - } - - function setUpdateFile($val) { - $this->setSetting('bupdate',$val); - } - - function setDefaultSkin($val) { - $this->setSetting('bdefskin',$val); - } - - function setURL($val) { - $this->setSetting('burl',$val); - } - - function setName($val) { - $this->setSetting('bname',$val); - } - - function setShortName($val) { - $this->setSetting('bshortname',$val); - } - - function setCommentsEnabled($val) { - $this->setSetting('bcomments',$val); - } - - function setMaxComments($val) { - $this->setSetting('bmaxcomments',$val); - } - - function setNotifyAddress($val) { - $this->setSetting('bnotify',$val); - } - - function setTimeOffset($val) { - // check validity of value - // 1. replace , by . (common mistake) - $val = str_replace(',','.',$val); - // 2. cast to float or int - if (is_numeric($val) && strstr($val,'.5')) { - $val = (float) $val; - } else { - $val = intval($val); - } - - $this->setSetting('btimeoffset',$val); - } - - function setDefaultCategory($val) { - $this->setSetting('bdefcat',$val); - } - - function getSetting($key) { - return $this->settings[$key]; - } - - function setSetting($key,$value) { - $this->settings[$key] = $value; - } - - - // tries to add a member to the team. Returns false if the member was already on - // the team - function addTeamMember($memberid, $admin) { - global $manager; - - $memberid = intval($memberid); - $admin = intval($admin); - - // check if member is already a member - $tmem = MEMBER::createFromID($memberid); - - if ($tmem->isTeamMember($this->getID())) - return 0; - - $manager->notify( - 'PreAddTeamMember', - array( - 'blog' => &$this, - 'member' => &$tmem, - 'admin' => &$admin - ) - ); - - // add to team - $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) ' - . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")'; - sql_query($query); - - $manager->notify( - 'PostAddTeamMember', - array( - 'blog' => &$this, - 'member' => &$tmem, - 'admin' => $admin - ) - - ); - - ACTIONLOG::add(INFO, 'Added ' . $tmem->getDisplayName() . ' (ID=' . - $memberid .') to the team of blog "' . $this->getName() . '"'); - - return 1; - } - - function getID() { - return $this->blogid; - } - - // returns true if there is a blog with the given shortname (static) - function exists($name) { - $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"'); - return (mysql_num_rows($r) != 0); - } - - // returns true if there is a blog with the given ID (static) - function existsID($id) { - $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id)); - return (mysql_num_rows($r) != 0); - } - - -} - -/** - * This class is used when parsing item templates - */ -class ITEMACTIONS extends BaseActions { - - // contains an assoc array with parameters that need to be included when - // generating links to items/archives/... (e.g. catid) - var $linkparams; - - // true when the current user is a blog admin (and thus allowed to edit all items) - var $allowEditAll; - - // timestamp of last visit - var $lastVisit; - - // item currently being handled (mysql result object, see BLOG::showUsingQuery) - var $currentItem; - - // reference to the blog currently being displayed - var $blog; - - // associative array with template info (part name => contents) - var $template; - - // true when comments need to be displayed - var $showComments; - - function ITEMACTIONS(&$blog) { - // call constructor of superclass first - $this->BaseActions(); - - // extra parameters for created links - global $catid; - if ($catid) - $this->linkparams = array('catid' => $catid); - - // check if member is blog admin (and thus allowed to edit all items) - global $member; - $this->allowEditAll = ($member->isLoggedIn() && $member->blogAdminRights($blog->getID())); - $this->setBlog($blog); - } - - function getDefinedActions() { - return array( - 'blogid', - 'title', - 'body', - 'more', - 'smartbody', - 'itemid', - 'morelink', - 'category', - 'categorylink', - 'author', - 'authorid', - 'authorlink', - 'catid', - 'karma', - 'date', - 'time', - 'query', - 'itemlink', - 'blogurl', - 'closed', - 'syndicate_title', - 'syndicate_description', - 'karmaposlink', - 'karmaneglink', - 'new', - 'image', - 'popup', - 'media', - 'daylink', - 'query', - 'include', - 'phpinclude', - 'parsedinclude', - 'skinfile', - 'set', - 'plugin', - 'edit', - 'editlink', - 'editpopupcode', - 'comments', - 'relevance' - ); - } - - - - function setLastVisit($lastVisit) { $this->lastVisit = $lastVisit; } - function setParser(&$parser) { $this->parser =& $parser; } - function setCurrentItem(&$item) { $this->currentItem =& $item; } - function setBlog(&$blog) { $this->blog =& $blog; } - function setTemplate($template) { $this->template =& $template; } - function setShowComments($val) { $this->showComments = $val; } - - // methods used by parser to insert content - - function parse_blogid() { echo $this->blog->getID(); } - function parse_body() { $this->highlightAndParse($this->currentItem->body); } - function parse_title() { $this->highlightAndParse($this->currentItem->title); } - function parse_more() { $this->highlightAndParse($this->currentItem->more); } - function parse_itemid() { echo $this->currentItem->itemid; } - function parse_category() { echo $this->currentItem->category; } - function parse_categorylink() { echo createCategoryLink($this->currentItem->catid); } - function parse_catid() { echo $this->currentItem->catid; } - function parse_authorid() { echo $this->currentItem->authorid; } - function parse_authorlink() { echo createMemberLink($this->currentItem->authorid, $this->linkparams); } - function parse_query() { echo $this->strHighlight; } - function parse_itemlink() { echo createItemLink($this->currentItem->itemid, $this->linkparams); } - function parse_blogurl() { echo $this->blog->getURL(); } - function parse_closed() { echo $this->currentItem->closed; } - function parse_relevance() { echo round($this->currentItem->score,2);} - - function parse_karma($type = 'totalscore') { - global $manager; - - // get karma object - $karma =& $manager->getKarma($this->currentItem->itemid); - - switch($type) { - case 'pos': - echo $karma->getNbPosVotes(); - break; - case 'neg': - echo $karma->getNbNegVotes(); - break; - case 'votes': - echo $karma->getNbOfVotes(); - break; - case 'posp': - $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbPosVotes() / $karma->getNbOfVotes()) : 50; - echo number_format($percentage,2), '%'; - break; - case 'negp': - $percentage = $karma->getNbOfVotes() ? 100 * ($karma->getNbNegVotes() / $karma->getNbOfVotes()) : 50; - echo number_format($percentage,2), '%'; - break; - case 'totalscore': - default: - echo $karma->getTotalScore(); - break; - } - - } - - function parse_author($which = '') { - switch($which) - { - case 'realname': - echo $this->currentItem->authorname; - break; - case 'id': - echo $this->currentItem->authorid; - break; - case 'email': - echo $this->currentItem->authormail; - break; - case 'url': - echo $this->currentItem->authorurl; - break; - case 'name': - default: - echo $this->currentItem->author; - } - } - - function parse_smartbody() { - if (!$this->currentItem->more) { - $this->highlightAndParse($this->currentItem->body); - } else { - $this->highlightAndParse($this->currentItem->more); - } - } - - function parse_morelink() { - if ($this->currentItem->more) - $this->parser->parse($this->template['MORELINK']); - } - - function parse_date($format = '') { - echo formatDate($format, $this->currentItem->timestamp, $this->template['FORMAT_DATE']); - } - - /** - * @param format optional strftime format - */ - function parse_time($format = '') { - echo strftime($format ? $format : $this->template['FORMAT_TIME'],$this->currentItem->timestamp); - } - - /** - * @param maxLength optional maximum length - */ - function parse_syndicate_title($maxLength = 100) { - $syndicated = strip_tags($this->currentItem->title); - echo htmlspecialchars(shorten($syndicated,$maxLength,'...')); - } - - /** - * @param maxLength optional maximum length - */ - function parse_syndicate_description($maxLength = 250, $addHighlight = 0) { - $syndicated = strip_tags($this->currentItem->body); - if ($addHighlight) { - echo $this->highlightAndParse(htmlspecialchars(shorten($syndicated,$maxLength,'...'))); - } else { - echo htmlspecialchars(shorten($syndicated,$maxLength,'...')); - } - } - - function parse_karmaposlink($text = '') { - global $CONF; - $link = $CONF['ActionURL'] . '?action=votepositive&itemid='.$this->currentItem->itemid; - echo $text ? ''.$text.'' : $link; - } - - function parse_karmaneglink($text = '') { - global $CONF; - $link = $CONF['ActionURL'] . '?action=votenegative&itemid='.$this->currentItem->itemid; - echo $text ? ''.$text.'' : $link; - } - - function parse_new() { - if (($this->lastVisit != 0) && ($this->currentItem->timestamp > $this->lastVisit)) - echo $this->template['NEW']; - } - - function parse_image() { - // image/popup calls have arguments separated by | - $args = func_get_args(); - $args = explode('|',implode($args,', ')); - call_user_func_array(array(&$this,'createImageCode'),$args); - } - function parse_popup() { - // image/popup calls have arguments separated by | - $args = func_get_args(); - $args = explode('|',implode($args,', ')); - call_user_func_array(array(&$this,'createPopupCode'),$args); - } - function parse_media() { - // image/popup calls have arguments separated by | - $args = func_get_args(); - $args = explode('|',implode($args,', ')); - call_user_func_array(array(&$this,'createMediaCode'),$args); - } - - function parse_daylink() { - echo createArchiveLink($this->blog->getID(), strftime('%Y-%m-%d',$this->currentItem->timestamp), $this->linkparams); - } - - function parse_comments($maxToShow = 0) { - if ($maxToShow == 0) - $maxToShow = $this->blog->getMaxComments(); - - // add comments - if ($this->showComments && $this->blog->commentsEnabled()) { - $comments =& new COMMENTS($this->currentItem->itemid); - $comments->setItemActions($this); - $comments->showComments($this->template, $maxToShow, $this->currentItem->closed ? 0 : 1, $this->strHighlight); - } - } - - /** - * Executes a plugin templatevar - * - * @param pluginName name of plugin (without the NP_) - * - * extra parameters can be added - */ - function parse_plugin($pluginName) { - global $manager; - - // only continue when the plugin is really installed - if (!$manager->pluginInstalled('NP_' . $pluginName)) - return; - - $plugin =& $manager->getPlugin('NP_' . $pluginName); - if (!$plugin) return; - - // get arguments - $params = func_get_args(); - - // remove plugin name - array_shift($params); - - // add item reference (array_unshift didn't work) - $params = array_merge(array(&$this->currentItem),$params); - - call_user_func_array(array(&$plugin,'doTemplateVar'), $params); - } - - function parse_edit() { - global $member, $CONF; - if ($this->allowEditAll || ($member->isLoggedIn() && ($member->getID() == $this->currentItem->authorid)) ) { - $this->parser->parse($this->template['EDITLINK']); - } - } - - function parse_editlink() { - global $CONF; - echo $CONF['AdminURL'],'bookmarklet.php?action=edit&itemid=',$this->currentItem->itemid; - } - - function parse_editpopupcode() { - echo "if (event && event.preventDefault) event.preventDefault();winbm=window.open(this.href,'nucleusbm','scrollbars=yes,width=600,height=500,left=10,top=10,status=yes,resizable=yes');winbm.focus();return false;"; - } - - // helper functions - - /** - * Parses highlighted text, with limited actions only (to prevent not fully trusted team members - * from hacking your weblog. - */ - function highlightAndParse(&$data) { - // allow only a limited subset of actions (do not allow includes etc, they might be evil) - $this->parser->actions = array('image','media','popup'); - $this->parser->parse($this->highlight($data)); - $this->parser->actions = $this->getDefinedActions(); - } - - function createPopupCode($filename, $width, $height, $text = '') { - global $CONF; - - // select private collection when no collection given - if (!strstr($filename,'/')) { - $filename = $this->currentItem->authorid . '/' . $filename; - } - - $windowwidth = $width; - $windowheight = $height; - - $vars['rawpopuplink'] = $CONF['Self'] . "?imagepopup=" . htmlspecialchars($filename) . "&width=$width&height=$height&imagetext=" . urlencode(htmlspecialchars($text)); - $vars['popupcode'] = "window.open(this.href,'imagepopup','status=no,toolbar=no,scrollbars=no,resizable=yes,width=$windowwidth,height=$windowheight');return false;"; - $vars['popuptext'] = htmlspecialchars($text); - $vars['popuplink'] = '' . $vars['popuptext'] . ''; - $vars['width'] = $width; - $vars['height'] = $height; - $vars['text'] = $text; - - echo TEMPLATE::fill($this->template['POPUP_CODE'],$vars); - } - - function createImageCode($filename, $width, $height, $text = '') { - global $CONF; - - // select private collection when no collection given - if (!strstr($filename,'/')) { - $filename = $this->currentItem->authorid . '/' . $filename; - } - - $windowwidth = $width; - $windowheight = $height; - - $vars['link'] = htmlspecialchars($CONF['MediaURL']. $filename); - $vars['text'] = htmlspecialchars($text); - $vars['image'] = '' . $vars['text'] . ''; - $vars['width'] = $width; - $vars['height'] = $height; - - - - echo TEMPLATE::fill($this->template['IMAGE_CODE'],$vars);; - - } - - function createMediaCode($filename, $text = '') { - global $CONF; - - // select private collection when no collection given - if (!strstr($filename,'/')) { - $filename = $this->currentItem->authorid . '/' . $filename; - } - - $vars['link'] = htmlspecialchars($CONF['MediaURL'] . $filename); - $vars['text'] = htmlspecialchars($text); - $vars['media'] = '' . $vars['text'] . ''; - - echo TEMPLATE::fill($this->template['MEDIA_CODE'],$vars);; - } - - -} - - -// used for mail notification (html -> text) - -function toAscii($html) { - // strip off most tags - $html = strip_tags($html,''); - $to_replace = "/]*href=[\"\']([^\"^']*)[\"\'][^>]*>([^<]*)<\/a>/i"; - _links_init(); - $ascii = preg_replace_callback ($to_replace, '_links_add', $html); - $ascii .= "\n\n" . _links_list(); - return strip_tags($ascii); -} - -function _links_init() { - global $tmp_links; - $tmp_links = array(); -} - -function _links_add($match) { - global $tmp_links; - array_push($tmp_links, $match[1]); - return $match[2] . ' [' . sizeof($tmp_links) .']'; -} - -function _links_list() { - global $tmp_links; - $output = ''; - $i = 1; - foreach ($tmp_links as $current) { - $output .= "[$i] $current\n"; - $i++; - } - return $output; -} - - -?> +blogid = intval($id); + $this->readSettings(); + + // try to set catid + // (the parse functions in SKIN.php will override this, so it's mainly useless) + global $catid; + $this->setSelectedCategory($catid); + } + + /** + * Shows the given amount of items for this blog + * + * @param $template + * String representing the template _NAME_ (!) + * @param $amountEntries + * amount of entries to show + * @param $startpos + * offset from where items should be shown (e.g. 5 = start at fifth item) + * @returns int + * amount of items shown + */ + function readLog($template, $amountEntries, $offset = 0, $startpos = 0) { + return $this->readLogAmount($template,$amountEntries,'','',1,1,$offset, $startpos); + } + + /** + * Shows an archive for a given month + * + * @param $year + * year + * @param $month + * month + * @param $template + * String representing the template name to be used + */ + function showArchive($templatename, $year, $month, $day=0) { + + // create extra where clause for select query + if ($day == 0) { + $timestamp_start = mktime(0,0,0,$month,1,$year); + $timestamp_end = mktime(0,0,0,$month+1,1,$year); // also works when $month==12 + } else { + $timestamp_start = mktime(0,0,0,$month,$day,$year); + $timestamp_end = mktime(0,0,0,$month,$day+1,$year); + } + $extra_query = ' and i.itime>=' . mysqldate($timestamp_start) + . ' and i.itime<' . mysqldate($timestamp_end); + + + $this->readLogAmount($templatename,0,$extra_query,'',1,1); + + } + + + // sets/gets current category (only when category exists) + function setSelectedCategory($catid) { + if ($this->isValidCategory($catid) || (intval($catid) == 0)) + $this->selectedcatid = intval($catid); + } + + function setSelectedCategoryByName($catname) { + $this->setSelectedCategory($this->getCategoryIdFromName($catname)); + } + + function getSelectedCategory() { + return $this->selectedcatid; + } + + /** + * Shows the given amount of items for this blog + * + * @param $template + * String representing the template _NAME_ (!) + * @param $amountEntries + * amount of entries to show (0 = no limit) + * @param $extraQuery + * extra conditions to be added to the query + * @param $highlight + * contains a query that should be highlighted + * @param $comments + * 1=show comments 0=don't show comments + * @param $dateheads + * 1=show dateheads 0=don't show dateheads + * @param $offset + * offset + * @returns int + * amount of items shown + */ + function readLogAmount($template, $amountEntries, $extraQuery, $highlight, $comments, $dateheads, $offset = 0, $startpos = 0) { + + $query = $this->getSqlBlog($extraQuery); + + if ($amountEntries > 0) { + // $offset zou moeten worden: + // (($startpos / $amountentries) + 1) * $offset ... later testen ... + $query .= ' LIMIT ' . intval($startpos + $offset).',' . intval($amountEntries); + } + return $this->showUsingQuery($template, $query, $highlight, $comments, $dateheads); + } + + function showUsingQuery($templateName, $query, $highlight = '', $comments = 0, $dateheads = 1) { + global $CONF, $manager; + + $lastVisit = cookieVar($CONF['CookiePrefix'] .'lastVisit'); + if ($lastVisit != 0) + $lastVisit = $this->getCorrectTime($lastVisit); + + // set templatename as global variable (so plugins can access it) + global $currentTemplateName; + $currentTemplateName = $templateName; + + $template =& $manager->getTemplate($templateName); + + // create parser object & action handler + $actions =& new ITEMACTIONS($this); + $parser =& new PARSER($actions->getDefinedActions(),$actions); + $actions->setTemplate($template); + $actions->setHighlight($highlight); + $actions->setLastVisit($lastVisit); + $actions->setParser($parser); + $actions->setShowComments($comments); + + // execute query + $items = sql_query($query); + + // loop over all items + while ($item = mysql_fetch_object($items)) { + + $item->timestamp = strtotime($item->itime); // string timestamp -> unix timestamp + + // action handler needs to know the item we're handling + $actions->setCurrentItem($item); + + // add date header if needed + $old_date = 0; + if ($dateheads) { + $new_date = date('dFY',$item->timestamp); + if ($new_date != $old_date) { + // unless this is the first time, write date footer + $timestamp = $item->timestamp; + if ($old_date != 0) { + $oldTS = strtotime($old_date); + $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => $oldTS)); + $tmp_footer = strftime($template['DATE_FOOTER'], $oldTS); + $parser->parse($tmp_footer); + $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => $oldTS)); + } + $manager->notify('PreDateHead',array('blog' => &$this, 'timestamp' => $timestamp)); + // note, to use templatvars in the dateheader, the %-characters need to be doubled in + // order to be preserved by strftime + $tmp_header = strftime((isset($template['DATE_HEADER']) ? $template['DATE_HEADER'] : null), $timestamp); + $parser->parse($tmp_header); + $manager->notify('PostDateHead',array('blog' => &$this, 'timestamp' => $timestamp)); + } + $old_date = $new_date; + } + + // parse item + $parser->parse($template['ITEM_HEADER']); + $manager->notify('PreItem', array('blog' => &$this, 'item' => &$item)); + $parser->parse($template['ITEM']); + $manager->notify('PostItem', array('blog' => &$this, 'item' => &$item)); + $parser->parse($template['ITEM_FOOTER']); + + } + + $numrows = mysql_num_rows($items); + + // add another date footer if there was at least one item + if (($numrows > 0) && $dateheads) { + $manager->notify('PreDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date))); + $parser->parse($template['DATE_FOOTER']); + $manager->notify('PostDateFoot',array('blog' => &$this, 'timestamp' => strtotime($old_date))); + } + + mysql_free_result($items); // free memory + + return $numrows; + + } + + function showOneitem($itemid, $template, $highlight) { + $extraQuery = ' and inumber=' . intval($itemid); + + return $this->readLogAmount($template, 1, $extraQuery, $highlight, 0, 0); + } + + + /** + * Adds an item to this blog + */ + function additem($catid, $title, $body, $more, $blogid, $authorid, $timestamp, $closed, $draft) { + global $manager; + + $blogid = intval($blogid); + $authorid = intval($authorid); + $title = $title; + $body = $body; + $more = $more; + $catid = intval($catid); + + // convert newlines to
+ if ($this->convertBreaks()) { + $body = addBreaks($body); + $more = addBreaks($more); + } + + if ($closed != '1') $closed = '0'; + if ($draft != '0') $draft = '1'; + + if (!$this->isValidCategory($catid)) + $catid = $this->getDefaultCategory(); + + if ($timestamp > $this->getCorrectTime()) + $isFuture = 1; + + $timestamp = date('Y-m-d H:i:s',$timestamp); + + $manager->notify('PreAddItem',array('title' => &$title, 'body' => &$body, 'more' => &$more, 'blog' => &$this, 'authorid' => &$authorid, 'timestamp' => &$timestamp, 'closed' => &$closed, 'draft' => &$draft, 'catid' => &$catid)); + + $title = addslashes($title); + $body = addslashes($body); + $more = addslashes($more); + + $query = 'INSERT INTO '.sql_table('item').' (ITITLE, IBODY, IMORE, IBLOG, IAUTHOR, ITIME, ICLOSED, IDRAFT, ICAT) ' + . "VALUES ('$title', '$body', '$more', $blogid, $authorid, '$timestamp', $closed, $draft, $catid)"; + sql_query($query); + $itemid = mysql_insert_id(); + + $manager->notify('PostAddItem',array('itemid' => $itemid)); + + if (!$draft) + $this->updateUpdateFile(); + + // send notification mail + if (!$draft && !$isFuture && $this->getNotifyAddress() && $this->notifyOnNewItem()) + $this->sendNewItemNotification($itemid, stripslashes($title), stripslashes($body)); + + return $itemid; + } + + function sendNewItemNotification($itemid, $title, $body) { + global $CONF, $member; + + // create text version of html post + $ascii = toAscii($body); + + $mailto_msg = _NOTIFY_NI_MSG . " \n"; +// $mailto_msg .= $CONF['IndexURL'] . 'index.php?itemid=' . $itemid . "\n\n"; + $temp = parse_url($CONF['Self']); + if ($temp['scheme']) { + $mailto_msg .= createItemLink($itemid) . "\n\n"; + } else { + $tempurl = $this->getURL(); + if (substr($tempurl, -1) == '/' || substr($tempurl, -4) == '.php') { + $mailto_msg .= $tempurl . '?itemid=' . $itemid . "\n\n"; + } else { + $mailto_msg .= $tempurl . '/?itemid=' . $itemid . "\n\n"; + } + } + $mailto_msg .= _NOTIFY_TITLE . ' ' . strip_tags($title) . "\n"; + $mailto_msg .= _NOTIFY_CONTENTS . "\n " . $ascii . "\n"; + $mailto_msg .= getMailFooter(); + + $mailto_title = $this->getName() . ': ' . _NOTIFY_NI_TITLE; + + $frommail = $member->getNotifyFromMailAddress(); + + $notify =& new NOTIFICATION($this->getNotifyAddress()); + $notify->notify($mailto_title, $mailto_msg , $frommail); + + + + } + + + /** + * Creates a new category for this blog + * + * @param $catName + * name of the new category. When empty, a name is generated automatically + * (starting with newcat) + * @param $catDescription + * description of the new category. Defaults to 'New Category' + * + * @returns + * the new category-id in case of success. + * 0 on failure + */ + function createNewCategory($catName = '', $catDescription = 'New category') { + global $member, $manager; + + if ($member->blogAdminRights($this->getID())) { + // generate + if ($catName == '') + { + $catName = 'newcat'; + $i = 1; + + $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID()); + while (mysql_num_rows($res) > 0) + { + $i++; + $res = sql_query('SELECT * FROM '.sql_table('category')." WHERE cname='".$catName.$i."' and cblog=".$this->getID()); + } + + $catName = $catName . $i; + } + + $manager->notify( + 'PreAddCategory', + array( + 'blog' => &$this, + 'name' => &$catName, + 'description' => $catDescription + ) + ); + + $query = 'INSERT INTO '.sql_table('category').' (cblog, cname, cdesc) VALUES (' . $this->getID() . ", '" . addslashes($catName) . "', '" . addslashes($catDescription) . "')"; + sql_query($query); + $catid = mysql_insert_id(); + + $manager->notify( + 'PostAddCategory', + array( + 'blog' => &$this, + 'name' => $catName, + 'description' => $catDescription, + 'catid' => $catid + ) + ); + + return $catid; + } else { + return 0; + } + + } + + + /** + * Searches all months of this blog for the given query + * + * @param $query + * search query + * @param $template + * template to be used (__NAME__ of the template) + * @param $amountMonths + * max amount of months to be search (0 = all) + * @param $maxresults + * max number of results to show + * @param $startpos + * offset + * @returns + * amount of hits found + */ + function search($query, $template, $amountMonths, $maxresults, $startpos) { + global $CONF, $manager; + + $highlight = ''; + $sqlquery = $this->getSqlSearch($query, $amountMonths, $highlight); + + if ($sqlquery == '') + { + // no query -> show everything + $extraquery = ''; + $amountfound = $this->readLogAmount($template, $maxresults, $extraQuery, $query, 1, 1); + } else { + + // add LIMIT to query (to split search results into pages) + if (intval($maxresults > 0)) + $sqlquery .= ' LIMIT ' . intval($startpos).',' . intval($maxresults); + + // show results + $amountfound = $this->showUsingQuery($template, $sqlquery, $highlight, 1, 1); + + // when no results were found, show a message + if ($amountfound == 0) + { + $template =& $manager->getTemplate($template); + $vars = array( + 'query' => htmlspecialchars($query), + 'blogid' => $this->getID() + ); + echo TEMPLATE::fill($template['SEARCH_NOTHINGFOUND'],$vars); + } + } + + return $amountfound; + } + + /** + * Returns an SQL query to use for a search query + * + * @param $query + * search query + * @param $amountMonths + * amount of months to search back. Default = 0 = unlimited + * @param $mode + * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query + * @returns $highlight + * words to highlight (out parameter) + * @returns + * either a full SQL query, or an empty string (if querystring empty) + * @note + * No LIMIT clause is added. (caller should add this if multiple pages are requested) + */ + function getSqlSearch($query, $amountMonths = 0, &$highlight, $mode = '') + { + $searchclass =& new SEARCH($query); + + $highlight = $searchclass->inclusive; + + // if querystring is empty, return empty string + if ($searchclass->inclusive == '') + return ''; + + + $where = $searchclass->boolean_sql_where('ititle,ibody,imore'); + $select = $searchclass->boolean_sql_select('ititle,ibody,imore'); + + // get list of blogs to search + $blogs = $searchclass->blogs; // array containing blogs that always need to be included + $blogs[] = $this->getID(); // also search current blog (duh) + $blogs = array_unique($blogs); // remove duplicates + $selectblogs = ''; + if (count($blogs) > 0) + $selectblogs = ' and i.iblog in (' . implode(',', $blogs) . ')'; + + if ($mode == '') + { + $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'; + if ($select) + $query .= ', '.$select. ' as score '; + } else { + $query = 'SELECT COUNT(*) as result '; + } + + $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' + . ' WHERE i.iauthor=m.mnumber' + . ' and i.icat=c.catid' + . ' and i.idraft=0' // exclude drafts + . $selectblogs + // don't show future items + . ' and i.itime<=' . mysqldate($this->getCorrectTime()) + . ' and '.$where; + + // take into account amount of months to search + if ($amountMonths > 0) + { + $localtime = getdate($this->getCorrectTime()); + $timestamp_start = mktime(0,0,0,$localtime['mon'] - $amountMonths,1,$localtime['year']); + $query .= ' and i.itime>' . mysqldate($timestamp_start); + } + + if ($mode == '') + { + if ($select) + $query .= ' ORDER BY score DESC'; + else + $query .= ' ORDER BY i.itime DESC '; + } + + return $query; + } + + /** + * Returns the SQL query that's normally used to display the blog items on the index type skins + * + * @param $mode + * either empty, or 'count'. In this case, the query will be a SELECT COUNT(*) query + * @returns + * either a full SQL query, or an empty string + * @note + * No LIMIT clause is added. (caller should add this if multiple pages are requested) + */ + function getSqlBlog($extraQuery, $mode = '') + { + if ($mode == '') + $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'; + else + $query = 'SELECT COUNT(*) as result '; + + $query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c' + . ' WHERE i.iblog='.$this->blogid + . ' and i.iauthor=m.mnumber' + . ' and i.icat=c.catid' + . ' and i.idraft=0' // exclude drafts + // don't show future items + . ' and i.itime<=' . mysqldate($this->getCorrectTime()); + + if ($this->getSelectedCategory()) + $query .= ' and i.icat=' . $this->getSelectedCategory() . ' '; + + + $query .= $extraQuery; + + if ($mode == '') + $query .= ' ORDER BY i.itime DESC'; + + return $query; + } + + /** + * Shows the archivelist using the given template + */ + function showArchiveList($template, $mode = 'month', $limit = 0) { + global $CONF, $catid, $manager; + + if ($catid) + $linkparams = array('catid' => $catid); + + $template =& $manager->getTemplate($template); + $data['blogid'] = $this->getID(); + + echo TEMPLATE::fill($template['ARCHIVELIST_HEADER'],$data); + + $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') + . ' WHERE iblog=' . $this->getID() + . ' and itime <=' . mysqldate($this->getCorrectTime()) // don't show future items! + . ' and idraft=0'; // don't show draft items + + if ($catid) + $query .= ' and icat=' . intval($catid); + + $query .= ' GROUP BY Year, Month'; + if ($mode == 'day') + $query .= ', Day'; + + + $query .= ' ORDER BY itime DESC'; + + if ($limit > 0) + $query .= ' LIMIT ' . intval($limit); + + $res = sql_query($query); + + while ($current = mysql_fetch_object($res)) { + $current->itime = strtotime($current->itime); // string time -> unix timestamp + + if ($mode == 'day') { + $archivedate = date('Y-m-d',$current->itime); + $archive['day'] = date('d',$current->itime); + } else { + $archivedate = date('Y-m',$current->itime); + } + $data['month'] = date('m',$current->itime); + $data['year'] = date('Y',$current->itime); + $data['archivelink'] = createArchiveLink($this->getID(),$archivedate,$linkparams); + + $temp = TEMPLATE::fill($template['ARCHIVELIST_LISTITEM'],$data); + echo strftime($temp,$current->itime); + + } + + mysql_free_result($res); + + echo TEMPLATE::fill($template['ARCHIVELIST_FOOTER'],$data); + } + + + /** + * Shows the list of categories using a given template + */ + function showCategoryList($template) { + global $CONF, $manager; + + // determine arguments next to catids + // I guess this can be done in a better way, but it works + global $archive, $archivelist; + + $linkparams = array(); + if ($archive) { + $blogurl = createArchiveLink($this->getID(), $archive, ''); + $linkparams['blogid'] = $this->getID(); + $linkparams['archive'] = $archive; + } else if ($archivelist) { + $blogurl = createArchiveListLink($this->getID(), ''); + $linkparams['archivelist'] = $archivelist; + } else { + $blogurl = createBlogidLink($this->getID(), ''); + $linkparams['blogid'] = $this->getID(); + } + + //$blogurl = $this->getURL() . $qargs; + //$blogurl = createBlogLink($this->getURL(), $linkparams); + + $template =& $manager->getTemplate($template); + + echo TEMPLATE::fill((isset($template['CATLIST_HEADER']) ? $template['CATLIST_HEADER'] : null), + array( + 'blogid' => $this->getID(), + 'blogurl' => $blogurl, + 'self' => $CONF['Self'] + )); + + $query = 'SELECT catid, cdesc as catdesc, cname as catname FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' ORDER BY cname ASC'; + $res = sql_query($query); + + + while ($data = mysql_fetch_assoc($res)) { + $data['blogid'] = $this->getID(); + $data['blogurl'] = $blogurl; + $data['catlink'] = createLink( + 'category', + array( + 'catid' => $data['catid'], + 'name' => $data['catname'], + 'extra' => $linkparams + ) + ); + $data['self'] = $CONF['Self']; + + echo TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data); + //$temp = TEMPLATE::fill((isset($template['CATLIST_LISTITEM']) ? $template['CATLIST_LISTITEM'] : null), $data); + //echo strftime($temp, $current->itime); + + } + + mysql_free_result($res); + + echo TEMPLATE::fill((isset($template['CATLIST_FOOTER']) ? $template['CATLIST_FOOTER'] : null), + array( + 'blogid' => $this->getID(), + 'blogurl' => $blogurl, + 'self' => $CONF['Self'] + )); + } + + /** + * Shows a list of all blogs in the system using a given template + */ + function showBlogList($template, $bnametype) { + global $CONF, $manager; + + $template =& $manager->getTemplate($template); + + echo TEMPLATE::fill((isset($template['BLOGLIST_HEADER']) ? $template['BLOGLIST_HEADER'] : null), + array( + 'sitename' => $CONF['SiteName'], + 'siteurl' => $CONF['IndexURL'] + )); + + $query = 'SELECT bnumber, bname, bshortname, bdesc, burl FROM '.sql_table('blog').' ORDER BY bnumber ASC'; + $res = sql_query($query); + + while ($data = mysql_fetch_assoc($res)) { + + $list = array(); + + $list['bloglink'] = createLink('blog', array('blogid' => $data['bnumber'])); + + $list['blogdesc'] = $data['bdesc']; + + if ($bnametype=='shortname') { + $list['blogname'] = $data['bshortname']; + } + else { // all other cases + $list['blogname'] = $data['bname']; + } + + echo TEMPLATE::fill((isset($template['BLOGLIST_LISTITEM']) ? $template['BLOGLIST_LISTITEM'] : null), $list); + + } + + mysql_free_result($res); + + echo TEMPLATE::fill((isset($template['BLOGLIST_FOOTER']) ? $template['BLOGLIST_FOOTER'] : null), + array( + 'sitename' => $CONF['SiteName'], + 'siteurl' => $CONF['IndexURL'] + )); + + } + + /** + * Blogsettings functions + */ + + function readSettings() { + $query = 'SELECT *' + . ' FROM '.sql_table('blog') + . ' WHERE bnumber=' . $this->blogid; + $res = sql_query($query); + + $this->isValid = (mysql_num_rows($res) > 0); + if (!$this->isValid) + return; + + $this->settings = mysql_fetch_assoc($res); + } + + function writeSettings() { + + // (can't use floatval since not available prior to PHP 4.2) + $offset = $this->getTimeOffset(); + if (!is_float($offset)) + $offset = intval($offset); + + $query = 'UPDATE '.sql_table('blog') + . " SET bname='" . addslashes($this->getName()) . "'," + . " bshortname='". addslashes($this->getShortName()) . "'," + . " bcomments=". intval($this->commentsEnabled()) . "," + . " bmaxcomments=" . intval($this->getMaxComments()) . "," + . " btimeoffset=" . $offset . "," + . " bpublic=" . intval($this->isPublic()) . "," + . " breqemail=" . intval($this->emailRequired()) . "," + . " bsendping=" . intval($this->pingUserland()) . "," + . " bconvertbreaks=" . intval($this->convertBreaks()) . "," + . " ballowpast=" . intval($this->allowPastPosting()) . "," + . " bnotify='" . addslashes($this->getNotifyAddress()) . "'," + . " bnotifytype=" . intval($this->getNotifyType()) . "," + . " burl='" . addslashes($this->getURL()) . "'," + . " bupdate='" . addslashes($this->getUpdateFile()) . "'," + . " bdesc='" . addslashes($this->getDescription()) . "'," + . " bdefcat=" . intval($this->getDefaultCategory()) . "," + . " bdefskin=" . intval($this->getDefaultSkin()) . "," + . " bincludesearch=" . intval($this->getSearchable()) + . " WHERE bnumber=" . intval($this->getID()); + sql_query($query); + + } + + + + // update update file if requested + function updateUpdatefile() { + if ($this->getUpdateFile()) { + $f_update = fopen($this->getUpdateFile(),'w'); + fputs($f_update,$this->getCorrectTime()); + fclose($f_update); + } + + } + + /** + * Sends a XML-RPC ping message to Userland, so the weblog can + * show up in the weblogs.com updates-list + */ + function sendUserlandPing() { + global $php_errormsg; + + if ($this->pingUserland()) { + // testmessage for adding an item + $message = new xmlrpcmsg('weblogUpdates.ping',array( + new xmlrpcval($this->getName(),'string'), + new xmlrpcval($this->getURL(),'string') + )); + + $c = new xmlrpc_client('/RPC2', 'rpc.weblogs.com', 80); + + // $c->setDebug(1); + + $r = $c->send($message,15); // 15 seconds timeout... + + if (($r == 0) && ($r->errno || $r->errstring)) { + return 'Error ' . $r->errno . ' : ' . $r->errstring; + } elseif (($r == 0) && ($php_errormsg)) { + return 'PHP Error: ' . $php_errormsg; + } elseif ($r == 0) { + return 'Error while trying to send ping. Sorry about that.'; + } elseif ($r->faultCode() != 0) { + return 'Error: ' . $r->faultString(); + } else { + $r = $r->value(); // get response struct + // get values + $flerror = $r->structmem('flerror'); + $flerror = $flerror->scalarval(); + + + $message = $r->structmem('message'); + $message = $message->scalarval(); + + if ($flerror != 0) + return 'Error (flerror=1): ' . $message; + else + return 'Success: ' . $message; + } + } + } + + function isValidCategory($catid) { + $query = 'SELECT * FROM '.sql_table('category').' WHERE cblog=' . $this->getID() . ' and catid=' . intval($catid); + $res = mysql_query($query); + return (mysql_num_rows($res) != 0); + } + + function getCategoryName($catid) { + $res = mysql_query('SELECT cname FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid)); + $o = mysql_fetch_object($res); + return $o->cname; + } + + function getCategoryDesc($catid) { + $res = mysql_query('SELECT cdesc FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and catid=' . intval($catid)); + $o = mysql_fetch_object($res); + return $o->cdesc; + } + + function getCategoryIdFromName($name) { + $res = mysql_query('SELECT catid FROM '.sql_table('category').' WHERE cblog='.$this->getID().' and cname="' . addslashes($name) . '"'); + if (mysql_num_rows($res) > 0) { + $o = mysql_fetch_object($res); + return $o->catid; + } else { + return $this->getDefaultCategory(); + } + } + + function pingUserland() { + return $this->getSetting('bsendping'); + } + + function setPingUserland($val) { + $this->setSetting('bsendping',$val); + } + + function convertBreaks() { + return $this->getSetting('bconvertbreaks'); + } + + function insertJavaScriptInfo($authorid = '') { + global $member, $CONF; + + if ($authorid == '') + $authorid = $member->getID(); + + ?> + setSetting('bconvertbreaks',$val); + } + function setAllowPastPosting($val) { + $this->setSetting('ballowpast',$val); + } + function allowPastPosting() { + return $this->getSetting('ballowpast'); + } + + function getCorrectTime($t=0) { + if ($t == 0) $t = time(); + return ($t + 3600 * $this->getTimeOffset()); + } + + function getName() { + return $this->getSetting('bname'); + } + + function getShortName() { + return $this->getSetting('bshortname'); + } + + function getMaxComments() { + return $this->getSetting('bmaxcomments'); + } + + function getNotifyAddress() { + return $this->getSetting('bnotify'); + } + + function getNotifyType() { + return $this->getSetting('bnotifytype'); + } + + function notifyOnComment() { + $n = $this->getNotifyType(); + return (($n != 0) && (($n % 3) == 0)); + } + + function notifyOnVote() { + $n = $this->getNotifyType(); + return (($n != 0) && (($n % 5) == 0)); + } + + function notifyOnNewItem() { + $n = $this->getNotifyType(); + return (($n != 0) && (($n % 7) == 0)); + } + + function setNotifyType($val) { + $this->setSetting('bnotifytype',$val); + } + + + function getTimeOffset() { + return $this->getSetting('btimeoffset'); + } + + function commentsEnabled() { + return $this->getSetting('bcomments'); + } + + function getURL() { + return $this->getSetting('burl'); + } + + function getDefaultSkin() { + return $this->getSetting('bdefskin'); + } + + function getUpdateFile() { + return $this->getSetting('bupdate'); + } + + function getDescription() { + return $this->getSetting('bdesc'); + } + + function isPublic() { + return $this->getSetting('bpublic'); + } + + function emailRequired() { + return $this->getSetting('breqemail'); + } + + function getSearchable() { + return $this->getSetting('bincludesearch'); + } + + function getDefaultCategory() { + return $this->getSetting('bdefcat'); + } + + function setPublic($val) { + $this->setSetting('bpublic',$val); + } + + function setSearchable($val) { + $this->setSetting('bincludesearch',$val); + } + + function setDescription($val) { + $this->setSetting('bdesc',$val); + } + + function setUpdateFile($val) { + $this->setSetting('bupdate',$val); + } + + function setDefaultSkin($val) { + $this->setSetting('bdefskin',$val); + } + + function setURL($val) { + $this->setSetting('burl',$val); + } + + function setName($val) { + $this->setSetting('bname',$val); + } + + function setShortName($val) { + $this->setSetting('bshortname',$val); + } + + function setCommentsEnabled($val) { + $this->setSetting('bcomments',$val); + } + + function setMaxComments($val) { + $this->setSetting('bmaxcomments',$val); + } + + function setNotifyAddress($val) { + $this->setSetting('bnotify',$val); + } + + function setEmailRequired($val) { + $this->setSetting('breqemail',$val); + } + + function setTimeOffset($val) { + // check validity of value + // 1. replace , by . (common mistake) + $val = str_replace(',','.',$val); + // 2. cast to float or int + if (is_numeric($val) && strstr($val,'.5')) { + $val = (float) $val; + } else { + $val = intval($val); + } + + $this->setSetting('btimeoffset',$val); + } + + function setDefaultCategory($val) { + $this->setSetting('bdefcat',$val); + } + + function getSetting($key) { + return $this->settings[$key]; + } + + function setSetting($key,$value) { + $this->settings[$key] = $value; + } + + + // tries to add a member to the team. Returns false if the member was already on + // the team + function addTeamMember($memberid, $admin) { + global $manager; + + $memberid = intval($memberid); + $admin = intval($admin); + + // check if member is already a member + $tmem = MEMBER::createFromID($memberid); + + if ($tmem->isTeamMember($this->getID())) + return 0; + + $manager->notify( + 'PreAddTeamMember', + array( + 'blog' => &$this, + 'member' => &$tmem, + 'admin' => &$admin + ) + ); + + // add to team + $query = 'INSERT INTO '.sql_table('team').' (TMEMBER, TBLOG, TADMIN) ' + . 'VALUES (' . $memberid .', '.$this->getID().', "'.$admin.'")'; + sql_query($query); + + $manager->notify( + 'PostAddTeamMember', + array( + 'blog' => &$this, + 'member' => &$tmem, + 'admin' => $admin + ) + + ); + + ACTIONLOG::add(INFO, 'Added ' . $tmem->getDisplayName() . ' (ID=' . + $memberid .') to the team of blog "' . $this->getName() . '"'); + + return 1; + } + + function getID() { + return intVal($this->blogid); + } + + // returns true if there is a blog with the given shortname (static) + function exists($name) { + $r = sql_query('select * FROM '.sql_table('blog').' WHERE bshortname="'.addslashes($name).'"'); + return (mysql_num_rows($r) != 0); + } + + // returns true if there is a blog with the given ID (static) + function existsID($id) { + $r = sql_query('select * FROM '.sql_table('blog').' WHERE bnumber='.intval($id)); + return (mysql_num_rows($r) != 0); + } + + +} + +?> \ No newline at end of file diff --git a/euc/nucleus/libs/COMMENT.php b/euc/nucleus/libs/COMMENT.php index 673dd1d..4142c3f 100755 --- a/euc/nucleus/libs/COMMENT.php +++ b/euc/nucleus/libs/COMMENT.php @@ -1,134 +1,139 @@ - tags - $body = addBreaks($body); - - // create hyperlinks for http:// addresses - // there's a testcase for this in /build/testcases/urllinking.txt - $replaceFrom = array( - '/([^:\/\/\w]|^)((https:\/\/)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie', - '/([^:\/\/\w]|^)((http:\/\/|www\.)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie', - '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([a-z0-9_\.-]+)([\/a-z0-9_+\.~%&?@=_:;#,-]+))/ie', - '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie' - ); - $replaceTo = array( - 'COMMENT::createLinkCode("\\1", "\\2","https")', - 'COMMENT::createLinkCode("\\1", "\\2","http")', - 'COMMENT::createLinkCode("\\1", "\\2","ftp")', - 'COMMENT::createLinkCode("\\1", "\\3","mailto")' - ); - $body = preg_replace($replaceFrom, $replaceTo, $body); - - return $body; - } - - function createLinkCode($pre, $url, $protocol = 'http') { - $post = ''; - - // it's possible that $url ends contains entities we don't want, - // since htmlspecialchars is applied _before_ URL linking - // move the part of URL, starting from the disallowed entity to the 'post' link part - $aBadEntities = array('"', '>', '<'); - foreach ($aBadEntities as $entity) - { - $pos = strpos($url, $entity); - if ($pos) - { - $post = substr($url, $pos) . $post; - $url = substr($url, 0, $pos); - - } - } - - // remove entities at end (&&&&) - if (preg_match('/(&\w+;)+$/i', $url, $matches)) { - $post = $matches[0] . $post; // found entities (1 or more) - $url = substr($url, 0, strlen($url) - strlen($post)); - } - - // move ending comma from url to 'post' part - if (substr($url, strlen($url) - 1) == ',') - { - $url = substr($url, 0, strlen($url) - 1); - $post = ',' . $post; - } - - if (!ereg('^'.$protocol.'://',$url)) - $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url; - else - $linkedUrl = $url; - - - if ($protocol != 'mailto') - $displayedUrl = $linkedUrl; - else - $displayedUrl = $url; - return $pre . '
'.shorten($displayedUrl,30,'...').'' . $post; - } - -} - -?> + tags + $body = addBreaks($body); + + // create hyperlinks for http:// addresses + // there's a testcase for this in /build/testcases/urllinking.txt + $replaceFrom = array( + '/([^:\/\/\w]|^)((https:\/\/)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', + '/([^:\/\/\w]|^)((http:\/\/|www\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', + '/([^:\/\/\w]|^)((ftp:\/\/|ftp\.)([\w\.-]+)([\/\w+\.~%&?@=_:;#,-]+))/ie', + '/([^:\/\/\w]|^)(mailto:(([a-zA-Z\@\%\.\-\+_])+))/ie' + ); + $replaceTo = array( + 'COMMENT::createLinkCode("\\1", "\\2","https")', + 'COMMENT::createLinkCode("\\1", "\\2","http")', + 'COMMENT::createLinkCode("\\1", "\\2","ftp")', + 'COMMENT::createLinkCode("\\1", "\\3","mailto")' + ); + $body = preg_replace($replaceFrom, $replaceTo, $body); + + return $body; + } + + function createLinkCode($pre, $url, $protocol = 'http') { + $post = ''; + + // it's possible that $url ends contains entities we don't want, + // since htmlspecialchars is applied _before_ URL linking + // move the part of URL, starting from the disallowed entity to the 'post' link part + $aBadEntities = array('"', '>', '<'); + foreach ($aBadEntities as $entity) + { + $pos = strpos($url, $entity); + if ($pos) + { + $post = substr($url, $pos) . $post; + $url = substr($url, 0, $pos); + + } + } + + // remove entities at end (&&&&) + if (preg_match('/(&\w+;)+$/i', $url, $matches)) { + $post = $matches[0] . $post; // found entities (1 or more) + $url = substr($url, 0, strlen($url) - strlen($post)); + } + + // move ending comma from url to 'post' part + if (substr($url, strlen($url) - 1) == ',') + { + $url = substr($url, 0, strlen($url) - 1); + $post = ',' . $post; + } + + if (!ereg('^'.$protocol.'://',$url)) + $linkedUrl = $protocol . (($protocol == 'mailto') ? ':' : '://') . $url; + else + $linkedUrl = $url; + + + if ($protocol != 'mailto') + $displayedUrl = $linkedUrl; + else + $displayedUrl = $url; + return $pre . ''.shorten($displayedUrl,30,'...').'' . $post; + } + +} + +?> \ No newline at end of file diff --git a/euc/nucleus/libs/SKIN.php b/euc/nucleus/libs/SKIN.php index 01ccdf7..85eb66f 100755 --- a/euc/nucleus/libs/SKIN.php +++ b/euc/nucleus/libs/SKIN.php @@ -1,1355 +1,422 @@ -id = intval($id); - - // read skin name/description/content type - $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id); - $obj = mysql_fetch_object($res); - $this->isValid = (mysql_num_rows($res) > 0); - if (!$this->isValid) - return; - - $this->name = $obj->sdname; - $this->description = $obj->sddesc; - $this->contentType = $obj->sdtype; - $this->includeMode = $obj->sdincmode; - $this->includePrefix = $obj->sdincpref; - - } - - function getID() { return $this->id; } - function getName() { return $this->name; } - function getDescription() { return $this->description; } - function getContentType() { return $this->contentType; } - function getIncludeMode() { return $this->includeMode; } - function getIncludePrefix() { return $this->includePrefix; } - - // returns true if there is a skin with the given shortname (static) - function exists($name) { - return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.addslashes($name).'"') > 0; - } - - // returns true if there is a skin with the given ID (static) - function existsID($id) { - return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0; - } - - // (static) - function createFromName($name) { - return new SKIN(SKIN::getIdFromName($name)); - } - - // (static) - function getIdFromName($name) { - $query = 'SELECT sdnumber' - . ' FROM '.sql_table('skin_desc') - . ' WHERE sdname="'.addslashes($name).'"'; - $res = sql_query($query); - $obj = mysql_fetch_object($res); - return $obj->sdnumber; - } - - // (static) - function getNameFromId($id) { - return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id)); - } - - /** - * Creates a new skin, with the given characteristics. - * - * (static) - */ - function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') { - global $manager; - - $manager->notify( - 'PreAddSkin', - array( - 'name' => &$name, - 'description' => &$desc, - 'type' => &$type, - 'includeMode' => &$includeMode, - 'includePrefix' => &$includePrefix - ) - ); - - sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "','".addslashes($type)."','".addslashes($includeMode)."','".addslashes($includePrefix)."')"); - $newid = mysql_insert_id(); - - $manager->notify( - 'PostAddSkin', - array( - 'skinid' => $newid, - 'name' => $name, - 'description' => $desc, - 'type' => $type, - 'includeMode' => $includeMode, - 'includePrefix' => $includePrefix - ) - ); - - return $newid; - } - - function parse($type) { - global $manager, $CONF; - - // set output type - sendContentType($this->getContentType(), 'skin', _CHARSET); - - // set skin name as global var (so plugins can access it) - global $currentSkinName; - $currentSkinName = $this->getName(); - - $contents = $this->getContent($type); - - if (!$contents) { - // use base skin if this skin does not have contents - $defskin =& new SKIN($CONF['BaseSkin']); - $contents = $defskin->getContent($type); - if (!$contents) { - echo _ERROR_SKIN; - return; - } - } - - $actions = $this->getAllowedActionsForType($type); - - $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type)); - - // set IncludeMode properties of parser - PARSER::setProperty('IncludeMode',$this->getIncludeMode()); - PARSER::setProperty('IncludePrefix',$this->getIncludePrefix()); - - $handler =& new ACTIONS($type, $this); - $parser =& new PARSER($actions, $handler); - $handler->setParser($parser); - $handler->setSkin($this); - $parser->parse($contents); - - $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type)); - - - } - - function getContent($type) { - $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". addslashes($type) ."'"; - $res = sql_query($query); - - if (mysql_num_rows($res) == 0) - return ''; - else - return mysql_result($res, 0, 0); - } - - /** - * Updates the contents of one part of the skin - */ - function update($type, $content) { - $skinid = $this->id; - - // delete old thingie - sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".addslashes($type)."' and sdesc=" . intval($skinid)); - - // write new thingie - if ($content) { - sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . addslashes($content) . "', stype='" . addslashes($type) . "', sdesc=" . intval($skinid)); - } - } - - /** - * Deletes all skin parts from the database - */ - function deleteAllParts() { - sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID()); - } - - /** - * Updates the general information about the skin - */ - function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') { - $query = 'UPDATE '.sql_table('skin_desc').' SET' - . " sdname='" . addslashes($name) . "'," - . " sddesc='" . addslashes($desc) . "'," - . " sdtype='" . addslashes($type) . "'," - . " sdincmode='" . addslashes($includeMode) . "'," - . " sdincpref='" . addslashes($includePrefix) . "'" - . " WHERE sdnumber=" . $this->getID(); - sql_query($query); - } - - /** - * static: returns an array of friendly names - */ - function getFriendlyNames() { - return array( - 'index' => _SKIN_PART_MAIN, - 'item' => _SKIN_PART_ITEM, - 'archivelist' => _SKIN_PART_ALIST, - 'archive' => _SKIN_PART_ARCHIVE, - 'search' => _SKIN_PART_SEARCH, - 'error' => _SKIN_PART_ERROR, - 'member' => _SKIN_PART_MEMBER, - 'imagepopup' => _SKIN_PART_POPUP - ); - } - - function getAllowedActionsForType($type) { - // some actions that can be performed at any time, from anywhere - $defaultActions = array('otherblog', - 'plugin', - 'version', - 'nucleusbutton', - 'include', - 'phpinclude', - 'parsedinclude', - 'loginform', - 'sitevar', - 'otherarchivelist', - 'otherarchivedaylist', - 'self', - 'adminurl', - 'todaylink', - 'archivelink', - 'member', - 'ifcat', // deprecated (Nucleus v2.0) - 'category', - 'searchform', - 'referer', - 'skinname', - 'skinfile', - 'set', - 'if', - 'else', - 'endif' - ); - - // extra actions specific for a certain skin type - $extraActions = array(); - - switch ($type) { - case 'index': - $extraActions = array('blog', - 'blogsetting', - 'preview', - 'additemform', - 'categorylist', - 'archivelist', - 'archivedaylist', - 'nextlink', - 'prevlink' - ); - break; - case 'archive': - $extraActions = array('blog', - 'archive', - 'otherarchive', - 'categorylist', - 'archivelist', - 'archivedaylist', - 'blogsetting', - 'archivedate', - 'nextarchive', - 'prevarchive', - 'nextlink', - 'prevlink', - 'archivetype' - ); - break; - case 'archivelist': - $extraActions = array('blog', - 'archivelist', - 'archivedaylist', - 'categorylist', - 'blogsetting', - ); - break; - case 'search': - $extraActions = array('blog', - 'archivelist', - 'archivedaylist', - 'categorylist', - 'searchresults', - 'othersearchresults', - 'blogsetting', - 'query', - 'nextlink', - 'prevlink' - ); - break; - case 'imagepopup': - $extraActions = array('image', - 'imagetext', // deprecated (Nucleus v2.0) - ); - break; - case 'member': - $extraActions = array( - 'membermailform', - 'blogsetting', - 'nucleusbutton' - ); - break; - case 'item': - $extraActions = array('blog', - 'item', - 'comments', - 'commentform', - 'vars', - 'blogsetting', - 'nextitem', - 'previtem', - 'nextlink', - 'prevlink', - 'nextitemtitle', - 'previtemtitle', - 'categorylist', - 'archivelist', - 'archivedaylist', - 'itemtitle', - 'itemid', - 'itemlink', - ); - break; - case 'error': - $extraActions = array( - 'errormessage' - ); - break; - } - return array_merge($defaultActions, $extraActions); - } - -} - - -/* - * This class contains the functions that get called by using - * the special tags in the skins - * - * The allowed tags for a type of skinpart are defined by the - * SKIN::getAllowedActionsForType($type) method - */ -class ACTIONS extends BaseActions { - - // part of the skin currently being parsed ('index', 'item', 'archive', - // 'archivelist', 'member', 'search', 'error', 'imagepopup') - var $skintype; - - // contains an assoc array with parameters that need to be included when - // generating links to items/archives/... (e.g. catid) - var $linkparams; - - // reference to the skin object for which a part is being parsed - var $skin; - - - // used when including templated forms from the include/ dir. The $formdata var - // contains the values to fill out in there (assoc array name -> value) - var $formdata; - - - // filled out with the number of displayed items after calling one of the - - // (other)blog/(other)searchresults skinvars. - - var $amountfound; - - function ACTIONS($type) { - // call constructor of superclass first - $this->BaseActions(); - - $this->skintype = $type; - - global $catid; - if ($catid) - $this->linkparams = array('catid' => $catid); - } - - function setSkin(&$skin) { - $this->skin =& $skin; - } - - function setParser(&$parser) { - $this->parser =& $parser; - } - - /* - Forms get parsedincluded now, using an extra skinvar - */ - function doForm($filename) { - global $DIR_NUCLEUS; - array_push($this->parser->actions,'formdata','text','callback','errordiv'); - $oldIncludeMode = PARSER::getProperty('IncludeMode'); - $oldIncludePrefix = PARSER::getProperty('IncludePrefix'); - PARSER::setProperty('IncludeMode','normal'); - PARSER::setProperty('IncludePrefix',''); - $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template'); - PARSER::setProperty('IncludeMode',$oldIncludeMode); - PARSER::setProperty('IncludePrefix',$oldIncludePrefix); - array_pop($this->parser->actions); // errordiv - array_pop($this->parser->actions); // callback - array_pop($this->parser->actions); // text - array_pop($this->parser->actions); // formdata - } - function parse_formdata($what) { - echo $this->formdata[$what]; - } - function parse_text($which) { - // constant($which) only available from 4.0.4 :( - if (defined($which)) { - eval("echo $which;"); - } - } - function parse_callback($eventName, $type) - { - global $manager; - $manager->notify($eventName, array('type' => $type)); - } - function parse_errordiv() { - global $errormessage; - if ($errormessage) - echo '
', htmlspecialchars($errormessage),'
'; - } - - function parse_skinname() { - echo $this->skin->getName(); - } - - function parse_if($field, $name='', $value = '') { - global $catid, $blog, $member, $itemidnext, $itemidprev, $manager; - - $condition = 0; - switch($field) { - case 'category': - $condition = ($blog && $this->_ifCategory($name,$value)); - break; - case 'blogsetting': - if ($name == 'trackback' && $manager->pluginInstalled('NP_TrackBack')) { - $plugin =& $manager->getPlugin('NP_TrackBack'); - if ($plugin != NULL && $blog){ - $bid = $blog->getID(); - if ($value === '1') $value = 'yes'; - if ($value === '0') $value = 'no'; - if ($plugin->getOption('AcceptPing') == 'no' ) { - $condition = ($value == 'no'); - } else { - $tb_option = $plugin->getBlogOption($bid,'AllowTrackBack'); - if (!$tb_option) { - $condition = ($value == 'yes'); - } else { - $condition = ($tb_option == $value); - } - } - } - break; - } - $condition = ($blog && ($blog->getSetting($name) == $value)); - break; - case 'loggedin': - $condition = $member->isLoggedIn(); - break; - case 'onteam': - $condition = $member->isLoggedIn() && $this->_ifOnTeam($name); - break; - case 'admin': - $condition = $member->isLoggedIn() && $this->_ifAdmin($name); - break; - case 'nextitem': - $condition = ($itemidnext != ''); - break; - case 'previtem': - $condition = ($itemidprev != ''); - break; - case 'skintype': - $condition = ($name == $this->skintype); - break; - /* - hasplugin,PlugName - -> checks if plugin exists - hasplugin,PlugName,OptionName - -> checks if the option OptionName from plugin PlugName is not set to 'no' - hasplugin,PlugName,OptionName=value - -> checks if the option OptionName from plugin PlugName is set to value - */ - case 'hasplugin': - $condition = false; - // (pluginInstalled method won't write a message in the actionlog on failure) - if ($manager->pluginInstalled('NP_'.$name)) - { - $plugin =& $manager->getPlugin('NP_' . $name); - if ($plugin != NULL){ - if ($value == "") { - $condition = true; - } else { - list($name2, $value2) = explode('=', $value, 2); - if ($value2 == "" && $plugin->getOption($name2) != 'no') { - $condition = true; - } else if ($plugin->getOption($name2) == $value2) { - $condition = true; - } - } - } - } - break; - default: - return; - } - $this->_addIfCondition($condition); - } - - function _ifCategory($name = '', $value='') { - global $blog, $catid; - - // when no parameter is defined, just check if a category is selected - if (($name != 'catname' && $name != 'catid') || ($value == '')) - return $blog->isValidCategory($catid); - - // check category name - if ($name == 'catname') { - $value = $blog->getCategoryIdFromName($value); - if ($value == $catid) - return $blog->isValidCategory($catid); - } - - // check category id - if (($name == 'catid') && ($value == $catid)) - return $blog->isValidCategory($catid); - - return false; - } - - function _ifOnTeam($blogName = '') { - global $blog, $member, $manager; - - // when no blog found - if (($blogName == '') && (!is_object($blog))) - return 0; - - // explicit blog selection - if ($blogName != '') - $blogid = getBlogIDFromName($blogName); - - if (($blogName == '') || !$manager->existsBlogID($blogid)) - // use current blog - $blogid = $blog->getID(); - - return $member->teamRights($blogid); - } - - function _ifAdmin($blogName = '') { - global $blog, $member, $manager; - - // when no blog found - if (($blogName == '') && (!is_object($blog))) - return 0; - - // explicit blog selection - if ($blogName != '') - $blogid = getBlogIDFromName($blogName); - - if (($blogName == '') || !$manager->existsBlogID($blogid)) - // use current blog - $blogid = $blog->getID(); - - return $member->isBlogAdmin($blogid); - } - - function parse_ifcat($text = '') { - if ($text == '') { - // new behaviour - $this->parse_if('category'); - } else { - // old behaviour - global $catid, $blog; - if ($blog->isValidCategory($catid)) - echo $text; - } - } - - // a link to the today page (depending on selected blog, etc...) - function parse_todaylink($linktext = '') { - global $blog, $CONF; - if ($blog) - echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext); - else - echo $this->_link($CONF['SiteUrl'], $linktext); - } - - // a link to the archives for the current blog (or for default blog) - function parse_archivelink($linktext = '') { - global $blog, $CONF; - if ($blog) - echo $this->_link(createArchiveListLink($blog->getID(),$this->linkparams), $linktext); - else - echo $this->_link(createArchiveListLink(), $linktext); - } - - // include itemid of prev item - function parse_previtem() { - global $itemidprev; - echo $itemidprev; - } - - // include itemtitle of prev item - function parse_previtemtitle() { - global $itemtitleprev; - echo htmlspecialchars($itemtitleprev); - } - - // include itemid of next item - function parse_nextitem() { - global $itemidnext; - echo $itemidnext; - } - - // include itemtitle of next item - function parse_nextitemtitle() { - global $itemtitlenext; - echo htmlspecialchars($itemtitlenext); - } - - function parse_prevarchive() { - global $archiveprev; - echo $archiveprev; - } - - function parse_nextarchive() { - global $archivenext; - echo $archivenext; - } - - function parse_archivetype() { - global $archivetype; - echo $archivetype; - } - - function parse_prevlink($linktext = '', $amount = 10) { - global $itemidprev, $archiveprev, $startpos; - - if ($this->skintype == 'item') - $this->_itemlink($itemidprev, $linktext); - else if ($this->skintype == 'search' || $this->skintype == 'index') - $this->_searchlink($amount, $startpos, 'prev', $linktext); - else - $this->_archivelink($archiveprev, $linktext); - } - - function parse_nextlink($linktext = '', $amount = 10) { - global $itemidnext, $archivenext, $startpos; - if ($this->skintype == 'item') - $this->_itemlink($itemidnext, $linktext); - else if ($this->skintype == 'search' || $this->skintype == 'index') - $this->_searchlink($amount, $startpos, 'next', $linktext); - else - $this->_archivelink($archivenext, $linktext); - } - - /** - * returns either - * - a raw link (html/xml encoded) when no linktext is provided - * - a (x)html '.htmlspecialchars($linktext).''; - else - $l = $u; - return $l; - } - - /** - * Outputs a next/prev link - * - * @param $maxresults - * The maximum amount of items shown per page (e.g. 10) - * @param $startpos - * Current start position (requestVar('startpos')) - * @param $direction - * either 'prev' or 'next' - * @param $linktext - * When present, the output will be a full link. When empty, - * only a raw link will be outputted - */ - function _searchlink($maxresults, $startpos, $direction, $linktext = '') { - global $CONF, $blog, $query, $amount; - // TODO: Move request uri to linkparams. this is ugly. sorry for that. - $startpos = intval($startpos); // will be 0 when empty. - $parsed = parse_url(serverVar('REQUEST_URI')); - $parsed = $parsed['query']; - $url = ''; - - switch ($direction) { - case 'prev': - if ( intval($startpos) - intval($maxresults) >= 0) { - $startpos = intval($startpos) - intval($maxresults); - $url = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos); - } - break; - case 'next': - $iAmountOnPage = $this->amountfound; - if ($iAmountOnPage == 0) - { - // [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%] - // try a count query - switch ($this->skintype) - { - case 'index': - $sqlquery = $blog->getSqlBlog('', 'count'); - break; - case 'search': - $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count'); - break; - } - if ($sqlquery) - $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos); - } - if (intval($iAmountOnPage) >= intval($maxresults)) { - $startpos = intval($startpos) + intval($maxresults); - $url = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos); - } - break; - default: - break; - } // switch($direction) - - if ($url != '') - echo $this->_link($url, $linktext); - } - - function _itemlink($id, $linktext = '') { - global $CONF; - if ($id) - echo $this->_link(createItemLink($id, $this->linkparams), $linktext); - else - $this->parse_todaylink($linktext); - } - - function _archivelink($id, $linktext = '') { - global $CONF, $blog; - if ($id) - echo $this->_link(createArchiveLink($blog->getID(), $id, $this->linkparams), $linktext); - else - $this->parse_todaylink($linktext); - } - - - function parse_itemlink($linktext = '') { - $this->_itemlink($itemid, $linktext); - } - - /** - * %archivedate(locale,date format)% - */ - function parse_archivedate($locale = '-def-') { - global $archive; - - if ($locale == '-def-') - setlocale(LC_TIME,$template['LOCALE']); - else - setlocale(LC_TIME,$locale); - - // get archive date - sscanf($archive,'%d-%d-%d',$y,$m,$d); - - // get format - $args = func_get_args(); - // format can be spread over multiple parameters - if (sizeof($args) > 1) { - // take away locale - array_shift($args); - // implode - $format=implode(',',$args); - } elseif ($d == 0) { - $format = '%B %Y'; - } else { - $format = '%d %B %Y'; - } - - echo strftime($format,mktime(0,0,0,$m,$d?$d:1,$y)); - } - - function parse_blog($template, $amount = 10, $category = '') { - global $blog, $startpos; - - list($limit, $offset) = sscanf($amount, '%d(%d)'); - $this->_setBlogCategory($blog, $category); - $this->_preBlogContent('blog',$blog); - $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos); - $this->_postBlogContent('blog',$blog); - } - - function parse_otherblog($blogname, $template, $amount = 10, $category = '') { - global $manager; - - list($limit, $offset) = sscanf($amount, '%d(%d)'); - - $b =& $manager->getBlog(getBlogIDFromName($blogname)); - $this->_setBlogCategory($b, $category); - $this->_preBlogContent('otherblog',$b); - $this->amountfound = $b->readLog($template, $limit, $offset); - $this->_postBlogContent('otherblog',$b); - } - - // include one item (no comments) - function parse_item($template) { - global $blog, $itemid, $highlight; - $this->_setBlogCategory($blog, ''); // need this to select default category - $this->_preBlogContent('item',$blog); - $r = $blog->showOneitem($itemid, $template, $highlight); - if ($r == 0) - echo _ERROR_NOSUCHITEM; - $this->_postBlogContent('item',$blog); - } - - function parse_itemid() { - global $itemid; - echo $itemid; - } - - - // include comments for one item - function parse_comments($template) { - global $itemid, $manager, $blog, $highlight; - $template =& $manager->getTemplate($template); - - // create parser object & action handler - $actions =& new ITEMACTIONS($blog); - $parser =& new PARSER($actions->getDefinedActions(),$actions); - $actions->setTemplate($template); - $actions->setParser($parser); - $item = ITEM::getitem($itemid, 0, 0); - $actions->setCurrentItem($item); - - $comments =& new COMMENTS($itemid); - $comments->setItemActions($actions); - $comments->showComments($template, -1, 1, $highlight); // shows ALL comments - } - - function parse_archive($template, $category = '') { - global $blog, $archive; - // can be used with either yyyy-mm or yyyy-mm-dd - sscanf($archive,'%d-%d-%d',$y,$m,$d); - $this->_setBlogCategory($blog, $category); - $this->_preBlogContent('achive',$blog); - $blog->showArchive($template, $y, $m, $d); - $this->_postBlogContent('achive',$blog); - - } - - function parse_otherarchive($blogname, $template, $category = '') { - global $archive, $manager; - sscanf($archive,'%d-%d-%d',$y,$m,$d); - $b =& $manager->getBlog(getBlogIDFromName($blogname)); - $this->_setBlogCategory($b, $category); - $this->_preBlogContent('otherachive',$b); - $b->showArchive($template, $y, $m, $d); - $this->_postBlogContent('otherachive',$b); - } - - function parse_archivelist($template, $category = 'all', $limit = 0) { - global $blog; - if ($category == 'all') $category = ''; - $this->_preBlogContent('archivelist',$blog); - $this->_setBlogCategory($blog, $category); - $blog->showArchiveList($template, 'month', $limit); - $this->_postBlogContent('archivelist',$blog); - } - - function parse_archivedaylist($template, $category = 'all', $limit = 0) { - global $blog; - if ($category == 'all') $category = ''; - $this->_preBlogContent('archivelist',$blog); - $this->_setBlogCategory($blog, $category); - $blog->showArchiveList($template, 'day', $limit); - $this->_postBlogContent('archivelist',$blog); - } - - - function parse_itemtitle() { - global $manager, $itemid; - $item =& $manager->getItem($itemid,0,0); - echo htmlspecialchars(strip_tags($item['title'])); - } - - function parse_categorylist($template, $blogname = '') { - global $blog, $manager; - - if ($blogname == '') { - $this->_preBlogContent('categorylist',$blog); - $blog->showCategoryList($template); - $this->_postBlogContent('categorylist',$blog); - } else { - $b =& $manager->getBlog(getBlogIDFromName($blogname)); - $this->_preBlogContent('categorylist',$b); - $b->showCategoryList($template); - $this->_postBlogContent('categorylist',$b); - } - } - - function parse_category($type = 'name') { - global $catid, $blog; - if (!$blog->isValidCategory($catid)) - return; - - switch($type) { - case 'name': - echo $blog->getCategoryName($catid); - break; - case 'desc': - echo $blog->getCategoryDesc($catid); - break; - case 'id': - echo $catid; - break; - } - } - - function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) { - global $manager; - if ($category == 'all') $category = ''; - $b =& $manager->getBlog(getBlogIDFromName($blogname)); - $this->_setBlogCategory($b, $category); - $this->_preBlogContent('otherarchivelist',$b); - $b->showArchiveList($template, 'month', $limit); - $this->_postBlogContent('otherarchivelist',$b); - } - - function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) { - global $manager; - if ($category == 'all') $category = ''; - $b =& $manager->getBlog(getBlogIDFromName($blogname)); - $this->_setBlogCategory($b, $category); - $this->_preBlogContent('otherarchivelist',$b); - $b->showArchiveList($template, 'day', $limit); - $this->_postBlogContent('otherarchivelist',$b); - } - - function parse_searchresults($template, $maxresults = 50 ) { - global $blog, $query, $amount, $startpos; - - $this->_setBlogCategory($blog, ''); // need this to select default category - $this->_preBlogContent('searchresults',$blog); - $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos); - $this->_postBlogContent('searchresults',$blog); - } - - function parse_othersearchresults($blogname, $template, $maxresults = 50) { - global $query, $amount, $manager, $startpos; - $b =& $manager->getBlog(getBlogIDFromName($blogname)); - $this->_setBlogCategory($b, ''); // need this to select default category - $this->_preBlogContent('othersearchresults',$b); - $b->search($query, $template, $amount, $maxresults, $startpos); - $this->_postBlogContent('othersearchresults',$b); - } - - // includes the search query - function parse_query() { - global $query; - echo htmlspecialchars($query); - } - - // include nucleus versionnumber - function parse_version() { - global $nucleus; - echo 'Nucleus CMS ' . $nucleus['version']; - } - - - function parse_errormessage() { - global $errormessage; - echo $errormessage; - } - - - function parse_imagetext() { - echo htmlspecialchars(requestVar('imagetext')); - } - - function parse_image($what = 'imgtag') { - global $CONF; - - $imagetext = htmlspecialchars(requestVar('imagetext')); - $imagepopup = requestVar('imagepopup'); - $width = intRequestVar('width'); - $height = intRequestVar('height'); - $fullurl = htmlspecialchars($CONF['MediaURL'] . $imagepopup); - - switch($what) - { - case 'url': - echo $fullurl; - break; - case 'width': - echo $width; - break; - case 'height': - echo $height; - break; - case 'caption': - case 'text': - echo $imagetext; - break; - case 'imgtag': - default: - echo "\"$imagetext\""; - break; - } - } - - // When commentform is not used, to include a hidden field with itemid - function parse_vars() { - global $itemid; - echo ''; - } - - // include a sitevar - function parse_sitevar($which) { - global $CONF; - switch($which) { - case 'url': - echo $CONF['IndexURL']; - break; - case 'name': - echo $CONF['SiteName']; - break; - case 'admin': - echo $CONF['AdminEmail']; - break; - case 'adminurl': - echo $CONF['AdminURL']; - } - } - - // shortcut for admin url - function parse_adminurl() { $this->parse_sitevar('adminurl'); } - - function parse_blogsetting($which) { - global $blog; - switch($which) { - case 'id': - echo $blog->getID(); - break; - case 'url': - echo $blog->getURL(); - break; - case 'name': - echo $blog->getName(); - break; - case 'desc': - echo $blog->getDescription(); - break; - case 'short': - echo $blog->getShortName(); - break; - } - } - - // includes a member info thingie - function parse_member($what) { - global $memberinfo, $member; - - // 1. only allow the member-details-page specific variables on member pages - if ($this->skintype == 'member') { - - switch($what) { - case 'name': - echo $memberinfo->getDisplayName(); - break; - case 'realname': - echo $memberinfo->getRealName(); - break; - case 'notes': - echo $memberinfo->getNotes(); - break; - case 'url': - echo $memberinfo->getURL(); - break; - case 'email': - echo $memberinfo->getEmail(); - break; - case 'id': - echo $memberinfo->getID(); - break; - } - } - - // 2. the next bunch of options is available everywhere, as long as the user is logged in - if ($member->isLoggedIn()) - { - switch($what) { - case 'yourname': - echo $member->getDisplayName(); - break; - case 'yourrealname': - echo $member->getRealName(); - break; - case 'yournotes': - echo $member->getNotes(); - break; - case 'yoururl': - echo $member->getURL(); - break; - case 'youremail': - echo $member->getEmail(); - break; - case 'yourid': - echo $member->getID(); - break; - } - } - - } - - function parse_preview($template) { - global $blog, $CONF, $manager; - - $template =& $manager->getTemplate($template); - $row['body'] = ''; - $row['title'] = ''; - $row['more'] = ''; - $row['itemlink'] = ''; - $row['itemid'] = 0; $row['blogid'] = $blog->getID(); - echo TEMPLATE::fill($template['ITEM_HEADER'],$row); - echo TEMPLATE::fill($template['ITEM'],$row); - echo TEMPLATE::fill($template['ITEM_FOOTER'],$row); - } - - function parse_additemform() { - global $blog, $CONF; - $this->formdata = array( - 'adminurl' => htmlspecialchars($CONF['AdminURL']), - 'catid' => $blog->getDefaultCategory() - ); - $blog->InsertJavaScriptInfo(); - $this->doForm('additemform'); - } - - /** - * Executes a plugin skinvar - * - * @param pluginName name of plugin (without the NP_) - * - * extra parameters can be added - */ - function parse_plugin($pluginName) { - global $manager; - - // only continue when the plugin is really installed - if (!$manager->pluginInstalled('NP_' . $pluginName)) - return; - - $plugin =& $manager->getPlugin('NP_' . $pluginName); - if (!$plugin) return; - - // get arguments - $params = func_get_args(); - - // remove plugin name - array_shift($params); - - // add skin type on front - array_unshift($params, $this->skintype); - - call_user_func_array(array(&$plugin,'doSkinVar'), $params); - } - - - function parse_commentform($destinationurl = '') { - global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage; - - // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0) - if (stristr($destinationurl, 'action.php')) { - $args = func_get_args(); - $destinationurl = $args[1]; - ACTIONLOG::add(WARNING,'actionurl is not longer a parameter on commentform skinvars. Moved to be a global setting instead.'); - } - - $actionurl = $CONF['ActionURL']; - - // if item is closed, show message and do nothing - $item =& $manager->getItem($itemid,0,0); - if ($item['closed'] || !$blog->commentsEnabled()) { - $this->doForm('commentform-closed'); - return; - } - - if (!$destinationurl) - $destinationurl = createItemLink($itemid, $this->linkparams); - - // values to prefill - $user = cookieVar($CONF['CookiePrefix'] .'comment_user'); - if (!$user) $user = postVar('user'); - $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid'); - if (!$userid) $userid = postVar('userid'); - $body = postVar('body'); - - $this->formdata = array( - 'destinationurl' => htmlspecialchars($destinationurl), - 'actionurl' => htmlspecialchars($actionurl), - 'itemid' => $itemid, - 'user' => htmlspecialchars($user), - 'userid' => htmlspecialchars($userid), - 'body' => htmlspecialchars($body), - 'membername' => $member->getDisplayName(), - 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':'' - ); - - if (!$member->isLoggedIn()) { - $this->doForm('commentform-notloggedin'); - } else { - $this->doForm('commentform-loggedin'); - } - } - - function parse_loginform() { - global $member, $CONF; - if (!$member->isLoggedIn()) { - $filename = 'loginform-notloggedin'; - $this->formdata = array(); - } else { - $filename = 'loginform-loggedin'; - $this->formdata = array( - 'membername' => $member->getDisplayName(), - ); - } - $this->doForm($filename); - } - - - function parse_membermailform($rows = 10, $cols = 40, $desturl = '') { - global $member, $CONF, $memberid; - - if ($desturl == '') { - if ($CONF['URLMode'] == 'pathinfo') - $desturl = createMemberLink($memberid); - else - $desturl = $CONF['IndexURL'] . createMemberLink($memberid); - } - - $message = postVar('message'); - $frommail = postVar('frommail'); - - $this->formdata = array( - 'url' => htmlspecialchars($desturl), - 'actionurl' => htmlspecialchars($CONF['ActionURL']), - 'memberid' => $memberid, - 'rows' => $rows, - 'cols' => $cols, - 'message' => htmlspecialchars($message), - 'frommail' => htmlspecialchars($frommail) - ); - if ($member->isLoggedIn()) { - $this->doForm('membermailform-loggedin'); - } else if ($CONF['NonmemberMail']) { - $this->doForm('membermailform-notloggedin'); - } else { - $this->doForm('membermailform-disallowed'); - } - - } - - function parse_searchform($blogname = '') { - global $CONF, $manager, $maxresults; - if ($blogname) { - $blog =& $manager->getBlog(getBlogIDFromName($blogname)); - } else { - global $blog; - } - // use default blog when no blog is selected - $this->formdata = array( - 'id' => $blog?$blog->getID():$CONF['DefaultBlog'], - 'query' => htmlspecialchars(getVar('query')), - ); - $this->doForm('searchform'); - } - - function parse_nucleusbutton($imgurl = '', - $imgwidth = '85', - $imgheight = '31') { - global $CONF; - if ($imgurl == '') { - $imgurl = $CONF['AdminURL'] . 'nucleus.gif'; - } else if (PARSER::getProperty('IncludeMode') == 'skindir'){ - // when skindit IncludeMode is used: start from skindir - $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl; - } - - $this->formdata = array( - 'imgurl' => $imgurl, - 'imgwidth' => $imgwidth, - 'imgheight' => $imgheight, - ); - $this->doForm('nucleusbutton'); - } - - function parse_self() { - global $CONF; - echo $CONF['Self']; - } - - function parse_referer() { - echo htmlspecialchars(serverVar('HTTP_REFERER')); - } - - /** - * Helper function that sets the category that a blog will need to use - * - * @param $blog - * An object of the blog class, passed by reference (we want to make changes to it) - * @param $catname - * The name of the category to use - */ - function _setBlogCategory(&$blog, $catname) { - global $catid; - if ($catname != '') - $blog->setSelectedCategoryByName($catname); - else - $blog->setSelectedCategory($catid); - } - - function _preBlogContent($type, &$blog) { - global $manager; - $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type)); - } - - function _postBlogContent($type, &$blog) { - global $manager; - $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type)); - } - -} - -?> +id = intval($id); + + // read skin name/description/content type + $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id); + $obj = mysql_fetch_object($res); + $this->isValid = (mysql_num_rows($res) > 0); + if (!$this->isValid) + return; + + $this->name = $obj->sdname; + $this->description = $obj->sddesc; + $this->contentType = $obj->sdtype; + $this->includeMode = $obj->sdincmode; + $this->includePrefix = $obj->sdincpref; + + } + + function getID() { return $this->id; } + function getName() { return $this->name; } + function getDescription() { return $this->description; } + function getContentType() { return $this->contentType; } + function getIncludeMode() { return $this->includeMode; } + function getIncludePrefix() { return $this->includePrefix; } + + /** + * Checks if a skin with a given shortname exists + * @param string $name Skin short name + * @return int number of skins with the given ID + * @static + */ + function exists($name) { + return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.addslashes($name).'"') > 0; + } + + /** + * Checks if a skin with a given ID exists + * @param string $id Skin ID + * @return int number of skins with the given ID + * @static + */ + function existsID($id) { + return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0; + } + + /** + * Returns a skin given its shortname + * @param string $name Skin shortname + * @return object SKIN + * @static + */ + function createFromName($name) { + return new SKIN(SKIN::getIdFromName($name)); + } + + /** + * Returns a skin ID given its shortname + * @param string $name Skin shortname + * @return int Skin ID + * @static + */ + function getIdFromName($name) { + $query = 'SELECT sdnumber' + . ' FROM '.sql_table('skin_desc') + . ' WHERE sdname="'.addslashes($name).'"'; + $res = sql_query($query); + $obj = mysql_fetch_object($res); + return $obj->sdnumber; + } + + /** + * Returns a skin shortname given its ID + * @param string $name + * @return string Skin short name + * @static + */ + function getNameFromId($id) { + return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id)); + } + + /** + * Creates a new skin, with the given characteristics. + * + * @static + */ + function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') { + global $manager; + + $manager->notify( + 'PreAddSkin', + array( + 'name' => &$name, + 'description' => &$desc, + 'type' => &$type, + 'includeMode' => &$includeMode, + 'includePrefix' => &$includePrefix + ) + ); + + sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "','".addslashes($type)."','".addslashes($includeMode)."','".addslashes($includePrefix)."')"); + $newid = mysql_insert_id(); + + $manager->notify( + 'PostAddSkin', + array( + 'skinid' => $newid, + 'name' => $name, + 'description' => $desc, + 'type' => $type, + 'includeMode' => $includeMode, + 'includePrefix' => $includePrefix + ) + ); + + return $newid; + } + + function parse($type) { + global $manager, $CONF; + + $manager->notify('InitSkinParse',array('skin' => &$this, 'type' => $type)); + + // set output type + sendContentType($this->getContentType(), 'skin', _CHARSET); + + // set skin name as global var (so plugins can access it) + global $currentSkinName; + $currentSkinName = $this->getName(); + + $contents = $this->getContent($type); + + if (!$contents) { + // use base skin if this skin does not have contents + $defskin =& new SKIN($CONF['BaseSkin']); + $contents = $defskin->getContent($type); + if (!$contents) { + echo _ERROR_SKIN; + return; + } + } + + $actions = $this->getAllowedActionsForType($type); + + $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type, 'contents' => &$contents)); + + // set IncludeMode properties of parser + PARSER::setProperty('IncludeMode',$this->getIncludeMode()); + PARSER::setProperty('IncludePrefix',$this->getIncludePrefix()); + + $handler =& new ACTIONS($type, $this); + $parser =& new PARSER($actions, $handler); + $handler->setParser($parser); + $handler->setSkin($this); + $parser->parse($contents); + + $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type)); + + + } + + function getContent($type) { + $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". addslashes($type) ."'"; + $res = sql_query($query); + + if (mysql_num_rows($res) == 0) + return ''; + else + return mysql_result($res, 0, 0); + } + + /** + * Updates the contents of one part of the skin + */ + function update($type, $content) { + $skinid = $this->id; + + // delete old thingie + sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".addslashes($type)."' and sdesc=" . intval($skinid)); + + // write new thingie + if ($content) { + sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . addslashes($content) . "', stype='" . addslashes($type) . "', sdesc=" . intval($skinid)); + } + } + + /** + * Deletes all skin parts from the database + */ + function deleteAllParts() { + sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID()); + } + + /** + * Updates the general information about the skin + */ + function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') { + $query = 'UPDATE '.sql_table('skin_desc').' SET' + . " sdname='" . addslashes($name) . "'," + . " sddesc='" . addslashes($desc) . "'," + . " sdtype='" . addslashes($type) . "'," + . " sdincmode='" . addslashes($includeMode) . "'," + . " sdincpref='" . addslashes($includePrefix) . "'" + . " WHERE sdnumber=" . $this->getID(); + sql_query($query); + } + + /** + * static: returns an array of friendly names + */ + function getFriendlyNames() { + $skintypes = array( + 'index' => _SKIN_PART_MAIN, + 'item' => _SKIN_PART_ITEM, + 'archivelist' => _SKIN_PART_ALIST, + 'archive' => _SKIN_PART_ARCHIVE, + 'search' => _SKIN_PART_SEARCH, + 'error' => _SKIN_PART_ERROR, + 'member' => _SKIN_PART_MEMBER, + 'imagepopup' => _SKIN_PART_POPUP + ); + + $query = "SELECT stype FROM " . sql_table('skin') . " WHERE stype NOT IN ('index', 'item', 'error', 'search', 'archive', 'archivelist', 'imagepopup', 'member')"; + $res = sql_query($query); + while ($row = mysql_fetch_array($res)) { + $skintypes[strtolower($row['stype'])] = ucfirst($row['stype']); + } + + return $skintypes; + } + + function getAllowedActionsForType($type) { + global $blogid; + + // some actions that can be performed at any time, from anywhere + $defaultActions = array('otherblog', + 'plugin', + 'version', + 'nucleusbutton', + 'include', + 'phpinclude', + 'parsedinclude', + 'loginform', + 'sitevar', + 'otherarchivelist', + 'otherarchivedaylist', + 'self', + 'adminurl', + 'todaylink', + 'archivelink', + 'member', + 'ifcat', // deprecated (Nucleus v2.0) + 'category', + 'searchform', + 'referer', + 'skinname', + 'skinfile', + 'set', + 'if', + 'else', + 'endif', + 'elseif', + 'ifnot', + 'elseifnot', + 'charset', + 'bloglist' + ); + + // extra actions specific for a certain skin type + $extraActions = array(); + + switch ($type) { + case 'index': + $extraActions = array('blog', + 'blogsetting', + 'preview', + 'additemform', + 'categorylist', + 'archivelist', + 'archivedaylist', + 'nextlink', + 'prevlink' + ); + break; + case 'archive': + $extraActions = array('blog', + 'archive', + 'otherarchive', + 'categorylist', + 'archivelist', + 'archivedaylist', + 'blogsetting', + 'archivedate', + 'nextarchive', + 'prevarchive', + 'nextlink', + 'prevlink', + 'archivetype' + ); + break; + case 'archivelist': + $extraActions = array('blog', + 'archivelist', + 'archivedaylist', + 'categorylist', + 'blogsetting', + ); + break; + case 'search': + $extraActions = array('blog', + 'archivelist', + 'archivedaylist', + 'categorylist', + 'searchresults', + 'othersearchresults', + 'blogsetting', + 'query', + 'nextlink', + 'prevlink' + ); + break; + case 'imagepopup': + $extraActions = array('image', + 'imagetext', // deprecated (Nucleus v2.0) + ); + break; + case 'member': + $extraActions = array( + 'membermailform', + 'blogsetting', + 'nucleusbutton' + ); + break; + case 'item': + $extraActions = array('blog', + 'item', + 'comments', + 'commentform', + 'vars', + 'blogsetting', + 'nextitem', + 'previtem', + 'nextlink', + 'prevlink', + 'nextitemtitle', + 'previtemtitle', + 'categorylist', + 'archivelist', + 'archivedaylist', + 'itemtitle', + 'itemid', + 'itemlink', + ); + break; + case 'error': + $extraActions = array( + 'errormessage' + ); + break; + default: + if ($blogid && $blogid > 0) { + $extraActions = array( + 'blog', + 'blogsetting', + 'preview', + 'additemform', + 'categorylist', + 'archivelist', + 'archivedaylist', + 'nextlink', + 'archivelist', + 'archivedaylist', + 'prevlink', + 'membermailform', + 'nucleusbutton' + ); + } + break; + } + + return array_merge($defaultActions, $extraActions); + } + +} + +?> diff --git a/euc/nucleus/libs/TEMPLATE.php b/euc/nucleus/libs/TEMPLATE.php index 23a4481..66c1984 100755 --- a/euc/nucleus/libs/TEMPLATE.php +++ b/euc/nucleus/libs/TEMPLATE.php @@ -1,187 +1,191 @@ -id = intval($templateid); - } - - function getID() { - return intval($this->id); - } - - // (static) - function createFromName($name) { - return new TEMPLATE(TEMPLATE::getIdFromName($name)); - } - - // (static) - function getIdFromName($name) { - $query = 'SELECT tdnumber' - . ' FROM '.sql_table('template_desc') - . ' WHERE tdname="'.addslashes($name).'"'; - $res = sql_query($query); - $obj = mysql_fetch_object($res); - return $obj->tdnumber; - } - - /** - * Updates the general information about the template - */ - function updateGeneralInfo($name, $desc) { - $query = 'UPDATE '.sql_table('template_desc').' SET' - . " tdname='" . addslashes($name) . "'," - . " tddesc='" . addslashes($desc) . "'" - . " WHERE tdnumber=" . $this->getID(); - sql_query($query); - } - - /** - * Updates the contents of one part of the template - */ - function update($type, $content) { - $id = $this->getID(); - - // delete old thingie - sql_query('DELETE FROM '.sql_table('template')." WHERE tpartname='". addslashes($type) ."' and tdesc=" . intval($id)); - - // write new thingie - if ($content) { - sql_query('INSERT INTO '.sql_table('template')." SET tcontent='" . addslashes($content) . "', tpartname='" . addslashes($type) . "', tdesc=" . intval($id)); - } - } - - - /** - * Deletes all template parts from the database - */ - function deleteAllParts() { - sql_query('DELETE FROM '.sql_table('template').' WHERE tdesc='.$this->getID()); - } - - /** - * Creates a new template - * - * (static) - */ - function createNew($name, $desc) { - global $manager; - - $manager->notify( - 'PreAddTemplate', - array( - 'name' => &$name, - 'description' => &$desc - ) - ); - - sql_query('INSERT INTO '.sql_table('template_desc')." (tdname, tddesc) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "')"); - $newId = mysql_insert_id(); - - $manager->notify( - 'PostAddTemplate', - array( - 'templateid' => $newId, - 'name' => $name, - 'description' => $desc - ) - ); - - return $newId; - } - - - - /** - * Reads a template and returns an array with the parts. - * (static) - * - * @param $name name of the template file - */ - function read($name) { - $query = 'SELECT tpartname, tcontent' - . ' FROM '.sql_table('template_desc').', '.sql_table('template') - . ' WHERE tdesc=tdnumber and tdname="' . addslashes($name) . '"'; - $res = sql_query($query); - while ($obj = mysql_fetch_object($res)) - $template[$obj->tpartname] = $obj->tcontent; - - // set locale according to template: - if ($template['LOCALE']) - setlocale(LC_TIME,$template['LOCALE']); - else - setlocale(LC_TIME,''); - - return $template; - } - - /** - * fills a template with values - * (static) - * - * @param $template - * Template to be used - * @param $values - * Array of all the values - */ - function fill($template, $values) { - - if (sizeof($values) != 0) { - // go through all the values - for(reset($values); $key = key($values); next($values)) { - $template = str_replace("<%$key%>",$values[$key],$template); - } - } - - // remove non matched template-tags - return preg_replace('/<%[a-zA-Z]+%>/','',$template); - } - - // returns true if there is a template with the given shortname - // (static) - function exists($name) { - $r = sql_query('select * FROM '.sql_table('template_desc').' WHERE tdname="'.addslashes($name).'"'); - return (mysql_num_rows($r) != 0); - } - - // returns true if there is a template with the given ID - // (static) - function existsID($id) { - $r = sql_query('select * FROM '.sql_table('template_desc').' WHERE tdnumber='.intval($id)); - return (mysql_num_rows($r) != 0); - } - - // (static) - function getNameFromId($id) { - return quickQuery('SELECT tdname as result FROM '.sql_table('template_desc').' WHERE tdnumber=' . intval($id)); - } - - // (static) - function getDesc($id) { - $query = 'SELECT tddesc FROM '.sql_table('template_desc').' WHERE tdnumber='. intval($id); - $obj = mysql_fetch_object(sql_query($query)); - return $obj->tddesc; - } - - - -} - -?> +id = intval($templateid); + } + + function getID() { + return intval($this->id); + } + + // (static) + function createFromName($name) { + return new TEMPLATE(TEMPLATE::getIdFromName($name)); + } + + // (static) + function getIdFromName($name) { + $query = 'SELECT tdnumber' + . ' FROM '.sql_table('template_desc') + . ' WHERE tdname="'.addslashes($name).'"'; + $res = sql_query($query); + $obj = mysql_fetch_object($res); + return $obj->tdnumber; + } + + /** + * Updates the general information about the template + */ + function updateGeneralInfo($name, $desc) { + $query = 'UPDATE '.sql_table('template_desc').' SET' + . " tdname='" . addslashes($name) . "'," + . " tddesc='" . addslashes($desc) . "'" + . " WHERE tdnumber=" . $this->getID(); + sql_query($query); + } + + /** + * Updates the contents of one part of the template + */ + function update($type, $content) { + $id = $this->getID(); + + // delete old thingie + sql_query('DELETE FROM '.sql_table('template')." WHERE tpartname='". addslashes($type) ."' and tdesc=" . intval($id)); + + // write new thingie + if ($content) { + sql_query('INSERT INTO '.sql_table('template')." SET tcontent='" . addslashes($content) . "', tpartname='" . addslashes($type) . "', tdesc=" . intval($id)); + } + } + + + /** + * Deletes all template parts from the database + */ + function deleteAllParts() { + sql_query('DELETE FROM '.sql_table('template').' WHERE tdesc='.$this->getID()); + } + + /** + * Creates a new template + * + * (static) + */ + function createNew($name, $desc) { + global $manager; + + $manager->notify( + 'PreAddTemplate', + array( + 'name' => &$name, + 'description' => &$desc + ) + ); + + sql_query('INSERT INTO '.sql_table('template_desc')." (tdname, tddesc) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "')"); + $newId = mysql_insert_id(); + + $manager->notify( + 'PostAddTemplate', + array( + 'templateid' => $newId, + 'name' => $name, + 'description' => $desc + ) + ); + + return $newId; + } + + + + /** + * Reads a template and returns an array with the parts. + * (static) + * + * @param $name name of the template file + */ + function read($name) { + $query = 'SELECT tpartname, tcontent' + . ' FROM '.sql_table('template_desc').', '.sql_table('template') + . ' WHERE tdesc=tdnumber and tdname="' . addslashes($name) . '"'; + $res = sql_query($query); + while ($obj = mysql_fetch_object($res)) + $template[$obj->tpartname] = $obj->tcontent; + + // set locale according to template: + if ($template['LOCALE']) + setlocale(LC_TIME,$template['LOCALE']); + else + setlocale(LC_TIME,''); + + return $template; + } + + /** + * fills a template with values + * (static) + * + * @param $template + * Template to be used + * @param $values + * Array of all the values + */ + function fill($template, $values) { + + if (sizeof($values) != 0) { + // go through all the values + for(reset($values); $key = key($values); next($values)) { + $template = str_replace("<%$key%>",$values[$key],$template); + } + } + + // remove non matched template-tags + return preg_replace('/<%[a-zA-Z]+%>/','',$template); + } + + // returns true if there is a template with the given shortname + // (static) + function exists($name) { + $r = sql_query('select * FROM '.sql_table('template_desc').' WHERE tdname="'.addslashes($name).'"'); + return (mysql_num_rows($r) != 0); + } + + // returns true if there is a template with the given ID + // (static) + function existsID($id) { + $r = sql_query('select * FROM '.sql_table('template_desc').' WHERE tdnumber='.intval($id)); + return (mysql_num_rows($r) != 0); + } + + // (static) + function getNameFromId($id) { + return quickQuery('SELECT tdname as result FROM '.sql_table('template_desc').' WHERE tdnumber=' . intval($id)); + } + + // (static) + function getDesc($id) { + $query = 'SELECT tddesc FROM '.sql_table('template_desc').' WHERE tdnumber='. intval($id); + $res = sql_query($query); + $obj = mysql_fetch_object($res); + return $obj->tddesc; + } + + + +} + +?> \ No newline at end of file diff --git a/euc/nucleus/libs/skinie.php b/euc/nucleus/libs/skinie.php index f9167d8..7a2b30b 100755 --- a/euc/nucleus/libs/skinie.php +++ b/euc/nucleus/libs/skinie.php @@ -1,565 +1,570 @@ -debug = 0; - - $this->reset(); - - } - - function reset() { - if ($this->parser) - xml_parser_free($this->parser); - - // XML file pointer - $this->fp = 0; - - // which data has been read? - $this->metaDataRead = 0; - $this->allRead = 0; - - // to maintain track of where we are inside the XML file - $this->inXml = 0; - $this->inData = 0; - $this->inMeta = 0; - $this->inSkin = 0; - $this->inTemplate = 0; - $this->currentName = ''; - $this->currentPartName = ''; - - // character data pile - $this->cdata = ''; - - // list of skinnames and templatenames (will be array of array) - $this->skins = array(); - $this->templates = array(); - - // extra info included in the XML files (e.g. installation notes) - $this->info = ''; - - // init XML parser - $this->parser = xml_parser_create(); - xml_set_object($this->parser, $this); - xml_set_element_handler($this->parser, 'startElement', 'endElement'); - xml_set_character_data_handler($this->parser, 'characterData'); - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); - - } - - /** - * Reads an XML file into memory - * - * @param $filename - * Which file to read - * @param $metaOnly - * Set to 1 when only the metadata needs to be read (optional, default 0) - */ - function readFile($filename, $metaOnly = 0) { - // open file - $this->fp = @fopen($filename, 'r'); - if (!$this->fp) return 'Failed to open file/URL'; - - // here we go! - $this->inXml = 1; - - while (!feof($this->fp)) { - $tempbuffer .= fread($this->fp, 4096); - } - fclose($this->fp); - -/* - [2004-08-04] dekarma - Took this out since it messes up good XML if it has skins/templates - with CDATA sections. need to investigate consequences. - see bug [ 999914 ] Import fails (multiple skins in XML/one of them with CDATA) - - // backwards compatibility with the non-wellformed skinbackup.xml files - // generated by v2/v3 (when CDATA sections were present in skins) - // split up those CDATA sections into multiple ones - $tempbuffer = preg_replace_callback( - "/(metaDataRead))) { - $err = xml_parse( $this->parser, $buffer, feof($temp) ); - if (!$err && $this->debug) - echo 'ERROR: ', xml_error_string(xml_get_error_code($this->parser)), '
'; - } - - // all done - $this->inXml = 0; - fclose($temp); - } - - /** - * Returns the list of skin names - */ - function getSkinNames() { - return array_keys($this->skins); - } - - /** - * Returns the list of template names - */ - function getTemplateNames() { - return array_keys($this->templates); - } - - /** - * Returns the extra information included in the XML file - */ - function getInfo() { - return $this->info; - } - - /** - * Writes the skins and templates to the database - * - * @param $allowOverwrite - * set to 1 when allowed to overwrite existing skins with the same name - * (default = 0) - */ - function writeToDatabase($allowOverwrite = 0) { - $existingSkins = $this->checkSkinNameClashes(); - $existingTemplates = $this->checkTemplateNameClashes(); - - // if not allowed to overwrite, check if any nameclashes exists - if (!$allowOverwrite) { - if ((sizeof($existingSkins) > 0) || (sizeof($existingTemplates) > 0)) - return 'Name clashes detected, re-run with allowOverwrite = 1 to force overwrite'; - } - - foreach ($this->skins as $skinName => $data) { - // 1. if exists: delete all part data, update desc data - // if not exists: create desc - if (in_array($skinName, $existingSkins)) { - $skinObj = SKIN::createFromName($skinName); - - // delete all parts of the skin - $skinObj->deleteAllParts(); - - // update general info - $skinObj->updateGeneralInfo($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']); - } else { - $skinid = SKIN::createNew($skinName, $data['description'], $data['type'], $data['includeMode'], $data['includePrefix']); - $skinObj = new SKIN($skinid); - } - - // 2. add parts - foreach ($data['parts'] as $partName => $partContent) { - $skinObj->update($partName, $partContent); - } - } - - foreach ($this->templates as $templateName => $data) { - // 1. if exists: delete all part data, update desc data - // if not exists: create desc - if (in_array($templateName, $existingTemplates)) { - $templateObj = TEMPLATE::createFromName($templateName); - - // delete all parts of the template - $templateObj->deleteAllParts(); - - // update general info - $templateObj->updateGeneralInfo($templateName, $data['description']); - } else { - $templateid = TEMPLATE::createNew($templateName, $data['description']); - $templateObj = new TEMPLATE($templateid); - } - - // 2. add parts - foreach ($data['parts'] as $partName => $partContent) { - $templateObj->update($partName, $partContent); - } - } - - - } - - /** - * returns an array of all the skin nameclashes (empty array when no name clashes) - */ - function checkSkinNameClashes() { - $clashes = array(); - - foreach ($this->skins as $skinName => $data) { - if (SKIN::exists($skinName)) - array_push($clashes, $skinName); - } - - return $clashes; - } - - /** - * returns an array of all the template nameclashes - * (empty array when no name clashes) - */ - function checkTemplateNameClashes() { - $clashes = array(); - - foreach ($this->templates as $templateName => $data) { - if (TEMPLATE::exists($templateName)) - array_push($clashes, $templateName); - } - - return $clashes; - } - - /** - * Called by XML parser for each new start element encountered - */ - function startElement($parser, $name, $attrs) { - if ($this->debug) echo 'START: ', $name, '
'; - - switch ($name) { - case 'nucleusskin': - $this->inData = 1; - break; - case 'meta': - $this->inMeta = 1; - break; - case 'info': - // no action needed - break; - case 'skin': - if (!$this->inMeta) { - $this->inSkin = 1; - $this->currentName = $attrs['name']; - $this->skins[$this->currentName]['type'] = $attrs['type']; - $this->skins[$this->currentName]['includeMode'] = $attrs['includeMode']; - $this->skins[$this->currentName]['includePrefix'] = $attrs['includePrefix']; - $this->skins[$this->currentName]['parts'] = array(); - } else { - $this->skins[$attrs['name']] = array(); - $this->skins[$attrs['name']]['parts'] = array(); - } - break; - case 'template': - if (!$this->inMeta) { - $this->inTemplate = 1; - $this->currentName = $attrs['name']; - $this->templates[$this->currentName]['parts'] = array(); - } else { - $this->templates[$attrs['name']] = array(); - $this->templates[$attrs['name']]['parts'] = array(); - } - break; - case 'description': - // no action needed - break; - case 'part': - $this->currentPartName = $attrs['name']; - break; - default: - echo 'UNEXPECTED TAG: ' , $name , '
'; - break; - } - - // character data never contains other tags - $this->clearCharacterData(); - - } - - /** - * Called by the XML parser for each closing tag encountered - */ - function endElement($parser, $name) { - if ($this->debug) echo 'END: ', $name, '
'; - - switch ($name) { - case 'nucleusskin': - $this->inData = 0; - $this->allRead = 1; - break; - case 'meta': - $this->inMeta = 0; - $this->metaDataRead = 1; - break; - case 'info': - $this->info = $this->getCharacterData(); - case 'skin': - if (!$this->inMeta) $this->inSkin = 0; - break; - case 'template': - if (!$this->inMeta) $this->inTemplate = 0; - break; - case 'description': - if ($this->inSkin) { - $this->skins[$this->currentName]['description'] = $this->getCharacterData(); - } else { - $this->templates[$this->currentName]['description'] = $this->getCharacterData(); - } - break; - case 'part': - if ($this->inSkin) { - $this->skins[$this->currentName]['parts'][$this->currentPartName] = $this->getCharacterData(); - } else { - $this->templates[$this->currentName]['parts'][$this->currentPartName] = $this->getCharacterData(); - } - break; - default: - echo 'UNEXPECTED TAG: ' , $name, '
'; - break; - } - $this->clearCharacterData(); - - } - - /** - * Called by XML parser for data inside elements - */ - function characterData ($parser, $data) { - if ($this->debug) echo 'NEW DATA: ', htmlspecialchars($data), '
'; - $this->cdata .= $data; - } - - /** - * Returns the data collected so far - */ - function getCharacterData() { - return $this->cdata; - } - - /** - * Clears the data buffer - */ - function clearCharacterData() { - $this->cdata = ''; - } - - /** - * Static method that looks for importable XML files in subdirs of the given dir - */ - function searchForCandidates($dir) { - $candidates = array(); - - $dirhandle = opendir($dir); - while ($filename = readdir($dirhandle)) { - if (@is_dir($dir . $filename) && ($filename != '.') && ($filename != '..')) { - $xml_file = $dir . $filename . '/skinbackup.xml'; - if (file_exists($xml_file) && is_readable($xml_file)) { - $candidates[$filename] = $filename; //$xml_file; - } - - // backwards compatibility - $xml_file = $dir . $filename . '/skindata.xml'; - if (file_exists($xml_file) && is_readable($xml_file)) { - $candidates[$filename] = $filename; //$xml_file; - } - } - } - closedir($dirhandle); - - return $candidates; - - } - - -} - - -class SKINEXPORT { - - var $templates; - var $skins; - var $info; - - /** - * Constructor initializes data structures - */ - function SKINEXPORT() { - // list of templateIDs to export - $this->templates = array(); - - // list of skinIDs to export - $this->skins = array(); - - // extra info to be in XML file - $this->info = ''; - } - - /** - * Adds a template to be exported - * - * @param id - * template ID - * @result false when no such ID exists - */ - function addTemplate($id) { - if (!TEMPLATE::existsID($id)) return 0; - - $this->templates[$id] = TEMPLATE::getNameFromId($id); - - return 1; - } - - /** - * Adds a skin to be exported - * - * @param id - * skin ID - * @result false when no such ID exists - */ - function addSkin($id) { - if (!SKIN::existsID($id)) return 0; - - $this->skins[$id] = SKIN::getNameFromId($id); - - return 1; - } - - /** - * Sets the extra info to be included in the exported file - */ - function setInfo($info) { - $this->info = $info; - } - - - /** - * Outputs the XML contents of the export file - * - * @param $setHeaders - * set to 0 if you don't want to send out headers - * (optional, default 1) - */ - function export($setHeaders = 1) { - if ($setHeaders) { - // make sure the mimetype is correct, and that the data does not show up - // in the browser, but gets saved into and XML file (popup download window) - header('Content-Type: text/xml'); - header('Content-Disposition: attachment; filename="skinbackup.xml"'); - header('Expires: 0'); - header('Pragma: no-cache'); - } - - echo "\n"; - - // meta - echo "\t\n"; - // skins - foreach ($this->skins as $skinId => $skinName) { - echo "\t\t", '',"\n"; - } - // templates - foreach ($this->templates as $templateId => $templateName) { - echo "\t\t", '