X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl-cms.git;a=blobdiff_plain;f=admin_pages.php;h=584aaa0798059210e6dd55c9a2ae9bba4c606b0b;hp=1a9b2cb9c735549a79fff8dbc393d8acc69d2cad;hb=3ed0f0b53ff1b3ea3e30292bf39eb6e30935e9eb;hpb=e34941f998d7d59c3f7713498caf1e21657fa764 diff --git a/admin_pages.php b/admin_pages.php index 1a9b2cb..584aaa0 100644 --- a/admin_pages.php +++ b/admin_pages.php @@ -5,9 +5,6 @@ define('ADMIN_PAGES_DB_FIELDS', 'title,filename,navbar,nav_title,content,description,keywords'); -require_once(DOCROOT . 'inc/wfpl/format.php'); -require_once(DOCROOT . 'inc/wfpl/email.php'); - function format_cms_filename($str) { $str = format_filename($str); $str = str_replace('.', '_', $str); @@ -75,22 +72,43 @@ function admin_pages_main_delete($id) { return './admin_pages'; } +# get all images from admin_images (for cms) function admin_pages_get_images() { - $images = db_get_assocs('cms_images', 'image,name,caption,sizes', 'order by name, caption, image'); - if ($images) { - $id = 0; - foreach($images as &$image) { - $image['id'] = '' . $id; - $id += 1; - } - return $images; + $out = []; + $rows = db_get_assocs('cms_images', 'image,name,caption', "order by coalesce(nullif(name, ''), caption), created_at"); + if ($rows) { + $id = -1; + foreach($rows as &$row) { $id += 1; + $parts = explode(' ', $row['image'] . ' ', 7); + $out[] = [ + 'id' => '' . $id, + 'src' => $parts[0], + 'aspect' => ''.(round(100000 * ((int)$parts[2]) / ((int)$parts[1]) / 1000)).'%', + 'name' => $row['name'], + 'caption' => $row['caption'] + ]; + } unset($row); } - return null; + return $out; } function admin_pages_main_listing() { - $listing_rows = db_get_assocs('cms_pages', 'id,filename,coalesce(nullif(nav_title,\'\'), title) as title', 'order by concat(nav_title,title)'); - tem_set('listings', $listing_rows); + $data = array(); + $desc = ''; + $sort = _REQUEST_cut('sort'); + if ($sort && substr($sort, 0, 1) === '-') { + $sort = substr($sort, 1); + $desc = ' DESC '; + } else { + $data["sorting-by-$sort"] = '-'; + } + $legal_sorts = explode(',', ADMIN_PAGES_DB_FIELDS); + if (!$sort || !in_array($sort, $legal_sorts)) { + $sort = 'filename'; + } + + $data['rows'] = db_get_assocs('cms_pages', 'id,coalesce(nullif(nav_title,\'\'), title) as title,filename', "order by $sort $desc limit 1000"); + tem_set('listing', $data); } function admin_pages_main_form($id = false) { @@ -149,7 +167,10 @@ function admin_pages_main_form($id = false) { $data = array('filename' => format_cms_filename($_REQUEST['new_filename'])); } - tem_set('wfpl_images', admin_pages_get_images()); + tem_set('wfpl_images_json', json_encode(admin_pages_get_images())); + tem_set('wfpl_image_width_full', WFPL_IMAGE_WIDTH_FULL); + tem_set('wfpl_image_width_small', WFPL_IMAGE_WIDTH_SMALL); + tem_set('wfpl_image_width_thumb', WFPL_IMAGE_WIDTH_THUMB); tem_set('form', $data); tem_set('$head'); # wysiwyg init goes in }