MDL-11082 Improved groups upgrade performance 1.8x -> 1.9; thanks Eloy for telling...
[moodle-pu.git] / mod / wiki / ewiki / plugins / jump.php
blob727f13ae0a391ac1e4fc5ae94b13ac64eda7f3d5
1 <?php
3 /*
4 This plugin adds a page redirection feature. ewiki instantly switches
5 to another page, when one of the following markup snippets is found:
7 [jump:AnotherPage]
8 [goto:SwitchToHere]
9 or
10 [jump:WardsWiki:WelcomeVisitors]
11 [jump:Google:ErfurtWiki:MarioSalzer]
12 [jump:http://www.heise.de/]
14 One can also use [redirect:] or [location:]. Page switching only occours
15 with the "view" action. Sending a HTTP redirect is the default, but in
16 place redirects are also possible.
17 There exists a loop protection, which limits redirects to 5 (for browsers
18 that cannot detect this themselfes).
21 #-- config
22 define("EWIKI_JUMP_HTTP", 1); #-- issue a HTTP redirect, or jump in place
23 define("EWIKI_UP_REDIRECT_COUNT", "redir");
25 #-- text
26 $ewiki_t["en"]["REDIRECTION_LOOP"] = "<h2>Redirection loop detected<h2>\nOperation stopped, because we're traped in an infinite redirection loop with page \$id.";
28 #-- plugin glue
29 $ewiki_plugins["handler"][] = "ewiki_handler_jump";
30 $ewiki_config["interwiki"]["jump"] = "";
31 $ewiki_config["interwiki"]["goto"] = "";
34 function ewiki_handler_jump(&$id, &$data, &$action) {
36 global $ewiki_config;
38 static $redirect_count = 5;
39 $jump_markup = array("jump", "goto", "redirect", "location");
41 #-- we only care about "view" action
42 if ($action != "view") {
43 return;
46 #-- escape from loop
47 if (isset($_REQUEST["EWIKI_UP_REDIRECT_COUNT"])) {
48 $redirect_count = $_REQUEST["EWIKI_UP_REDIRECT_COUNT"];
50 if ($redirect_count-- <= 0) {
51 return(ewiki_t("REDIRECTION_LOOP", array("id"=>$id)));
54 #-- search for [jump:...]
55 if ($links = explode("\n", trim($data["refs"])))
56 foreach ($links as $link) {
58 if (strlen($link) && strpos($link, ":")
59 && in_array(strtolower(strtok($link, ":")), $jump_markup)
60 && ($dest = trim(strtok("\n"))) )
62 $url = "";
63 if (strpos($dest, "://")) {
64 $url = $dest;
66 else {
67 $url = ewiki_interwiki($dest);
70 #-- Location:
71 if (EWIKI_JUMP_HTTP && EWIKI_HTTP_HEADERS && !headers_sent()) {
73 if (empty($url)) {
74 $url = ewiki_script("", $dest,
75 array(EWIKI_UP_REDIRECT_COUNT=>$redirect_count),
76 0, 0, ewiki_script_url()
79 header("Location: $url");
80 die();
83 #-- show page as usual, what will reveal dest URL
84 elseif ($url) {
85 return("");
86 # the rendering kernel will just show up the [jump:]!
87 # (without the jump: of course)
89 #-- it's simply about another WikiPage
90 else {
92 #-- we'll just restart ewiki
93 $data = array();
94 $id = $dest;
95 return(ewiki_page("view/".$id));
98 }#-search