From d8a3c68fe7131555725440aabc9f82e53520b5dc Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Thu, 19 Jan 2017 15:52:10 -0500 Subject: [PATCH] db_upgrade rework, admin_header, cleanup --- Makefile | 2 +- admin.html | 10 +-- admin_files.php | 8 +-- admin_header.html | 35 ++++++++++ admin_header.php | 72 +++++++++++++++++++++ admin_images.php | 4 +- admin_pages.php | 2 +- admin_users.php | 2 +- cms_images_autoresize.php | 9 ++- config.php | 16 ++--- contact.php | 4 +- inc/cms.php | 42 ++++++++---- inc/db_upgrade.php | 158 ++++++++++++++++++++++++++++++++------------- inc/wfpl | 2 +- login.php | 4 +- style.styl | 15 ++++- template.html | 7 +- wfpl_main.php | 6 +- 18 files changed, 300 insertions(+), 98 deletions(-) create mode 100644 admin_header.html create mode 100644 admin_header.php diff --git a/Makefile b/Makefile index e6222d1..b32e60b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -svgs= images/sprites.svg +svgs= minified_svgs= $(svgs:.svg=.min.svg) generated_images= $(svgs:.svg=.png) images= diff --git a/admin.html b/admin.html index 1e1e677..4529ac9 100644 --- a/admin.html +++ b/admin.html @@ -9,13 +9,15 @@

~$host~ Admin Control Panel

-

Manage images

+

Images

-

Manage pages

+

Header image (top of every page)

-

Manage (downloadable) files

+

Pages

-

Manage accounts (admin passwords, etc.)

+

Files (downloadable)

+ +

Accounts (admin passwords, etc.)

Log out

