Example #1
0
 /**
  * Loads the template for a new blog post and does some text replacements
  *
  * @author Gina Haeussge <*****@*****.**>
  *
  * @param $id
  * @param $title
  * @return bool|mixed|string
  */
 function _prepare_template($id, $title)
 {
     $tpl = pageTemplate($id);
     if (!$tpl) {
         $tpl = io_readFile(DOKU_PLUGIN . 'blogtng/tpl/newentry.txt');
     }
     $replace = array('@TITLE@' => $title);
     $tpl = str_replace(array_keys($replace), array_values($replace), $tpl);
     return $tpl;
 }
Example #2
0
 /**
  * Return a raw wiki page
  * @param string $id wiki page id
  * @param string $rev revision number of the page
  * @return page text.
  */
 function rawPage($id, $rev = '')
 {
     $id = $this->resolvePageId($id);
     if (auth_quickaclcheck($id) < AUTH_READ) {
         throw new RemoteAccessDeniedException('You are not allowed to read this file', 111);
     }
     $text = rawWiki($id, $rev);
     if (!$text) {
         return pageTemplate($id);
     } else {
         return $text;
     }
 }
Example #3
0
 /**
  * Checks if 'newentry' was given as action, if so we
  * do handle the event our self and no further checking takes place
  */
 function handle_act_preprocess(&$event, $param)
 {
     //if ($event->data != 'newentry') return; // nothing to do for us
     global $ACT;
     global $ID;
     echo "param={$param}";
     return;
     // we can handle it -> prevent others
     $event->stopPropagation();
     $event->preventDefault();
     $ns = $_REQUEST['ns'];
     $title = str_replace(':', '', $_REQUEST['title']);
     $id = ($ns ? $ns . ':' : '') . cleanID($title);
     // check if we are allowed to create this file
     if (auth_quickaclcheck($id) >= AUTH_CREATE) {
         $back = $ID;
         $ID = $id;
         $file = wikiFN($ID);
         //check if locked by anyone - if not lock for my self
         if (checklock($ID)) {
             $ACT = 'locked';
         } else {
             lock($ID);
         }
         // prepare the new thread file with default stuff
         if (!@file_exists($file)) {
             global $TEXT;
             global $INFO;
             global $conf;
             $TEXT = pageTemplate($ns . ':' . $title);
             if (!$TEXT) {
                 $TEXT = "====== {$title} ======\n\n\n\n" . "~~DISCUSSION~~\n";
             }
             $ACT = 'preview';
         } else {
             $ACT = 'edit';
         }
     } else {
         $ACT = 'show';
     }
 }
Example #4
0
 /**
  * Creates a new entry page
  */
 function _handle_newEntry()
 {
     global $ID, $INFO;
     $ns = cleanID($_REQUEST['ns']);
     $title = str_replace(':', '', $_REQUEST['title']);
     $ID = $this->_newEntryID($ns, $title);
     $INFO = pageinfo();
     // check if we are allowed to create this file
     if ($INFO['perm'] >= AUTH_CREATE) {
         //check if locked by anyone - if not lock for my self
         if ($INFO['locked']) {
             return 'locked';
         } else {
             lock($ID);
         }
         // prepare the new thread file with default stuff
         if (!@file_exists($INFO['filepath'])) {
             global $TEXT;
             $TEXT = pageTemplate(array(($ns ? $ns . ':' : '') . $title));
             if (!$TEXT) {
                 $data = array('id' => $ID, 'ns' => $ns, 'title' => $title);
                 $TEXT = $this->_pageTemplate($data);
             }
             return 'preview';
         } else {
             return 'edit';
         }
     } else {
         return 'show';
     }
 }
Example #5
0
 /**
  * Return a raw wiki page
  */
 function rawPage($id, $rev = '')
 {
     $id = cleanID($id);
     if (auth_quickaclcheck($id) < AUTH_READ) {
         return new IXR_Error(1, 'You are not allowed to read this page');
     }
     $text = rawWiki($id, $rev);
     if (!$text) {
         return pageTemplate($id);
     } else {
         return $text;
     }
 }
