Subversion Repositories travelsized

Rev

Rev 474 | 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/
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


$page_author = $creator_name;
$page_author_email = $creator_email;
$page_menu = 1;
$page_date = formatTime( time() );

/**
 * Draws an editing dialogue (with built-in previewing system), allowing editing of any page.
 */

class PageEditDialogue
{
        /// \private
        var $dialogue;  ///< @var       optionsPanel    The dialogue used for editing the page
        /// \private
        var $pageChanged;       ///< @var       bool    True if the page has been edited
       
        /**
         * Creates a new instance of the page editing dialogue, which is used for editing the contents of any page data structure
         *
         * @param       string  page_title      The title of the page you wish to edit
         * @param       string  page_language   The language of the page you wish to edit
         * @param       integer page_menu       The menu ID for the page you wish to edit
         * @param       string  page_content    The content of the page you wish to edit
         *
         * @return string
         */

        function PageEditDialogue( $page_title, $page_language, $page_menuID, $page_content )
        {
                global $languages, $languages_names, $pagectl, $menu_folder;
               
                $theLanguages = array();
                foreach( $languages as $key => $value )
                        $theLanguages[$value] = $languages_names[$key];
               
                $theMenus = array();
                $menus = $pagectl->fetchMenuMenuList($menu_folder);
                foreach( $menus as $key => $value )
                {
                        $itemTitle = "";
                        if (is_array($value["language"]))
                        {
                                $firstLanguage = true;
                                $delimiter = "";
                                foreach ($value["language"] as $key2 => $value2)
                                {
                                        if( $firstLanguage == false )
                                                $delimiter = ", ";
                                        $itemTitle .= $delimiter . $value2 . ": " . $value["title"][$key2];
                                        $firstLanguage = false;
                                }
                        }
                        else
                                $itemTitle .= i18n( "##0##: ##1##", array( $value["language"], $value["title"] ) );
                        $theMenus[$value["id"]] = i18n("ID ##0## (##1##)", array( $value["id"], $itemTitle ) );
                }
               
                $this->dialogue = new optionsPanel("pageEditor");
                $this->dialogue->saveTitle = i18n("Save");
                $this->dialogue->addCommand( i18n("Preview"), "preview" );
                $this->dialogue->showHeader = false;
               
                $this->dialogue->addOption(
                        i18n("Title"),
                        i18n("The title of the page"),
                        $page_title,
                        "title",
                        "text"
                        );
               
                $this->dialogue->addOption(
                        i18n("Language"),
                        i18n("Which language version of the page you currently editing"),
                        $page_language,
                        "language",
                        "select",
                        $theLanguages
                        );
               
                $this->dialogue->addOption(
                        i18n("Menu"),
                        i18n("Which menu belongs to the page (really, this is a section and we should be calling it that...)"),
                        $page_menuID,
                        "menuid",
                        "select",
                        $theMenus
                        );
               
                $this->dialogue->addOption(
                        i18n("Content"),
                        "",
                        $page_content,
                        "content",
                        "pagedata"
                        );
               
                $this->pageChanged = $this->dialogue->submitted == "default" ? true : false;
        }
       
        function getTitle()
        { return $this->dialogue->getValue("title"); }
        function getLanguage()
        { return $this->dialogue->getValue("language"); }
        function getMenuID()
        { return $this->dialogue->getValue("menuid"); }
        function getContent()
        { return $this->dialogue->getValue("content"); }
       
        /**
         * @return      bool    Describes wether the dialogue has been saved
         */

        function pageSaved()
        { return $this->pageChanged; }
       
        /**
         * Render a preview of the page content if a preview has been requested
         *
         * @return      string  The rendered preview
         */

        function renderPreview()
        {
                $renderedContent = "";
                if( $this->dialogue->submitted == "preview" )
                        $renderedContent .= parse_page_data( $this->getContent() );
                return $renderedContent;
        }
       
        function render()
        {
                $renderedContent = "";
               
                $renderedContent .= $this->dialogue->render();
                $renderedContent .= generate_pagehelplink();
               
                return $renderedContent;
        }
}

if( array_key_exists( "username", $_REQUEST ) && array_key_exists( "password", $_REQUEST ) && !auth( $_REQUEST["username"], $_REQUEST["password"] ) )
        $page_content = loginform($language, globalIDtoURL("setup/pagesetup"), $auth_messages);
