Source: show.php
author:
KlenWell
<?php
/**
* Display a page if the user has read access or is an admin.
*
* This is the default page handler used by Wikka when no other handler is specified.
* Depending on user privileges, it displays the page body or an error message. It also
* displays footer comments and a form to post comments, depending on ACL and general
* config settings.
*
* @package Handlers
* @subpackage Page
* @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @filesource
*
* @uses Wakka::Format()
* @uses Wakka::FormClose()
* @uses Wakka::FormOpen()
* @uses Wakka::GetConfigValue()
* @uses Wakka::GetPageTag()
* @uses Wakka::GetUser()
* @uses Wakka::GetUserName()
* @uses Wakka::HasAccess()
* @uses Wakka::Href()
* @uses Wakka::htmlspecialchars_ent()
* @uses Wakka::LoadComments()
* @uses Wakka::LoadPage()
* @uses Wakka::LoadUser()
* @uses Wakka::UserIsOwner()
* @uses Config::$anony_delete_own_comments
* @uses Config::$hide_comments
*
* @todo move <div> to template;
* @todo replace $_REQUEST with either $_GET or $_POST (or both if really
* necessary) - #312
*/
// *** Show Flags for Controller
$_SHOW['page_start'] =
0;
$_SHOW['no_access'] =
0;
$_SHOW['not_exists'] =
0;
$_SHOW['page_body'] =
0;
$_SHOW['revision_info'] =
0;
$_SHOW['revision_edit_form'] =
0;
$_SHOW['comments'] =
0;
$_SHOW['hidden_comments'] =
0;
$_SHOW['no_comments'] =
0;
$_SHOW['comment_form'] =
0;
$_SHOW['page_close'] =
0;
// *** HTML Blocks
$_HTML['page'] =
'';
$_HTML['page_start'] =
'';
$_HTML['no_access'] =
'';
$_HTML['not_exists'] =
'';
$_HTML['revision_info'] =
'';
$_HTML['page_body'] =
'';
$_HTML['revision_edit_form'] =
'';
$_HTML['page_close_div'] =
'';
$_HTML['comments_header'] =
'';
$_HTML['comments'] =
'';
$_HTML['comment_form'] =
'';
$_HTML['hidden_comments'] =
'';
$_HTML['page_close'] =
'';
// *** Controller
// Default Shows
$_SHOW['page_start'] =
1;
$_SHOW['page_close'] =
1;
// Has Page Access
if (!
$this->
HasAccess('read'))
{
$_SHOW['no_access'] =
1;
}
// Page Exists
if ( !
$this->
page )
{
$_SHOW['not_exists'] =
1;
}
else
{
$_SHOW['page_body'] =
1;
}
// As Revision
if ($this->
page['latest'] ==
'N')
{
$_SHOW['revision_info'] =
1;
}
// Revision w/ write access
if ( ($this->
page['latest'] ==
'N' &&
$this->
HasAccess('write')) &&
($latest =
$this->
LoadPage($this->
tag)) )
{
$_SHOW['revision_edit_form'] =
1;
}
// Show Comment Form
if ( $this->
GetConfigValue('hide_comments') !=
1 )
{
// get page tag
$tag =
$this->
GetPageTag();
// session settings?
if ( !
isset($_SESSION['show_comments'][$tag]) )
{
$_SESSION['show_comments'][$tag] =
($this->
UserWantsComments() ?
'1' :
'0');
}
// GET setting takes precedence
if ( isset($_GET['show_comments']) ) #312
{
if ( $_GET['show_comments'] ==
0 )
{
$_SESSION['show_comments'][$tag] =
0;
}
elseif ( $_GET['show_comments'] ==
1 )
{
$_SESSION['show_comments'][$tag] =
1;
}
}
if ($_SESSION['show_comments'][$tag])
{
$_SHOW['comment_form'] =
1;
}
else
{
$_SHOW['hidden_comments'] =
1;
}
}
// Show Comments?
$comments =
$this->
LoadComments($this->
tag);
if ( $_SESSION['show_comments'][$tag] &&
$comments )
{
$_SHOW['comments'] =
1;
}
// *** Viewer Blocks
// Page Start
if ( $_SHOW['page_start'] )
{
$_js =
( ($user =
$this->
GetUser()) &&
($user['doubleclickedit'] ==
'N') || !
$this->
HasAccess('write') ) ?
'' :
'ondblclick="document.location=\''.
$this->
Href('edit').
'\';" ';
$_HTML['page_start'] = <<<HTML
<!--starting page content-->
<div
class=
"page" {$_js }>
HTML;
}
// Generic
if ( $_SHOW['no_access'] )
{
$_HTML['no_access'] = <<<HTML
<p><em
class=
"error">You aren
't allowed to read this page.</em></p>
</div>
HTML;
}
// Page does not exist yet
if ( $_SHOW['not_exists
'] )
{
$_HTML['not_exists
'] = <<<HTML
<p>This page doesn't exist yet. Maybe you want to <a href=
"{$this->Href('edit')}">create</a> it?</p>
</div>
HTML;
}
// Revision Info
if ( $_SHOW['revision_info'] )
{
$href =
$this->
Href();
$alabel =
$this->
GetPageTag();
$ptime =
$this->
page['time'];
$_HTML['revision_info'] = <<<HTML
<div
class=
"revisioninfo">
This is an old revision of <a href=
"{$href}">
{$alabel}</a> from
{$ptime}
</div>
HTML;
}
// Page Body
if ( $_SHOW['page_body'] )
{
$_HTML['page_body'] =
$this->
Format($this->
page['body'],
'wakka');
$_HTML['page_close_div'] =
"</div>\n";
}
// Revision Edit Form
if ( $_SHOW['revision_edit_form'] )
{
$form_start =
$this->
FormOpen('edit');
$lid =
$latest['id'];
$hvalue =
$this->
htmlspecialchars_ent($this->
page['body']);
$form_close =
$this->
FormClose();
$_HTML['revision_edit_form'] = <<<HTML
<br />
$form_start
<input type=
"hidden" name=
"previous" value=
"$lid" />
<input type=
"hidden" name=
"body" value=
"$hvalue" />
<input type=
"submit" value=
"Re-edit this old revision" />
$form_close
HTML;
}
// Comments Header and Form
if ( $_SHOW['comment_form'] )
{
$href =
$this->
Href('',
'',
'show_comments=0');
$_HTML['comments_header'] = <<<HTML
<div
class=
"commentsheader">
<span id=
"comments"> </span>Comments
[<a href=
"$href">Hide comments/form</a>
]
</div>
HTML;
$form_start =
$this->
FormOpen('addcomment');
$form_close =
$this->
FormClose();
$_HTML['comment_form'] = <<<HTML
<div
class=
"commentform">
$form_start
<label
for=
"commentbox">Add a comment to this page:<br />
<textarea id=
"commentbox" name=
"body" rows=
"6" cols=
"78"></textarea><br />
<input type=
"submit" value=
"Add Comment" accesskey=
"s" />
</label>
$form_close
</div>
HTML;
}
// comments themselves
if ( $_SHOW['comments'] )
{
$current_user =
$this->
GetUserName();
$comment_stack =
'';
foreach ($comments as $comment)
{
$comment_stack .=
'<div class="comment">'.
"\n";
$comment_stack .=
'<span id="comment_'.
$comment['id'].
'"></span>'.
$comment['comment'].
"\n";
$comment_stack .=
"\t".
'<div class="commentinfo">'.
"\n-- ";
$comment_stack .=
( $this->
LoadUser($comment['user']) ) ?
$this->
Format($comment['user']) :
$comment['user'];
$comment_stack .=
' ('.
$comment['time'].
')'.
"\n";
// does comment get delete form?
if ($this->
UserIsOwner() ||
$current_user ==
$comment['user'] ||
($this->
config['anony_delete_own_comments'] &&
$current_user ==
$comment['user']) )
{
$comment_stack .=
$this->
FormOpen("delcomment");
$comment_stack .=
'<input type="hidden" name="comment_id" value="' .
$comment['id'] .
'" />';
$comment_stack .=
'<input type="submit" value="Delete Comment" />';
$comment_stack .=
$this->
FormClose();
}
$comment_stack .=
"\n\t".
'</div>'.
"\n";
$comment_stack .=
'</div>'.
"\n";
}
$_HTML['comments'] =
$comment_stack;
}
// hidden comments
if ( $_SHOW['hidden_comments'] )
{
switch (count($comments))
{
case 0:
$comment_count =
'<p>There are no comments on this page. ';
$showcomments_text =
'Add comment';
break;
case 1:
$comment_count =
'<p>There is one comment on this page. ';
$showcomments_text =
'Display comment';
break;
default:
$comment_count =
'<p>There are '.count
($comments).
' comments on this page. ';
$showcomments_text =
'Display comments';
}
$href =
$this->
Href('',
'',
'show_comments=1#comments');
$_HTML['hidden_comments'] = <<<HTML
<div
class=
"commentsheader">
$comment_count
[<a href=
"$href">
$showcomments_text</a>
]</p>
</div>
HTML;
}
// Page Close
if ( $_SHOW['page_close'] )
{
$_HTML['page_close'] = <<<HTML
</div>
<!--closing page content-->
HTML;
}
// End Viewer Blocks
// *** TEMPLATE: stitch it all together
$_HTML['page'] = <<<HTML
{$_HTML['page_start']}
{$_HTML['no_access']}
{$_HTML['not_exists']}
{$_HTML['revision_info']}
{$_HTML['page_body']}
{$_HTML['revision_edit_form']}
{$_HTML['page_close_div']}
{$_HTML['comments_header']}
{$_HTML['comments']}
{$_HTML['comment_form']}
{$_HTML['hidden_comments']}
{$_HTML['page_close']}
HTML;
echo $_HTML['page'];
?>