wiclear-2007-07-19/inc/classes/node.class.php
<?php
# ***** BEGIN LICENSE BLOCK *****
# This file is part of WiClear.
# Copyright (c) 2004-2007 David Jobet. All rights
# reserved.
#
# WiClear 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.
#
# WiClear is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DotClear; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
# ***** END LICENSE BLOCK *****
/**
* \brief represents a wiki node with content, translations, acls ...
*/
class node
{
var $id; //!< database id
var $title; //!< title
var $alternate_title; //!< alternate title (may be empty)
var $content; //!< content
var $commit_msg; //!< commit message used
var $minor_major; //!< minor/major changement ?
var $ip; //!< ip of user that last modified the node
var $timestamp; //!< date of last modification
var $lang; //!< lang object
var $parent_id; //!< database id of parent
var $left; //!< nested set model 'left' value
var $right; //!< nested set model 'right' value
var $related_content_id; //!< master node id (if equals to id, this node is a master node)
var $user_id; //!< database id of user that last modified the node or 0 if user was anonymous
var $login; //!< login of anonymous user
var $first_name; //!< first name of anonymous user
var $last_name; //!< last name of anonymous user
var $email; //!< email of anonymous user
var $groups; //!< array<acl_type => array<id => group> >
var $langs; //!< array<id=>lang>
var $extra; //!< array<string=>whatever>
function node(
$id,
$title,
$alternate_title,
$content,
$commit_msg,
$minor_major,
$ip,
$timestamp,
$lang,
$parent_id,
$left,
$right,
$related_content_id,
$user_id,
$login,
$first_name,
$last_name,
$email
)
{
$this->id = $id;
$this->title = $title;
$this->alternate_title = $alternate_title;
$this->content = $content;
$this->commit_msg = $commit_msg;
$this->minor_major = $minor_major;
$this->ip = $ip;
$this->timestamp = $timestamp;
$this->lang = $lang;
$this->parent_id = $parent_id;
$this->left = $left;
$this->right = $right;
$this->related_content_id = $related_content_id;
$this->user_id = $user_id;
$this->login = $login;
$this->first_name = $first_name;
$this->last_name = $last_name;
$this->email = $email;
$this->extra = array();
}
function setParents($parents)
{
$this->parents = $parents;
}
function setLinks($links)
{
$this->links = $links;
}
function setComments($comments)
{
$this->comments = $comments;
}
function setGroups($groups)
{
$this->groups = $groups;
}
function setLangs($langs)
{
$this->langs = $langs;
}
/**
* \brief is this node the root node of the wiki ? (the parent of all other pages)
*
* \return true if this is the root node
*/
function isRootNode()
{
return $this->id == $this->parent_id;
}
/**
* \brief is this node a node in main lang ? (the lang defined as the main lang of the wiki)
*
* \return true if this is a master node
*/
function isMasterNode()
{
return $this->id == $this->related_content_id;
}
/**
* \brief is this node a translation ? (not in the lang defined as the main lang of the wiki)
*
* \return true if this is a translation
*/
function isTranslationNode()
{
return $this->id != $this->related_content_id;
}
/**
* \brief format this node in html format
*
* if allLangs is not empty, a list of images will be generated
*
* \param showTOC display or not TOC
* \param editBySection display Edit link on each section
* \param allLangs array<lang>
* \param canEdit provides link to translate the node
* \return html representation of node
*/
function toHtml($showTOC, $editBySection, $allLangs = array(), $canEdit = true)
{
global $wikiRenderer;
global $showLangWithTitle;
$wikiRenderer->config->doGenerateToc = $showTOC;
$wikiRenderer->config->doEditBySection = $editBySection;
$preview = $wikiRenderer->render($this->content);
if ($showTOC)
{
$toc = $wikiRenderer->config->generateTOC();
if (!empty($toc))
{
$toc = '<div id="tocheader">'.$toc.'</div>';
}
}
else
{
$toc = '';
}
$author = formatName($this->login, $this->first_name, $this->last_name);
// construct the list of available langs for this node
$currentLang = '';
if (count($allLangs) > 0)
{
$langList = '<ul class="flags">';
foreach ($allLangs as $lang)
{
$imgUrl = '<img src="'.createIconURL($lang->flag).'" alt="'.$lang->description.'"/>';
if ($this->lang->id == $lang->id)
{
// current lang : no link
$currentLang = $imgUrl;
}
else
{
$options = array('lang'=>$lang->code);
if ($canEdit)
{
// try to find the lang in the list of already translated lang
$translated = false;
foreach ($this->langs as $tlangid=>$tlangcode)
{
if ($tlangid == $lang->id)
{
// already translated
$translated = true;
break;
}
}
if ($translated == false)
{
// provide a link to edit the node
$options['mode'] = 'edit';
$options['related_content_id'] = $this->related_content_id;
}
}
// create URL
$url = createUrl($this->title, $options);
$html = '<a href="'.$url.'">'.$imgUrl.'</a>';
$langList .= '<li>'.$html.'</li>';
}
}
$langList .= '</ul>';
}
else
{
$langList = '';
}
$url = createUrl($this->title, array('lang'=>$this->lang->code));
$title = $this->title;
if (!empty($this->alternate_title))
{
$title = $this->alternate_title;
}
$titleHtml = formatHtml($title);
if ($showLangWithTitle)
{
$titleHtml = '<a href="'.$url.'">'.$currentLang.' '.$titleHtml.'</a>';
}
return
'<div class="content_meta">'.
'<h1>'.$titleHtml.'</h1>'.
'<p>'.formatDate($this->timestamp).', '.tr('by').' '.formatAuthor($author, $this->email).'</p>'.
$langList.
'</div> '.
$toc.$preview;
}
}
?>