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)
66 use_javascript('/scripts/jquery/jquery.js');
67 // provides support for the popup for compact preview
68 use_javascript('/plugins/'.$this->name.'/scripts/oslcTooltip.js');
70 function javascript (&$params) {
71 // make sure jquery won't conflict with prototype
72 $params['return'] = 'jQuery.noConflict();';
74 function cssfile (&$params) {
75 use_stylesheet('/plugins/'.$this->name.'/css/oslcTooltipStyle.css');
79 * Declaration of which content-negociation alternatives are provided by this plugin
80 * @param unknown_type $params
82 function script_accepted_types (&$params) {
83 $script = $params['script'];
84 if ($script == 'user_home' || $script == 'project_home') {
85 // we do support content-negociation on /users and /project with the following accept header values
86 // for OSLC compact-preview
87 $params['accepted_types'][] = 'application/x-oslc-compact+xml';
88 // for fusionforge compact preview
89 $params['accepted_types'][] = 'application/x-fusionforge-compact+html';
93 function display_user_html_compact_preview($username, $title = false) {
96 require_once $gfwww.'include/user_profile.php';
98 $user_obj = user_get_object_by_name($username);
101 $user_real_name = $user_obj->getRealName();
102 $user_id = $user_obj->getID();
106 <title>User: '. $user_real_name .' (Identifier: '. $user_id .')</title>
110 $html .= user_personal_information($user_obj, $compact, $title);
118 function display_project_html_compact_preview($project, $title) {
120 $project_obj = group_get_object_by_name($project);
122 $public_name = $project_obj->getPublicName();
123 $unix_name = $project_obj->getUnixName();
124 $id = $project_obj->getID();
125 $home_page = util_make_url ("/projects/$unix_name/");
126 $description = $project_obj->getDescription();
127 $start_date = $project_obj->getStartDate();
128 $status = $project_obj->getStatus();
131 $project_status = 'Active';
134 $project_status = 'Hold';
137 $project_status = 'Pending';
140 $project_status = 'Incomplete';
145 if ($project_obj->isPublic()) {
153 <title>Project: '. $public_name .' ('. $unix_name .')</title>
159 <td colspan="2"><i>'. $title .'</i></td>
162 '/* <td rowspan="8"><img src="/plugins/compactpreview/images/userTooltip/oslc.png" />
164 <td><b>Project name:</b>
168 '. $public_name .'</td>
171 <td><b>Project short name:</b>
175 '. $unix_name .'</td>
178 <td><b>Identifier:</b>
185 <td><b>Started since:</b>
189 '. date(_('Y-m-d H:i'), $start_date) .'</td>
196 '. $project_status .'</td>
199 <td><b>Is Public:</b>
206 <td><b>Description:</b>
210 '. $description .'</td>
213 <td><small><b>Home Page:</b> <a href="'. $home_page .'">'. $home_page .'
225 function content_negociated_user_home (&$params) {
227 $username = $params['username'];
228 $accept = $params['accept'];
229 $param['content'] = false;
232 // if want some OSLC compact-preview, provide the document pointing to the compact-preview
233 case 'application/x-oslc-compact+xml' : {
234 $params['content_type'] = 'application/x-oslc-compact+xml';
235 $params['content'] = '<?xml version="1.0"?>
236 <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#">
237 <oslc:Compact rdf:about="/plugins/oslc/compact/user/'. $username .'">
238 <dcterms:title>'. $username . '</dcterms:title>
239 <oslc:shortTitle>'. $username . '</oslc:shortTitle>
242 <oslc:document rdf:ressource="/plugins/'.$this->name.'/user.php?user='. $username .'"/>
243 <oslc:hintWidth>500px</oslc:hintWidth>
244 <oslc:hintHeight>150px</oslc:hintHeight>
251 // if want direct compact-preview rendering
252 case 'application/x-fusionforge-compact+html' : {
253 $params['content_type'] = 'text/html';
254 $title = _('Compact preview of local user');
255 $params['content'] = $this->display_user_html_compact_preview($username, $title);
261 function content_negociated_project_home (&$params) {
263 $projectname = $params['groupname'];
264 $accept = $params['accept'];
266 // if want some OSLC compact-preview, provide the document pointing to the compact-preview
267 case 'application/x-oslc-compact+xml' : {
268 $params['content_type'] = 'application/x-oslc-compact+xml';
269 $params['content'] = '<?xml version="1.0"?>
270 <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#">
271 <oslc:Compact rdf:about="/plugins/oslc/compact/project/'. $projectname .'">
272 <dcterms:title>'. $projectname . '</dcterms:title>
273 <oslc:shortTitle>'. $projectname . '</oslc:shortTitle>
276 <oslc:document rdf:ressource="/plugins/'.$this->name.'/project.php?project='. $projectname .'"/>
277 <oslc:hintWidth>500px</oslc:hintWidth>
278 <oslc:hintHeight>150px</oslc:hintHeight>
285 // if want direct compact-preview rendering
286 case 'application/x-fusionforge-compact+html' : {
287 $params['content_type'] = 'text/html';
288 $title = _('Compact preview of local project');
289 $params['content'] = $this->display_project_html_compact_preview($projectname, $title);
298 // c-file-style: "bsd"