X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=admin_images.php;h=2a5ae51511500ea1f05b8099b48d6c4111c999b2;hb=3fe5000888dd47ae4de76a1f6678b2e21cacc1bc;hp=8b6e5132e534ec66d018db16ac1baf5e60f759ac;hpb=c469d2530ad9684e56742d38f5817cb08ad98eef;p=wfpl-cms.git diff --git a/admin_images.php b/admin_images.php index 8b6e513..2a5ae51 100644 --- a/admin_images.php +++ b/admin_images.php @@ -1,37 +1,11 @@ $references, @@ -123,68 +100,22 @@ 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; - } - 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; - } - - $smaller[] = array( - 'src' => $src, - 'max_width' => $max_width, - 'max_height' => $max_height, - 'width' => $width, - 'height' => $height); - } - } - if($smaller) { - $data['smaller'] = $smaller; - } else { - tem_set('no_sizes'); - } - tem_set('display', $data); } function admin_images_main_delete($id) { $data = db_get_assoc('cms_images', 'image,sizes', 'where id=%i', $id); if ($data) { - $filenames = array(); - $space = strpos($data['image'], ' '); - $dot = strpos($data['image'], '.'); - if ($space !== false && $dot !== false && $dot < $space) { - $base = substr($data['image'], 0, $dot); - $ext = substr($data['image'], $dot, $space - $dot); - $filenames[] = "$base$ext"; - $filenames[] = "{$base}_thumb$ext"; - $sizes = explode("\n", $data['sizes']); - foreach ($sizes as $max_hw) { - $max_hw = format_width_height($max_hw); - if($max_hw == '') { - continue; - } - list($max_width, $max_height) = explode('x', $max_hw); - $filenames[] = "$base-{$max_width}x$max_height$ext"; # old naming scheme - $filenames[] = "$base-{$max_width}-$max_height$ext"; # new namich scheme + $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); } - } - foreach ($filenames as $filename) { - if (file_exists($filename)) { - unlink($filename); + foreach ($filenames as $filename) { + if (file_exists($filename)) { + unlink($filename); + } } } db_delete('cms_images', 'where id=%i', $id); @@ -196,7 +127,22 @@ function admin_images_main_delete($id) { } function admin_images_main_listing() { - $listing_rows = db_get_assocs('cms_images', 'id,image,name,caption', 'order by name, caption'); + $sort_by = 'name'; + $sorts = array( + 'age' => 'created_at desc', + 'name' => "coalesce(nullif(name, ''), caption), created_at", + 'caption' => "coalesce(nullif(caption, ''), name), created_at" + ); + if (isset($_REQUEST['sort'])) { + foreach ($sorts as $s => $sql) { + if ($_REQUEST['sort'] == $s) { + $sort_by = $s; + break; + } + } + } + tem_set("sort_by_$sort_by"); + $listing_rows = db_get_assocs('cms_images', 'id,image,name,caption', 'order by ' . $sorts[$sort_by]); tem_set('listings', $listing_rows); } @@ -211,23 +157,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);