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 oslcPlugin extends Plugin {
25 public function __construct($id=0) {
28 $this->text = "oslc"; // To show in the tabs, use...
29 $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin
30 $this->_addHook("usermenu");
31 $this->_addHook("groupmenu"); // To put into the project tabs
32 $this->_addHook("groupisactivecheckbox"); // The "use ..." checkbox in editgroupinfo
33 $this->_addHook("groupisactivecheckboxpost"); //
34 $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account
35 $this->_addHook("userisactivecheckboxpost"); //
36 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
37 /* $this->_addHook("user_link_with_tooltip"); // override the way user links are done (for user compact preview support)
38 $this->_addHook("project_link_with_tooltip");
39 $this->_addHook("javascript_file"); // Add js files for oslc plugin
40 $this->_addHook("javascript"); // Add js initialization code
41 $this->_addHook("cssfile");
42 $this->_addHook("script_accepted_types");
43 $this->_addHook("content_negociated_user_home");
44 $this->_addHook("content_negociated_project_home");
46 $this->_addHook("project_rdf_metadata"); // will provide some RDF metadata for the project's DOAP profile to 'doaprdf' plugin
49 function CallHook ($hookname, &$params) {
50 global $use_oslcplugin,$G_SESSION,$HTML, $group_id;
51 if ($hookname == "usermenu") {
52 $text = $this->text; // this is what shows in the tab
53 if ($G_SESSION->usesPlugin("oslc")) {
54 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we're calling is the user one
55 echo $HTML->PrintSubMenu (array ($text),
56 array ('/plugins/oslc/index.php' . $param ));
58 } elseif ($hookname == "groupmenu") {
59 $group_id=$params['group'];
60 $project = &group_get_object($group_id);
61 if (!$project || !is_object($project)) {
64 if ($project->isError()) {
67 if (!$project->isProject()) {
70 if ( $project->usesPlugin ( $this->name ) ) {
71 $params['TITLES'][]=$this->text;
72 $params['DIRS'][]=util_make_uri('/plugins/oslc/');
73 $params['ADMIN'][]='';
75 $params['TITLES'][]=$this->text." is [Off]";
77 $params['ADMIN'][]='';
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_oslcplugin" 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_oslcplugin = getStringFromRequest('use_oslcplugin');
103 if ( $use_oslcplugin == 1 ) {
104 $group->setPluginUse ( $this->name );
106 $group->setPluginUse ( $this->name, false );
108 } elseif ($hookname == "userisactivecheckbox") {
109 //check if user is active
110 // this code creates the checkbox in the user account manteinance page to activate/deactivate the plugin
111 $user = $params['user'];
114 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
115 // checked or unchecked?
116 if ( $user->usesPlugin ( $this->name ) ) {
119 echo " /> Use ".$this->text." Plugin";
122 } elseif ($hookname == "userisactivecheckboxpost") {
123 // this code actually activates/deactivates the plugin after the form was submitted in the user account manteinance page
124 $user = $params['user'];
125 $use_oslcplugin = getStringFromRequest('use_oslcplugin');
126 if ( $use_oslcplugin == 1 ) {
127 $user->setPluginUse ( $this->name );
129 $user->setPluginUse ( $this->name, false );
133 echo ' <input type="checkbox" name="use_oslcplugin" value="1" ';
134 // checked or unchecked?
135 if ( $user->usesPlugin ( $this->name ) ) {
138 echo " /> Use ".$this->text." Plugin";
141 } elseif ($hookname == "user_personal_links") {
142 // this displays the link in the user's profile page to it's personal oslc (if you want other sto access it, youll have to change the permissions in the index.php
143 $userid = $params['user_id'];
144 $user = user_get_object($userid);
145 $text = $params['text'];
146 //check if the user has the plugin activated
147 if ($user->usesPlugin($this->name)) {
149 echo util_make_link ("/plugins/oslc/index.php?id=$userid&type=user&pluginname=".$this->name,
150 _('View Personal oslc')
154 } elseif ($hookname == "project_admin_plugins") {
155 // this displays the link in the project admin options page to it's oslc administration
156 $group_id = $params['group_id'];
157 $group = &group_get_object($group_id);
158 if ( $group->usesPlugin ( $this->name ) ) {
159 echo '<p>'.util_make_link ("/plugins/oslc/admin/index.php?id=".$group->getID().'&type=admin&pluginname='.$this->name,
160 _('oslc Admin')).'</p>' ;
164 elseif ($hookname == "user_link_with_tooltip"){
165 // override util_display_user() with modified version to display compact preview popup on user links
166 require_once dirname( __FILE__ ) . '/CompactResource.class.php';
167 $cR = CompactResource::createCompactResource($params);
168 $params['user_link'] = $cR->getResourceLink();
170 elseif ($hookname == "project_link_with_tooltip") {
171 require_once dirname( __FILE__ ) . '/CompactResource.class.php';
172 $cR = CompactResource::createCompactResource($params);
173 $params['group_link'] = $cR->getResourceLink();
175 elseif ($hookname == "javascript_file") {
176 // The userTooltip.js script is used by the compact preview feature (see content_negociated_user_home)
177 use_javascript('/scripts/jquery/jquery.js');
178 // provides support for the popup for compact preview
179 use_javascript('/plugins/oslc/scripts/oslcTooltip.js');
181 elseif ($hookname == "javascript") {
182 // make sure jquery won't conflict with prototype
183 $params['return'] = 'jQuery.noConflict();';
185 elseif ($hookname == "cssfile") {
186 use_stylesheet('/plugins/oslc/css/oslcTooltipStyle.css');
188 elseif($hookname == "script_accepted_types"){
189 $script = $params['script'];
190 if ($script == 'user_home' || $script == 'project_home') {
191 $params['accepted_types'][] = 'application/x-oslc-compact+xml';
194 elseif($hookname == "content_negociated_user_home") {
195 $username = $params['username'];
196 $accept = $params['accept'];
197 if($accept == 'application/x-oslc-compact+xml') {
198 $params['content_type'] = 'application/x-oslc-compact+xml';
199 $params['content'] = '<?xml version="1.0"?>
200 <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#">
201 <oslc:Compact rdf:about="/plugins/oslc/compact/user/'. $username .'">
202 <dcterms:title>'. $username . '</dcterms:title>
203 <oslc:shortTitle>'. $username . '</oslc:shortTitle>
206 <oslc:document rdf:ressource="/plugins/oslc/compact/user/'. $username .'/type/small"/>
207 <oslc:hintWidth>500px</oslc:hintWidth>
208 <oslc:hintHeight>150px</oslc:hintHeight>
215 elseif($hookname == "content_negociated_project_home") {
216 $projectname = $params['groupname'];
217 $accept = $params['accept'];
218 if($accept == 'application/x-oslc-compact+xml') {
219 $params['content_type'] = 'application/x-oslc-compact+xml';
220 $params['content'] = '<?xml version="1.0"?>
221 <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#">
222 <oslc:Compact rdf:about="/plugins/oslc/compact/project/'. $projectname .'">
223 <dcterms:title>'. $projectname . '</dcterms:title>
224 <oslc:shortTitle>'. $projectname . '</oslc:shortTitle>
227 <oslc:document rdf:ressource="/plugins/oslc/compact/project/'. $projectname .'/type/small"/>
228 <oslc:hintWidth>500px</oslc:hintWidth>
229 <oslc:hintHeight>150px</oslc:hintHeight>
236 elseif($hookname == "project_rdf_metadata") {
238 $serviceprovider = util_make_url ("/plugins/oslc/cm/oslc-cm-services/".$group_id);
240 if (! $params['prefixes']['http://open-services.net/ns/core#']) {
241 $params['prefixes']['http://open-services.net/ns/core#'] = 'oslc';
243 $params['xml'][] = '<oslc:serviceProvider rdf:resource="'.$serviceprovider.'"/>';
245 elseif ($hookname == "blahblahblah") {
253 // c-file-style: "bsd"