Beispiel #1
0
function ParseAndLink($bracketlink) {
      global $ScriptUrl, $AllowedProtocols, $InlineImages;
           
      preg_match("/(\[\s*)(.+?)(\s*\])/", $bracketlink, $match);
      
      preg_match("/([^|]+)(\|)?([^|]+)?/", $match[2], $matches);

      if (isset($matches[3])) {
         
         $URL = trim($matches[3]);
         $linkname = htmlspecialchars(trim($matches[1]));
     $linktype = 'named';
      } else {
         
         $URL = trim($matches[1]);
     $linkname = '';
     $linktype = 'simple';
      }

      if (preg_match("#^($AllowedProtocols):#", $URL)) {
        // if it's an image, embed it; otherwise, it's a regular link
         if (preg_match("/($InlineImages)$/i", $URL)) {
        $link['type'] = "image-$linktype";
            $link['link'] = LinkImage($URL, $linkname);
         } else {
        $link['type'] = "url-$linktype";
            $link['link'] = LinkURL($URL, $linkname);
         }
      } elseif (preg_match("#^\d+$#", $URL)) {
         $link['type'] = "reference-$linktype";
     $link['link'] = $URL;
      } else {
     $link['type'] = "wiki-unknown-$linktype";
         $link['link'] = LinkUnknown($URL, $linkname);
      }

      return $link;
   }
Beispiel #2
0
/**
 * Dump all pages as XHTML to a directory, as pagename.html.
 * Copies all used css files to the directory, all used images to a 
 * "images" subdirectory, and all used buttons to a "images/buttons" subdirectory.
 * The webserver must have write permissions to these directories. 
 *   chown httpd HTML_DUMP_DIR; chmod u+rwx HTML_DUMP_DIR 
 * should be enough.
 *
 * @param string directory (optional) path to dump to. Default: HTML_DUMP_DIR
 * @param string pages     (optional) Comma-seperated of glob-style pagenames to dump
 * @param string exclude   (optional) Comma-seperated of glob-style pagenames to exclude
 */
