changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / mpi / mpi_registerspam.php
1 <?php
2 /*
3    This MpiPlugin should be called from the BannedLinks or BlockedLinks
4    pages to ease injecting fresh URLs (it strips "http://" and "www."
5    prefixes, titles and thereby yields shorter matching patterns).
6 */
7
8 $ewiki_plugins["mpi"]["registerspam"] = "ewiki_mpi_registerspam";
9
10 function ewiki_mpi_registerspam($action, &$args, &$iii, &$s) {
11
12    global $ewiki_id;
13
14    if (!$_POST["regspam"]) {
15       return<<<END
16 <form action="$_SERVER[REQUEST_URI]" method="POST" enctype="multipart/form-data">
17 <textarea name="add_spam" cols="50" rows="3"></textarea><br/>
18 <input type="submit" name="regspam" value="add listed urls" />
19 </form>
20 END;
21    }
22    else {
23    
24       #-- scan for links
25       $text = $_REQUEST["add_spam"];
26       ewiki_scan_wikiwords($text, $uu);
27       $ls = array();
28       foreach ($uu as $href=>$uu) {
29          if ($l = strpos($href, "://")) {
30             // filter out redundant pattern parts
31             $href = substr($href, $l + 3);
32             if (strpos($href, "www.")===0) {
33                $href = substr($href, 4);
34             }
35             $href = trim($href, "/");
36             $ls[] = strtok($href, " ");
37          }
38       }
39       
40       #-- reduce
41       $ls = array_unique($ls);
42       $data = ewiki_db::GET($ewiki_id);
43       foreach (explode("\n", trim($data["refs"])) as $href) {
44          if (in_array($href, $ls)) {
45             unset($ls[array_search($href, $ls)]);
46          }
47       }
48       
49       #-- add to current page
50       if ($ls) {
51          $inj = "* [" . implode("], [", $ls) . "]\n";
52          $data["content"] = preg_replace("/(^[-*#])/m", "$inj$1", $data["content"], 1);
53          ewiki_db::UPDATE($data);
54          $data["version"]++;
55          ewiki_db::WRITE($data);
56          return "\n<div class=\"system-message ok\">new links added as patterns here (please go back and reload page to see it)</div>\n";
57       }
58       else {
59          return "\n<div class=\"system-message failure\">no new links found, please add the patterns by hand then</div>\n";
60       }
61    }
62 }
63
64 ?>