示例#1
0
 /**
  * Initalize
  * @return string
  */
 function init()
 {
     $args = $this->args;
     if (!count($args) || count($args) > 2) {
         return $this->display = VoodooError::displayError('WikiImage: Invalid number of Arguments supplied.');
     }
     // TODO: mkpretty regular expression to check for file type
     $opts = '';
     $allowedOpts = array('width', 'height', 'style', 'class', 'border', 'align');
     $replace = '%s';
     if (isset($args[1])) {
         $options = explode(';', $args[1]);
         // Loop through the options
         foreach ($options as $opt) {
             list($var, $val) = explode(':', $opt);
             if (in_array($var, $allowedOpts)) {
                 $opts .= sprintf(' %s="%s"', $var, $val);
             } elseif ($var == 'wiki') {
                 $replace = sprintf('<a href="%s/wiki/%s">', PATH_TO_DOCROOT, $val) . '%s</a>';
             } elseif ($var == 'link') {
                 $replace = sprintf('<a href="%s">', $val) . '%s</a>';
             }
         }
     }
     return $this->display = sprintf($replace, sprintf('<img src="%s"%s />', $args[0], $opts));
 }
示例#2
0
 /**
  * @return string
  */
 function init()
 {
     $r =& VoodooRegistry::getInstance();
     $template =& VoodooTemplate::getInstance();
     $template->setDir(WIKI_TEMPLATES);
     $vc =& $r->registry('VC');
     $temp = 'wiki.login';
     $args = array('prepath' => PATH_TO_DOCROOT, 'loginpath' => $this->formatter->handler . '/' . $this->formatter->action);
     if (isset($_POST['action']) && $_POST['action'] == 'dologin' && !empty($_POST['handle'])) {
         // Check success of the login action
         if ($this->login($this->formatter->db, $_POST['handle'], $_POST['passwd'])) {
             return $this->display = VoodooError::displayError('Succesfully Logged in.');
         } else {
             $args['message'] = VoodooError::displayError('Incorrect Username and/or Password.');
         }
     } elseif (isset($_GET['action']) && $_GET['action'] == 'logout') {
         $this->logout();
     }
     // Hey! We're already logged in
     // TODO: mkpretty
     if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) {
         return $this->display = sprintf('You are already logged in. <a href="%s/%s/%s?action=logout">Logout</a>', PATH_TO_DOCROOT, $this->formatter->handler, $this->formatter->action);
     }
     // Parse the login screen from the template
     return $this->display = $template->parse($temp, $args);
 }
 function init()
 {
     $this->_configure();
     $this->display = '';
     if ($this->use_sheet_characters && !$this->allow_any_character && $_SESSION['user_id'] <= 0) {
         return $this->display .= VoodooError::displayError('No permission');
     }
     require_once CLASSES . 'TableFactory.php';
     $hash = isset($_GET['hash']) ? $_GET['hash'] : false;
     $limit = isset($this->args[0]) ? $this->args[0] : 12;
     if (!empty($_POST['name']) || !empty($_POST['character'])) {
         if (empty($_POST['action']) || empty($_POST['number'])) {
             $this->display .= VoodooError::displayError('Character, Action and Dice Pool are required fields');
         } else {
             $postvars = array('character' => $_POST['name'] ? $_POST['name'] : $_POST['character'], 'action' => $_POST['action']);
             $sgdr = new SheetgenDiceRoller($this->formatter->db, $postvars);
             $difficulty = $this->variable_difficulty && isset($_POST['difficulty']) ? $_POST['difficulty'] : $this->default_difficulty;
             if (!$sgdr->roll((int) $_POST['number'], $_POST['type'], isset($_POST['substract']), $difficulty)) {
                 $this->display .= VoodooError::displayError('Incorrect usage of the Diceroller');
             } else {
                 header(sprintf('Location: http://%s%s/wiki/%s?hash=%s', $_SERVER['SERVER_NAME'], PATH_TO_DOCROOT, $this->formatter->action, $sgdr->hash));
                 exit;
             }
         }
     }
     $sgdr = new SheetgenDiceRoller($this->formatter->db);
     $t =& VoodooTemplate::getInstance();
     $old = $t->getDir();
     $t->setDir(SHEETGEN_TEMPLATES);
     if (!$hash) {
         $chars = false;
         $args = array('prepath' => PATH_TO_DOCROOT, 'page' => $this->formatter->action);
         $args['name'] = isset($_POST['name']) ? $_POST['name'] : '';
         $args['action'] = isset($_POST['action']) ? $_POST['action'] : '';
         $args['number'] = isset($_POST['number']) ? $_POST['number'] : '';
         if ($this->use_sheet_characters) {
             $chars = $sgdr->getCharacters($_SESSION['user_id']);
             if (sizeof($chars) == 0 && !$this->allow_any_character) {
                 $this->display .= VoodooError::displayError('No characters available, please create one first.');
                 return;
             }
         }
         $chars && ($args['use_sheet_characters'] = $chars);
         if ($this->allow_any_character && !($this->mutually_exclusive && $chars)) {
             $args['allow_any_character'] = $this->allow_any_character;
         }
         $args['variable_difficulty'] = $this->variable_difficulty;
         $args['difficulty'] = isset($_POST['difficulty']) ? $_POST['difficulty'] : $this->default_difficulty;
         $this->display .= $t->parse('diceroller', $args);
     }
     $q = $sgdr->getOverview($limit, $hash);
     require_once CLASSES . 'TableFactory.php';
     $tf = new TableFactory($q);
     $tf->setHiddenField(array('User', 'ROLL_ID', 'number', 'successes', 'roll_character', 'action', 'rolls', 'rerolls', 'difficulty', 'substract'));
     $tf->setValueProcessor(array('Result', 'Link', 'Roll Description'), array($this, 'tfValueProcessor'));
     $this->display .= $tf->getXHTMLTable('list report diceroller');
     $this->display .= sprintf('<a href="%s/wiki/%s">Refresh</a>', PATH_TO_DOCROOT, $this->formatter->action);
     $t->template_dir = $old;
 }
