Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
170 jpm 1
<?php
171 jpm 2
// $Id: Freelink.php,v 1.2 2004-11-24 19:06:43 jpm Exp $
170 jpm 3
 
4
 
5
/**
6
*
7
* This class implements a Text_Wiki_Parse to find source text marked as a
8
* wiki freelink, and automatically create a link to that page.
9
*
10
* A freelink is any page name not conforming to the standard
11
* StudlyCapsStyle for a wiki page name.  For example, a page normally
12
* named MyHomePage can be renamed and referred to as ((My Home Page)) --
13
* note the spaces in the page name.  You can also make a "nice-looking"
14
* link without renaming the target page; e.g., ((MyHomePage|My Home
15
* Page)).  Finally, you can use named anchors on the target page:
16
* ((MyHomePage|My Home Page#Section1)).
17
*
18
* @author Paul M. Jones <pmjones@ciaweb.net>
19
*
20
* @package Text_Wiki
21
*
22
*/
23
 
24
class Text_Wiki_Parse_Freelink extends Text_Wiki_Parse {
25
 
26
 
27
    /**
28
    *
29
    * Constructor.  We override the Text_Wiki_Parse constructor so we can
30
    * explicitly comment each part of the $regex property.
31
    *
32
    * @access public
33
    *
34
    * @param object &$obj The calling "parent" Text_Wiki object.
35
    *
36
    */
37
 
38
    function Text_Wiki_Parse_Freelink(&$obj)
39
    {
40
        parent::Text_Wiki_Parse($obj);
41
 
42
        $this->regex =
43
            '/' .                                                   // START regex
44
            "\\[\\[" .                                               // double crochet ouvrant
45
            "(" .                                                   // START freelink page patter
46
            "[-A-Za-z0-9_+\\/.,;!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character mmais pas les :
47
            ")" .                                                   // END  freelink page pattern
48
            "(" .                                                   // START display-name
49
            " " .                                                   // un espace pour démarer l'affichage du texte
50
            "[-A-Za-z0-9 _+\\/.,;!?'\"\\[\\]\\{\\}&\xc0-\xff]+" . // 1 or more of just about any character mmais pas les :
51
            ")?" .                                                   // END display-name pattern 0 or 1
52
            "()\\]\\]" .                                           // double close-parens
53
            '/';                                                   // END regex
54
    }
55
 
56
 
57
    /**
58
    *
59
    * Generates a replacement for the matched text.  Token options are:
60
    *
61
    * 'page' => the wiki page name (e.g., HomePage).
62
    *
63
    * 'text' => alternative text to be displayed in place of the wiki
64
    * page name.
65
    *
66
    * 'anchor' => a named anchor on the target wiki page
67
    *
68
    * @access public
69
    *
70
    * @param array &$matches The array of matches from parse().
71
    *
72
    * @return A delimited token to be used as a placeholder in
73
    * the source text, plus any text priot to the match.
74
    *
75
    */
76
 
77
    function process(&$matches)
78
    {
79
        // use nice variable names
80
        $page = $matches[1];
81
        $text = $matches[2];
82
 
83
        // get rid of the leading # from the anchor, if any
84
        //$anchor = substr($matches[3], 1);
85
 
86
        // is the page given a new text appearance?
87
        if (trim($text) == '') {
88
            // no
89
            $text = $page;
90
        } else {
91
            // yes, strip the leading | character
92
            $text = substr($text, 1);
93
        }
94
 
95
        // set the options
96
        $options = array(
97
            'page'   => $page,
98
            'text'   => $text,
171 jpm 99
            'anchor' => ''
170 jpm 100
        );
101
 
102
        // return a token placeholder
103
        return $this->wiki->addToken($this->rule, $options);
104
    }
105
}
106
?>