/**
 * Display an ad
 *
 * @param array $args       Displaying options
 * @return string|void      Ad code or none if echo set to true
 */
function quads_ad($args)
{
    $defaults = array('location' => '', 'echo' => true);
    $args = wp_parse_args($args, $defaults);
    $code = '';
    if (quads_has_ad($args['location'])) {
        global $quads_options;
        quads_set_ad_count_custom();
        // increase amount of shortcode ads
        $location_settings = quads_get_ad_location_settings($args['location']);
        $code .= "\n" . '<!-- WP QUADS Custom Ad v. ' . QUADS_VERSION . ' -->' . "\n";
        $code .= $quads_options['ad' . $location_settings['ad']]['code'];
    }
    if ($args['echo']) {
        echo $code;
    } else {
        return $code;
    }
}
/**
 * Return ad locations HTML based on new API.
 *
 * @param $html
 * @return string   Locations HTML
 */
function quads_render_ad_locations($html)
{
    global $_quads_registered_ad_locations;
    global $quads_options;
    if (isset($_quads_registered_ad_locations) && is_array($_quads_registered_ad_locations)) {
        foreach ($_quads_registered_ad_locations as $location => $location_args) {
            $location_settings = quads_get_ad_location_settings($location);
            $html .= QUADS()->html->checkbox(array('name' => 'quads_settings[location_settings][' . $location . '][status]', 'current' => !empty($location_settings['status']) ? $location_settings['status'] : null, 'class' => 'quads-checkbox'));
            $html .= ' ' . __('Assign', 'quick-adsense-reloaded') . ' ';
            $html .= QUADS()->html->select(array('options' => quads_get_ads(), 'name' => 'quads_settings[location_settings][' . $location . '][ad]', 'selected' => !empty($location_settings['ad']) ? $location_settings['ad'] : null, 'show_option_all' => false, 'show_option_none' => false));
            $html .= ' ' . $location_args['description'] . '</br>';
        }
    }
    return $html;
}