4 * CompactPreviewPlugin Class
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 class CompactPreviewPlugin extends Plugin {
26 public function __construct($id=0) {
28 $this->name = "compactpreview";
29 $this->text = "CompactPreview!"; // To show in the tabs, use...
30 $this->_addHook("user_link_with_tooltip"); // override the way user links are done (for user compact preview support)
31 $this->_addHook("project_link_with_tooltip");
32 $this->_addHook("javascript_file"); // Add js files for oslc plugin
33 $this->_addHook("javascript"); // Add js initialization code
34 $this->_addHook("cssfile");
35 $this->_addHook("script_accepted_types");
36 $this->_addHook("content_negociated_user_home");
37 $this->_addHook("content_negociated_project_home");
44 * override util_display_user() with modified version to display compact preview popup on user links
45 * @param array $params hook params (return in $params['user_link'])
47 function user_link_with_tooltip (&$params) {
49 require_once dirname( __FILE__ ) . '/CompactResource.class.php';
50 $cR = CompactResource::createCompactResource($params);
51 $params['user_link'] = $cR->getResourceLink();
55 * override util_make_link_g() with modified version to display compact preview popup on project links
56 * @param array $params hook params (return in $params['user_link'])
58 function project_link_with_tooltip (&$params) {
59 require_once dirname( __FILE__ ) . '/CompactResource.class.php';
60 $cR = CompactResource::createCompactResource($params);
61 $params['group_link'] = $cR->getResourceLink();
64 function javascript_file (&$params) {
65 // The userTooltip.js script is used by the compact preview feature (see content_negociated_user_home)
67 // provides support for the popup for compact preview
68 use_javascript('/plugins/'.$this->name.'/scripts/oslcTooltip.js');
71 function javascript (&$params) {
72 // make sure jquery won't conflict with prototype
73 $params['return'] = 'jQuery.noConflict();';
76 function cssfile (&$params) {
77 use_stylesheet('/plugins/'.$this->name.'/css/oslcTooltipStyle.css');
81 * Declaration of which content-negociation alternatives are provided by this plugin
82 * @param unknown_type $params
84 function script_accepted_types (&$params) {
85 $script = $params['script'];
86 if ($script == 'user_home' || $script == 'project_home') {
87 // we do support content-negociation on /users and /project with the following accept header values
88 // for OSLC compact-preview
89 $params['accepted_types'][] = 'application/x-oslc-compact+xml';
90 // for fusionforge compact preview
91 $params['accepted_types'][] = 'application/x-fusionforge-compact+html';
95 function display_user_html_compact_preview($username, $title = false) {
98 require_once $gfwww.'include/user_profile.php';
100 $user_obj = user_get_object_by_name($username);
102 $user_real_name = $user_obj->getRealName();
103 $user_id = $user_obj->getID();
107 <title>User: '. $user_real_name .' (Identifier: '. $user_id .')</title>
111 $html .= user_personal_information($user_obj, true, $title);
119 function display_project_html_compact_preview($project, $title) {
121 $project_obj = group_get_object_by_name($project);
123 $public_name = $project_obj->getPublicName();
124 $unix_name = $project_obj->getUnixName();
125 $id = $project_obj->getID();
126 $home_page = util_make_url ("/projects/$unix_name/");
127 $description = $project_obj->getDescription();
128 $start_date = $project_obj->getStartDate();
129 $status = $project_obj->getStatus();
132 $project_status = 'Active';
135 $project_status = 'Hold';
138 $project_status = 'Pending';
141 $project_status = 'Incomplete';
146 if ($project_obj->isPublic()) {
154 <title>Project: '. $public_name .' ('. $unix_name .')</title>
160 <td colspan="2"><i>'. $title .'</i></td>
163 '/* <td rowspan="8"><img src="/plugins/compactpreview/images/userTooltip/oslc.png" />
165 <td><b>Project name:</b>
169 '. $public_name .'</td>
172 <td><b>Project short name:</b>
176 '. $unix_name .'</td>
179 <td><b>Identifier:</b>
186 <td><b>Started since:</b>
190 '. date(_('Y-m-d H:i'), $start_date) .'</td>
197 '. $project_status .'</td>
200 <td><b>Is Public:</b>
207 <td><b>Description:</b>
211 '. $description .'</td>
214 <td><small><b>Home Page:</b> <a href="'. $home_page .'">'. $home_page .'
226 function content_negociated_user_home (&$params) {
228 $username = $params['username'];
229 $accept = $params['accept'];
230 $param['content'] = false;
233 // if want some OSLC compact-preview, provide the document pointing to the compact-preview
234 case 'application/x-oslc-compact+xml' : {
235 $params['content_type'] = 'application/x-oslc-compact+xml';
236 $params['content'] = '<?xml version="1.0"?>
237 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc="http://open-services.net/ns/core#">
238 <oslc:Compact rdf:about="/plugins/oslc/compact/user/'. $username .'">
239 <dcterms:title>'. $username . '</dcterms:title>
240 <oslc:shortTitle>'. $username . '</oslc:shortTitle>
243 <oslc:document rdf:ressource="/plugins/'.$this->name.'/user.php?user='. $username .'"/>
244 <oslc:hintWidth>500px</oslc:hintWidth>
245 <oslc:hintHeight>150px</oslc:hintHeight>
252 // if want direct compact-preview rendering
253 case 'application/x-fusionforge-compact+html' : {
254 $params['content_type'] = 'text/html';
255 $title = _('Compact preview of local user');
256 $params['content'] = $this->display_user_html_compact_preview($username, $title);
262 function content_negociated_project_home (&$params) {
264 $projectname = $params['groupname'];
265 $accept = $params['accept'];
267 // if want some OSLC compact-preview, provide the document pointing to the compact-preview
268 case 'application/x-oslc-compact+xml' : {
269 $params['content_type'] = 'application/x-oslc-compact+xml';
270 $params['content'] = '<?xml version="1.0"?>
271 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc="http://open-services.net/ns/core#">
272 <oslc:Compact rdf:about="/plugins/oslc/compact/project/'. $projectname .'">
273 <dcterms:title>'. $projectname . '</dcterms:title>
274 <oslc:shortTitle>'. $projectname . '</oslc:shortTitle>
277 <oslc:document rdf:ressource="/plugins/'.$this->name.'/project.php?project='. $projectname .'"/>
278 <oslc:hintWidth>500px</oslc:hintWidth>
279 <oslc:hintHeight>150px</oslc:hintHeight>
286 // if want direct compact-preview rendering
287 case 'application/x-fusionforge-compact+html' : {
288 $params['content_type'] = 'text/html';
289 $title = _('Compact preview of local project');
290 $params['content'] = $this->display_project_html_compact_preview($projectname, $title);
299 // c-file-style: "bsd"