Exemple #1
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()
 {
     $t = VoodooTemplate::getInstance();
     $old = $t->getDir();
     $t->setDir(SHEETGEN_TEMPLATES);
     $args = array('prepath' => PATH_TO_DOCROOT);
     $conf = VoodooIni::load('sheetgen');
     $args['sheets'] = $conf['sheets'];
     $this->display = $t->parse('index', $args);
     $t->template_dir = $old;
 }
Exemple #3
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));
 }
Exemple #4
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);
 }
Exemple #5
0
 /**
  * @param string $dispatcher
  * @param string $handle
  * @return string
  */
 function getAttachments($dispatcher, $handle)
 {
     if (is_object($handle)) {
         $action = $handle->handle;
         $handle = $handle->id;
     } else {
         $action = $handle;
     }
     require_once ATTACHMENT_CLASSES . 'Attachment.php';
     $t =& VoodooTemplate::getInstance();
     $t->setDir(ATTACHMENT_TEMPLATES);
     $al = new AttachmentLink($this->db, strtoupper($dispatcher));
     if (!($q = $al->getAttachmentsForLink($handle))) {
         return '';
     }
     if (!$q->rows()) {
         return '';
     }
     $args = array();
     while ($r = $q->fetch()) {
         $args[] = array('name' => $r->NAME, 'filesize' => Attachment::prettyBytes($r->FILESIZE), 'lastupdate' => $r->LAST_UPDATE, 'user' => $r->USER_NAME, 'desc' => $r->DESCRIPTION ? sprintf('<q>%s</q>, ', $r->DESCRIPTION) : '');
     }
     return $t->parse('attachments', array('prepath' => PATH_TO_DOCROOT, 'cont' => strtolower($dispatcher), 'action' => $action, 'attachments' => $args));
 }
 function tfValueProcessor($args)
 {
     switch ($args['head']) {
         case "Result":
             $r = $args['row'];
             $t =& VoodooTemplate::getInstance();
             return $t->parse('diceroller_result', $r);
             break;
         case "Roll Description":
             $r = $args['row'];
             $r['rerolls'] = !$r['rerolls'] ? 'no rerolls' : ($r['rerolls'] === '10' ? '' : $r['rerolls'] . '-again');
             $r['difficulty'] = $r['difficulty'] == $this->default_difficulty ? '' : $r['difficulty'];
             $t =& VoodooTemplate::getInstance();
             return $t->parse('diceroller_description', $r);
             break;
         case "Link":
             return sprintf('<a href="%s/wiki/%s?hash=%s">Link</a>', PATH_TO_DOCROOT, $this->formatter->action, $args['value']);
             break;
     }
     return $args['value'];
 }
Exemple #7
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));
 }
Exemple #8
0
 /**
  * Returns the output that was build by the controller and its dispatchers
  * @return string
  */
 function display($template = null, $dir = null)
 {
     $template || ($template = THEME_NAME);
     $r =& VoodooRegistry::getInstance();
     $t =& VoodooTemplate::getInstance();
     $t->setDir($dir);
     $v =& $r->registry('VC');
     return $t->parse($template, array_merge($this->siteArgs, array('site_title' => $v->conf['engine']['site.title'], 'script' => $this->script, 'styles' => $this->styles, 'style' => $this->style, 'title' => $this->title, 'prepath' => PATH_TO_DOCROOT, 'request_uri' => preg_replace('/[\\/]?\\?(.*)/', '', $_SERVER['REQUEST_URI']), 'menu' => $this->getMenu($v->conf['menu'], isset($v->conf['menu.privileges']) ? $v->conf['menu.privileges'] : array()), 'content' => $this->content)));
 }
Exemple #9
0
 function _nestedTemplate($args)
 {
     $template =& VoodooTemplate::getInstance();
     return $template->parse($args[1], $this->replace);
 }
