From: Jason Woofenden Date: Mon, 7 Jun 2010 06:42:12 +0000 (-0400) Subject: generic editable site X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl-cms.git;a=commitdiff_plain;h=059569fef59006c2ab9af689c582fc3e9b0d7e6e generic editable site --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..442b74a --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.tar.gz +*.tgz +cms_images diff --git a/.gitmodules b/.gitmodules index a7b64d8..8e7aaba 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "code/wfpl"] path = code/wfpl url = git://gitorious.org/wfpl/wfpl.git +[submodule "code/ckeditor"] + path = code/ckeditor + url = git://gitorious.org/jasonwoof/ckeditor.git diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..c2a8568 --- /dev/null +++ b/.htaccess @@ -0,0 +1,15 @@ +# php_value post_max_size 205M +# php_value upload_max_filesize 200M +php_flag register_globals off +php_flag magic_quotes_gpc off +Options -MultiViews +DirectorySlash Off +AddDefaultCharset UTF-8 +RewriteEngine on +RewriteRule ^[^/.]*$ /run.php [L] +RewriteRule ^style_[0-9]*.css$ /style.css [L] + + + ExpiresActive On + ExpiresDefault A31536000 + diff --git a/.sync b/.sync new file mode 100644 index 0000000..90638d8 --- /dev/null +++ b/.sync @@ -0,0 +1,3 @@ +#!/bin/bash + +verbose git push diff --git a/admin.html b/admin.html new file mode 100644 index 0000000..2cf3368 --- /dev/null +++ b/admin.html @@ -0,0 +1,20 @@ + + + + + <!--~main_title show {~-->~this_host~ Administration<!--~}~--> + + + + + +

~this_host~ Administration

+ +

Upload/edit images

+ +

Add/edit pages

+ +

Log out

+ + + diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..8c115ce --- /dev/null +++ b/admin.php @@ -0,0 +1,11 @@ + + + + + <!--~main_title show {~-->Images<!--~}~--> + + + + + + +

Image details

+ +

Add another image

+ +

Back to images

+ +

Edit

+ +

Note: This image appears on the following page~count s~: ~title html~,

+ +

How to put one of these images on a page

