5 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
6 * Copyright (C) 2002-2005 The Nucleus Group
\r
8 * This program is free software; you can redistribute it and/or
\r
9 * modify it under the terms of the GNU General Public License
\r
10 * as published by the Free Software Foundation; either version 2
\r
11 * of the License, or (at your option) any later version.
\r
12 * (see nucleus/documentation/index.html#license for more info)
\r
14 * Class representing a skin
\r
16 * $Id: SKIN.php,v 1.4 2005-03-12 06:19:05 kimitake Exp $
\r
21 // after creating a SKIN object, evaluates to true when the skin exists
\r
24 // skin characteristics. Use the getXXX methods rather than accessing directly
\r
28 var $includeMode; // either 'normal' or 'skindir'
\r
32 function SKIN($id) {
\r
33 $this->id = intval($id);
\r
35 // read skin name/description/content type
\r
36 $res = sql_query('SELECT * FROM '.sql_table('skin_desc').' WHERE sdnumber=' . $this->id);
\r
37 $obj = mysql_fetch_object($res);
\r
38 $this->isValid = (mysql_num_rows($res) > 0);
\r
39 if (!$this->isValid)
\r
42 $this->name = $obj->sdname;
\r
43 $this->description = $obj->sddesc;
\r
44 $this->contentType = $obj->sdtype;
\r
45 $this->includeMode = $obj->sdincmode;
\r
46 $this->includePrefix = $obj->sdincpref;
\r
50 function getID() { return $this->id; }
\r
51 function getName() { return $this->name; }
\r
52 function getDescription() { return $this->description; }
\r
53 function getContentType() { return $this->contentType; }
\r
54 function getIncludeMode() { return $this->includeMode; }
\r
55 function getIncludePrefix() { return $this->includePrefix; }
\r
57 // returns true if there is a skin with the given shortname (static)
\r
58 function exists($name) {
\r
59 return quickQuery('select count(*) as result FROM '.sql_table('skin_desc').' WHERE sdname="'.addslashes($name).'"') > 0;
\r
62 // returns true if there is a skin with the given ID (static)
\r
63 function existsID($id) {
\r
64 return quickQuery('select COUNT(*) as result FROM '.sql_table('skin_desc').' WHERE sdnumber='.intval($id)) > 0;
\r
68 function createFromName($name) {
\r
69 return new SKIN(SKIN::getIdFromName($name));
\r
73 function getIdFromName($name) {
\r
74 $query = 'SELECT sdnumber'
\r
75 . ' FROM '.sql_table('skin_desc')
\r
76 . ' WHERE sdname="'.addslashes($name).'"';
\r
77 $res = sql_query($query);
\r
78 $obj = mysql_fetch_object($res);
\r
79 return $obj->sdnumber;
\r
83 function getNameFromId($id) {
\r
84 return quickQuery('SELECT sdname as result FROM '.sql_table('skin_desc').' WHERE sdnumber=' . intval($id));
\r
88 * Creates a new skin, with the given characteristics.
\r
92 function createNew($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
\r
99 'description' => &$desc,
\r
101 'includeMode' => &$includeMode,
\r
102 'includePrefix' => &$includePrefix
\r
106 sql_query('INSERT INTO '.sql_table('skin_desc')." (sdname, sddesc, sdtype, sdincmode, sdincpref) VALUES ('" . addslashes($name) . "','" . addslashes($desc) . "','".addslashes($type)."','".addslashes($includeMode)."','".addslashes($includePrefix)."')");
\r
107 $newid = mysql_insert_id();
\r
112 'skinid' => $newid,
\r
114 'description' => $desc,
\r
116 'includeMode' => $includeMode,
\r
117 'includePrefix' => $includePrefix
\r
124 function parse($type) {
\r
125 global $manager, $CONF;
\r
128 sendContentType($this->getContentType(), 'skin', _CHARSET);
\r
130 // set skin name as global var (so plugins can access it)
\r
131 global $currentSkinName;
\r
132 $currentSkinName = $this->getName();
\r
134 $contents = $this->getContent($type);
\r
137 // use base skin if this skin does not have contents
\r
138 $defskin =& new SKIN($CONF['BaseSkin']);
\r
139 $contents = $defskin->getContent($type);
\r
146 $actions = $this->getAllowedActionsForType($type);
\r
148 $manager->notify('PreSkinParse',array('skin' => &$this, 'type' => $type));
\r
150 // set IncludeMode properties of parser
\r
151 PARSER::setProperty('IncludeMode',$this->getIncludeMode());
\r
152 PARSER::setProperty('IncludePrefix',$this->getIncludePrefix());
\r
154 $handler =& new ACTIONS($type, $this);
\r
155 $parser =& new PARSER($actions, $handler);
\r
156 $handler->setParser($parser);
\r
157 $handler->setSkin($this);
\r
158 $parser->parse($contents);
\r
160 $manager->notify('PostSkinParse',array('skin' => &$this, 'type' => $type));
\r
165 function getContent($type) {
\r
166 $query = 'SELECT scontent FROM '.sql_table('skin')." WHERE sdesc=$this->id and stype='". addslashes($type) ."'";
\r
167 $res = sql_query($query);
\r
169 if (mysql_num_rows($res) == 0)
\r
172 return mysql_result($res, 0, 0);
\r
176 * Updates the contents of one part of the skin
\r
178 function update($type, $content) {
\r
179 $skinid = $this->id;
\r
181 // delete old thingie
\r
182 sql_query('DELETE FROM '.sql_table('skin')." WHERE stype='".addslashes($type)."' and sdesc=" . intval($skinid));
\r
184 // write new thingie
\r
186 sql_query('INSERT INTO '.sql_table('skin')." SET scontent='" . addslashes($content) . "', stype='" . addslashes($type) . "', sdesc=" . intval($skinid));
\r
191 * Deletes all skin parts from the database
\r
193 function deleteAllParts() {
\r
194 sql_query('DELETE FROM '.sql_table('skin').' WHERE sdesc='.$this->getID());
\r
198 * Updates the general information about the skin
\r
200 function updateGeneralInfo($name, $desc, $type = 'text/html', $includeMode = 'normal', $includePrefix = '') {
\r
201 $query = 'UPDATE '.sql_table('skin_desc').' SET'
\r
202 . " sdname='" . addslashes($name) . "',"
\r
203 . " sddesc='" . addslashes($desc) . "',"
\r
204 . " sdtype='" . addslashes($type) . "',"
\r
205 . " sdincmode='" . addslashes($includeMode) . "',"
\r
206 . " sdincpref='" . addslashes($includePrefix) . "'"
\r
207 . " WHERE sdnumber=" . $this->getID();
\r
208 sql_query($query);
\r
212 * static: returns an array of friendly names
\r
214 function getFriendlyNames() {
\r
216 'index' => _SKIN_PART_MAIN,
\r
217 'item' => _SKIN_PART_ITEM,
\r
218 'archivelist' => _SKIN_PART_ALIST,
\r
219 'archive' => _SKIN_PART_ARCHIVE,
\r
220 'search' => _SKIN_PART_SEARCH,
\r
221 'error' => _SKIN_PART_ERROR,
\r
222 'member' => _SKIN_PART_MEMBER,
\r
223 'imagepopup' => _SKIN_PART_POPUP
\r
227 function getAllowedActionsForType($type) {
\r
228 // some actions that can be performed at any time, from anywhere
\r
229 $defaultActions = array('otherblog',
\r
238 'otherarchivelist',
\r
239 'otherarchivedaylist',
\r
245 'ifcat', // deprecated (Nucleus v2.0)
\r
257 // extra actions specific for a certain skin type
\r
258 $extraActions = array();
\r
262 $extraActions = array('blog',
\r
274 $extraActions = array('blog',
\r
289 case 'archivelist':
\r
290 $extraActions = array('blog',
\r
298 $extraActions = array('blog',
\r
303 'othersearchresults',
\r
311 $extraActions = array('image',
\r
312 'imagetext', // deprecated (Nucleus v2.0)
\r
316 $extraActions = array(
\r
323 $extraActions = array('blog',
\r
344 $extraActions = array(
\r
349 return array_merge($defaultActions, $extraActions);
\r
356 * This class contains the functions that get called by using
\r
357 * the special tags in the skins
\r
359 * The allowed tags for a type of skinpart are defined by the
\r
360 * SKIN::getAllowedActionsForType($type) method
\r
362 class ACTIONS extends BaseActions {
\r
364 // part of the skin currently being parsed ('index', 'item', 'archive',
\r
365 // 'archivelist', 'member', 'search', 'error', 'imagepopup')
\r
368 // contains an assoc array with parameters that need to be included when
\r
369 // generating links to items/archives/... (e.g. catid)
\r
372 // reference to the skin object for which a part is being parsed
\r
376 // used when including templated forms from the include/ dir. The $formdata var
\r
377 // contains the values to fill out in there (assoc array name -> value)
\r
381 // filled out with the number of displayed items after calling one of the
\r
383 // (other)blog/(other)searchresults skinvars.
\r
387 function ACTIONS($type) {
\r
388 // call constructor of superclass first
\r
389 $this->BaseActions();
\r
391 $this->skintype = $type;
\r
395 $this->linkparams = array('catid' => $catid);
\r
398 function setSkin(&$skin) {
\r
399 $this->skin =& $skin;
\r
402 function setParser(&$parser) {
\r
403 $this->parser =& $parser;
\r
407 Forms get parsedincluded now, using an extra <formdata> skinvar
\r
409 function doForm($filename) {
\r
410 global $DIR_NUCLEUS;
\r
411 array_push($this->parser->actions,'formdata','text','callback','errordiv');
\r
412 $oldIncludeMode = PARSER::getProperty('IncludeMode');
\r
413 $oldIncludePrefix = PARSER::getProperty('IncludePrefix');
\r
414 PARSER::setProperty('IncludeMode','normal');
\r
415 PARSER::setProperty('IncludePrefix','');
\r
416 $this->parse_parsedinclude($DIR_NUCLEUS . 'forms/' . $filename . '.template');
\r
417 PARSER::setProperty('IncludeMode',$oldIncludeMode);
\r
418 PARSER::setProperty('IncludePrefix',$oldIncludePrefix);
\r
419 array_pop($this->parser->actions); // errordiv
\r
420 array_pop($this->parser->actions); // callback
\r
421 array_pop($this->parser->actions); // text
\r
422 array_pop($this->parser->actions); // formdata
\r
424 function parse_formdata($what) {
\r
425 echo $this->formdata[$what];
\r
427 function parse_text($which) {
\r
428 // constant($which) only available from 4.0.4 :(
\r
429 if (defined($which)) {
\r
430 eval("echo $which;");
\r
433 function parse_callback($eventName, $type)
\r
436 $manager->notify($eventName, array('type' => $type));
\r
438 function parse_errordiv() {
\r
439 global $errormessage;
\r
441 echo '<div class="error">', htmlspecialchars($errormessage),'</div>';
\r
444 function parse_skinname() {
\r
445 echo $this->skin->getName();
\r
448 function parse_if($field, $name='', $value = '') {
\r
449 global $catid, $blog, $member, $itemidnext, $itemidprev, $manager;
\r
454 $condition = ($blog && $this->_ifCategory($name,$value));
\r
456 case 'blogsetting':
\r
457 if ($name == 'trackback' && $manager->pluginInstalled('NP_TrackBack')) {
\r
458 $plugin =& $manager->getPlugin('NP_TrackBack');
\r
459 if ($plugin != NULL && $blog){
\r
460 $bid = $blog->getID();
\r
461 if ($value === '1') $value = 'yes';
\r
462 if ($value === '0') $value = 'no';
\r
463 if ($plugin->getOption('AcceptPing') == 'no' ) {
\r
464 $condition = ($value == 'no');
\r
466 $tb_option = $plugin->getBlogOption($bid,'AllowTrackBack');
\r
468 $condition = ($value == 'yes');
\r
470 $condition = ($tb_option == $value);
\r
476 $condition = ($blog && ($blog->getSetting($name) == $value));
\r
479 $condition = $member->isLoggedIn();
\r
482 $condition = $member->isLoggedIn() && $this->_ifOnTeam($name);
\r
485 $condition = $member->isLoggedIn() && $this->_ifAdmin($name);
\r
488 $condition = ($itemidnext != '');
\r
491 $condition = ($itemidprev != '');
\r
494 $condition = ($name == $this->skintype);
\r
498 -> checks if plugin exists
\r
499 hasplugin,PlugName,OptionName
\r
500 -> checks if the option OptionName from plugin PlugName is not set to 'no'
\r
501 hasplugin,PlugName,OptionName=value
\r
502 -> checks if the option OptionName from plugin PlugName is set to value
\r
505 $condition = false;
\r
506 // (pluginInstalled method won't write a message in the actionlog on failure)
\r
507 if ($manager->pluginInstalled('NP_'.$name))
\r
509 $plugin =& $manager->getPlugin('NP_' . $name);
\r
510 if ($plugin != NULL){
\r
511 if ($value == "") {
\r
514 list($name2, $value2) = explode('=', $value, 2);
\r
515 if ($value2 == "" && $plugin->getOption($name2) != 'no') {
\r
517 } else if ($plugin->getOption($name2) == $value2) {
\r
527 $this->_addIfCondition($condition);
\r
530 function _ifCategory($name = '', $value='') {
\r
531 global $blog, $catid;
\r
533 // when no parameter is defined, just check if a category is selected
\r
534 if (($name != 'catname' && $name != 'catid') || ($value == ''))
\r
535 return $blog->isValidCategory($catid);
\r
537 // check category name
\r
538 if ($name == 'catname') {
\r
539 $value = $blog->getCategoryIdFromName($value);
\r
540 if ($value == $catid)
\r
541 return $blog->isValidCategory($catid);
\r
544 // check category id
\r
545 if (($name == 'catid') && ($value == $catid))
\r
546 return $blog->isValidCategory($catid);
\r
551 function _ifOnTeam($blogName = '') {
\r
552 global $blog, $member, $manager;
\r
554 // when no blog found
\r
555 if (($blogName == '') && (!is_object($blog)))
\r
558 // explicit blog selection
\r
559 if ($blogName != '')
\r
560 $blogid = getBlogIDFromName($blogName);
\r
562 if (($blogName == '') || !$manager->existsBlogID($blogid))
\r
563 // use current blog
\r
564 $blogid = $blog->getID();
\r
566 return $member->teamRights($blogid);
\r
569 function _ifAdmin($blogName = '') {
\r
570 global $blog, $member, $manager;
\r
572 // when no blog found
\r
573 if (($blogName == '') && (!is_object($blog)))
\r
576 // explicit blog selection
\r
577 if ($blogName != '')
\r
578 $blogid = getBlogIDFromName($blogName);
\r
580 if (($blogName == '') || !$manager->existsBlogID($blogid))
\r
581 // use current blog
\r
582 $blogid = $blog->getID();
\r
584 return $member->isBlogAdmin($blogid);
\r
587 function parse_ifcat($text = '') {
\r
590 $this->parse_if('category');
\r
593 global $catid, $blog;
\r
594 if ($blog->isValidCategory($catid))
\r
599 // a link to the today page (depending on selected blog, etc...)
\r
600 function parse_todaylink($linktext = '') {
\r
601 global $blog, $CONF;
\r
603 echo $this->_link(createBlogidLink($blog->getID(),$this->linkparams), $linktext);
\r
605 echo $this->_link($CONF['SiteUrl'], $linktext);
\r
608 // a link to the archives for the current blog (or for default blog)
\r
609 function parse_archivelink($linktext = '') {
\r
610 global $blog, $CONF;
\r
612 echo $this->_link(createArchiveListLink($blog->getID(),$this->linkparams), $linktext);
\r
614 echo $this->_link(createArchiveListLink(), $linktext);
\r
617 // include itemid of prev item
\r
618 function parse_previtem() {
\r
619 global $itemidprev;
\r
623 // include itemtitle of prev item
\r
624 function parse_previtemtitle() {
\r
625 global $itemtitleprev;
\r
626 echo htmlspecialchars($itemtitleprev);
\r
629 // include itemid of next item
\r
630 function parse_nextitem() {
\r
631 global $itemidnext;
\r
635 // include itemtitle of next item
\r
636 function parse_nextitemtitle() {
\r
637 global $itemtitlenext;
\r
638 echo htmlspecialchars($itemtitlenext);
\r
641 function parse_prevarchive() {
\r
642 global $archiveprev;
\r
646 function parse_nextarchive() {
\r
647 global $archivenext;
\r
651 function parse_archivetype() {
\r
652 global $archivetype;
\r
656 function parse_prevlink($linktext = '', $amount = 10) {
\r
657 global $itemidprev, $archiveprev, $startpos;
\r
659 if ($this->skintype == 'item')
\r
660 $this->_itemlink($itemidprev, $linktext);
\r
661 else if ($this->skintype == 'search' || $this->skintype == 'index')
\r
662 $this->_searchlink($amount, $startpos, 'prev', $linktext);
\r
664 $this->_archivelink($archiveprev, $linktext);
\r
667 function parse_nextlink($linktext = '', $amount = 10) {
\r
668 global $itemidnext, $archivenext, $startpos;
\r
669 if ($this->skintype == 'item')
\r
670 $this->_itemlink($itemidnext, $linktext);
\r
671 else if ($this->skintype == 'search' || $this->skintype == 'index')
\r
672 $this->_searchlink($amount, $startpos, 'next', $linktext);
\r
674 $this->_archivelink($archivenext, $linktext);
\r
679 * - a raw link (html/xml encoded) when no linktext is provided
\r
680 * - a (x)html <a href... link when a text is present (text htmlencoded)
\r
682 function _link($url, $linktext = '')
\r
684 $u = htmlspecialchars($url);
\r
685 $u = preg_replace("/&amp;/",'&',$u); // fix URLs that already had encoded ampersands
\r
686 if ($linktext != '')
\r
687 $l = '<a href="' . $u .'">'.htmlspecialchars($linktext).'</a>';
\r
694 * Outputs a next/prev link
\r
696 * @param $maxresults
\r
697 * The maximum amount of items shown per page (e.g. 10)
\r
699 * Current start position (requestVar('startpos'))
\r
700 * @param $direction
\r
701 * either 'prev' or 'next'
\r
703 * When present, the output will be a full <a href...> link. When empty,
\r
704 * only a raw link will be outputted
\r
706 function _searchlink($maxresults, $startpos, $direction, $linktext = '') {
\r
707 global $CONF, $blog, $query, $amount;
\r
708 // TODO: Move request uri to linkparams. this is ugly. sorry for that.
\r
709 $startpos = intval($startpos); // will be 0 when empty.
\r
710 $parsed = parse_url(serverVar('REQUEST_URI'));
\r
711 $parsed = $parsed['query'];
\r
714 switch ($direction) {
\r
716 if ( intval($startpos) - intval($maxresults) >= 0) {
\r
717 $startpos = intval($startpos) - intval($maxresults);
\r
718 $url = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
\r
722 $iAmountOnPage = $this->amountfound;
\r
723 if ($iAmountOnPage == 0)
\r
725 // [%nextlink%] or [%prevlink%] probably called before [%blog%] or [%searchresults%]
\r
726 // try a count query
\r
727 switch ($this->skintype)
\r
730 $sqlquery = $blog->getSqlBlog('', 'count');
\r
733 $sqlquery = $blog->getSqlSearch($query, $amount, $unused_highlight, 'count');
\r
737 $iAmountOnPage = intval(quickQuery($sqlquery)) - intval($startpos);
\r
739 if (intval($iAmountOnPage) >= intval($maxresults)) {
\r
740 $startpos = intval($startpos) + intval($maxresults);
\r
741 $url = $CONF['SearchURL'].'?'.alterQueryStr($parsed,'startpos',$startpos);
\r
746 } // switch($direction)
\r
749 echo $this->_link($url, $linktext);
\r
752 function _itemlink($id, $linktext = '') {
\r
755 echo $this->_link(createItemLink($id, $this->linkparams), $linktext);
\r
757 $this->parse_todaylink($linktext);
\r
760 function _archivelink($id, $linktext = '') {
\r
761 global $CONF, $blog;
\r
763 echo $this->_link(createArchiveLink($blog->getID(), $id, $this->linkparams), $linktext);
\r
765 $this->parse_todaylink($linktext);
\r
769 function parse_itemlink($linktext = '') {
\r
770 $this->_itemlink($itemid, $linktext);
\r
774 * %archivedate(locale,date format)%
\r
776 function parse_archivedate($locale = '-def-') {
\r
779 if ($locale == '-def-')
\r
780 setlocale(LC_TIME,$template['LOCALE']);
\r
782 setlocale(LC_TIME,$locale);
\r
784 // get archive date
\r
785 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
788 $args = func_get_args();
\r
789 // format can be spread over multiple parameters
\r
790 if (sizeof($args) > 1) {
\r
791 // take away locale
\r
792 array_shift($args);
\r
794 $format=implode(',',$args);
\r
795 } elseif ($d == 0) {
\r
796 $format = '%B %Y';
\r
798 $format = '%d %B %Y';
\r
801 echo strftime($format,mktime(0,0,0,$m,$d?$d:1,$y));
\r
804 function parse_blog($template, $amount = 10, $category = '') {
\r
805 global $blog, $startpos;
\r
807 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
808 $this->_setBlogCategory($blog, $category);
\r
809 $this->_preBlogContent('blog',$blog);
\r
810 $this->amountfound = $blog->readLog($template, $limit, $offset, $startpos);
\r
811 $this->_postBlogContent('blog',$blog);
\r
814 function parse_otherblog($blogname, $template, $amount = 10, $category = '') {
\r
817 list($limit, $offset) = sscanf($amount, '%d(%d)');
\r
819 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
820 $this->_setBlogCategory($b, $category);
\r
821 $this->_preBlogContent('otherblog',$b);
\r
822 $this->amountfound = $b->readLog($template, $limit, $offset);
\r
823 $this->_postBlogContent('otherblog',$b);
\r
826 // include one item (no comments)
\r
827 function parse_item($template) {
\r
828 global $blog, $itemid, $highlight;
\r
829 $this->_setBlogCategory($blog, ''); // need this to select default category
\r
830 $this->_preBlogContent('item',$blog);
\r
831 $r = $blog->showOneitem($itemid, $template, $highlight);
\r
833 echo _ERROR_NOSUCHITEM;
\r
834 $this->_postBlogContent('item',$blog);
\r
837 function parse_itemid() {
\r
843 // include comments for one item
\r
844 function parse_comments($template) {
\r
845 global $itemid, $manager, $blog, $highlight;
\r
846 $template =& $manager->getTemplate($template);
\r
848 // create parser object & action handler
\r
849 $actions =& new ITEMACTIONS($blog);
\r
850 $parser =& new PARSER($actions->getDefinedActions(),$actions);
\r
851 $actions->setTemplate($template);
\r
852 $actions->setParser($parser);
\r
853 $item = ITEM::getitem($itemid, 0, 0);
\r
854 $actions->setCurrentItem($item);
\r
856 $comments =& new COMMENTS($itemid);
\r
857 $comments->setItemActions($actions);
\r
858 $comments->showComments($template, -1, 1, $highlight); // shows ALL comments
\r
861 function parse_archive($template, $category = '') {
\r
862 global $blog, $archive;
\r
863 // can be used with either yyyy-mm or yyyy-mm-dd
\r
864 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
865 $this->_setBlogCategory($blog, $category);
\r
866 $this->_preBlogContent('achive',$blog);
\r
867 $blog->showArchive($template, $y, $m, $d);
\r
868 $this->_postBlogContent('achive',$blog);
\r
872 function parse_otherarchive($blogname, $template, $category = '') {
\r
873 global $archive, $manager;
\r
874 sscanf($archive,'%d-%d-%d',$y,$m,$d);
\r
875 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
876 $this->_setBlogCategory($b, $category);
\r
877 $this->_preBlogContent('otherachive',$b);
\r
878 $b->showArchive($template, $y, $m, $d);
\r
879 $this->_postBlogContent('otherachive',$b);
\r
882 function parse_archivelist($template, $category = 'all', $limit = 0) {
\r
884 if ($category == 'all') $category = '';
\r
885 $this->_preBlogContent('archivelist',$blog);
\r
886 $this->_setBlogCategory($blog, $category);
\r
887 $blog->showArchiveList($template, 'month', $limit);
\r
888 $this->_postBlogContent('archivelist',$blog);
\r
891 function parse_archivedaylist($template, $category = 'all', $limit = 0) {
\r
893 if ($category == 'all') $category = '';
\r
894 $this->_preBlogContent('archivelist',$blog);
\r
895 $this->_setBlogCategory($blog, $category);
\r
896 $blog->showArchiveList($template, 'day', $limit);
\r
897 $this->_postBlogContent('archivelist',$blog);
\r
901 function parse_itemtitle() {
\r
902 global $manager, $itemid;
\r
903 $item =& $manager->getItem($itemid,0,0);
\r
904 echo htmlspecialchars(strip_tags($item['title']));
\r
907 function parse_categorylist($template, $blogname = '') {
\r
908 global $blog, $manager;
\r
910 if ($blogname == '') {
\r
911 $this->_preBlogContent('categorylist',$blog);
\r
912 $blog->showCategoryList($template);
\r
913 $this->_postBlogContent('categorylist',$blog);
\r
915 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
916 $this->_preBlogContent('categorylist',$b);
\r
917 $b->showCategoryList($template);
\r
918 $this->_postBlogContent('categorylist',$b);
\r
922 function parse_category($type = 'name') {
\r
923 global $catid, $blog;
\r
924 if (!$blog->isValidCategory($catid))
\r
929 echo $blog->getCategoryName($catid);
\r
932 echo $blog->getCategoryDesc($catid);
\r
940 function parse_otherarchivelist($blogname, $template, $category = 'all', $limit = 0) {
\r
942 if ($category == 'all') $category = '';
\r
943 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
944 $this->_setBlogCategory($b, $category);
\r
945 $this->_preBlogContent('otherarchivelist',$b);
\r
946 $b->showArchiveList($template, 'month', $limit);
\r
947 $this->_postBlogContent('otherarchivelist',$b);
\r
950 function parse_otherarchivedaylist($blogname, $template, $category = 'all', $limit = 0) {
\r
952 if ($category == 'all') $category = '';
\r
953 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
954 $this->_setBlogCategory($b, $category);
\r
955 $this->_preBlogContent('otherarchivelist',$b);
\r
956 $b->showArchiveList($template, 'day', $limit);
\r
957 $this->_postBlogContent('otherarchivelist',$b);
\r
960 function parse_searchresults($template, $maxresults = 50 ) {
\r
961 global $blog, $query, $amount, $startpos;
\r
963 $this->_setBlogCategory($blog, ''); // need this to select default category
\r
964 $this->_preBlogContent('searchresults',$blog);
\r
965 $this->amountfound = $blog->search($query, $template, $amount, $maxresults, $startpos);
\r
966 $this->_postBlogContent('searchresults',$blog);
\r
969 function parse_othersearchresults($blogname, $template, $maxresults = 50) {
\r
970 global $query, $amount, $manager, $startpos;
\r
971 $b =& $manager->getBlog(getBlogIDFromName($blogname));
\r
972 $this->_setBlogCategory($b, ''); // need this to select default category
\r
973 $this->_preBlogContent('othersearchresults',$b);
\r
974 $b->search($query, $template, $amount, $maxresults, $startpos);
\r
975 $this->_postBlogContent('othersearchresults',$b);
\r
978 // includes the search query
\r
979 function parse_query() {
\r
981 echo htmlspecialchars($query);
\r
984 // include nucleus versionnumber
\r
985 function parse_version() {
\r
987 echo 'Nucleus CMS ' . $nucleus['version'];
\r
991 function parse_errormessage() {
\r
992 global $errormessage;
\r
993 echo $errormessage;
\r
997 function parse_imagetext() {
\r
998 echo htmlspecialchars(requestVar('imagetext'));
\r
1001 function parse_image($what = 'imgtag') {
\r
1004 $imagetext = htmlspecialchars(requestVar('imagetext'));
\r
1005 $imagepopup = requestVar('imagepopup');
\r
1006 $width = intRequestVar('width');
\r
1007 $height = intRequestVar('height');
\r
1008 $fullurl = htmlspecialchars($CONF['MediaURL'] . $imagepopup);
\r
1027 echo "<img src=\"$fullurl\" width=\"$width\" height=\"$height\" alt=\"$imagetext\" title=\"$imagetext\" />";
\r
1032 // When commentform is not used, to include a hidden field with itemid
\r
1033 function parse_vars() {
\r
1035 echo '<input type="hidden" name="itemid" value="'.$itemid.'" />';
\r
1038 // include a sitevar
\r
1039 function parse_sitevar($which) {
\r
1043 echo $CONF['IndexURL'];
\r
1046 echo $CONF['SiteName'];
\r
1049 echo $CONF['AdminEmail'];
\r
1052 echo $CONF['AdminURL'];
\r
1056 // shortcut for admin url
\r
1057 function parse_adminurl() { $this->parse_sitevar('adminurl'); }
\r
1059 function parse_blogsetting($which) {
\r
1063 echo $blog->getID();
\r
1066 echo $blog->getURL();
\r
1069 echo $blog->getName();
\r
1072 echo $blog->getDescription();
\r
1075 echo $blog->getShortName();
\r
1080 // includes a member info thingie
\r
1081 function parse_member($what) {
\r
1082 global $memberinfo, $member;
\r
1084 // 1. only allow the member-details-page specific variables on member pages
\r
1085 if ($this->skintype == 'member') {
\r
1089 echo $memberinfo->getDisplayName();
\r
1092 echo $memberinfo->getRealName();
\r
1095 echo $memberinfo->getNotes();
\r
1098 echo $memberinfo->getURL();
\r
1101 echo $memberinfo->getEmail();
\r
1104 echo $memberinfo->getID();
\r
1109 // 2. the next bunch of options is available everywhere, as long as the user is logged in
\r
1110 if ($member->isLoggedIn())
\r
1114 echo $member->getDisplayName();
\r
1116 case 'yourrealname':
\r
1117 echo $member->getRealName();
\r
1120 echo $member->getNotes();
\r
1123 echo $member->getURL();
\r
1126 echo $member->getEmail();
\r
1129 echo $member->getID();
\r
1136 function parse_preview($template) {
\r
1137 global $blog, $CONF, $manager;
\r
1139 $template =& $manager->getTemplate($template);
\r
1140 $row['body'] = '<span id="prevbody"></span>';
\r
1141 $row['title'] = '<span id="prevtitle"></span>';
\r
1142 $row['more'] = '<span id="prevmore"></span>';
\r
1143 $row['itemlink'] = '';
\r
1144 $row['itemid'] = 0; $row['blogid'] = $blog->getID();
\r
1145 echo TEMPLATE::fill($template['ITEM_HEADER'],$row);
\r
1146 echo TEMPLATE::fill($template['ITEM'],$row);
\r
1147 echo TEMPLATE::fill($template['ITEM_FOOTER'],$row);
\r
1150 function parse_additemform() {
\r
1151 global $blog, $CONF;
\r
1152 $this->formdata = array(
\r
1153 'adminurl' => htmlspecialchars($CONF['AdminURL']),
\r
1154 'catid' => $blog->getDefaultCategory()
\r
1156 $blog->InsertJavaScriptInfo();
\r
1157 $this->doForm('additemform');
\r
1161 * Executes a plugin skinvar
\r
1163 * @param pluginName name of plugin (without the NP_)
\r
1165 * extra parameters can be added
\r
1167 function parse_plugin($pluginName) {
\r
1170 // only continue when the plugin is really installed
\r
1171 if (!$manager->pluginInstalled('NP_' . $pluginName))
\r
1174 $plugin =& $manager->getPlugin('NP_' . $pluginName);
\r
1175 if (!$plugin) return;
\r
1178 $params = func_get_args();
\r
1180 // remove plugin name
\r
1181 array_shift($params);
\r
1183 // add skin type on front
\r
1184 array_unshift($params, $this->skintype);
\r
1186 call_user_func_array(array(&$plugin,'doSkinVar'), $params);
\r
1190 function parse_commentform($destinationurl = '') {
\r
1191 global $blog, $itemid, $member, $CONF, $manager, $DIR_LIBS, $errormessage;
\r
1193 // warn when trying to provide a actionurl (used to be a parameter in Nucleus <2.0)
\r
1194 if (stristr($destinationurl, 'action.php')) {
\r
1195 $args = func_get_args();
\r
1196 $destinationurl = $args[1];
\r
1197 ACTIONLOG::add(WARNING,'actionurl is not longer a parameter on commentform skinvars. Moved to be a global setting instead.');
\r
1200 $actionurl = $CONF['ActionURL'];
\r
1202 // if item is closed, show message and do nothing
\r
1203 $item =& $manager->getItem($itemid,0,0);
\r
1204 if ($item['closed'] || !$blog->commentsEnabled()) {
\r
1205 $this->doForm('commentform-closed');
\r
1209 if (!$destinationurl)
\r
1210 $destinationurl = createItemLink($itemid, $this->linkparams);
\r
1212 // values to prefill
\r
1213 $user = cookieVar($CONF['CookiePrefix'] .'comment_user');
\r
1214 if (!$user) $user = postVar('user');
\r
1215 $userid = cookieVar($CONF['CookiePrefix'] .'comment_userid');
\r
1216 if (!$userid) $userid = postVar('userid');
\r
1217 $body = postVar('body');
\r
1219 $this->formdata = array(
\r
1220 'destinationurl' => htmlspecialchars($destinationurl),
\r
1221 'actionurl' => htmlspecialchars($actionurl),
\r
1222 'itemid' => $itemid,
\r
1223 'user' => htmlspecialchars($user),
\r
1224 'userid' => htmlspecialchars($userid),
\r
1225 'body' => htmlspecialchars($body),
\r
1226 'membername' => $member->getDisplayName(),
\r
1227 'rememberchecked' => cookieVar($CONF['CookiePrefix'] .'comment_user')?'checked="checked"':''
\r
1230 if (!$member->isLoggedIn()) {
\r
1231 $this->doForm('commentform-notloggedin');
\r
1233 $this->doForm('commentform-loggedin');
\r
1237 function parse_loginform() {
\r
1238 global $member, $CONF;
\r
1239 if (!$member->isLoggedIn()) {
\r
1240 $filename = 'loginform-notloggedin';
\r
1241 $this->formdata = array();
\r
1243 $filename = 'loginform-loggedin';
\r
1244 $this->formdata = array(
\r
1245 'membername' => $member->getDisplayName(),
\r
1248 $this->doForm($filename);
\r
1252 function parse_membermailform($rows = 10, $cols = 40, $desturl = '') {
\r
1253 global $member, $CONF, $memberid;
\r
1255 if ($desturl == '') {
\r
1256 if ($CONF['URLMode'] == 'pathinfo')
\r
1257 $desturl = createMemberLink($memberid);
\r
1259 $desturl = $CONF['IndexURL'] . createMemberLink($memberid);
\r
1262 $message = postVar('message');
\r
1263 $frommail = postVar('frommail');
\r
1265 $this->formdata = array(
\r
1266 'url' => htmlspecialchars($desturl),
\r
1267 'actionurl' => htmlspecialchars($CONF['ActionURL']),
\r
1268 'memberid' => $memberid,
\r
1271 'message' => htmlspecialchars($message),
\r
1272 'frommail' => htmlspecialchars($frommail)
\r
1274 if ($member->isLoggedIn()) {
\r
1275 $this->doForm('membermailform-loggedin');
\r
1276 } else if ($CONF['NonmemberMail']) {
\r
1277 $this->doForm('membermailform-notloggedin');
\r
1279 $this->doForm('membermailform-disallowed');
\r
1284 function parse_searchform($blogname = '') {
\r
1285 global $CONF, $manager, $maxresults;
\r
1287 $blog =& $manager->getBlog(getBlogIDFromName($blogname));
\r
1291 // use default blog when no blog is selected
\r
1292 $this->formdata = array(
\r
1293 'id' => $blog?$blog->getID():$CONF['DefaultBlog'],
\r
1294 'query' => htmlspecialchars(getVar('query')),
\r
1296 $this->doForm('searchform');
\r
1299 function parse_nucleusbutton($imgurl = '',
\r
1301 $imgheight = '31') {
\r
1303 if ($imgurl == '') {
\r
1304 $imgurl = $CONF['AdminURL'] . 'nucleus.gif';
\r
1305 } else if (PARSER::getProperty('IncludeMode') == 'skindir'){
\r
1306 // when skindit IncludeMode is used: start from skindir
\r
1307 $imgurl = $CONF['SkinsURL'] . PARSER::getProperty('IncludePrefix') . $imgurl;
\r
1310 $this->formdata = array(
\r
1311 'imgurl' => $imgurl,
\r
1312 'imgwidth' => $imgwidth,
\r
1313 'imgheight' => $imgheight,
\r
1315 $this->doForm('nucleusbutton');
\r
1318 function parse_self() {
\r
1320 echo $CONF['Self'];
\r
1323 function parse_referer() {
\r
1324 echo htmlspecialchars(serverVar('HTTP_REFERER'));
\r
1328 * Helper function that sets the category that a blog will need to use
\r
1331 * An object of the blog class, passed by reference (we want to make changes to it)
\r
1333 * The name of the category to use
\r
1335 function _setBlogCategory(&$blog, $catname) {
\r
1337 if ($catname != '')
\r
1338 $blog->setSelectedCategoryByName($catname);
\r
1340 $blog->setSelectedCategory($catid);
\r
1343 function _preBlogContent($type, &$blog) {
\r
1345 $manager->notify('PreBlogContent',array('blog' => &$blog, 'type' => $type));
\r
1348 function _postBlogContent($type, &$blog) {
\r
1350 $manager->notify('PostBlogContent',array('blog' => &$blog, 'type' => $type));
\r