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_MyArtifacts.class.php');
30 //require_once('common/widget/Widget_MyBugs.class.php');
31 //require_once('common/widget/Widget_MySrs.class.php');
32 //require_once('common/widget/Widget_MyTasks.class.php');
33 require_once('common/widget/Widget_MyRss.class.php');
35 require_once('common/widget/Widget_MyAdmin.class.php');
37 require_once('common/widget/Widget_MyTwitterFollow.class.php');
38 require_once('common/widget/Widget_MySystemEvent.class.php');
39 //require_once('common/widget/Widget_MyWikiPage.class.php');
40 require_once('common/widget/Widget_ProjectDescription.class.php');
41 require_once('common/widget/Widget_ProjectClassification.class.php');
42 require_once('common/widget/Widget_ProjectMembers.class.php');
43 require_once('common/widget/Widget_ProjectLatestFileReleases.class.php');
44 require_once('common/widget/Widget_ProjectLatestNews.class.php');
45 require_once('common/widget/Widget_ProjectPublicAreas.class.php');*/
46 require_once('common/widget/Widget_ProjectRss.class.php');/*
47 require_once('common/widget/Widget_ProjectLatestSvnCommits.class.php');
48 require_once('common/widget/Widget_ProjectLatestCvsCommits.class.php');
49 require_once('common/widget/Widget_ProjectTwitterFollow.class.php');
50 //require_once('common/widget/Widget_ProjectWikiPage.class.php');
51 require_once('common/widget/Widget_ProjectSvnStats.class.php');
57 /* abstract */ class Widget {
67 function Widget($id) {
69 $this->content_id = 0;
72 function display($layout_id, $column_id, $readonly, $is_minimized, $display_preferences, $owner_id, $owner_type) {
73 $GLOBALS['HTML']->widget($this, $layout_id, $readonly, $column_id, $is_minimized, $display_preferences, $owner_id, $owner_type);
78 function getContent() {
81 function getPreferencesForm($layout_id, $owner_id, $owner_type) {
83 $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 .'">';
84 $prefs .= '<fieldset><legend>'. _("Preferences") .'</legend>';
85 $prefs .= $this->getPreferences();
87 $prefs .= '<input type="submit" name="cancel" value="'. _("Cancel") .'" /> ';
88 $prefs .= '<input type="submit" value="'. _("Submit") .'" />';
89 $prefs .= '</fieldset>';
93 function getInstallPreferences() {
96 function getPreferences() {
99 function hasPreferences() {
102 function updatePreferences(&$request) {
108 function getRssUrl($owner_id, $owner_type) {
109 if ($this->hasRss()) {
110 return '/widgets/widget.php?owner='.$owner_type.$owner_id.'&action=rss&name['. $this->id .']='. $this->getInstanceId();
115 function isUnique() {
118 function isAvailable() {
124 function getInstanceId() {
125 return $this->content_id;
127 function loadContent($id) {
129 function setOwner($owner_id, $owner_type) {
130 $this->owner_id = $owner_id;
131 $this->owner_type = $owner_type;
133 function canBeUsedByProject(&$project) {
139 * Take the content of a widget, clone it and return the id of the new content
141 * @param $id the id of the content to clone
142 * @param $owner_id the owner of the widget of the new widget
143 * @param $owner_type the type of the owner of the new widget (see WidgetLayoutManager)
145 function cloneContent($id, $owner_id, $owner_type) {
146 return $this->getInstanceId();
148 function create(&$request) {
150 function destroy($id) {
152 /* static */ function & getInstance($widget_name) {
154 switch($widget_name) {
156 $o =& new Widget_MySurveys();
159 $o =& new Widget_MyProjects();
162 $o =& new Widget_MyBookmarks();
164 case 'mymonitoredforums':
165 $o =& new Widget_MyMonitoredForums();
168 $o =& new Widget_MyArtifacts();
171 $o =& new Widget_MyRss();
174 if (UserManager::instance()->getCurrentUser()->is_super_user) { //This widget is only for super admin
175 $o =& new Widget_MyAdmin();
179 $o =& new Widget_MySrs();
181 case 'mymonitoredfp':
182 $o =& new Widget_MyMonitoredFp();
184 case 'mylatestsvncommits':
185 $o =& new Widget_MyLatestSvnCommits();
188 $o =& new Widget_MyBugs();
191 $o =& new Widget_MyTasks();
193 case 'mytwitterfollow':
194 $o =& new Widget_MyTwitterFollow();
196 case 'mywikipage': //not yet
197 $o =& new Widget_MyWikiPage();
199 case 'mysystemevent':
200 if (user_is_super_user()) { //This widget is only for super admin
201 $o = new Widget_MySystemEvent();
204 case 'projectdescription':
205 $o =& new Widget_ProjectDescription();
207 case 'projectclassification':
208 $o =& new Widget_ProjectClassification();
210 case 'projectmembers':
211 $o =& new Widget_ProjectMembers();
213 case 'projectlatestfilereleases':
214 $o =& new Widget_ProjectLatestFileReleases();
216 case 'projectlatestnews':
217 $o =& new Widget_ProjectLatestNews();
219 case 'projectpublicareas':
220 $o =& new Widget_ProjectPublicAreas();
223 $o =& new Widget_ProjectRss();
225 case 'projecttwitterfollow':
226 $o =& new Widget_ProjectTwitterFollow();
228 case 'projectsvnstats':
229 $o =& new Widget_ProjectSvnStats();
231 //case 'projectwikipage': //not yet
232 // $o =& new Widget_ProjectWikiPage();
234 case 'projectlatestsvncommits':
235 $o =& new Widget_ProjectLatestSvnCommits();
237 case 'projectlatestcvscommits':
238 $o =& new Widget_ProjectLatestCvsCommits();
241 //$em =& EventManager::instance();
242 //$em->processEvent('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
243 plugin_hook('widget_instance', array('widget' => $widget_name, 'instance' => &$o));
246 if (!$o || !is_a($o, 'Widget')) {
251 /* static */ function getCodendiWidgets($owner_type) {
252 switch ($owner_type) {
253 case WidgetLayoutManager::OWNER_TYPE_USER:
254 $widgets = array('myadmin', 'mysurveys', 'myprojects', 'mybookmarks',
255 'mymonitoredforums', 'mymonitoredfp', 'myartifacts', 'mybugs', //'mywikipage' //not yet
256 'mytasks', 'mysrs', 'mylatestsvncommits', 'mytwitterfollow',
257 'mysystemevent', 'myrss',
260 case WidgetLayoutManager::OWNER_TYPE_GROUP:
261 $widgets = array('projectdescription', 'projectmembers',
262 'projectlatestfilereleases', 'projectlatestnews', 'projectpublicareas', //'projectwikipage' //not yet
263 'projectlatestsvncommits', 'projectlatestcvscommits', 'projecttwitterfollow',
264 'projectsvnstats', 'projectrss',
267 case WidgetLayoutManager::OWNER_TYPE_HOME:
275 $plugins_widgets = array();
276 //$em =& EventManager::instance();
277 //$em->processEvent('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
278 plugin_hook('widgets', array('codendi_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
280 if (is_array($plugins_widgets)) {
281 $widgets = array_merge($widgets, $plugins_widgets);
285 /* static */ function getExternalWidgets($owner_type) {
286 switch ($owner_type) {
287 case WidgetLayoutManager::OWNER_TYPE_USER:
291 case WidgetLayoutManager::OWNER_TYPE_GROUP:
295 case WidgetLayoutManager::OWNER_TYPE_HOME:
303 $plugins_widgets = array();
304 $em =& EventManager::instance();
305 $em->processEvent('widgets', array('external_widgets' => &$plugins_widgets, 'owner_type' => $owner_type));
307 if (is_array($plugins_widgets)) {
308 $widgets = array_merge($widgets, $plugins_widgets);
313 function getCategory() {
316 function getDescription() {
319 function getPreviewCssClass() {
320 $locale = UserManager::instance()->getCurrentUser()->getLanguage();
322 return 'widget-preview-'.($this->id).'-'.$locale;
324 function getAjaxUrl($owner_id, $owner_type) {
325 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=ajax&name['. $this->id .']='. $this->getInstanceId();
327 function getIframeUrl($owner_id, $owner_type) {
328 return '/widgets/widget.php?owner='. $owner_type.$owner_id .'&action=iframe&name['. $this->id .']='. $this->getInstanceId();