Example #1
0
 function EditToolbar()
 {
     global $WikiTheme;
     $this->tokens = array();
     //FIXME: enable Undo button for all other buttons also, not only the search/replace button
     if (JS_SEARCHREPLACE) {
         $this->tokens['JS_SEARCHREPLACE'] = 1;
         $undo_btn = $WikiTheme->getImageURL("ed_undo.png");
         $undo_d_btn = $WikiTheme->getImageURL("ed_undo_d.png");
         // JS_SEARCHREPLACE from walterzorn.de
         $js = Javascript("\nuri_undo_btn   = '" . $undo_btn . "'\nmsg_undo_alt   = '" . _("Undo") . "'\nuri_undo_d_btn = '" . $undo_d_btn . "'\nmsg_undo_d_alt = '" . _("Undo disabled") . "'\nmsg_do_undo    = '" . _("Operation undone") . "'\nmsg_replfound  = '" . _("Substring \"\\1\" found \\2 times. Replace with \"\\3\"?") . "'\nmsg_replnot    = '" . _("String \"%s\" not found.") . "'\nmsg_repl_title     = '" . _("Search & Replace") . "'\nmsg_repl_search    = '" . _("Search for") . "'\nmsg_repl_replace_with = '" . _("Replace with") . "'\nmsg_repl_ok        = '" . _("OK") . "'\nmsg_repl_close     = '" . _("Close") . "'\n");
         if (empty($WikiTheme->_headers_printed)) {
             $WikiTheme->addMoreHeaders($js);
             $WikiTheme->addMoreAttr('body', "SearchReplace", " onload='define_f()'");
         } else {
             // from an actionpage: WikiBlog, AddComment, WikiForum
             printXML($js);
         }
     } else {
         $WikiTheme->addMoreAttr('body', "editfocus", "document.getElementById('edit-content]').editarea.focus()");
     }
     if (ENABLE_EDIT_TOOLBAR) {
         $js = JavaScript('', array('src' => $WikiTheme->_findData("toolbar.js")));
         if (empty($WikiTheme->_headers_printed)) {
             $WikiTheme->addMoreHeaders($js);
         } else {
             // from an actionpage: WikiBlog, AddComment, WikiForum
             printXML($js);
             printXML(JavaScript('define_f()'));
         }
     }
     require_once "lib/WikiPluginCached.php";
     $cache = WikiPluginCached::newCache();
     $dbi = $GLOBALS['request']->getDbh();
     // regenerate if number of pages changes (categories, pages, templates)
     $key = $dbi->numPages();
     $key .= '+categories+plugin' . (isBrowserSafari() ? '+safari' : '');
     if (TOOLBAR_PAGELINK_PULLDOWN) {
         $key .= "+pages";
     }
     if (TOOLBAR_TEMPLATE_PULLDOWN) {
         $key .= "+templates_" . $dbi->getTimestamp();
     }
     $id = $cache->generateId($key);
     $content = $cache->get($id, 'toolbarcache');
     if (!empty($content)) {
         $this->tokens['EDIT_TOOLBAR'] =& $content;
     } else {
         $content = $this->_generate();
         // regenerate buttons every 1 hr/6 hrs
         $cache->save($id, $content, DEBUG ? '+3600' : '+21600', 'toolbarcache');
         $this->tokens['EDIT_TOOLBAR'] =& $content;
     }
 }
