3 * Copyright (c) STMicroelectronics, 2004-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/>.
20 require_once $gfcommon.'include/preplugins.php';
22 class ForumMLPlugin extends Plugin {
24 function __construct($id=0) {
25 parent::__construct($id);
26 $this->name = "forumml" ;
27 $this->text = "ForumML" ; // To show in the tabs, use...
28 $this->_addHook("user_personal_links");//to make a link to the user�s personal part of the plugin
29 $this->_addHook("usermenu") ;
30 $this->_addHook("groupisactivecheckbox") ; // The "use ..." checkbox in editgroupinfo
31 $this->_addHook("groupisactivecheckboxpost") ; //
32 $this->_addHook("userisactivecheckbox") ; // The "use ..." checkbox in user account
33 $this->_addHook("userisactivecheckboxpost") ; //
34 $this->_addHook("project_admin_plugins"); // to show up in the admin page fro group
35 $this->_addHook('browse_archives','forumml_browse_archives',false);
36 $this->_addHook('cssfile','cssFile',false);
37 $this->_addHook('javascript_file', 'jsFile', false);
38 $this->_addHook('search_type', 'search_type', false);
39 $this->_addHook('layout_searchbox_options', 'forumml_searchbox_option', false);
40 $this->_addHook('layout_searchbox_hiddenInputs', 'forumml_searchbox_hiddenInput', false);
41 $this->_addHook('plugins_powered_search', 'forumml_search', false);
42 $this->_addHook('cssfile');
43 $this->_addHook('search_engines');
44 $this->_addHook('full_search_engines');
45 // Set ForumML plugin scope to 'Projects' wide
46 //$this->setScope(Plugin::SCOPE_PROJECT);
47 $this->allowedForProject = array();
50 function CallHook ($hookname, &$params) {
51 global $use_mailmanplugin,$G_SESSION,$HTML,$gfcommon,$gfwww,$gfplugins;
52 if ($hookname == "usermenu") {
53 $text = $this->text; // this is what shows in the tab
54 if ($G_SESSION->usesPlugin("mailman")) {
55 $param = '?type=user&id=' . $G_SESSION->getId() . "&pluginname=" . $this->name; // we indicate the part we�re calling is the user one
56 echo ' | ' . $HTML->PrintSubMenu (array ($text),
57 array ('/plugins/mailman/index.php' . $param ));
59 } elseif ($hookname =='cssfile') {
60 echo '<link rel="stylesheet" type="text/css" href="/plugins/forumml/themes/default/css/style.css" />';
61 } elseif ($hookname == "groupisactivecheckbox") {
62 //Check if the group is active
63 // this code creates the checkbox in the project edit public info page to activate/deactivate the plugin
64 $group_id=$params['group'];
65 $group = &group_get_object($group_id);
68 echo ' <input type="CHECKBOX" name="use_forummlplugin" value="1" ';
69 // CHECKED OR UNCHECKED?
70 if ( $group->usesPlugin ( $this->name ) ) {
76 echo "<strong>Use ".$this->text." Plugin</strong>";
80 } elseif ($hookname == "groupisactivecheckboxpost") {
81 // this code actually activates/deactivates the plugin after the form was submitted in the project edit public info page
82 $group_id=$params['group'];
83 $group = &group_get_object($group_id);
84 $use_mailmanplugin = getStringFromRequest('use_forummlplugin');
85 if ( $use_mailmanplugin == 1 ) {
86 $group->setPluginUse ( $this->name );
88 $group->setPluginUse ( $this->name, false );
90 } elseif ($hookname == 'search_engines') {
91 require_once 'ForumMLSearchEngine.class.php';
92 // FIXME: when the hook is called, the group_id is not set.
93 // So I use the global variable instead.
94 $request =& HTTPRequest::instance();
95 $group_id = (int) $request->get('group_id');
97 $group =& group_get_object($group_id);
98 if ($group->usesPlugin('forumml')) {
99 if (isset($params['object'])) {
100 $searchManager = $params['object'];
102 $searchManager = $params;
104 $searchManager->addSearchEngine(
105 SEARCH__TYPE_IS_LIST,
106 new ForumMLSearchEngine(SEARCH__TYPE_IS_LIST,
107 'ForumMLHtmlSearchRenderer',
108 _("This project's mailing lists"), $group_id)
112 } elseif ($hookname == "browse_archives") {
113 $this->forumml_browse_archives($params);
114 } elseif ($hookname == "cssfile") {
115 $this->cssFile($params);
116 } elseif ($hookname == "javascript_file") {
117 $this->jsFile($params);
118 } elseif ($hookname == "search_type") {
119 $this->search_type($params);
120 } elseif ($hookname == "layout_searchbox_options") {
121 $this->forumml_searchbox_option($params);
122 } elseif ($hookname == "layout_searchbox_hiddenInputs") {
123 $this->forumml_searchbox_hiddenInput($params);
124 } elseif ($hookname == "plugins_powered_search") {
125 $this->forumml_search($params);
130 function &getPluginInfo() {
131 if (!is_a($this->pluginInfo, 'ForumMLPluginInfo')) {
132 require_once 'ForumMLPluginInfo.class.php';
133 $this->pluginInfo = new ForumMLPluginInfo($this);
135 return $this->pluginInfo;
139 * Return true if current project has the right to use this plugin.
141 function isAllowed($group_id=false) {
143 $request =& HTTPRequest::instance();
144 $group_id = (int) $request->get('group_id');
146 if(!isset($this->allowedForProject[$group_id])) {
147 $pM =& PluginManager::instance();
148 $this->allowedForProject[$group_id] = $pM->isPluginAllowedForProject($this, $group_id);
150 return $this->allowedForProject[$group_id];
153 function forumml_searchbox_option($params) {
154 $request =& HTTPRequest::instance();
155 $group_id = (int) $request->get('group_id');
156 if(isset($_REQUEST['list']) && isset($group_id)) {
157 $params['option_html'] .= "\t<OPTION value=\"mail\"".( $params['type_of_search'] == "mail" ? " SELECTED" : "" ).">"._('This List')."</OPTION>\n";
161 function forumml_searchbox_hiddenInput($params) {
162 if(isset($_REQUEST['list'])) {
163 $params['input_html'] .= "\t<INPUT TYPE=\"HIDDEN\" VALUE=\"". $_REQUEST['list'] ."\" NAME=\"list\">\n";
167 function forumml_browse_archives($params) {
168 if ($this->isAllowed()) {
169 $request =& HTTPRequest::instance();
170 $group_id = (int) $request->get('group_id');
171 $params['html'] = '<A href="/plugins/forumml/message.php?group_id='.$group_id.'&list='.$params['group_list_id'].'"> '._('Archives').'</A>';
175 function cssFile($params) {
176 $request =& HTTPRequest::instance();
177 if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0) {
178 echo '<link rel="stylesheet" type="text/css" href="'.$this->getThemePath().'/css/style.css" />'."\n";
182 function jsFile($params) {
183 //$request =& HTTPRequest::instance();
184 if (strpos($_SERVER['REQUEST_URI'], $this->getPluginPath()) === 0) {
185 //echo '<link rel="stylesheet" type="text/css" href="'.$this->getThemePath().'/css/style.css" />'."\n";
186 echo '<script type="text/javascript" src="'.$this->getPluginPath().'/scripts/forumml.js"></script>'."\n";
190 function forumml_search($params) {
191 if($params['type_of_search'] == 'mail') {
192 $params['plugins_powered_search'] = true;
196 function search_type($params) {
197 if(isset($params['type_of_search']) && $params['type_of_search'] == 'mail') {
198 $request =& HTTPRequest::instance();
199 $group_id = (int) $request->get('group_id');
200 $list = (int) $request->get('list');
201 util_return_to('/plugins/forumml/message.php?group_id='.$group_id.'&list='.$list.'&search='.urlencode($params['words']));