| 1 |
<?php
|
| 2 |
// $Id: quotes.admin.inc,v 1.4 2009/10/11 01:01:25 nancyw Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* The quotes module allows users to maintain a list of quotes that
|
| 6 |
* can be displayed in any number of administrator-defined quote
|
| 7 |
* blocks.
|
| 8 |
*
|
| 9 |
* @copyright Copyright (c) 2003-2007 Jim Riggs. All rights reserved.
|
| 10 |
* @author Jim Riggs <drupal at jim and lissa dot com>
|
| 11 |
*/
|
| 12 |
|
| 13 |
/**
|
| 14 |
* Displays the admin settings page.
|
| 15 |
*/
|
| 16 |
function quotes_admin_settings_page() {
|
| 17 |
return drupal_get_form('quotes_admin_settings');
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Displays the general admin settings form.
|
| 22 |
*
|
| 23 |
* @return
|
| 24 |
* An array containing the form elements to be displayed.
|
| 25 |
*/
|
| 26 |
function quotes_admin_settings() {
|
| 27 |
$form = array();
|
| 28 |
drupal_add_css(drupal_get_path('module', 'quotes') . '/quotes.css');
|
| 29 |
$yesno = array(1 => t('Yes'), 0 => t('No'));
|
| 30 |
|
| 31 |
$form['display'] = array(
|
| 32 |
'#type' => 'fieldset',
|
| 33 |
'#title' => t('Display Options'),
|
| 34 |
'#collapsible' => TRUE,
|
| 35 |
'#collapsed' => FALSE,
|
| 36 |
'#description' => t('These options are for general theming.'),
|
| 37 |
);
|
| 38 |
|
| 39 |
$form['display']['quotes_leader'] = array(
|
| 40 |
'#type' => 'textfield',
|
| 41 |
'#title' => t('Author leader'),
|
| 42 |
'#default_value' => variable_get('quotes_leader', '—'),
|
| 43 |
'#description' => t('The text placed before the author attribution (e.g. "&mdash;" for an em-dash or "&#8226;" for a bullet).')
|
| 44 |
);
|
| 45 |
|
| 46 |
$form['display']['quotes_author_link'] = array(
|
| 47 |
'#type' => 'radios',
|
| 48 |
'#options' => $yesno,
|
| 49 |
'#title' => t('Make author a link'),
|
| 50 |
'#default_value' => (int) variable_get('quotes_author_link', FALSE),
|
| 51 |
'#description' => t('If selected, the author text will be a link to show all quotes by that author.'),
|
| 52 |
'#prefix' => '<div class="quotes-radios">',
|
| 53 |
'#suffix' => '</div>',
|
| 54 |
);
|
| 55 |
|
| 56 |
$form['display']['quotes_author_bio'] = array(
|
| 57 |
'#type' => 'radios',
|
| 58 |
'#options' => array(0 => t("Don't display"), 1 => t('Include text'), 2 => t('Include as a link')),
|
| 59 |
'#title' => t("Include author's bio"),
|
| 60 |
'#default_value' => (int) variable_get('quotes_author_bio', FALSE),
|
| 61 |
'#description' => t("If selected, the author's biography will be shown on the Quotes page."),
|
| 62 |
'#prefix' => '<div class="quotes-radios">',
|
| 63 |
'#suffix' => '</div>',
|
| 64 |
);
|
| 65 |
|
| 66 |
$form['display']['quotes_per_page'] = array(
|
| 67 |
'#type' => 'textfield',
|
| 68 |
'#title' => t('Quotes per page'),
|
| 69 |
'#size' => 6,
|
| 70 |
'#default_value' => variable_get('quotes_per_page', 10),
|
| 71 |
'#description' => t('The number of quotes included on a page.'),
|
| 72 |
'#prefix' => '<div class="clear-block"></div>',
|
| 73 |
);
|
| 74 |
|
| 75 |
$form['display']['quotes_edit_link'] = array(
|
| 76 |
'#type' => 'radios',
|
| 77 |
'#options' => $yesno,
|
| 78 |
'#prefix' => '<div class="quotes-radios">',
|
| 79 |
'#suffix' => '</div>',
|
| 80 |
'#title' => t('Add an "edit" link'),
|
| 81 |
'#default_value' => (int) variable_get('quotes_edit_link', TRUE),
|
| 82 |
'#description' => t('If selected, an "edit" link will be shown for each quote.'),
|
| 83 |
);
|
| 84 |
|
| 85 |
$form['myquotes'] = array(
|
| 86 |
'#type' => 'fieldset',
|
| 87 |
'#title' => t('My Quotes links'),
|
| 88 |
'#collapsible' => TRUE,
|
| 89 |
'#collapsed' => FALSE,
|
| 90 |
);
|
| 91 |
|
| 92 |
$form['myquotes']['quotes_showlink'] = array(
|
| 93 |
'#type' => 'radios',
|
| 94 |
'#options' => $yesno,
|
| 95 |
'#prefix' => '<div class="quotes-radios">',
|
| 96 |
'#suffix' => '</div>',
|
| 97 |
'#title' => t('Show link to users\' quotes'),
|
| 98 |
'#default_value' => (int) variable_get('quotes_showlink', TRUE),
|
| 99 |
'#description' => t('Uncheck this to disable the link to each users\' "my quotes" page when viewing a node.')
|
| 100 |
);
|
| 101 |
|
| 102 |
$form['myquotes']['quotes_show_myquotes_original'] = array(
|
| 103 |
'#type' => 'value',
|
| 104 |
'#value' => variable_get('quotes_show_myquotes', TRUE),
|
| 105 |
);
|
| 106 |
|
| 107 |
$form['myquotes']['quotes_show_myquotes'] = array(
|
| 108 |
'#type' => 'radios',
|
| 109 |
'#options' => $yesno,
|
| 110 |
'#prefix' => '<div class="quotes-radios">',
|
| 111 |
'#suffix' => '</div>',
|
| 112 |
'#title' => t('Show the "my quotes" menu item'),
|
| 113 |
'#default_value' => (int) variable_get('quotes_show_myquotes', TRUE),
|
| 114 |
'#description' => t('Uncheck this to disable the "My quotes" menu item for all users. Note, changing this setting will <a href="!url">require the menu to be rebuilt</a>.', array('!url' => url('admin/settings/performance')))
|
| 115 |
);
|
| 116 |
|
| 117 |
$form['user'] = array(
|
| 118 |
'#type' => 'fieldset',
|
| 119 |
'#title' => t('User Options'),
|
| 120 |
'#collapsible' => TRUE,
|
| 121 |
'#collapsed' => FALSE,
|
| 122 |
'#description' => t('These options are for users.'),
|
| 123 |
);
|
| 124 |
|
| 125 |
$form['user']['quotes_user_recent'] = array(
|
| 126 |
'#type' => 'radios',
|
| 127 |
'#options' => $yesno,
|
| 128 |
'#prefix' => '<div class="quotes-radios">',
|
| 129 |
'#suffix' => '</div>',
|
| 130 |
'#title' => t('Add a "Recent quotes" link on the "My account" page?'),
|
| 131 |
'#default_value' => (int) variable_get('quotes_user_recent', FALSE),
|
| 132 |
);
|
| 133 |
|
| 134 |
$form['#submit'][] = '_quotes_settings_form_submit';
|
| 135 |
return system_settings_form($form);
|
| 136 |
}
|
| 137 |
|
| 138 |
/**
|
| 139 |
* Check the menu settings for changes..
|
| 140 |
*/
|
| 141 |
function _quotes_settings_form_submit($form, &$form_state) {
|
| 142 |
if ($form_state['values']['quotes_show_myquotes'] != $form_state['values']['quotes_show_myquotes_original']) {
|
| 143 |
// Force the menu to be rebuilt.
|
| 144 |
menu_rebuild();
|
| 145 |
}
|
| 146 |
}
|
| 147 |
|
| 148 |
/**
|
| 149 |
* Export function page.
|
| 150 |
*
|
| 151 |
* @return
|
| 152 |
* A form with a tab-delimited list of quotes.
|
| 153 |
*/
|
| 154 |
function quotes_export() {
|
| 155 |
$form['intro'] = array(
|
| 156 |
'#type' => 'item',
|
| 157 |
'#title' => t('Copy and paste this list to the receiving site'),
|
| 158 |
);
|
| 159 |
|
| 160 |
$output = NULL;
|
| 161 |
$count = 0;
|
| 162 |
//$sql = db_rewrite_sql("SELECT nr.body, nr.title, qa.name AS author, q.citation FROM {node} n INNER JOIN {node_revisions} nr USING (vid) INNER JOIN {quotes} q USING (vid) INNER JOIN {quotes_authors} qa USING (aid) WHERE n.status=1 AND n.type='quotes' ORDER BY qa.name");
|
| 163 |
$query = db_select('node', 'n');
|
| 164 |
$nr_alias = $query->join('node_revision', 'nr', 'nr.vid = n.vid');
|
| 165 |
$q_alais = $query->join('quotes', 'q', 'q.vid=n.vid');
|
| 166 |
$qa_alais = $query->join('quotes_authors', 'qa', 'qa.aid=n.vid');
|
| 167 |
$query
|
| 168 |
->fields('n', array('nid'))
|
| 169 |
->condition('n.status', '1')
|
| 170 |
->condition('n.type', 'quotes')
|
| 171 |
->orderby('qa.name');
|
| 172 |
$query->addTag('node_access');
|
| 173 |
$result = $query->execute();
|
| 174 |
|
| 175 |
|
| 176 |
while ($row = db_fetch_object($result)) {
|
| 177 |
++$count;
|
| 178 |
$output .= _quotes_escape_newlines($row->body) . "\t" .
|
| 179 |
_quotes_escape_newlines($row->author) . "\t" .
|
| 180 |
_quotes_escape_newlines($row->citation) . "\n";
|
| 181 |
}
|
| 182 |
drupal_set_message(t('Found !count quotes.', array('!count' => $count)));
|
| 183 |
if ($count == 0) {
|
| 184 |
$count = 1;
|
| 185 |
$output = t('No quotes were found.');
|
| 186 |
}
|
| 187 |
|
| 188 |
$form['list'] = array(
|
| 189 |
'#type' => 'textarea',
|
| 190 |
'#value' => $output,
|
| 191 |
'#rows' => min(30, $count),
|
| 192 |
);
|
| 193 |
|
| 194 |
return $form;
|
| 195 |
}
|
| 196 |
|
| 197 |
/**
|
| 198 |
* Helper function to strip Windows newline and format Unix newlines.
|
| 199 |
*
|
| 200 |
* @param $text
|
| 201 |
* The text to be scanned.
|
| 202 |
* @return
|
| 203 |
* Text with newlines processed.
|
| 204 |
*/
|
| 205 |
function _quotes_escape_newlines($text) {
|
| 206 |
// Get rid of Windows crap.
|
| 207 |
$text = str_replace("\r", '', $text);
|
| 208 |
return str_replace("\n", "\\\n", $text);
|
| 209 |
}
|
| 210 |
|
| 211 |
/**
|
| 212 |
* Displays a list of currently-defined quote blocks.
|
| 213 |
*
|
| 214 |
* @return
|
| 215 |
* An array containing the form elements to be displayed.
|
| 216 |
*/
|
| 217 |
function quotes_blocks_settings() {
|
| 218 |
$form = array();
|
| 219 |
$form['name'] = array(
|
| 220 |
'#type' => 'textfield',
|
| 221 |
'#size' => 32,
|
| 222 |
'#maxlength' => 64
|
| 223 |
);
|
| 224 |
$form['submit'] = array(
|
| 225 |
'#type' => 'submit',
|
| 226 |
'#value' => t('Add block')
|
| 227 |
);
|
| 228 |
|
| 229 |
return $form;
|
| 230 |
}
|
| 231 |
|
| 232 |
/**
|
| 233 |
* Validates that the new block name is valid.
|
| 234 |
*/
|
| 235 |
function quotes_blocks_settings_validate($form, &$form_state) {
|
| 236 |
$name = trim($form_state['values']['name']);
|
| 237 |
|
| 238 |
if (!$name) {
|
| 239 |
form_set_error('name', t('You must specify a valid block name.'));
|
| 240 |
}
|
| 241 |
elseif (db_result(db_query("SELECT 1 FROM {quotes_blocks} qb WHERE qb.name = '%s'", $name))) {
|
| 242 |
form_set_error('name', t('The block name %name already exists. Please choose another block name.', array('%name' => $name)));
|
| 243 |
}
|
| 244 |
}
|
| 245 |
|
| 246 |
/**
|
| 247 |
* Creates the new quote block.
|
| 248 |
*
|
| 249 |
* @param $form
|
| 250 |
* The string specifying the form ID of the form that was submitted.
|
| 251 |
* @param $form
|
| 252 |
* The array specifying the form values.
|
| 253 |
*/
|
| 254 |
function quotes_blocks_settings_submit($form, &$form_state) {
|
| 255 |
db_query("INSERT INTO {quotes_blocks} (name, block_type, nid_filter, aid_filter, rid_filter, uid_filter, tid_filter, cron_interval, cron_step, cron_last, vid) VALUES ('%s', 0, '', '', '', '', '', 0, 0, 0, 0)", trim($form_state['values']['name']));
|
| 256 |
}
|
| 257 |
|
| 258 |
/**
|
| 259 |
* Renders the quote block list, including the "Add block" row.
|
| 260 |
*
|
| 261 |
* @param $form
|
| 262 |
* The array specifying the form to be rendered.
|
| 263 |
*
|
| 264 |
* @result
|
| 265 |
* The formatted HTML table of blocks.
|
| 266 |
*/
|
| 267 |
function theme_quotes_blocks_settings($form) {
|
| 268 |
$header = array(t('Name'), t('Filters'), array('data' => t('Operations'), 'colspan' => 2));
|
| 269 |
$result = db_query('SELECT qb.* FROM {quotes_blocks} qb ORDER BY qb.name');
|
| 270 |
$rows = array();
|
| 271 |
|
| 272 |
while ($block = db_fetch_object($result)) {
|
| 273 |
$filters = array();
|
| 274 |
|
| 275 |
if ($block->nid_filter) {
|
| 276 |
$filters[] = t('node');
|
| 277 |
}
|
| 278 |
|
| 279 |
if ($block->rid_filter) {
|
| 280 |
$filters[] = t('role');
|
| 281 |
}
|
| 282 |
|
| 283 |
if ($block->uid_filter) {
|
| 284 |
$filters[] = t('user');
|
| 285 |
}
|
| 286 |
|
| 287 |
if ($block->tid_filter) {
|
| 288 |
$filters[] = t('term');
|
| 289 |
}
|
| 290 |
|
| 291 |
$rows[] = array(
|
| 292 |
$block->name,
|
| 293 |
implode(', ', (count($filters) ? $filters : array(t('none')))),
|
| 294 |
l(t('configure block'), "admin/build/block/configure/quotes/$block->bid"),
|
| 295 |
l(t('delete block'), "admin/settings/quotes/delete/$block->bid")
|
| 296 |
);
|
| 297 |
}
|
| 298 |
|
| 299 |
$rows[] = array(
|
| 300 |
drupal_render($form['name']),
|
| 301 |
array('data' => drupal_render($form['submit']), 'colspan' => 3)
|
| 302 |
);
|
| 303 |
|
| 304 |
$output = drupal_render($form);
|
| 305 |
|
| 306 |
if (count($rows)) {
|
| 307 |
$output .= theme('table', $header, $rows);
|
| 308 |
}
|
| 309 |
else {
|
| 310 |
$output .= theme('table', $header, array(array(array('data' => t('No blocks are defined.'), 'colspan' => 4))));
|
| 311 |
}
|
| 312 |
|
| 313 |
return $output;
|
| 314 |
}
|
| 315 |
|
| 316 |
/**
|
| 317 |
* Confirms the deletion a quote block.
|
| 318 |
*
|
| 319 |
* @param $bid
|
| 320 |
* The block ID of the block being deleted.
|
| 321 |
*
|
| 322 |
* @return
|
| 323 |
* A string containing the confirmation form displayed to the user.
|
| 324 |
*/
|
| 325 |
function _quotes_block_delete($form_stuff, $bid) {
|
| 326 |
$block = db_fetch_object(db_query('SELECT qb.name FROM {quotes_blocks} qb WHERE qb.bid = %d', $bid));
|
| 327 |
|
| 328 |
$form = array();
|
| 329 |
$form['bid'] = array(
|
| 330 |
'#type' => 'value',
|
| 331 |
'#value' => $bid
|
| 332 |
);
|
| 333 |
$form['block_name'] = array(
|
| 334 |
'#type' => 'value',
|
| 335 |
'#value' => $block->name
|
| 336 |
);
|
| 337 |
|
| 338 |
return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $block->name)), 'admin/settings/quotes/blocks', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
|
| 339 |
}
|
| 340 |
|
| 341 |
/**
|
| 342 |
* Deletes the specified block.
|
| 343 |
*
|
| 344 |
* @param $form
|
| 345 |
* The string specifying the form ID of the form that was submitted.
|
| 346 |
* @param $form_state
|
| 347 |
* The array specifying the form values.
|
| 348 |
*
|
| 349 |
* @result
|
| 350 |
* A string specifying the page to which the user should be
|
| 351 |
* redirected (admin/settings/quotes/blocks).
|
| 352 |
*/
|
| 353 |
Function _quotes_block_delete_submit($form, &$form_state) {
|
| 354 |
db_query("DELETE FROM {quotes_blocks} WHERE bid = %d", $form_state['values']['bid']);
|
| 355 |
drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['block_name'])));
|
| 356 |
cache_clear_all();
|
| 357 |
|
| 358 |
$form_state['redirect'] = 'admin/settings/quotes/blocks';
|
| 359 |
return;
|
| 360 |
}
|
| 361 |
|
| 362 |
/**
|
| 363 |
* Bios maintenance page.
|
| 364 |
*
|
| 365 |
* @return
|
| 366 |
* A form with a tab-delimited list of quotes.
|
| 367 |
*/
|
| 368 |
function quotes_bios(&$form_state, $aid = NULL) {
|
| 369 |
$form = array();
|
| 370 |
$first_pass = is_null($aid);
|
| 371 |
|
| 372 |
if ($first_pass) {
|
| 373 |
$auths = quotes_get_authors();
|
| 374 |
$count = count($auths);
|
| 375 |
$data = array('name' => NULL, 'bio' => NULL);
|
| 376 |
}
|
| 377 |
else {
|
| 378 |
// Get the data.
|
| 379 |
$data = db_fetch_array(db_query("SELECT * FROM {quotes_authors} WHERE aid=%d", $aid));
|
| 380 |
}
|
| 381 |
|
| 382 |
$form['aid'] = array(
|
| 383 |
'#type' => 'hidden',
|
| 384 |
'#value' => $aid,
|
| 385 |
);
|
| 386 |
|
| 387 |
$form['author'] = array(
|
| 388 |
'#type' => 'select',
|
| 389 |
'#options' => $auths,
|
| 390 |
'#size' => min(20, $count),
|
| 391 |
'#description' => t('Pick the author whose biography you wish to update.'),
|
| 392 |
);
|
| 393 |
|
| 394 |
$form['name'] = array(
|
| 395 |
'#type' => 'markup',
|
| 396 |
'#value' => '<h3>' . t('Biography for %name', array('%name' => $data['name'])) . '</h3>',
|
| 397 |
);
|
| 398 |
|
| 399 |
$form['bio'] = array(
|
| 400 |
'#type' => 'textarea',
|
| 401 |
'#description' => t("This is the author's biography."),
|
| 402 |
'#default_value' => $data['bio'],
|
| 403 |
);
|
| 404 |
|
| 405 |
$form['submit'] = array(
|
| 406 |
'#type' => 'submit',
|
| 407 |
'#value' => $first_pass ? t('Get biography') : t('Update'),
|
| 408 |
);
|
| 409 |
|
| 410 |
// Show the fields at the right time.
|
| 411 |
if ($first_pass) {
|
| 412 |
$form['name']['#type'] = 'hidden';
|
| 413 |
$form['bio']['#type'] = 'hidden';
|
| 414 |
}
|
| 415 |
else {
|
| 416 |
$form['author']['#type'] = 'hidden';
|
| 417 |
}
|
| 418 |
|
| 419 |
return $form;
|
| 420 |
}
|
| 421 |
|
| 422 |
function quotes_bios_submit($form, &$form_state) {
|
| 423 |
if ($form_state['values']['op'] == 'Update') {
|
| 424 |
$vals = array($form_state['values']['bio'], $form_state['values']['aid']);
|
| 425 |
$upd = db_query("UPDATE {quotes_authors} SET bio='%s' WHERE aid=%d", $vals);
|
| 426 |
$form_state['redirect'] = BIOS_PATH;
|
| 427 |
}
|
| 428 |
else {
|
| 429 |
$form_state['redirect'] = BIOS_PATH . '/' . $form_state['values']['author'];
|
| 430 |
}
|
| 431 |
}
|