' . __('Settings', 'dfrads') . ''; array_unshift($links, $settings_link); return $links; } // Parse $_GET values function dfrads_return_get($field) { if (isset($_GET[$field]) && trim($_GET[$field]) != '') { return trim($_GET[$field]); } return false; } // Parse $_POST values function dfrads_return_post($field) { if (isset($_POST[$field]) && trim($_POST[$field]) != '') { return trim($_POST[$field]); } return false; } // Determine what to do function dfrads_options() { if (isset($_POST['submit-add-group'])) { check_admin_referer('dfrads_add_group'); $ads = ''; foreach ($_POST as $k => $v) { if (preg_match("/\bad_/", $k) && trim($v) != '') { $ads .= trim($v) . '[DFRADS]'; } } if ($ads != '') { $ads = substr($ads, 0, -8); } $dfrads = get_option('dfrads'); $new_group_id = dfrads_new_group_id($dfrads); $dfrads[$new_group_id]['name'] = (trim($_POST['group_name']) != '') ? stripslashes(trim($_POST['group_name'])) : $new_group_id; $dfrads[$new_group_id]['before_ad'] = stripslashes(trim($_POST['before_ad'])); $dfrads[$new_group_id]['after_ad'] = stripslashes(trim($_POST['after_ad'])); $dfrads[$new_group_id]['ads'] = stripslashes($ads); update_option('dfrads', $dfrads); } if (isset($_POST['submit-edit-group'])) { check_admin_referer('dfrads_edit_group'); $ads = ''; foreach ($_POST as $k => $v) { if (preg_match("/\bad_/", $k) && trim($v) != '') { $ads .= trim($v) . '[DFRADS]'; } } if ($ads != '') { $ads = substr($ads, 0, -8); } $dfrads = get_option('dfrads'); $group_id = $_POST['group_id']; $dfrads[$group_id]['name'] = (trim($_POST['group_name']) != '') ? stripslashes(trim($_POST['group_name'])) : $group_id; $dfrads[$group_id]['before_ad'] = stripslashes(trim($_POST['before_ad'])); $dfrads[$group_id]['after_ad'] = stripslashes(trim($_POST['after_ad'])); $dfrads[$group_id]['ads'] = stripslashes($ads); update_option('dfrads', $dfrads); } if (dfrads_return_get('action') == 'edit' && dfrads_return_get('group_id')) { dfrads_edit_group(dfrads_return_get('group_id')); } elseif (dfrads_return_get('action') == 'add') { dfrads_add_group(); } elseif (dfrads_return_get('action') == 'duplicate' && dfrads_return_get('group_id')) { dfrads_duplicate_group(dfrads_return_get('group_id')); } elseif (dfrads_return_get('action') == 'delete' && dfrads_return_get('group_id')) { dfrads_delete_group(dfrads_return_get('group_id')); } else { dfrads_show_groups(); } } // Add CSS, JS and initial HTML function dfrads_header($page = '') {?>

Datafeedr Random Ads V2

function dfrads_footer() { echo '
'; } // Show All Groups function dfrads_show_groups() { dfrads_header(); ?> $v) { $i++; if ($i % 2 == 0) { $class = "alternate"; } else { $class = ""; } $name = ($v['name'] == '') ? $k : $v['name']; ?> '; } ?>
Ad ID Ad Name Template Code Actions
Ad ID Ad Name Template Code Actions
<?php if (function_exists('dfrads')) { echo dfrads(''); } ?> edit | "'> | "' onclick="return confirm(' \n\n ')" class="delete" >
There are no ad groups. Create a new group.
Ad #{$i} (Remove this ad) {$ad}
"; } dfrads_header('edit'); ?>

Optional Fields

The following fields are optional. You can insert text and/or HTML code before or after the entire ad group and each individual ad.

Ad Group Name: (No HTML. This field will not appear on your site.)
Before Ad:
After Ad:

Ad Boxes

Enter one ad into each box. To add additional boxes, click the "Add Box" link at the bottom of this page.

Add Box

Optional Fields

The following fields are optional. You can insert text and/or HTML code before or after the entire ad group and each individual ad.

Ad Group Name (No HTML. This field will not appear on your site.)
Before Ad:
After Ad:

Ad Boxes

Enter one ad into each box. To add additional boxes, click the "Add Box" button at the bottom of this page.

Ad #1 (Remove this ad)
Add Box
Datafeedr Random Ads Message:
' . $msg . ''; } return ''; } // Display the ads from a template function function dfrads($group_id = false) { if (!$group_id) { return dfrads_display_admin_error('A group ID is required.'); } $dfrads = get_option('dfrads'); if (!is_array($dfrads[$group_id])) { return dfrads_display_admin_error('The ad group "' . $group_id . '" does not exist.'); } $ads = explode('[DFRADS]', $dfrads[$group_id]['ads']); $num_ads = count($ads); $ad_id = mt_rand(1, $num_ads); $ad = $ads[($ad_id - 1)]; return $dfrads[$group_id]['before_ad'] . $ad . $dfrads[$group_id]['after_ad']; } /** * Add function to widgets_init that'll load our widget. * @since 0.1 */ add_action('widgets_init', 'example_load_widgets'); /** * Register our widget. * 'DfrAds_Widget' is the widget class used below. * * @since 0.1 */ function example_load_widgets() { register_widget('DfrAds_Widget'); } /** * Example Widget class. * This class handles everything that needs to be handled with the widget: * the settings, form, display, and update. Nice! * * @since 0.1 */ class DfrAds_Widget extends WP_Widget { /** * Widget setup. */ function __construct() { /* Widget settings. */ $widget_ops = array('classname' => 'dfrads', 'description' => __('Display your rotating ads in the sidebar.', 'dfrads')); /* Widget control settings. */ $control_ops = array('id_base' => 'dfrads-widget'); /* Create the widget. */ parent::__construct('dfrads-widget', __('Datafeedr Random Ads', 'dfrads'), $widget_ops, $control_ops); } /** * How to display the widget on the screen. */ function widget($args, $instance) { extract($args); /* Our variables from the widget settings. */ $title = apply_filters('widget_title', $instance['title']); $group_id = $instance['group_id']; /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ($title) { echo $before_title . $title . $after_title; } /* Display name from widget settings if one was input. */ echo dfrads($group_id); /* After widget (defined by themes). */ echo $after_widget; } /** * Update the widget settings. */ function update($new_instance, $old_instance) { $instance = $old_instance; /* Strip tags for title and name to remove HTML (important for text inputs). */ $instance['title'] = strip_tags($new_instance['title']); /* No need to strip tags for sex and show_sex. */ $instance['group_id'] = $new_instance['group_id']; return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form($instance) { /* Set up some default widget settings. */ $defaults = array('title' => __('Our Sponsors', 'dfrads')); $instance = wp_parse_args((array) $instance, $defaults); $dfrads = get_option('dfrads'); ?>