else if( isauth() )
{
        $menu_menus = $pagectl->fetchMenuMenuList($menu_folder);
        $createNewPage = false;
        if ($editFrontpage)
        {
                if( file_exists( $page_folder . "/0.$language.php" ) || file_exists( $page_folder . "/0.$default_language.php" ) )
                {
                        $edit_page = $pagectl->fetchPageData("0", $theEditLanguage);
                        $edit_page["title"] = str_replace("&", "&amp;", $edit_page["title"]);
                        $edit_page["content"] = str_replace("&", "&amp;", $edit_page["content"]);
                }
                else
                {
                        // This is done to ensure that you cannot completely delete the front page. If the front page is deleted, travelsized will
                        // revert to using the default front page stored alongside the i18n data (it also keeps backwards compatability)
                        include("$setup_folder/i18n/$theEditLanguage/0.inc");

                        $edit_page["id"] = 0;
                        $edit_page["title"] = str_replace("&", "&amp;", $page_title);
                        $edit_page["language"] = $theEditLanguage;
                        $edit_page["content"] = str_replace("&", "&amp;", $page_content);
                        $edit_page["menu"] = $page_menu;
                       
                }
                $page_title = i18n("Edit front page");
        }
        else
        {
                global $default_language, $language;
                if ($theEditID)
                { //This means edit this page
                        if ($theEditLanguage)
                                $edit_page = $pagectl->fetchPageData($theEditID, $theEditLanguage);
                        else
                                $edit_page = $pagectl->fetchPageData($theEditID, $default_language);
                }
                else if ($theEditTitle)
                { //This means we wanna make a new page with this name
                        $edit_page["id"] = $pagectl->getFreePageID($page_folder, $pagectl);
                        $edit_page["title"] = $theEditTitle;
                        $edit_page["language"] = $language;
                        $edit_page["content"] = i18n("Write your content here. Formatting help can be found below.");
                        $createNewPage = true;
                }
                $edit_page["title"] = str_replace("&", "&amp;", $edit_page["title"]);
                $edit_page["content"] = str_replace("&", "&amp;", $edit_page["content"]);
                $page_title = i18n("Edit page id ##0##", array( $edit_page["id"] ) );
        }
       
        $edit_page["author"] = getUserInfo(currentUser(), "name");
        $edit_page["email"] = getUserInfo(currentUser(), "email");

        $page_menu = $pagectl->fetchMenuMenu( $menu_folder, 1, $language );
        $page_content = "";
        $pageDialogue = new PageEditDialogue( $edit_page["title"], $edit_page["language"], $edit_page["menu"], $edit_page["content"] );
       
        if( $createNewPage )
        {
                if( $pagectl->savePageData( $page_folder, $edit_page["id"], $pageDialogue->getLanguage(), $edit_page["author"], $edit_page["email"], $pageDialogue->getMenuID(), $pageDialogue->getTitle(), $pageDialogue->getContent() ) )
                {
                        update_getpage_id($page_folder, $setup_folder, $pagectl);
                        rotate_recent($edit_page["id"], $pageDialogue->getTitle(), $pageDialogue->getLanguage(), date("j/n/y"), $recent_file);
                        header( "Location: " . globalIDtoURL("setup/editpage/" . $pageDialogue->getLanguage() . "/" . $edit_page["id"] ) );
                }
                else
                        $page_content = renderErrorBox(i18n("Page creation failed"), i18n("The page could not be created! Please click on your browser's back button and try again.") );
        }
        if( $pageDialogue->pageSaved() )
        {
                if( $pagectl->savePageData( $page_folder, $edit_page["id"], $pageDialogue->getLanguage(), $edit_page["author"], $edit_page["email"], $pageDialogue->getMenuID(), $pageDialogue->getTitle(), $pageDialogue->getContent() ) )
                {
                        $page_content = renderInformationBox( i18n("The page was saved."), i18n("The page with the title ##0## was successfully saved and you should be transferred there momentarily.", array( $pageDialogue->getTitle() ) ) );
                        update_getpage_id($page_folder, $setup_folder, $pagectl);
                        rotate_recent($edit_page["id"], $pageDialogue->getTitle(), $pageDialogue->getLanguage(), date("j/n/y"), $recent_file);
                        header("Location: " . globalIDtoURL("content/" . $pageDialogue->getLanguage() . "/" . $edit_page["id"] ));
                }
                else
                        $page_content = parse_page_data(i18n("The page was not saved! Click on your browser's back button and try again."));
        }
       
        $page_content .= $pageDialogue->renderPreview() . "<form action=\"" . globalIDtoURL("setup/editpage/{$edit_page['language']}/{$edit_page['id']}") . "\" method=\"POST\">" . $pageDialogue->render() . "</form>";

}
?>