changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / linking / link_icons.php
1 <?php
2
3 /*
4  this _link_regex_callback() plugin scans for icons in a
5  given directory and prepends it before all links generated
6  by ewiki_format()
7 */
8
9
10 $ewiki_plugins["link_final"][] = "ewiki_link_icons";
11
12 define("EWIKI_LINK_ICONS_DIR", "/icons/");              # absolute to www root
13 define("EWIKI_LINK_ICONS_LOOKUP_DIR", "./icons");       # to access the files
14 define("EWIKI_LINK_ICONS_LOOKUP_SIZE", 1);              # use getimagesize()
15 define("EWIKI_LINK_ICONS_DEFAULT_SIZE", 'width="14" height="14"');  # fallback
16
17 $ewiki_link_icons = array(
18    "wikipage" => "",
19    "notfound" => "bomb.png",
20    "email" => "letter.gif",
21    "binary" => "disk.jpeg",
22    "http" => "www",
23    "mailto" => "letter.gif",
24    "ftp" => "disk.jpeg",
25 );
26
27
28
29 function ewiki_link_icons(&$html, $type, $href, $title) {
30
31    global $ewiki_link_icons;
32
33    ksort($type);
34    foreach (array_reverse($type) as $probe) {
35
36       if ($probe == "image") {
37          return;
38       }
39       $probe = strtolower($probe);
40
41       $test = array(
42          $ewiki_link_icons[$probe],
43          $probe,
44          $probe.".png",
45          $probe.".gif",
46          $probe.".jpeg",
47       );
48
49       foreach ($test as $f) {
50
51          if (strlen($f) && file_exists($fn2 = EWIKI_LINK_ICONS_LOOKUP_DIR . "/" . $f)) {
52
53             if (EWIKI_LINK_ICONS_LOOKUP_SIZE && ($uu = @getimagesize($fn2))) {
54                $img_sizes = $uu[4];
55             }
56             else {
57                $img_sizes = EWIKI_LINK_ICONS_DEFAULT_SIZE;
58             }
59
60             $img = '<img src="' . EWIKI_LINK_ICONS_DIR . $f . '" ' .
61                     $img_sizes . ' alt="\'" border="0" />';
62
63             $html = strtok($html, ">") . ">" . $img . strtok("\000");
64
65             return;
66          }
67
68       }
69
70    }
71
72 }
73
74
75 ?>