f7b55f6d2d334b8a1dcc24e8618fe8019f114cd2
[atutor.git] / mods / wiki / plugins / mpi / mpi_farinclude.php
1 <?php
2 /*
3    A plugin call like <?plugin FarInclude http://example.org/doc.htm ?>
4    rapes the text/html body from the given URL and inserts this into
5    the current page. You could also specify (Perl-) regular expressions
6    to break the wanted content out with (case-insensitive):
7     <?plugin  FarInclude  url=...  start="<b><i>"  end="<\/b>"  ?>
8    Where quotation marks must be escaped with backslashes, if you need
9    them, and the borders won't be included of course.
10
11    This can be used in conjuction with WikiFeatures:SnippetPublishing
12    and ewikis htm/ action -> "http://erfurtwiki.sf.net/htm/SandBox".
13 */
14
15
16 $ewiki_plugins["mpi"]["farinclude"] = "ewiki_mpi_farinclude";
17 function ewiki_mpi_farinclude($action, &$args, &$iii, &$s) {
18
19    global $ewiki_config;
20
21    #-- get params
22    ($url = $args["url"])
23    or ($url = $args["href"])
24    or ($url = $args["src"])
25    or ($url = $args[0]);
26    if (!$url || (strpos($url, "http") !== 0)) {
27       return;
28    }
29
30    #-- load page
31    ini_set("user_agent", "mpi_FarInclude/1.2 $ewiki_config[ua]");
32    if (function_exists("ewiki_http")) {
33       $html = ewiki_http("GET", $url);
34    }
35    else {
36       $html = @implode("", @file($url));
37    }
38    if (!$html) {
39       return;
40    }
41
42    #-- strip out stuff
43    if ($l = strpos(strtolower($html), "<body")) {
44       $html = substr($html, strpos($html, ">", $l) + 1);
45    }
46    if ($l = strpos(strtolower($html), "</body")) {
47       $html = substr($html, 0, $l);
48    }
49
50    #-- reduce by regex
51    if (($a = $args["start"]) and ($z = $args["end"])) {
52       if (preg_match("\007$a(.+?)$z\007ims", $html, $uu)) {
53          $html = $uu[1];
54       }
55    }
56
57    #-- that's it
58    $html = "\n<!-- the following was raped from \"$url\" -->\n$html\n<!-- end of FarInclude'd stuff -->\n";
59    return($html);
60 }
61
62
63 ?>