4 * Copyright (C) 2006 Alain Peyrat, Alcatel-Lucent
5 * Copyright (C) 2010 Alain Peyrat <aljeux@free.fr>
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Standard Alcatel-Lucent disclaimer for contributing to open source
27 * "The provided file ("Contribution") has not been tested and/or
28 * validated for release as or in products, combinations with products or
29 * other commercial use. Any use of the Contribution is entirely made at
30 * the user's own responsibility and the user can not rely on any features,
31 * functionalities or performances Alcatel-Lucent has attributed to the
34 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
35 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
37 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
38 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
39 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
40 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
42 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
46 forge_define_config_item('templates_file','blocks','$core/source_path/plugins/blocks/etc/templates.json');
48 class blocksPlugin extends Plugin {
49 function blocksPlugin () {
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
59 function CallHook ($hookname, &$params) {
60 if ($hookname == "project_admin_plugins") {
61 // this displays the link in the project admin options page to it's blocks administration
62 $group_id = $params['group_id'];
63 $group = group_get_object($group_id);
64 if ( $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>';
67 } elseif ($hookname == "blocks") {
68 return $this->blocks($params);
71 function blocks($params) {
72 // Check if block is active and if yes, display the block.
73 // Return true if plugin is active, false otherwise.
74 $group = group_get_object($GLOBALS['group_id']);
75 if ( $group && $group->usesPlugin ( $this->name ) ) {
77 $c = $this->renderBlock($params);
86 function renderBlock($name) {
87 $group_id = $GLOBALS['group_id'];
88 $res = db_query_params('SELECT content
93 array($group_id, $name)); // 1 is for active
94 if (db_numrows($res)== 0) {
97 $content = db_result($res,0,"content");
99 return $this->parseContent($content).'<br />';
101 return "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">" .
102 "<tr><td align=\"center\">block: $name</td></tr></table><br />";
107 function parseContent($t) {
110 $t = preg_replace('/<p>{boxTop (.*?)}<\/p>/ie', '$HTML->boxTop(\'$1\')', $t);
111 $t = preg_replace('/{boxTop (.*?)}/ie', '$HTML->boxTop(\'$1\')', $t);
112 $t = preg_replace('/<p>{boxMiddle (.*?)}<\/p>/ie', '$HTML->boxMiddle(\'$1\')', $t);
113 $t = preg_replace('/{boxMiddle (.*?)}/ie', '$HTML->boxMiddle(\'$1\')', $t);
114 $t = preg_replace('/<p>{boxBottom}<\/p>/i', $HTML->boxBottom(), $t);
115 $t = preg_replace('/{boxBottom}/i', $HTML->boxBottom(), $t);
117 $t = preg_replace('/<p>{boxHeader}/i', '<hr />', $t);
118 $t = preg_replace('/{boxHeader}/i', '<hr />', $t);
119 $t = preg_replace('/{boxFooter}<\/p>/i', '<hr />', $t);
120 $t = preg_replace('/{boxFooter}/i', '<hr />', $t);
128 // c-file-style: "bsd"