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