]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/SemanticRelations.php
Replace tabs by spaces; remove EOL spaces
[SourceForge/phpwiki.git] / lib / plugin / SemanticRelations.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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         return _("SemanticRelations");
36     }
37     function getDescription() {
38         return _("Display the list of relations and attributes on this page.");
39     }
40     function getVersion() {
41         return preg_replace("/[Revision: $]/", '',
42                             "\$Revision$");
43     }
44     function getDefaultArguments() {
45         return array(
46                      'page'       => "[pagename]", // which pages (glob allowed), default: current
47                      'relations'  => '', // which relations. default all
48                      'attributes' => '', // which attributes. default all
49                      'units'      => '', // ?
50                      'noheader'   => false,
51                      'nohelp'     => false
52                      );
53     }
54     function run ($dbi, $argstr, &$request, $basepage) {
55         global $WikiTheme;
56         $args = $this->getArgs($argstr, $request);
57         extract($args);
58         if (empty($page))
59             $page = $request->getArg('pagename');
60         $relhtml = HTML();
61         if ($args['relations'] != '') {
62             $relfilter = explode(",", $args['relations']);
63         } else
64             $relfilter = array();
65         if ($args['attributes'] != '') {
66             $attfilter = explode(",", $args['attributes']);
67         } else
68             $attfilter = array();
69         foreach (explodePageList($page) as $pagename) {
70             $p = $dbi->getPage($pagename);
71             if ($args['relations'] != '0') {
72               $links = $p->getRelations(); // iter of pagelinks
73               // TODO: merge same relations together located_in::here, located_in::there
74               while ($object = $links->next()) {
75                 if ($related = $object->get('linkrelation')) { // a page name
76                     if ($relfilter and !in_array($related, $relfilter)) {
77                              continue;
78                     }
79                     $rellink = WikiLink($related, false, $related);
80                     $rellink->setAttr('class', $rellink->getAttr('class').' relation');
81                     $relhtml->pushContent
82                         ($pagename . " ",
83                          // Link to a special "Relation:" InterWiki link?
84                          $rellink,
85                          HTML::span(array('class'=>'relation-symbol'), "::"), // use spaces?
86                          WikiLink($object->_pagename),
87                          " ",
88                          // Link to SemanticSearch
89                          $WikiTheme->makeActionButton(array('relation' => $related,
90                                                             's'   => $object->_pagename),
91                                                       '+',
92                                                       _("SemanticSearch")),
93                          (count($relfilter) > 3 ? HTML::br() : " "));
94                 }
95               }
96               if (!empty($relhtml->_content) and !$noheader)
97                   $relhtml = HTML(HTML::hr(),
98                                   HTML::h3(fmt("Semantic relations for %s", $pagename)),
99                                   $relhtml);
100             }
101             $atthtml = HTML();
102             if ($args['attributes'] != '0') {
103               if ($attributes = $p->get('attributes')) { // a hash of unique pairs
104                 foreach ($attributes as $att => $val) {
105                     if ($attfilter and !in_array($att, $attfilter)) continue;
106                     $rellink = WikiLink($att, false, $att);
107                     $rellink->setAttr('class', $rellink->getAttr('class').' relation');
108                     $searchlink = $WikiTheme->makeActionButton
109                         (array('attribute' => $att,
110                                's'         => $val),
111                          $val,
112                          _("SemanticSearch"));
113                     $searchlink->setAttr('class', $searchlink->getAttr('class').' attribute');
114                     if (!$noheader)
115                         $atthtml->pushContent("$pagename  ");
116                     $atthtml->pushContent(HTML::span(array('class' => 'attribute '.$att),
117                                                      $rellink,
118                                                      HTML::span(array('class'=>'relation-symbol'),
119                                                                 ":="),
120                                                      $searchlink),
121                                           (count($attfilter) > 3 ? HTML::br() : " "));
122                 }
123                 if (!$noheader)
124                     $relhtml = HTML($relhtml,
125                                     HTML::hr(),
126                                     HTML::h3(fmt("Attributes of %s", $pagename)),
127                                     $atthtml);
128                 else
129                     $relhtml = HTML($relhtml, $atthtml);
130              }
131            }
132         }
133         if ($nohelp) return $relhtml;
134         return HTML($relhtml,
135                     HTML::hr(),
136                     WikiLink(_("Help/SemanticRelations"), false,
137                              HTML::em(_("Help/SemanticRelations"))),
138                     " - ",
139                     HTML::em(_("Find out how to add relations and attributes to pages.")));
140     }
141 };
142
143 // Local Variables:
144 // mode: php
145 // tab-width: 8
146 // c-basic-offset: 4
147 // c-hanging-comment-ender-p: nil
148 // indent-tabs-mode: nil
149 // End:
150 ?>