function DumpHtmlToDir(&$request)
{
    $directory = $request->getArg('directory');
    if (empty($directory)) {
        $directory = HTML_DUMP_DIR;
    }
    // See lib/plugin/WikiForm.php:87
    if (empty($directory)) {
        $request->finish(_("You must specify a directory to dump to"));
    }
    // see if we can access the directory the user wants us to use
    if (!file_exists($directory)) {
        if (!mkdir($directory, 0755)) {
            $request->finish(fmt("Cannot create directory '%s'", $directory));
        } else {
            $html = HTML::p(fmt("Created directory '%s' for the page dump...", $directory));
        }
    } else {
        $html = HTML::p(fmt("Using directory '%s'", $directory));
    }
    $request->_TemplatesProcessed = array();
    StartLoadDump($request, _("Dumping Pages"), $html);
    $thispage = $request->getArg('pagename');
    // for "Return to ..."
    $dbi =& $request->_dbi;
    if ($exclude = $request->getArg('exclude')) {
        // exclude which pagenames
        $excludeList = explodePageList($exclude);
    } else {
        $excludeList = array();
    }
    if ($pages = $request->getArg('pages')) {
        // which pagenames
        if ($pages == '[]') {
            // current page
            $pages = $thispage;
        }
        $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages));
        // not at admin page: dump only the current page
    } elseif ($thispage != _("PhpWikiAdministration")) {
        $page_iter = new WikiDB_Array_PageIterator(array($thispage));
    } else {
        $page_iter = $dbi->getAllPages(false, false, false, $excludeList);
    }
    global $WikiTheme;
    if (defined('HTML_DUMP_SUFFIX')) {
        $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
    }
    $WikiTheme->DUMP_MODE = 'HTML';
    $_bodyAttr = @$WikiTheme->_MoreAttr['body'];
    unset($WikiTheme->_MoreAttr['body']);
    // check if the dumped file will be accessible from outside
    $doc_root = $request->get("DOCUMENT_ROOT");
    $ldir = NormalizeLocalFileName($directory);
    $wikiroot = NormalizeLocalFileName('');
    if (string_starts_with($ldir, $doc_root)) {
        $link_prefix = substr($directory, strlen($doc_root)) . "/";
    } elseif (string_starts_with($ldir, $wikiroot)) {
        $link_prefix = NormalizeWebFileName(substr($directory, strlen($wikiroot))) . "/";
    } else {
        $prefix = '';
        if (isWindows()) {
            $prefix = '/' . substr($doc_root, 0, 2);
            // add drive where apache is installed
        }
        $link_prefix = "file://" . $prefix . $directory . "/";
    }
    $request_args = $request->args;
    $timeout = !$request->getArg('start_debug') ? 20 : 240;
    while ($page = $page_iter->next()) {
        $request->args = $request_args;
        // some plugins might change them (esp. on POST)
        longer_timeout($timeout);
        // Reset watchdog
        $pagename = $page->getName();
        if (!isa($request, 'MockRequest')) {
            PrintXML(HTML::br(), $pagename, ' ... ');
            flush();
        }
        if (in_array($pagename, $excludeList)) {
            if (!isa($request, 'MockRequest')) {
                PrintXML(_("Skipped."));
                flush();
            }
            continue;
        }
        $request->setArg('pagename', $pagename);
        // Template::_basepage fix
        $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
        $msg = HTML();
        $revision = $page->getCurrentRevision();
        $template = new Template('browse', $request, array('revision' => $revision, 'CONTENT' => $revision->getTransformedContent()));
        $data = GeneratePageasXML($template, $pagename);
        if (!($fd = fopen($directory . "/" . $filename, "wb"))) {
            $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing", "{$directory}/{$filename}")));
            $request->finish($msg);
        }
        $num = fwrite($fd, $data, strlen($data));
        if ($page->getName() != $filename) {
            $link = LinkURL($link_prefix . $filename, $filename);
            $msg->pushContent(HTML::small(_("saved as "), $link, " ... "));
        }
        $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n"));
        if (!isa($request, 'MockRequest')) {
            PrintXML($msg);
        }
        flush();
        $request->chunkOutput();
        assert($num == strlen($data));
        fclose($fd);
        if (USECACHE) {
            $request->_dbi->_cache->invalidate_cache($pagename);
            unset($request->_dbi->_cache->_pagedata_cache);
            unset($request->_dbi->_cache->_versiondata_cache);
            unset($request->_dbi->_cache->_glv_cache);
        }
        unset($request->_dbi->_cache->_backend->_page_data);
        unset($msg);
        unset($revision->_transformedContent);
        unset($revision);
        unset($template->_request);
        unset($template);
        unset($data);
    }
    $page_iter->free();
    if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
        @mkdir("{$directory}/images");
        foreach ($WikiTheme->dumped_images as $img_file) {
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                $target = "{$directory}/images/" . basename($img_file);
                if (copy($WikiTheme->_path . $from, $target)) {
                    _copyMsg($from, fmt("... copied to %s", $target));
                } else {
                    _copyMsg($from, fmt("... not copied to %s", $target));
                }
            } else {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
        // Buttons also
        @mkdir("{$directory}/images/buttons");
        foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                $target = "{$directory}/images/buttons/" . basename($img_file);
                if (copy($WikiTheme->_path . $from, $target)) {
                    _copyMsg($from, fmt("... copied to %s", $target));
                } else {
                    _copyMsg($from, fmt("... not copied to %s", $target));
                }
            } else {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
        foreach ($WikiTheme->dumped_css as $css_file) {
            if ($css_file and $from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) {
                $target = "{$directory}/" . basename($css_file);
                if (copy($WikiTheme->_path . $from, $target)) {
                    _copyMsg($from, fmt("... copied to %s", $target));
                } else {
                    _copyMsg($from, fmt("... not copied to %s", $target));
                }
            } else {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    $WikiTheme->HTML_DUMP_SUFFIX = '';
    $WikiTheme->DUMP_MODE = false;
    $WikiTheme->_MoreAttr['body'] = $_bodyAttr;
    $request->setArg('pagename', $thispage);
    // Template::_basepage fix
    EndLoadDump($request);
}
Beispiel #3
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $args = $this->getArgs($argstr, $request);
     extract($args);
     if (!$src) {
         return $this->error(fmt("%s parameter missing", "'src'"));
     }
     // FIXME: Better recursion detection.
     // FIXME: Currently this doesnt work at all.
     if ($src == $request->getURLtoSelf()) {
         return $this->error(fmt("recursive inclusion of url %s", $src));
     }
     if (!IsSafeURL($src)) {
         return $this->error(_("Bad url in src: remove all of <, >, \""));
     }
     $params = array('title' => _("Transcluded page"), 'src' => $src, 'width' => "100%", 'height' => $height, 'marginwidth' => 0, 'marginheight' => 0, 'class' => 'transclude', "onload" => "adjust_iframe_height(this);");
     $noframe_msg[] = fmt("See: %s", HTML::a(array('href' => $src), $src));
     $noframe_msg = HTML::div(array('class' => 'transclusion'), HTML::p(array(), $noframe_msg));
     $iframe = HTML::div(HTML::iframe($params, $noframe_msg));
     /* This doesn't work very well...  maybe because CSS screws up NS4 anyway...
        $iframe = new HtmlElement('ilayer', array('src' => $src), $iframe);
        */
     return HTML(HTML::p(array('class' => 'transclusion-title'), fmt("Transcluded from %s", LinkURL($src))), $this->_js(), $iframe);
 }
Beispiel #4
0
function _DumpHtmlToDir($target, $page_iter, $exclude = false)
{
    global $WikiTheme, $request, $ErrorManager;
    $silent = true;
    $zip = false;
    $directory = false;
    if ($WikiTheme->DUMP_MODE == 'HTML') {
        $directory = $target;
        $silent = false;
    } elseif ($WikiTheme->DUMP_MODE == 'PDFHTML') {
        $directory = $target;
    } elseif (is_object($target)) {
        // $WikiTheme->DUMP_MODE == 'ZIPHTML'
        $zip = $target;
    }
    $request->_TemplatesProcessed = array();
    if ($exclude) {
        // exclude which pagenames
        $excludeList = explodePageList($exclude);
    } else {
        $excludeList = array('DebugAuthInfo', 'DebugGroupInfo', 'AuthInfo');
    }
    $WikiTheme->VALID_LINKS = array();
    if ($request->getArg('format')) {
        // pagelist
        $page_iter_sav = $page_iter;
        foreach ($page_iter_sav->asArray() as $handle) {
            $WikiTheme->VALID_LINKS[] = is_string($handle) ? $handle : $handle->getName();
        }
        $page_iter_sav->reset();
    }
    if (defined('HTML_DUMP_SUFFIX')) {
        $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX;
    }
    $_bodyAttr = @$WikiTheme->_MoreAttr['body'];
    unset($WikiTheme->_MoreAttr['body']);
    $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler'));
    // check if the dumped file will be accessible from outside
    $doc_root = $request->get("DOCUMENT_ROOT");
    if ($WikiTheme->DUMP_MODE == 'HTML') {
        $ldir = NormalizeLocalFileName($directory);
        $wikiroot = NormalizeLocalFileName('');
        if (string_starts_with($ldir, $doc_root)) {
            $link_prefix = substr($directory, strlen($doc_root)) . "/";
        } elseif (string_starts_with($ldir, $wikiroot)) {
            $link_prefix = NormalizeWebFileName(substr($directory, strlen($wikiroot))) . "/";
        } else {
            $prefix = '';
            if (isWindows()) {
                $prefix = '/';
                // . substr($doc_root,0,2); // add drive where apache is installed
            }
            $link_prefix = "file://" . $prefix . $directory . "/";
        }
    } else {
        $link_prefix = "";
    }
    $request_args = $request->args;
    $timeout = !$request->getArg('start_debug') ? 60 : 240;
    if ($directory) {
        if (isWindows()) {
            $directory = str_replace("\\", "/", $directory);
        }
        // no Win95 support.
        @mkdir("{$directory}/images");
    }
    $already = array();
    $outfiles = array();
    $already_images = array();
    while ($page = $page_iter->next()) {
        if (is_string($page)) {
            $pagename = $page;
            $page = $request->_dbi->getPage($pagename);
        } else {
            $pagename = $page->getName();
        }
        if (empty($firstpage)) {
            $firstpage = $pagename;
        }
        if (array_key_exists($pagename, $already)) {
            continue;
        }
        $already[$pagename] = 1;
        $current = $page->getCurrentRevision();
        //if ($current->getVersion() == 0)
        //    continue;
        $request->args = $request_args;
        // some plugins might change them (esp. on POST)
        longer_timeout($timeout);
        // Reset watchdog
        if ($zip) {
            $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1);
            if ($page->get('locked')) {
                $attrib['write_protected'] = 1;
            }
        } elseif (!$silent) {
            if (!isa($request, 'MockRequest')) {
                PrintXML(HTML::br(), $pagename, ' ... ');
                flush();
            }
        }
        if (in_array($pagename, $excludeList)) {
            if (!$silent and !isa($request, 'MockRequest')) {
                PrintXML(_("Skipped."));
                flush();
            }
            continue;
        }
        $relative_base = '';
        if ($WikiTheme->DUMP_MODE == 'PDFHTML') {
            $request->setArg('action', 'pdf');
        }
        // to omit cache headers
        $request->setArg('pagename', $pagename);
        // Template::_basepage fix
        $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX;
        $args = array('revision' => $current, 'CONTENT' => $current->getTransformedContent(), 'relative_base' => $relative_base);
        // For every %2F will need to mkdir -p dirname($pagename)
        if (preg_match("/(%2F|\\/)/", $filename)) {
            // mkdir -p and set relative base for subdir pages
            $filename = preg_replace("/%2F/", "/", $filename);
            $count = substr_count($filename, "/");
            $dirname = dirname($filename);
            if ($directory) {
                mkdir_p($directory . "/" . $dirname);
            }
            // Fails with "XX / YY", "XX" is created, "XX / YY" cannot be written
            // if (isWindows()) // interesting Windows bug: cannot mkdir "bla "
            // Since dumps needs to be copied, we have to disallow this for all platforms.
            $filename = preg_replace("/ \\//", "/", $filename);
            $relative_base = "../";
            while ($count > 1) {
                $relative_base .= "../";
                $count--;
            }
            $args['relative_base'] = $relative_base;
        }
        $msg = HTML();
        $DUMP_MODE = $WikiTheme->DUMP_MODE;
        $data = GeneratePageasXML(new Template('browse', $request, $args), $pagename, $current, $args);
        $WikiTheme->DUMP_MODE = $DUMP_MODE;
        if (preg_match_all("/<img .*?src=\"(\\/.+?)\"/", $data, $m)) {
            // fix to local relative path for uploaded images, so that pdf will work
            foreach ($m[1] as $img_file) {
                $base = basename($img_file);
                $data = str_replace('src="' . $img_file . '"', 'src="images/' . $base . '"', $data);
                if (array_key_exists($img_file, $already_images)) {
                    continue;
                }
                $already_images[$img_file] = 1;
                // resolve src from webdata to file
                $src = $doc_root . $img_file;
                if (file_exists($src) and $base) {
                    if ($directory) {
                        $target = "{$directory}/images/{$base}";
                        if (copy($src, $target)) {
                            if (!$silent) {
                                _copyMsg($img_file, fmt("... copied to %s", $target));
                            }
                        } else {
                            if (!$silent) {
                                _copyMsg($img_file, fmt("... not copied to %s", $target));
                            }
                        }
                    } else {
                        $target = "images/{$base}";
                        $zip->addSrcFile($target, $src);
                    }
                }
            }
        }
        if ($directory) {
            $outfile = $directory . "/" . $filename;
            if (!($fd = fopen($outfile, "wb"))) {
                $msg->pushContent(HTML::strong(fmt("couldn't open file '%s' for writing", $outfile)));
                $request->finish($msg);
            }
            $len = strlen($data);
            $num = fwrite($fd, $data, $len);
            if ($pagename != $filename) {
                $link = LinkURL($link_prefix . $filename, $filename);
                $msg->pushContent(HTML::small(_("saved as "), $link, " ... "));
            }
            $msg->pushContent(HTML::small(fmt("%s bytes written", $num), "\n"));
            if (!$silent) {
                if (!isa($request, 'MockRequest')) {
                    PrintXML($msg);
                }
                flush();
                $request->chunkOutput();
            }
            assert($num == $len);
            fclose($fd);
            $outfiles[] = $outfile;
        } else {
            $zip->addRegularFile($filename, $data, $attrib);
        }
        if (USECACHE) {
            $request->_dbi->_cache->invalidate_cache($pagename);
            unset($request->_dbi->_cache->_pagedata_cache);
            unset($request->_dbi->_cache->_versiondata_cache);
            unset($request->_dbi->_cache->_glv_cache);
        }
        unset($request->_dbi->_cache->_backend->_page_data);
        unset($msg);
        unset($current->_transformedContent);
        unset($current);
        if (!empty($template)) {
            unset($template->_request);
            unset($template);
        }
        unset($data);
    }
    $page_iter->free();
    $attrib = false;
    //array('is_ascii' => 0);
    if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) {
        // @mkdir("$directory/images");
        foreach ($WikiTheme->dumped_images as $img_file) {
            if (array_key_exists($img_file, $already_images)) {
                continue;
            }
            $already_images[$img_file] = 1;
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                if ($directory) {
                    $target = "{$directory}/images/" . basename($from);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    $target = "images/" . basename($from);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) {
        // Buttons also
        if ($directory) {
            @mkdir("{$directory}/images/buttons");
        }
        foreach ($WikiTheme->dumped_buttons as $text => $img_file) {
            if (array_key_exists($img_file, $already_images)) {
                continue;
            }
            $already_images[$img_file] = 1;
            if ($img_file and $from = $WikiTheme->_findFile($img_file, true) and basename($from)) {
                if ($directory) {
                    $target = "{$directory}/images/buttons/" . basename($from);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    $target = "images/buttons/" . basename($from);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) {
        foreach ($WikiTheme->dumped_css as $css_file) {
            if (array_key_exists($css_file, $already_images)) {
                continue;
            }
            $already_images[$css_file] = 1;
            if ($css_file and $from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) {
                // TODO: fix @import url(main.css);
                if ($directory) {
                    $target = "{$directory}/" . basename($css_file);
                    if ($silent) {
                        copy($WikiTheme->_path . $from, $target);
                    } else {
                        if (copy($WikiTheme->_path . $from, $target)) {
                            _copyMsg($from, fmt("... copied to %s", $target));
                        } else {
                            _copyMsg($from, fmt("... not copied to %s", $target));
                        }
                    }
                } else {
                    //$attrib = array('is_ascii' => 0);
                    $target = basename($css_file);
                    $zip->addSrcFile($target, $WikiTheme->_path . $from);
                }
            } elseif (!$silent) {
                _copyMsg($from, _("... not found"));
            }
        }
    }
    if ($zip) {
        $zip->finish();
    }
    if ($WikiTheme->DUMP_MODE == 'PDFHTML') {
        if (USE_EXTERNAL_HTML2PDF and $outfiles) {
            $cmd = EXTERNAL_HTML2PDF_PAGELIST . ' "' . join('" "', $outfiles) . '"';
            $filename = FilenameForPage($firstpage);
            if (DEBUG) {
                $tmpfile = $directory . "/createpdf.bat";
                $fp = fopen($tmpfile, "wb");
                fwrite($fp, $cmd . " > {$filename}.pdf");
                fclose($fp);
            }
            if (!headers_sent()) {
                Header('Content-Type: application/pdf');
                passthru($cmd);
            } else {
                $tmpdir = getUploadFilePath();
                $s = passthru($cmd . " > {$tmpdir}/{$filename}.pdf");
                $errormsg = "<br />\nGenerated <a href=\"" . getUploadDataPath() . "{$filename}.pdf\">Upload:{$filename}.pdf</a>\n";
                $errormsg .= $s;
                echo $errormsg;
            }
            if (!DEBUG) {
                foreach ($outfiles as $f) {
                    unlink($f);
                }
            }
        }
        if (!empty($errormsg)) {
            $request->discardOutput();
            $GLOBALS['ErrorManager']->_postponed_errors = array();
        }
    }
    $ErrorManager->popErrorHandler();
    $WikiTheme->HTML_DUMP_SUFFIX = '';
    $WikiTheme->DUMP_MODE = false;
    $WikiTheme->_MoreAttr['body'] = $_bodyAttr;
}
Beispiel #5
0
 function _getValue(&$page, $revision_handle)
 {
     $html = false;
     $pagename = $page->getName();
     $count = count($this->parentobj->_wpagelist[$pagename]);
     return LinkURL(WikiURL($page, array('action' => 'BackLinks'), false), fmt("(%d Links)", $count));
 }
Beispiel #6
0
 function expand($basepage, &$markup)
 {
     global $request;
     $label = isset($this->_label) ? $this->_label : false;
     $link = LinkURL($this->_url, $label);
     if (GOOGLE_LINKS_NOFOLLOW) {
         // Ignores nofollow when the user who saved the page was authenticated.
         $page = $request->getPage($basepage);
         $current = $page->getCurrentRevision(false);
         if (!$current->get('author_id')) {
             $link->setAttr('rel', 'nofollow');
         }
     }
     return $link;
 }
Beispiel #7
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     $args = $this->getArgs($argstr, $request);
     //        if (empty($args['s']))
     //    return '';
     $html = HTML();
     extract($args);
     // prevent from dump
     if ($q and $request->isPost()) {
         require_once "lib/Google.php";
         $google = new Google();
         if (!$google) {
             return '';
         }
         switch ($mode) {
             case 'search':
                 $result = $google->doGoogleSearch($q);
                 break;
             case 'cache':
                 $result = $google->doGetCachedPage($q);
                 break;
             case 'spell':
                 $result = $google->doSpellingSuggestion($q);
                 break;
             default:
                 trigger_error("Invalid mode");
         }
         if (isa($result, 'HTML')) {
             $html->pushContent($result);
         }
         if (isa($result, 'GoogleSearchResults')) {
             //TODO: result template
             if (!empty($result->resultElements)) {
                 $list = HTML::ol();
                 foreach ($result->resultElements as $res) {
                     $li = HTML::li(LinkURL($res['URL'], $res['directoryTitle']), HTML::br(), $res['directoryTitle'] ? HTML(HTML::raw('&nbsp;&nbsp;'), HTML::em($res['summary']), ' -- ', LinkURL($res['URL'])) : '');
                     $list->pushContent($li);
                 }
                 $html->pushContent($list);
             } else {
                 return _("Nothing found");
             }
         }
         if (is_string($result)) {
             // cache content also?
             $html->pushContent(HTML::blockquote(HTML::raw($result)));
         }
     }
     if ($formsize < 1) {
         $formsize = 30;
     }
     // todo: template
     $form = HTML::form(array('action' => $request->getPostURL(), 'method' => 'post', 'accept-charset' => $GLOBALS['charset']), HiddenInputs(array('pagename' => $basepage, 'mode' => $mode)));
     $form->pushContent(HTML::input(array('type' => 'text', 'value' => $q, 'name' => 'q', 'size' => $formsize)));
     $form->pushContent(HTML::input(array('type' => 'submit', 'class' => 'button', 'value' => gettext($mode))));
     return HTML($html, $form);
 }
Beispiel #8
0
 $tmpline = tokenize($tmpline, '\\[.+?\\]', $replacements, $ntokens);
 while ($oldn < $ntokens) {
     $link = ParseAndLink($replacements[$oldn]);
     $replacements[$oldn] = $link['link'];
     $oldn++;
 }
 //////////////////////////////////////////////////////////
 // replace all URL's with tokens, so we don't confuse them
 // with Wiki words later. Wiki words in URL's break things.
 // URLs preceeded by a '!' are not linked
 $tmpline = tokenize($tmpline, "!?\\b({$AllowedProtocols}):[^\\s<>\\[\\]\"'()]*[^\\s<>\\[\\]\"'(),.?]", $replacements, $ntokens);
 while ($oldn < $ntokens) {
     if ($replacements[$oldn][0] == '!') {
         $replacements[$oldn] = substr($replacements[$oldn], 1);
     } else {
         $replacements[$oldn] = LinkURL($replacements[$oldn]);
     }
     $oldn++;
 }
 //////////////////////////////////////////////////////////
 // Link Wiki words
 // Wikiwords preceeded by a '!' are not linked
 $oldn = $ntokens;
 $tmpline = tokenize($tmpline, "!?{$WikiNameRegexp}", $replacements, $ntokens);
 while ($oldn < $ntokens) {
     $old = $replacements[$oldn];
     if ($old[0] == '!') {
         $replacements[$oldn] = substr($old, 1);
     } elseif (IsWikiPage($dbi, $old)) {
         $replacements[$oldn] = LinkExistingWikiWord($old);
     } else {
Beispiel #9
0
function ParseAndLink($bracketlink)
{
    global $dbi, $ScriptUrl, $AllowedProtocols, $InlineImages;
    // $bracketlink will start and end with brackets; in between
    // will be either a page name, a URL or both separated by a pipe.
    // strip brackets and leading space
    preg_match("/(\\[\\s*)(.+?)(\\s*\\])/", $bracketlink, $match);
    // match the contents
    preg_match("/([^|]+)(\\|)?([^|]+)?/", $match[2], $matches);
    if (isset($matches[3])) {
        // named link of the form  "[some link name | http://blippy.com/]"
        $URL = trim($matches[3]);
        $linkname = htmlspecialchars(trim($matches[1]));
        $linktype = 'named';
    } else {
        // unnamed link of the form "[http://blippy.com/] or [wiki page]"
        $URL = trim($matches[1]);
        $linkname = '';
        $linktype = 'simple';
    }
    if (IsWikiPage($dbi, $URL)) {
        $link['type'] = "wiki-{$linktype}";
        $link['link'] = LinkExistingWikiWord($URL, $linkname);
    } elseif (preg_match("#^({$AllowedProtocols}):#", $URL)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (preg_match("/({$InlineImages})\$/i", $URL)) {
            $link['type'] = "image-{$linktype}";
            $link['link'] = LinkImage($URL, $linkname);
        } else {
            $link['type'] = "url-{$linktype}";
            $link['link'] = LinkURL($URL, $linkname);
        }
    } elseif (preg_match("#^phpwiki:(.*)#", $URL, $match)) {
        $link['type'] = "url-wiki-{$linktype}";
        if (empty($linkname)) {
            $linkname = htmlspecialchars($URL);
        }
        $link['link'] = "<a href=\"{$ScriptUrl}{$match['1']}\">{$linkname}</a>";
    } elseif (preg_match("#^\\d+\$#", $URL)) {
        $link['type'] = "reference-{$linktype}";
        $link['link'] = $URL;
    } else {
        $link['type'] = "wiki-unknown-{$linktype}";
        $link['link'] = LinkUnknownWikiWord($URL, $linkname);
    }
    return $link;
}