| 1 |
<?php
|
| 2 |
// vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
|
| 3 |
// $Id: tribune.admin.inc,v 1.8 2008/11/30 15:04:59 seeschloss Exp $
|
| 4 |
|
| 5 |
function tribune_admin() {
|
| 6 |
drupal_set_title(t("Tribune settings"));
|
| 7 |
$breadcrumb = drupal_get_breadcrumb();
|
| 8 |
$breadcrumb[] = l(t("Tribune settings"), "admin/settings/tribune");
|
| 9 |
drupal_set_breadcrumb($breadcrumb);
|
| 10 |
|
| 11 |
$form['tribune_max_message_size'] = array(
|
| 12 |
'#type' => 'textfield',
|
| 13 |
'#title' => t('Maximum length of a comment'),
|
| 14 |
'#default_value' => variable_get('tribune_max_message_size', 512),
|
| 15 |
'#size' => 4,
|
| 16 |
'#maxlength' => 4,
|
| 17 |
'#description' => t('The maximum length of a comment.'),
|
| 18 |
);
|
| 19 |
|
| 20 |
$form['tribune_history_size'] = array(
|
| 21 |
'#type' => 'textfield',
|
| 22 |
'#title' => t('Number of comments displayed'),
|
| 23 |
'#default_value' => variable_get('tribune_history_size', 25),
|
| 24 |
'#size' => 3,
|
| 25 |
'#maxlength' => 3,
|
| 26 |
'#description' => t('The number of comments to display.'),
|
| 27 |
);
|
| 28 |
|
| 29 |
$form['tribune_history_block_size'] = array(
|
| 30 |
'#type' => 'textfield',
|
| 31 |
'#title' => t('Number of comments displayed in the block'),
|
| 32 |
'#default_value' => variable_get('tribune_history_block_size', 10),
|
| 33 |
'#size' => 3,
|
| 34 |
'#maxlength' => 3,
|
| 35 |
'#description' => t('The number of comments to display in the block.'),
|
| 36 |
);
|
| 37 |
|
| 38 |
$form['tribune_xml_size'] = array(
|
| 39 |
'#type' => 'textfield',
|
| 40 |
'#title' => t('Number of comments displayed in the XML backend'),
|
| 41 |
'#default_value' => variable_get('tribune_xml_size', 100),
|
| 42 |
'#size' => 3,
|
| 43 |
'#maxlength' => 3,
|
| 44 |
'#description' => t('The number of comments to display in the XML backend.'),
|
| 45 |
);
|
| 46 |
|
| 47 |
$form['tribune_rss_size'] = array(
|
| 48 |
'#type' => 'textfield',
|
| 49 |
'#title' => t('Number of comments displayed in the RSS feed'),
|
| 50 |
'#default_value' => variable_get('tribune_rss_size', 50),
|
| 51 |
'#size' => 3,
|
| 52 |
'#maxlength' => 3,
|
| 53 |
'#description' => t('The number of comments to display in the RSS feed.'),
|
| 54 |
);
|
| 55 |
|
| 56 |
$form['tribune_reload_delay'] = array(
|
| 57 |
'#type' => 'textfield',
|
| 58 |
'#title' => t('Reload delay'),
|
| 59 |
'#default_value' => variable_get('tribune_reload_delay', 30),
|
| 60 |
'#size' => 3,
|
| 61 |
'#maxlength' => 3,
|
| 62 |
'#description' => t('The delay between automatic reloading of the tribune, in seconds (0 to disable Ajax reloading).'),
|
| 63 |
);
|
| 64 |
|
| 65 |
$form['tribune_name'] = array(
|
| 66 |
'#type' => 'textfield',
|
| 67 |
'#title' => t('Tribune name'),
|
| 68 |
'#default_value' => variable_get('tribune_name', variable_get('site_name', '')),
|
| 69 |
'#description' => t('The name of your tribune, needed for people who use Coincoins.'),
|
| 70 |
);
|
| 71 |
|
| 72 |
$form['tribune_message'] = array(
|
| 73 |
'#type' => 'textarea',
|
| 74 |
'#title' => t('Tribune message'),
|
| 75 |
'#default_value' => variable_get('tribune_message', ''),
|
| 76 |
'#description' => t('Warning or information to display at the top of the tribune. You can use any HTML code you want, but you have to insert linebreaks yourself.'),
|
| 77 |
);
|
| 78 |
|
| 79 |
$form['tribune_flood_protection_delay'] = array(
|
| 80 |
'#type' => 'textfield',
|
| 81 |
'#title' => t('Flood protection'),
|
| 82 |
'#default_value' => variable_get('tribune_flood_protection_delay', 3),
|
| 83 |
'#size' => 3,
|
| 84 |
'#maxlength' => 3,
|
| 85 |
'#description' => t('Minimum time before someone can post again, in seconds.'),
|
| 86 |
);
|
| 87 |
|
| 88 |
$form['tribune_order'] = array(
|
| 89 |
'#type' => 'radios',
|
| 90 |
'#title' => t('Message order'),
|
| 91 |
'#default_value' => variable_get('tribune_order', 'top_to_bottom'),
|
| 92 |
'#options' => array('top_to_bottom' => t("Last messages at the bottom"), 'bottom_to_top' => t("Last messages at the top")),
|
| 93 |
'#description' => t('How the messages are displayed. Displaying the messages top-to-bottom makes it easier to follow real discussions, but displaying the latest one at the top is sometimes less confusing.'),
|
| 94 |
);
|
| 95 |
|
| 96 |
$form['tribune_pager'] = array(
|
| 97 |
'#type' => 'checkbox',
|
| 98 |
'#title' => t('Show pager'),
|
| 99 |
'#default_value' => variable_get('tribune_pager', FALSE),
|
| 100 |
'#description' => t('Show a pager on the main page.'),
|
| 101 |
);
|
| 102 |
|
| 103 |
return system_settings_form($form);
|
| 104 |
}
|
| 105 |
|
| 106 |
function tribune_admin_validate($form_id, $form_values) {
|
| 107 |
if (!is_numeric($form_values['values']['tribune_max_message_size'])) {
|
| 108 |
form_set_error("tribune_max_message_size", t("The maximum comment length must be an integer"));
|
| 109 |
}
|
| 110 |
|
| 111 |
if (!is_numeric($form_values['values']['tribune_history_size'])) {
|
| 112 |
form_set_error("tribune_history_size", t("The number of comments displayed must be an integer"));
|
| 113 |
}
|
| 114 |
|
| 115 |
if (!is_numeric($form_values['values']['tribune_history_block_size'])) {
|
| 116 |
form_set_error("tribune_history_block_size", t("The number of comments displayed in the block must be an integer"));
|
| 117 |
}
|
| 118 |
|
| 119 |
if (!is_numeric($form_values['values']['tribune_xml_size'])) {
|
| 120 |
form_set_error("tribune_xml_size", t("The number of comments in the XML backend must be an integer"));
|
| 121 |
}
|
| 122 |
|
| 123 |
if (!is_numeric($form_values['values']['tribune_reload_delay'])) {
|
| 124 |
form_set_error("tribune_reload_delay", t("The reload delay must be a time in seconds"));
|
| 125 |
}
|
| 126 |
|
| 127 |
if (strlen($form_values['values']['tribune_message']) > 2048) {
|
| 128 |
$form_values['values']['tribune_message'] =
|
| 129 |
substr($form_values['values']['tribune_message'], 0, 2048);
|
| 130 |
}
|
| 131 |
|
| 132 |
if (!is_numeric($form_values['values']['tribune_flood_protection_delay'])) {
|
| 133 |
form_set_error("tribune_flood_protection_delay", t("The flood protection delay must be a time in seconds"));
|
| 134 |
}
|
| 135 |
}
|
| 136 |
|
| 137 |
function tribune_admin_migration() {
|
| 138 |
$form = array();
|
| 139 |
|
| 140 |
$form['migration'] = array(
|
| 141 |
'#type' => 'fieldset',
|
| 142 |
'#title' => t('Tribune migration'),
|
| 143 |
'#description' => t('You have recently updated your tribune from 1.x to
|
| 144 |
2.x. Tribunes are now nodes, and posts from your former tribune are not
|
| 145 |
yet associated with any tribune node. This page allows you to move all
|
| 146 |
your existing posts to a new tribune node, or alternatively to
|
| 147 |
delete all your existing posts if you do not want to keep them.'),
|
| 148 |
);
|
| 149 |
|
| 150 |
$form['migration']['create_node'] = array(
|
| 151 |
'#type' => 'checkbox',
|
| 152 |
'#disabled' => TRUE,
|
| 153 |
'#value' => TRUE,
|
| 154 |
'#title' => t('Create a new tribune node'),
|
| 155 |
'#description' => t('You have not created any tribune node yet. A new
|
| 156 |
node will be created before moving all the existing posts into it.'),
|
| 157 |
);
|
| 158 |
|
| 159 |
if (function_exists('path_set_alias')) {
|
| 160 |
$form['migration']['set_alias'] = array(
|
| 161 |
'#type' => 'checkbox',
|
| 162 |
'#value' => TRUE,
|
| 163 |
'#title' => t('Set path alias /tribune -> new node'),
|
| 164 |
'#description' => t('You have the path module activated, if this
|
| 165 |
box is checked, an alias will be set so that the "/tribune" path will
|
| 166 |
work and show your new tribune node. Otherwise, your new tribune will
|
| 167 |
be accessible only with its node/<em>123</em> path. You can always
|
| 168 |
change this later.'),
|
| 169 |
);
|
| 170 |
}
|
| 171 |
|
| 172 |
$form['migration']['migrate'] = array(
|
| 173 |
'#type' => 'submit',
|
| 174 |
'#value' => t('Migrate posts'),
|
| 175 |
'#submit' => array('tribune_admin_migration_submit'),
|
| 176 |
);
|
| 177 |
|
| 178 |
$form['#redirect'] = FALSE;
|
| 179 |
|
| 180 |
return $form;
|
| 181 |
}
|
| 182 |
|
| 183 |
function tribune_admin_migration_submit(&$form, $form_state) {
|
| 184 |
if ($form_state['values']['create_node']) {
|
| 185 |
global $user;
|
| 186 |
$node = new stdClass();
|
| 187 |
|
| 188 |
$node->nid = 0;
|
| 189 |
$node->type = 'tribune';
|
| 190 |
$node->uid = $user->uid;
|
| 191 |
$node->status = 1;
|
| 192 |
$node->created = time();
|
| 193 |
|
| 194 |
$node->title = variable_get('tribune_name', variable_get('site_name', ''));
|
| 195 |
$node->body = variable_get('tribune_message', '');
|
| 196 |
$node->body_filter = 2;
|
| 197 |
|
| 198 |
$node->tribune_settings['max_message_size'] = variable_get('tribune_max_message_size', 512);
|
| 199 |
$node->tribune_settings['history_size'] = variable_get('tribune_history_size', 25);
|
| 200 |
$node->tribune_settings['xml_size'] = variable_get('tribune_xml_size', 100);
|
| 201 |
$node->tribune_settings['rss_size'] = variable_get('tribune_rss_size', 50);
|
| 202 |
$node->tribune_settings['reload_delay'] = variable_get('tribune_reload_delay', 30);
|
| 203 |
$node->tribune_settings['flood_protection_delay'] = variable_get('tribune_flood_protection_delay', 3);
|
| 204 |
$node->tribune_settings['posts_order'] = (variable_get('tribune_posts_order', 'top_to_bottom') == 'top_to_bottom');
|
| 205 |
$node->tribune_settings['show_pager'] = variable_get('tribune_show_pager', FALSE);
|
| 206 |
$node->tribune_settings['enabled_filters'] = variable_get('tribune_enabled_filters', array('totoz' => 'totoz', 'url' => 'url'));
|
| 207 |
|
| 208 |
node_save($node);
|
| 209 |
|
| 210 |
if ($form_state['values']['set_alias']) {
|
| 211 |
path_set_alias('node/'. $node->nid, 'tribune');
|
| 212 |
}
|
| 213 |
|
| 214 |
db_query('UPDATE {tribune} SET tribune_id = %d WHERE tribune_id = 0', $node->nid);
|
| 215 |
|
| 216 |
drupal_set_message(t('Your tribune node was created, you can see it here: !url. Do not forget to set the !permissions_url if you want users to have access to your tribunes.', array('!url' => l($node->title, 'node/'. $node->nid), '!permissions_url' => l('permissions', 'admin/user/permissions'))));
|
| 217 |
header('Location: '. url('node/'. $node->nid));
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|