Example #2
0
function ConvertAndDisplayPdf(&$request)
{
    global $WikiTheme;
    if (empty($request->_is_buffering_output)) {
        $request->buffer_output(false);
    }
    $pagename = $request->getArg('pagename');
    $dest = $request->getArg('dest');
    // Disable CACHE
    $WikiTheme->DUMP_MODE = true;
    include_once "lib/display.php";
    // TODO: urldecode pagename to get rid of %20 in filename.pdf
    displayPage($request, new Template('htmldump', $request));
    $html = ob_get_contents();
    $WikiTheme->DUMP_MODE = false;
    // check hook for external converters
    if (defined('USE_EXTERNAL_HTML2PDF') and USE_EXTERNAL_HTML2PDF) {
        // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
        // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
        Header('Content-Type: application/pdf');
        $request->discardOutput();
        $request->buffer_output(false);
        require_once "lib/WikiPluginCached.php";
        $cache = new WikiPluginCached();
        $cache->newCache();
        $tmpfile = $cache->tempnam('pdf.html');
        $fp = fopen($tmpfile, "wb");
        fwrite($fp, $html);
        fclose($fp);
        passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile));
        unlink($tmpfile);
    }
    // clean the hints errors
    global $ErrorManager;
    $ErrorManager->destroyPostponedErrors();
    if (!empty($errormsg)) {
        $request->discardOutput();
    }
}
Example #3
0
 function EditToolbar()
 {
     global $WikiTheme;
     $this->tokens = array();
     //FIXME: enable Undo button for all other buttons also, not only the search/replace button
     if (JS_SEARCHREPLACE) {
         $this->tokens['JS_SEARCHREPLACE'] = 1;
         $undo_btn = $WikiTheme->getImageURL("ed_undo.png");
         $undo_d_btn = $WikiTheme->getImageURL("ed_undo_d.png");
         // JS_SEARCHREPLACE from walterzorn.de
         $WikiTheme->addMoreHeaders(Javascript("\nvar f, sr_undo, replacewin, undo_buffer=new Array(), undo_buffer_index=0;\n\nfunction define_f() {\n   f=document.getElementById('editpage');\n   f.editarea=document.getElementById('edit[content]');\n   sr_undo=document.getElementById('sr_undo');\n   undo_enable(false);\n   f.editarea.focus();\n}\nfunction undo_enable(bool) {\n   if (bool) {\n     sr_undo.src='" . $undo_btn . "';\n     sr_undo.alt='" . _("Undo") . "';\n     sr_undo.disabled = false;\n   } else {\n     sr_undo.src='" . $undo_d_btn . "';\n     sr_undo.alt='" . _("Undo disabled") . "';\n     sr_undo.disabled = true;\n     if(sr_undo.blur) sr_undo.blur();\n  }\n}\nfunction replace() {\n   replacewin = window.open('','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,height=90,width=450');\n   replacewin.window.document.write('<html><head><title>" . _("Search & Replace") . "</title><style type=\"text/css\"><'+'!'+'-- body, input {font-family:Tahoma,Arial,Helvetica,sans-serif;font-size:10pt;font-weight:bold;} td {font-size:9pt}  --'+'></style></head><body bgcolor=\"#dddddd\" onload=\"if(document.forms[0].ein.focus) document.forms[0].ein.focus(); return false;\"><form><center><table><tr><td align=\"right\">'+'" . _("Search") . ":</td><td align=\"left\"><input type=\"text\" name=\"ein\" size=\"45\" maxlength=\"500\"></td></tr><tr><td align=\"right\">'+' " . _("Replace with") . ":</td><td align=\"left\"><input type=\"text\" name=\"aus\" size=\"45\" maxlength=\"500\"></td></tr><tr><td colspan=\"2\" align=\"center\"><input type=\"button\" value=\" " . _("OK") . " \" onclick=\"if(self.opener)self.opener.do_replace(); return false;\">&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"" . _("Close") . "\" onclick=\"self.close(); return false;\"></td></tr></table></center></form></body></html>');\n   replacewin.window.document.close();\n   return false;\n}\nfunction do_replace() {\n   var txt=undo_buffer[undo_buffer_index]=f.editarea.value, ein=new RegExp(replacewin.document.forms[0].ein.value,'g'), aus=replacewin.document.forms[0].aus.value;\n   if (ein==''||ein==null) {\n      if (replacewin) replacewin.window.document.forms[0].ein.focus();\n      return;\n   }\n   var z_repl=txt.match(ein)? txt.match(ein).length : 0;\n   txt=txt.replace(ein,aus);\n   ein=ein.toString().substring(1,ein.toString().length-2);\n   result(z_repl, '" . sprintf(_("Substring \"%s\" found %s times. Replace with \"%s\"?"), "'+ein+'", "'+z_repl+'", "'+aus+'") . "', txt, '" . sprintf(_("String \"%s\" not found."), "'+ein+'") . "');\n   replacewin.window.focus();\n   replacewin.window.document.forms[0].ein.focus();\n   return false;\n}\nfunction result(zahl,frage,txt,alert_txt) {\n   if (zahl>0) {\n      if(window.confirm(frage)==true) {\n         f.editarea.value=txt;\n         undo_save();\n         undo_enable(true);\n      }\n   } else alert(alert_txt);\n}\nfunction do_undo() {\n   if(undo_buffer_index==0) return;\n   else if(undo_buffer_index>0) {\n      f.editarea.value=undo_buffer[undo_buffer_index-1];\n      undo_buffer[undo_buffer_index]=null;\n      undo_buffer_index--;\n      if(undo_buffer_index==0) {\n         alert('" . _("Operation undone") . "');\n         undo_enable(false);\n      }\n   }\n}\n//save a snapshot in the undo buffer\nfunction undo_save() {\n   undo_buffer[undo_buffer_index]=f.editarea.value;\n   undo_buffer_index++;\n   undo_enable(true);\n}\n"));
         $WikiTheme->addMoreAttr('body', "SearchReplace", " onload='define_f()'");
     } else {
         $WikiTheme->addMoreAttr('body', "editfocus", "document.getElementById('edit[content]').editarea.focus()");
     }
     if (ENABLE_EDIT_TOOLBAR) {
         $WikiTheme->addMoreHeaders(JavaScript('', array('src' => $WikiTheme->_findData("toolbar.js"))));
     }
     include_once "lib/WikiPluginCached.php";
     $cache = WikiPluginCached::newCache();
     $dbi = $GLOBALS['request']->getDbh();
     // regenerate if number of pages changes (categories, pages, templates)
     $key = $dbi->numPages();
     $key .= '+categories+plugin';
     if (TOOLBAR_PAGELINK_PULLDOWN) {
         $key .= "+pages";
     }
     if (TOOLBAR_TEMPLATE_PULLDOWN) {
         $key .= "+templates_" . $dbi->getTimestamp();
     }
     $id = $cache->generateId($key);
     $content = $cache->get($id, 'toolbarcache');
     if (!empty($content)) {
         $this->tokens['EDIT_TOOLBAR'] =& $content;
     } else {
         $content = $this->_generate();
         // regenerate buttons every 3600 seconds
         $cache->save($id, $content, '+3600', 'toolbarcache');
         $this->tokens['EDIT_TOOLBAR'] =& $content;
     }
 }