+
    +
  1. Choose which size you want. If you want a size that is not shown below, edit this image and add a new display size.
  2. +
  3. Above the image (at your chosen size) you will see HTML code with a light gray background. Drag (or triple click) to select the HTML code for your desired alignment, and copy it to the clipboard.
  4. +
  5. Open the page editor in another tab (so you can refer to these instructions while you use it.)
  6. +
  7. In the page editor, type "HERE HERE HERE" where you'd like to insert the image, then click the "Source" button at the top/left of the editor.
  8. +
  9. Now you will see the HTML code for the page. Find where it says "HERE HERE HERE", select those three words, then paste over them. You can paste with Ctrl-V (on Mac that's Command-V) or with the Edit menu, but the right-click paste may not work.
  10. +
  11. Click the "Source" button again to get back to the normal view. Your image should now be visible in the editor (though you may have to scroll down to see it.)
  12. +
+ + +
On the right: (with the page text to the left of it)
<span class="float_right"><img src="~src~" width="~width~" height="~height~" alt="" />~caption html~</span>
+
On the left: (with the page text to the right of it)
<span class="float_left"><img src="~src~" width="~width~" height="~height~" alt="" />~caption html~</span>
+
Centered: (with nothing to either side)
<div class="mid_pic" style="width: ~width~px"><img src="~src~" width="~width~" height="~height~" alt="" />~caption html~</div>
+
+ + +
Full Size (centered):
<div class="mid_pic"><img src="~image image_src~" width="~image image_width~" height="~image image_height~" alt="" />~caption html~</div>
+
+ + +

To display this image smaller, edit this image and enter display size(s).

+ + + + +

Back to images

+ +

Edit

+ + + +

Add a new imageEdit image "~name html~"

+ +
+
+ +
Image
+
+ +
Name (optional)
+
This name is only displayed on the image administration page.
+
+ +
Caption (optional)
+
Here's some symbols you might want to paste in: ©   —   –
+
+ +
Sizes
+
(Enter the width and height (in pixels) at which you'd like to use this image. Put an x between them with no spaces, so it looks like this: 100x200. The image will be scaled so it maintains it's aspect ratio (shape) and just fits inside those dimentions. You can use this image at multiple different sizes, by entering a different set of dimensions (WIDTHxHEIGHT) on each line)
+
+ +
 
+
+ +
+ +
 
+
Cancel
+ + + +

Images Listing

+ + +

[Add a new image]

+ + + + + + + + + + +
ImageNameCaption 
~name html~~caption html~[delete this image]
+ + +

No images in database.

+ + +

[Add a new image]

+ + + + + diff --git a/admin_images.php b/admin_images.php new file mode 100644 index 0000000..a8c8a9b --- /dev/null +++ b/admin_images.php @@ -0,0 +1,242 @@ + true)); + return; + } + + # make sure there's something clickable + foreach($rows as &$row) { + if($row['name'] == '') { + $row['name'] = '--'; + } + } + tem_set('listings', array( + 'populated_listing' => true, + 'rows' => $rows)); + return true; +} + +function admin_images_main() { + if(!logged_in_as_admin()) { + $_REQUEST['url'] = this_url(); + return 'admin_login'; + } + + if(isset($_REQUEST['admin_images_id'])) { + return admin_images_display_main(); + } else { + return admin_images_edit_main(); + } +} + +function admin_images_display_main() { + $id = format_int($_REQUEST['admin_images_id']); + unset($_REQUEST['admin_images_id']); + if(!$id) { + message('Error: Broken link'); + return './admin_images'; + } + $data = db_get_assoc('cms_images', 'id,'.ADMIN_IMAGES_DB_FIELDS, 'where id=%i', $id); + if(!$data) { + message('Error: Image not found'); + return './admin_images'; + } + + # Find pages that have this image on it + if($data['image']) { + $references = db_get_assocs('cms_pages', 'title,filename', 'where content like "%%%s%%" order by concat(nav_title,title)', substr(enc_image_src($data['image']), 0, -4)); # FIXME test that this works for smaller images + if($references) { + $data['references'] = array( + 'data' => $references, + 'count' => count($references)); + } + } + + # 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_hw.", $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_edit_main() { + $edit_id = format_int($_REQUEST['admin_images_edit_id']); + unset($_REQUEST['admin_images_edit_id']); + if($edit_id) { + # add hidden field for database id of row we're editing + tem_set('admin_images_edit_id', $edit_id); + tem_set('editing', 'show'); + tem_set('edit_msg', 'show'); + } + + $delete_id = format_int($_REQUEST['admin_images_delete_id']); + unset($_REQUEST['admin_images_delete_id']); + if($delete_id) { + db_delete('cms_images', 'where id=%i', $delete_id); + message('Image deleted.'); + + return './admin_images'; + } + + if(!$edit_id) { + if(!isset($_REQUEST['admin_images_new']) && !isset($_REQUEST['name'])) { + admin_images_display_listing(); + return; + } + + tem_set('new_msg', 'show'); + } + + if(isset($_POST['name'])) { + $data = admin_images_get_fields(); + + # 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_hw.", $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($edit_id) { + db_update_assoc('cms_images', $data, 'where id=%i', $edit_id); + message('Image updated.'); + $saved_id = $edit_id; + } else { + db_insert_assoc('cms_images', $data); + message('Image saved.'); + $saved_id = db_auto_id(); + } + + # return user to display page where they can see instructions, etc + return "./admin_images?admin_images_id=$saved_id"; + + } elseif($edit_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_images', ADMIN_IMAGES_DB_FIELDS, 'where id=%i', $edit_id); + } else { + # form not submitted, set default values: + $data = array('sizes' => '275x500'); + } + + tem_set('upload_max_filesize', upload_max_filesize()); + + tem_set('form', $data); +} + +?> diff --git a/admin_images.sql b/admin_images.sql new file mode 100644 index 0000000..815969e --- /dev/null +++ b/admin_images.sql @@ -0,0 +1,8 @@ +drop table if exists cms_images; +create table cms_images ( + id int unique auto_increment, + image varchar(240) not null default "", + name varchar(200) not null default "", + caption varchar(200) not null default "", + sizes text not null default "" +); diff --git a/admin_login.html b/admin_login.html new file mode 100644 index 0000000..9da243f --- /dev/null +++ b/admin_login.html @@ -0,0 +1,26 @@ + + + + + <!--~main_title show {~-->~this_host~ Admin Login<!--~}~--> + + + + + +

~this_host~ Admin Login

+ +
+
Username
+
+ +
Password
+
+ +
 
