3 * Copyright (C) 2006 Alain Peyrat, Alcatel-Lucent
4 * Copyright (C) 2010 Alain Peyrat <aljeux@free.fr>
5 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
6 * Copyright 2014,2016, Franck Villaume - TrivialDev
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() {
50 parent::__construct();
51 $this->name = 'blocks';
52 $this->text = _('Blocks'); // To show in the tabs, use...
54 _("This plugin contains the Blocks subsystem of FusionForge. It allows each
55 FusionForge project to have its own Blocks, and gives some
56 control over it to the project's administrator.");
57 $this->hooks[] = 'groupisactivecheckbox'; // The "use ..." checkbox in editgroupinfo
58 $this->hooks[] = 'groupisactivecheckboxpost'; //
59 $this->hooks[] = 'project_admin_plugins'; // to show up in the admin page fro group
60 $this->hooks[] = 'blocks'; // to show up in the admin page fro group
61 $this->hooks[] = 'widget_instance';
62 $this->hooks[] = 'widgets';
65 function project_admin_plugins($params) {
66 // this displays the link in the project admin options page to it's blocks administration
67 $group = group_get_object($params['group_id']);
68 if ($group && $group->usesPlugin ( $this->name )) {
69 echo html_e('p', array(), util_make_link('/plugins/blocks/index.php?id='.$group->getID().'&type=admin&pluginname='.$this->name, _('Blocks Admin')));
73 function blocks($params) {
74 // Check if block is active and if yes, display the block.
75 // Return true if plugin is active, false otherwise.
76 $group = group_get_object($GLOBALS['group_id']);
77 if ($group && $group->usesPlugin($this->name)) {
78 $content = $this->renderBlock($params);
79 if ($content !== false) {
87 function getTitleBlock($name) {
88 $group_id = $GLOBALS['group_id'];
89 $res = db_query_params('SELECT title
94 array($group_id, $name)); // 1 is for active
95 if (db_numrows($res) == 0) {
98 return db_result($res, 0, 'title');
102 function getContentBlock($name) {
103 $group_id = $GLOBALS['group_id'];
104 $res = db_query_params('SELECT content
109 array($group_id, $name)); // 1 is for active
110 if (db_numrows($res) == 0) {
113 return db_result($res, 0, 'content');
116 function renderBlock($name) {
117 $content = $this->getContentBlock($name);
118 if ($content === false) {
120 } elseif ($content) {
121 return $this->parseContent($content);
123 return '<table class="fullwidth boxed">'.
124 '<tr><td class="align-center">block: '.$name.'</td></tr></table><br />';
128 function parseContent($text) {
130 $parsertype = forge_get_config('parser_type', 'blocks');
131 switch ($parsertype) {
133 require_once 'markdown.php';
134 $text = Markdown($text);
137 $text = preg_replace_callback('/<p>{boxTop (.*?)}<\/p>/i', function($m) { global $HTML; return $HTML->boxTop($m[1]); }, $text);
138 $text = preg_replace_callback('/{boxTop (.*?)}/i', function($m) { global $HTML; return $HTML->boxTop($m[1]); }, $text);
139 $text = preg_replace_callback('/<p>{boxMiddle (.*?)}<\/p>/i', function($m) { global $HTML; return $HTML->boxMiddle($m[1]); }, $text);
140 $text = preg_replace_callback('/{boxMiddle (.*?)}/i', function($m) { global $HTML; return $HTML->boxMiddle($m[1]); }, $text);
141 $text = preg_replace_callback('/<p>{boxBottom}<\/p>/i', function($m) { global $HTML; return $HTML->boxBottom($m[1]); }, $text);
142 $text = preg_replace_callback('/{boxBottom}/i', function($m) { global $HTML; return $HTML->boxBottom($m[1]); }, $text);
144 $text = preg_replace('/<p>{boxHeader}/i', '<hr />', $text);
145 $text = preg_replace('/{boxHeader}/i', '<hr />', $text);
146 $text = preg_replace('/{boxFooter}<\/p>/i', '<hr />', $text);
147 $text = preg_replace('/{boxFooter}/i', '<hr />', $text);
153 function widget_instance($params) {
154 require_once 'common/widget/WidgetLayoutManager.class.php';
157 if ($params['widget'] == 'plugin_blocks_project_summary') {
158 require_once 'blocks_Widget_ProjectSummary.class.php';
159 $params['instance'] = new blocks_Widget_ProjectSummary(WidgetLayoutManager::OWNER_TYPE_GROUP, $GLOBALS['group_id']);
162 if ($params['widget'] == 'plugin_blocks_home_summary') {
163 require_once 'blocks_Widget_HomeSummary.class.php';
164 $params['instance'] = new blocks_Widget_HomeSummary(WidgetLayoutManager::OWNER_TYPE_HOME, 0);
169 function widgets($params) {
170 if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
171 $group = group_get_object($GLOBALS['group_id']);
172 if ( !$group || !$group->usesPlugin ( $this->name ) ) {
175 require_once 'common/widget/WidgetLayoutManager.class.php';
176 $params['fusionforge_widgets'][] = 'plugin_blocks_project_summary';
178 } elseif ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_HOME) {
179 $params['fusionforge_widgets'][] = 'plugin_blocks_home_summary';
188 // c-file-style: "bsd"