From a9d7f4f27d60bc9c770758dc6333d72930c748f1 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Tue, 20 Sep 2011 00:18:52 -0400 Subject: [PATCH] refactored/cleaned up admin_pages.php/html also styled admin_links --- admin_pages.html | 89 ++++++++++++++++++++---------------- admin_pages.php | 134 ++++++++++++++++++++++++------------------------------ code/cms.php | 2 +- code/wfpl | 2 +- style.less | 53 +++++++++++---------- 5 files changed, 140 insertions(+), 140 deletions(-) diff --git a/admin_pages.html b/admin_pages.html index 56e244b..2181eef 100644 --- a/admin_pages.html +++ b/admin_pages.html @@ -2,8 +2,8 @@ - <!--~$title show {~-->~this_host~ Admin: <!--~listings {~-->Pages Listing<!--~}~--><!--~form {~--><!--~new_msg {~-->Add a new page<!--~}~--><!--~edit_msg {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--> + <!--~$title show {~-->~this_host~ Admin: <!--~listings {~-->Pages Listing<!--~}~--><!--~form {~--><!--~id {~-->Add a new page<!--~}~--><!--~id unset {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--> @@ -39,65 +39,74 @@ -
+

Add a new pageEdit page "~title html~"

+
-
Title
-
(This appears at the top of the page, in the window title-bar (by the close button) and as the headline/link of search engine results.)
-
+
Title
+
(This appears at the top of the page, in the window title-bar (by the close button) and as the headline/link of search engine results.)
+
-
Filename
-
(Careful: if you change this, be sure to update all links to this pagePlease use only a-z, 0-9 and _ (underscore) in your filename. Please, no capitals, punctuation or spaces.)
-
+
Filename
+
(Careful: if you change this, be sure to update all links to this pagePlease use only a-z, 0-9 and _ (underscore) in your filename. Please, no capitals, punctuation or spaces.)
+
-
Show in navigation links
-
(On the left of every page.)
-
+
Show in navigation links
+
(On the left of every page.)
+
-
Navigation Link Text
-
(If you'd like this page to appear in the navigation with a shorter title.)
-
+
Navigation Link Text
+
(If you'd like this page to appear in the navigation with a shorter title.)
+
-
Content
-
-
    -
  • If you don't see an editor below (with buttons in it) then please try this page in Mozilla FireFox or Google Chrome.
  • -
  • If you're pasting from Microsoft Word, please use the "paste from word" button (4 right of the scissors).
  • -
  • In the link dialog, you can make a link to another page on this site by entering that page's "filename" in the URL field.
  • -
-
+
Content
+
+
    +
  • If you don't see an editor below (with buttons in it) then please try this page in Mozilla FireFox or Google Chrome.
  • +
  • If you're pasting from Microsoft Word, please use the "paste from word" button (4 right of the scissors).
  • +
  • In the link dialog, you can make a link to another page on this site by entering that page's "filename" in the URL field.
  • +
+
+
-
Description
-
(Hidden description of this page, primarily for search engines.)
-
+
Description
+
(Hidden description of this page, primarily for search engines.)
+
-
Keywords
-
(Hidden words (up to 30) with commas between them for search engines)
-
+
Keywords
+
(Hidden words (up to 30) with commas between them for search engines)
+
-
+
 
+
+ +
 
+
Cancel
- - -

[Add a new page]

+ + + +

[Add a new page]

- + + - - - - + + + + +
TitleFilename 
TitleFilename 
~title html~~filename html~[delete this page]
~title html~(untitled)~filename html~(offline)[delete this page]
- +

No pages in database.

-

[Add a new page]

+

[Add a new page]

diff --git a/admin_pages.php b/admin_pages.php index 8ac29d1..b1e7f16 100644 --- a/admin_pages.php +++ b/admin_pages.php @@ -17,41 +17,19 @@ function format_cms_filename($str) { function admin_pages_get_fields() { $data = array(); - $data['title'] = format_oneline($_REQUEST['title']); - $data['filename'] = format_cms_filename($_REQUEST['filename']); - $data['navbar'] = format_oneline($_REQUEST['navbar'], 'navbar'); - $data['nav_title'] = format_oneline($_REQUEST['nav_title']); - $data['content'] = format_unix($_REQUEST['content']); - $data['description'] = format_unix($_REQUEST['description']); - $data['keywords'] = format_unix($_REQUEST['keywords']); + + $data['title'] = format_oneline(_REQUEST_cut('title')); + $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['content'] = format_unix(_REQUEST_cut('content')); + $data['description'] = format_unix(_REQUEST_cut('description')); + $data['keywords'] = format_unix(_REQUEST_cut('keywords')); return $data; } -# You may pass a "where clause" for the db query. -function admin_pages_display_listing($where = 'order by concat(nav_title,title)') { - $rows = db_get_assocs('cms_pages', 'id,filename,coalesce(nullif(nav_title,\'\'), title) as title', $where); - if($rows == false || count($rows) == 0) { - tem_set('listings', array('empty_listing' => true)); - return; - } - - # make sure there's something clickable - foreach($rows as &$row) { - if($row['filename'] == '') { - $row['filename'] = '-- offline --'; - } - if($row['title'] == '') { - $row['title'] = '-- untitled --'; - } - } - tem_set('listings', array( - 'populated_listing' => true, - 'rows' => $rows)); - return true; -} - function admin_pages_main() { if(!logged_in_as_admin()) { $_REQUEST['url'] = this_url(); @@ -60,57 +38,64 @@ function admin_pages_main() { tem_set('this_host', this_host()); - if(isset($_REQUEST['admin_pages_id'])) { - return admin_pages_display_main(); - } else { - return admin_pages_edit_main(); + $id = _REQUEST_cut('edit_id'); + if($id) { + return admin_pages_main_form($id); } -} -# admin-only access to view pages with no filename -function admin_pages_display_main() { - $id = format_int($_REQUEST['admin_pages_id']); - unset($_REQUEST['admin_pages_id']); - if(!$id) { - message('Error: Broken link'); - return './admin_pages'; + $id = _REQUEST_cut('admin_pages_delete_id'); + if($id) { + return admin_pages_main_delete($id); + } + + if(_REQUEST_cut('new')) { + return admin_pages_main_form(); } - cms_display_content($GLOBALS['wfpl_main_template'], 'where id=%i', $id); -} -function admin_pages_edit_main() { - $edit_id = format_int($_REQUEST['admin_pages_edit_id']); - unset($_REQUEST['admin_pages_edit_id']); - if($edit_id) { - # add hidden field for database id of row we're editing - tem_set('admin_pages_edit_id', $edit_id); - tem_set('editing', 'show'); - tem_set('edit_msg', 'show'); + if(_REQUEST_cut('list')) { + return admin_pages_main_listing(); } - $delete_id = format_int($_REQUEST['admin_pages_delete_id']); - unset($_REQUEST['admin_pages_delete_id']); - if($delete_id) { - db_delete('cms_pages', 'where id=%i', $delete_id); - message('Page deleted.'); + $id = _REQUEST_cut('id'); + if($id) { + return admin_pages_main_display($id); + } - return './admin_pages'; + if(isset($_POST['title'])) { + return admin_pages_main_form(); } - if(!$edit_id) { - if(!isset($_REQUEST['admin_pages_new']) && !isset($_REQUEST['title'])) { - admin_pages_display_listing(); - return; - } + # default action: + return admin_pages_main_listing(); +} + +# 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); +} + +function admin_pages_main_delete($id) { + db_delete('cms_pages', 'where id=%i', $id); + message('Page deleted.'); + return './admin_pages'; +} - tem_set('new_msg', 'show'); +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); +} + +function admin_pages_main_form($id = false) { + if($id) { + tem_set('id', $id); } + $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) { list($other_id, $other_title, $other_ord) = $rows[$i]; - if($other_id != $edit_id) { # don't display ourselves + if($other_id != $id) { # don't display ourselves $navbar_options[] = array($i + 1, "After \"$other_title\""); } } @@ -121,16 +106,16 @@ function admin_pages_edit_main() { # We'll save anything (no required fields) - $data['navbar'] = db_reposition('cms_pages', $edit_id, $data['navbar'], 'navbar', 'page'); + $data['navbar'] = db_reposition('cms_pages', $id, $data['navbar'], 'navbar', 'page'); if($data['navbar'] && $data['filename'] == '') { message('This page was removed from the navigation column because it does not have a filename. (Pages without filenames are visible only to admins.)'); $data['navbar'] = 0; } - if($edit_id) { - db_update_assoc('cms_pages', $data, 'where id=%i', $edit_id); - $id = $edit_id; + if($id) { + db_update_assoc('cms_pages', $data, 'where id=%i', $id); + $id = $id; message('Page updated.'); } else { db_insert_assoc('cms_pages', $data); @@ -140,22 +125,21 @@ function admin_pages_edit_main() { if($data['filename']) { return "./$data[filename]"; } else { - return "./admin_pages?admin_pages_id=$id"; + return "./admin_pages?id=$id"; } - } elseif($edit_id) { + } elseif($id) { # we've recieved an edit id, but no data. So we grab the values to be edited from the database - $data = db_get_assoc('cms_pages', ADMIN_PAGES_DB_FIELDS, 'where id=%i', $edit_id); + $data = db_get_assoc('cms_pages', ADMIN_PAGES_DB_FIELDS, 'where id=%i', $id); if($data['navbar']) { $data['navbar'] = db_count('cms_pages', 'where navbar!=0 && navbar<%i', $data['navbar']); } else { $data['navbar'] = 'ignored'; } } else { - # form not submitted, you can set default values like so: - #$data = array('title' => 'Yes'); + # form not submitted, set default values: $data = array('filename' => format_cms_filename($_REQUEST['new_filename'])); } tem_set('form', $data); - tem_set('$head', 'show'); # wysiwyg init goes in + tem_set('$head'); # wysiwyg init goes in } diff --git a/code/cms.php b/code/cms.php index c1e2589..eacff25 100644 --- a/code/cms.php +++ b/code/cms.php @@ -8,7 +8,7 @@ function cms_display($basename, &$tem) { $nav_item['filename'] = './'; } if($nav_item['title'] == '') { - $nav_item['title'] = '-- blank --'; + $nav_item['title'] = '(untitled)'; } } $tem->set('$navbar_items', $nav_items); diff --git a/code/wfpl b/code/wfpl index 7b6c6ac..66b97fc 160000 --- a/code/wfpl +++ b/code/wfpl @@ -1 +1 @@ -Subproject commit 7b6c6ac8d6c1f53b85491ee455f2402da1d149ba +Subproject commit 66b97fc1bbcae31d1f503d491cb23d01659b7b4b diff --git a/style.less b/style.less index ec55b52..52e4c8b 100644 --- a/style.less +++ b/style.less @@ -79,6 +79,13 @@ footer { height: 1px; } } + +#admin_links { + background: #fdd; + padding: 3px; + margin-bottom: 15px; +} + .caption { margin-top: 15px; font-weight: bold; @@ -107,29 +114,7 @@ div.error { background: #fdd; } -/* hack so that vertical margins are only between siblings for the most part */ -td > :first-child, -th > :first-child, -legend + *, -article > :first-child, -section > :first-child, -nav > :first-child, -div > :first-child, -.first { - margin-top: 0px; -} -td > :last-child, -th > :last-child, -fieldset > :last-child, -article > :last-child, -section > :last-child, -nav > :last-child, -div > :last-child, -.last { - margin-bottom: 0px; -} - -/************ FLOATING IMAGES (from CMS) **************/ +// floating images (from pastable example code on admin_images) span.wfpl_ifl { display: block; float: left; @@ -155,3 +140,25 @@ div.wfpl_ic { background-repeat: no-repeat; background-position: center top; } + +// hack so that vertical margins are only between siblings for the most part +td > :first-child, +th > :first-child, +legend + *, +article > :first-child, +section > :first-child, +nav > :first-child, +div > :first-child, +.first { + margin-top: 0px; +} +td > :last-child, +th > :last-child, +fieldset > :last-child, +article > :last-child, +section > :last-child, +nav > :last-child, +div > :last-child, +.last { + margin-bottom: 0px; +} -- 1.7.10.4