Example #4
0
 function getHtml($dbi, $argarray, $request, $basepage)
 {
     $this->run($dbi, WikiPluginCached::glueArgs($argarray), $request, $basepage);
 }
Example #5
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     extract($this->getArgs($argstr, $request));
     $page = $dbi->getPage($pagename);
     $current = $page->getCurrentRevision();
     $source = $current->getPackedContent();
     if (empty($source)) {
         return $this->error(fmt("empty source"));
     }
     if ($basepage == _("SpellCheck")) {
         return $this->error(fmt("Cannot SpellCheck myself"));
     }
     $lang = $page->get('lang');
     if (empty($lang)) {
         $lang = $GLOBALS['LANG'];
     }
     $html = HTML();
     if (!function_exists('pspell_new_config')) {
         // use the aspell commandline interface
         include_once "lib/WikiPluginCached.php";
         $args = "";
         $source = preg_replace("/^/m", "^", $source);
         if (ASPELL_DATA_DIR) {
             $args .= " --data-dir=" . ASPELL_DATA_DIR;
         }
         // MAYBE TODO: do we have the language dictionary?
         $args .= " --lang=" . $lang;
         // use -C or autosplit wikiwords in the text
         $commandLine = ASPELL_EXE . " -a -C {$args} ";
         $cache = new WikiPluginCached();
         $code = $cache->filterThroughCmd($source, $commandLine);
         if (empty($code)) {
             return $this->error(fmt("Couldn't start commandline '%s'", $commandLine));
         }
         $sugg = array();
         foreach (preg_split("/\n/", $code) as $line) {
             if (preg_match("/^& (\\w+) \\d+ \\d+: (.+)\$/", $line, $m)) {
                 $sugg[$m[1]] = preg_split("/, /", $m[2]);
             }
         }
         /*$pre = HTML::pre(HTML::raw($code));
           $html->pushContent($pre);*/
     } else {
         $sugg = pspell_check($source, $lang);
     }
     //$html->pushContent(HTML::hr(),HTML::h1(_("Spellcheck")));
     $page = $request->getPage();
     if ($version) {
         $revision = $page->getRevision($version);
         if (!$revision) {
             NoSuchRevision($request, $page, $version);
         }
     } else {
         $revision = $page->getCurrentRevision();
     }
     $GLOBALS['request']->setArg('suggestions', $sugg);
     include_once "lib/BlockParser.php";
     $ori_html = TransformText($revision, $revision->get('markup'), $page);
     $GLOBALS['request']->setArg('suggestions', false);
     $html->pushContent($ori_html, HTML::hr(), HTML::h1(_("SpellCheck result")));
     $list = HTML::ul();
     foreach ($sugg as $word => $suggs) {
         $w = HTML::span(array('class' => 'spell-wrong'), $word);
         // TODO: optional replace-link. jscript or request button with word replace.
         $r = HTML();
         foreach ($suggs as $s) {
             $r->pushContent(HTML::a(array('class' => 'spell-sugg', 'href' => "javascript:do_replace('{$word}','{$s}')"), $s), ", ");
         }
         $list->pushContent(HTML::li($w, ": ", $r));
     }
     $html->pushContent($list);
     return $html;
 }