Exemple #10
0
 function AuthObject(&$dispatcher)
 {
     $this->dispatcher =& $dispatcher;
     $this->db = $dispatcher->controller->DBConnect();
     $this->template =& VoodooTemplate::getInstance();
     $this->template->setDir(AUTH_TEMPLATES);
 }
 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 execute()
 {
     $dry_run = true;
     if (isset($_GET['dry_run']) && $_GET['dry_run'] == 0) {
         $dry_run = false;
     }
     $sql = "SELECT USER_EMAIL as email, USER_PASSWORD as passwd, \r\n\t\t\t\tSHEET_VALUE_ID as sheet_id, SHEET_ID as type\r\n\t\t\tFROM TBL_SHEET_USER \r\n\t\t\tORDER BY SHEET_VALUE_ID";
     $q = $this->original_db->query($sql);
     $q->execute();
     $rv = '';
     $users = array();
     $failures = 0;
     $total = array();
     $user = new User($this->db);
     while ($r = $q->fetch()) {
         $total[$r->sheet_id] = array($r->email, $this->sheet_conv[$r->type]);
         $rv .= sprintf('Converting Sheet <strong>%s</strong>... <ul>', $r->sheet_id);
         if (!$user->setUserByName($r->email)) {
             $rv .= sprintf('<li>new user: %s</li>', $r->email);
             if (isset($users[$r->email])) {
                 $rv .= '<li>user already in list to be created</li>';
                 if ($r->passwd != $users[$r->email]) {
                     $rv .= '<li>[<span class="rejected">failed</span>] = passwords dont match</li>';
                     $failures++;
                 } else {
                     $rv .= '<li>[<span class="blue_text">success</span>] = passwords match</li>';
                 }
             } else {
                 $users[$r->email] = $r->passwd;
             }
         } else {
             $rv .= '<li>user exists...</li>';
             if ($user->password != $r->passwd) {
                 $rv .= '<li>[<span class="rejected">failed</span>] = passwords dont match</li>';
                 $failures++;
             } else {
                 $rv .= '<li>[<span class="blue_text">success</span>] = passwords match</li>';
             }
         }
         $rv .= '</ul><br />';
     }
     $rv .= sprintf('<br />Total Failures <span class="rejected">%s</span> ' . 'out of <span class="blue_text">%s</span><br /><br />', $failures, count($total));
     if ($dry_run) {
         $template =& VoodooTemplate::getInstance();
         $template->setDir(SHEETGEN_TEMPLATES);
         $rv .= $template->parse('button', array('button' => 'CONVERT ALL NON-FAILURES!', 'prepath' => PATH_TO_DOCROOT, 'button_action' => '/sheet/convert?dry_run=0'));
     } else {
         $insert = "INSERT INTO TBL_SHEET_VALUES \r\n\t\t\t\t(VALUE_ID, SHEET_ID, VALUE_INT, VALUE_STRING) VALUES ";
         foreach ($total as $id => $args) {
             list($user_name, $type) = $args;
             $user = new User($this->db);
             if (!$user->setUserByName($user_name)) {
                 $user = new User($this->db, array('name' => $user_name, 'password' => $users[$user_name], 'email' => $user_name));
                 $user->accesslevel = 30;
                 $user->insert();
             }
             $res = $this->convert_sheet($insert, $id, $type, $user);
             $insert = $res;
         }
         $insert = substr($insert, 0, -1);
         $q = $this->db->query($insert);
         $q->execute();
     }
     return $rv;
 }
Exemple #13
0
 /**
  * Constructor
  * 
  * Set the default vars like template, db and dispatcher
  * @param WikiDispatcher &$dispatcher
  */
 function WikiPrivileges(&$dispatcher)
 {
     $this->dispatcher = $dispatcher;
     $config = isset($this->dispatcher->conf['template']) ? $this->dispatcher->conf['template'] : null;
     $this->template =& VoodooTemplate::getInstance($config);
     $this->template->setDir(WIKI_TEMPLATES);
     $this->db = $this->dispatcher->controller->DBConnect();
     $this->defaultArgs = array('prepath' => PATH_TO_DOCROOT);
     $this->privs = new VoodooPrivileges($this->dispatcher->controller);
     $this->siteArgs = array('view' => array('name' => 'article', 'extra' => '<span class="spacer" />'));
     if ($this->hasRights($_SESSION['access'], 'modify')) {
         $this->siteArgs['edit'] = array('name' => 'edit this page');
     } elseif ($this->hasRights($_SESSION['access'], 'source')) {
         $this->siteArgs['source'] = array('name' => 'source');
     }
     if ($this->hasRights($_SESSION['access'], 'history')) {
         $this->siteArgs['history'] = array('name' => 'history');
     }
 }