ProjectWikka
This Action is encapsulated in a class. This is the code:
<?php
/**
* simpleactionclass.php
* An extremely simplified version of a klenwell wikka action class.
*
* NOTE: For a more finished version of this class see klenwell action class:
* http://code.google.com/p/klenwell/source/browse/trunk/projects/php/wikka/libs/action.class.php
*
* References
* http://docs.wikkawiki.org/UsingActions
*
* @package Action
* @author Tom Atwell <klenwell@gmail.com>
* @copyright Copyright 2010, Tom Atwell <klenwell@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
*
* @uses Wakka::GetUser()
* @uses Wakka::IsAdmin()
* @uses Wakka::format()
*
* @input n/a
* @output source code
*/
class SimpleWikkaAction {
# defaults
# internal
var $Wikka = NULL;
var $Param = array();
var $user = NULL;
var $user_role = 'viewer'; # viewer, user, or admin
var $is_admin = FALSE;
function __construct($Wakka=NULL, $ActionParams=array()) {
if ( is_null($Wakka) ) {
$this->_abort('must pass wakka object as argument for action class');
}
$this->Wikka = $Wakka;
$this->_load_wikka_acl();
$this->Param = $ActionParams;
$this->Get = $_GET;
$this->Post = $_POST;
$this->tag = $this->Wikka->tag;
$this->here = $this->Wikka->GetConfigValue('base_url') . $this->tag;
}
function main() {
return $this->_format_content();
}
function output($content, $wikka_format=0) {
#printf('<pre>%s</pre>', $content);
if ( $wikka_format ) {
$content = $this->Wikka->format($content);
}
print $content;
}
function _format_content() {
# note: NOT using wikka formatting
$template = <<<XHTML
<h4>A Simple Action Class</h4>
This Action is encapsulated in a class. This is the code:
<div class="code">
%s
</div>
XHTML;
# output
$source_code = highlight_file(__FILE__, 1);
return sprintf($template, $source_code);
}
function _load_wikka_acl() {
$this->user = $this->Wikka->GetUser();
if ( !empty($this->user) ) {
$this->is_admin = $this->Wikka->IsAdmin($this->user);
}
if ( $this->is_admin ) {
$this->user_role = 'admin';
}
elseif ( $this->user ) {
$this->user_role = 'user';
}
return;
}
}
# Main Routine
try {
# note: must pass Wikka object ($this) and $vars
$Action = new SimpleWikkaAction($this, $vars);
$content = $Action->main();
$Action->output($content, 0);
}
catch(Exception $e) {
printf('Exception: %s', $e->getMessage());
}
?>
[There are no comments on this page]