function ad_remote_form_submit in Advertisement 5
Same name and namespace in other branches
- 5.2 remote/ad_remote.module \ad_remote_form_submit()
- 6.3 remote/ad_remote.module \ad_remote_form_submit()
- 6 remote/ad_remote.module \ad_remote_form_submit()
- 6.2 remote/ad_remote.module \ad_remote_form_submit()
- 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 /><!--' . t('start') . '--><br />' . htmlentities(ad($group, $quantity, array(
'raw' => 1,
'hostid' => $hostid,
))) . '<br /><!--' . t('end') . '-->';
$output .= '</div></div>';
print theme('page', $output);
}