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 {
25 public function __construct($id=0) {
27 $this->name = "compactpreview";
28 $this->text = "CompactPreview!"; // To show in the tabs, use...
30 $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
31 $this->_addHook("usermenu");
32 $this->_addHook("groupmenu"); // To put into the project tabs
33 $this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
34 $this->_addHook("groupisactivecheckboxpost"); //
35 $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
36 $this->_addHook("userisactivecheckboxpost"); //
37 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
39 $this->_addHook("user_link_with_tooltip"); // override the way user links are done (for user compact preview support)
40 $this->_addHook("project_link_with_tooltip");
41 $this->_addHook("javascript_file"); // Add js files for oslc plugin
42 $this->_addHook("javascript"); // Add js initialization code
43 $this->_addHook("cssfile");
44 $this->_addHook("script_accepted_types");
45 $this->_addHook("content_negociated_user_home");
46 $this->_addHook("content_negociated_project_home");
50 function CallHook ($hookname, &$params) {
51 global $use_compactpreviewplugin,$G_SESSION,$HTML;
52 if ($hookname == "usermenu") {
53 $text = $this->text; // this is what shows in the tab
54 if ($G_SESSION->usesPlugin("compactpreview")) {
55 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
56 echo $HTML->PrintSubMenu (array ($text),
57 array ('/plugins/compactpreview/index.php' . $param ));
60 } elseif ($hookname == "groupmenu") {
61 $group_id=$params['group'];
62 $project = &group_get_object($group_id);
63 if (!$project || !is_object($project)) {
66 if ($project->isError()) {
69 if (!$project->isProject()) {
72 if ( $project->usesPlugin ( $this->name ) ) {
73 $params['TITLES'][]=$this->text;
74 $params['DIRS'][]=util_make_url ('/plugins/compactpreview/index.php?type=group&id=' . $group_id . "&pluginname=" . $this->name) ; // we indicate the part we're calling is the project one
76 $params['TITLES'][]=$this->text." is [Off]";
79 (($params['toptab'] == $this->name) ? $params['selected']=(count($params['TITLES'])-1) : '' );
80 } elseif ($hookname == "groupisactivecheckbox") {
81 //Check if the group is active
82 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
83 $group_id=$params['group'];
84 $group = &group_get_object($group_id);
87 echo ' <input type="checkbox" name="use_compactpreviewplugin" value="1" ';
88 // checked or unchecked?
89 if ( $group->usesPlugin ( $this->name ) ) {
95 echo "<strong>Use ".$this->text." Plugin</strong>";
98 } elseif ($hookname == "groupisactivecheckboxpost") {
99 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
100 $group_id=$params['group'];
101 $group = &group_get_object($group_id);
102 $use_compactpreviewplugin = getStringFromRequest('use_compactpreviewplugin');
103 if ( $use_compactpreviewplugin == 1 ) {
104 $group->setPluginUse ( $this->name );
106 $group->setPluginUse ( $this->name, false );
108 } elseif ($hookname == "user_personal_links") {
109 // this displays the link in the user's profile page to it's personal CompactPreview (if you want other sto access it, youll have to change the permissions in the index.php
110 $userid = $params['user_id'];
111 $user = user_get_object($userid);
112 $text = $params['text'];
113 //check if the user has the plugin activated
114 if ($user->usesPlugin($this->name)) {
116 echo util_make_link ("/plugins/compactpreview/index.php?id=$userid&type=user&pluginname=".$this->name,
117 _('View Personal CompactPreview')
121 } elseif ($hookname == "project_admin_plugins") {
122 // this displays the link in the project admin options page to it's CompactPreview administration
123 $group_id = $params['group_id'];
124 $group = &group_get_object($group_id);
125 if ( $group->usesPlugin ( $this->name ) ) {
126 echo '<p>'.util_make_link ("/plugins/compactpreview/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
127 _('CompactPreview Admin')).'</p>' ;
130 elseif ($hookname == "blahblahblah") {
135 function user_link_with_tooltip (&$params) {
136 // override util_display_user() with modified version to display compact preview popup on user links
137 require_once dirname( __FILE__ ) . '/CompactResource.class.php';
138 $cR = CompactResource::createCompactResource($params);
139 $params['user_link'] = $cR->getResourceLink();
141 function project_link_with_tooltip (&$params) {
142 require_once dirname( __FILE__ ) . '/CompactResource.class.php';
143 $cR = CompactResource::createCompactResource($params);
144 $params['group_link'] = $cR->getResourceLink();
146 function javascript_file (&$params) {
147 // The userTooltip.js script is used by the compact preview feature (see content_negociated_user_home)
148 use_javascript('/scripts/jquery/jquery.js');
149 // provides support for the popup for compact preview
150 use_javascript('/plugins/'.$this->name.'/scripts/oslcTooltip.js');
152 function javascript (&$params) {
153 // make sure jquery won't conflict with prototype
154 $params['return'] = 'jQuery.noConflict();';
156 function cssfile (&$params) {
157 use_stylesheet('/plugins/'.$this->name.'/css/oslcTooltipStyle.css');
159 function script_accepted_types (&$params) {
160 $script = $params['script'];
161 if ($script == 'user_home' || $script == 'project_home') {
162 $params['accepted_types'][] = 'application/x-oslc-compact+xml';
165 function content_negociated_user_home (&$params) {
167 $username = $params['username'];
168 $accept = $params['accept'];
169 if($accept == 'application/x-oslc-compact+xml') {
170 $params['content_type'] = 'application/x-oslc-compact+xml';
171 $params['content'] = '<?xml version="1.0"?>
172 <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#">
173 <oslc:Compact rdf:about="/plugins/oslc/compact/user/'. $username .'">
174 <dcterms:title>'. $username . '</dcterms:title>
175 <oslc:shortTitle>'. $username . '</oslc:shortTitle>
178 <oslc:document rdf:ressource="/plugins/'.$this->name.'/user.php?user='. $username .'"/>
179 <oslc:hintWidth>500px</oslc:hintWidth>
180 <oslc:hintHeight>150px</oslc:hintHeight>
187 function content_negociated_project_home (&$params) {
189 $projectname = $params['groupname'];
190 $accept = $params['accept'];
191 if($accept == 'application/x-oslc-compact+xml') {
192 $params['content_type'] = 'application/x-oslc-compact+xml';
193 $params['content'] = '<?xml version="1.0"?>
194 <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#">
195 <oslc:Compact rdf:about="/plugins/oslc/compact/project/'. $projectname .'">
196 <dcterms:title>'. $projectname . '</dcterms:title>
197 <oslc:shortTitle>'. $projectname . '</oslc:shortTitle>
200 <oslc:document rdf:ressource="/plugins/'.$this->name.'/compact/project/'. $projectname .'/type/small"/>
201 <oslc:hintWidth>500px</oslc:hintWidth>
202 <oslc:hintHeight>150px</oslc:hintHeight>
215 // c-file-style: "bsd"