AB BG Slideshow', 'upload_files', 'ab-bg-slideshow', 'ab_show_admin_page');
}
// add "Settings" link to plugin page
add_filter('plugin_action_links_' . plugin_basename(__FILE__) , 'ab_show_plugin_action_links');
function ab_show_plugin_action_links($links) {
$wp_cycle_settings_link = sprintf( '%s', admin_url( 'options-general.php?page=ab-bg-slideshow' ), __('Settings') );
array_unshift($links, $wp_cycle_settings_link);
return $links;
}
function ab_show_admin_page() {
echo '
';
// handle image upload, if necessary
if($_REQUEST['action'] == 'wp_handle_upload')
ab_bg_handle_upload();
// delete an image, if necessary
if(isset($_REQUEST['delete']))
ab_bg_delete_upload($_REQUEST['delete']);
// the image management form
ab_bg_images_admin();
// the settings management form - abooze
echo '
';
}
function ab_bg_handle_upload() {
global $wp_cycle_settings, $wp_cycle_images;
// upload the image
$upload = wp_handle_upload($_FILES['wp_cycle'], 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;
}
// make the thumbnail
$thumb_height = round((100 * $wp_cycle_settings['img_height']) / $wp_cycle_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
$wp_cycle_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
$wp_cycle_images['update'] = 'Added';
update_option('wp_cycle_images', $wp_cycle_images);
}
// this function deletes the image,
// and removes the image data from the db
function ab_bg_delete_upload($id) {
global $wp_cycle_images;
// if the ID passed to this function is invalid,
// halt the process, and don't try to delete.
if(!isset($wp_cycle_images[$id])) return;
// delete the image and thumbnail
unlink($wp_cycle_images[$id]['file']);
unlink($wp_cycle_images[$id]['thumbnail']);
// indicate that the image was deleted
$wp_cycle_images['update'] = 'Deleted';
// remove the image data from the db
unset($wp_cycle_images[$id]);
update_option('wp_cycle_images', $wp_cycle_images);
}
function ab_bg_settings_update_check() {
global $wp_cycle_settings;
if(isset($wp_cycle_settings['update'])) {
echo 'Ab-Background Slideshow Settings '.$wp_cycle_settings['update'].'
';
unset($wp_cycle_settings['update']);
update_option('wp_cycle_settings', $wp_cycle_settings);
}
}
// this function checks to see if we just added a new image
// if so, it displays the "updated" message.
function ab_bg_images_update_check() {
global $wp_cycle_images;
if($wp_cycle_images['update'] == 'Added' || $wp_cycle_images['update'] == 'Deleted' || $wp_cycle_images['update'] == 'Updated') {
echo 'Image '.$wp_cycle_images['update'].' Successfully
';
unset($wp_cycle_images['update']);
update_option('wp_cycle_images', $wp_cycle_images);
}
}
function ab_bg_images_admin() { ?>
| Image |
Actions |
| Image |
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']);
}
}
return $input;
}
function ab_bg_show($args = array(), $content = null) {
global $wp_cycle_settings, $wp_cycle_images;
// possible future use
$args = wp_parse_args($args, $wp_cycle_settings);
$newline = "\n"; // line break
echo 'images: [';
foreach((array)$wp_cycle_images as $image => $data) {
//echo $data['file_url'];
echo "'" . $data['file_url'] . "', ";
}
echo "]";
}
?>