]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/SemanticRelations.php
default pagename: current. improve output: class, linked attributes. switch to Semant...
[SourceForge/phpwiki.git] / lib / plugin / SemanticRelations.php
1 <?php // -*-php-*-
2 rcs_id('$Id: SemanticRelations.php,v 1.2 2007-01-02 13:22:41 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.2 $");
42     }
43     function getDefaultArguments() { 
44         return array(
45                      'page'       => "[pagename]", // 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                     $rellink = WikiLink($related, false, $related);
67                     $rellink->setAttr('class', $rellink->getAttr('class').' relation');
68                     $relhtml->pushContent
69                         ($pagename . " ",
70                          // Link to a special "Relation:" InterWiki link?
71                          $rellink, 
72                          HTML::strong(" :: "), // use spaces?
73                          WikiLink($object->_pagename), 
74                          " ",
75                          // Link to SemanticSearch
76                          $WikiTheme->makeActionButton(array('relation' => $related,
77                                                             's'   => $object->_pagename),
78                                                       '+',
79                                                       _("SemanticSearch")),
80                          HTML::br());
81                 }
82             }
83             if (!empty($relhtml->_content) and !$noheader)
84                 $relhtml = HTML(HTML::hr(),
85                                 HTML::h3(fmt("Semantic relations for %s", $pagename)),
86                                 $relhtml);
87             $atthtml = HTML();
88             if ($attributes = $p->get('attributes')) { // a hash of unique pairs
89                 foreach ($attributes as $att => $val) {
90                     $rellink = WikiLink($att, false, $att);
91                     $rellink->setAttr('class', $rellink->getAttr('class').' relation');
92                     $searchlink = $WikiTheme->makeActionButton
93                         (array('attribute' => $att,
94                                's'         => $val),
95                          '+',
96                          _("SemanticSearch"));
97                     if (!$noheader)
98                         $atthtml->pushContent("$pagename  ");
99                     $atthtml->pushContent(HTML::span($rellink, 
100                                                      HTML::strong(" := "), 
101                                                      HTML($val)),
102                                           " ", $searchlink,
103                                           HTML::br());
104                 }
105                 if (!$noheader)
106                     $relhtml = HTML($relhtml,
107                                     HTML::hr(),
108                                     HTML::h3(fmt("Attributes of %s", $pagename)), 
109                                     $atthtml);
110                 else
111                     $relhtml = HTML($relhtml, $atthtml);
112             }
113         }
114         if ($nohelp) return $relhtml;
115         return HTML($relhtml, 
116                     HTML::hr(), 
117                     WikiLink(_("Help/SemanticRelations"), false,
118                              HTML::em(_("Help/SemanticRelations"))),
119                     " - ",
120                     HTML::em(_("Find out how to add relations and attributes to pages.")));
121     }
122
123 };
124
125 // $Log: not supported by cvs2svn $
126 // Revision 1.1  2005/11/21 20:14:20  rurban
127 // Plugin to display the list of SemanticRelations - list of relations and
128 // attributes of given page(s).
129 // Relations are stored in the link table.
130 // Attributes as simple page meta-data.
131 //
132
133 // Local Variables:
134 // mode: php
135 // tab-width: 8
136 // c-basic-offset: 4
137 // c-hanging-comment-ender-p: nil
138 // indent-tabs-mode: nil
139 // End:
140 ?>