'aioslideshow', 'description' => __('All-In-One Slideshow widget', 'aioslideshow') );
/* Create the widget. */
$this->WP_Widget( 'aioslideshow-widget', __('All-In-One Slideshow widget', 'aioslideshow'), $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'] );
/* 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;
aio_slideshow();
/* 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'] );
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* when creating your form elements. This handles the confusing stuff.
*/
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => __('All-In-One Slideshow', 'aioslideshow'));
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
'',
'on_pages' => '',
'on_archive' => 1,
'rotate' => 1,
'effect' => 'fade',
'easing' => 'none',
'delay' => 3,
'duration' => 1,
'img_width' => 500,
'img_height' => 300,
'div' => 'aio-slideshow',
'fontFamily' => 'geo-sans-ligh.font.js',
'arrnav' => 'allthetime',
'numnav_position' => 'dont_display',
'text_position' => 'bottom_left',
'textbg_margin' => 5,
'text_align' => 'left',
'text_size' => 40,
'textColorsCSS' => 0,
'text_shadow_enabled' => 1,
'text_bg' => '000',
'text_color1' => 'FFF',
'text_color2' => 'C0C0C0',
'text_shadow' => '000',
'your_css' => ''
));
// pull the settings from the db
$aio_slideshow_settings = get_option('aio_slideshow_settings');
$aio_slideshow_images = get_option('aio_slideshow_images');
// fallback
$aio_slideshow_settings = wp_parse_args($aio_slideshow_settings, $aio_slideshow_defaults);
/*
///////////////////////////////////////////////
This section hooks the proper functions
to the proper actions in WordPress
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
// this function registers our settings in the db
add_action('admin_init', 'aio_slideshow_register_settings');
function aio_slideshow_register_settings() {
register_setting('aio_slideshow_images', 'aio_slideshow_images', 'aio_slideshow_images_validate');
register_setting('aio_slideshow_settings', 'aio_slideshow_settings', 'aio_slideshow_settings_validate');
}
add_action('admin_print_scripts', 'aio_slideshow_colorpicker');
function aio_slideshow_colorpicker() {?>
%s', admin_url( 'options-general.php?page=aio-slideshow' ), __('Settings') );
array_unshift($links, $aio_slideshow_settings_link);
return $links;
}
/*
///////////////////////////////////////////////
this function is the code that gets loaded when the
settings page gets loaded by the browser. It calls
functions that handle image uploads and image settings
changes, as well as producing the visible page output.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
function aio_slideshow_admin_page() {
echo '
';
// handle image upload, if necessary
if($_REQUEST['action'] == 'wp_handle_upload')
aio_slideshow_handle_upload();
// delete an image, if necessary
if(isset($_REQUEST['delete']))
aio_slideshow_delete_upload($_REQUEST['delete']);
// the image management form
aio_slideshow_images_admin();
// the settings management form
aio_slideshow_settings_admin();
echo '
';
}
/*
///////////////////////////////////////////////
this section handles uploading images, adding
the image data to the database, deleting images,
and deleting image data from the database.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
// this function handles the file upload,
// resize/crop, and adds the image data to the db
function aio_slideshow_handle_upload() {
global $aio_slideshow_settings, $aio_slideshow_images;
// upload the image
$upload = wp_handle_upload($_FILES['aio_slideshow'], 0);
// extract the $upload array
extract($upload);
// the URL of the directory the file was loaded in
$upload_dir_url = str_replace(basename($file), '', $url);
// get the image dimensions
list($width, $height) = getimagesize($file);
// if the uploaded file is NOT an image
if(strpos($type, 'image') === FALSE) {
unlink($file); // delete the file
echo '
Sorry, but the file you uploaded does not seem to be a valid image. Please try again.
';
return;
}
// if the image doesn't meet the minimum width/height requirements ...
if($width < $aio_slideshow_settings['img_width'] || $height < $aio_slideshow_settings['img_height']) {
unlink($file); // delete the image
echo '
Sorry, but this image does not meet the minimum height/width requirements. Please upload another image
';
return;
}*/
// if the image is larger than the width/height requirements, then scale it down.
if($width > $aio_slideshow_settings['img_width'] || $height > $aio_slideshow_settings['img_height']) {
// resize the image
$resized = image_resize($file, $aio_slideshow_settings['img_width'], $aio_slideshow_settings['img_height'], true, 'resized');
$resized_url = $upload_dir_url . basename($resized);
// delete the original
unlink($file);
$file = $resized;
$url = $resized_url;
}
// make the thumbnail
$thumb_height = round((100 * $aio_slideshow_settings['img_height']) / $aio_slideshow_settings['img_width']);
if(isset($upload['file'])) {
$thumbnail = image_resize($file, 100, $thumb_height, true, 'thumb');
$thumbnail_url = $upload_dir_url . basename($thumbnail);
}
// use the timestamp as the array key and id
$time = date('YmdHis');
// add the image data to the array
$aio_slideshow_images[$time] = array(
'id' => $time,
'file' => $file,
'file_url' => $url,
'thumbnail' => $thumbnail,
'thumbnail_url' => $thumbnail_url,
'image_links_to' => ''
);
// add the image information to the database
$aio_slideshow_images['update'] = 'Added';
update_option('aio_slideshow_images', $aio_slideshow_images);
}
// this function deletes the image,
// and removes the image data from the db
function aio_slideshow_delete_upload($id) {
global $aio_slideshow_images;
// if the ID passed to this function is invalid,
// halt the process, and don't try to delete.
if(!isset($aio_slideshow_images[$id])) return;
// delete the image and thumbnail
unlink($aio_slideshow_images[$id]['file']);
unlink($aio_slideshow_images[$id]['thumbnail']);
// indicate that the image was deleted
$aio_slideshow_images['update'] = 'Deleted';
// remove the image data from the db
unset($aio_slideshow_images[$id]);
update_option('aio_slideshow_images', $aio_slideshow_images);
}
/*
///////////////////////////////////////////////
these two functions check to see if an update
to the data just occurred. if it did, then they
will display a notice, and reset the update option.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
// this function checks to see if we just updated the settings
// if so, it displays the "updated" message.
function aio_slideshow_settings_update_check() {
global $aio_slideshow_settings;
if(isset($aio_slideshow_settings['update'])) {
echo '
';
unset($aio_slideshow_settings['update']);
update_option('aio_slideshow_settings', $aio_slideshow_settings);
}
}
// this function checks to see if we just added a new image
// if so, it displays the "updated" message.
function aio_slideshow_images_update_check() {
global $aio_slideshow_images;
if($aio_slideshow_images['update'] == 'Added' || $aio_slideshow_images['update'] == 'Deleted' || $aio_slideshow_images['update'] == 'Updated') {
echo '
';
unset($aio_slideshow_images['update']);
update_option('aio_slideshow_images', $aio_slideshow_images);
}
}
/*
///////////////////////////////////////////////
these two functions display the front-end code
on the admin page. it's mostly form markup.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
// display the images administration code
function aio_slideshow_images_admin() { ?>
Please, click and read before you start uploading images.
1. The first you have to set dimensions of the images [General / Image Dimensions].
2. Dimensions of the uploaded image should NOT be smaller than the dimensions you set below.
3. Check if you have correct file permissions set for your uploads directory (CHMOD).
4. Upload folder should be "wp-content/uploads" (check in Settings / Media / Store uploads in this folder). It should never start with a slash "/".
5. If you are still having a problem, let me know in the forum on my site please.
Upload New Image
Image
Image Links To
Title
Actions
Image
Image Links To
Title
Actions
$value) {
if($key != 'update') {
$input[$key]['file_url'] = clean_url($value['file_url']);
$input[$key]['thumbnail_url'] = clean_url($value['thumbnail_url']);
if($value['image_links_to'])
$input[$key]['image_links_to'] = clean_url($value['image_links_to']);
if($value['title'])
$input[$key]['title'] = ($value['title']);
}
}
return $input;
}
/*
///////////////////////////////////////////////
this final section generates all the code that
is displayed on the front-end of the WP Theme
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
*/
function aio_slideshow($args = array(), $content = null) {
global $aio_slideshow_settings, $aio_slideshow_images, $value;
// possible future use
$args = wp_parse_args($args, $aio_slideshow_settings);
$newline = "\n"; // line break
echo '
'.$newline;
echo '
'.$newline;
foreach((array)$aio_slideshow_images as $image => $data) {
echo '