Example #6
0
 /**
  * Load template(s) for targetpage as given via action field
  *
  * @param string $tpl    template name as given in form
  * @return string parsed templatename
  */
 protected function getActionTargetpages($tpl)
 {
     global $USERINFO;
     global $conf;
     global $ID;
     $runas = $this->getConf('runas');
     if ($tpl == '_') {
         // use namespace template
         if (!isset($this->targetpages[$this->pagename])) {
             $this->targetpages[$this->pagename] = pageTemplate(array($this->pagename));
         }
     } elseif ($tpl !== '!') {
         $tpl = $this->replace($tpl);
         resolve_pageid(getNS($ID), $tpl, $ignored);
         $backup = array();
         if ($runas) {
             // Hack user credentials.
             $backup = array($_SERVER['REMOTE_USER'], $USERINFO['grps']);
             $_SERVER['REMOTE_USER'] = $runas;
             $USERINFO['grps'] = array();
         }
         $template_pages = array();
         //search checks acl (as runas)
         $opts = array('depth' => 0, 'listfiles' => true, 'showhidden' => true);
         search($template_pages, $conf['datadir'], 'search_universal', $opts, str_replace(':', '/', getNS($tpl)));
         foreach ($template_pages as $template_page) {
             $templatepageid = cleanID($template_page['id']);
             // try to replace $tpl path with $this->pagename path in the founded $templatepageid
             // - a single-page template will only match on itself and will be replaced,
             //   other newtargets are pages in same namespace, so aren't changed
             // - a namespace as template will match at the namespaces-part of the path of pages in this namespace
             //   so these newtargets are changed
             // if there exist a single-page and a namespace with name $tpl, both are selected
             $newTargetpageid = preg_replace('/^' . preg_quote_cb(cleanID($tpl)) . '($|:)/', $this->pagename . '$1', $templatepageid);
             if ($newTargetpageid === $templatepageid) {
                 // only a single-page template or page in the namespace template
                 // which matches the $tpl path are changed
                 continue;
             }
             if (!isset($this->targetpages[$newTargetpageid])) {
                 $this->addParsedTargetpage($newTargetpageid, $templatepageid);
             }
         }
         if ($runas) {
             /* Restore user credentials. */
             list($_SERVER['REMOTE_USER'], $USERINFO['grps']) = $backup;
         }
     }
     return $tpl;
 }
