X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=admin_images.php;h=73d16c64c0d21e5af5d8dcb1fa96e13fe993daa0;hb=e7424acd48ed670f1b8bd8d7c1ff69b37ce6334b;hp=90a99c00399ccbc37ab81f626a4cc3363e477e22;hpb=426a14728194dbd7de892bf2cfd2093b89106b6a;p=wfpl-cms.git diff --git a/admin_images.php b/admin_images.php index 90a99c0..73d16c6 100644 --- a/admin_images.php +++ b/admin_images.php @@ -1,38 +1,11 @@ $references, @@ -124,46 +100,29 @@ function admin_images_main_display($id) { } } - # display smaller versions with instructions and example code - $smaller == array(); - if($data['image'] && $data['sizes']) { - $big_src = enc_image_src($data['image']); - $row = explode("\n", $data['sizes']); - foreach($row as $max_hw) { - $max_hw = format_width_height($max_hw); - if($max_hw == '') { - continue; + tem_set('display', $data); +} + +function admin_images_main_delete($id) { + $data = db_get_assoc('cms_images', 'image,sizes', 'where id=%i', $id); + if ($data) { + $src = enc_image_src($data['image']); + if ($src) { + $filenames = array($src); + foreach ($GLOBALS['wfpl_image_widths'] as $w) { + $filenames [] = substr($src, 0, -4) . 'w' . $w . substr($src, -4); } - list($max_width, $max_height) = explode('x', $max_hw); - $src = str_replace('.', "-$max_width-$max_height.", $big_src); - $dimensions = image_dimensions($src); - if($dimensions) { - list($width, $height) = explode('x', $dimensions); - } else { - $width = $max_width; - $height = $max_height; + foreach ($filenames as $filename) { + if (file_exists($filename)) { + unlink($filename); + } } - - $smaller[] = array( - 'src' => $src, - 'max_width' => $max_width, - 'max_height' => $max_height, - 'width' => $width, - 'height' => $height); } - } - if($smaller) { - $data['smaller'] = $smaller; + db_delete('cms_images', 'where id=%i', $id); + message('Image deleted.'); } else { - tem_set('no_sizes'); + message("Couldn't find image to delete. Maybe it's already been deleted?"); } - - tem_set('display', $data); -} - -function admin_images_main_delete($id) { - db_delete('cms_images', 'where id=%i', $id); - message('Image deleted.'); return './admin_images'; } @@ -183,23 +142,6 @@ function admin_images_main_form($id = false) { # save anything # Note: If you change this to re-display the form in some cases, be sure to handle image uploads well (don't make them upload it again.) - # resize image as needed - if($data['image'] && $data['sizes']) { - $big_src = enc_image_src($data['image']); - $row = explode("\n", $data['sizes']); - foreach($row as $max_hw) { - $max_hw = format_width_height($max_hw); - if($max_hw == '') { - continue; - } - list($max_width, $max_height) = explode('x', $max_hw); - $src = str_replace('.', "-$max_width-$max_height.", $big_src); - if(($_FILES['image'] && $_FILES['image']['error'] == 0) || !file_exists($src)) { - imagemagick_convert($big_src, $src, "-geometry $max_hw", 'Resizing image'); - } - } - } - # save to database if($id) { db_update_assoc('cms_images', $data, 'where id=%i', $id); @@ -207,12 +149,12 @@ function admin_images_main_form($id = false) { $saved_id = $id; } else { db_insert_assoc('cms_images', $data); - message('Image saved.'); + message('Image saved. Next time you open a page editor, this image will be availble in the "Insert Image" dialog.'); $saved_id = db_auto_id(); } # return user to display page where they can see instructions, etc - return "./admin_images?id=$saved_id"; + return "./admin_images"; } elseif($id) { # we've recieved an edit id, but no data. So we grab the values to be edited from the database