function validate_range($inp, $field, $minval, $maxval, $user_default)
{
    if (false === $user_default) {
        $default_value = sss_settings_defaults($field);
    } else {
        $default_value = $user_default;
    }
    $safe_inp = (int) $inp;
    if (!ctype_digit($inp) or $safe_inp < $minval or $safe_inp > $maxval) {
        return $default_value;
    } else {
        return $safe_inp;
    }
}
function sss_handle_shortcode($attrs)
{
    $resp = '';
    $defaults = get_option('sss_settings');
    if (!$defaults) {
        $defaults = sss_settings_defaults(NULL, true);
    }
    $stored_cycle_version = $defaults['cycle_version'];
    // Stops a possible injection of cycle_version as shortcode argument
    unset($defaults['cycle_version']);
    extract(sss_settings_validate(shortcode_atts($defaults, $attrs), true));
    // Will always be 'lite' (so wrong) - use $stored_cycle_version instead
    unset($cycle_version);
    $images =& get_children('post_type=attachment&post_mime_type=' . 'image&post_parent=' . get_the_ID() . '&orderby=menu_order&order=ASC');
    // Don't load anything or start processing if there are no
    // images to display.
    if (empty($images)) {
        return '';
    }
    if (!empty($attrs['exclude'])) {
        $exclude = explode(',', $attrs['exclude']);
        foreach ($exclude as $image_id) {
            unset($images[trim($image_id)]);
        }
    }
    // Figure out the maximum size of the images being displayed so we can
    // set the smallest possible fixed-size container to cycle in.
    $thumb_w = $thumb_h = 0;
    $captions = array();
    foreach ($images as $image_id => $image_data) {
        $info = wp_get_attachment_metadata($image_id);
        $thumb_w = max($thumb_w, $info['sizes'][$size]['width']);
        $thumb_h = max($thumb_h, $info['sizes'][$size]['height']);
        $captions[$image_id] = $image_data->post_excerpt;
    }
    $slider_show_id = 'simpleslider_show_' . get_the_ID();
    $slider_show_number = get_the_ID();
    $resp .= "<div class=\"simpleslider_show\" id=\"{$slider_show_id}\" style=\"height: {$thumb_h}px; width: {$thumb_w}px;\">\n";
    $first = true;
    foreach ($images as $image_id => $image_data) {
        $opacity = $first ? '1' : '0';
        $first = false;
        $image_prop = wp_get_attachment_image_src($image_id, $size);
        $image_tag = "<img src=\"{$image_prop[0]}\" width=\"{$image_prop[1]}\" height=\"{$image_prop[2]}\" alt=\"{$captions[$image_id]}\">";
        $resp .= "<div style=\"opacity: {$opacity}\">";
        if (1 == $link_click) {
            $link = 'direct' == $link_target ? wp_get_attachment_url($image_id) : get_attachment_link($image_id);
            $resp .= '<a href="' . $link . '" class="simpleslider_image_link simpleslider_link" target="_new">' . $image_tag . '</a>';
        } else {
            $resp .= $image_tag;
        }
        $resp .= "</div>\n";
    }
    $resp .= "</div>\n";
    // Controls
    if (true == $show_controls) {
        $resp .= "\n" . '<div class="simpleslider_controls">';
        $resp .= "<a href=\"#\" id=\"{$slider_show_id}_prev\" title=\"Previous Image\" class=\"simpleslider_link prev\">◄ " . __('Prev.', 'simple_slideshow') . "</a> ";
        if (true == $show_counter) {
            $resp .= '&nbsp; <div class="simpleslider_counter"><span id="' . $slider_show_id . '_count">1</span>/' . count($images) . '</div>';
        }
        $resp .= "&nbsp; <a href=\"#\" id=\"{$slider_show_id}_next\" title=\"Next Image\" class=\"simpleslider_link next\">" . __('Next', 'simple_slideshow') . " ►</a>";
        $resp .= '</div>';
    } elseif (true == $show_counter) {
        $resp .= "\n" . '<div class="simpleslider_counter"><span id="' . $slider_show_id . '_count">1</span>/' . count($images) . '</div>';
    }
    // JavaScript
    $prefs = array('slides' => count($images), 'transition_speed' => $transition_speed);
    if ('all' == $stored_cycle_version) {
        $prefs['fx'] = $transition;
    }
    if (1 == $auto_advance) {
        $prefs['auto_advance_speed'] = $auto_advance_speed;
    }
    $resp .= "\n" . '<script type="text/javascript">simpleslider_prefs[' . $slider_show_number . '] = ' . json_encode($prefs) . '</script>';
    return $resp;
}
function sss_settings_show_controls()
{
    $opts = get_option('sss_settings');
    $curr = sss_settings_defaults('show_controls');
    if ($opts and isset($opts['show_controls'])) {
        $curr = $opts['show_controls'];
    }
    echo '<select id="sss_show_controls" name="sss_settings[show_controls]">', '<option ';
    if (!$curr) {
        echo 'selected ';
    }
    echo 'value="0">No</option><option ';
    if ($curr) {
        echo 'selected ';
    }
    echo 'value="1">Yes</option></select>';
}