Contributions API

pingback_form_alter

Definition

pingback_form_alter(&$form, &$form_state, $form_id)
contributions/pingback/pingback.module, line 28

Description

Implementation of hook_form_alter().

Code

<?php
function pingback_form_alter(&$form, &$form_state, $form_id) {
  global $user;
  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
    $type = $form['#node_type']->type;
    $form['workflow']['pingback'] = array(
      '#type' => 'radios',
      '#title' => t('Pingbacks'),
      '#options' => array(1 => t('Enabled'), 0 => t('Disabled')),
      '#default_value' => _pingback_valid_for_node_type($type),
      '#description' => t('Enable pingbacks for this node type.')
    );
  }
  else if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
    $node = $form['#node'];
    if (_pingback_valid_for_node_type($node->type)) {
      // if there are any past successful pingbacks from this posting, add them to the node editing page.
      $past_successes_listing = array();
      $q = db_query("SELECT url FROM {pingback_sent} WHERE nid = %d", $node->nid);
      while ($pb = db_fetch_object($q)) {
        $past_successes_listing[] = $pb->url;
      }
      // add listing of successfully pingbacked URLs
      if (count($past_successes_listing)) {
        $form['pingback'] = array(
          '#type' => 'fieldset',
          '#title' => t('Pingbacks'),
          '#collapsible' => TRUE
        );
        $form['pingback'][] = array(
          '#type' => 'markup',
          '#value' => theme('item_list', $past_successes_listing, t('Successfully pingbacked URLs')),
        );
        //t('These URLs have been successfuly pinged by this post.')
      }
    }
  }
  //hide pingback input format if desired for anon users
  else if (
    $form_id == 'comment_form'
    && (!$user->uid)
    && variable_get('pingback_hide_format_for_anon', 0)
    //&& (isset($GLOBALS['pingback_bypass_format_hiding']) ? !$GLOBALS['pingback_bypass_format_hiding'] : TRUE)
  ) {
    //dpm($form);
    $alternate_formats = array();
    foreach ($form['comment_filter']['format'] as $k => $v) {
      //dpm($k);
      if (!element_property($k) && isset($v['#return_value'])) {
        if ($v['#return_value'] == variable_get('pingback_input_format', FILTER_FORMAT_DEFAULT)) {
          unset($form['comment_filter']['format'][$k]);
        }
        else {
          // Make a list of alternate formats for the comment form.
          $alternate_formats[] = $k;
        }
      }
    }
    if (count($alternate_formats) == 1) {
      // There is only one available format. Remove fieldset and go back to hidden form field.
      $new_form[$alternate_formats[0]] = array(
        '#type' => 'value',
        '#value' => $alternate_formats[0],
        '#parents' => $form['comment_filter']['format'][$alternate_formats[0]]['#parents'],
      );
      $new_form['format']['guidelines'] = array(
        '#title' => t('Formatting guidelines'),
        '#value' => $form['comment_filter']['format'][$alternate_formats[0]]['#description'],
      );
      $form['comment_filter']['format'] = $new_form;
    }
  }
}
?>