]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/interwiki.php
InterWiki link-icon added.
[SourceForge/phpwiki.git] / lib / interwiki.php
1 <?php rcs_id('$Id: interwiki.php,v 1.10 2001-12-07 05:27:20 carstenklapp Exp $');
2
3 function generate_interwikimap_and_regexp()
4 {
5     global $interwikimap_file, $InterWikiLinkRegexp, $interwikimap;
6
7     $intermap_data = file(INTERWIKI_MAP_FILE, 1);
8     $wikiname_regexp = "";
9     for ($i=0; $i<count($intermap_data); $i++)
10         {
11             list( $wiki, $inter_url ) = split(' ', chop($intermap_data[$i]));
12             $interwikimap[$wiki] = $inter_url;
13             if ($wikiname_regexp)
14                 $wikiname_regexp .= "|";
15             $wikiname_regexp .= $wiki;
16         }
17
18     $InterWikiLinkRegexp = "($wikiname_regexp)";
19 }
20
21 generate_interwikimap_and_regexp();
22
23 function LinkInterWikiLink($link, $linktext='')
24 {
25     global $interwikimap;
26
27     list( $wiki, $page ) = split( ":", $link, 2 );
28
29     $url = $interwikimap[$wiki];
30
31     // Urlencode page only if it's a query arg.
32     // FIXME: this is a somewhat broken heuristic.
33     $page_enc = strstr($url, '?') ? rawurlencode($page) : $page;
34     
35     if (strstr($url, '%s'))
36         $url = sprintf($url, $page_enc);
37     else
38         $url .= $page_enc;
39
40     if ($linktext) {
41         $linktext = htmlspecialchars($linktext);
42         $class = 'named-interwiki';
43     }
44     else {
45         $linktext = ( htmlspecialchars("$wiki:")
46                       . QElement('span', array('class' => 'wikipage'), $page) );
47         $class = 'interwiki';
48     }
49
50     $linkproto='interwiki';
51     $ICONS = &$GLOBALS['URL_LINK_ICONS'];
52     
53     $linkimg = isset($ICONS[$linkproto]) ? $ICONS[$linkproto] : $ICONS['*'];
54     if (!empty($linkimg)) {
55         $imgtag = Element('img', array('src' => DataURL($linkimg),
56                                        'alt' => $linkproto,
57                                        'class' => 'linkicon'));
58         $linktext = $imgtag . $linktext;
59     }
60
61     return Element('a', array('href' => $url,
62                               'class' => $class),
63                    $linktext);
64 }
65
66 // Link InterWiki links
67 // These can be protected by a '!' like Wiki words.
68 function wtt_interwikilinks($match, &$trfrm)
69 {
70     if ($match[0] == "!")
71         return htmlspecialchars(substr($match,1));
72     return LinkInterWikiLink($match);
73 }
74
75 // For emacs users
76 // Local Variables:
77 // mode: php
78 // tab-width: 8
79 // c-basic-offset: 4
80 // c-hanging-comment-ender-p: nil
81 // indent-tabs-mode: nil
82 // End:
83
84 ?>