Example #6
0
 /**
  * static workaround on broken Cache or broken dot executable,
  * called only if debug=static.
  *
  * @access private
  * @param  url      string  url pointing to the image part of the map
  * @param  map      string  &lt;area&gt; tags defining active
  *                          regions in the map
  * @param  dbi      WikiDB  database abstraction class
  * @param  argarray array   complete (!) arguments to produce
  *                          image. It is not necessary to call
  *                          WikiPlugin->getArgs anymore.
  * @param  request  Request ???
  * @return          string  html output
  */
 function embedImg($url, &$dbi, $argarray, &$request)
 {
     if (!VISUALWIKI_ALLOWOPTIONS) {
         $argarray = $this->defaultarguments();
     }
     $this->checkArguments($argarray);
     //extract($argarray);
     if ($argarray['help']) {
         return array($this->helpImage(), ' ');
     }
     // FIXME
     $this->createColors();
     $this->extract_wikipages($dbi, $argarray);
     list($imagehandle, $content['html']) = $this->invokeDot($argarray);
     // write to uploads and produce static url
     $file_dir = getUploadFilePath();
     $upload_dir = getUploadDataPath();
     $tmpfile = tempnam($file_dir, "VisualWiki") . "." . $argarray['imgtype'];
     WikiPluginCached::writeImage($argarray['imgtype'], $imagehandle, $tmpfile);
     ImageDestroy($imagehandle);
     return WikiPluginCached::embedMap(1, $upload_dir . basename($tmpfile), $content['html'], $dbi, $argarray, $request);
 }
Example #7
0
/**
 * Initializes PhpWiki and calls the plugin specified in the url to
 * produce an image. Furthermore, allow the usage of Apache's
 * ErrorDocument mechanism in order to make this file only called when 
 * image could not be found in the cache.
 * (see doc/README.phpwiki-cache for further information).
 */
