Subversion Repositories travelsized

Rev

Rev 438 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * This file is part of Travelsized CMS
 *              A content management system with modules, based on wiki syntax
 *
 * Author: Dan Jensen <admin@leinir.dk>
 * Copyright 2003/2004
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License is available at: http://www.gnu.org/copyleft/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


//! A simplistic breadcrumb class - used by the breadcrumbs class
class breadcrumb
{
        var $title;              ///< The crumb's translated title
        var $url;                ///< The crumb's URL
       
        /**
         * Constructor for the breadcrumb class
         *
         * @param    title          The crumb's translated title
         * @param    url            The crumb's URL
         */

        function breadcrumb( $title, $url )
        {
                $this->title = $title;
                $this->url = $url;
        }
       
        /**
         * Render the breadcrumb
         *
         * @return   A string containing the rendered breadcrumb
         */

        function render()
        {
                return "<a class=\"breadcrumb\" href=\"" . $this->url . "\">" . $this->title . "</a>";
        }
}

//! A simplistic class for handling breadcrumb trails
class breadcrumbs
{
        var $crumbs;             ///< An array of crumbs
       
        /**
         * Constructor for the breadcrumbs handling class
         *
         * @param    basetitle      The translated title of the base element of the breadcrumbs trail
         * @param    baseurl        The url of the base element of the breadcrumbs trail
         */

        function breadcrumbs( $basetitle, $baseurl )
        {
                $this->crumbs[] = new breadcrumb( $basetitle, $baseurl );
        }
       
        /**
         * Add a breadcrumb to the breadcrumbs trail
         *
         * @param    title          The translated title of the breadcrumbs trail
         * @param    url            The URL to link to
         *
         * @return   void
         */

        function addCrumb( $title, $url )
        {
                $this->crumbs[] = new breadcrumb( $title, $url );
        }
       
        /**
         * Render the actual breadcrumbs trail
         *
         * @return   A string containing the rendered breadcrumbs trail
         */

        function render()
        {
                $rendered = "<div class=\"breadcrumbs\">";
               
                foreach( $this->crumbs as $key => $value )
                        $rendered .= $value->render() . " &raquo; ";
               
                // Snip off the last raquo
                $rendered = substr( $rendered, 0, -9 );
               
                $rendered .= "</div>";
               
                return $rendered;
        }
}

/**
 * Translates a global ID into an instance of the breadcrumbs class
 *
 * @param     globalID       The global ID to translate into a breadcrumbs trail
 * @param     baseLevel      How deep in you wish to start showing the breadcrumbs.
 *
 * @return    An instance of the breadcrumbs class
 */

function globalIDtoBreadcrumb( $globalID, $baseLevel = 0 )
{
        $splitID = explode( "/", $globalID );
        foreach( $splitID as $key => $value)
        {
                if( $key > $baseLevel )
                {
                        $currentID .= "/$value";
                        $trail->addCrumb( $value, globalIDtoURL( $currentID ) );
                }
                else
                {
                        if( $key == 0 )
                                $currentID = $value;
                        else
                                $currentID .= "/$value";
                       
                        if( $key == $baseLevel )
                                $trail = new breadcrumbs( $value, globalIDtoURL( $currentID ) );
                }
        }
       
        return $trail;
}

/**
 * renderNavigator will create a navigation bar for pagination...
 *
 * @param    $entryCount      int the total amount of entries
 * @param    $currentPage     int the current page
 * @param    $lowerBound      int the number of the first entry on the page
 * @param    $upperBound      int the number of the last entry on the page
 * @param    $entriesPerPage  int the amount of entries per page
 *
 * @return   string           The div containing the navigator
 */

function renderNavigator($entryCount, $currentPage, $lowerBound, $upperBound, $entriesPerPage)
{
        if( $upperBound + 1 > $entryCount )
                $upperBound = $entryCount;
       
        $navigator = $navigator_previous = $navigator_next = "";
       
        if( $currentPage <= ($upperBound / $entriesPerPage) - 1 )
                $navigator_previous .= "<a class=\"command\" href=\"" . thisPageURL() . "&amp;currentpage=" . ($currentPage + 1) . "\">[ &laquo; " . i18n("Prevous ##0##", array($entriesPerPage) ) . "]</a> ";
       
        if( $currentPage > 0 )
                $navigator_next .= " <a class=\"command\" href=\"" . thisPageURL() . "&amp;currentpage=" . ($currentPage - 1) . "\">[" . i18n("Next ##0##", array($entriesPerPage) ) . " &raquo; ]</a>";
       
        if( $entryCount > $entriesPerPage ) // Then there are actually pages...
                $navigator = "
                <div class=\"pagination_navigator\">
                        $navigator_previous
                        "
.i18n("Showing entries number ##0## to ##1## of ##2##", array($entryCount - $upperBound + 1, $entryCount - $lowerBound, $entryCount ) ) . "
                        $navigator_next
                </div>"
;
               
        return $navigator;
}


/**
 * Takes a timestamp, and returns a formatted string containing a time
 *
 * @param     timestamp   A timestamp in integer format (normal UNIX time)
 *
 * @return    string      The timestamp formatted pretty
 */