Example #7
0
/**
 * Handle 'edit', 'preview', 'recover'
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function act_edit($act)
{
    global $ID;
    global $INFO;
    global $TEXT;
    global $RANGE;
    global $PRE;
    global $SUF;
    global $REV;
    global $SUM;
    global $lang;
    global $DATE;
    if (!isset($TEXT)) {
        if ($INFO['exists']) {
            if ($RANGE) {
                list($PRE, $TEXT, $SUF) = rawWikiSlices($RANGE, $ID, $REV);
            } else {
                $TEXT = rawWiki($ID, $REV);
            }
        } else {
            $TEXT = pageTemplate($ID);
        }
    }
    //set summary default
    if (!$SUM) {
        if ($REV) {
            $SUM = $lang['restored'];
        } elseif (!$INFO['exists']) {
            $SUM = $lang['created'];
        }
    }
    // Use the date of the newest revision, not of the revision we edit
    // This is used for conflict detection
    if (!$DATE) {
        $DATE = $INFO['meta']['date']['modified'];
    }
    //check if locked by anyone - if not lock for my self
    $lockedby = checklock($ID);
    if ($lockedby) {
        return 'locked';
    }
    lock($ID);
    return $act;
}
Example #8
0
    /**
     * function _preprocess
     * @author  Myron Turner <*****@*****.**>
     */
    function _preprocess()
    {
        global $ID;
        global $REV;
        global $DATE;
        global $RANGE;
        global $PRE;
        global $SUF;
        global $INFO;
        global $SUM;
        global $lang;
        global $conf;
        global $ckgedit_lang;
        //set summary default
        if (!$SUM) {
            if ($REV) {
                $SUM = $lang['restored'];
            } elseif (!$INFO['exists']) {
                $SUM = $lang['created'];
            }
        }
        if ($INFO['exists']) {
            if ($RANGE) {
                list($PRE, $text, $SUF) = rawWikiSlices($RANGE, $ID, $REV);
            } else {
                $text = rawWiki($ID, $REV);
            }
        } else {
            //try to load a pagetemplate
            $text = pageTemplate($ID);
            //Check for text from template event handler
            if (!$text && $this->page_from_template) {
                $text = $this->page_from_template;
            }
        }
        $text = preg_replace_callback('/(~~NOCACHE~~|~~NOTOC~~|\\{\\{rss>http:\\/\\/.*?\\}\\})/ms', create_function('$matches', '$matches[0] = str_replace("{{rss>http://", "{ { rss>Feed:",  $matches[0]);
               $matches[0] = str_replace("~", "~ ",  $matches[0]);
               return $matches[0];'), $text);
        if ($this->getConf('smiley_hack')) {
            $new_addr = $_SERVER['SERVER_NAME'] . DOKU_BASE;
            $text = preg_replace("#(?<=http://)(.*?)(?=lib/plugins/ckgedit/ckeditor/plugins/smiley/images)#s", $new_addr, $text);
        }
        $text = preg_replace_callback('/\\[\\[\\w+>.*?\\]\\]/ms', create_function('$matches', 'return str_replace("/", "__IWIKI_FSLASH__" ,$matches[0]);'), $text);
        global $useComplexTables;
        if ($this->getConf('complex_tables') || strrpos($text, '~~COMPLEX_TABLES~~') !== false) {
            $useComplexTables = true;
        } else {
            $useComplexTables = false;
        }
        if (strpos($text, '%%') !== false) {
            $text = preg_replace_callback("/<(nowiki|code|file)>(.*?)<\\/(nowiki|code|file)/ms", function ($matches) {
                $matches[0] = str_replace('%%', 'DBLPERCENT', $matches[0]);
                return $matches[0];
            }, $text);
            $text = preg_replace_callback("/(?<!nowiki>)%%(.*?)%%/ms", function ($matches) {
                return '<nowiki>' . $matches[1] . '</nowiki>';
            }, $text);
            $text = str_replace('DBLPERCENT', '%%', $text);
        }
        $pos = strpos($text, '<');
        if ($pos !== false) {
            $text = preg_replace_callback('/(<nowiki>)(.*?)(<\\/nowiki>)/ms', create_function('$matches', '$needles =  array("[","]", "/",  ".", "*", "_","\'","<",">","%", "{", "}", "\\\\","(");
                  $replacements = array("&#91;","&#93;","&#47;", "&#46;", "&#42;", "&#95;", "&#39;", "&#60;","&#62;","&#37;", "&#123;","&#125;", "&#92;","&#40;"); 
                  $matches[2] = str_replace($needles, $replacements, $matches[2]);
                  return  $matches[1] . $matches[2] . $matches[3];'), $text);
            $text = preg_replace_callback('/<(code|file)(.*?)(>)(.*?)(<\\/\\1>)/ms', create_function('$matches', ' //file_put_contents("geshi.txt", print_r($matches,true));
                 if(preg_match("/(^\\s*geshi:\\s*(\\w+)(\\s+\\w+\\.\\w+)*\\s*)$/m",$matches[0],$gmatch)){
                      $gmatch[0] = preg_replace("/\\s*geshi:\\s+/","",$gmatch[0]);                    
                      $matches[1] .= " " . trim($gmatch[0]);                       
                      //file_put_contents("gmatch.txt", print_r($gmatch,true));
                      $c=1;
                      $matches[4] = str_replace($gmatch[1],"",$matches[4],$c);
                  }
                 if(preg_match("/\\w+/",$matches[2])) {
                   $matches[4] = str_replace("CHEVRONescC", ">>",$matches[4]);
                   $matches[4] = str_replace("CHEVRONescO", "<<",$matches[4]);
                   $matches[4] = preg_replace("/<(?!\\s)/ms", "__GESHI_OPEN__", $matches[4]); 
                  }
                  else {
                  if( preg_match("/MULTI/",$matches[0])) {
                     $open = "< ";
                     $close = " >";
                  }
                  else {  
                     $open = "&lt;";
                     $close = "&gt;";
                  }
                  $matches[4] = preg_replace("/<(?!\\s)/ms", $open, $matches[4]); 
                  $matches[4] = preg_replace("/(?<!\\s)>/ms", $close, $matches[4]);                    
                  }
                  $matches[4] = str_replace("\\"", "__GESHI_QUOT__", $matches[4]);     
                  return "<" . $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];'), $text);
            /* \n_ckgedit_NPBBR_\n: the final \n prevents this from iterfering with next in line markups
                  -- in particular tables which require a new line and margin left 
                 this may leave an empty paragraph in the xhtml, which is removed below 
               */
            $text = preg_replace('/<\\/(code|file)>(\\s*)(?=[^\\w])(\\s*)/m', "</\$1>\n_ckgedit_NPBBR_\n\$2", $text);
            $text = preg_replace_callback('/~~START_HTML_BLOCK~~.*?CLOSE_HTML_BLOCK/ms', create_function('$matches', '$matches[0] = str_replace("_ckgedit_NPBBR_","",$matches[0]);
                 return $matches[0];'), $text);
            $text = preg_replace_callback('/(\\|\\s*)(<code>|<file>)(.*?)(<\\/code>|<\\/file>)\\n_ckgedit_NPBBR_(?=.*?\\|)/ms', create_function('$matches', '$matches[2] = preg_replace("/<code>/ms", "TPRE_CODE", $matches[2]); 
                  $matches[2] = preg_replace("/<file>/ms", "TPRE_FILE", $matches[2]);    
                  $matches[4] = "TPRE_CLOSE";                    
                  $matches[3] = preg_replace("/^\\n+/", "TC_NL",$matches[3]);  
                  $matches[3] = preg_replace("/\\n/ms", "TC_NL",$matches[3]);                                   
                  return $matches[1] . $matches[2] .  trim($matches[3]) .   $matches[4];'), $text);
            $text = preg_replace('/TPRE_CLOSE\\s+/ms', "TPRE_CLOSE", $text);
            $text = preg_replace('/<(?!code|file|del|sup|sub|\\/\\/|\\s|\\/del|\\/code|\\/file|\\/sup|\\/sub)/ms', "&lt;", $text);
            $text = str_replace('%%&lt;', '&#37;&#37;&#60;', $text);
        }
        if ($this->getConf('duplicate_notes')) {
            $text = preg_replace_callback('/\\(\\((.*?)\\)\\)/ms', create_function('$matches', 'static $count = 0;
				   $count++;
				   $ins = "FNoteINSert" . $count;
                   $needles =  array("[","]", "/",  ".", "*", "_","\'","<",">","%", "{", "}", "\\\\","(");
                   $replacements = array("&#91;","&#93;","&#47;", "&#46;", "&#42;", "&#95;", "&#39;", "&#60;","&#62;","&#37;", "&#123;","&#125;", "&#92;","&#40;"); 
                   $matches[1] = str_replace($needles, $replacements, $matches[1]);                    
              	   return "(($ins" . $matches[1] . "))" ;'), $text);
        }
        $text = preg_replace('/^\\>/ms', "_QUOT_", $text);
        // dw quotes
        $text = str_replace('>>', 'CHEVRONescC', $text);
        $text = str_replace('<<', 'CHEVRONescO', $text);
        $text = preg_replace('/(={3,}.*?)(\\{\\{.*?\\}\\})(.*?={3,})/', "\$1\$3\n\$2", $text);
        $email_regex = '/\\/\\/\\<\\/\\/(.*?@.*?)>/';
        $text = preg_replace($email_regex, "<\$1>", $text);
        $text = preg_replace('/{{(.*)\\.swf(\\s*)}}/ms', "__SWF__\$1.swf\$2__FWS__", $text);
        $this->xhtml = $this->_render_xhtml($text);
        $this->xhtml = str_replace("__IWIKI_FSLASH__", "&frasl;", $this->xhtml);
        if ($this->getConf('duplicate_notes')) {
            $this->xhtml = preg_replace("/FNoteINSert\\d+/ms", "", $this->xhtml);
        }
        $this->xhtml = str_replace("__GESHI_QUOT__", '&#34;', $this->xhtml);
        $this->xhtml = str_replace("__GESHI_OPEN__", "&#60; ", $this->xhtml);
        $this->xhtml = str_replace('CHEVRONescC', '>>', $this->xhtml);
        $this->xhtml = str_replace('CHEVRONescO', '<<', $this->xhtml);
        $this->xhtml = preg_replace('/_QUOT_/ms', '>', $this->xhtml);
        // dw quotes
        if ($pos !== false) {
            $this->xhtml = preg_replace_callback('/(TPRE_CODE|TPRE_FILE)(.*?)(TPRE_CLOSE)/ms', create_function('$matches', '$matches[1] = preg_replace("/TPRE_CODE/","<pre class=\'code\'>\\n", $matches[1]);  
                    $matches[1] = preg_replace("/TPRE_FILE/","<pre class=\'file\'>\\n", $matches[1]);  
                    $matches[2] = preg_replace("/TC_NL/ms", "\\n", $matches[2]);  
                    $matches[3] = "</pre>";                    
                    return $matches[1] . $matches[2] . $matches[3];'), $this->xhtml);
        }
        $this->xhtml = preg_replace_callback('/~~START_HTML_BLOCK~~[\\n\\s]*(.*?)CLOSE_HTML_BLOCK/ms', create_function('$matches', '$matches[1] = str_replace("&amp;","&",$matches[1]);
         $matches[1] =  html_entity_decode($matches[1],ENT_QUOTES, "UTF-8");
             $matches[1] = preg_replace("/<\\/?code.*?>/", "",$matches[1]);
         $matches[1] = preg_replace("/^\\s*<\\/p>/","",$matches[1]);
         $tmp = explode("\\n", $matches[1]);
         for($n=0; $n<7; $n++) {
               if( (preg_match("/(<p>\\s*)*(&nbsp;|\\s+)<\\/p>/",$tmp[$n])) || (preg_match("/^\\s+$/",$tmp[$n]))) {
                unset($tmp[$n]);
             }
          }
         return "~~START_HTML_BLOCK~~" . implode("\\n",$tmp) . "CLOSE_HTML_BLOCK"; '), $this->xhtml);
        $this->xhtml = preg_replace_callback('/(<pre)(.*?)(>)(.*?)(<\\/pre>)/ms', create_function('$matches', '$matches[4] = preg_replace("/(\\||\\^)[ ]+(\\||\\^)/ms","$1 &nbsp; $2" , $matches[4]);                    
                  return  $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];'), $this->xhtml);
        $this->xhtml = preg_replace_callback('/~~MULTI_PLUGIN_OPEN~~(.*?)~~MULTI_PLUGIN_CLOSE~~/ms', create_function('$matches', 'return str_replace("&lt;", "< ",$matches[0]);'), $this->xhtml);
        $cname = getCacheName($INFO['client'] . $ID, '.draft.fckl');
        if (file_exists($cname)) {
            $cdata = unserialize(io_readFile($cname, false));
            $cdata['text'] = urldecode($cdata['text']);
            preg_match_all("/<\\/(.*?)\\>/", $cdata['text'], $matches);
            /* exclude drafts saved from preview mode */
            if (!in_array('code', $matches[1]) && !in_array('file', $matches[1]) && !in_array('nowiki', $matches[1])) {
                $this->draft_text = $cdata['text'];
                $this->draft_found = true;
                msg($this->getLang('draft_msg'));
            }
            unlink($cname);
        }
        return true;
    }
 function run($data, $thanks, $argv)
 {
     global $ID;
     global $conf;
     global $USERINFO;
     list($tpl, $pagename, $sep) = $argv;
     if (is_null($sep)) {
         $sep = $conf['sepchar'];
     }
     $runas = $this->getConf('runas');
     $patterns = array();
     $values = array();
     $templates = array();
     // run through fields
     foreach ($data as $opt) {
         $label = $opt->getParam('label');
         $value = $opt->getParam('value');
         // prepare replacements
         if (!is_null($label)) {
             $patterns[$label] = '/(@@|##)' . preg_quote($label, '/') . '(?:\\|([^|]*?))' . (is_null($value) ? '' : '?') . '\\1/si';
             $values[$label] = is_null($value) ? '$2' : $value;
             $patterns[$label . '|'] = '/(@@|##)' . preg_quote($label, '/') . '(?:\\|(.*?))(?:\\|(.*?))\\1/si';
             $values[$label . '|'] = is_null($value) ? '$2' : '$3';
         }
         // handle pagenames
         $pname = $opt->getParam('pagename');
         if (!is_null($pname)) {
             $pagename .= $sep . $pname;
         }
         if (!is_null($opt->getParam('page_tpl')) && !is_null($opt->getParam('page_tgt'))) {
             $page_tpl = $this->replace($patterns, $values, $opt->getParam('page_tpl'));
             if (auth_aclcheck($page_tpl, $runas ? $runas : $_SERVER['REMOTE_USER'], $USERINFO['grps']) >= AUTH_READ) {
                 $templates[$opt->getParam('page_tgt')] = rawWiki($page_tpl);
             }
         }
     }
     $pagename = $this->replace($patterns, $values, $pagename);
     // check pagename
     $pagename = cleanID($pagename);
     if ($pagename === '') {
         throw new Exception($this->getLang('e_pagename'));
     }
     $_templates = array();
     foreach ($templates as $k => $v) {
         $_templates[cleanID("{$pagename}:{$k}")] = $v;
     }
     $templates = $_templates;
     // get templates
     if ($tpl == '_') {
         // use namespace template
         if (!isset($templates[$pagename])) {
             $templates[$pagename] = pageTemplate(array($pagename));
         }
     } elseif ($tpl !== '!') {
         // Namespace link
         require_once DOKU_INC . 'inc/search.php';
         if ($runas) {
             // Hack user credentials.
             global $USERINFO;
             $backup = array($_SERVER['REMOTE_USER'], $USERINFO['grps']);
             $_SERVER['REMOTE_USER'] = $runas;
             $USERINFO['grps'] = array();
         }
         $t_pages = array();
         search($t_pages, $conf['datadir'], 'search_universal', array('depth' => 0, 'listfiles' => true), str_replace(':', '/', getNS($tpl)));
         foreach ($t_pages as $t_page) {
             $t_name = cleanID($t_page['id']);
             $p_name = preg_replace('/^' . preg_quote_cb(cleanID($tpl)) . '($|:)/', $pagename . '$1', $t_name);
             if ($p_name === $t_name) {
                 // When using a single-page template, ignore other pages
                 // in the same namespace.
                 continue;
             }
             if (!isset($templates[$p_name])) {
                 // load page data and do default pattern replacements like
                 // namespace templates do
                 $data = array('id' => $p_name, 'tpl' => rawWiki($t_name), 'doreplace' => true);
                 parsePageTemplate($data);
                 $templates[$p_name] = $data['tpl'];
             }
         }
         if ($runas) {
             /* Restore user credentials. */
             global $USERINFO;
             list($_SERVER['REMOTE_USER'], $USERINFO['grps']) = $backup;
         }
     }
     if (empty($templates)) {
         throw new Exception(sprintf($this->getLang('e_template'), $tpl));
     }
     // check all target pagenames
     foreach (array_keys($templates) as $pname) {
         // prevent overriding already existing pages
         if (page_exists($pname)) {
             throw new Exception(sprintf($this->getLang('e_pageexists'), html_wikilink($pname)));
         }
         // check auth
         if ($runas) {
             $auth = auth_aclcheck($pname, $runas, array());
         } else {
             $auth = auth_quickaclcheck($pname);
         }
         if ($auth < AUTH_CREATE) {
             throw new Exception($this->getLang('e_denied'));
         }
     }
     foreach ($templates as $pname => $template) {
         // set NSBASE var to make certain dataplugin constructs easier
         $patterns['__nsbase__'] = '/@NSBASE@/';
         $values['__nsbase__'] = noNS(getNS($pname));
         // save page
         saveWikiText($pname, $this->replace($patterns, $values, $template, false), sprintf($this->getLang('summary'), $ID));
     }
     $ret = "<p>{$thanks}</p>";
     // Build result tree
     $pages = array_keys($templates);
     usort($pages, array($this, '_sort'));
     $oldid = $ID;
     $data = array();
     $last_folder = array();
     foreach ($pages as $ID) {
         $lvl = substr_count($ID, ':');
         for ($n = 0; $n < $lvl; ++$n) {
             if (!isset($last_folder[$n]) || strpos($ID, $last_folder[$n]['id']) !== 0) {
                 $last_folder[$n] = array('id' => substr($ID, 0, strpos($ID, ':', ($n > 0 ? strlen($last_folder[$n - 1]['id']) : 0) + 1) + 1), 'level' => $n + 1, 'open' => 1);
                 $data[] = $last_folder[$n];
             }
         }
         $data[] = array('id' => $ID, 'level' => 1 + substr_count($ID, ':'), 'type' => 'f');
     }
     $ret .= html_buildlist($data, 'idx', array($this, 'html_list_index'), 'html_li_index');
     // Add indexer bugs for every just-created page
     $ret .= '<div class="no">';
     ob_start();
     foreach ($pages as $ID) {
         // indexerWebBug uses ID and INFO[exists], but the bureaucracy form
         // page always exists, as does the just-saved page, so INFO[exists]
         // is correct in any case
         tpl_indexerWebBug();
         // the iframe will trigger real rendering of the pages to make sure
         // any used plugins are initialized (eg. the do plugin)
         echo '<iframe src="' . wl($ID, array('do' => 'export_html')) . '" width="1" height="1" style="visibility:hidden"></iframe>';
     }
     $ret .= ob_get_contents();
     ob_end_clean();
     $ID = $oldid;
     $ret .= '</div>';
     return $ret;
 }
Example #10
0
/**
 * Handle 'edit', 'preview', 'recover'
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function act_edit($act)
{
    global $ID;
    global $INFO;
    global $TEXT;
    global $RANGE;
    global $PRE;
    global $SUF;
    global $REV;
    global $SUM;
    global $lang;
    global $DATE;
    if (!isset($TEXT)) {
        if ($INFO['exists']) {
            if ($RANGE) {
                list($PRE, $TEXT, $SUF) = rawWikiSlices($RANGE, $ID, $REV);
            } else {
                $TEXT = rawWiki($ID, $REV);
            }
        } else {
            $TEXT = pageTemplate($ID);
        }
    }
    //set summary default
    if (!$SUM) {
        if ($REV) {
            $SUM = sprintf($lang['restored'], dformat($REV));
        } elseif (!$INFO['exists']) {
            $SUM = $lang['created'];
        }
    }
    // Use the date of the newest revision, not of the revision we edit
    // This is used for conflict detection
    if (!$DATE) {
        $DATE = @filemtime(wikiFN($ID));
    }
    //check if locked by anyone - if not lock for my self
    //do not lock when the user can't edit anyway
    if ($INFO['writable']) {
        $lockedby = checklock($ID);
        if ($lockedby) {
            return 'locked';
        }
        lock($ID);
    }
    return $act;
}
Example #11
0
    /**
     * function _preprocess
     * @author  Myron Turner <*****@*****.**>
     */
    function _preprocess()
    {
        global $ID;
        global $REV;
        global $DATE;
        global $RANGE;
        global $PRE;
        global $SUF;
        global $INFO;
        global $SUM;
        global $lang;
        global $conf;
        global $fckg_lang;
        //set summary default
        if (!$SUM) {
            if ($REV) {
                $SUM = $lang['restored'];
            } elseif (!$INFO['exists']) {
                $SUM = $lang['created'];
            }
        }
        if ($INFO['exists']) {
            if ($RANGE) {
                list($PRE, $text, $SUF) = rawWikiSlices($RANGE, $ID, $REV);
            } else {
                $text = rawWiki($ID, $REV);
            }
        } else {
            //try to load a pagetemplate
            $text = pageTemplate($ID);
            //Check for text from template event handler
            if (!$text && $this->page_from_template) {
                $text = $this->page_from_template;
            }
        }
        if ($this->getConf('smiley_hack')) {
            $new_addr = $_SERVER['SERVER_NAME'] . DOKU_BASE;
            $text = preg_replace("#(?<=http://)(.*?)(?=lib/plugins/fckg/fckeditor/editor/images/smiley/msn)#s", $new_addr, $text);
        }
        $text = preg_replace_callback('/\\[\\[\\w+>.*?\\]\\]/ms', create_function('$matches', 'return str_replace("/", "__IWIKI_FSLASH__" ,$matches[0]);'), $text);
        global $useComplexTables;
        if ($this->getConf('complex_tables') || strrpos($text, '~~COMPLEX_TABLES~~') !== false) {
            $useComplexTables = true;
        } else {
            $useComplexTables = false;
        }
        if (strpos($text, '%%') !== false) {
            $text = preg_replace_callback('/(<nowiki>)*(\\s*)%%\\s*([^%]+)\\s*%%(<\\/nowiki>)*(\\s*)/ms', create_function('$matches', 'if(preg_match("/<nowiki>/",$matches[1])) {
                   $matches[1] .= "%%";
                }
                else  $matches[1] = "<nowiki>";
                if(preg_match("/<\\/nowiki>/",$matches[4])) {
                   $matches[4] = "%%</nowiki>";
                }
                else $matches[4] = "</nowiki>";  
                return   $matches[1] .  $matches[2] .  $matches[3] . $matches[4] . $matches[5];'), $text);
        }
        /* convert html tags to entities in indented code blocks*/
        $text = preg_replace_callback('/(\\n  )((?![\\*\\-]).*?)(\\n)(?!\\s)/ms', create_function('$matches', '$matches[0] = preg_replace("/(\\[\\[\\w+)>/ms","$1__IWIKI__",$matches[0]);
            $matches[0] = preg_replace("/<(?!\\s)/ms", "&lt;", $matches[0]); 
            $matches[0] = preg_replace("/(?<!\\s)>/ms", "&gt;", $matches[0]);    
            $matches[0] = preg_replace("/__IWIKI__/ms", ">", $matches[0]);    
            return $matches[0];  '), $text);
        $pos = strpos($text, '<');
        if ($pos !== false) {
            $text = preg_replace_callback('/(<nowiki>)(.*?)(<\\/nowiki>)/ms', create_function('$matches', '$needles =  array("[","]", "/",  ".", "*", "_","\'","<",">","%", "{", "}", "\\\\");
                  $replacements = array("&#91;","&#93;","&#47;", "&#46;", "&#42;", "&#95;", "&#39;", "&#60;","&#62;","&#37;", "&#123;","&#125;", "&#92;"); 
                  $matches[2] = str_replace($needles, $replacements, $matches[2]);
                  return  $matches[1] . $matches[2] . $matches[3];'), $text);
            $text = preg_replace_callback('/<(code|file)(.*?)(>)(.*?)(<\\/\\1>)/ms', create_function('$matches', 'if(preg_match("/\\w+/",$matches[2])) {
                   $matches[4] = str_replace("CHEVRONescC", ">>",$matches[4]);
                   $matches[4] = str_replace("CHEVRONescO", "<<",$matches[4]);
                   $matches[4] = preg_replace("/<(?!\\s)/ms", "__GESHI_OPEN__", $matches[4]); 
                  }
                  else {
                  if( preg_match("/MULTI/",$matches[0])) {
                     $open = "< ";
                     $close = " >";
                  }
                  else {  
                     $open = "&lt;";
                     $close = "&gt;";
                  }
                  $matches[4] = preg_replace("/<(?!\\s)/ms", $open, $matches[4]); 
                  $matches[4] = preg_replace("/(?<!\\s)>/ms", $close, $matches[4]);                    
                  }
                  $matches[4] = str_replace("\\"", "__GESHI_QUOT__", $matches[4]);     
                  return "<" . $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];'), $text);
            /* \n_fckg_NPBBR_\n: the final \n prevents this from iterfering with next in line markups
                  -- in particular tables which require a new line and margin left 
                 this may leave an empty paragraph in the xhtml, which is removed below 
               */
            $text = preg_replace('/<\\/(code|file)>(\\s*)(?=[^\\w])(\\s*)/m', "</\$1>\n_fckg_NPBBR_\n\$2", $text);
            $text = preg_replace_callback('/(\\|\\s*)(<code>|<file>)(.*?)(<\\/code>|<\\/file>)\\n_fckg_NPBBR_(?=.*?\\|)/ms', create_function('$matches', '$matches[2] = preg_replace("/<code>/ms", "TPRE_CODE", $matches[2]); 
                  $matches[2] = preg_replace("/<file>/ms", "TPRE_FILE", $matches[2]);    
                  $matches[4] = "TPRE_CLOSE";                    
                  $matches[3] = preg_replace("/^\\n+/", "TC_NL",$matches[3]);  
                  $matches[3] = preg_replace("/\\n/ms", "TC_NL",$matches[3]);                                   
                  return $matches[1] . $matches[2] .  trim($matches[3]) .   $matches[4];'), $text);
            $text = preg_replace('/TPRE_CLOSE\\s+/ms', "TPRE_CLOSE", $text);
            $text = preg_replace('/<(?!code|file|plugin|del|sup|sub|\\/\\/|\\s|\\/del|\\/code|\\/file|\\/plugin|\\/sup|\\/sub)/ms', "//<//", $text);
            $text = str_replace('%%//<//', '&#37;&#37;&#60;', $text);
            $text = preg_replace_callback('/<plugin(.*?)(?=<\\/plugin>)/ms', create_function('$matches', 'return str_replace("//","", $matches[0]);'), $text);
            $text = str_replace('</plugin>', '</plugin> ', $text);
        }
        if ($this->getConf('duplicate_notes')) {
            $text = preg_replace_callback('/\\(\\(/ms', create_function('$matches', 'static $count = 0;
				   $count++;
				   $ins = "FNoteINSert" . $count;
				   return "(($ins";'), $text);
        }
        $text = str_replace('>>', 'CHEVRONescC', $text);
        $text = str_replace('<<', 'CHEVRONescO', $text);
        $text = preg_replace('/(={3,}.*?)(\\{\\{.*?\\}\\})(.*?={3,})/', "\$1\$3\n\$2", $text);
        $email_regex = '/\\/\\/\\<\\/\\/(.*?@.*?)>/';
        $text = preg_replace($email_regex, "<\$1>", $text);
        $text = preg_replace('/{{(.*)\\.swf(\\s*)}}/ms', "SWF\$1.swf\$2FWS", $text);
        $this->xhtml = $this->_render_xhtml($text);
        $this->xhtml = str_replace("__IWIKI_FSLASH__", "&frasl;", $this->xhtml);
        if ($this->getConf('duplicate_notes')) {
            $this->xhtml = preg_replace("/FNoteINSert\\d+/ms", "", $this->xhtml);
        }
        $this->xhtml = str_replace("__GESHI_QUOT__", '&#34;', $this->xhtml);
        $this->xhtml = str_replace("__GESHI_OPEN__", "&#60; ", $this->xhtml);
        $this->xhtml = str_replace('CHEVRONescC', '>>', $this->xhtml);
        $this->xhtml = str_replace('CHEVRONescO', '<<', $this->xhtml);
        if ($pos !== false) {
            $this->xhtml = preg_replace_callback('/(TPRE_CODE|TPRE_FILE)(.*?)(TPRE_CLOSE)/ms', create_function('$matches', '$matches[1] = preg_replace("/TPRE_CODE/","<pre class=\'code\'>\\n", $matches[1]);  
                    $matches[1] = preg_replace("/TPRE_FILE/","<pre class=\'file\'>\\n", $matches[1]);  
                    $matches[2] = preg_replace("/TC_NL/ms", "\\n", $matches[2]);  
                    $matches[3] = "</pre>";                    
                    return $matches[1] . $matches[2] . $matches[3];'), $this->xhtml);
        }
        $this->xhtml = preg_replace_callback('/(<pre)(.*?)(>)(.*?)(<\\/pre>)/ms', create_function('$matches', '$matches[4] = preg_replace("/(\\||\\^)[ ]+(\\||\\^)/ms","$1 &nbsp; $2" , $matches[4]);                    
                  return  $matches[1] . $matches[2] . $matches[3] . $matches[4] . $matches[5];'), $this->xhtml);
        $cname = getCacheName($INFO['client'] . $ID, '.draft.fckl');
        if (file_exists($cname)) {
            $cdata = unserialize(io_readFile($cname, false));
            $cdata['text'] = urldecode($cdata['text']);
            preg_match_all("/<\\/(.*?)\\>/", $cdata['text'], $matches);
            /* exclude drafts saved from preview mode */
            if (!in_array('code', $matches[1]) && !in_array('file', $matches[1]) && !in_array('nowiki', $matches[1])) {
                $this->draft_text = $cdata['text'];
                $this->draft_found = true;
                msg($fckg_lang['draft_msg']);
            }
            unlink($cname);
        }
        return true;
    }
Example #12
0
 /**
  * @param $fields
  * @param $tpl
  * @param $runas
  * @return string template
  */
 function getTemplates($fields, $tpl, $runas)
 {
     global $USERINFO;
     global $conf;
     if ($tpl == '_') {
         // use namespace template
         if (!isset($this->templates[$this->pagename])) {
             $this->templates[$this->pagename] = pageTemplate(array($this->pagename));
         }
     } elseif ($tpl !== '!') {
         $tpl = $this->replaceDefault($tpl);
         // Namespace link
         if ($runas) {
             // Hack user credentials.
             $backup = array($_SERVER['REMOTE_USER'], $USERINFO['grps']);
             $_SERVER['REMOTE_USER'] = $runas;
             $USERINFO['grps'] = array();
         }
         $t_pages = array();
         search($t_pages, $conf['datadir'], 'search_universal', array('depth' => 0, 'listfiles' => true, 'showhidden' => true), str_replace(':', '/', getNS($tpl)));
         foreach ($t_pages as $t_page) {
             $t_name = cleanID($t_page['id']);
             $p_name = preg_replace('/^' . preg_quote_cb(cleanID($tpl)) . '($|:)/', $this->pagename . '$1', $t_name);
             if ($p_name === $t_name) {
                 // When using a single-page template, ignore other pages
                 // in the same namespace.
                 continue;
             }
             if (!isset($this->templates[$p_name])) {
                 // load page data and do default pattern replacements like
                 // namespace templates do
                 $data = array('id' => $p_name, 'tpl' => rawWiki($t_name), 'doreplace' => true);
                 parsePageTemplate($data);
                 $this->templates[$p_name] = $this->replace(array('__lang__' => $this->patterns['__lang__'], '__trans__' => $this->patterns['__trans__']), array('__lang__' => $this->values['__lang__'], '__trans__' => $this->values['__trans__']), $data['tpl'], false);
             }
         }
         if ($runas) {
             /* Restore user credentials. */
             list($_SERVER['REMOTE_USER'], $USERINFO['grps']) = $backup;
         }
     }
     return $tpl;
 }