3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once('common/widget/WidgetLayoutManager.class.php');
23 require_once('common/widget/Widget_MySurveys.class.php');
24 require_once('common/widget/Widget_MyProjects.class.php');
25 require_once('common/widget/Widget_MyBookmarks.class.php');
26 require_once('common/widget/Widget_MyMonitoredForums.class.php');
27 //require_once('common/widget/Widget_MyMonitoredFp.class.php');
28 require_once('common/widget/Widget_MyLatestSvnCommits.class.php');
29 require_once('common/widget/Widget_MyProjectsLastDocuments.class.php');
30 require_once('common/widget/Widget_MyArtifacts.class.php');
31 //require_once('common/widget/Widget_MyBugs.class.php');
32 //require_once('common/widget/Widget_MySrs.class.php');
33 require_once('common/widget/Widget_MyTasks.class.php');
34 require_once('common/widget/Widget_MyRss.class.php');
36 require_once('common/widget/Widget_MyAdmin.class.php');
38 require_once('common/widget/Widget_MyTwitterFollow.class.php');
39 require_once('common/widget/Widget_MySystemEvent.class.php');
40 //require_once('common/widget/Widget_MyWikiPage.class.php');
41 */require_once('common/widget/Widget_ProjectDescription.class.php');
42 //require_once('common/widget/Widget_ProjectClassification.class.php');
44 require_once('common/widget/Widget_ProjectMembers.class.php');
45 require_once('common/widget/Widget_ProjectInfo.class.php');
46 require_once('common/widget/Widget_ProjectLatestFileReleases.class.php');
47 require_once('common/widget/Widget_ProjectLatestDocuments.class.php');
49 require_once('common/widget/Widget_ProjectLatestNews.class.php');
50 require_once('common/widget/Widget_ProjectPublicAreas.class.php');
51 require_once('common/widget/Widget_ProjectRss.class.php');/*
52 require_once('common/widget/Widget_ProjectLatestSvnCommits.class.php');
53 require_once('common/widget/Widget_ProjectLatestCvsCommits.class.php');
54 require_once('common/widget/Widget_ProjectTwitterFollow.class.php');
55 //require_once('common/widget/Widget_ProjectWikiPage.class.php');
56 require_once('common/widget/Widget_ProjectSvnStats.class.php');
59 require_once('common/widget/Widget_MyMonitoredDocuments.class.php');
62 * "Codendi" Layout Widget
66 /* abstract */ class Widget {
77 function Widget($id) {
79 $this->content_id = 0;
82 function display($layout_id, $column_id, $readonly, $is_minimized, $display_preferences, $owner_id, $owner_type) {
83 $GLOBALS['HTML']->widget($this, $layout_id, $readonly, $column_id, $is_minimized, $display_preferences, $owner_id, $owner_type);
89 * TODO : Enter description here ...
92 function getContent() {
95 function getPreferencesForm($layout_id, $owner_id, $owner_type) {
97 $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 .'">';
98 $prefs .= '<fieldset><legend>'. _("Preferences") .'</legend>';
99 $prefs .= $this->getPreferences();
101 $prefs .= '<input type="submit" name="cancel" value="'. _("Cancel") .'" /> ';
102 $prefs .= '<input type="submit" value="'. _("Submit") .'" />';
103 $prefs .= '</fieldset>';
107 function getInstallPreferences() {
110 function getPreferences() {
113 function hasPreferences() {
116 function hasButtons() {
119 function updatePreferences(&$request) {
125 function getRssUrl($owner_id, $owner_type) {
126 if ($this->hasRss()) {
127 return '/widgets/widget.php?owner='.$owner_type.$owner_id.'&action=rss&name['. $this->id .']='. $this->getInstanceId();
132 function isUnique() {
135 function isAvailable() {
141 function getInstanceId() {
142 return $this->content_id;
144 function loadContent($id) {
146 function setOwner($owner_id, $owner_type) {
147 $this->owner_id = $owner_id;
148 $this->owner_type = $owner_type;
150 function canBeUsedByProject(&$project) {
156 * Take the content of a widget, clone it and return the id of the new content
158 * @param $id the id of the content to clone
159 * @param $owner_id the owner of the widget of the new widget
160 * @param $owner_type the type of the owner of the new widget (see WidgetLayoutManager)
162 function cloneContent($id, $owner_id, $owner_type) {
163 return $this->getInstanceId();
165 function create(&$request) {
167 function destroy($id) {
170 * getInstance - Returns an instance of a widget given its name
171 * @param string $widget_name
172 * @return Widget instance
174 static function & getInstance($widget_name) {
176 switch($widget_name) {
178 $o = new Widget_MySurveys();
181 $o = new Widget_MyProjects();
184 $o = new Widget_MyBookmarks();
186 case 'mymonitoredforums':
187 $o = new Widget_MyMonitoredForums();
189 case 'mymonitoreddocuments':
190 $o = new Widget_MyMonitoredDocuments();
192 case 'myprojectslastdocuments':
193 $o = new Widget_MyProjectsLastDocuments();
196 $o = new Widget_MyArtifacts();
199 $o = new Widget_MyRss();
202 $o = new Widget_MyTasks();
205 if (forge_check_global_perm('forge_admin')
206 || forge_check_global_perm('approve_projects')
207 || forge_check_global_perm('approve_news')) {
208 $o = new Widget_MyAdmin();
212 $o = new Widget_MySrs();
214 case 'mymonitoredfp':
215 $o = new Widget_MyMonitoredFp();
217 case 'mylatestsvncommits':
218 $o = new Widget_MyLatestSvnCommits();
221 $o = new Widget_MyBugs();
223 case 'mytwitterfollow':
224 $o = new Widget_MyTwitterFollow();
226 case 'mywikipage': //not yet
227 $o = new Widget_MyWikiPage();
229 case 'mysystemevent':
230 // This widget is only for super admin
231 if (forge_check_global_perm('forge_admin')) {
232 $o = new Widget_MySystemEvent();
235 case 'projectclassification':
236 $o = new Widget_ProjectClassification();
238 case 'projectdescription':
239 $o = new Widget_ProjectDescription();
241 case 'projectmembers':
242 $o = new Widget_ProjectMembers();
245 $o = new Widget_ProjectInfo();
247 case 'projectlatestfilereleases':
248 $o = new Widget_ProjectLatestFileReleases();
250 case 'projectlatestdocuments':
251 $o = new Widget_ProjectLatestDocuments();
253 case 'projectlatestnews':
254 $o = new Widget_ProjectLatestNews();
256 case 'projectpublicareas':
257 $o = new Widget_ProjectPublicAreas();
260 $o = new Widget_ProjectRss();
262 case 'projecttwitterfollow':
263 $o = new Widget_ProjectTwitterFollow();
265 case 'projectsvnstats':
266 $o = new Widget_ProjectSvnStats();
268 //case 'projectwikipage': //not yet
269 // $o = new Widget_ProjectWikiPage();
271 case 'projectlatestsvncommits':
272 $o = new Widget_ProjectLatestSvnCommits();
274 case 'projectlatestcvscommits':
275 $o = new Widget_ProjectLatestCvsCommits();
278 //$em = EventManager::instance();
279 //$em->processEvent('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
280 // calls the plugin's hook to get an instance of the widget
281 plugin_hook('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
284 if (!$o || !($o instanceof Widget)) {
290 * getCodendiWidgets - Static
291 * @param unknown_type $owner_type
294 static function getCodendiWidgets($owner_type) {
295 switch ($owner_type) {
296 case WidgetLayoutManager::OWNER_TYPE_USER:
297 $widgets = array('myadmin', 'mysurveys', 'myprojects', 'mybookmarks',
298 'mymonitoredforums', 'mymonitoredfp', 'myartifacts', 'mybugs', //'mywikipage' //not yet
299 'mytasks', 'mysrs', 'mylatestsvncommits', 'mytwitterfollow',
300 'mysystemevent', 'myrss', 'mymonitoreddocuments', 'myprojectslastdocuments',
303 case WidgetLayoutManager::OWNER_TYPE_GROUP:
304 // project home widgets
305 $widgets = array('projectdescription', 'projectmembers', 'projectinfo',
306 'projectlatestfilereleases', 'projectlatestdocuments', 'projectlatestnews', 'projectpublicareas', //'projectwikipage' //not yet
307 'projectlatestsvncommits', 'projectlatestcvscommits', 'projecttwitterfollow',
308 'projectsvnstats', 'projectrss',
311 case WidgetLayoutManager::OWNER_TYPE_HOME:
319 // add widgets of the plugins, declared through hooks
320 $plugins_widgets = array();
321 //$em =& EventManager::instance();
322 //$em->processEvent('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
323 plugin_hook('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
324 plugin_hook('widgets', array('fusionforge_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
326 if (is_array($plugins_widgets)) {
327 $widgets = array_merge($widgets, $plugins_widgets);
331 /* static */ function getExternalWidgets($owner_type) {
332 switch ($owner_type) {
333 case WidgetLayoutManager::OWNER_TYPE_USER:
337 case WidgetLayoutManager::OWNER_TYPE_GROUP:
341 case WidgetLayoutManager::OWNER_TYPE_HOME:
349 $plugins_widgets = array();
350 $em =& EventManager::instance();
351 $em->processEvent('widgets', array('external_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
353 if (is_array($plugins_widgets)) {
354 $widgets = array_merge($widgets, $plugins_widgets);
359 function getCategory() {
362 function getDescription() {
365 function getPreviewCssClass() {
366 $locale = UserManager::instance()->getCurrentUser()->getLanguage();
368 return 'widget-preview-'.($this->id).'-'.$locale;
370 function getAjaxUrl($owner_id, $owner_type) {
371 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=ajax&name['. $this->id .']='. $this->getInstanceId();
373 function getIframeUrl($owner_id, $owner_type) {
374 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=iframe&name['. $this->id .']='. $this->getInstanceId();