]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/SemanticRelations.php
Reformat code
[SourceForge/phpwiki.git] / lib / plugin / SemanticRelations.php
1 <?php
2
3 /*
4  * Copyright 2005 Reini Urban
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * SemanticRelations - Display the list of relations and attributes of given page(s).
25  * Relations are stored in the link table.
26  * Attributes as simple page meta-data.
27  *
28  * @author: Reini Urban
29  * @see WikiPlugin_SemanticSearch
30  */
31 class WikiPlugin_SemanticRelations
32     extends WikiPlugin
33 {
34     function getName()
35     {
36         return _("SemanticRelations");
37     }
38
39     function getDescription()
40     {
41         return _("Display the list of relations and attributes on this page.");
42     }
43
44     function getDefaultArguments()
45     {
46         return array(
47             'page' => "[pagename]", // which pages (glob allowed), default: current
48             'relations' => '', // which relations. default all
49             'attributes' => '', // which attributes. default all
50             'units' => '', // ?
51             'noheader' => false,
52             'nohelp' => false
53         );
54     }
55
56     function run($dbi, $argstr, &$request, $basepage)
57     {
58         global $WikiTheme;
59         $args = $this->getArgs($argstr, $request);
60         extract($args);
61         if (empty($page))
62             $page = $request->getArg('pagename');
63         $relhtml = HTML();
64         if ($args['relations'] != '') {
65             $relfilter = explode(",", $args['relations']);
66         } else
67             $relfilter = array();
68         if ($args['attributes'] != '') {
69             $attfilter = explode(",", $args['attributes']);
70         } else
71             $attfilter = array();
72         foreach (explodePageList($page) as $pagename) {
73             $p = $dbi->getPage($pagename);
74             if ($args['relations'] != '0') {
75                 $links = $p->getRelations(); // iter of pagelinks
76                 // TODO: merge same relations together located_in::here, located_in::there
77                 while ($object = $links->next()) {
78                     if ($related = $object->get('linkrelation')) { // a page name
79                         if ($relfilter and !in_array($related, $relfilter)) {
80                             continue;
81                         }
82                         $rellink = WikiLink($related, false, $related);
83                         $rellink->setAttr('class', $rellink->getAttr('class') . ' relation');
84                         $relhtml->pushContent
85                         ($pagename . " ",
86                             // Link to a special "Relation:" InterWiki link?
87                             $rellink,
88                             HTML::span(array('class' => 'relation-symbol'), "::"), // use spaces?
89                             WikiLink($object->_pagename),
90                             " ",
91                             // Link to SemanticSearch
92                             $WikiTheme->makeActionButton(array('relation' => $related,
93                                     's' => $object->_pagename),
94                                 '+',
95                                 _("SemanticSearch")),
96                             (count($relfilter) > 3 ? HTML::br() : " "));
97                     }
98                 }
99                 if (!empty($relhtml->_content) and !$noheader)
100                     $relhtml = HTML(HTML::hr(),
101                         HTML::h3(fmt("Semantic relations for %s", $pagename)),
102                         $relhtml);
103             }
104             $atthtml = HTML();
105             if ($args['attributes'] != '0') {
106                 if ($attributes = $p->get('attributes')) { // a hash of unique pairs
107                     foreach ($attributes as $att => $val) {
108                         if ($attfilter and !in_array($att, $attfilter)) continue;
109                         $rellink = WikiLink($att, false, $att);
110                         $rellink->setAttr('class', $rellink->getAttr('class') . ' relation');
111                         $searchlink = $WikiTheme->makeActionButton
112                         (array('attribute' => $att,
113                                 's' => $val),
114                             $val,
115                             _("SemanticSearch"));
116                         $searchlink->setAttr('class', $searchlink->getAttr('class') . ' attribute');
117                         if (!$noheader)
118                             $atthtml->pushContent("$pagename  ");
119                         $atthtml->pushContent(HTML::span(array('class' => 'attribute ' . $att),
120                                 $rellink,
121                                 HTML::span(array('class' => 'relation-symbol'),
122                                     ":="),
123                                 $searchlink),
124                             (count($attfilter) > 3 ? HTML::br() : " "));
125                     }
126                     if (!$noheader)
127                         $relhtml = HTML($relhtml,
128                             HTML::hr(),
129                             HTML::h3(fmt("Attributes of %s", $pagename)),
130                             $atthtml);
131                     else
132                         $relhtml = HTML($relhtml, $atthtml);
133                 }
134             }
135         }
136         if ($nohelp) return $relhtml;
137         return HTML($relhtml,
138             HTML::hr(),
139             WikiLink(_("Help/SemanticRelations"), false,
140                 HTML::em(_("Help/SemanticRelations"))),
141             " - ",
142             HTML::em(_("Find out how to add relations and attributes to pages.")));
143     }
144 }
145
146 // Local Variables:
147 // mode: php
148 // tab-width: 8
149 // c-basic-offset: 4
150 // c-hanging-comment-ender-p: nil
151 // indent-tabs-mode: nil
152 // End: