JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added admin_files, s/this_host/$host/, etc
authorJason Woofenden <jason@jasonwoof.com>
Fri, 14 Oct 2011 00:14:32 +0000 (20:14 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Fri, 14 Oct 2011 00:14:32 +0000 (20:14 -0400)
Makefile
admin.html
admin.php
admin_files.html
admin_files.php
admin_login.html
admin_login.php
admin_pages.html
admin_pages.php
code/cms.php

index 9eeb0f4..11039bc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,14 @@
 
 all: style.css tags
 
+init: files cms_images all
+
+files:
+       mkdir -m 777 $@
+
+cms_images:
+       mkdir -m 777 $@
+
 tags: *.php code/*.php code/wfpl/*.php
        exuberant-ctags *.php code/*.php code/wfpl/*.php
 
index cf25af3..c89654e 100644 (file)
@@ -2,17 +2,19 @@
 
 <html lang="en">
 <head>
-       <title><!--~$title show {~-->~this_host~ Administration<!--~}~--></title>
+       <title><!--~$title show {~-->~$host~ Administration<!--~}~--></title>
        <link rel="stylesheet" href="style.css" type="text/css" />
 </head>
 
 <body>
        <!--~$body show {~-->
-               <h2>~this_host~ Administration</h2>
+               <h2>~$host~ Administration</h2>
 
-               <p><a href="admin_images">Upload/edit images</a></p>
+               <p><a href="admin_images">Manage images</a></p>
 
-               <p><a href="admin_pages">Add/edit pages</a></p>
+               <p><a href="admin_pages">Manage pages</a></p>
+
+               <p><a href="admin_files">Manage (downloadable) files</a></p>
 
                <p><a href="logout">Log out</a></p>
        <!--~}~-->
index 8c115ce..8442e97 100644 (file)
--- a/admin.php
+++ b/admin.php
@@ -7,5 +7,4 @@ function admin_main() {
                $_REQUEST['url'] = this_url();
                return 'admin_login';
        }
-       tem_set('this_host', this_host());
 }
index 180d515..172ad09 100644 (file)
 
                <form action="admin_files" method="post" enctype="multipart/form-data"><!--~id {~--><div style="display: none"><input type="hidden" name="edit_id" value="~id attr~"></div><!--~}~--><input type="hidden" name="MAX_FILE_SIZE" value="~upload_max_filesize~">
 
-                       <div class="caption">Filename</div>
+                       <div class="caption">File</div>
                        <div class="field"><input type="file" name="filename"><input type="hidden" name="old_filename" value="~filename attr~"></div>
 
-                       <div class="caption">Description</div>
+                       <div class="caption">Description (optional)</div>
+                       <div class="field_notes">The files admin page sorts by this, so you can find your files.</div>
                        <div class="field"><input type="text" name="description" value="~description attr~"></div>
 
                        <div class="caption">&nbsp;</div>
                <h2>Files Listing</h2>
 
                <!--~listings once_if {~-->
+                       <p>The value in the "Path" column below can be pasted into the "URL" field of the link dialog on the page editor. Be sure to set the "protocol" pulldown there to "other". To link to a file from any other website (or e-mail, etc) create the full address by prefixing it with "http://~$host~"</p>
+
                        <p><a href="admin_files?new=1">[Add a new file]</a></p>
 
                        <table cellspacing="0" cellpadding="4" border="1" summary="">
-                               <tr><th>Filename</th><th>Description</th><th>&nbsp;</th></tr><!--~listings {~-->
+                               <tr><th>Path</th><th>Description</th><th>&nbsp;</th></tr><!--~listings {~-->
                                <tr>
-                                       <td class="listing"><a href="admin_files?edit_id=~id~">~filename html~<!--~filename empty {~--><em>(blank)</em><!--~}~--></a></td>
+                                       <td class="listing"><a href="admin_files?edit_id=~id~">/~filename html~<!--~filename empty {~--><em>(blank)</em><!--~}~--></a></td>
                                        <td class="listing"><a href="admin_files?edit_id=~id~">~description html~<!--~description empty {~--><em>(blank)</em><!--~}~--></a></td>
                                        <td><a href="admin_files?admin_files_delete_id=~id~" onclick="return confirm('Permanently delete?')">[delete this file]</a></td>
                                </tr><!--~}~-->
index 56a78ae..56db7ca 100644 (file)
@@ -21,9 +21,10 @@ define('ADMIN_FILES_DB_FIELDS', 'filename,description');
 
 # Set this to the path to your uploads directory. It can be relative to the
 # location of this script. IT MUST END WITH A SLASH
-$GLOBALS['upload_directory'] = 'uploads/';
+$GLOBALS['upload_directory'] = 'files/';
 
-$GLOBALS['filename_file_name'] = uniqid() . getmypid() . '.txt'; # comment this out to use uploader's filename
+# emergency backup in case uploaders file name is blank somehow
+$GLOBALS['filename_file_name'] = uniqid() . getmypid() . '.txt';
 
 
 require_once('code/wfpl/format.php');
@@ -35,9 +36,12 @@ function admin_files_get_fields() {
 
        $data['description'] = format_oneline(_REQUEST_cut('description'));
 
-       $filename_filename_tmp = $GLOBALS['filename_file_name'];
+       #header('Content-Type: text/plain');
+       #print_r(array($_REQUEST['filename'], $_FILES['filename']));
+       #exit();
+       $filename_filename_tmp = format_filename($_FILES['filename']['name']);
        if(!$filename_filename_tmp) {
-               $filename_filename_tmp = format_filename(_REQUEST_cut('filename'));
+               $filename_filename_tmp = $GLOBALS['filename_file_name'];
        }
        if($_FILES['filename'] && $_FILES['filename']['error'] == 0) {
                $data['filename'] = save_uploaded_file('filename', $GLOBALS['upload_directory'] . $filename_filename_tmp);
@@ -95,7 +99,7 @@ function admin_files_main_delete($id) {
 }
 
 function admin_files_main_listing() {
-       $listing_rows = db_get_assocs('files', 'id,filename,description', 'order by description limit 100');
+       $listing_rows = db_get_assocs('files', 'id,filename,description', 'order by coalesce(nullif(description, ""), substring(filename, 7)) limit 100');
        tem_set('listings', $listing_rows);
 }
 
index 1cb44ce..4dc10b7 100644 (file)
@@ -2,13 +2,13 @@
 
 <html>
 <head>
-       <title><!--~$title show {~-->~this_host~ Admin Login<!--~}~--></title>
+       <title><!--~$title show {~-->~$host~ Admin Login<!--~}~--></title>
 </head>
 
 <body>
        <!--~$body show {~-->
                <!--~form {~-->
-                       <h2>~this_host~ Admin Login</h2>
+                       <h2>~$host~ Admin Login</h2>
 
                        <form action="admin_login" method="post">
                                <div class="caption">Username (case sensitive)</div>
index a3d47ce..92d3ab6 100644 (file)
@@ -40,9 +40,6 @@ function admin_login_main() {
        # Don't put (even failed) password back into the form
        $data['password'] = '';
 
-       # include domain name in title (especially for bookmarks) and header
-       tem_set('this_host', this_host());
-
        # display the form [again]
        tem_set('form', $data);
 }
index 9f769b3..f72d501 100644 (file)
@@ -3,7 +3,7 @@
 <html lang="en">
 <head>
        <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>
+       <title><!--~$title show {~-->~$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">
index b1e7f16..f674b66 100644 (file)
@@ -36,8 +36,6 @@ function admin_pages_main() {
                return 'admin_login';
        }
 
-       tem_set('this_host', this_host());
-
        $id = _REQUEST_cut('edit_id');
        if($id) {
                return admin_pages_main_form($id);
index eacff25..6111440 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 function cms_display($basename, &$tem) {
+       $tem->set('$host', this_host());
        $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) {