+
+
+ + + + diff --git a/admin_login.php b/admin_login.php new file mode 100644 index 0000000..a3d47ce --- /dev/null +++ b/admin_login.php @@ -0,0 +1,48 @@ + + + + + <!--~main_title show {~-->~this_host~ Admin: <!--~listings {~-->Pages Listing<!--~}~--><!--~form {~--><!--~new_msg {~-->Add a new page<!--~}~--><!--~edit_msg {~-->Edit 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.)
+
+ +
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.)
+
+ +
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.
  • +
+
+ +
Description
+
(Hidden description of this page, primarily for search engines.)
+
+ +
Keywords
+
(Hidden words (up to 30) with commas between them for search engines)
+
+ +
+ +
+ + + +

[Add a new page]

+ + + + + + + + + +
TitleFilename 
~title html~~filename html~[delete this page]
+ + +

No pages in database.

+ + +

[Add a new page]

+ + + + + diff --git a/admin_pages.php b/admin_pages.php new file mode 100644 index 0000000..cb2ecbe --- /dev/null +++ b/admin_pages.php @@ -0,0 +1,161 @@ + 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(); + return 'admin_login'; + } + + tem_set('this_host', this_host()); + + if(isset($_REQUEST['admin_pages_id'])) { + return admin_pages_display_main(); + } else { + return admin_pages_edit_main(); + } +} + +# 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'; + } + 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'); + } + + $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.'); + + return './admin_pages'; + } + + if(!$edit_id) { + if(!isset($_REQUEST['admin_pages_new']) && !isset($_REQUEST['title'])) { + admin_pages_display_listing(); + return; + } + + tem_set('new_msg', 'show'); + } + + $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 + $navbar_options[] = array($i + 1, "After \"$other_title\""); + } + } + pulldown('navbar', $navbar_options, PULLDOWN_2D); + + if(isset($_POST['title'])) { + $data = admin_pages_get_fields(); + + # We'll save anything (no required fields) + + $data['navbar'] = db_reposition('cms_pages', $edit_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; + message('Page updated.'); + } else { + db_insert_assoc('cms_pages', $data); + $id = db_auto_id(); + message('Page saved.'); + } + if($data['filename']) { + return "./$data[filename]"; + } else { + return "./admin_pages?admin_pages_id=$id"; + } + } elseif($edit_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); + 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'); + $data = array('filename' => format_cms_filename($_REQUEST['new_filename'])); + } + + tem_set('form', $data); + tem_set('extra_headers', 'show'); +} diff --git a/admin_pages.sql b/admin_pages.sql new file mode 100644 index 0000000..e82ed35 --- /dev/null +++ b/admin_pages.sql @@ -0,0 +1,11 @@ +drop table if exists pages; +create table cms_pages ( + id int unique auto_increment, + filename varchar(200) not null default "", + title varchar(200) not null default "", + nav_title varchar(200) not null default "", + navbar int not null default 0, + content text not null default "", + description text not null default "", + keywords text not null default "" +); diff --git a/code/ckeditor b/code/ckeditor new file mode 160000 index 0000000..c9fdde6 --- /dev/null +++ b/code/ckeditor @@ -0,0 +1 @@ +Subproject commit c9fdde67e6384bd5a66adc2b3bba5c4ce9db56c7 diff --git a/code/cms.php b/code/cms.php new file mode 100644 index 0000000..60e53b9 --- /dev/null +++ b/code/cms.php @@ -0,0 +1,37 @@ +set('basename', $basename); + + $nav_items = db_get_assocs('cms_pages', "coalesce(nullif(nav_title,''), title) as title,filename", 'where navbar!=0 order by navbar'); + if($nav_items) { + foreach($nav_items as &$nav_item) { + if($nav_item['filename'] == 'index') { + $nav_item['filename'] = './'; + } + if($nav_item['title'] == '') { + $nav_item['title'] = '-- blank --'; + } + } + $tem->set('navbar_items', $nav_items); + } + + $have_content = cms_display_content($tem, 'where filename=%"', $basename); + + if(logged_in_as_admin()) { + $tem->set('admin_links', 1); + } + return $have_content; +} + +function cms_display_content(&$tem /*, 'where clause %", %i', string, int */) { + $args = array_slice(func_get_args(), 1); + $args = array_merge(array('cms_pages', 'id as admin_edit_page_id,title as cms_title,content as cms_body,keywords as meta_keywords,description as meta_description'), $args); + $row = call_user_func_array('db_get_assoc', $args); + if($row) { + # dump it into the global scope: + $tem->sets($row); + return true; + } + return false; +} diff --git a/code/config.php b/code/config.php new file mode 100644 index 0000000..39900ee --- /dev/null +++ b/code/config.php @@ -0,0 +1,19 @@ + + + + ~main_title html~~cms_title html~ + + + + + + + + + +
+
+ header image here +
+ + +
+ + + + +
+

~data html~

+
+
+ + +
+ ~cms_body~ + + ~main_body~ +
+ +
+
+ +