示例#4
0
 /**
  * Usage: [[Attachment_WikiAttachmentImage(attachment.jpg)]]
  * This assumes that the requested image is part of the current handler/action
  * Requires one argument
  */
 function init()
 {
     if (!isset($this->args[0])) {
         return $this->display = VoodooError::displayError('Incorrect number of arguments supplied for WikiAttachmentImage');
     }
     $name = $this->args[0];
     $this->display = sprintf('<img src="%s/attachment/%s/%s/%s?action=download" alt="%s" />', PATH_TO_DOCROOT, $this->formatter->handler, $this->formatter->action, $name, $name);
 }
示例#5
0
 /**
  * Returns the potions output for display purposes
  * @return string
  */
 function display()
 {
     // We have an error! Let it be known
     if ($this->error) {
         return VoodooError::displayError($this->error);
     }
     return $this->display;
 }
示例#6
0
 /**
  * @return string
  */
 function init()
 {
     $args = $this->args;
     if (!count($args)) {
         // No arguments = error
         return $this->display = VoodooError::displayError('WikiInclude: Invalid number of Arguments supplied.');
     }
     if (substr($args[0], -5) != '.html') {
         // Not .html = error
         return $this->display = VoodooError::displayError('WikiInclude: Argument needs to be a .html filename.');
     }
     if (substr($args[0], 0, 1) == '.' || substr($args[0], 0, 1) == '/') {
         // start with / or a dot (.) = error
         return $this->display = VoodooError::displayError('WikiInclude: Invalid Argument supplied..');
     }
     $template =& VoodooTemplate::getInstance();
     $template->setDir(WIKI_TEMPLATES);
     return $this->display = $template->parse(str_replace('.html', '', $args[0]), array('prepath' => PATH_TO_DOCROOT));
 }
示例#7
0
 /**
  * 
  */
 function init()
 {
     $r =& VoodooRegistry::getInstance();
     $template =& VoodooTemplate::getInstance();
     $template->setDir(WIKI_TEMPLATES);
     $vc =& $r->registry('VC');
     $temp = 'wiki.register';
     $args = array('prepath' => PATH_TO_DOCROOT, 'loginpath' => $this->formatter->handler . '/' . $this->formatter->action);
     if (isset($_POST['action']) && $_POST['action'] == 'doregister' && !empty($_POST['handle'])) {
         // We do not have a failure! Happy Time!
         if (!($failure = $this->register($this->formatter->db))) {
             return $this->display = VoodooError::displayError('Succesfully Registered `' . $_POST['handle'] . '`.');
         } else {
             $args['message'] = VoodooError::displayError(sprintf('Registration failed: %s', $failure));
         }
     }
     if ($_SESSION['user_id'] > 0) {
         return $this->display = 'You are already registered.';
     }
     return $this->display = $template->parse($temp, $args);
 }
