<?php

// Backlinks: returns pages which link to a given page.
rcs_id('$Id: backlinks.php,v 1.1 2004/09/28 21:48:44 gcasse Exp $');
if (get_magic_quotes_gpc()) {
    $refs = stripslashes($refs);
}
$pagename = $refs;
// No HTML markup allowed in $title.
$title = sprintf(gettext("Pages which link to %s"), htmlspecialchars($pagename));
if (IsWikiPage($dbi, $pagename)) {
    $pagelink = LinkExistingWikiWord($pagename);
} else {
    $pagelink = LinkUnknownWikiWord($pagename);
}
$html = "<p><b>" . sprintf(gettext("Pages which link to %s") . " .....", $pagelink) . "</b></p>\n<ul>\n";
// search matching pages
$query = InitBackLinkSearch($dbi, $pagename);
$found = 0;
while ($page = BackLinkSearchNextMatch($dbi, $query)) {
    $found++;
    $html .= "<li>" . LinkExistingWikiWord($page) . "<br>\n";
}
$html .= "</ul>\n<hr noshade>\n" . sprintf(gettext("%d pages link to %s."), $found, $pagelink) . "\n";
GeneratePage('MESSAGE', $html, $title, 0);
     }
     $oldn++;
 }
 //////////////////////////////////////////////////////////
 // Link Wiki words
 // Wikiwords preceeded by a '!' are not linked
 $oldn = $ntokens;
 $tmpline = tokenize($tmpline, "!?{$WikiNameRegexp}", $replacements, $ntokens);
 while ($oldn < $ntokens) {
     $old = $replacements[$oldn];
     if ($old[0] == '!') {
         $replacements[$oldn] = substr($old, 1);
     } elseif (IsWikiPage($dbi, $old)) {
         $replacements[$oldn] = LinkExistingWikiWord($old);
     } else {
         $replacements[$oldn] = LinkUnknownWikiWord($old);
     }
     $oldn++;
 }
 //////////////////////////////////////////////////////////
 // escape HTML metachars
 $tmpline = str_replace('&', '&amp;', $tmpline);
 $tmpline = str_replace('>', '&gt;', $tmpline);
 $tmpline = str_replace('<', '&lt;', $tmpline);
 // Gilles Casse (2003-01-21) for the Oralux website
 // The PhpWiki features are lowered:
 // - first because today we do not need them
 // - second to have a page which can be validated as xhtml 1.0 strict
 //
 // %%% are linebreaks
 $tmpline = str_replace('%%%', '<br />', $tmpline);
Exemple #3
0
function ParseAndLink($bracketlink)
{
    global $dbi, $ScriptUrl, $AllowedProtocols, $InlineImages;
    // $bracketlink will start and end with brackets; in between
    // will be either a page name, a URL or both separated by a pipe.
    // strip brackets and leading space
    preg_match("/(\\[\\s*)(.+?)(\\s*\\])/", $bracketlink, $match);
    // match the contents
    preg_match("/([^|]+)(\\|)?([^|]+)?/", $match[2], $matches);
    if (isset($matches[3])) {
        // named link of the form  "[some link name | http://blippy.com/]"
        $URL = trim($matches[3]);
        $linkname = htmlspecialchars(trim($matches[1]));
        $linktype = 'named';
    } else {
        // unnamed link of the form "[http://blippy.com/] or [wiki page]"
        $URL = trim($matches[1]);
        $linkname = '';
        $linktype = 'simple';
    }
    if (IsWikiPage($dbi, $URL)) {
        $link['type'] = "wiki-{$linktype}";
        $link['link'] = LinkExistingWikiWord($URL, $linkname);
    } elseif (preg_match("#^({$AllowedProtocols}):#", $URL)) {
        // if it's an image, embed it; otherwise, it's a regular link
        if (preg_match("/({$InlineImages})\$/i", $URL)) {
            $link['type'] = "image-{$linktype}";
            $link['link'] = LinkImage($URL, $linkname);
        } else {
            $link['type'] = "url-{$linktype}";
            $link['link'] = LinkURL($URL, $linkname);
        }
    } elseif (preg_match("#^phpwiki:(.*)#", $URL, $match)) {
        $link['type'] = "url-wiki-{$linktype}";
        if (empty($linkname)) {
            $linkname = htmlspecialchars($URL);
        }
        $link['link'] = "<a href=\"{$ScriptUrl}{$match['1']}\">{$linkname}</a>";
    } elseif (preg_match("#^\\d+\$#", $URL)) {
        $link['type'] = "reference-{$linktype}";
        $link['link'] = $URL;
    } else {
        $link['type'] = "wiki-unknown-{$linktype}";
        $link['link'] = LinkUnknownWikiWord($URL, $linkname);
    }
    return $link;
}