function formatTime( $timestamp )
{
        global $systemOptions;
       
        if( $timestamp == 0 )
                $thetime = i18n("never");
        else
        {
                $timeformat = getUserInfo( currentUser(), "timeformat" );
                if( $timeformat == getUserInfo( currentUser(), "/none/" )  || $timeformat == i18n( "No ##0## information\n", array("timeformat") ) )
                        $timeformat = $systemOptions["timeformat"];
               
                if( $timeformat == "" )
                        $timeformat = "r";
               
                $thetime = date( $timeformat, $timestamp );
        }
        return $thetime;
}

/**
 * Draws a customised information box (supports setting a class)
 *
 * @param     title               String containing the translated title for the information box
 * @param     text                String containing the translated contents for the information box
 * @param     class               String containing the class you wish to set in place of information
 * @param     page_data           Boolean defining wether the text should be parsed as page_data. Default is true
 *
 * @return    string              The rendered information box
 */

function renderCustomBox( $title, $text, $class, $page_data = true )
{
        if( $page_data )
                $parsedtext = str_replace( "<p >", "<p class=\"$class\">", parse_page_data( $text ) );
        else
                $parsedtext = $text;
       
        $thebox = "
        <div class=\"$class\">
                <h6 class=\"$class\">$title</h6>
                $parsedtext
        </div>"
;
       
        return $thebox;
}

/**
 * Draws an information box
 *
 * @param     title               String containing the translated title for the information box
 * @param     text                String containing the translated contents for the information box
 * @param     page_data           Boolean defining wether the text should be parsed as page_data. Default is true
 *
 * @return    string              The rendered information box
 */

function renderInformationBox( $title, $text, $page_data = true )
{
        return renderCustomBox( $title, $text, "information", $page_data );
}

/**
 * Draws an warning box
 *
 * @param     title               String containing the translated title for the information box
 * @param     text                String containing the translated contents for the information box
 * @param     page_data           Boolean defining wether the text should be parsed as page_data. Default is true
 *
 * @return    string              The rendered information box
 */

function renderWarningBox( $title, $text, $page_data = true )
{
        return renderCustomBox( $title, $text, "warning", $page_data );
}

/**
 * Draws an error box
 *
 * @param     title               String containing the translated title for the information box
 * @param     text                String containing the translated contents for the information box
 * @param     page_data           Boolean defining wether the text should be parsed as page_data. Default is true
 *
 * @return    string              The rendered information box
 */

function renderErrorBox( $title, $text, $page_data = true )
{
        return renderCustomBox( $title, $text, "error", $page_data );
}

/**
 * Draws a question box
 *
 * @param     title               String containing the translated title for the information box
 * @param     text                String containing the translated contents for the information box
 * @param     page_data           Boolean defining wether the text should be parsed as page_data. Default is true
 *
 * @return    string              The rendered information box
 */

function renderQuestionBox( $title, $text, $page_data = true )
{
        return renderCustomBox( $title, $text, "question", $page_data );
}

//! The confirmDeleteDialog class, which creates and manages a dialog used to confirm the deletion of an item
class confirmDeleteDialog
{
        var $name;
        var $description;
        var $globalID;
       
        var $title;
        var $text;
        var $checkbox;
       
        var $submitted;
        var $confirmed;
       
        function confirmDeleteDialog( $name, $description, $globalID )
        {
                $this->name = $name;
                $this->description = $description;
                $this->globalID = $globalID;
               
                $this->title = i18n( "Please conform delete of ##0##", array( $this->name ) );
                $this->text = i18n("Please confirm that you wish to delete the item described below by ticking the checkbox. When you have made your choice, click the Continue button.");
                $this->checkbox = i18n("Yes, delete ##0##.", array( $this->name ) );
               
                if( array_key_exists( "deleteSubmitted", $_POST ) )
                        $this->submitted = true;
                if( array_key_exists( "deleteConfirmed", $_POST ) )
                        $this->confirmed = true;
        }
       
        function render()
        {
                $thumbnail = getGlobalIDThumbnail($this->globalID);
                $content = $this->text . "<hr />";
                $content .= "<p class=\"question wikicenteralign\"><img src=\"" . $thumbnail["uri"] . "\" width=\"" . $thumbnail["width"] . "\" height=\"" . $thumbnail["height"] . "\" alt=\"" . $this->name . "\" /></p>";
                $content .= parse_page_data($this->description) . "<hr />";
                $content .= "<p class=\"question\"><label><input type=\"checkbox\" name=\"deleteConfirmed\" />" . $this->checkbox . "</label></p>";
                $content .= "<p class=\"question wikicenteralign\"><input type=\"submit\" name=\"deleteSubmitted\" value=\"" . i18n("Continue") . "\" /></p>";
               
                $renderedDialog = "<form method=\"POST\" action=\"" . thisPageURL() . "\">" . renderQuestionBox( $this->title, $content, false ) . "</form>";
               
                return $renderedDialog;
        }
}

?>