diff --git a/admin_files.php b/admin_files.php index 1531d9f..71ca43e 100644 --- a/admin_files.php +++ b/admin_files.php @@ -12,9 +12,9 @@ $GLOBALS['upload_directory'] = 'files/'; $GLOBALS['filename_file_name'] = uniqid() . getmypid() . '.txt'; -require_once(DOCROOT . 'inc/wfpl/format.php'); -require_once(DOCROOT . 'inc/wfpl/email.php'); -require_once(DOCROOT . 'inc/wfpl/upload.php'); +require_once(__DIR__.'/'.'inc/wfpl/format.php'); +require_once(__DIR__.'/'.'inc/wfpl/email.php'); +require_once(__DIR__.'/'.'inc/wfpl/upload.php'); function admin_files_get_fields() { $data = array(); @@ -44,7 +44,7 @@ function admin_files_get_fields() { function admin_files_main() { - session_auth_must('manage_files'); + session_auth_must('admin_files'); $id = _REQUEST_cut('edit_id'); if($id) { diff --git a/admin_header.html b/admin_header.html new file mode 100644 index 0000000..fc452ae --- /dev/null +++ b/admin_header.html @@ -0,0 +1,35 @@ + + + + + <!--~$title show {~-->~$host~ Admin: Header Image<!--~}~--> + + + + + + +

~$host~ Admin: Set header image for home page

+ +
+ +
Width (in pixels)
+
Your image will be automatically resized to be this wide. ~width_max~ is the full width of the available space.
+
+ +
Image
+
Please upload an image that is at least the width you specified above.
+
+ +
Caption (optional)
+
If specified, this will overlay the bottom/left corner of the header image.
+
+ +
+ +
+ + + + + diff --git a/admin_header.php b/admin_header.php new file mode 100644 index 0000000..66430ad --- /dev/null +++ b/admin_header.php @@ -0,0 +1,72 @@ + WFPL_SITE_WIDTH) { + $data['width'] = WFPL_SITE_WIDTH; + } + + $old = persistent_get('wfplcms_header_image'); + if ($_FILES['image'] && $_FILES['image']['error'] == 0) { + if ($old) { + $data['version'] = 1 + $old['version']; + } else { + $data['version'] = 1; + } + $ext = generate_filename($_FILES['image']['name'], $_FILES['image']['type']); + $ext = substr($ext, strrpos($ext, '.') + 1); + $ext = strtolower($ext); + if ($ext !== 'jpg' && $ext !== 'jpeg') { + $ext = 'png'; + } + $dest = "{$GLOBALS['upload_directory']}header_v{$data['version']}.$ext"; + $image = convert_uploaded_image('image', $dest, $data['width'], 2000); + # FIXME use autoresizer instead, and call identify to get aspect ratio + $image = explode(' ', $image); + $data['url'] = $image[0]; + $data['width'] = $image[1]; + $data['height'] = $image[2]; + } else if ($old) { + $data['url'] = $old['url']; + if ($data['width'] == $old['width']) { + $data['height'] = $old['height']; + } else { + $data['height'] = $old['height'] / $old['width'] * $data['width']; + } + } + unset($_FILES['image']); + + return $data; +} + + +function admin_header_main() { + session_auth_must('admin_header'); + + if (isset($_REQUEST['width'])) { + $data = admin_header_get_fields(); + if (isset($data['url'])) { + persistent_set('wfplcms_header_image', $data); + message('Header image updated'); + return './admin_header'; + } + } else { + $data = persistent_get('wfplcms_header_image'); + if (!$data) { + $data = array('width' => ''); + } + } + + tem_set('width_max', WFPL_SITE_WIDTH); + + tem_set('form', $data); +} \ No newline at end of file diff --git a/admin_images.php b/admin_images.php index c4647c1..443aae9 100644 --- a/admin_images.php +++ b/admin_images.php @@ -4,8 +4,8 @@ define('ADMIN_IMAGES_DB_FIELDS', 'image,name,caption'); -require_once(DOCROOT . 'inc/wfpl/format.php'); -require_once(DOCROOT . 'inc/wfpl/upload.php'); +require_once(__DIR__.'/'.'inc/wfpl/format.php'); +require_once(__DIR__.'/'.'inc/wfpl/upload.php'); # example: 200x300 function format_width_height($str) { diff --git a/admin_pages.php b/admin_pages.php index 7981bf6..4081f94 100644 --- a/admin_pages.php +++ b/admin_pages.php @@ -36,7 +36,7 @@ function admin_pages_get_fields() { function admin_pages_main() { - session_auth_must('edit_page'); + session_auth_must('admin_pages'); $id = _REQUEST_cut('edit_id'); if($id) { diff --git a/admin_users.php b/admin_users.php index 624b6b0..9e4a753 100644 --- a/admin_users.php +++ b/admin_users.php @@ -153,7 +153,7 @@ function admin_users_main_form($id = false) { if (isset($data['pass1']) && strlen($data['pass1']) > 0) { # hash password for db storage if (!function_exists('password_hash')) { - require_once(DOCROOT . 'inc/password_funcs_backported.php'); + require_once(__DIR__.'/'.'inc/password_funcs_backported.php'); } $data['password'] = password_hash($data['pass1'], PASSWORD_DEFAULT); } diff --git a/cms_images_autoresize.php b/cms_images_autoresize.php index 922b3cf..0d3e667 100644 --- a/cms_images_autoresize.php +++ b/cms_images_autoresize.php @@ -1,8 +1,7 @@ DOCROOT . 'inc/payment_membership.php' + #'membership' => __DIR__.'/'.'inc/payment_membership.php' ]; $GLOBALS['email_templates'] = [ diff --git a/contact.php b/contact.php index e19fe19..11d53b2 100644 --- a/contact.php +++ b/contact.php @@ -12,8 +12,8 @@ $globals['contact_subject'] = ''; $GLOBALS['contact_robot_answer'] = 1002; -require_once(DOCROOT . 'inc/wfpl/format.php'); -require_once(DOCROOT . 'inc/wfpl/email.php'); +require_once(__DIR__.'/'.'inc/wfpl/format.php'); +require_once(__DIR__.'/'.'inc/wfpl/email.php'); function contact_get_fields() { $data = array(); diff --git a/inc/cms.php b/inc/cms.php index f8154a9..06324f0 100644 --- a/inc/cms.php +++ b/inc/cms.php @@ -2,6 +2,12 @@ # This function (which loads the navbar and page content from the database) is # called automatically by wfpl_main() + +function enc_css_str($str) { + $str = str_replace("\\", "\\00005c", $str); + return str_replace("\"", "\\000022", $str); +} + function cms_display($basename, &$tem) { if(preg_match('/([.]l(ocal)?$)|^192[.]168[.]|^127.0.0.1$|^10[.]/', $_SERVER['HTTP_HOST'])) { $GLOBALS['wfpl_main_template']->set('$running_locally'); @@ -24,6 +30,29 @@ function cms_display($basename, &$tem) { $tem->set('$navbar_items', $nav_items); } + $header_image = persistent_get('wfplcms_header_image'); + if ($header_image) { + $hi_css = "\n\n"; + + $tem->set('$cms_css', $hi_css); + } + $cms_page_id = cms_display_content($tem, 'where filename=%"', $basename); $footer = db_get_value('cms_pages', 'content', 'where filename="_footer"'); @@ -31,19 +60,6 @@ function cms_display($basename, &$tem) { $tem->set('$cms_footer', $footer); } - $header = db_get_value('cms_images', 'image', 'where name="Header"'); - if ($header) { - $parts = explode(' ', $header . ' ', 7); - $tem->set('$cms_header', - '
' - ); - } - if(session_auth_can('admin_links')) { $admin_links = array(); if($cms_page_id) { diff --git a/inc/db_upgrade.php b/inc/db_upgrade.php index 07c633f..8bfa14f 100644 --- a/inc/db_upgrade.php +++ b/inc/db_upgrade.php @@ -1,49 +1,117 @@ .centerer position: relative -header#site_header - margin-bottom: 15px +#site_header + margin: 0 auto 15px auto + position: relative +#site_header:before + display: block + background-size: 100% +#site_header:after + display: block + position: absolute + bottom: 0 + right: 0 + padding: 4px + text-align: right body > .centerer > .nav margin-bottom: 15px diff --git a/template.html b/template.html index 2c853c1..288065f 100644 --- a/template.html +++ b/template.html @@ -10,16 +10,17 @@ +
- - - diff --git a/wfpl_main.php b/wfpl_main.php index ecc2acc..134ca9b 100644 --- a/wfpl_main.php +++ b/wfpl_main.php @@ -2,9 +2,7 @@ # This file should be run automatically by .htaccess -define('DOCROOT', __DIR__ .'/'); +require_once(__DIR__.'/' . 'config.php'); -require_once(DOCROOT . 'config.php'); - -require_once(DOCROOT . 'inc/wfpl/main.php'); +require_once(__DIR__.'/' . 'inc/wfpl/main.php'); wfpl_main(); -- 1.7.10.4