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)
164 function cloneContent($id, $owner_id, $owner_type) {
165 return $this->getInstanceId();
167 function create(&$request) {
169 function destroy($id) {
172 * getInstance - Returns an instance of a widget given its name
173 * @param string $widget_name
174 * @return Widget instance
176 static function & getInstance($widget_name) {
178 switch($widget_name) {
180 $o = new Widget_MySurveys();
183 $o = new Widget_MyProjects();
186 $o = new Widget_MyBookmarks();
188 case 'mymonitoredforums':
189 $o = new Widget_MyMonitoredForums();
191 case 'mymonitoreddocuments':
192 $o = new Widget_MyMonitoredDocuments();
194 case 'myprojectslastdocuments':
195 $o = new Widget_MyProjectsLastDocuments();
198 $o = new Widget_MyArtifacts();
201 $o = new Widget_MyRss();
204 $o = new Widget_MyTasks();
207 if (forge_check_global_perm('forge_admin')
208 || forge_check_global_perm('approve_projects')
209 || forge_check_global_perm('approve_news')) {
210 $o = new Widget_MyAdmin();
214 $o = new Widget_MySrs();
216 case 'mymonitoredfp':
217 $o = new Widget_MyMonitoredFp();
219 case 'mylatestsvncommits':
220 $o = new Widget_MyLatestSvnCommits();
223 $o = new Widget_MyBugs();
225 case 'mytwitterfollow':
226 $o = new Widget_MyTwitterFollow();
228 case 'mywikipage': //not yet
229 $o = new Widget_MyWikiPage();
231 case 'mysystemevent':
232 // This widget is only for super admin
233 if (forge_check_global_perm('forge_admin')) {
234 $o = new Widget_MySystemEvent();
237 case 'projectclassification':
238 $o = new Widget_ProjectClassification();
240 case 'projectdescription':
241 $o = new Widget_ProjectDescription();
243 case 'projectmembers':
244 $o = new Widget_ProjectMembers();
247 $o = new Widget_ProjectInfo();
249 case 'projectlatestfilereleases':
250 $o = new Widget_ProjectLatestFileReleases();
252 case 'projectlatestdocuments':
253 $o = new Widget_ProjectLatestDocuments();
255 case 'projectdocumentsactivity':
256 $o = new Widget_ProjectDocumentsActivity();
258 case 'projectlatestnews':
259 $o = new Widget_ProjectLatestNews();
261 case 'projectpublicareas':
262 $o = new Widget_ProjectPublicAreas();
265 $o = new Widget_ProjectRss();
267 case 'projecttwitterfollow':
268 $o = new Widget_ProjectTwitterFollow();
270 case 'projectsvnstats':
271 $o = new Widget_ProjectSvnStats();
273 //case 'projectwikipage': //not yet
274 // $o = new Widget_ProjectWikiPage();
276 case 'projectlatestsvncommits':
277 $o = new Widget_ProjectLatestSvnCommits();
279 case 'projectlatestcvscommits':
280 $o = new Widget_ProjectLatestCvsCommits();
283 //$em = EventManager::instance();
284 //$em->processEvent('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
285 // calls the plugin's hook to get an instance of the widget
286 plugin_hook('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
289 if (!$o || !($o instanceof Widget)) {
295 * getCodendiWidgets - Static
296 * @param unknown_type $owner_type
299 static function getCodendiWidgets($owner_type) {
300 switch ($owner_type) {
301 case WidgetLayoutManager::OWNER_TYPE_USER:
302 $widgets = array('myadmin', 'mysurveys', 'myprojects', 'mybookmarks',
303 'mymonitoredforums', 'mymonitoredfp', 'myartifacts', 'mybugs', //'mywikipage' //not yet
304 'mytasks', 'mysrs', 'mylatestsvncommits', 'mytwitterfollow',
305 'mysystemevent', 'myrss', 'mymonitoreddocuments', 'myprojectslastdocuments',
308 case WidgetLayoutManager::OWNER_TYPE_GROUP:
309 // project home widgets
310 $widgets = array('projectdescription', 'projectmembers', 'projectinfo',
311 'projectlatestfilereleases', 'projectlatestdocuments', 'projectlatestnews', 'projectpublicareas', //'projectwikipage' //not yet
312 'projectlatestsvncommits', 'projectlatestcvscommits', 'projecttwitterfollow',
313 'projectsvnstats', 'projectrss', 'projectdocumentsactivity',
316 case WidgetLayoutManager::OWNER_TYPE_HOME:
324 // add widgets of the plugins, declared through hooks
325 $plugins_widgets = array();
326 //$em =& EventManager::instance();
327 //$em->processEvent('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
328 plugin_hook('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
329 plugin_hook('widgets', array('fusionforge_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
331 if (is_array($plugins_widgets)) {
332 $widgets = array_merge($widgets, $plugins_widgets);
336 /* static */ function getExternalWidgets($owner_type) {
337 switch ($owner_type) {
338 case WidgetLayoutManager::OWNER_TYPE_USER:
342 case WidgetLayoutManager::OWNER_TYPE_GROUP:
346 case WidgetLayoutManager::OWNER_TYPE_HOME:
354 $plugins_widgets = array();
355 $em =& EventManager::instance();
356 $em->processEvent('widgets', array('external_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
358 if (is_array($plugins_widgets)) {
359 $widgets = array_merge($widgets, $plugins_widgets);
364 function getCategory() {
367 function getDescription() {
370 function getPreviewCssClass() {
371 $locale = UserManager::instance()->getCurrentUser()->getLanguage();
373 return 'widget-preview-'.($this->id).'-'.$locale;
375 function getAjaxUrl($owner_id, $owner_type) {
376 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=ajax&name['. $this->id .']='. $this->getInstanceId();
378 function getIframeUrl($owner_id, $owner_type) {
379 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=iframe&name['. $this->id .']='. $this->getInstanceId();