JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
little space below menu
[wfpl-cms.git] / admin_pages.php
index 9c7f56a..7981bf6 100644 (file)
@@ -2,7 +2,7 @@
 
 # This form requires wfpl. See: http://sametwice.com/wfpl
 
-define('ADMIN_PAGES_DB_FIELDS', 'title,filename,navbar,nav_title,content,description,keywords');
+define('ADMIN_PAGES_DB_FIELDS', 'title,filename,navbar,nav_title,layout,content,sidebar_content,description,keywords');
 
 
 function format_cms_filename($str) {
@@ -19,9 +19,17 @@ function admin_pages_get_fields() {
        $data['filename'] = format_cms_filename(_REQUEST_cut('filename'));
        $data['navbar'] = format_options(_REQUEST_cut('navbar'), 'navbar');
        $data['nav_title'] = format_oneline(_REQUEST_cut('nav_title'));
+       $data['layout'] = format_options(_REQUEST_cut('layout'), 'layout');
        $data['content'] = format_unix(_REQUEST_cut('content'));
-       $data['description'] = format_unix(_REQUEST_cut('description'));
-       $data['keywords'] = format_unix(_REQUEST_cut('keywords'));
+       if (isset($_REQUEST['sidebar_content'])) { // probs not needed
+               $data['sidebar_content'] = format_unix(_REQUEST_cut('sidebar_content'));
+       }
+       if (isset($_REQUEST['description'])) {
+               $data['description'] = format_unix(_REQUEST_cut('description'));
+       }
+       if (isset($_REQUEST['keywords'])) {
+               $data['keywords'] = format_unix(_REQUEST_cut('keywords'));
+       }
 
        return $data;
 }
@@ -64,6 +72,7 @@ function admin_pages_main() {
 # admin-only access to view pages with no filename
 function admin_pages_main_display($id) {
        cms_display_content($GLOBALS['wfpl_main_template'], 'where id=%i', $id);
+       $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_id'] = $id;
 }
 
 function admin_pages_main_delete($id) {
@@ -75,22 +84,18 @@ function admin_pages_main_delete($id) {
 # get all images from admin_images (for cms)
 function admin_pages_get_images() {
        $out = [];
-       $rows = db_get_assocs('cms_images', 'image,name,caption,sizes', 'order by name, caption, image');
+       $rows = db_get_assocs('cms_images', 'image,name,caption', "order by coalesce(nullif(name, ''), caption), created_at");
        if ($rows) {
-               $id = 0;
-               foreach($rows as &$row) {
+               $id = -1;
+               foreach($rows as &$row) { $id += 1;
                        $parts = explode(' ', $row['image'] . '      ', 7);
                        $out[] = [
                                'id' => '' . $id,
-                               'thumb' => $parts[3],
-                               'image' => $parts[0],
-                               'image_width' => (int)$parts[1],
-                               'image_height' => (int)$parts[2],
-                               'sizes' => $row['sizes'],
+                               'src' => $parts[0],
+                               'aspect' => ''.(round(100000 * ((int)$parts[2]) / ((int)$parts[1]) / 1000)).'%',
                                'name' => $row['name'],
                                'caption' => $row['caption']
                        ];
-                       $id += 1;
                } unset($row);
        }
        return $out;
@@ -122,6 +127,12 @@ function admin_pages_main_form($id = false) {
 
        tem_set('$basename', 'admin_pages');
 
+       pulldown('layout', [
+               ['0', "Full (no sidebar)"],
+               ['1', "With Plain Sidebar"],
+               ['2', "With Bordered Sidebar"]
+       ]);
+
        $navbar_options = array(array('ignored', 'Not at all'), array('0', 'First'));
        $rows = db_get_rows('cms_pages', 'id,coalesce(nullif(nav_title,\'\'), title) as title,navbar', 'where navbar != 0 order by navbar');
        if($rows) for($i = 0; $i < count($rows); ++$i) {
@@ -171,7 +182,16 @@ function admin_pages_main_form($id = false) {
                $data = array('filename' => format_cms_filename($_REQUEST['new_filename']));
        }
 
+       if (!isset($data['layout']) || $data['layout'] === '' || $data['layout'] === '0') {
+               $data['sidebar_editor_display'] = 'none';
+       } else {
+               $data['sidebar_editor_display'] = 'block';
+       }
+
        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 <head>
 }