Example #1
0
 /**
  * @param Database $db
  * @param string $formatter
  */
 function setFormatter($db, $formatter = false)
 {
     $formatter || ($formatter = 'VoodooFormatter');
     if (!preg_match('/^[A-Za-z0-9_]+$/', $formatter)) {
         exit('Incorrect Formatter');
     }
     // Error out
     $split = split('_', $formatter);
     require_once CLASSES . 'VoodooFormatter.php';
     if (count($split) == 2) {
         list($dir, $formatter) = $split;
         if (is_file(SPELLBOOK . $dir . '/classes/' . $formatter . '.php')) {
             require_once SPELLBOOK . $dir . '/classes/' . $formatter . '.php';
         } else {
             $formatter = 'VoodooFormatter';
         }
     }
     $f = new $formatter($db);
     VoodooFormatter::register($f);
 }
Example #2
0
 /**
  * @param string $text
  * @param mixed $args
  * @return string
  */
 function format($text, $args = array())
 {
     $formatter =& VoodooFormatter::getInstance();
     return $formatter->parse($text, $args);
 }
Example #3
0
 /**
  * Parse the context content and replace wikiformatting
  * @return string $content
  */
 function parse($txt, $args = array())
 {
     if ($args) {
         foreach ($args as $index => $value) {
             $this->{$index} = $value;
         }
     }
     $txt = preg_replace_callback('/{{{(.*)}}}/siU', array(&$this, '__callbackMonospace'), $txt);
     $txt = preg_replace_callback("/^(={1,3})(.*)(={1,3})/m", array(&$this, '__callbackHeading'), $txt);
     $txt = preg_replace_callback('/(?<=^|\\n| )([\\!]?[A-Z]{1}[a-z]+([A-Z]{1}[a-z]+)+)/', array(&$this, '__callbackCamelCase'), $txt);
     // Underline
     $txt = preg_replace('/__(.*)__/iU', '<u>\\1</u>', $txt);
     // Deleting, strike through
     $txt = preg_replace('/~~(.*)~~/iU', '<del>\\1</del>', $txt);
     // Super text
     $txt = preg_replace('/\\^(.*)\\^/iU', '<sup>\\1</sup>', $txt);
     // Sub text
     $txt = preg_replace('/,,(.*),,/iU', '<sub>\\1</sub>', $txt);
     // Bold-Italic text
     $txt = preg_replace('/\'\'\'\'(.*)\'\'\'\'/iU', '<strong><em>\\1</em></strong>', $txt);
     // Bold text
     $txt = preg_replace('/\'\'\'(.*)\'\'\'/iU', '<strong>\\1</strong>', $txt);
     // Italic text
     $txt = preg_replace('/\'\'(.*)\'\'/iU', '<em>\\1</em>', $txt);
     $txt = preg_replace_callback("/\\[(http[s]?:\\/\\/.*)\\]/siU", array(&$this, '__callbackLink'), $txt);
     $txt = preg_replace_callback("/\\[img:(http[s]?:\\/\\/.*)\\]/siU", array(&$this, '__callbackImage'), $txt);
     $txt = preg_replace_callback("/\\[wiki:(.*)\\]/siU", array(&$this, '__callbackWiki'), $txt);
     // Horizontal Ruler
     $txt = preg_replace('/----/iU', '<hr size="1">', $txt);
     //		$txt = preg_replace_callback("/[\!]?\{([0-9]+)\}|[\!]?report:([0-9]+)/siU", array(&$this,'__replaceReportLink'), $txt);
     //	$txt = preg_replace_callback("/[\!]?#([0-9]+)|[\!]?topic:([0-9]+)/siU", array(&$this,'__replaceTopicLink'), $txt);
     // Line end. Hard enter
     $txt = preg_replace("/\\[\\[BR\\]\\]/siU", '<br />', $txt);
     $txt = preg_replace_callback("/(\\!)?\\[\\[([a-z0-9_]+)(\\(.*\\))?\\]\\]/siU", array(&$this, '__callbackPotion'), $txt);
     if (preg_match('/^([ ]+)\\*.*$/m', $txt)) {
         $txt = $this->__callbackUL($txt);
     }
     if (preg_match('/^([ ]+)(\\d+|a|i)\\..*$/m', $txt)) {
         $txt = $this->__callbackOL($txt);
     }
     return parent::parse($txt, array());
 }
Example #4
0
 /**
  * @param int $id
  * @param string $content
  * @param bool $actions
  * @param bool|int $revision 
  */
 function execute($id = null, $content = '', $actions = true, $revision = false)
 {
     $handle = '';
     if ($id) {
         $w = new Wiki($this->db);
         $w->set($id, $revision);
         $content = $w->revision->content;
         $handle = $w->handle;
         $this->dispatcher->controller->dispatcherObject = $w;
     }
     // We dont have rights to view wiki's (or this individual page)
     // @see VoodooPrivileges
     if (!$this->hasRights($_SESSION['access'], 'view', $handle)) {
         return array($handle . ' - WikiView', 'No Permission');
     }
     $wf =& VoodooFormatter::getInstance();
     $wf->setWikiPotions($this->dispatcher->conf['potions']);
     // this assumes stuff
     if (isset($this->dispatcher->conf['templates']) && isset($this->dispatcher->conf['templates']['template.' . $handle])) {
         $this->dispatcher->controller->site_template = $this->dispatcher->conf['templates']['template.' . $handle];
     }
     $content = $wf->parse($content, array('handler' => 'wiki', 'action' => $handle));
     // Add simple template in case the rights are to modify/delete
     // We were told to show actions, so lets verify the rights
     $buttons = '';
     $attachments = (bool) (isset($this->dispatcher->conf['attachment']) && $this->dispatcher->conf['attachment'] && defined('ATTACHMENT_CLASSES'));
     // We can modify the wiki page, show the button to do so
     if ($actions && $this->hasRights($_SESSION['access'], 'modify', $handle)) {
         $args = $this->defaultArgs;
         $args['button_action'] = '/wiki/' . $handle . '?action=edit';
         $args['button'] = 'Edit this page';
         $args['class'] = 'buttonmargin';
         $buttons .= $this->template->parse('button', $args);
         // We can add attachments
         // TODO: we dont want the wiki to know anything about attachments
         if ($attachments) {
             $args = $this->defaultArgs;
             $args['button_action'] = '/attachment/wiki/' . $handle . '?action=create';
             $args['button'] = 'Attach file';
             $args['class'] = 'buttonmargin';
             $buttons .= $this->template->parse('button', $args);
         }
     }
     $buttons .= '<span class="spacer"></span>';
     // We can view the history of the wiki page, show the button
     if ($actions && $this->hasRights($_SESSION['access'], 'history', $handle)) {
         $args = $this->defaultArgs;
         $args['button_action'] = '/wiki/' . $handle . '?action=history';
         $args['button'] = 'View page history';
         $args['class'] = 'buttonlargemargin';
         $buttons .= $this->template->parse('button', $args);
     }
     // We can delete the wiki page, show the button
     if ($actions && $this->hasRights($_SESSION['access'], 'delete', $handle)) {
         $args = $this->defaultArgs;
         $args['button_action'] = '/wiki/' . $handle . '?action=delete';
         $args['button'] = 'Delete page';
         $args['class'] = 'buttonmargin';
         $buttons .= $this->template->parse('button', $args);
     }
     $this->siteArgs['view']['active'] = 'active';
     $this->addSiteArgs();
     return array($handle . ' - WikiView', $this->template->parse('view', array('content' => $content, 'buttons' => $buttons)));
 }