<html lang="en">
<head>
- <title><!--~$title show {~-->~this_host~ Admin: <!--~listings {~-->Pages Listing<!--~}~--><!--~form {~--><!--~new_msg {~-->Add a new page<!--~}~--><!--~edit_msg {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--></title>
<meta charset="utf-8" />
+ <title><!--~$title show {~-->~this_host~ Admin: <!--~listings {~-->Pages Listing<!--~}~--><!--~form {~--><!--~id {~-->Add a new page<!--~}~--><!--~id unset {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--></title>
<!--~$head {~-->
<script type="text/javascript" src="code/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
['Styles', 'Format', 'Font', 'FontSize'],
['TextColor', 'BGColor'],
['Maximize', 'ShowBlocks']
- ]
+ ]
});
}
</script>
<!--~$body show {~-->
<!--~form {~-->
- <form action="admin_pages" method="post"><!--~editing {~--><div style="display: none"><input type="hidden" name="and_then" value="~and_then attr~" /><input type="hidden" name="admin_pages_edit_id" value="~admin_pages_edit_id attr~" /></div><!--~}~-->
+ <h2><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--></h2>
+ <form action="admin_pages" method="post"><!--~id {~--><div style="display: none"><input type="hidden" name="edit_id" value="~id attr~"></div><!--~}~-->
- <div class="caption">Title</div>
- <div class="field_notes">(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.)</div>
- <div class="field"><input type="text" name="title" value="~title attr~" /></div>
+ <div class="caption">Title</div>
+ <div class="field_notes">(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.)</div>
+ <div class="field"><input type="text" name="title" value="~title attr~"></div>
- <div class="caption">Filename</div>
- <div class="field_notes">(<!--~editing {~-->Careful: if you change this, be sure to update all links to this page<!--~}~--><!--~editing unset {~-->Please use only a-z, 0-9 and _ (underscore) in your filename. Please, no capitals, punctuation or spaces.<!--~}~-->)</div>
- <div class="field"><input type="text" name="filename" value="~filename attr~" /></div>
+ <div class="caption">Filename</div>
+ <div class="field_notes">(<!--~editing {~-->Careful: if you change this, be sure to update all links to this page<!--~}~--><!--~editing unset {~-->Please use only a-z, 0-9 and _ (underscore) in your filename. Please, no capitals, punctuation or spaces.<!--~}~-->)</div>
+ <div class="field"><input type="text" name="filename" value="~filename attr~"></div>
- <div class="caption">Show in navigation links</div>
- <div class="field_notes">(On the left of every page.)</div>
- <div class="field"><select name="navbar"><!--~navbar options~--></select></div>
+ <div class="caption">Show in navigation links</div>
+ <div class="field_notes">(On the left of every page.)</div>
+ <div class="field"><select name="navbar"><!--~navbar options~--></select></div>
- <div class="caption">Navigation Link Text</div>
- <div class="field_notes">(If you'd like this page to appear in the navigation with a shorter title.)</div>
- <div class="field"><input type="text" name="nav_title" value="~nav_title attr~" /></div>
+ <div class="caption">Navigation Link Text</div>
+ <div class="field_notes">(If you'd like this page to appear in the navigation with a shorter title.)</div>
+ <div class="field"><input type="text" name="nav_title" value="~nav_title attr~"></div>
- <div class="caption">Content</div>
- <div class="field_notes">
- <ul>
- <li>If you don't see an editor below (with buttons in it) then please try this page in <a href="http://getfirefox.com">Mozilla FireFox</a> or <a href="http://www.google.com/chrome/">Google Chrome</a>.</li>
- <li>If you're pasting from Microsoft Word, please use the "paste from word" button (4 right of the scissors).</li>
- <li>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.</li>
- </ul></div>
- <div class="field"><textarea class="html_editor" rows="20" cols="50" id="content" name="content">~content html~</textarea><script type="text/javascript">make_wysiwyg('content');</script></div>
+ <div class="caption">Content</div>
+ <div class="field_notes">
+ <ul>
+ <li>If you don't see an editor below (with buttons in it) then please try this page in <a href="http://getfirefox.com">Mozilla FireFox</a> or <a href="http://www.google.com/chrome/">Google Chrome</a>.</li>
+ <li>If you're pasting from Microsoft Word, please use the "paste from word" button (4 right of the scissors).</li>
+ <li>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.</li>
+ </ul>
+ </div>
+ <div class="field"><textarea class="html_editor" rows="20" cols="50" id="content" name="content">~content html~</textarea><script type="text/javascript">make_wysiwyg('content');</script></div>
- <div class="caption">Description</div>
- <div class="field_notes">(Hidden description of this page, primarily for search engines.)</div>
- <div class="field"><textarea rows="9" cols="22" name="description">~description html~</textarea></div>
+ <div class="caption">Description</div>
+ <div class="field_notes">(Hidden description of this page, primarily for search engines.)</div>
+ <div class="field"><textarea rows="9" cols="22" name="description">~description html~</textarea></div>
- <div class="caption">Keywords</div>
- <div class="field_notes">(Hidden words (up to 30) with commas between them for search engines)</div>
- <div class="field"><textarea rows="9" cols="22" name="keywords">~keywords html~</textarea></div>
+ <div class="caption">Keywords</div>
+ <div class="field_notes">(Hidden words (up to 30) with commas between them for search engines)</div>
+ <div class="field"><textarea rows="9" cols="22" name="keywords">~keywords html~</textarea></div>
- <div class="field"><input type="submit" name="save" value="Save" /></div>
+ <div class="caption"> </div>
+ <div class="field"><input type="submit" name="save" value="Save"></div>
</form>
+
+ <div class="caption"> </div>
+ <div class="field"><a href="~filename nonempty {~~filename attr~~}~~filename empty {~admin_pages~id {~?id=~id~~}~~}~">Cancel</a></div>
<!--~}~-->
- <!--~listings {~-->
- <!--~populated_listing {~-->
- <p><a href="admin_pages?admin_pages_new=1">[Add a new page]</a></p>
+
+ <!--~listings once {~-->
+ <!--~listings once_if {~-->
+ <p><a href="admin_pages?new=1">[Add a new page]</a></p>
<table cellspacing="0" cellpadding="4" border="1" summary="">
- <th>Title</th><th>Filename</th><th> </th><!--~rows {~-->
+ <tr><th>Title</th><th>Filename</th><th> </th></tr>
+ <!--~listings {~-->
<tr>
- <td class="listing"><a href="admin_pages?admin_pages_edit_id=~id~">~title html~</a></td>
- <td class="listing"><a href="admin_pages?admin_pages_edit_id=~id~">~filename html~</a></td>
- <td><a href="admin_pages?admin_pages_delete_id=~id~" onclick="return confirm('Permanently delete?')">[delete this page]</a></td>
- </tr><!--~}~-->
+ <td class="listing"><a href="admin_pages?edit_id=~id~">~title html~<!--~title empty {~--><em>(untitled)</em><!--~}~--></a></td>
+ <td class="listing"><a href="admin_pages?edit_id=~id~">~filename html~<!--~filename empty {~--><em>(offline)</em><!--~}~--></a></td>
+ <td><a href="admin_pages?admin_pages_delete_id=~id~" onclick="return confirm('Permanently delete?')">[delete this page]</a></td>
+ </tr>
+ <!--~}~-->
</table>
<!--~}~-->
- <!--~empty_listing {~-->
+ <!--~listings once_else {~-->
<p>No pages in database.</p>
<!--~}~-->
- <p><a href="admin_pages?admin_pages_new=1">[Add a new page]</a></p>
+ <p><a href="admin_pages?new=1">[Add a new page]</a></p>
<!--~}~-->
<!--~}~-->
</body>
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();
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\"");
}
}
# 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);
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 <head>
+ tem_set('$head'); # wysiwyg init goes in <head>
}