Location: PHPKode > projects > Webessence CMS > themes/default/functions.php
<?php

function page_get_root()
{
	$parent = $GLOBALS['we_page'];
	while (isset($GLOBALS['we_pages']['ID'][$parent->parentid]))
		$parent = $GLOBALS['we_pages']['ID'][$parent->parentid];
	return $parent;
}

function show_collections_in_sidebar()
{
	if (count($GLOBALS['we_collectionid_collections']) > 0)
	{
		foreach ($GLOBALS['we_collectionid_collections'] as $collectionid => $collection)
		{
			echo '<div id="we_submenu" class="we_sidebar_block"><div class="we_title">' . $collection->name . '</div><ul>';
			foreach ($GLOBALS['we_collectionid_collectionitems'][$collectionid] as $item)
			{
				if ($collection->external_url)
					echo "<li><a title=\"$item->description\" href=\"$item->url_title\">$item->title</a></li>";
				else
				{
					$link = WE_PATH_SUB . "/$collection->base_page_path/" . CollectionItem::get_link($item);
					echo "<li><a href=\"$link\">$item->title</a></li>";
				}
			}
			echo '</ul></div>';
		}
	}
}

function add_css_js()
{
	if (isset($GLOBALS['we_css_files']))
	{
		foreach ($GLOBALS['we_css_files'] as $cssFile)
			echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$cssFile\" />\n";
	}

	if (isset($GLOBALS['we_js_files']))
	{
		foreach ($GLOBALS['we_js_files'] as $jsFile)
			echo "<script type=\"text/javascript\" src=\"$jsFile\"></script>\n";
	}
}

function show_tags_in_sidebar()
{
	if (isset($GLOBALS['we_collection_tagcount']) && count($GLOBALS['we_collection_tagcount']) > 0)
	{
		echo '<div id="we_submenu" class="we_sidebar_block"><div class="we_title">Tags</div><ul>';
		$activeTag = isset($GLOBALS['we_tag']) ? $GLOBALS['we_tag'] : null;
		foreach ($GLOBALS['we_collection_tagcount'] as $tagname => $tagcount)
		{
			$classvalue = (isset($activeTag) && $activeTag == $tagname) ? 'class="activelink"' : '';
			echo "<li><a $classvalue title='$tagcount items' href='" . WE_PATH_SUB . "/" . $GLOBALS['we_page']->prepath . $GLOBALS['we_page']->pathname . "/?tag=$tagname'>$tagname</a></li>";
		}
		echo '</ul></div>';
	}
}

function get_tags($item)
{
	$tags = '<em>No tags</em>';
	if (!empty($item->tags))
	{
		$tags = array();
		foreach ($item->tags as $tagname)
		{
			$tags[] = "<a href='" . WE_PATH_SUB . "/" . $GLOBALS['we_page']->prepath . $GLOBALS['we_page']->pathname . "/?tag=$tagname'>$tagname</a>";
		}
		$tags = implode(', ', $tags);
	}
	return $tags;
}

function show_submenu($parentId)
{
	if (isset($GLOBALS['we_pages']['PARENT_ID'][$parentId]))
	{
		//echo '<h2>Submenu</h2>';
		echo '<ul>';

		$ps = $GLOBALS['we_pages']['PARENT_ID'][$parentId];
		
		foreach ($ps as $pageId => $p)
		{
			$cssClass = $p->id == $GLOBALS['we_page']->id ? 'class="we_active"' : '';
			echo '<li><a ' . $cssClass . ' href="' . WE_PATH_SUB . '/' . $p->prepath . $p->pathname . '/">' . $p->menuname . '</a>';
			if (isset($GLOBALS['we_pages']['PARENT_ID'][$p->id]))
			{
				show_submenu($p->id);
			}
			
			echo "</li>";
		}
		echo '</ul>';
	}
}

function menu_fixed($rootpage)
{
	if (isset($GLOBALS['we_pages']['PARENT_ID'][0]))
	{
		echo '<ul>';
		foreach ($GLOBALS['we_pages']['PARENT_ID'][0] as $id => $page)
		{
			$cssClass = $page->id == $rootpage->id ? 'class="we_active"' : '';
			echo "<li><a $cssClass href='" . WE_PATH_SUB . "/$page->prepath$page->pathname/'>$page->menuname</a></li>";
		}
		echo '</ul>';
	}
}

function nav_prev_next()
{
	$tag = isset($GLOBALS['we_tag']) ? $GLOBALS['we_tag'] : null;

	$parameters = array('/' . $GLOBALS['we_page']->prepath . $GLOBALS['we_page']->pathname);
	if (isset($_GET['year'])) $parameters[] = $_GET['year'];
	if (isset($_GET['month'])) $parameters[] = str_pad($_GET['month'], 2, 0, STR_PAD_LEFT);
	if (isset($_GET['day'])) $parameters[] = str_pad($_GET['day'], 2, 0, STR_PAD_LEFT);

	$pUrl = WE_PATH_SUB . implode('/', $parameters) . '/';

	$offsetParString = "?";
	if (isset($GLOBALS['we_tag']))
	{
		$offsetParString = "&";
		$pUrl .= "?tag=" . $GLOBALS['we_tag'];
	}

	echo '<div class="we_content_block we_meta we_next_prev">';
	if ($GLOBALS['we_collection_offset'] + $GLOBALS['we_collection_limit'] < $GLOBALS['we_collection']->items_visible_count)
	{
		echo '<a href="' . $pUrl . $offsetParString . 'offset=' . ($GLOBALS['we_collection_offset'] + $GLOBALS['we_collection_limit']) . '">&laquo; Older items</a> | ';
	}
	else
	{
		echo '<a class="we_disabled">&laquo; Older items</a> | ';
	}
	if ($GLOBALS['we_collection_offset'] > 0)
	{
		if ($GLOBALS['we_collection_offset'] - $GLOBALS['we_collection_limit'] == 0)
		{
			echo ' <a href="' . $pUrl . '">Newer items &raquo;</a>';
		}
		else
		{
			echo ' <a href="' . $pUrl . $offsetParString . 'offset=' . ($GLOBALS['we_collection_offset'] - $GLOBALS['we_collection_limit']) . '">Newer items &raquo;</a>';
		}
	}
	else
	{
		echo ' <a class="we_disabled">Newer items &raquo;</a>';
	}
	echo '</div>';
}

?>
Return current item: Webessence CMS