示例#8
0
 /**
  * Create new Admin users. 
  * 
  * The first Admin user created will be a God user. 
  * TODO: get the highest ranked user from the engine.ini file and use that as first user.
  * TODO: the ADMIN_ACCESSLEVEL constant should be dynamically assigned in VoodooController
  */
 function createAdmin()
 {
     $db = $this->controller->DBConnect();
     $sql = "SELECT USER_ID FROM TBL_USER WHERE USER_ACCESSLEVEL >= ??";
     $q = $db->query($sql);
     $q->bind_values(ADMIN_ACCESSLEVEL);
     $q->execute();
     $firstAdmin = !(bool) $q->rows();
     if (!$firstAdmin && !$this->hasRights($_SESSION['access'], 'admin', 'create')) {
         return array('Error', VoodooError::displayError('No Permission'));
     }
     $template =& VoodooTemplate::getInstance();
     $template->setDir(WIKI_TEMPLATES);
     $args = array('prepath' => PATH_TO_DOCROOT, 'loginpath' => 'setup/CreateAdmin');
     if (!empty($_POST['handle'])) {
         $user = new User($db);
         if ($_POST['passwd'] != $_POST['passwd_verify']) {
             $args['message'] = VoodooError::displayError('Passwords dont match');
         } elseif (!$user->checkEmail($_POST['email'])) {
             $args['message'] = VoodooError::displayError('Passwords dont match');
         } else {
             $user->name = $_POST['handle'];
             $user->password = md5($_POST['passwd']);
             $user->email = $_POST['email'];
             $rv = $this->controller->convertAccessLevel($firstAdmin ? 'God' : 'Admin');
             $user->accesslevel = array_pop($rv);
             $user->insert();
             header(sprintf('Location: %s/setup/Login', PATH_TO_DOCROOT));
             exit;
         }
     }
     return array('Create New Admin User', $template->parse('wiki.register', $args));
 }
示例#9
0
 /**
  * @static
  * @param string $error
  */
 function displayError($error)
 {
     return array('Error', VoodooError::displayError($error));
 }
示例#10
0
 /**
  * @access protected
  * @param string $potion
  * @return string
  */
 function __disabledPotion($potion)
 {
     $error = sprintf('Error, Potion `%s` is not enabled. Please refer to your conf/wiki.ini to enable it.', $potion);
     return VoodooError::displayError($error);
 }
示例#11
0
 function execute()
 {
     $args = array('prepath' => PATH_TO_DOCROOT);
     if (isset($_POST['action']) && $_POST['action'] == 'doregister' && !empty($_POST['handle'])) {
         // We do not have a failure! Happy Time!
         if (!($failure = $this->registerSuccesful())) {
             return array('Registration Succesful', VoodooError::displayError('Succesfully Registered `' . $_POST['handle'] . '`.'));
         } else {
             $args['message'] = VoodooError::displayError(sprintf('Registration failed: %s', $failure));
         }
     }
     $args['loginpath'] = 'auth/register';
     return array('Register Here', $this->template->parse('register', $args));
 }
