eda04259ed44a1d51a243403e694236d93f7e87d
[atutor.git] / mods / wiki / plugins / linking / instanturls.php
1 <?php
2
3 /*
4    Using this plugin allows to have a page, which associates short
5    page titles to URLs. Whenever a page title occours on another page,
6    it will link directly to the given URL.
7
8    A definition page, can associate titles to URLs using either a
9    table or a definition list:
10
11       |Remote site|  http://www.remote.org/|
12       |Second thing| http://www.example.com/|
13    or:
14       :Partners: http://google.com/
15
16    So if you write on another page things like [Remote site], it will
17    directly link to the URL you defined somewhere else.
18 */
19
20 $ewiki_config["instant_url_pages"][] = "InstantURLs";
21 //$ewiki_config["instant_url_pages"][] = "MoreLinks";
22
23
24 $ewiki_plugins["format_prepare_linking"][] = "ewiki_linking_instanturls";
25 function ewiki_linking_instanturls(&$src) {
26
27    global $ewiki_links, $ewiki_config;
28
29    #-- get list of URL abbreviations
30    if (empty($ewiki_config["instant"])) {
31       ewiki_get_instanturls();
32    }
33
34    #-- scan for non-existent pages
35    foreach ($ewiki_links as $id=>$is) {
36       if (!$is) {
37
38          ($url = $ewiki_config["instant"][$id])
39          or
40          ($url = $ewiki_config["interwiki"][$id])
41          ;
42
43          #-- use URL if defined
44          if ($url) {
45             $ewiki_links[$id] = $url;
46          }
47    }  }
48 }
49
50
51 function ewiki_get_instanturls() {
52    global $ewiki_config;
53
54    $ewiki_config["instant"] = array();
55    $DL = '[:|]([^:|]+)[:|]([^|]+)';
56
57    #-- walk through URL definition pages
58    foreach ($ewiki_config["instant_url_pages"] as $id) {
59
60       #-- fetch content
61       $data = ewiki_db::GET($id);
62       if ($data) {
63          preg_match_all("/^$DL/m", $data["content"], $uu);
64          if ($uu) {
65             foreach ($uu[1] as $i=>$name) {
66                $ewiki_config["instant"][trim($name)] = strtok(trim($uu[2][$i]), " ");
67             }
68       }  }
69    }
70 }
71
72 ?>