]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/SemanticRelations.php
Plugin to display the list of SemanticRelations - list of relations and
[SourceForge/phpwiki.git] / lib / plugin / SemanticRelations.php
1 <?php // -*-php-*-
2 rcs_id('$Id: SemanticRelations.php,v 1.1 2005-11-21 20:14:20 rurban Exp $');
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  */
30 class WikiPlugin_SemanticRelations
31 extends WikiPlugin
32 {
33     function getName() {
34         return _("SemanticRelations");
35     }
36     function getDescription() {
37         return _("Display the list of relations and attributes");
38     }
39     function getVersion() {
40         return preg_replace("/[Revision: $]/", '',
41                             "\$Revision: 1.1 $");
42     }
43     function getDefaultArguments() { 
44         return array(
45                      'page'       => "", // which pages (glob allowed), default: current
46                      'relations'  => '', // which relations. default all
47                      'attributes' => '', // which attributes. default all
48                      'units'      => '', // ?
49                      'noheader'   => false,
50                      'nohelp'     => false
51                      );
52     }
53     function run ($dbi, $argstr, &$request, $basepage) { 
54         global $WikiTheme;
55         $args = $this->getArgs($argstr, $request);
56         extract($args);
57         if (empty($page))
58             $page = $request->getArg('pagename');
59         $relhtml = HTML();
60         foreach (explodePageList($page) as $pagename) {
61             $p = $dbi->getPage($pagename);
62             $links = $p->getRelations(); // iter of pagelinks
63             // TODO: merge same relations together located_in::here, located_in::there
64             while ($object = $links->next()) {
65                 if ($related = $object->get('linkrelation')) { // a page name
66                     $relhtml->pushContent
67                         ($pagename . " ",
68                          // Link to a special "Relation:" InterWiki link?
69                          WikiLink($related, false, $related), 
70                          " :: ", // use spaces?
71                          WikiLink($object->_pagename), 
72                          " ",
73                          // Link to SemanticSearch
74                          $WikiTheme->makeActionButton(array('relation' => $related,
75                                                             'object'   => $object->_pagename),
76                                                       '+',
77                                                       _("SemanticSearch")),
78                          HTML::br());
79                 }
80             }
81             if (!empty($relhtml->_content) and !$noheader)
82                 $relhtml = HTML(HTML::hr(),
83                                 HTML::h3(fmt("Semantic relations for %s", $p->getName())),
84                                 $relhtml);
85             $atthtml = HTML();
86             if ($attributes = $p->get('attributes')) { // a hash of unique pairs
87                 foreach ($attributes as $att => $val) {
88                     if ($noheader)
89                         $atthtml->pushContent("$pagename  $att := $val", HTML::br());
90                     else
91                         $atthtml->pushContent("$att := $val", HTML::br());
92                 }
93                 if (!$noheader)
94                     $relhtml = HTML($relhtml,
95                                     HTML::hr(),
96                                     HTML::h3(fmt("Attributes of %s", $p->getName())), 
97                                     $atthtml);
98                 else
99                     $relhtml = HTML($relhtml, $atthtml);
100             }
101         }
102         if ($nohelp) return $relhtml;
103         return HTML($relhtml, 
104                     HTML::hr(), 
105                     WikiLink(_("Help/SemanticRelations"), false,
106                              HTML::em(_("Help/SemanticRelations"))),
107                     " - ",
108                     HTML::em(_("Find out how to add relations and attributes to pages.")));
109     }
110
111 };
112
113 // $Log: not supported by cvs2svn $
114
115 // Local Variables:
116 // mode: php
117 // tab-width: 8
118 // c-basic-offset: 4
119 // c-hanging-comment-ender-p: nil
120 // indent-tabs-mode: nil
121 // End:
122 ?>