3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2016, Franck Villaume - TrivialDev
6 * This file is a part of Codendi.
8 * Codendi is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Codendi is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
22 require_once 'common/include/HTTPRequest.class.php';
24 class blocks_Widget_HomeSummary extends Widget {
28 function __construct($owner_type, $owner_id) {
29 $request =& HTTPRequest::instance();
30 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_HOME) {
31 $this->widget_id = 'plugin_blocks_home_summary';
32 $this->group_id = $owner_id;
34 parent::__construct($this->widget_id);
35 $this->setOwner($owner_id, $owner_type);
40 return ($this->title ? $this->title : _('Summary Page block of text'));
43 function getDescription() {
44 return _('Add a free block on the forge homepage to allow giving information.');
50 function hasPreferences() {
53 private function getPartialPreferencesForm($title, $content) {
55 $prefs .= '<tr><td>'._('Title')._(':').'</td>';
56 $prefs .= '<td><input type="text" class="textfield_medium" name="title" value="'. htmlspecialchars($title) .'" /></td></tr>';
57 $prefs .= '<tr><td>'._('Content')._(':').'</td>';
59 $params['body'] = $content;
60 $params['width'] = "500";
61 $params['height'] = "250";
62 $params['group'] = $this->group_id;
63 $params['toolbar'] = 'FusionForge-Basic';
64 $params['content'] = '<textarea name="body" rows="10" cols="55">'.$content.'</textarea>';
65 plugin_hook_by_reference("text_editor", $params);
66 $prefs .= '<td>'.$params['content'].'</td></tr>';
71 function getPreferences() {
72 return $this->getPartialPreferencesForm($this->getTitle(), $this->content);
75 function getInstallPreferences() {
76 return $this->getPartialPreferencesForm(_('Enter title of block'), '');
78 function updatePreferences(&$request) {
80 $vContentId = new Valid_UInt('content_id');
81 $vContentId->required();
82 if ($request->valid($vContentId)) {
83 $vTitle = new Valid_String('title');
84 if($request->valid($vTitle)) {
85 $title = htmlspecialchars($request->get('title'));
90 $vContent = new Valid_Text('body');
91 $vContent->required();
92 if($request->valid($vContent)) {
93 $content = $request->get('body');
94 if (getStringFromRequest('_body_content_type') == 'html') {
95 $content = TextSanitizer::purify($content);
97 $content = htmlspecialchars($content);
104 $sql = "UPDATE plugin_blocks SET title=$1, content=$2 WHERE group_id =$3 AND id = $4";
105 $res = db_query_params($sql,array($title,$content,$this->group_id,(int)$request->get('content_id')));
112 function loadContent($id) {
113 $this->title = plugin_get_object('blocks')->getTitleBlock('summary_block'.$id);
114 $this->content = plugin_get_object('blocks')->getContentBlock('summary_block'.$id);
115 $this->content_id = $id;
118 function create(&$request) {
119 $title = getStringFromRequest('title');
120 $content = getStringFromRequest('body');
121 $res = db_query_params('INSERT INTO plugin_blocks (group_id, name, status, title, content)
122 VALUES ($1, $2, 1, $3, $4)',
123 array($this->owner_id, 'summary_block?', $title, $content));
124 $content_id = db_insertid($res, 'plugin_blocks', 'id');
125 $res = db_query_params('UPDATE plugin_blocks SET name=$1 WHERE id=$2',
126 array('summary_block'.$content_id, $content_id));
130 function getContent() {
131 return plugin_get_object('blocks')->parseContent($this->content);
134 function destroy($id) {
135 $sql = 'DELETE FROM plugin_blocks WHERE id = $1 AND group_id = $2';
136 db_query_params($sql,array($id,$this->group_id));