summaryrefslogtreecommitdiff
path: root/modules/block/block.admin.inc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/block/block.admin.inc')
-rw-r--r--modules/block/block.admin.inc109
1 files changed, 83 insertions, 26 deletions
diff --git a/modules/block/block.admin.inc b/modules/block/block.admin.inc
index 358211f3c..ba311aa0d 100644
--- a/modules/block/block.admin.inc
+++ b/modules/block/block.admin.inc
@@ -101,9 +101,18 @@ function block_admin_display_form(&$form_state, $blocks, $theme = NULL) {
*/
function block_admin_display_form_submit($form, &$form_state) {
foreach ($form_state['values'] as $block) {
- $block['status'] = $block['region'] != BLOCK_REGION_NONE;
+ $block['status'] = (int) ($block['region'] != BLOCK_REGION_NONE);
$block['region'] = $block['status'] ? $block['region'] : '';
- db_query("UPDATE {block} SET status = %d, weight = %d, region = '%s' WHERE module = '%s' AND delta = '%s' AND theme = '%s'", $block['status'], $block['weight'], $block['region'], $block['module'], $block['delta'], $block['theme']);
+ db_update('block')
+ ->fields(array(
+ 'status' => $block['status'],
+ 'weight' => $block['weight'],
+ 'region' => $block['region'],
+ ))
+ ->condition('module', $block['module'])
+ ->condition('delta', $block['delta'])
+ ->condition('theme', $block['theme'])
+ ->execute();
}
drupal_set_message(t('The block settings have been updated.'));
cache_clear_all();
@@ -156,7 +165,10 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#value' => $delta,
);
- $edit = db_fetch_array(db_query("SELECT pages, visibility, custom, title FROM {block} WHERE module = '%s' AND delta = '%s'", $module, $delta));
+ $edit = db_query("SELECT pages, visibility, custom, title FROM {block} WHERE module = :module AND delta = :delta", array(
+ ':module' => $module,
+ ':delta' => $delta,
+ ))->fetchAssoc();
$form['block_settings'] = array(
'#type' => 'fieldset',
@@ -210,7 +222,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
'#type' => 'radios',
'#title' => t('Show block on specific pages'),
'#options' => $options,
- '#default_value' => $edit['visibility'],
+ '#default_value' => (int) $edit['visibility'],
);
$form['page_vis_settings']['pages'] = array(
'#type' => 'textarea',
@@ -221,16 +233,11 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
}
// Role-based visibility settings.
- $default_role_options = array();
- $result = db_query("SELECT rid FROM {block_role} WHERE module = '%s' AND delta = '%s'", $module, $delta);
- while ($role = db_fetch_object($result)) {
- $default_role_options[] = $role->rid;
- }
- $result = db_query('SELECT rid, name FROM {role} ORDER BY name');
- $role_options = array();
- while ($role = db_fetch_object($result)) {
- $role_options[$role->rid] = $role->name;
- }
+ $default_role_options = db_query("SELECT rid FROM {block_role} WHERE module = :module AND delta = :delta", array(
+ ':module' => $module,
+ ':delta' => $delta,
+ ))->fetchCol();
+ $role_options = db_query('SELECT rid, name FROM {role} ORDER BY name')->fetchAllKeyed();
$form['role_vis_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Role specific visibility settings'),
@@ -261,7 +268,7 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
t('Hide this block by default but let individual users show it.')
),
'#description' => t('Allow individual users to customize the visibility of this block in their account settings.'),
- '#default_value' => $edit['custom'],
+ '#default_value' => (int) $edit['custom'],
);
$form['submit'] = array(
@@ -274,7 +281,10 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
function block_admin_configure_validate($form, &$form_state) {
if ($form_state['values']['module'] == 'block') {
- $box_exists = (bool) db_query_range('SELECT 1 FROM {box} WHERE bid <> :bid AND info = :info', array(':bid' => $form_state['values']['delta'], ':info' => $form_state['values']['info']), 0, 1)->fetchField();
+ $box_exists = (bool) db_query_range('SELECT 1 FROM {box} WHERE bid <> :bid AND info = :info', array(
+ ':bid' => $form_state['values']['delta'],
+ ':info' => $form_state['values']['info'],
+ ), 0, 1)->fetchField();
if (empty($form_state['values']['info']) || $box_exists) {
form_set_error('info', t('Please ensure that each block description is unique.'));
}
@@ -283,11 +293,29 @@ function block_admin_configure_validate($form, &$form_state) {
function block_admin_configure_submit($form, &$form_state) {
if (!form_get_errors()) {
- db_query("UPDATE {block} SET visibility = %d, pages = '%s', custom = %d, title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $form_state['values']['delta']);
- db_query("DELETE FROM {block_role} WHERE module = '%s' AND delta = '%s'", $form_state['values']['module'], $form_state['values']['delta']);
+ db_update('block')
+ ->fields(array(
+ 'visibility' => $form_state['values']['visibility'],
+ 'pages' => trim($form_state['values']['pages']),
+ 'custom' => $form_state['values']['custom'],
+ 'title' => $form_state['values']['title'],
+ ))
+ ->condition('module', $form_state['values']['module'])
+ ->condition('delta', $form_state['values']['delta'])
+ ->execute();
+ db_delete('block_role')
+ ->condition('module', $form_state['values']['module'])
+ ->condition('delta', $form_state['values']['delta'])
+ ->execute();
+ $query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
foreach (array_filter($form_state['values']['roles']) as $rid) {
- db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $form_state['values']['delta']);
+ $query->values(array(
+ 'rid' => $rid,
+ 'module' => $form_state['values']['module'],
+ 'delta' => $form_state['values']['delta'],
+ ));
}
+ $query->execute();
module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']);
drupal_set_message(t('The block configuration has been saved.'));
cache_clear_all();
@@ -315,18 +343,42 @@ function block_add_block_form_validate($form, &$form_state) {
* Save the new custom block.
*/
function block_add_block_form_submit($form, &$form_state) {
- db_query("INSERT INTO {box} (body, info, format) VALUES ('%s', '%s', %d)", $form_state['values']['body'], $form_state['values']['info'], $form_state['values']['body_format']);
- $delta = db_last_insert_id('box', 'bid');
-
+ $delta = db_insert('box')
+ ->fields(array(
+ 'body' => $form_state['values']['body'],
+ 'info' => $form_state['values']['info'],
+ 'format' => $form_state['values']['body_format'],
+ ))
+ ->execute();
+
+ $query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache'));
foreach (list_themes() as $key => $theme) {
if ($theme->status) {
- db_query("INSERT INTO {block} (visibility, pages, custom, title, module, theme, status, weight, delta, cache) VALUES(%d, '%s', %d, '%s', '%s', '%s', %d, %d, '%s', %d)", $form_state['values']['visibility'], trim($form_state['values']['pages']), $form_state['values']['custom'], $form_state['values']['title'], $form_state['values']['module'], $theme->name, 0, 0, $delta, BLOCK_NO_CACHE);
+ $query->values(array(
+ 'visibility' => $form_state['values']['visibility'],
+ 'pages' => trim($form_state['values']['pages']),
+ 'custom' => $form_state['values']['custom'],
+ 'title' => $form_state['values']['title'],
+ 'module' => $form_state['values']['module'],
+ 'theme' => $theme->name,
+ 'status' => 0,
+ 'weight' => 0,
+ 'delta' => $delta,
+ 'cache' => BLOCK_NO_CACHE,
+ ));
}
}
+ $query->execute();
+ $query = db_insert('block_role')->fields(array('rid', 'module', 'delta'));
foreach (array_filter($form_state['values']['roles']) as $rid) {
- db_query("INSERT INTO {block_role} (rid, module, delta) VALUES (%d, '%s', '%s')", $rid, $form_state['values']['module'], $delta);
+ $query->values(array(
+ 'rid' => $rid,
+ 'module' => $form_state['values']['module'],
+ 'delta' => $delta,
+ ));
}
+ $query->execute();
drupal_set_message(t('The block has been created.'));
cache_clear_all();
@@ -349,8 +401,13 @@ function block_box_delete(&$form_state, $bid = 0) {
* Deletion of custom blocks.
*/
function block_box_delete_submit($form, &$form_state) {
- db_query('DELETE FROM {box} WHERE bid = %d', $form_state['values']['bid']);
- db_query("DELETE FROM {block} WHERE module = 'block' AND delta = '%s'", $form_state['values']['bid']);
+ db_delete('box')
+ ->condition('bid', $form_state['values']['bid'])
+ ->execute();
+ db_delete('block')
+ ->condition('module', 'block')
+ ->condition('delta', $form_state['values']['bid'])
+ ->execute();
drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info'])));
cache_clear_all();
$form_state['redirect'] = 'admin/build/block';