示例#12
0
 function execute()
 {
     if (!$this->hasRights($_SESSION['access'], 'view', $this->attachment)) {
         return array('Attachment Error', VoodooError::displayError('Permission Denied'));
     }
     if (!$this->attachment) {
         return array('', '');
     }
     $this->al->linked = (object) array('id' => $this->dispatcher->action);
     $attachment = new Attachment($this->dispatcher->controller->DBConnect());
     $attachment->setByName($this->attachment);
     if (!$attachment->isComplete()) {
         return array('Attachment Error', VoodooError::displayError('Attachment Does Not Exist'));
     }
     $attachment->user->set();
     $t =& VoodooTemplate::getInstance();
     $t->setDir(ATTACHMENT_TEMPLATES);
     $defArgs = array('prepath' => PATH_TO_DOCROOT);
     $buttons = '';
     if ($this->hasRights($_SESSION['access'], 'modify', $this->attachment)) {
         $args = $defArgs;
         $args['button_action'] = '/attachment/' . $this->dispatcher->cont . '/' . $this->dispatcher->action . '/' . $this->attachment . '?action=modify';
         $args['button'] = 'Modify attachment';
         $args['class'] = 'buttonmargin';
         $buttons .= $t->parse('button', $args);
     }
     if ($this->hasRights($_SESSION['access'], 'delete', $this->attachment)) {
         $args = $defArgs;
         $args['button_action'] = '/attachment/' . $this->dispatcher->cont . '/' . $this->dispatcher->action . '/' . $this->attachment . '?action=delete';
         $args['button'] = 'Delete attachment';
         $args['class'] = 'buttonmargin';
         $buttons .= $t->parse('button', $args);
     }
     $args = array('prepath' => PATH_TO_DOCROOT, 'action' => $this->dispatcher->action, 'name' => $this->attachment, 'cont' => $this->dispatcher->cont, 'last_update' => $attachment->lastupdate, 'size' => Attachment::prettyBytes($attachment->filesize), 'user' => $attachment->user->name, 'desc' => $attachment->description, 'preview' => $this->renderPreview($attachment), 'buttons' => $buttons);
     return array($this->dispatcher->action . ' - ' . $this->attachment, $t->parse('preview', $args));
 }
 function createSheet($type)
 {
     if (!$this->hasRights('create', false)) {
         return array('Error', VoodooError::displayError('No Permission To Create Sheet'));
     }
     $template =& VoodooTemplate::getInstance();
     $template->setDir(SHEETGEN_TEMPLATES);
     $this->controller->addStyleSheet('sheetgen/sheet_' . $type . '.css');
     $this->controller->script = '<script type="text/javascript" src="' . PATH_TO_DOCROOT . '/scripts/sheetgen/sheetgen.js"></script>';
     $vars = parse_ini_file(SHEETGEN_CONF . 'sheet_' . $type . '.ini', true);
     if (isset($_POST['sheet'])) {
         $name = $_POST['value_' . $vars['main_settings']['name_field']];
         $id = $this->sheet->saveSheet($type, $name);
         header('Location: ' . PATH_TO_DOCROOT . '/sheet/' . $id . '?message=true');
         exit;
     } else {
         $args = $this->sheet->buildVars($vars);
     }
     $args['prepath'] = PATH_TO_DOCROOT;
     $args['type_or_id'] = $type;
     $args['sheetaction'] = 'create';
     $args['buttons'] = $template->parse('submit', array('button' => 'Save'));
     return array($this->conf['sheets'][$type], $template->parse('sheet_' . $type, $args));
 }
示例#14
0
 /**
  * @param array $action
  */
 function dispatch($action)
 {
     if (!$action) {
         header('Location: ' . PATH_TO_DOCROOT . '/wiki/' . $this->conf['setup']['default']);
         exit;
     }
     $wiki = $action[0];
     $lookup = strtolower($wiki);
     // Wiki page Names can only include letters
     // TODO: allow underscores and numbers as well as colons?
     preg_match('/([a-z]+)/i', $wiki, $matches);
     if ($matches[0] !== $wiki) {
         return VoodooError::displayError('Permission Denied');
     }
     // The Wiki doesn't exist yet, see if we can create it.
     if (!isset($this->wikilist[$lookup])) {
         $wc = new WikiCreate($this);
         return $wc->execute($wiki);
     } elseif ($wiki !== $this->wikilist[$lookup]['handle']) {
         // In case the CamelCase varied from the stored version (eg. CameLcase instead of CamelCase)
         exit('Did you mean ``' . $this->wikilist[$lookup]['handle']);
     }
     // Check for the action handler (eg. edit,delete,etc.)
     if (isset($this->action)) {
         switch ($this->action) {
             case 'edit':
                 // Edit a page
                 $wm = new WikiModify($this);
                 return $wm->execute($this->wikilist[$lookup]['id']);
                 break;
             case 'delete':
                 // Delete a page
                 $wd = new WikiDelete($this);
                 return $wd->execute($this->wikilist[$lookup]['id']);
                 break;
             case 'history':
                 // View the page history (revisions)
                 $wh = new WikiHistory($this);
                 return $wh->execute($this->wikilist[$lookup]['id']);
                 break;
             case 'source':
                 $ws = new WikiSource($this);
                 return $ws->execute($this->wikilist[$lookup]['id']);
                 break;
         }
     }
     // No actions were supplied and the page is valid, lets display it
     $wv = new WikiView($this);
     return $wv->execute($this->wikilist[$lookup]['id']);
 }