3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2012, Franck Villaume - TrivialDev
6 * This file is a part of Fusionforge.
8 * Fusionforge 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.
13 * Fusionforge 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.
18 * You should have received a copy of the GNU General Public License
19 * along with Fusionforge. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'common/widget/WidgetLayoutManager.class.php';
24 require_once 'common/widget/Widget_MySurveys.class.php';
25 require_once 'common/widget/Widget_MyProjects.class.php';
26 require_once 'common/widget/Widget_MyBookmarks.class.php';
27 require_once 'common/widget/Widget_MyMonitoredForums.class.php';
28 //require_once('common/widget/Widget_MyMonitoredFp.class.php');
29 require_once 'common/widget/Widget_MyLatestSvnCommits.class.php';
30 require_once 'common/widget/Widget_MyProjectsLastDocuments.class.php';
31 require_once 'common/widget/Widget_MyArtifacts.class.php';
32 //require_once('common/widget/Widget_MyBugs.class.php');
33 //require_once('common/widget/Widget_MySrs.class.php');
34 require_once 'common/widget/Widget_MyTasks.class.php';
35 require_once 'common/widget/Widget_MyRss.class.php';
37 require_once 'common/widget/Widget_MyAdmin.class.php';
39 require_once 'common/widget/Widget_MyTwitterFollow.class.php';
40 require_once 'common/widget/Widget_MySystemEvent.class.php';
41 //require_once('common/widget/Widget_MyWikiPage.class.php');
42 */require_once('common/widget/Widget_ProjectDescription.class.php');
43 //require_once('common/widget/Widget_ProjectClassification.class.php');
45 require_once 'common/widget/Widget_ProjectMembers.class.php';
46 require_once 'common/widget/Widget_ProjectInfo.class.php';
47 require_once 'common/widget/Widget_ProjectLatestFileReleases.class.php';
48 require_once 'common/widget/Widget_ProjectLatestDocuments.class.php';
49 require_once('common/widget/Widget_ProjectDocumentsActivity.class.php');
51 require_once 'common/widget/Widget_ProjectLatestNews.class.php';
52 require_once 'common/widget/Widget_ProjectPublicAreas.class.php';
53 require_once 'common/widget/Widget_ProjectRss.class.php';/*
54 require_once 'common/widget/Widget_ProjectLatestSvnCommits.class.php';
55 require_once 'common/widget/Widget_ProjectLatestCvsCommits.class.php';
56 require_once 'common/widget/Widget_ProjectTwitterFollow.class.php';
57 //require_once('common/widget/Widget_ProjectWikiPage.class.php');
58 require_once 'common/widget/Widget_ProjectSvnStats.class.php';
61 require_once 'common/widget/Widget_MyMonitoredDocuments.class.php';
64 * "Codendi" Layout Widget
68 /* abstract */ class Widget {
79 function Widget($id) {
81 $this->content_id = 0;
84 function display($layout_id, $column_id, $readonly, $is_minimized, $display_preferences, $owner_id, $owner_type) {
85 $GLOBALS['HTML']->widget($this, $layout_id, $readonly, $column_id, $is_minimized, $display_preferences, $owner_id, $owner_type);
91 * TODO : Enter description here ...
94 function getContent() {
97 function getPreferencesForm($layout_id, $owner_id, $owner_type) {
99 $prefs .= '<form method="post" action="/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=update&name['. $this->id .']='. $this->getInstanceId() .'&content_id='. $this->getInstanceId() .'&layout_id='. $layout_id .'">';
100 $prefs .= '<fieldset><legend>'. _("Preferences") .'</legend>';
101 $prefs .= $this->getPreferences();
103 $prefs .= '<input type="submit" name="cancel" value="'. _("Cancel") .'" /> ';
104 $prefs .= '<input type="submit" value="'. _("Submit") .'" />';
105 $prefs .= '</fieldset>';
109 function getInstallPreferences() {
112 function getPreferences() {
115 function hasPreferences() {
118 function hasButtons() {
121 function updatePreferences(&$request) {
127 function getRssUrl($owner_id, $owner_type) {
128 if ($this->hasRss()) {
129 return '/widgets/widget.php?owner='.$owner_type.$owner_id.'&action=rss&name['. $this->id .']='. $this->getInstanceId();
134 function isUnique() {
137 function isAvailable() {
143 function getInstanceId() {
144 return $this->content_id;
146 function loadContent($id) {
148 function setOwner($owner_id, $owner_type) {
149 $this->owner_id = $owner_id;
150 $this->owner_type = $owner_type;
152 function canBeUsedByProject(&$project) {
158 * Take the content of a widget, clone it and return the id of the new content
160 * @param $id the id of the content to clone
161 * @param $owner_id the owner of the widget of the new widget
162 * @param $owner_type the type of the owner of the new widget (see WidgetLayoutManager)
165 function cloneContent($id, $owner_id, $owner_type) {
166 return $this->getInstanceId();
168 function create(&$request) {
170 function destroy($id) {
173 * getInstance - Returns an instance of a widget given its name
174 * @param string $widget_name
175 * @return Widget instance
177 static function & getInstance($widget_name) {
179 switch($widget_name) {
181 $o = new Widget_MySurveys();
184 $o = new Widget_MyProjects();
187 $o = new Widget_MyBookmarks();
189 case 'mymonitoredforums':
190 $o = new Widget_MyMonitoredForums();
192 case 'mymonitoreddocuments':
193 $o = new Widget_MyMonitoredDocuments();
195 case 'myprojectslastdocuments':
196 $o = new Widget_MyProjectsLastDocuments();
199 $o = new Widget_MyArtifacts();
202 $o = new Widget_MyRss();
205 $o = new Widget_MyTasks();
208 if (forge_check_global_perm('forge_admin')
209 || forge_check_global_perm('approve_projects')
210 || forge_check_global_perm('approve_news')) {
211 $o = new Widget_MyAdmin();
215 $o = new Widget_MySrs();
217 case 'mymonitoredfp':
218 $o = new Widget_MyMonitoredFp();
220 case 'mylatestsvncommits':
221 $o = new Widget_MyLatestSvnCommits();
224 $o = new Widget_MyBugs();
226 case 'mytwitterfollow':
227 $o = new Widget_MyTwitterFollow();
229 case 'mywikipage': //not yet
230 $o = new Widget_MyWikiPage();
232 case 'mysystemevent':
233 // This widget is only for super admin
234 if (forge_check_global_perm('forge_admin')) {
235 $o = new Widget_MySystemEvent();
238 case 'projectclassification':
239 $o = new Widget_ProjectClassification();
241 case 'projectdescription':
242 $o = new Widget_ProjectDescription();
244 case 'projectmembers':
245 $o = new Widget_ProjectMembers();
248 $o = new Widget_ProjectInfo();
250 case 'projectlatestfilereleases':
251 $o = new Widget_ProjectLatestFileReleases();
253 case 'projectlatestdocuments':
254 $o = new Widget_ProjectLatestDocuments();
256 case 'projectdocumentsactivity':
257 $o = new Widget_ProjectDocumentsActivity();
259 case 'projectlatestnews':
260 $o = new Widget_ProjectLatestNews();
262 case 'projectpublicareas':
263 $o = new Widget_ProjectPublicAreas();
266 $o = new Widget_ProjectRss();
268 case 'projecttwitterfollow':
269 $o = new Widget_ProjectTwitterFollow();
271 case 'projectsvnstats':
272 $o = new Widget_ProjectSvnStats();
274 //case 'projectwikipage': //not yet
275 // $o = new Widget_ProjectWikiPage();
277 case 'projectlatestsvncommits':
278 $o = new Widget_ProjectLatestSvnCommits();
280 case 'projectlatestcvscommits':
281 $o = new Widget_ProjectLatestCvsCommits();
284 //$em = EventManager::instance();
285 //$em->processEvent('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
286 // calls the plugin's hook to get an instance of the widget
287 plugin_hook('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
290 if (!$o || !($o instanceof Widget)) {
296 * getCodendiWidgets - Static
297 * @param unknown_type $owner_type
300 static function getCodendiWidgets($owner_type) {
301 switch ($owner_type) {
302 case WidgetLayoutManager::OWNER_TYPE_USER:
303 $widgets = array('myadmin', 'mysurveys', 'myprojects', 'mybookmarks',
304 'mymonitoredforums', 'mymonitoredfp', 'myartifacts', 'mybugs', //'mywikipage' //not yet
305 'mytasks', 'mysrs', 'mylatestsvncommits', 'mytwitterfollow',
306 'mysystemevent', 'myrss', 'mymonitoreddocuments', 'myprojectslastdocuments',
309 case WidgetLayoutManager::OWNER_TYPE_GROUP:
310 // project home widgets
311 $widgets = array('projectdescription', 'projectmembers', 'projectinfo',
312 'projectlatestfilereleases', 'projectlatestdocuments', 'projectlatestnews', 'projectpublicareas', //'projectwikipage' //not yet
313 'projectlatestsvncommits', 'projectlatestcvscommits', 'projecttwitterfollow',
314 'projectsvnstats', 'projectrss', 'projectdocumentsactivity',
317 case WidgetLayoutManager::OWNER_TYPE_HOME:
325 // add widgets of the plugins, declared through hooks
326 $plugins_widgets = array();
327 //$em =& EventManager::instance();
328 //$em->processEvent('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
329 plugin_hook('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
330 plugin_hook('widgets', array('fusionforge_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
332 if (is_array($plugins_widgets)) {
333 $widgets = array_merge($widgets, $plugins_widgets);
337 /* static */ function getExternalWidgets($owner_type) {
338 switch ($owner_type) {
339 case WidgetLayoutManager::OWNER_TYPE_USER:
343 case WidgetLayoutManager::OWNER_TYPE_GROUP:
347 case WidgetLayoutManager::OWNER_TYPE_HOME:
355 $plugins_widgets = array();
356 $em =& EventManager::instance();
357 $em->processEvent('widgets', array('external_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
359 if (is_array($plugins_widgets)) {
360 $widgets = array_merge($widgets, $plugins_widgets);
365 function getCategory() {
368 function getDescription() {
371 function getPreviewCssClass() {
372 $locale = UserManager::instance()->getCurrentUser()->getLanguage();
374 return 'widget-preview-'.($this->id).'-'.$locale;
376 function getAjaxUrl($owner_id, $owner_type) {
377 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=ajax&name['. $this->id .']='. $this->getInstanceId();
379 function getIframeUrl($owner_id, $owner_type) {
380 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=iframe&name['. $this->id .']='. $this->getInstanceId();