4 * Copyright (C) 2006 Alain Peyrat, Alcatel-Lucent
5 * Copyright (C) 2010 Alain Peyrat <aljeux@free.fr>
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * Standard Alcatel-Lucent disclaimer for contributing to open source
28 * "The provided file ("Contribution") has not been tested and/or
29 * validated for release as or in products, combinations with products or
30 * other commercial use. Any use of the Contribution is entirely made at
31 * the user's own responsibility and the user can not rely on any features,
32 * functionalities or performances Alcatel-Lucent has attributed to the
35 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
36 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
37 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
38 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
39 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
40 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
41 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
43 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 class blocksPlugin extends Plugin {
49 function __construct() {
51 $this->name = "blocks" ;
52 $this->text = "Blocks" ; // To show in the tabs, use...
53 $this->hooks[] = "groupisactivecheckbox" ; // The "use ..." checkbox in editgroupinfo
54 $this->hooks[] = "groupisactivecheckboxpost" ; //
55 $this->hooks[] = "project_admin_plugins"; // to show up in the admin page fro group
56 $this->hooks[] = "blocks"; // to show up in the admin page fro group
57 $this->hooks[] = 'widget_instance';
58 $this->hooks[] = 'widgets';
61 function project_admin_plugins($params) {
62 // this displays the link in the project admin options page to it's blocks administration
63 $group = group_get_object($params['group_id']);
64 if ($group && $group->usesPlugin ( $this->name )) {
65 echo '<p><a href="/plugins/blocks/index.php?id=' . $group->getID() . '&type=admin&pluginname=' . $this->name . '">' . _("Blocks Admin") . '</a></p>';
69 function blocks($params) {
70 // Check if block is active and if yes, display the block.
71 // Return true if plugin is active, false otherwise.
72 $group = group_get_object($GLOBALS['group_id']);
73 if ($group && $group->usesPlugin ( $this->name )) {
74 $content = $this->renderBlock($params);
75 if ($content !== false) {
83 function getTitleBlock($name) {
84 $group_id = $GLOBALS['group_id'];
85 $res = db_query_params('SELECT title
90 array($group_id, $name)); // 1 is for active
91 if (db_numrows($res)== 0) {
94 return db_result($res,0,"title");
98 function getContentBlock($name) {
99 $group_id = $GLOBALS['group_id'];
100 $res = db_query_params('SELECT content
105 array($group_id, $name)); // 1 is for active
106 if (db_numrows($res)== 0) {
109 return db_result($res,0,"content");
112 function renderBlock($name) {
113 $content = $this->getContentBlock($name);
114 if ($content === false) {
116 } elseif ($content) {
117 return $this->parseContent($content).'<br />';
119 return "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">" .
120 "<tr><td align=\"center\">block: $name</td></tr></table><br />";
124 function parseContent($text) {
127 $text = preg_replace('/<p>{boxTop (.*?)}<\/p>/ie', '$HTML->boxTop(\'$1\')', $text);
128 $text = preg_replace('/{boxTop (.*?)}/ie', '$HTML->boxTop(\'$1\')', $text);
129 $text = preg_replace('/<p>{boxMiddle (.*?)}<\/p>/ie', '$HTML->boxMiddle(\'$1\')', $text);
130 $text = preg_replace('/{boxMiddle (.*?)}/ie', '$HTML->boxMiddle(\'$1\')', $text);
131 $text = preg_replace('/<p>{boxBottom}<\/p>/i', $HTML->boxBottom(), $text);
132 $text = preg_replace('/{boxBottom}/i', $HTML->boxBottom(), $text);
134 $text = preg_replace('/<p>{boxHeader}/i', '<hr />', $text);
135 $text = preg_replace('/{boxHeader}/i', '<hr />', $text);
136 $text = preg_replace('/{boxFooter}<\/p>/i', '<hr />', $text);
137 $text = preg_replace('/{boxFooter}/i', '<hr />', $text);
142 function widget_instance($params) {
143 require_once 'common/widget/WidgetLayoutManager.class.php';
145 $user = UserManager::instance()->getCurrentUser();
148 // if ($params['widget'] == 'plugin_hudson_my_jobs') {
149 // require_once('hudson_Widget_MyMonitoredJobs.class.php');
150 // $params['instance'] = new hudson_Widget_MyMonitoredJobs($this);
152 // if ($params['widget'] == 'plugin_hudson_my_joblastbuilds') {
153 // require_once('hudson_Widget_JobLastBuilds.class.php');
154 // $params['instance'] = new hudson_Widget_JobLastBuilds(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
156 // if ($params['widget'] == 'plugin_hudson_my_jobtestresults') {
157 // require_once('hudson_Widget_JobTestResults.class.php');
158 // $params['instance'] = new hudson_Widget_JobTestResults(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
160 // if ($params['widget'] == 'plugin_hudson_my_jobtesttrend') {
161 // require_once('hudson_Widget_JobTestTrend.class.php');
162 // $params['instance'] = new hudson_Widget_JobTestTrend(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
164 // if ($params['widget'] == 'plugin_hudson_my_jobbuildhistory') {
165 // require_once('hudson_Widget_JobBuildHistory.class.php');
166 // $params['instance'] = new hudson_Widget_JobBuildHistory(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
168 // if ($params['widget'] == 'plugin_hudson_my_joblastartifacts') {
169 // require_once('hudson_Widget_JobLastArtifacts.class.php');
170 // $params['instance'] = new hudson_Widget_JobLastArtifacts(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
174 if ($params['widget'] == 'plugin_blocks_project_summary') {
175 require_once 'blocks_Widget_ProjectSummary.class.php';
176 $params['instance'] = new blocks_Widget_ProjectSummary(WidgetLayoutManager::OWNER_TYPE_GROUP, $GLOBALS['group_id']);
179 function widgets($params) {
180 $group = group_get_object($GLOBALS['group_id']);
181 if ( !$group || !$group->usesPlugin ( $this->name ) ) {
185 require_once 'common/widget/WidgetLayoutManager.class.php';
186 // if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_USER) {
187 // $params['codendi_widgets'][] = 'plugin_hudson_my_jobs';
188 // $params['codendi_widgets'][] = 'plugin_hudson_my_joblastbuilds';
189 // $params['codendi_widgets'][] = 'plugin_hudson_my_jobtestresults';
190 // $params['codendi_widgets'][] = 'plugin_hudson_my_jobtesttrend';
191 // $params['codendi_widgets'][] = 'plugin_hudson_my_jobbuildhistory';
192 // $params['codendi_widgets'][] = 'plugin_hudson_my_joblastartifacts';
194 if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
195 $params['codendi_widgets'][] = 'plugin_blocks_project_summary';
203 // c-file-style: "bsd"