<?php
// PukiWiki - Yet another WikiWikiWeb clone
// $Id: pagename.inc.php,v 1.6.1 2005/01/29 14:31:04 miko Exp $
//
// 'pagename' plugin for PukiWiki, available under GPL

// Show a link to $defaultpage or not
define('PLUGIN_PAGENAME_TOP_DISPLAY', 1);

// Label for $defaultpage
define('PLUGIN_PAGENAME_TOP_LABEL', 'Top');

// Separetor / of / topic / path
define('PLUGIN_PAGENAME_TOP_SEPARATOR', ' &gt; ');

// Show the page itself or not
define('PLUGIN_PAGENAME_THIS_PAGE_DISPLAY', 1);

// If PLUGIN_PAGENAME_THIS_PAGE_DISPLAY, add a link to itself
define('PLUGIN_PAGENAME_THIS_PAGE_LINK', 1);

function plugin_pagename_convert()
{
	return '<div id ="pagename">' . plugin_pagename_inline() . '</div>';
}

function plugin_pagename_inline()
{
	global $script, $vars, $defaultpage;

	$page = isset($vars['page']) ? $vars['page'] : '';
	if ($page == '' || $page == $defaultpage) return '';

	$parts = explode('/', $page);

	$b_link = TRUE;
	if (PLUGIN_PAGENAME_THIS_PAGE_DISPLAY) {
		$b_link = PLUGIN_PAGENAME_THIS_PAGE_LINK;
	} else {
		array_pop($parts); // Remove the page itself
	}

	$topic_path = array();
	while (! empty($parts)) {
		$_landing = join('/', $parts);
		$landing  = rawurlencode($_landing);
		$element = htmlspecialchars(array_pop($parts));
		if (! $b_link)  {
			// This page ($_landing == $page)
			$b_link = TRUE;
			$topic_path[] = $element;
		} else if (PKWK_READONLY && ! is_page($_landing)) {
			// Page not exists
			$topic_path[] = $element;
		} else {
			// Page exists or not exists
			$topic_path[] = '<a href="' . $script . '?' . $landing . '">' .
				$element . '</a>';
		}
	}

	if (PLUGIN_PAGENAME_TOP_DISPLAY)
		$topic_path[] = make_pagelink($defaultpage, PLUGIN_PAGENAME_TOP_LABEL);

	#return join(PLUGIN_PAGENAME_TOP_SEPARATOR, array_reverse($topic_path));
	return $topic_path[0];
}
?>
