You are here

function sharedblocks_subscribe_form_submit in Shared Blocks 6

Same name and namespace in other branches
  1. 7 sharedblocks.module \sharedblocks_subscribe_form_submit()

Submit callback for subscription block add/edit form.

File

./sharedblocks.module, line 268

Code

function sharedblocks_subscribe_form_submit($form, &$form_state) {
  $values = $form_state['values'];

  // Fetch the block from the publishing site.
  $block_data = sharedblocks_fetch_block($values['url']);
  if (!$block_data) {
    drupal_set_message(t('Block information not received, please check your URL.'), 'error');
  }

  // Specify to drupal_write_record() whether we're doing an insert or update.
  if (is_null($values['id'])) {
    $update = array();
  }
  else {
    $update = array(
      'id',
    );
    $record['id'] = $values['id'];
  }

  // Prep our values for the database.
  $record['name'] = $values['name'];
  $record['url'] = $values['url'];
  $record['update_interval'] = (int) $values['update_interval'];
  $record['block_data'] = serialize($block_data);
  $record['description'] = $block_data->subject;
  $record['last_update'] = time();
  $record['expiration'] = time() + $values['update_interval'];

  // Populate the table with values.
  drupal_write_record('sharedblocks', $record, $update);

  // Redirect back to the listing page.
  $form_state['redirect'] = 'admin/settings/sharedblocks/subscribe';
  drupal_set_message(t('Your subscription block has been saved.'));
}