function mainImageCache()
{
    $request = new Request();
    // normalize pagename
    $request->setArg('pagename', deducePagename($request));
    $pagename = $request->getArg('pagename');
    $request->_dbi = WikiDB::open($GLOBALS['DBParams']);
    if (ENABLE_USER_NEW) {
        $request->_user = new _AnonUser();
        $request->_prefs =& $request->_user->_prefs;
    } else {
        $request->_user = new WikiUser($request);
        $request->_prefs = new UserPreferences();
    }
    // Enable the output of most of the warning messages.
    // The warnings will screw up zip files and setpref though.
    // They will also screw up my images... But I think
    // we should keep them.
    global $ErrorManager;
    $ErrorManager->setPostponedErrorMask(E_NOTICE | E_USER_NOTICE);
    $id = $request->getArg('id');
    $args = $request->getArg('args');
    $request->setArg('action', 'imagecache');
    $cache = new WikiPluginCached();
    if ($id) {
        // this indicates a direct call (script wasn't called as
        // 404 ErrorDocument)
    } else {
        // deduce image id or image args (plugincall) from
        // refering URL
        $uri = $request->get('REDIRECT_URL');
        $query = $request->get('REDIRECT_QUERY_STRING');
        $uri .= $query ? '?' . $query : '';
        if (!$uri) {
            $uri = $request->get('REQUEST_URI');
        }
        if (!$uri) {
            $cache->printError('png', 'Could not deduce image identifier or creation' . ' parameters. (Neither REQUEST nor REDIRECT' . ' obtained.)');
            return;
        }
        //$cacheparams = $GLOBALS['CacheParams'];
        if (!preg_match(':^(.*/)?' . PLUGIN_CACHED_FILENAME_PREFIX . '([^\\?/]+)\\.img(\\?args=([^\\?&]*))?$:', $uri, $matches)) {
            $cache->printError('png', "I do not understand this URL: {$uri}");
            return;
        }
        $request->setArg('id', $matches[2]);
        if ($matches[4]) {
            // md5 args?
            $request->setArg('args', rawurldecode($matches[4]));
        }
        $request->setStatus(200);
        // No, we do _not_ have an Error 404 :->
    }
    $cache->fetchImageFromCache($request->_dbi, $request, 'png');
}
 function getHtml($dbi, $argarray, $request, $basepage)
 {
     $loader = new WikiPluginLoader();
     return $loader->expandPI('<?plugin RecentChanges ' . WikiPluginCached::glueArgs($argarray) . ' ?>', $request, $this, $basepage);
 }
Example #9
0
 /** 
  * static workaround on broken Cache or broken dot executable, 
  * called only if debug=static.
  *
  * @access private
  * @param  url      string  url pointing to the image part of the map
  * @param  map      string  &lt;area&gt; tags defining active
  *                          regions in the map
  * @param  dbi      WikiDB  database abstraction class
  * @param  argarray array   complete (!) arguments to produce 
  *                          image. It is not necessary to call 
  *                          WikiPlugin->getArgs anymore.
  * @param  request  Request ??? 
  * @return          string  html output
  */
 function embedImg($url, &$dbi, $argarray, &$request)
 {
     if (!VISUALWIKI_ALLOWOPTIONS) {
         $argarray = $this->defaultarguments();
     }
     $this->checkArguments($argarray);
     //extract($argarray);
     if ($argarray['help']) {
         return array($this->helpImage(), ' ');
     }
     // FIXME
     $this->createColors();
     $this->extract_wikipages($dbi, $argarray);
     list($imagehandle, $content['html']) = $this->invokeDot($argarray);
     // write to uploads and produce static url
     $file_dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR . "/uploads" : "uploads";
     $upload_dir = SERVER_URL . (substr(DATA_PATH, 0, 1) == '/' ? '' : "/") . DATA_PATH . '/uploads/';
     $tmpfile = tempnam($file_dir, "VisualWiki") . "." . $argarray['imgtype'];
     WikiPluginCached::writeImage($argarray['imgtype'], $imagehandle, $tmpfile);
     ImageDestroy($imagehandle);
     return WikiPluginCached::embedMap(1, $upload_dir . basename($tmpfile), $content['html'], $dbi, $argarray, $request);
 }
