Commit ec77501b authored by Ben Bradshaw's avatar Ben Bradshaw
Browse files

[3348] Added a configurable character limit for wall posts

parent f7d53218
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-wall
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
function xmldb_blocktype_wall_upgrade($oldversion=0) {
if ($oldversion < 2009021801) {
set_config_plugin('blocktype', 'wall', 'defaultpostsizelimit', 1500); // 1500 characters
}
return true;
}
?>
......@@ -41,4 +41,14 @@ $string['deletepost'] = 'Delete post';
$string['Post'] = 'Post';
$string['deletepostsure'] = 'Are you sure you want to do this? It cannot be undone.';
$string['deletepostsuccess'] = 'Post deleted successfully';
$string['maxcharacters'] = "Maximum %s characters per post.";
$string['sorrymaxcharacters'] = "Sorry, your post cannot be more than %s characters long.";
// Config strings
$string['postsizelimit'] = "Post Size Limit";
$string['postsizelimitdescription'] = "You can limit the size of wall posts here. Existing posts will not be changed";
$string['postsizelimitmaxcharacters'] = "Maximum number of characters";
$string['postsizelimitinvalid'] = "This is not a valid number.";
$string['postsizelimittoosmall'] = "This limit cannot be lower than zero.";
?>
......@@ -77,6 +77,52 @@ class PluginBlocktypeWall extends SystemBlocktype {
return false;
}
public static function has_config() {
return true;
}
public static function get_config_options() {
$elements = array();
$elements['sizelimitfieldset'] = array(
'type' => 'fieldset',
'legend' => get_string('postsizelimit', 'blocktype.wall'),
'elements' => array(
'postsizelimitdescription' => array(
'value' => get_string('postsizelimitdescription', 'blocktype.wall')
),
'defaultpostsizelimit' => array(
'title' => get_string('postsizelimitmaxcharacters', 'blocktype.wall'),
'type' => 'text',
'defaultvalue' => get_config_plugin('blocktype', 'wall', 'defaultpostsizelimit'),
'rules' => array( 'maxlength' => 6 )
)
),
);
return array(
'elements' => $elements,
);
}
public static function validate_config_options($form, $values) {
if (!is_numeric($values['defaultpostsizelimit'])) {
$form->set_error('defaultpostsizelimit', get_string('postsizelimitinvalid', 'blocktype.wall'));
}
else if ($values['defaultpostsizelimit'] < 0) {
$form->set_error('defaultpostsizelimit', get_string('postsizelimittoosmall', 'blocktype.wall'));
}
}
public static function save_config_options($values) {
set_config_plugin('blocktype', 'wall', 'defaultpostsizelimit', (int)$values['defaultpostsizelimit']);
}
public static function postinst($prevversion) {
if ($prevversion == 0) {
set_config_plugin('blocktype', 'wall', 'defaultpostsizelimit', 1500); // 1500 characters
}
}
public static function delete_instance(BlockInstance $instance) {
return delete_records('blocktype_wall_post', 'instance', $instance->get('id'));
}
......@@ -90,12 +136,12 @@ class PluginBlocktypeWall extends SystemBlocktype {
}
require_once('pieforms/pieform.php');
return pieform(array(
'name' => 'wallpost',
'name' => 'wallpost_'.$instance->get('id'),
'renderer' => 'maharatable',
'action' => get_config('wwwroot') . 'blocktype/wall/post.php',
'autofocus' => false,
'template' => 'wallpost.php',
'templatedir' => pieform_template_dir('wallpost.php', 'blocktype/wall'),
'validatecallback' => array('PluginBlocktypeWall', 'wallpost_validate'),
'successcallback' => array('PluginBlocktypeWall', 'wallpost_submit'),
'elements' => array(
'text' => array(
......@@ -106,6 +152,10 @@ class PluginBlocktypeWall extends SystemBlocktype {
'defaultvalue' => '',
'width' => '100%',
),
'postsizelimit' => array(
'type' => 'html',
'value' => get_string('maxcharacters', 'blocktype.wall', get_config_plugin('blocktype', 'wall', 'defaultpostsizelimit'))
),
'private' => array(
'type' => 'checkbox',
'title' => get_string('makeyourpostprivate', 'blocktype.wall'),
......@@ -128,6 +178,13 @@ class PluginBlocktypeWall extends SystemBlocktype {
// depending on if the user we're replying to has a wall
}
public static function wallpost_validate(Pieform $form, $values) {
$sizelimit = get_config_plugin('blocktype', 'wall', 'defaultpostsizelimit');
if (strlen($values['text']) > $sizelimit) {
$form->set_error('text', get_string('sorrymaxcharacters', 'blocktype.wall', $sizelimit));
}
}
public static function wallpost_submit(Pieform $form, $values) {
global $USER;
$record = (object)array(
......@@ -138,6 +195,7 @@ class PluginBlocktypeWall extends SystemBlocktype {
'postdate' => db_format_timestamp(time()),
'text' => $values['text'],
);
insert_record('blocktype_wall_post', $record);
$userid = get_field_sql('SELECT owner FROM {view} WHERE id = (SELECT "view" FROM {block_instance} WHERE id = ?)', array($values['instance']));
redirect('/user/view.php?id=' . $userid);
......
......@@ -4,8 +4,11 @@
// element, but there's no validation or descriptions on this form currently
echo $form_tag;
echo '<div class="description">' . $elements['text']['description'] . '</div>';
echo '<div class="description">' . $elements['postsizelimit']['html'] . ' ' . $elements['text']['description'] . '</div>';
echo '<div>' . $elements['text']['html'] .'</div>';
if (isset($elements['text']['error'])) {
echo '<div>' . $elements['text']['error'] . '</div>';
}
echo '<div class="makeprivate">' . $elements['private']['labelhtml'] . ' ' . $elements['private']['html'] . '</div>';
echo '<div>' . $elements['submit']['html'] . '</div>';
echo $hidden_elements;
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009021800;
$config->release = '1.0.0';
$config->version = 2009073000;
$config->release = '1.0.1';
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment