e5fe7e9a8d8a2b1237b63a9083cb6182716c2025
[atutor.git] / mods / wiki / plugins / mpi / mpi_addlink.php
1 <?php
2
3 /*
4    <?plugin AddLink ?> will add an inline <form> to add a link to the
5    current page
6 */
7
8 $ewiki_plugins["mpi"]["addlink"] = "ewiki_mpi_addlink";
9
10
11 // view <form>
12 function ewiki_mpi_addlink($action, $args, &$iii, &$s) 
13 {
14     global $ewiki_id, $ewiki_action;
15     $o = "";
16
17     #-- add URL
18     if ($_REQUEST["link_save"]) {
19
20        #-- check parameters
21        $url = trim($_REQUEST["link_url"]);
22        $text = "";
23        $title = $desc = "";
24        if (!strpos($url, "example.com") && (strlen($url) > 12) && preg_match('#^https?://#', $url)) {
25           $text = implode("", file($url));
26           if ($text) {
27              (preg_match('#<title[^>]*>([^<]+)</title>#ims', $text, $uu))
28              and ($title = $uu[1])
29              or (preg_match('#//([^/]+)#', $url, $uu))
30              and ($title = $uu[1]);
31              (preg_match('#<meta[^>]+name=["\']description["\'][^>]+content=["\']([^"\']+)["\']#ims', $text, $uu))
32              and ($desc = $uu[1])
33              or (preg_match('#<body[^>]+>(.+?)</body#ims', $text, $uu))
34              and ($desc = strip_tags($uu[1]));
35              $desc = substr(preg_replace('/\s+/', " ", $desc), 0, 300);
36           }
37           $add = ":$title:\n   $url %%%\n   $desc\n";
38        }
39
40        #-- store bugreport
41        if ($text)  {
42            $data = ewiki_db::GET($ewiki_id);
43            $data["content"] = rtrim($data["content"]) . "\n" . $add;
44            ewiki_data_update($data);
45            $data["version"]++;
46            ewiki_db::WRITE($data);
47
48            #-- append to page output
49            $iii[] = array(
50               $add,
51               0xFFFF,
52               "core"
53            );
54        }
55     }
56     else {
57        $url = ewiki_script("", $ewiki_id);
58        $o .=<<<EOT
59 <form style="border:2px #333370 solid; background:#7770B0; padding:5px;"class="BugReport" action="$url" method="POST" enctype="multipart/form-data">
60 <input type="hidden" name="id" value="$ewiki_action/$ewiki_id">
61 Link <input type="text" name="link_url" value="http://www.example.com/" size="50">
62 <input type="submit" name="link_save" value="hinzufügen">
63 </form>
64 EOT;
65     }
66
67     return($o);
68 }
69
70
71 ?>