Example #10
0
function ConvertAndDisplayPdf(&$request)
{
    if (empty($request->_is_buffering_output)) {
        $request->buffer_output(false);
    }
    $pagename = $request->getArg('pagename');
    $dest = $request->getArg('dest');
    //TODO: inline cached content: /getimg.php? => image.png
    // Disable CACHE
    include_once "lib/display.php";
    displayPage($request);
    $html = ob_get_contents();
    // check hook for external converters
    if (defined('USE_EXTERNAL_HTML2PDF') and USE_EXTERNAL_HTML2PDF) {
        // See http://phpwiki.sourceforge.net/phpwiki/PhpWikiToDocBookAndPDF
        // htmldoc or ghostscript + html2ps or docbook (dbdoclet, xsltproc, fop)
        $request->discardOutput();
        $request->buffer_output(false);
        require_once "lib/WikiPluginCached.php";
        $cache = new WikiPluginCached();
        $cache->newCache();
        $tmpfile = $cache->tempnam();
        $fp = fopen($tmpfile, "wb");
        fwrite($fp, $html);
        fclose($fp);
        Header('Content-Type: application/pdf');
        passthru(sprintf(USE_EXTERNAL_HTML2PDF, $tmpfile));
        unlink($tmpfile);
    } else {
        // use fpdf:
        if ($GLOBALS['LANG'] == 'ja') {
            include_once "lib/fpdf/japanese.php";
            $pdf = new PDF_Japanese();
        } elseif ($GLOBALS['LANG'] == 'zh') {
            include_once "lib/fpdf/chinese.php";
            $pdf = new PDF_Chinese();
        } else {
            $pdf = new PDF();
        }
        $pdf->Open();
        $pdf->AddPage();
        $pdf->ConvertFromHTML($html);
        $request->discardOutput();
        $request->buffer_output(false);
        $pdf->Output($pagename . ".pdf", $dest ? $dest : 'I');
    }
    if (!empty($errormsg)) {
        $request->discardOutput();
    }
}
Example #11
0
 function discspace()
 {
     global $DBParams, $request;
     include_once "lib/WikiPluginCached.php";
     $cache = WikiPluginCached::newCache();
     $id = $cache->generateId('SystemInfo::discspace');
     $cachedir = 'plugincache';
     $content = $cache->get($id, $cachedir);
     if (empty($content)) {
         $dir = defined('PHPWIKI_DIR') ? PHPWIKI_DIR : '.';
         //TODO: windows only (no cygwin)
         $appsize = `du -s {$dir} | cut -f1`;
         if (in_array($DBParams['dbtype'], array('SQL', 'ADODB'))) {
             //TODO: where is the data is actually stored? see phpMyAdmin
             $pagesize = 0;
         } elseif ($DBParams['dbtype'] == 'dba') {
             $pagesize = 0;
             $dbdir = $DBParams['directory'];
             if ($DBParams['dba_handler'] == 'db3') {
                 $pagesize = filesize($DBParams['directory'] . "/wiki_pagedb.db3") / 1024;
             }
             // if issubdirof($dbdir, $dir) $appsize -= $pagesize;
         } else {
             // flatfile, cvs
             $dbdir = $DBParams['directory'];
             $pagesize = `du -s {$dbdir}`;
             // if issubdirof($dbdir, $dir) $appsize -= $pagesize;
         }
         $content = array('appsize' => $appsize, 'pagesize' => $pagesize);
         // regenerate cache every 30 minutes
         $cache->save($id, $content, '+1800', $cachedir);
     } else {
         $appsize = $content['appsize'];
         $pagesize = $content['pagesize'];
     }
     $s = sprintf(_("Application size: %d Kb"), $appsize);
     if ($pagesize) {
         $s .= ", " . sprintf(_("Pagedata size: %d Kb", $pagesize));
     }
     return $s;
 }