You are here

function ad_remote_form_submit in Advertisement 5

Same name and namespace in other branches
  1. 5.2 remote/ad_remote.module \ad_remote_form_submit()
  2. 6.3 remote/ad_remote.module \ad_remote_form_submit()
  3. 6 remote/ad_remote.module \ad_remote_form_submit()
  4. 6.2 remote/ad_remote.module \ad_remote_form_submit()
  5. 7 remote/ad_remote.module \ad_remote_form_submit()

Prepare quantity and group.

File

remote/ad_remote.module, line 75
Enhances the ad module to providing cut-and-paste source snippets allowing ads to be easily displayed on remote websites. This module is a proof of concept.

Code

function ad_remote_form_submit($form_id, $form_values) {
  global $user;
  if (isset($form_values['quantity'])) {

    // Sanity chacke, be sure quantity is an integer.
    $quantity = (int) $form_values['quantity'];
  }
  if (!$quantity) {

    // Must display at least one advertisement.
    $quantity = 1;
  }
  $group = NULL;
  if (is_array($form_values['group']) && !empty($form_values['group'])) {
    if ($form_values['group'][0] == 0) {
      unset($form_values['group'][0]);
    }
    $group = implode(',', $form_values['group']);

    // Sanity check, be sure group is only numbers and commas.
    $group = preg_replace('/[^0-9,]/', '', $group);
  }
  if (!$group) {
    $group = 0;
  }
  $output = '<div class="ad_remote">';

  // Instructions.
  $output .= '<div class="instructions">';
  $output .= t('Insert the following source snippet into your web page to display ads hosted on this web site.  Include the entire snippet, and do not modify it in any way.');
  $output .= '</div>';

  // Output the actual source snippet.
  $output .= '<div class="snippet">';
  $hostid = ad_host_id_create($user->uid);
  $output .= '<br />&lt;!--' . t('start') . '--&gt;<br />' . htmlentities(ad($group, $quantity, array(
    'raw' => 1,
    'hostid' => $hostid,
  ))) . '<br />&lt;!--' . t('end') . '--&gt;';
  $output .= '</div></div>';
  print theme('page', $output);
}