JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
indent with spaces
authorJason Woofenden <jason@jasonwoof.com>
Sun, 3 May 2020 20:51:52 +0000 (16:51 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Sun, 3 May 2020 20:51:52 +0000 (16:51 -0400)
31 files changed:
.gitmodules
.htaccess
admin.html
admin.php
admin_email_templates.html
admin_email_templates.php
admin_files.html
admin_files.php
admin_header.html
admin_header.php
admin_images.html
admin_images.php
admin_pages.html
admin_pages.php
admin_users.html
admin_users.php
cms_images_autoresize.php
config.php
contact.html
contact.php
error_404.html
error_404.php
inc/cms.php
inc/db_upgrade.php
inc/misc.php
inc/session_auth.php
login.html
login.php
logout.php
paypal_ipn.php
template.html

index 002e8ba..0b8e212 100644 (file)
@@ -1,6 +1,6 @@
 [submodule "inc/wfpl"]
-       path = inc/wfpl
-       url = /home/jasonwoof/www/wfpl.git
+    path = inc/wfpl
+    url = /home/jasonwoof/www/wfpl.git
 [submodule "inc/ckeditor"]
-       path = inc/ckeditor
-       url = /home/jasonwoof/www/ckeditor.git
+    path = inc/ckeditor
+    url = /home/jasonwoof/www/ckeditor.git
index 092abd1..38ace93 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -10,8 +10,8 @@ RewriteEngine  on
 RewriteRule ^[^/.]*$ /wfpl_main.php [L]
 
 <FilesMatch "\.(css|jpg|png)$">
-       ExpiresActive On
-       ExpiresDefault A31536000
+    ExpiresActive On
+    ExpiresDefault A31536000
 </FilesMatch>
 
 # SECURITY: don't execute code on the server (exception below)
@@ -26,16 +26,16 @@ RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo
 RewriteRule ^(wfpl_main\.php|paypal_ipn\.php|cms_images_autoresize\.php)$  - [L]
 RewriteRule .*\.php$ - [L,R=404]
 <Files "wfpl_main.php">
-       php_flag engine on
-       SetHandler application/x-httpd-php
+    php_flag engine on
+    SetHandler application/x-httpd-php
 </Files>
 <Files "paypal_ipn.php">
-       php_flag engine on
-       SetHandler application/x-httpd-php
+    php_flag engine on
+    SetHandler application/x-httpd-php
 </Files>
 <Files "cms_images_autoresize.php">
-       php_flag engine on
-       SetHandler application/x-httpd-php
+    php_flag engine on
+    SetHandler application/x-httpd-php
 </Files>
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^cms_images/[0-9a-f]+w[0-9]+\.[pj][np]g$ /cms_images_autoresize.php
index 4529ac9..b123142 100644 (file)
@@ -2,24 +2,24 @@
 
 <html lang="en">
 <head>
-       <title><!--~$title show {~-->~$host~ Administration<!--~}~--></title>
+    <title><!--~$title show {~-->~$host~ Administration<!--~}~--></title>
 </head>
 
 <body>
-       <!--~$body show {~-->
-               <h1>~$host~ Admin Control Panel</h1>
+    <!--~$body show {~-->
+        <h1>~$host~ Admin Control Panel</h1>
 
-               <p><a href="admin_images">Images</a></p>
+        <p><a href="admin_images">Images</a></p>
 
-               <p><a href="admin_header">Header image (top of every page)</a></p>
+        <p><a href="admin_header">Header image (top of every page)</a></p>
 
-               <p><a href="admin_pages">Pages</a></p>
+        <p><a href="admin_pages">Pages</a></p>
 
-               <p><a href="admin_files">Files (downloadable)</a></p>
+        <p><a href="admin_files">Files (downloadable)</a></p>
 
-               <p><a href="admin_users">Accounts (admin passwords, etc.)</a></p>
+        <p><a href="admin_users">Accounts (admin passwords, etc.)</a></p>
 
-               <p><a href="logout">Log out</a></p>
-       <!--~}~-->
+        <p><a href="logout">Log out</a></p>
+    <!--~}~-->
 </body>
 </html>
index ed40e7a..4dcff01 100644 (file)
--- a/admin.php
+++ b/admin.php
@@ -1,5 +1,5 @@
 <?php
 
 function admin_main() {
-       session_auth_must('admin_control_panel');
+    session_auth_must('admin_control_panel');
 }
index a2a3e00..176c9a7 100644 (file)
 
 <html lang="en">
 <head>
-       <meta charset="utf-8" />
-       <title><!--~$title show {~-->Email templates<!--~}~--></title>
+    <meta charset="utf-8" />
+    <title><!--~$title show {~-->Email templates<!--~}~--></title>
 </head>
 
 <body>
 <!--~$body show {~-->
 
-       <!--~form {~-->
-               <h2>Edit email template "~title html~"</h2>
-
-               <p>~description htmlbrtab~</p>
-
-               <form action="admin_email_templates" method="post">
-                       <div class="caption">Notes</div>
-                       <div class="field_notes">This is here just for admins to save any kind of notes (for example clarifications on when/how this email template is used, or notes on what the template was like previously.)</div>
-                       <div class="field"><textarea rows="6" cols="22" name="notes">~notes html~</textarea></div>
-
-                       <div class="caption">"From:" email address (required)</div>
-                       <div class="field_notes">When this email template is used, the email generated will be sent <strong>from</strong> this address.</div>
-                       <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
-                       <div class="field"><input type="text" name="from_addr" value="~from_addr attr~"></div>
-
-                       <!--~want_to_addr {~-->
-                               <div class="caption">"To:" email address (required)</div>
-                               <div class="field_notes">When this email template is used, the email generated will sent <strong>to</strong> this address.</div>
-                               <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
-                               <div class="field"><input type="text" name="to_addr" value="~to_addr attr~"></div>
-                       <!--~}~-->
-
-                       <div class="caption">"Cc:" email address (optional)</div>
-                       <div class="field_notes">If you enter an email address here, it will be added to the "Cc:" header, that is, it will get a copy of every email that uses this template. Note that the "Cc:" header is visible to all recipients, so this feature should probably only be used for testing.</div>
-                       <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
-                       <div class="field"><input type="text" name="cc_addr" value="~cc_addr attr~"></div>
-
-                       <div class="caption">"Bcc:" email address (optional)</div>
-                       <div class="field_notes">If you enter an email address here, it will be added to the "Bcc:" header, that is, it will get a copy of every email that uses this template. This email address will <em>not</em> be visible to recipients, and will not be included in replies.</div>
-                       <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
-                       <div class="field"><input type="text" name="bcc_addr" value="~bcc_addr attr~"></div>
-
-                       <div class="caption">Template Variables</div>
-                       <div class="field">You can place variables into the Subject and Message Body fields. This can be used, for example, to insert the recipients username into the message. Below is a table showing the variables that are available for this particular email template:
-                               <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd" style="margin-top: 5px">
-                                       <tr>
-                                               <th>Variable</th>
-                                               <th>Description</th>
-                                       </tr>
-                                       <tr>
-                                               <td>~~~~</td>
-                                               <td>Puts a single ~~ in the email. You <em>must</em> do this if you want a ~~ in your email.</td>
-                                       </tr>
-                                       <!--~variables {~-->
-                                               <tr>
-                                                       <td>~~~0~~~</td>
-                                                       <td>~1~</td>
-                                               </tr>
-                                       <!--~}~-->
-                               </table>
-                       </div>
-
-                       <div class="caption">Subject</div>
-                       <div class="field_notes">This field uses template variables, see above.</div>
-                       <div class="field"><input type="text" name="subject" value="~subject attr~"></div>
-
-                       <div class="caption">Message Body</div>
-                       <div class="field_notes">This field uses template variables, see above.</div>
-                       <div class="field"><textarea rows="9" cols="22" name="content">~content html~</textarea></div>
-
-                       <div class="caption"></div>
-                       <div class="field">
-                               <input type="hidden" name="slug" value="~slug attr~">
-                               <input type="submit" name="save" value="Save">
-                       </div>
-
-               </form>
-
-               <div class="caption">&nbsp;</div>
-               <div class="field"><a href="admin_email_templates~id {~?id=~id~~}~">Cancel</a></div>
-       <!--~}~-->
-
-       <!--~listings {~-->
-               <h2>Email Templates</h2>
-
-               <p>Click one to edit:</p>
-
-               <!--~rows once_if {~-->
-                       <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
-                               <tr>
-                                       <th><a href="?sort=~sorting-by-title~title">Template Title</a></th>
-                                       <th><a href="?sort=~sorting-by-subject~subject">Email Subject</a></th>
-                               </tr><!--~rows {~-->
-                               <tr>
-                                       <td class="listing"><a href="admin_email_templates?slug=~slug~">~title html~<!--~title empty {~--><em>(blank)</em><!--~}~--></a></td>
-                                       <td class="listing"><a href="admin_email_templates?slug=~slug~">~subject html~<!--~subject empty {~--><em>(blank)</em><!--~}~--></a></td>
-                               </tr><!--~}~-->
-
-                       </table>
-               <!--~}~-->
-       <!--~}~-->
+    <!--~form {~-->
+        <h2>Edit email template "~title html~"</h2>
+
+        <p>~description htmlbrtab~</p>
+
+        <form action="admin_email_templates" method="post">
+            <div class="caption">Notes</div>
+            <div class="field_notes">This is here just for admins to save any kind of notes (for example clarifications on when/how this email template is used, or notes on what the template was like previously.)</div>
+            <div class="field"><textarea rows="6" cols="22" name="notes">~notes html~</textarea></div>
+
+            <div class="caption">"From:" email address (required)</div>
+            <div class="field_notes">When this email template is used, the email generated will be sent <strong>from</strong> this address.</div>
+            <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
+            <div class="field"><input type="text" name="from_addr" value="~from_addr attr~"></div>
+
+            <!--~want_to_addr {~-->
+                <div class="caption">"To:" email address (required)</div>
+                <div class="field_notes">When this email template is used, the email generated will sent <strong>to</strong> this address.</div>
+                <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
+                <div class="field"><input type="text" name="to_addr" value="~to_addr attr~"></div>
+            <!--~}~-->
+
+            <div class="caption">"Cc:" email address (optional)</div>
+            <div class="field_notes">If you enter an email address here, it will be added to the "Cc:" header, that is, it will get a copy of every email that uses this template. Note that the "Cc:" header is visible to all recipients, so this feature should probably only be used for testing.</div>
+            <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
+            <div class="field"><input type="text" name="cc_addr" value="~cc_addr attr~"></div>
+
+            <div class="caption">"Bcc:" email address (optional)</div>
+            <div class="field_notes">If you enter an email address here, it will be added to the "Bcc:" header, that is, it will get a copy of every email that uses this template. This email address will <em>not</em> be visible to recipients, and will not be included in replies.</div>
+            <div class="field_notes">To supply a name also, use this <em>exact</em> format: <code>John Smith &lt;john@example.com&gt;</code></div>
+            <div class="field"><input type="text" name="bcc_addr" value="~bcc_addr attr~"></div>
+
+            <div class="caption">Template Variables</div>
+            <div class="field">You can place variables into the Subject and Message Body fields. This can be used, for example, to insert the recipients username into the message. Below is a table showing the variables that are available for this particular email template:
+                <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd" style="margin-top: 5px">
+                    <tr>
+                        <th>Variable</th>
+                        <th>Description</th>
+                    </tr>
+                    <tr>
+                        <td>~~~~</td>
+                        <td>Puts a single ~~ in the email. You <em>must</em> do this if you want a ~~ in your email.</td>
+                    </tr>
+                    <!--~variables {~-->
+                        <tr>
+                            <td>~~~0~~~</td>
+                            <td>~1~</td>
+                        </tr>
+                    <!--~}~-->
+                </table>
+            </div>
+
+            <div class="caption">Subject</div>
+            <div class="field_notes">This field uses template variables, see above.</div>
+            <div class="field"><input type="text" name="subject" value="~subject attr~"></div>
+
+            <div class="caption">Message Body</div>
+            <div class="field_notes">This field uses template variables, see above.</div>
+            <div class="field"><textarea rows="9" cols="22" name="content">~content html~</textarea></div>
+
+            <div class="caption"></div>
+            <div class="field">
+                <input type="hidden" name="slug" value="~slug attr~">
+                <input type="submit" name="save" value="Save">
+            </div>
+
+        </form>
+
+        <div class="caption">&nbsp;</div>
+        <div class="field"><a href="admin_email_templates~id {~?id=~id~~}~">Cancel</a></div>
+    <!--~}~-->
+
+    <!--~listings {~-->
+        <h2>Email Templates</h2>
+
+        <p>Click one to edit:</p>
+
+        <!--~rows once_if {~-->
+            <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
+                <tr>
+                    <th><a href="?sort=~sorting-by-title~title">Template Title</a></th>
+                    <th><a href="?sort=~sorting-by-subject~subject">Email Subject</a></th>
+                </tr><!--~rows {~-->
+                <tr>
+                    <td class="listing"><a href="admin_email_templates?slug=~slug~">~title html~<!--~title empty {~--><em>(blank)</em><!--~}~--></a></td>
+                    <td class="listing"><a href="admin_email_templates?slug=~slug~">~subject html~<!--~subject empty {~--><em>(blank)</em><!--~}~--></a></td>
+                </tr><!--~}~-->
+
+            </table>
+        <!--~}~-->
+    <!--~}~-->
 
 <!--~}~-->
 </body>
index 10ed922..4ca36a4 100644 (file)
@@ -6,21 +6,21 @@
 #
 # in config.php you'll need something like this:
 #
-#      $GLOBALS['email_templates'] = [
-#              'slug' => [
-#                      'title' => "Title shown in admin only",
-#                      'description' => "explain (for admins) what this template is for",
-#                      'variables' => [
-#                              ['name', "explan (for admins) what this variable is for"],
-#                              ['verbing', "admins can put these variables into the template"]
-#                      ],
-#                      'subject' => "email subject",
-#                      'content' => "Hi, ~name~ this is the email body, thanks for ~verbing~!",
-#                      'from_addr' => 'noreply@airservices.info',
-#                      'to_addr' => 'optional@to.address' # optional
-#              ]
-#              # , 'slug2' => ...
-#      ];
+#    $GLOBALS['email_templates'] = [
+#        'slug' => [
+#            'title' => "Title shown in admin only",
+#            'description' => "explain (for admins) what this template is for",
+#            'variables' => [
+#                ['name', "explan (for admins) what this variable is for"],
+#                ['verbing', "admins can put these variables into the template"]
+#            ],
+#            'subject' => "email subject",
+#            'content' => "Hi, ~name~ this is the email body, thanks for ~verbing~!",
+#            'from_addr' => 'noreply@airservices.info',
+#            'to_addr' => 'optional@to.address' # optional
+#        ]
+#        # , 'slug2' => ...
+#    ];
 
 # To save results to a database, you'll need to create the email_templates table.
 # The file admin_email_templates.sql should help with this
@@ -30,157 +30,157 @@ define('ADMIN_EMAIL_TEMPLATES_DB_FIELDS', 'slug,notes,from_addr,to_addr,cc_addr,
 
 
 $GLOBALS['admin_email_templates_field_to_caption'] = array(
-       'slug' => 'Slug',
-       'notes' => 'Notes',
-       'from_addr' => 'From Address',
-       'to_addr' => 'To Address',
-       'cc_addr' => 'Cc Address',
-       'bcc_addr' => 'Bcc Address',
-       'subject' => 'Subject',
-       'content' => 'Content'
+    'slug' => 'Slug',
+    'notes' => 'Notes',
+    'from_addr' => 'From Address',
+    'to_addr' => 'To Address',
+    'cc_addr' => 'Cc Address',
+    'bcc_addr' => 'Bcc Address',
+    'subject' => 'Subject',
+    'content' => 'Content'
 );
 
 function admin_email_templates_get_fields() {
-       $data = array();
-
-       # slug is cut in *_main()
-       $data['notes'] = format_unix(_REQUEST_cut('notes'));
-       $data['to_addr'] = format_email(trim(_REQUEST_cut('to_addr')));
-       $data['from_addr'] = format_email(trim(_REQUEST_cut('from_addr')));
-       $data['cc_addr'] = format_email(trim(_REQUEST_cut('cc_addr')));
-       $data['bcc_addr'] = format_email(trim(_REQUEST_cut('bcc_addr')));
-       $data['subject'] = format_oneline(trim(_REQUEST_cut('subject')));
-       $data['content'] = format_unix(_REQUEST_cut('content'));
-
-       return $data;
+    $data = array();
+
+    # slug is cut in *_main()
+    $data['notes'] = format_unix(_REQUEST_cut('notes'));
+    $data['to_addr'] = format_email(trim(_REQUEST_cut('to_addr')));
+    $data['from_addr'] = format_email(trim(_REQUEST_cut('from_addr')));
+    $data['cc_addr'] = format_email(trim(_REQUEST_cut('cc_addr')));
+    $data['bcc_addr'] = format_email(trim(_REQUEST_cut('bcc_addr')));
+    $data['subject'] = format_oneline(trim(_REQUEST_cut('subject')));
+    $data['content'] = format_unix(_REQUEST_cut('content'));
+
+    return $data;
 }
 
 
 function admin_email_templates_main() {
-       session_auth_must('admin_email_templates');
+    session_auth_must('admin_email_templates');
 
-       $slug = _REQUEST_cut('slug');
-       if ($slug && isset($GLOBALS['email_templates'][$slug])) {
-               return admin_email_templates_main_form($slug);
-       }
+    $slug = _REQUEST_cut('slug');
+    if ($slug && isset($GLOBALS['email_templates'][$slug])) {
+        return admin_email_templates_main_form($slug);
+    }
 
-       # default action:
-       return admin_email_templates_main_listing();
+    # default action:
+    return admin_email_templates_main_listing();
 }
 
 function admin_email_templates_main_sort_title($a, $b) {
-       return strcasecmp($a['title'], $b['title']);
+    return strcasecmp($a['title'], $b['title']);
 }
 function admin_email_templates_main_sort_title_reverse($a, $b) {
-       return strcasecmp($b['title'], $a['title']);
+    return strcasecmp($b['title'], $a['title']);
 }
 function admin_email_templates_main_sort_subject($a, $b) {
-       return strcasecmp($a['subject'], $b['subject']);
+    return strcasecmp($a['subject'], $b['subject']);
 }
 function admin_email_templates_main_sort_subject_reverse($a, $b) {
-       return strcasecmp($b['subject'], $a['subject']);
+    return strcasecmp($b['subject'], $a['subject']);
 }
 
 function admin_email_templates_main_listing() {
-       $data = array();
-       $reverse = '';
-       $sort = _REQUEST_cut('sort');
-       if ($sort && substr($sort, 0, 1) === '-') {
-               $sort = substr($sort, 1);
-               $reverse = "_reverse";
-       } else {
-               $data["sorting-by-$sort"] = '-';
-       }
-       $legal_sorts = array('title', 'subject');
-       if (!$sort || !in_array($sort, $legal_sorts)) {
-               $sort = 'title';
-       }
-
-       $data['rows'] = array();
-
-       $rows = db_get_assocs('email_templates', 'slug,from_addr,cc_addr,bcc_addr,subject');
-       $by_slug = array();
-       foreach ($rows as $row) {
-               $by_slug[$row['slug']] = $row;
-       }
-       foreach ($GLOBALS['email_templates'] as $slug => $row) {
-               $out = array('slug' => $slug);
-               # defaults from config
-               foreach($row as $k => $v) {
-                       $out[$k] = $v;
-               }
-               # overwrite with db (if it's in the db)
-               if ($by_slug[$slug]) {
-                       foreach($by_slug[$slug] as $k => $v) {
-                               $out[$k] = $v;
-                       }
-               }
-               $data['rows'][] = $out;
-       }
-
-       usort($data['rows'], "admin_email_templates_main_sort_$sort$reverse");
-
-       tem_set('listings', $data);
+    $data = array();
+    $reverse = '';
+    $sort = _REQUEST_cut('sort');
+    if ($sort && substr($sort, 0, 1) === '-') {
+        $sort = substr($sort, 1);
+        $reverse = "_reverse";
+    } else {
+        $data["sorting-by-$sort"] = '-';
+    }
+    $legal_sorts = array('title', 'subject');
+    if (!$sort || !in_array($sort, $legal_sorts)) {
+        $sort = 'title';
+    }
+
+    $data['rows'] = array();
+
+    $rows = db_get_assocs('email_templates', 'slug,from_addr,cc_addr,bcc_addr,subject');
+    $by_slug = array();
+    foreach ($rows as $row) {
+        $by_slug[$row['slug']] = $row;
+    }
+    foreach ($GLOBALS['email_templates'] as $slug => $row) {
+        $out = array('slug' => $slug);
+        # defaults from config
+        foreach($row as $k => $v) {
+            $out[$k] = $v;
+        }
+        # overwrite with db (if it's in the db)
+        if ($by_slug[$slug]) {
+            foreach($by_slug[$slug] as $k => $v) {
+                $out[$k] = $v;
+            }
+        }
+        $data['rows'][] = $out;
+    }
+
+    usort($data['rows'], "admin_email_templates_main_sort_$sort$reverse");
+
+    tem_set('listings', $data);
 }
 
 function admin_email_templates_main_form($slug) {
-       if (isset($_POST['subject'])) {
-               $data = admin_email_templates_get_fields();
-               $data['slug'] = $slug;
-
-               $all_good = true;
-               $email_fields = ['from', 'to', 'cc', 'bcc'];
-               foreach ($email_fields as &$field) {
-                       $value = $data[$field . '_addr'];
-                       if (strlen($value)) {
-                               if (!email_header($value)) {
-                                       $pretty = ucfirst($field) . ':';
-                                       message("ERROR: invalid value in \"$pretty\" field. Be very careful with formatting, and only put one address in this field.");
-                                       $all_good = false;
-                               }
-                       }
-               } unset($field);
-
-               if (strlen($data['from_addr']) == 0) {
-                       message("ERROR: the \"From:\" field is required.");
-                       $all_good = false;
-               }
-
-               if (strlen($data['to_addr']) == 0 && isset($GLOBALS['email_templates'][$slug]['to_addr'])) {
-                       message("ERROR: the \"To:\" field is required for this template.");
-                       $all_good = false;
-               }
-               if ($all_good) {
-                       if (0 < db_count('email_templates', 'where slug=%"', $slug)) {
-                               db_update_assoc('email_templates', $data, 'where slug=%"', $slug);
-                       } else {
-                               db_insert_assoc('email_templates', $data);
-                       }
-                       message('Email template updated.');
-                       if ($error !== true) {
-                               return './admin_email_templates';
-                       }
-               } else {
-                       $custom = $data;
-               }
-       } else {
-               $custom = db_get_assoc('email_templates', ADMIN_EMAIL_TEMPLATES_DB_FIELDS, 'where slug=%"', $slug);
-       }
-
-       $out = array('slug' => $slug);
-       # defaults from globals
-       foreach($GLOBALS['email_templates'][$slug] as $k => $v) {
-               $out[$k] = $v;
-       }
-       # show 'to_addr' field if it's relevant
-       if (isset($out['to_addr'])) {
-               $out['want_to_addr'] = true;
-       }
-       # override with db values
-       if ($custom) {
-               foreach($custom as $k => $v) {
-                       $out[$k] = $v;
-               }
-       }
-       tem_set('form', $out);
+    if (isset($_POST['subject'])) {
+        $data = admin_email_templates_get_fields();
+        $data['slug'] = $slug;
+
+        $all_good = true;
+        $email_fields = ['from', 'to', 'cc', 'bcc'];
+        foreach ($email_fields as &$field) {
+            $value = $data[$field . '_addr'];
+            if (strlen($value)) {
+                if (!email_header($value)) {
+                    $pretty = ucfirst($field) . ':';
+                    message("ERROR: invalid value in \"$pretty\" field. Be very careful with formatting, and only put one address in this field.");
+                    $all_good = false;
+                }
+            }
+        } unset($field);
+
+        if (strlen($data['from_addr']) == 0) {
+            message("ERROR: the \"From:\" field is required.");
+            $all_good = false;
+        }
+
+        if (strlen($data['to_addr']) == 0 && isset($GLOBALS['email_templates'][$slug]['to_addr'])) {
+            message("ERROR: the \"To:\" field is required for this template.");
+            $all_good = false;
+        }
+        if ($all_good) {
+            if (0 < db_count('email_templates', 'where slug=%"', $slug)) {
+                db_update_assoc('email_templates', $data, 'where slug=%"', $slug);
+            } else {
+                db_insert_assoc('email_templates', $data);
+            }
+            message('Email template updated.');
+            if ($error !== true) {
+                return './admin_email_templates';
+            }
+        } else {
+            $custom = $data;
+        }
+    } else {
+        $custom = db_get_assoc('email_templates', ADMIN_EMAIL_TEMPLATES_DB_FIELDS, 'where slug=%"', $slug);
+    }
+
+    $out = array('slug' => $slug);
+    # defaults from globals
+    foreach($GLOBALS['email_templates'][$slug] as $k => $v) {
+        $out[$k] = $v;
+    }
+    # show 'to_addr' field if it's relevant
+    if (isset($out['to_addr'])) {
+        $out['want_to_addr'] = true;
+    }
+    # override with db values
+    if ($custom) {
+        foreach($custom as $k => $v) {
+            $out[$k] = $v;
+        }
+    }
+    tem_set('form', $out);
 }
index 9074a6e..bec7918 100644 (file)
@@ -2,70 +2,70 @@
 
 <html lang="en">
 <head>
-       <title><!--~$title show {~-->~$host~ Admin: Manage files<!--~}~--></title>
+    <title><!--~$title show {~-->~$host~ Admin: Manage files<!--~}~--></title>
 </head>
 
 <body>
 <!--~$body show {~-->
 
-       <!--~form {~-->
-               <h1>~$host~ Admin Control Panel</h1>
+    <!--~form {~-->
+        <h1>~$host~ Admin Control Panel</h1>
 
-               <h2><!--~id unset {~-->Add a new downloadable file<!--~}~--><!--~id {~-->Edit downloadable file "~description html~"<!--~}~--></h2>
+        <h2><!--~id unset {~-->Add a new downloadable file<!--~}~--><!--~id {~-->Edit downloadable file "~description html~"<!--~}~--></h2>
 
-               <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~">
+        <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">File</div>
-                       <div class="field"><input type="file" name="filename"><input type="hidden" name="old_filename" value="~filename attr~"></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 (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">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>
-                       <div class="field"><input type="submit" name="save" value="Save"></div>
+            <div class="caption">&nbsp;</div>
+            <div class="field"><input type="submit" name="save" value="Save"></div>
 
-               </form>
+        </form>
 
-               <div class="caption">&nbsp;</div>
-               <div class="field"><a href="admin_files~id {~?id=~id~~}~">Cancel</a></div>
-       <!--~}~-->
+        <div class="caption">&nbsp;</div>
+        <div class="field"><a href="admin_files~id {~?id=~id~~}~">Cancel</a></div>
+    <!--~}~-->
 
-       <!--~listings once {~-->
-               <h1>~$host~ Admin Control Panel</h1>
-               <h2>Manage downloadable Files</h2>
+    <!--~listings once {~-->
+        <h1>~$host~ Admin Control Panel</h1>
+        <h2>Manage downloadable Files</h2>
 
-               <p>To create a download link on your website:</p>
-               <ul>
-                       <li>Use the "Add a new file" link below to upload a file, then come back to this page.</li>
-                       <li>Select the value in the "Path" column below and copy it to the clipboard.</li>
-                       <li>Open the page editor for the page where you'd like the download link to appear. (Open the editor in another tab/window so you can still refer to these instructions.)</li>
-                       <li>In the page editor, type the text you'd like people to click on to download the file, then select this text and click the "link" button in the editor (it looks like a globe and a chain).</li>
-                       <li>Paste the "Path" (that you copied earlier from below) into the "URL" field, and set the "Protocol" field to "&lt;other&gt;". Click OK to close the link dialog.</li>
-                       <li>Click "Save" at the bottom of the editor page.</li>
-                       <li>Test your download link by clicking on it.</li>
-               </ul>
+        <p>To create a download link on your website:</p>
+        <ul>
+            <li>Use the "Add a new file" link below to upload a file, then come back to this page.</li>
+            <li>Select the value in the "Path" column below and copy it to the clipboard.</li>
+            <li>Open the page editor for the page where you'd like the download link to appear. (Open the editor in another tab/window so you can still refer to these instructions.)</li>
+            <li>In the page editor, type the text you'd like people to click on to download the file, then select this text and click the "link" button in the editor (it looks like a globe and a chain).</li>
+            <li>Paste the "Path" (that you copied earlier from below) into the "URL" field, and set the "Protocol" field to "&lt;other&gt;". Click OK to close the link dialog.</li>
+            <li>Click "Save" at the bottom of the editor page.</li>
+            <li>Test your download link by clicking on it.</li>
+        </ul>
 
-               <p><a href="admin_files?new=1">[Add a new file]</a></p>
+        <p><a href="admin_files?new=1">[Add a new file]</a></p>
 
-               <!--~listings once_if {~-->
-                       <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
-                               <tr><th>&nbsp;</th><th>Path</th><th>Description</th><th>&nbsp;</th></tr><!--~listings {~-->
-                               <tr>
-                                       <td class="listing"><!--~filename nonempty {~--><a href="/~filename attr~">download</a><!--~}~--><!--~filename empty {~-->&nbsp;<!--~}~--></td>
-                                       <td class="listing"><!--~filename nonempty {~-->~filename html~<!--~}~--><!--~filename empty {~--><em>(file missing)</em><!--~}~--></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><!--~}~-->
+        <!--~listings once_if {~-->
+            <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
+                <tr><th>&nbsp;</th><th>Path</th><th>Description</th><th>&nbsp;</th></tr><!--~listings {~-->
+                <tr>
+                    <td class="listing"><!--~filename nonempty {~--><a href="/~filename attr~">download</a><!--~}~--><!--~filename empty {~-->&nbsp;<!--~}~--></td>
+                    <td class="listing"><!--~filename nonempty {~-->~filename html~<!--~}~--><!--~filename empty {~--><em>(file missing)</em><!--~}~--></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><!--~}~-->
 
-                       </table>
-               <!--~}~-->
-               <!--~listings once_else {~-->
-                       <p>No downloadable files in database.</p>
-               <!--~}~-->
+            </table>
+        <!--~}~-->
+        <!--~listings once_else {~-->
+            <p>No downloadable files in database.</p>
+        <!--~}~-->
 
-               <p><a href="admin_files?new=1">[Add a new file]</a></p>
-       <!--~}~-->
+        <p><a href="admin_files?new=1">[Add a new file]</a></p>
+    <!--~}~-->
 
 <!--~}~-->
 </body>
index d32b14d..4b6ae04 100644 (file)
@@ -17,112 +17,112 @@ require_once(__DIR__.'/'.'inc/wfpl/email.php');
 require_once(__DIR__.'/'.'inc/wfpl/upload.php');
 
 function admin_files_get_fields() {
-       $data = array();
-
-       $data['description'] = format_oneline(_REQUEST_cut('description'));
-
-       #header('Content-Type: text/plain');
-       #print_r(array($_REQUEST['filename'], $_FILES['filename']));
-       #exit();
-       $filename_filename_tmp = format_filename($_FILES['filename']['name'], true);
-       if(!$filename_filename_tmp) {
-               $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);
-       } else {
-               if(_REQUEST_cut('delete_filename') == 'Yes') {
-                       $data['filename'] = '';
-               } else {
-                       $data['filename'] = format_path(_REQUEST_cut('old_filename'), true);
-               }
-       }
-       unset($_FILES['filename']);
-
-       return $data;
+    $data = array();
+
+    $data['description'] = format_oneline(_REQUEST_cut('description'));
+
+    #header('Content-Type: text/plain');
+    #print_r(array($_REQUEST['filename'], $_FILES['filename']));
+    #exit();
+    $filename_filename_tmp = format_filename($_FILES['filename']['name'], true);
+    if(!$filename_filename_tmp) {
+        $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);
+    } else {
+        if(_REQUEST_cut('delete_filename') == 'Yes') {
+            $data['filename'] = '';
+        } else {
+            $data['filename'] = format_path(_REQUEST_cut('old_filename'), true);
+        }
+    }
+    unset($_FILES['filename']);
+
+    return $data;
 }
 
 
 function admin_files_main() {
-       session_auth_must('admin_files');
+    session_auth_must('admin_files');
 
-       $id = _REQUEST_cut('edit_id');
-       if($id) {
-               return admin_files_main_form($id);
-       }
+    $id = _REQUEST_cut('edit_id');
+    if($id) {
+        return admin_files_main_form($id);
+    }
 
-       $id = _REQUEST_cut('admin_files_delete_id');
-       if($id) {
-               return admin_files_main_delete($id);
-       }
+    $id = _REQUEST_cut('admin_files_delete_id');
+    if($id) {
+        return admin_files_main_delete($id);
+    }
 
-       if(_REQUEST_cut('new')) {
-               return admin_files_main_form();
-       }
+    if(_REQUEST_cut('new')) {
+        return admin_files_main_form();
+    }
 
-       if(_REQUEST_cut('list')) {
-               return admin_files_main_listing();
-       }
+    if(_REQUEST_cut('list')) {
+        return admin_files_main_listing();
+    }
 
-       if(isset($_POST['description'])) {
-               return admin_files_main_form();
-       }
+    if(isset($_POST['description'])) {
+        return admin_files_main_form();
+    }
 
-       # default action:
-       return admin_files_main_listing();
+    # default action:
+    return admin_files_main_listing();
 }
 
 function admin_files_main_delete($id) {
-       $fn = db_get_value('files', 'filename', 'where id=%i', $id);
-       if ($fn) {
-               unlink($fn);
-               db_delete('files', 'where id=%i', $id);
-               message('File deleted.');
-       } else {
-               message("Couldn't find file to delete. Maybe it's already been deleted?");
-       }
-       return './admin_files';
+    $fn = db_get_value('files', 'filename', 'where id=%i', $id);
+    if ($fn) {
+        unlink($fn);
+        db_delete('files', 'where id=%i', $id);
+        message('File deleted.');
+    } else {
+        message("Couldn't find file to delete. Maybe it's already been deleted?");
+    }
+    return './admin_files';
 }
 
 function admin_files_main_listing() {
-       $listing_rows = db_get_assocs('files', 'id,filename,description', 'order by coalesce(nullif(description, ""), substring(filename, 7)) limit 100');
-       tem_set('listings', $listing_rows);
+    $listing_rows = db_get_assocs('files', 'id,filename,description', 'order by coalesce(nullif(description, ""), substring(filename, 7)) limit 100');
+    tem_set('listings', $listing_rows);
 }
 
 function admin_files_main_form($id = false) {
-       if($id) {
-               tem_set('id', $id);
-       }
-
-       if(isset($_POST['description'])) {
-               $data = admin_files_get_fields();
-
-               if("you're happy with the POSTed values") {
-                       if($id) {
-                               db_update_assoc('files', $data, 'where id=%i', $id);
-                               message('File updated.');
-                       } else {
-                               db_insert_assoc('files', $data);
-                               message('File saved.');
-                       }
-                       if($error !== true) {
-                               return './admin_files';
-                       }
-               }
-               # otherwise, we display the form again. admin_files_get_fields() has
-               # already put the posted values back into the template engine, so they will
-               # show up in the form fields. You should add some message asking people to
-               # fix their entry in whatever way you require.
-       } 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('files', ADMIN_FILES_DB_FIELDS, 'where id=%i', $id);
-       } else {
-               # form not submitted, you can set default values like so:
-               #$data = array('description' => 'Yes');
-               $data = array();
-       }
-
-       tem_set('upload_max_filesize', upload_max_filesize());
-
-       tem_set('form', $data);
+    if($id) {
+        tem_set('id', $id);
+    }
+
+    if(isset($_POST['description'])) {
+        $data = admin_files_get_fields();
+
+        if("you're happy with the POSTed values") {
+            if($id) {
+                db_update_assoc('files', $data, 'where id=%i', $id);
+                message('File updated.');
+            } else {
+                db_insert_assoc('files', $data);
+                message('File saved.');
+            }
+            if($error !== true) {
+                return './admin_files';
+            }
+        }
+        # otherwise, we display the form again. admin_files_get_fields() has
+        # already put the posted values back into the template engine, so they will
+        # show up in the form fields. You should add some message asking people to
+        # fix their entry in whatever way you require.
+    } 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('files', ADMIN_FILES_DB_FIELDS, 'where id=%i', $id);
+    } else {
+        # form not submitted, you can set default values like so:
+        #$data = array('description' => 'Yes');
+        $data = array();
+    }
+
+    tem_set('upload_max_filesize', upload_max_filesize());
+
+    tem_set('form', $data);
 }
index b74de64..fad2ee0 100644 (file)
@@ -1,34 +1,34 @@
 <!DOCTYPE html>
 <html lang="en">
 <head>
-       <meta charset="utf-8" />
-       <title><!--~$title show {~-->~$host~ Admin: Header Image<!--~}~--></title>
+    <meta charset="utf-8" />
+    <title><!--~$title show {~-->~$host~ Admin: Header Image<!--~}~--></title>
 </head>
 
 <body>
 <!--~$body show {~-->
 
-       <!--~form {~-->
-               <h2>~$host~ Admin: Set header image for home page</h2>
+    <!--~form {~-->
+        <h2>~$host~ Admin: Set header image for home page</h2>
 
-               <form action="admin_header" method="post" enctype="multipart/form-data"><input type="hidden" name="MAX_FILE_SIZE" value="~$upload_max_filesize~">
+        <form action="admin_header" method="post" enctype="multipart/form-data"><input type="hidden" name="MAX_FILE_SIZE" value="~$upload_max_filesize~">
 
-                       <div class="caption">Width (in pixels)</div>
-                       <div class="field_notes">Your image will be automatically resized to be this wide. ~width_max~ is the full width of the available space.</div>
-                       <div class="field"><input type="text" name="width" value="~width attr~" placeholder="~width_max~"></div>
+            <div class="caption">Width (in pixels)</div>
+            <div class="field_notes">Your image will be automatically resized to be this wide. ~width_max~ is the full width of the available space.</div>
+            <div class="field"><input type="text" name="width" value="~width attr~" placeholder="~width_max~"></div>
 
-                       <div class="caption">Image</div>
-                       <div class="field_notes">Please upload an image that is at least the width you specified above.</div>
-                       <div class="field"><input type="file" name="image"></div>
+            <div class="caption">Image</div>
+            <div class="field_notes">Please upload an image that is at least the width you specified above.</div>
+            <div class="field"><input type="file" name="image"></div>
 
-                       <div class="caption">Caption (optional)</div>
-                       <div class="field_notes">If specified, this will overlay the bottom/right corner of the header image.</div>
-                       <div class="field"><input type="text" name="caption" value="~caption attr~"></div>
+            <div class="caption">Caption (optional)</div>
+            <div class="field_notes">If specified, this will overlay the bottom/right corner of the header image.</div>
+            <div class="field"><input type="text" name="caption" value="~caption attr~"></div>
 
-                       <div class="caption field"><input type="submit" name="save" value="Save"></div>
+            <div class="caption field"><input type="submit" name="save" value="Save"></div>
 
-               </form>
-       <!--~}~-->
+        </form>
+    <!--~}~-->
 
 <!--~}~-->
 </body>
index 66430ad..f05640b 100644 (file)
@@ -6,67 +6,67 @@ $GLOBALS['upload_directory'] = 'image/';
 
 
 function admin_header_get_fields() {
-       $data = array();
+    $data = array();
 
-       $data['width'] = (int) format_int_0(_REQUEST_cut('width'));
-       $data['caption'] = format_oneline(_REQUEST_cut('caption'));
+    $data['width'] = (int) format_int_0(_REQUEST_cut('width'));
+    $data['caption'] = format_oneline(_REQUEST_cut('caption'));
 
-       if ($data['width'] < 100 || $data['width'] > WFPL_SITE_WIDTH) {
-               $data['width'] = WFPL_SITE_WIDTH;
-       }
+    if ($data['width'] < 100 || $data['width'] > 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']);
+    $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;
+    return $data;
 }
 
 
 function admin_header_main() {
-       session_auth_must('admin_header');
+    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' => '');
-               }
-       }
+    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('width_max', WFPL_SITE_WIDTH);
 
-       tem_set('form', $data);
+    tem_set('form', $data);
 }
\ No newline at end of file
index 9633384..fa3dc93 100644 (file)
@@ -2,71 +2,71 @@
 
 <html lang="en">
 <head>
-       <title><!--~$title show {~-->~$host~ Admin: Manage Images<!--~}~--></title>
+    <title><!--~$title show {~-->~$host~ Admin: Manage Images<!--~}~--></title>
 </head>
 
 <body>
 <!--~$body show {~-->
-       <!--~form {~-->
-               <h1>~$host~ Admin Control Panel</h1>
-
-               <h2><!--~id unset {~-->Add a new image<!--~}~--><!--~id {~-->Edit image "~name html~"<!--~}~--></h2>
-
-               <form action="admin_images" 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~">
-
-                       <!--~image once_if {~-->
-                               <div class="wfpl_ri"><div class="wfpl_i" style="background-image: url(~image image_src_small~); padding-top: ~image image_aspect~"></div>~caption html~</div>
-                       <!--~}~-->
-                       <!--~image once_else {~-->
-                       <div class="caption">Image</div>
-                       <div class="field"><input type="file" name="image"></div>
-                       <!--~}~-->
-
-                       <div class="caption">Name (used for sorting, optional)</div>
-                       <div class="field_notes">This value is never displayed to site visitors. Your collection of images are sorted by name, so you can use this field to keep your images organized.</div>
-                       <div class="field"><input type="text" name="name" value="~name attr~"></div>
-
-                       <div class="caption">Caption (optional)</div>
-                       <div class="field_notes">Here's some symbols you might want to paste in: &copy; &nbsp; &mdash; &nbsp; &ndash;</div>
-                       <div class="field"><input type="text" name="caption" value="~caption attr~"></div>
-
-                       <div class="caption field"><input type="submit" name="save" value="Save"></div>
-
-               </form>
-
-               <div class="caption">&nbsp;</div>
-               <div class="field"><a href="admin_images~id {~?id=~id~~}~">Cancel</a></div>
-       <!--~}~-->
-
-       <!--~listings once {~-->
-               <h1>~$host~ Admin Control Panel</h1>
-
-               <h2>Manage Images</h2>
-
-               <!--~listings once_if {~-->
-                       <p><a href="admin_images?new=1">[Add a new image]</a></p>
-
-                       <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
-                               <tr><th colspan="4" class="th_toggle_buttons">
-                                       <div><!--~sort_by_age unset {~--><a href="?sort=age"><!--~}~-->[sort by age]<!--~sort_by_age unset {~--></a><!--~}~--></div> <div><!--~sort_by_name unset {~--><a href="?sort=name"><!--~}~-->[sort by name/caption]<!--~sort_by_name unset {~--></a><!--~}~--></div> <div><!--~sort_by_caption unset {~--><a href="?sort=caption"><!--~}~-->[sort by caption/name]<!--~sort_by_caption unset {~--></a><!--~}~--></div>
-                               </th></tr>
-                               <!--~listings {~-->
-                               <tr>
-                                       <td class="listing"><!--~image nonempty {~--><a style="cursor: zoom-in" href="~image image_src_full~" target="_blank"><span class="wfpl_thumb" style="background-image: url(~image image_src_thumb~)"></span></a><!--~}~--></td>
-                                       <td class="listing">Name: ~name html~<br>Caption: ~caption html~</td>
-                                       <td><a href="admin_images?edit_id=~id~">[edit]</a></td>
-                                       <td><a href="admin_images?admin_images_delete_id=~id~" onclick="return confirm('Permanently delete?')" style="color: red">[delete]</a></td>
-                               </tr>
-                               <!--~}~-->
-
-                       </table>
-               <!--~}~-->
-               <!--~listings once_else {~-->
-                       <p>No images in database.</p>
-               <!--~}~-->
-
-               <p><a href="admin_images?new=1">[Add a new image]</a></p>
-       <!--~}~-->
+    <!--~form {~-->
+        <h1>~$host~ Admin Control Panel</h1>
+
+        <h2><!--~id unset {~-->Add a new image<!--~}~--><!--~id {~-->Edit image "~name html~"<!--~}~--></h2>
+
+        <form action="admin_images" 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~">
+
+            <!--~image once_if {~-->
+                <div class="wfpl_ri"><div class="wfpl_i" style="background-image: url(~image image_src_small~); padding-top: ~image image_aspect~"></div>~caption html~</div>
+            <!--~}~-->
+            <!--~image once_else {~-->
+            <div class="caption">Image</div>
+            <div class="field"><input type="file" name="image"></div>
+            <!--~}~-->
+
+            <div class="caption">Name (used for sorting, optional)</div>
+            <div class="field_notes">This value is never displayed to site visitors. Your collection of images are sorted by name, so you can use this field to keep your images organized.</div>
+            <div class="field"><input type="text" name="name" value="~name attr~"></div>
+
+            <div class="caption">Caption (optional)</div>
+            <div class="field_notes">Here's some symbols you might want to paste in: &copy; &nbsp; &mdash; &nbsp; &ndash;</div>
+            <div class="field"><input type="text" name="caption" value="~caption attr~"></div>
+
+            <div class="caption field"><input type="submit" name="save" value="Save"></div>
+
+        </form>
+
+        <div class="caption">&nbsp;</div>
+        <div class="field"><a href="admin_images~id {~?id=~id~~}~">Cancel</a></div>
+    <!--~}~-->
+
+    <!--~listings once {~-->
+        <h1>~$host~ Admin Control Panel</h1>
+
+        <h2>Manage Images</h2>
+
+        <!--~listings once_if {~-->
+            <p><a href="admin_images?new=1">[Add a new image]</a></p>
+
+            <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
+                <tr><th colspan="4" class="th_toggle_buttons">
+                    <div><!--~sort_by_age unset {~--><a href="?sort=age"><!--~}~-->[sort by age]<!--~sort_by_age unset {~--></a><!--~}~--></div> <div><!--~sort_by_name unset {~--><a href="?sort=name"><!--~}~-->[sort by name/caption]<!--~sort_by_name unset {~--></a><!--~}~--></div> <div><!--~sort_by_caption unset {~--><a href="?sort=caption"><!--~}~-->[sort by caption/name]<!--~sort_by_caption unset {~--></a><!--~}~--></div>
+                </th></tr>
+                <!--~listings {~-->
+                <tr>
+                    <td class="listing"><!--~image nonempty {~--><a style="cursor: zoom-in" href="~image image_src_full~" target="_blank"><span class="wfpl_thumb" style="background-image: url(~image image_src_thumb~)"></span></a><!--~}~--></td>
+                    <td class="listing">Name: ~name html~<br>Caption: ~caption html~</td>
+                    <td><a href="admin_images?edit_id=~id~">[edit]</a></td>
+                    <td><a href="admin_images?admin_images_delete_id=~id~" onclick="return confirm('Permanently delete?')" style="color: red">[delete]</a></td>
+                </tr>
+                <!--~}~-->
+
+            </table>
+        <!--~}~-->
+        <!--~listings once_else {~-->
+            <p>No images in database.</p>
+        <!--~}~-->
+
+        <p><a href="admin_images?new=1">[Add a new image]</a></p>
+    <!--~}~-->
 
 <!--~}~-->
 </body>
index 443aae9..c2f4943 100644 (file)
@@ -9,150 +9,150 @@ require_once(__DIR__.'/'.'inc/wfpl/upload.php');
 
 # example: 200x300
 function format_width_height($str) {
-       $fields = explode('x', $str);
-       if(count($fields) != 2) {
-               return '';
-       }
+    $fields = explode('x', $str);
+    if(count($fields) != 2) {
+        return '';
+    }
 
-       list($width, $height) = $fields;
-       $width = format_int_0($width);
-       $height = format_int_0($height);
+    list($width, $height) = $fields;
+    $width = format_int_0($width);
+    $height = format_int_0($height);
 
-       return "${width}x$height";
+    return "${width}x$height";
 }
 
 function admin_images_get_fields() {
-       $data = array();
-
-       $data['name'] = format_oneline(_REQUEST_cut('name'));
-       $data['caption'] = format_oneline(_REQUEST_cut('caption'));
-
-       if($_FILES['image'] && $_FILES['image']['error'] == 0 && file_exists($_FILES['image']['tmp_name'])) {
-               $image_fn_ext = path_or_mime_to_ext($_FILES['image']['name'], $_FILES['image']['type']);
-               $image_fn_ext = ext_to_web_image_ext($image_fn_ext);
-               $image_fn_base = sha1_file($_FILES['image']['tmp_name']);
-               if (strlen($image_fn_base) == 40) {
-                       $image_fn_base = substr($image_fn_base, 0, 16);
-                       $image_filename = 'cms_images/' . $image_fn_base . '.' . $image_fn_ext;
-                       $data['image'] = convert_uploaded_image('image', $image_filename);
-               }
-       } else {
-               if(_REQUEST_cut('delete_image') == 'Yes') {
-                       $data['image'] = '';
-               }
-       }
-       unset($_FILES['image']);
-
-       return $data;
+    $data = array();
+
+    $data['name'] = format_oneline(_REQUEST_cut('name'));
+    $data['caption'] = format_oneline(_REQUEST_cut('caption'));
+
+    if($_FILES['image'] && $_FILES['image']['error'] == 0 && file_exists($_FILES['image']['tmp_name'])) {
+        $image_fn_ext = path_or_mime_to_ext($_FILES['image']['name'], $_FILES['image']['type']);
+        $image_fn_ext = ext_to_web_image_ext($image_fn_ext);
+        $image_fn_base = sha1_file($_FILES['image']['tmp_name']);
+        if (strlen($image_fn_base) == 40) {
+            $image_fn_base = substr($image_fn_base, 0, 16);
+            $image_filename = 'cms_images/' . $image_fn_base . '.' . $image_fn_ext;
+            $data['image'] = convert_uploaded_image('image', $image_filename);
+        }
+    } else {
+        if(_REQUEST_cut('delete_image') == 'Yes') {
+            $data['image'] = '';
+        }
+    }
+    unset($_FILES['image']);
+
+    return $data;
 }
 
 
 function admin_images_main() {
-       session_auth_must('admin_images');
+    session_auth_must('admin_images');
 
-       $id = _REQUEST_cut('edit_id');
-       if($id) {
-               return admin_images_main_form($id);
-       }
+    $id = _REQUEST_cut('edit_id');
+    if($id) {
+        return admin_images_main_form($id);
+    }
 
-       $id = _REQUEST_cut('admin_images_delete_id');
-       if($id) {
-               return admin_images_main_delete($id);
-       }
+    $id = _REQUEST_cut('admin_images_delete_id');
+    if($id) {
+        return admin_images_main_delete($id);
+    }
 
-       if(_REQUEST_cut('new')) {
-               return admin_images_main_form();
-       }
+    if(_REQUEST_cut('new')) {
+        return admin_images_main_form();
+    }
 
-       if(_REQUEST_cut('list')) {
-               return admin_images_main_listing();
-       }
+    if(_REQUEST_cut('list')) {
+        return admin_images_main_listing();
+    }
 
-       if(isset($_POST['name'])) {
-               return admin_images_main_form();
-       }
+    if(isset($_POST['name'])) {
+        return admin_images_main_form();
+    }
 
-       # default action:
-       return admin_images_main_listing();
+    # default action:
+    return admin_images_main_listing();
 }
 
 function admin_images_main_delete($id) {
-       $data = db_get_assoc('cms_images', 'image', 'where id=%i', $id);
-       if ($data) {
-               $src = enc_image_src($data['image']);
-               if ($src) {
-                       $filenames = array($src);
-                       foreach ($GLOBALS['wfpl_image_widths'] as $w) {
-                               $filenames [] = substr($src, 0, -4) . 'w' . $w . substr($src, -4);
-                       }
-                       foreach ($filenames as $filename) {
-                               if (file_exists($filename)) {
-                                       unlink($filename);
-                               }
-                       }
-               }
-               db_delete('cms_images', 'where id=%i', $id);
-               message('Image deleted.');
-       } else {
-               message("Couldn't find image to delete. Maybe it's already been deleted?");
-       }
-       return './admin_images';
+    $data = db_get_assoc('cms_images', 'image', 'where id=%i', $id);
+    if ($data) {
+        $src = enc_image_src($data['image']);
+        if ($src) {
+            $filenames = array($src);
+            foreach ($GLOBALS['wfpl_image_widths'] as $w) {
+                $filenames [] = substr($src, 0, -4) . 'w' . $w . substr($src, -4);
+            }
+            foreach ($filenames as $filename) {
+                if (file_exists($filename)) {
+                    unlink($filename);
+                }
+            }
+        }
+        db_delete('cms_images', 'where id=%i', $id);
+        message('Image deleted.');
+    } else {
+        message("Couldn't find image to delete. Maybe it's already been deleted?");
+    }
+    return './admin_images';
 }
 
 function admin_images_main_listing() {
-       $sort_by = 'name';
-       $sorts = array(
-               'age' => 'created_at desc',
-               'name' => "coalesce(nullif(name, ''), caption), created_at",
-               'caption' => "coalesce(nullif(caption, ''), name), created_at"
-       );
-       if (isset($_REQUEST['sort'])) {
-               foreach ($sorts as $s => $sql) {
-                       if ($_REQUEST['sort'] == $s) {
-                               $sort_by = $s;
-                               break;
-                       }
-               }
-       }
-       tem_set("sort_by_$sort_by");
-       $listing_rows = db_get_assocs('cms_images', 'id,image,name,caption', 'order by ' . $sorts[$sort_by]);
-       tem_set('listings', $listing_rows);
+    $sort_by = 'name';
+    $sorts = array(
+        'age' => 'created_at desc',
+        'name' => "coalesce(nullif(name, ''), caption), created_at",
+        'caption' => "coalesce(nullif(caption, ''), name), created_at"
+    );
+    if (isset($_REQUEST['sort'])) {
+        foreach ($sorts as $s => $sql) {
+            if ($_REQUEST['sort'] == $s) {
+                $sort_by = $s;
+                break;
+            }
+        }
+    }
+    tem_set("sort_by_$sort_by");
+    $listing_rows = db_get_assocs('cms_images', 'id,image,name,caption', 'order by ' . $sorts[$sort_by]);
+    tem_set('listings', $listing_rows);
 }
 
 function admin_images_main_form($id = false) {
-       if($id) {
-               tem_set('id', $id);
-       }
-
-       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.)
-
-               # save to database
-               if($id) {
-                       db_update_assoc('cms_images', $data, 'where id=%i', $id);
-                       message('Image updated.');
-                       $saved_id = $id;
-                       return "./admin_images";
-               } else {
-                       $data['created_at'] = time();
-                       db_insert_assoc('cms_images', $data);
-                       message('Image saved. Next time you open a page editor, this image will be availble in the "Insert Image" dialog.');
-                       $saved_id = db_auto_id();
-                       return "./admin_images?sort=age";
-               }
-
-       } 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_images', ADMIN_IMAGES_DB_FIELDS, 'where id=%i', $id);
-       } else {
-               # form not submitted, set default values:
-               $data = array();
-       }
-
-       tem_set('upload_max_filesize', upload_max_filesize());
-
-       tem_set('form', $data);
+    if($id) {
+        tem_set('id', $id);
+    }
+
+    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.)
+
+        # save to database
+        if($id) {
+            db_update_assoc('cms_images', $data, 'where id=%i', $id);
+            message('Image updated.');
+            $saved_id = $id;
+            return "./admin_images";
+        } else {
+            $data['created_at'] = time();
+            db_insert_assoc('cms_images', $data);
+            message('Image saved. Next time you open a page editor, this image will be availble in the "Insert Image" dialog.');
+            $saved_id = db_auto_id();
+            return "./admin_images?sort=age";
+        }
+
+    } 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_images', ADMIN_IMAGES_DB_FIELDS, 'where id=%i', $id);
+    } else {
+        # form not submitted, set default values:
+        $data = array();
+    }
+
+    tem_set('upload_max_filesize', upload_max_filesize());
+
+    tem_set('form', $data);
 }
index 0d5614c..cc23bfc 100644 (file)
 
 <html>
 <head>
-       <title><!--~$title show {~-->~$host~ Admin: <!--~listing {~-->Manage Pages<!--~}~--><!--~form {~--><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--></title>
-       <!--~$head {~-->
-       <script src="inc/ckeditor/ckeditor.js?t=F0RD"></script>
-       <style>
-               /* icon in cke buttons */
-               .cke_button_icon.cke_button__wfpl_images_icon {
-                       background-image: url(/inc/ckeditor/plugins/icons.png?t=F0RD);
-                       background-position: 0 -936px;
-               }
-               .cke_wfpl_images_dialog * {
-                       white-space: normal !important;
-               }
-               .cke_wfpl_images_dialog h3 {
-                       margin-top: 10px;
-                       font-weight: bold;
-                       font-size: 18px;
-               }
-               .cke_wfpl_images_dialog strong {
-                       color: inherit;
-               }
-               .cke_wfpl_images_dialog p {
-                       font-size: 12px;
-                       line-height: 16px;
-               }
-               .cke_wfpl_images_dialog * + p {
-                       padding-top: 5px;
-               }
-               .cke_wfpl_images_dialog * a {
-                       text-decoration: underline;
-                       color: blue;
-               }
-               .cke_wfpl_images_dialog .cke_wfpl_thumbs {
-                       height: 270px;
-                       overflow-y: scroll;
-               }
-               .cke_wfpl_thumbs .cke_wfpl_thumb {
-                       width: 50px;
-                       height: 50px;
-                       padding: 10px;
-                       color: transparent;
-                       font-size: 10px;
-                       font-weight: bold;
-                       display: inline-block;
-                       overflow: hidden;
-                       text-align: center;
-                       background-size: contain;
-                       background-position: 50% 50%;
-                       background-repeat: no-repeat;
-                       background-color: transparent;
-                       border: 2px solid white;
-               }
-               .cke_wfpl_thumbs .cke_wfpl_thumb:hover, .cke_wfpl_thumbs .cke_wfpl_thumb.selected {
-                       color: white;
-                       text-shadow: 1px 1px 2px #000;
-                       box-shadow: 1px 1px 6px #444;
-                       border: 2px solid #444;
-               }
-       </style>
-       <script>
-               window.cke_wfpl_images = {
-                       images: ~wfpl_images_json~,
-                       full_width: ~wfpl_image_width_full~,
-                       small_width: ~wfpl_image_width_small~,
-                       thumb_width: ~wfpl_image_width_thumb~,
-                       next_id: 0,
-                       selected: [],
-                       editors: []
-               };
-               var enc_html = function(str) {
-                       return str.replace(/[<>&]/g, function(i) { return '&#' + i.charCodeAt(0) + ';'; });
-               };
-               function cke_wfpl_images_thumb_click(plugin_id, element, image_id) {
-                       var thumbs = element.parentNode.children;
-                       var i, thumb;
-                       for (i = 0; i < thumbs.length; i++) {
-                               thumb = thumbs[i];
-                               if (thumb === element) {
-                                       if (thumb.className.substr(0, 9) !== 'selected ') {
-                                               thumb.className = 'selected ' + thumb.className;
-                                       }
-                               } else {
-                                       if (thumb.className.substr(0, 9) === 'selected ') {
-                                               thumb.className = thumb.className.substr(9);
-                                       }
-                               }
-                       }
-                       window.cke_wfpl_images.selected[plugin_id] = image_id;
-               }
-               function cke_wfpl_images_insert_click(plugin_id, align) {
-                       var selected = window.cke_wfpl_images.selected[plugin_id];
-                       var editor = window.cke_wfpl_images.editors[plugin_id];
-                       var image;
-                       var code, src, caption;
-                       if (selected == null) {
-                               CKEDITOR.dialog.getCurrent().hide();
-                               return;
-                       }
-                       image = window.cke_wfpl_images.images[selected];
-                       switch(align) {
-                               case 'left':
-                                       code = '<div class="wfpl_li">'
-                               break;
-                               case 'centered':
-                                       code = '<div class="wfpl_ci">'
-                               break;
-                               case 'right':
-                                       code = '<div class="wfpl_ri">'
-                               break;
-                               case 'full':
-                                       code = '<div class="wfpl_fi">'
-                               break;
-                       }
-                       code += '<div class="wfpl_i"'
-                       src =
-                               image.src.substr(0, image.src.length - 4)
-                               + 'w'
-                               + window.cke_wfpl_images[align == 'full' ? 'full_width' : 'small_width']
-                               + image.src.substr(image.src.length - 4);
-                       if (image.caption == '') {
-                               caption = '&nbsp;';
-                       } else {
-                               caption = enc_html(image.caption);
-                       }
-                       code += ' style="background-image: url(/' + src + ');';
-                       code += ' padding-top: ' + image.aspect;
-                       code += '">&nbsp</div>' + caption;
-                       code += '</div>'
-                       CKEDITOR.dialog.getCurrent().hide();
-                       CKEDITOR.currentInstance.insertElement(CKEDITOR.dom.element.createFromHtml(code));
-               }
-               CKEDITOR.plugins.add('wfpl_images', {
-                       init: function (editor) {
-                               var plugin_id = window.cke_wfpl_images.editors.length;
-                               window.cke_wfpl_images.editors.push(editor);
-                               window.cke_wfpl_images.selected.push(window.cke_wfpl_images.images.length > 0 ? 0 : null);
+    <title><!--~$title show {~-->~$host~ Admin: <!--~listing {~-->Manage Pages<!--~}~--><!--~form {~--><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--><!--~}~--><!--~}~--></title>
+    <!--~$head {~-->
+    <script src="inc/ckeditor/ckeditor.js?t=F0RD"></script>
+    <style>
+        /* icon in cke buttons */
+        .cke_button_icon.cke_button__wfpl_images_icon {
+            background-image: url(/inc/ckeditor/plugins/icons.png?t=F0RD);
+            background-position: 0 -936px;
+        }
+        .cke_wfpl_images_dialog * {
+            white-space: normal !important;
+        }
+        .cke_wfpl_images_dialog h3 {
+            margin-top: 10px;
+            font-weight: bold;
+            font-size: 18px;
+        }
+        .cke_wfpl_images_dialog strong {
+            color: inherit;
+        }
+        .cke_wfpl_images_dialog p {
+            font-size: 12px;
+            line-height: 16px;
+        }
+        .cke_wfpl_images_dialog * + p {
+            padding-top: 5px;
+        }
+        .cke_wfpl_images_dialog * a {
+            text-decoration: underline;
+            color: blue;
+        }
+        .cke_wfpl_images_dialog .cke_wfpl_thumbs {
+            height: 270px;
+            overflow-y: scroll;
+        }
+        .cke_wfpl_thumbs .cke_wfpl_thumb {
+            width: 50px;
+            height: 50px;
+            padding: 10px;
+            color: transparent;
+            font-size: 10px;
+            font-weight: bold;
+            display: inline-block;
+            overflow: hidden;
+            text-align: center;
+            background-size: contain;
+            background-position: 50% 50%;
+            background-repeat: no-repeat;
+            background-color: transparent;
+            border: 2px solid white;
+        }
+        .cke_wfpl_thumbs .cke_wfpl_thumb:hover, .cke_wfpl_thumbs .cke_wfpl_thumb.selected {
+            color: white;
+            text-shadow: 1px 1px 2px #000;
+            box-shadow: 1px 1px 6px #444;
+            border: 2px solid #444;
+        }
+    </style>
+    <script>
+        window.cke_wfpl_images = {
+            images: ~wfpl_images_json~,
+            full_width: ~wfpl_image_width_full~,
+            small_width: ~wfpl_image_width_small~,
+            thumb_width: ~wfpl_image_width_thumb~,
+            next_id: 0,
+            selected: [],
+            editors: []
+        };
+        var enc_html = function(str) {
+            return str.replace(/[<>&]/g, function(i) { return '&#' + i.charCodeAt(0) + ';'; });
+        };
+        function cke_wfpl_images_thumb_click(plugin_id, element, image_id) {
+            var thumbs = element.parentNode.children;
+            var i, thumb;
+            for (i = 0; i < thumbs.length; i++) {
+                thumb = thumbs[i];
+                if (thumb === element) {
+                    if (thumb.className.substr(0, 9) !== 'selected ') {
+                        thumb.className = 'selected ' + thumb.className;
+                    }
+                } else {
+                    if (thumb.className.substr(0, 9) === 'selected ') {
+                        thumb.className = thumb.className.substr(9);
+                    }
+                }
+            }
+            window.cke_wfpl_images.selected[plugin_id] = image_id;
+        }
+        function cke_wfpl_images_insert_click(plugin_id, align) {
+            var selected = window.cke_wfpl_images.selected[plugin_id];
+            var editor = window.cke_wfpl_images.editors[plugin_id];
+            var image;
+            var code, src, caption;
+            if (selected == null) {
+                CKEDITOR.dialog.getCurrent().hide();
+                return;
+            }
+            image = window.cke_wfpl_images.images[selected];
+            switch(align) {
+                case 'left':
+                    code = '<div class="wfpl_li">'
+                break;
+                case 'centered':
+                    code = '<div class="wfpl_ci">'
+                break;
+                case 'right':
+                    code = '<div class="wfpl_ri">'
+                break;
+                case 'full':
+                    code = '<div class="wfpl_fi">'
+                break;
+            }
+            code += '<div class="wfpl_i"'
+            src =
+                image.src.substr(0, image.src.length - 4)
+                + 'w'
+                + window.cke_wfpl_images[align == 'full' ? 'full_width' : 'small_width']
+                + image.src.substr(image.src.length - 4);
+            if (image.caption == '') {
+                caption = '&nbsp;';
+            } else {
+                caption = enc_html(image.caption);
+            }
+            code += ' style="background-image: url(/' + src + ');';
+            code += ' padding-top: ' + image.aspect;
+            code += '">&nbsp</div>' + caption;
+            code += '</div>'
+            CKEDITOR.dialog.getCurrent().hide();
+            CKEDITOR.currentInstance.insertElement(CKEDITOR.dom.element.createFromHtml(code));
+        }
+        CKEDITOR.plugins.add('wfpl_images', {
+            init: function (editor) {
+                var plugin_id = window.cke_wfpl_images.editors.length;
+                window.cke_wfpl_images.editors.push(editor);
+                window.cke_wfpl_images.selected.push(window.cke_wfpl_images.images.length > 0 ? 0 : null);
 
-                               editor.addCommand('wfpl_images', new CKEDITOR.dialogCommand('wfpl_images_dialog'));
-                               editor.ui.addButton('wfpl_images', {
-                                       label: 'Insert Image',
-                                       command: 'wfpl_images',
-                                       toolbar: 'insert'
-                               });
-                               CKEDITOR.dialog.add('wfpl_images_dialog', function (api) {
-                                       var i, im, selected, thumbs;
-                                       selected = 'selected ';
-                                       thumbs = '<div class="cke_wfpl_thumbs">'
-                                       for (i in window.cke_wfpl_images.images) {
-                                               im = window.cke_wfpl_images.images[i];
-                                               thumbs += '<div class="'+selected+'cke_wfpl_thumb" onclick="return window.cke_wfpl_images_thumb_click('+plugin_id+', this, '+im.id+')" style="background-image: url('+im.src.substr(0, im.src.length - 4) + 'w' + window.cke_wfpl_images.thumb_width + im.src.substr(im.src.length - 4) + ')">'+ enc_html(im.name.length > 0 ? im.name : im.caption) + '</div>';
-                                               selected = '';
-                                       }
-                                       thumbs += '</div>'
-                                       return {
-                                               title: 'Insert Image',
-                                               minWidth: 700,
-                                               minHeight: 350,
-                                               contents: [
-                                                       {
-                                                               expand: true,
-                                                               padding: 0,
-                                                               elements: [
-                                                                       {
-                                                                               type: 'html',
-                                                                               html: '<div class="cke_wfpl_images_dialog">'
-                                                                                       + '<h3>Step 1: Choose an image to insert:</h3>'
-                                                                                       + thumbs
-                                                                               + '<p>If you\'d like to insert an image not shown above, you can <a href="admin_images?new=1" target="_blank">upload it here</a>. Sorry, it won\'t appear here until you reload this editor page (hit Save below, then "edit this page" again.)</p>'
-                                                                               + '</div>'
-                                                                       }
-                                                               ]
-                                                       }
-                                               ],
-                                               buttons: [
-                                                       {
-                                                               type: 'button',
-                                                               label: 'Insert on Left',
-                                                               className: 'cke_dialog_ui_button_ok',
-                                                               onClick: function() {
-                                                                       cke_wfpl_images_insert_click(plugin_id, 'left');
-                                                               }
-                                                       },
-                                                       {
-                                                               type: 'button',
-                                                               label: 'Insert Centered',
-                                                               className: 'cke_dialog_ui_button_ok',
-                                                               onClick: function() {
-                                                                       cke_wfpl_images_insert_click(plugin_id, 'centered');
-                                                               }
-                                                       },
-                                                       {
-                                                               type: 'button',
-                                                               label: 'Insert on Right',
-                                                               className: 'cke_dialog_ui_button_ok',
-                                                               onClick: function() {
-                                                                       cke_wfpl_images_insert_click(plugin_id, 'right');
-                                                               }
-                                                       },
-                                                       {
-                                                               type: 'button',
-                                                               label: 'Insert BIG',
-                                                               className: 'cke_dialog_ui_button_ok',
-                                                               onClick: function() {
-                                                                       cke_wfpl_images_insert_click(plugin_id, 'full');
-                                                               }
-                                                       },
-                                                       CKEDITOR.dialog.cancelButton
-                                               ]
-                                       };
-                               });
-                       }
-               });
-               function make_wysiwyg(name, bodyid_postfix) {
-                       CKEDITOR.replace(name, {
-                               'contentsCss': 'css.css?m=~css.css mtime~',
-                               'allowedContent': true,
-                               bodyId: '~$basename~' + '_wysiwyg_' + (bodyid_postfix ? bodyid_postfix : name),
-                               'stylesSet': [
-                                       { name: 'Paragraph', element: 'p'},
-                                       { name: 'Page Headline', element: 'h1'},
-                                       { name: 'Section Headline', element: 'h2'},
-                                       { name: 'Subsection Headline', element: 'h3'},
-                                       { name: 'Tagline (under headline)', element: 'h4', attributes: { class: 'tagline'}},
-                                       { name: 'Quote', element: 'p', attributes: { class: 'quote'}},
-                                       { name: 'Quote Author', element: 'p', attributes: { class: 'attrib'}},
-                                       { name: 'div (generic box)', element: 'div'}
-                               ],
-                               'uiColor': '#ccccff',
-                               'removePlugins': 'forms,templates,smiley,pagebreak,save,newpage,preview,print',
-                               'extraPlugins': 'wfpl_images',
-                               'height': '300px',
-                               'toolbar': [
-                                       ['Source'],
-                                       ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'SpellChecker', 'Scayt'],
-                                       ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
-                                       '/',
-                                       ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript'],
-                                       ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
-                                       ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
-                                       ['Link', 'Unlink', 'Anchor'],
-                                       ['wfpl_images', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak'],
-                                       '/',
-                                       ['Styles', 'Font', 'FontSize'],
-                                       ['TextColor', 'BGColor'],
-                                       ['Maximize', 'ShowBlocks']
-                               ]
-                       });
-               }
-               window.admin_pages_cur_layout = null
-               function admin_pages_layout(layout) {
-                       if (layout === undefined) {
-                               layout = document.getElementById('layout').value
-                       }
-                       if (typeof layout === 'string') {
-                               layout = parseInt(layout);
-                       }
-                       if (layout === window.admin_pages_cur_layout) {
-                               return;
-                       }
-                       // hide/show sidebar editor
-                       if (layout === 0) {
-                               document.getElementById('sidebar_editor').style.display = 'none'
-                       } else {
-                               document.getElementById('sidebar_editor').style.display = 'block'
-                       }
-                       // remove existing ckeditors
-                       if (window.admin_pages_cur_layout !== null) {
-                               for (name in CKEDITOR.instances) {
-                                       CKEDITOR.instances[name].destroy();
-                               }
-                       }
-                       // create ckeditors
-                       if (layout === 0) {
-                               make_wysiwyg('content', 'content_full_main');
-                       } else if (layout === 1) {
-                               make_wysiwyg('content', 'content_with_sidebar_main');
-                               make_wysiwyg('sidebar_content', 'content_with_sidebar_sidebar_plain');
-                       } else {
-                               make_wysiwyg('content', 'content_with_sidebar_main');
-                               make_wysiwyg('sidebar_content', 'content_with_sidebar_sidebar_bordered');
-                       }
+                editor.addCommand('wfpl_images', new CKEDITOR.dialogCommand('wfpl_images_dialog'));
+                editor.ui.addButton('wfpl_images', {
+                    label: 'Insert Image',
+                    command: 'wfpl_images',
+                    toolbar: 'insert'
+                });
+                CKEDITOR.dialog.add('wfpl_images_dialog', function (api) {
+                    var i, im, selected, thumbs;
+                    selected = 'selected ';
+                    thumbs = '<div class="cke_wfpl_thumbs">'
+                    for (i in window.cke_wfpl_images.images) {
+                        im = window.cke_wfpl_images.images[i];
+                        thumbs += '<div class="'+selected+'cke_wfpl_thumb" onclick="return window.cke_wfpl_images_thumb_click('+plugin_id+', this, '+im.id+')" style="background-image: url('+im.src.substr(0, im.src.length - 4) + 'w' + window.cke_wfpl_images.thumb_width + im.src.substr(im.src.length - 4) + ')">'+ enc_html(im.name.length > 0 ? im.name : im.caption) + '</div>';
+                        selected = '';
+                    }
+                    thumbs += '</div>'
+                    return {
+                        title: 'Insert Image',
+                        minWidth: 700,
+                        minHeight: 350,
+                        contents: [
+                            {
+                                expand: true,
+                                padding: 0,
+                                elements: [
+                                    {
+                                        type: 'html',
+                                        html: '<div class="cke_wfpl_images_dialog">'
+                                            + '<h3>Step 1: Choose an image to insert:</h3>'
+                                            + thumbs
+                                        + '<p>If you\'d like to insert an image not shown above, you can <a href="admin_images?new=1" target="_blank">upload it here</a>. Sorry, it won\'t appear here until you reload this editor page (hit Save below, then "edit this page" again.)</p>'
+                                        + '</div>'
+                                    }
+                                ]
+                            }
+                        ],
+                        buttons: [
+                            {
+                                type: 'button',
+                                label: 'Insert on Left',
+                                className: 'cke_dialog_ui_button_ok',
+                                onClick: function() {
+                                    cke_wfpl_images_insert_click(plugin_id, 'left');
+                                }
+                            },
+                            {
+                                type: 'button',
+                                label: 'Insert Centered',
+                                className: 'cke_dialog_ui_button_ok',
+                                onClick: function() {
+                                    cke_wfpl_images_insert_click(plugin_id, 'centered');
+                                }
+                            },
+                            {
+                                type: 'button',
+                                label: 'Insert on Right',
+                                className: 'cke_dialog_ui_button_ok',
+                                onClick: function() {
+                                    cke_wfpl_images_insert_click(plugin_id, 'right');
+                                }
+                            },
+                            {
+                                type: 'button',
+                                label: 'Insert BIG',
+                                className: 'cke_dialog_ui_button_ok',
+                                onClick: function() {
+                                    cke_wfpl_images_insert_click(plugin_id, 'full');
+                                }
+                            },
+                            CKEDITOR.dialog.cancelButton
+                        ]
+                    };
+                });
+            }
+        });
+        function make_wysiwyg(name, bodyid_postfix) {
+            CKEDITOR.replace(name, {
+                'contentsCss': 'css.css?m=~css.css mtime~',
+                'allowedContent': true,
+                bodyId: '~$basename~' + '_wysiwyg_' + (bodyid_postfix ? bodyid_postfix : name),
+                'stylesSet': [
+                    { name: 'Paragraph', element: 'p'},
+                    { name: 'Page Headline', element: 'h1'},
+                    { name: 'Section Headline', element: 'h2'},
+                    { name: 'Subsection Headline', element: 'h3'},
+                    { name: 'Tagline (under headline)', element: 'h4', attributes: { class: 'tagline'}},
+                    { name: 'Quote', element: 'p', attributes: { class: 'quote'}},
+                    { name: 'Quote Author', element: 'p', attributes: { class: 'attrib'}},
+                    { name: 'div (generic box)', element: 'div'}
+                ],
+                'uiColor': '#ccccff',
+                'removePlugins': 'forms,templates,smiley,pagebreak,save,newpage,preview,print',
+                'extraPlugins': 'wfpl_images',
+                'height': '300px',
+                'toolbar': [
+                    ['Source'],
+                    ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'SpellChecker', 'Scayt'],
+                    ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
+                    '/',
+                    ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript'],
+                    ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
+                    ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
+                    ['Link', 'Unlink', 'Anchor'],
+                    ['wfpl_images', 'Table', 'HorizontalRule', 'SpecialChar', 'PageBreak'],
+                    '/',
+                    ['Styles', 'Font', 'FontSize'],
+                    ['TextColor', 'BGColor'],
+                    ['Maximize', 'ShowBlocks']
+                ]
+            });
+        }
+        window.admin_pages_cur_layout = null
+        function admin_pages_layout(layout) {
+            if (layout === undefined) {
+                layout = document.getElementById('layout').value
+            }
+            if (typeof layout === 'string') {
+                layout = parseInt(layout);
+            }
+            if (layout === window.admin_pages_cur_layout) {
+                return;
+            }
+            // hide/show sidebar editor
+            if (layout === 0) {
+                document.getElementById('sidebar_editor').style.display = 'none'
+            } else {
+                document.getElementById('sidebar_editor').style.display = 'block'
+            }
+            // remove existing ckeditors
+            if (window.admin_pages_cur_layout !== null) {
+                for (name in CKEDITOR.instances) {
+                    CKEDITOR.instances[name].destroy();
+                }
+            }
+            // create ckeditors
+            if (layout === 0) {
+                make_wysiwyg('content', 'content_full_main');
+            } else if (layout === 1) {
+                make_wysiwyg('content', 'content_with_sidebar_main');
+                make_wysiwyg('sidebar_content', 'content_with_sidebar_sidebar_plain');
+            } else {
+                make_wysiwyg('content', 'content_with_sidebar_main');
+                make_wysiwyg('sidebar_content', 'content_with_sidebar_sidebar_bordered');
+            }
 
-                       window.admin_pages_cur_layout = layout
-               }
-       </script>
-       <!--~}~-->
+            window.admin_pages_cur_layout = layout
+        }
+    </script>
+    <!--~}~-->
 
 </head>
 
 <body>
 <!--~$body show {~-->
 
-       <!--~form {~-->
-               <h1>~$host~ Admin Control Panel</h1>
+    <!--~form {~-->
+        <h1>~$host~ Admin Control Panel</h1>
 
-               <h2><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--></h2>
+        <h2><!--~id unset {~-->Add a new page<!--~}~--><!--~id {~-->Edit page "~title html~"<!--~}~--></h2>
 
-               <!--~archived_versions {~-->
-                       <p><a href="admin_pages?history_page_id=~id~">View archived versions of this page</a></p>
-               <!--~}~-->
+        <!--~archived_versions {~-->
+            <p><a href="admin_pages?history_page_id=~id~">View archived versions of this page</a></p>
+        <!--~}~-->
 
-               <form action="admin_pages" method="post"><!--~id {~--><div style="display: none"><input type="hidden" name="edit_id" value="~id attr~"></div><!--~}~-->
+        <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~" class="wide_field"></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~" class="wide_field"></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 site-wide navigation links (optional)</div>
-                       <div class="field"><select name="navbar"><!--~navbar options~--></select></div>
+            <div class="caption">Show in site-wide navigation links (optional)</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">Page Template/Layout</div>
-                       <div class="field"><select id="layout" name="layout" onchange="return admin_pages_layout()"><!--~layout options~--></select></div>
+            <div class="caption">Page Template/Layout</div>
+            <div class="field"><select id="layout" name="layout" onchange="return admin_pages_layout()"><!--~layout options~--></select></div>
 
-                       <div class="caption">Page Contents</div>
-                       <div class="field_notes">
-                               <ul class="first">
-                                       <li style="color: red; list-style: none">Please read these instructions in full:</li>
-                                       <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 (looks like a clipboard with a "W").</li>
-                                       <li>To make a link, type the text to be clicked, select it, click the "Link" button (looks like a short chain) and paste the web address (where the link should point to) into the "URL" field. Exception: If you're making a link to another page on this site, please remove the "http://~$host~/" from the beginning of the "URL" field and set the "Protocol" to &lt;other&gt;.</li>
-                                       <li>To insert an image: place the cursor at the beginning of a line and click the "insert image" button in the editor. Note that you will only be able to insert images that you have already uploaded on the <a href="admin_images" target="_blank">manage images</a> page.</li>
-                               </ul>
-                       </div>
-                       <div class="field"><textarea class="html_editor" rows="20" cols="50" id="content" name="content">~content html~</textarea></div>
+            <div class="caption">Page Contents</div>
+            <div class="field_notes">
+                <ul class="first">
+                    <li style="color: red; list-style: none">Please read these instructions in full:</li>
+                    <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 (looks like a clipboard with a "W").</li>
+                    <li>To make a link, type the text to be clicked, select it, click the "Link" button (looks like a short chain) and paste the web address (where the link should point to) into the "URL" field. Exception: If you're making a link to another page on this site, please remove the "http://~$host~/" from the beginning of the "URL" field and set the "Protocol" to &lt;other&gt;.</li>
+                    <li>To insert an image: place the cursor at the beginning of a line and click the "insert image" button in the editor. Note that you will only be able to insert images that you have already uploaded on the <a href="admin_images" target="_blank">manage images</a> page.</li>
+                </ul>
+            </div>
+            <div class="field"><textarea class="html_editor" rows="20" cols="50" id="content" name="content">~content html~</textarea></div>
 
-                       <div id="sidebar_editor" style="display: ~sidebar_editor_display~">
-                               <div class="caption">Sidebar Contents</div>
-                               <div class="field_notes">
-                                       <ul class="first">
-                                               <li>Ditto to the notes above "Page Contents" field.</li>
-                                               <li>Centered images appear smaller in this editor than on the real page.</li>
-                                               <li>Don't use the "Insert on Left" and "or Insert on Right" options for images inserting images in this sidebar.</li>
-                                       </ul>
-                               </div>
-                               <div class="field"><textarea class="html_editor" rows="20" cols="50" id="sidebar_content" name="sidebar_content">~sidebar_content html~</textarea></div>
-                       </div>
+            <div id="sidebar_editor" style="display: ~sidebar_editor_display~">
+                <div class="caption">Sidebar Contents</div>
+                <div class="field_notes">
+                    <ul class="first">
+                        <li>Ditto to the notes above "Page Contents" field.</li>
+                        <li>Centered images appear smaller in this editor than on the real page.</li>
+                        <li>Don't use the "Insert on Left" and "or Insert on Right" options for images inserting images in this sidebar.</li>
+                    </ul>
+                </div>
+                <div class="field"><textarea class="html_editor" rows="20" cols="50" id="sidebar_content" name="sidebar_content">~sidebar_content html~</textarea></div>
+            </div>
 
-                       <script>admin_pages_layout()</script>
+            <script>admin_pages_layout()</script>
 
-                       <!--
-                       <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="caption">&nbsp;</div>
-                       <div class="field"><input type="submit" name="save" value="Save"></div>
+            <div class="caption">&nbsp;</div>
+            <div class="field"><input type="submit" name="save" value="Save"></div>
 
-               </form>
+        </form>
 
-               <div class="caption">&nbsp;</div>
-               <div class="field"><a href="~filename nonempty {~~filename attr~~}~~filename empty {~admin_pages~id {~?id=~id~~}~~}~">Cancel</a></div>
-       <!--~}~-->
+        <div class="caption">&nbsp;</div>
+        <div class="field"><a href="~filename nonempty {~~filename attr~~}~~filename empty {~admin_pages~id {~?id=~id~~}~~}~">Cancel</a></div>
+    <!--~}~-->
 
-       <!--~listing {~-->
-               <h1>~$host~ Admin Control Panel</h1>
+    <!--~listing {~-->
+        <h1>~$host~ Admin Control Panel</h1>
 
-               <h2>Manage Pages</h2>
+        <h2>Manage Pages</h2>
 
-               <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
-                       <tr>
-                               <td><em>(new)</em></td>
-                               <td>
-                                       <form style="display: inline-block" action="admin_pages"><input type="hidden" name="new" value="1"><input type="submit" value="create"></form>
-                               </td>
-                       </tr>
-                       <!--~no_home {~-->
-                               <tr>
-                                       <td><em>(home page)</em></td>
-                                       <td>
-                                               <form style="display: inline-block" action="admin_pages">
-                                                       <input type="hidden" name="new" value="1">
-                                                       <input type="hidden" name="new_filename" value="index">
-                                                       <input type="submit" value="create"></form>
-                                       </td>
-                               </tr>
-                       <!--~}~-->
-                       <!--~rows {~-->
-                       <tr>
-                               <td>~title html~<!--~title empty {~--><em>(untitled)</em><!--~}~--></td>
-                               <td>
-                                       <form style="display: inline-block" action="admin_pages"><input type="hidden" name="edit_id" value="~id~"><input type="submit" value="edit"></form>
-                                       <form style="display: inline-block" action="admin_pages"><input type="hidden" name="history_page_id" value="~id~"><input type="submit" value="history"></form>
-                                       <form style="display: inline-block" action="admin_pages" onsubmit="return confirm('Permanently delete?')"><input type="hidden" name="admin_pages_delete_id" value="~id~"><input type="submit" value="delete"></form>
-                               </td>
-                       </tr><!--~}~-->
+        <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
+            <tr>
+                <td><em>(new)</em></td>
+                <td>
+                    <form style="display: inline-block" action="admin_pages"><input type="hidden" name="new" value="1"><input type="submit" value="create"></form>
+                </td>
+            </tr>
+            <!--~no_home {~-->
+                <tr>
+                    <td><em>(home page)</em></td>
+                    <td>
+                        <form style="display: inline-block" action="admin_pages">
+                            <input type="hidden" name="new" value="1">
+                            <input type="hidden" name="new_filename" value="index">
+                            <input type="submit" value="create"></form>
+                    </td>
+                </tr>
+            <!--~}~-->
+            <!--~rows {~-->
+            <tr>
+                <td>~title html~<!--~title empty {~--><em>(untitled)</em><!--~}~--></td>
+                <td>
+                    <form style="display: inline-block" action="admin_pages"><input type="hidden" name="edit_id" value="~id~"><input type="submit" value="edit"></form>
+                    <form style="display: inline-block" action="admin_pages"><input type="hidden" name="history_page_id" value="~id~"><input type="submit" value="history"></form>
+                    <form style="display: inline-block" action="admin_pages" onsubmit="return confirm('Permanently delete?')"><input type="hidden" name="admin_pages_delete_id" value="~id~"><input type="submit" value="delete"></form>
+                </td>
+            </tr><!--~}~-->
 
-               </table>
-       <!--~}~-->
-       <!--~page_history {~-->
-               <h1>~$host~ Admin Control Panel</h1>
+        </table>
+    <!--~}~-->
+    <!--~page_history {~-->
+        <h1>~$host~ Admin Control Panel</h1>
 
-               <h2>Edit history for page "~title html~"</h2>
+        <h2>Edit history for page "~title html~"</h2>
 
-               <!--~rows once_else {~-->
-                       <p>There are no archived versions of this page.</p>
-               <!--~}~-->
-               <!--~rows once_if {~-->
-                       <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
-                               <tr>
-                                       <th>title</th>
-                                       <th>saved at</th>
-                                       <th>by</th>
-                                       <th></th>
-                               </tr>
-                               <!--~rows {~-->
-                                       <tr>
-                                               <td>~title html~<!--~title empty {~--><em>(untitled)</em><!--~}~--></td>
-                                               <td class="timestamp">~timestamp~</td>
-                                               <td>~who html~</td>
-                                               <td>
-                                                       <!--~first {~-->
-                                                               <!--~filename nonempty {~-->
-                                                                       <form style="display: inline-block" action="~filename attr~"><input type="submit" value="view"></form>
-                                                               <!--~}~-->
-                                                               <!--~filename empty {~-->
-                                                                       <form style="display: inline-block" action="admin_pages"><input type="hidden" name="id" value="~page_id~"><input type="submit" value="view"></form>
-                                                               <!--~}~-->
-                                                       <!--~}~-->
-                                                       <!--~first unset {~-->
-                                                               <form style="display: inline-block" action="admin_pages"><input type="hidden" name="history_id" value="~history_id~"><input type="submit" value="view"></form>
-                                                       <!--~}~-->
-                                               </td>
-                                       </tr>
-                               <!--~}~-->
-                               <script>
-                                       (function () {
-                                               var i, i02, d, hours, el, els
-                                               i02 = function (i) { return i > 9 ? i : '0' + i }
-                                               els = document.getElementsByClassName('timestamp');
-                                               for (i = 0; i < els.length; ++i) {
-                                                       el = els[i]
-                                                       d = new Date(parseInt(el.innerText) * 1000)
-                                                       hours = d.getHours();
-                                                       el.innerText =
-                                                               i02(d.getMonth() + 1) + '/' +
-                                                               i02(d.getDate()) + '/' +
-                                                               d.getFullYear() + ' ' +
-                                                               i02((hours + 11) % 12 + 1) + ':' +
-                                                               i02(d.getMinutes()) + '' +
-                                                               (hours < 12 ? 'am' : 'pm')
-                                               }
-                                       })();
-                               </script>
-                       </table>
-               <!--~}~-->
-       <!--~}~-->
+        <!--~rows once_else {~-->
+            <p>There are no archived versions of this page.</p>
+        <!--~}~-->
+        <!--~rows once_if {~-->
+            <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
+                <tr>
+                    <th>title</th>
+                    <th>saved at</th>
+                    <th>by</th>
+                    <th></th>
+                </tr>
+                <!--~rows {~-->
+                    <tr>
+                        <td>~title html~<!--~title empty {~--><em>(untitled)</em><!--~}~--></td>
+                        <td class="timestamp">~timestamp~</td>
+                        <td>~who html~</td>
+                        <td>
+                            <!--~first {~-->
+                                <!--~filename nonempty {~-->
+                                    <form style="display: inline-block" action="~filename attr~"><input type="submit" value="view"></form>
+                                <!--~}~-->
+                                <!--~filename empty {~-->
+                                    <form style="display: inline-block" action="admin_pages"><input type="hidden" name="id" value="~page_id~"><input type="submit" value="view"></form>
+                                <!--~}~-->
+                            <!--~}~-->
+                            <!--~first unset {~-->
+                                <form style="display: inline-block" action="admin_pages"><input type="hidden" name="history_id" value="~history_id~"><input type="submit" value="view"></form>
+                            <!--~}~-->
+                        </td>
+                    </tr>
+                <!--~}~-->
+                <script>
+                    (function () {
+                        var i, i02, d, hours, el, els
+                        i02 = function (i) { return i > 9 ? i : '0' + i }
+                        els = document.getElementsByClassName('timestamp');
+                        for (i = 0; i < els.length; ++i) {
+                            el = els[i]
+                            d = new Date(parseInt(el.innerText) * 1000)
+                            hours = d.getHours();
+                            el.innerText =
+                                i02(d.getMonth() + 1) + '/' +
+                                i02(d.getDate()) + '/' +
+                                d.getFullYear() + ' ' +
+                                i02((hours + 11) % 12 + 1) + ':' +
+                                i02(d.getMinutes()) + '' +
+                                (hours < 12 ? 'am' : 'pm')
+                        }
+                    })();
+                </script>
+            </table>
+        <!--~}~-->
+    <!--~}~-->
 <!--~}~-->
 </body>
 </html>
index ae0fa33..384591d 100644 (file)
@@ -6,264 +6,264 @@ define('ADMIN_PAGES_DB_FIELDS', 'title,filename,navbar,nav_title,layout,content,
 
 
 function format_cms_filename($str) {
-       $str = format_filename($str);
-       $str = str_replace('.', '_', $str);
-       return $str;
+    $str = format_filename($str);
+    $str = str_replace('.', '_', $str);
+    return $str;
 }
 
 
 function admin_pages_get_fields() {
-       $data = array();
-
-       $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['layout'] = format_options(_REQUEST_cut('layout'), 'layout');
-       $data['content'] = format_unix(_REQUEST_cut('content'));
-       if (isset($_REQUEST['sidebar_content'])) { // probs not needed
-               $data['sidebar_content'] = format_unix(_REQUEST_cut('sidebar_content'));
-       }
-       if (isset($_REQUEST['description'])) {
-               $data['description'] = format_unix(_REQUEST_cut('description'));
-       }
-       if (isset($_REQUEST['keywords'])) {
-               $data['keywords'] = format_unix(_REQUEST_cut('keywords'));
-       }
-
-       return $data;
+    $data = array();
+
+    $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['layout'] = format_options(_REQUEST_cut('layout'), 'layout');
+    $data['content'] = format_unix(_REQUEST_cut('content'));
+    if (isset($_REQUEST['sidebar_content'])) { // probs not needed
+        $data['sidebar_content'] = format_unix(_REQUEST_cut('sidebar_content'));
+    }
+    if (isset($_REQUEST['description'])) {
+        $data['description'] = format_unix(_REQUEST_cut('description'));
+    }
+    if (isset($_REQUEST['keywords'])) {
+        $data['keywords'] = format_unix(_REQUEST_cut('keywords'));
+    }
+
+    return $data;
 }
 
 
 function admin_pages_main() {
-       session_auth_must('admin_pages');
-
-       $id = _REQUEST_cut('edit_id');
-       if($id) {
-               return admin_pages_main_form($id);
-       }
-
-       $id = _REQUEST_cut('edit_history_id');
-       if($id) {
-               return admin_pages_main_form(null, $id);
-       }
-
-       $id = _REQUEST_cut('history_page_id');
-       if($id) {
-               return admin_pages_main_page_history($id);
-       }
-
-       $id = _REQUEST_cut('history_id');
-       if($id) {
-               return admin_pages_main_history($id);
-       }
-
-       $id = _REQUEST_cut('admin_pages_delete_id');
-       if($id) {
-               return admin_pages_main_delete($id);
-       }
-
-       if(_REQUEST_cut('new')) {
-               return admin_pages_main_form();
-       }
-
-       if(_REQUEST_cut('list')) {
-               return admin_pages_main_listing();
-       }
-
-       $id = _REQUEST_cut('id');
-       if($id) {
-               return admin_pages_main_display($id);
-       }
-
-       if(isset($_POST['title'])) {
-               return admin_pages_main_form();
-       }
-
-       # default action:
-       return admin_pages_main_listing();
+    session_auth_must('admin_pages');
+
+    $id = _REQUEST_cut('edit_id');
+    if($id) {
+        return admin_pages_main_form($id);
+    }
+
+    $id = _REQUEST_cut('edit_history_id');
+    if($id) {
+        return admin_pages_main_form(null, $id);
+    }
+
+    $id = _REQUEST_cut('history_page_id');
+    if($id) {
+        return admin_pages_main_page_history($id);
+    }
+
+    $id = _REQUEST_cut('history_id');
+    if($id) {
+        return admin_pages_main_history($id);
+    }
+
+    $id = _REQUEST_cut('admin_pages_delete_id');
+    if($id) {
+        return admin_pages_main_delete($id);
+    }
+
+    if(_REQUEST_cut('new')) {
+        return admin_pages_main_form();
+    }
+
+    if(_REQUEST_cut('list')) {
+        return admin_pages_main_listing();
+    }
+
+    $id = _REQUEST_cut('id');
+    if($id) {
+        return admin_pages_main_display($id);
+    }
+
+    if(isset($_POST['title'])) {
+        return admin_pages_main_form();
+    }
+
+    # default action:
+    return admin_pages_main_listing();
 }
 
 # admin-only access to view pages with no filename
 function admin_pages_main_display($id) {
-       $page = db_get_assoc('cms_pages', 'id,title,keywords,description,layout,content,sidebar_content', 'where id=%"', $id);
-       cms_display_content($GLOBALS['wfpl_main_template'], $page);
-       $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_id'] = $id;
+    $page = db_get_assoc('cms_pages', 'id,title,keywords,description,layout,content,sidebar_content', 'where id=%"', $id);
+    cms_display_content($GLOBALS['wfpl_main_template'], $page);
+    $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_id'] = $id;
 }
 
 function admin_pages_main_delete($id) {
-       db_delete('cms_pages', 'where id=%i', $id);
-       message('Page deleted.');
-       return './admin_pages';
+    db_delete('cms_pages', 'where id=%i', $id);
+    message('Page deleted.');
+    return './admin_pages';
 }
 
 # get all images from admin_images (for cms)
 function admin_pages_get_images() {
-       $out = [];
-       $rows = db_get_assocs('cms_images', 'image,name,caption', "order by coalesce(nullif(name, ''), caption), created_at");
-       if ($rows) {
-               $id = -1;
-               foreach($rows as &$row) { $id += 1;
-                       $parts = explode(' ', $row['image'] . '      ', 7);
-                       $out[] = [
-                               'id' => '' . $id,
-                               'src' => $parts[0],
-                               'aspect' => ''.(round(100000 * ((int)$parts[2]) / ((int)$parts[1]) / 1000)).'%',
-                               'name' => $row['name'],
-                               'caption' => $row['caption']
-                       ];
-               } unset($row);
-       }
-       return $out;
+    $out = [];
+    $rows = db_get_assocs('cms_images', 'image,name,caption', "order by coalesce(nullif(name, ''), caption), created_at");
+    if ($rows) {
+        $id = -1;
+        foreach($rows as &$row) { $id += 1;
+            $parts = explode(' ', $row['image'] . '      ', 7);
+            $out[] = [
+                'id' => '' . $id,
+                'src' => $parts[0],
+                'aspect' => ''.(round(100000 * ((int)$parts[2]) / ((int)$parts[1]) / 1000)).'%',
+                'name' => $row['name'],
+                'caption' => $row['caption']
+            ];
+        } unset($row);
+    }
+    return $out;
 }
 
 function admin_pages_main_listing() {
-       $data = array();
-
-       $rows = db_get_assocs('cms_pages', 'id,coalesce(nullif(nav_title,""), title) as title,filename', 'order by coalesce(nullif(nav_title,""), title), filename limit 2000');
-       $have_home_page = false;
-       if (count($rows) !== 0) {
-               $data['rows'] = $rows;
-               foreach ($rows as &$row) {
-                       if ($row['filename'] === 'index') {
-                               $have_home_page = true;
-                               break;
-                       }
-               } unset($row);
-       }
-       if ($have_home_page === false) {
-               $data['no_home'] = true;
-       }
-       tem_set('listing', $data);
+    $data = array();
+
+    $rows = db_get_assocs('cms_pages', 'id,coalesce(nullif(nav_title,""), title) as title,filename', 'order by coalesce(nullif(nav_title,""), title), filename limit 2000');
+    $have_home_page = false;
+    if (count($rows) !== 0) {
+        $data['rows'] = $rows;
+        foreach ($rows as &$row) {
+            if ($row['filename'] === 'index') {
+                $have_home_page = true;
+                break;
+            }
+        } unset($row);
+    }
+    if ($have_home_page === false) {
+        $data['no_home'] = true;
+    }
+    tem_set('listing', $data);
 }
 
 function admin_pages_main_page_history ($id) {
-       $data = array();
-
-       $rows = db_get_assocs('history_cms_pages left join users on history_cms_pages.history_user_id = users.id', 'history_cms_pages.id as page_id,history_cms_pages.history_id,history_cms_pages.filename,coalesce(nullif(history_cms_pages.nav_title,""), history_cms_pages.title) as title,history_when as timestamp,coalesce(nullif(users.name,""), users.username) as who', 'where history_cms_pages.id=%i order by history_id desc', $id);
-       if (count($rows) !== 0) {
-               $data['title'] = $rows[0]['title'];
-               $rows[0]['first'] = true;
-               if ($rows[0]['filename'] === 'index') {
-                       $rows[0]['filename'] = './';
-               }
-               $data['rows'] = $rows;
-       }
-       tem_set('page_history', $data);
+    $data = array();
+
+    $rows = db_get_assocs('history_cms_pages left join users on history_cms_pages.history_user_id = users.id', 'history_cms_pages.id as page_id,history_cms_pages.history_id,history_cms_pages.filename,coalesce(nullif(history_cms_pages.nav_title,""), history_cms_pages.title) as title,history_when as timestamp,coalesce(nullif(users.name,""), users.username) as who', 'where history_cms_pages.id=%i order by history_id desc', $id);
+    if (count($rows) !== 0) {
+        $data['title'] = $rows[0]['title'];
+        $rows[0]['first'] = true;
+        if ($rows[0]['filename'] === 'index') {
+            $rows[0]['filename'] = './';
+        }
+        $data['rows'] = $rows;
+    }
+    tem_set('page_history', $data);
 }
 
 function admin_pages_main_history ($id) {
-       $cms_page = db_get_assoc('history_cms_pages', 'id,title,keywords,description,layout,content,sidebar_content', 'where history_id=%"', $id);
-       if (!$cms_page) {
-               message("Error 9393 please inform developer");
-               return './admin_pages';
-       }
-       message('You are viewing an archived version of this page. To publish this version (revert the page) click the "Edit this page" link at the top, then the "save" at the bottom of the editor page. Feel free to make changes before saving.');
-       cms_display_content($GLOBALS['wfpl_main_template'], $cms_page);
-       $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_id'] = null;
-       $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_history_id'] = $id;
+    $cms_page = db_get_assoc('history_cms_pages', 'id,title,keywords,description,layout,content,sidebar_content', 'where history_id=%"', $id);
+    if (!$cms_page) {
+        message("Error 9393 please inform developer");
+        return './admin_pages';
+    }
+    message('You are viewing an archived version of this page. To publish this version (revert the page) click the "Edit this page" link at the top, then the "save" at the bottom of the editor page. Feel free to make changes before saving.');
+    cms_display_content($GLOBALS['wfpl_main_template'], $cms_page);
+    $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_id'] = null;
+    $GLOBALS['wfpl_main_template']->data['$admin_links']['$edit_page_history_id'] = $id;
 }
 
 function admin_pages_main_form($id = false, $history_id = false) {
-       if ($history_id) {
-               message('The fields below have been filled with an archived version of this page. To publish this version (revert the page) click "save" button at the bottom. Feel free to make changes before saving.');
-               $history_data = db_get_assoc('history_cms_pages', 'id,'.ADMIN_PAGES_DB_FIELDS, 'where history_id=%i', $history_id);
-               if (!$history_data) {
-                       message("Error 3938 please inform developer");
-                       return './admin_pages';
-               }
-               $id = $history_data['id'];
-       } elseif ($id) {
-               if (db_count('history_cms_pages', 'where id=%i', $id) > 1) {
-                       tem_set('archived_versions');
-               }
-       }
-       if($id) {
-               tem_set('id', $id);
-       }
-
-       tem_set('$basename', 'admin_pages');
-
-       pulldown('layout', [
-               ['0', "Full (no sidebar)"],
-               ['1', "With Plain Sidebar"],
-               ['2', "With Bordered Sidebar"]
-       ]);
-
-       $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 != $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', $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;
-               }
-
-               # save
-               if($id) {
-                       db_update_assoc('cms_pages', $data, 'where id=%i', $id);
-                       message('Page updated.');
-               } else {
-                       db_insert_assoc('cms_pages', $data);
-                       $id = db_auto_id();
-                       message('Page saved.');
-               }
-
-               # save to version history
-               $data['id'] = $id;
-               $data['history_when'] = time();
-               $s = session_auth();
-               $data['history_user_id'] = $s['id'];
-               db_insert_assoc('history_cms_pages', $data);
-
-               # redirect
-               if ($data['filename'] === 'index') {
-                       return './';
-               } elseif($data['filename'] !== '') {
-                       return "./{$data['filename']}";
-               } else {
-                       return "./admin_pages?id=$id";
-               }
-       } elseif($id) {
-               # we've recieved an edit id, but no data. So we grab the values to be edited from the database
-               if ($history_id) {
-                       $data = $history_data;
-               } else {
-                       $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, set default values:
-               $data = array('filename' => format_cms_filename($_REQUEST['new_filename']));
-       }
-
-       if (!isset($data['layout']) || $data['layout'] === '' || $data['layout'] === '0') {
-               $data['sidebar_editor_display'] = 'none';
-       } else {
-               $data['sidebar_editor_display'] = 'block';
-       }
-
-       tem_set('wfpl_images_json', json_encode(admin_pages_get_images()));
-       tem_set('wfpl_image_width_full', WFPL_IMAGE_WIDTH_FULL);
-       tem_set('wfpl_image_width_small', WFPL_IMAGE_WIDTH_SMALL);
-       tem_set('wfpl_image_width_thumb', WFPL_IMAGE_WIDTH_THUMB);
-       tem_set('form', $data);
-       tem_set('$head'); # wysiwyg init goes in <head>
+    if ($history_id) {
+        message('The fields below have been filled with an archived version of this page. To publish this version (revert the page) click "save" button at the bottom. Feel free to make changes before saving.');
+        $history_data = db_get_assoc('history_cms_pages', 'id,'.ADMIN_PAGES_DB_FIELDS, 'where history_id=%i', $history_id);
+        if (!$history_data) {
+            message("Error 3938 please inform developer");
+            return './admin_pages';
+        }
+        $id = $history_data['id'];
+    } elseif ($id) {
+        if (db_count('history_cms_pages', 'where id=%i', $id) > 1) {
+            tem_set('archived_versions');
+        }
+    }
+    if($id) {
+        tem_set('id', $id);
+    }
+
+    tem_set('$basename', 'admin_pages');
+
+    pulldown('layout', [
+        ['0', "Full (no sidebar)"],
+        ['1', "With Plain Sidebar"],
+        ['2', "With Bordered Sidebar"]
+    ]);
+
+    $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 != $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', $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;
+        }
+
+        # save
+        if($id) {
+            db_update_assoc('cms_pages', $data, 'where id=%i', $id);
+            message('Page updated.');
+        } else {
+            db_insert_assoc('cms_pages', $data);
+            $id = db_auto_id();
+            message('Page saved.');
+        }
+
+        # save to version history
+        $data['id'] = $id;
+        $data['history_when'] = time();
+        $s = session_auth();
+        $data['history_user_id'] = $s['id'];
+        db_insert_assoc('history_cms_pages', $data);
+
+        # redirect
+        if ($data['filename'] === 'index') {
+            return './';
+        } elseif($data['filename'] !== '') {
+            return "./{$data['filename']}";
+        } else {
+            return "./admin_pages?id=$id";
+        }
+    } elseif($id) {
+        # we've recieved an edit id, but no data. So we grab the values to be edited from the database
+        if ($history_id) {
+            $data = $history_data;
+        } else {
+            $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, set default values:
+        $data = array('filename' => format_cms_filename($_REQUEST['new_filename']));
+    }
+
+    if (!isset($data['layout']) || $data['layout'] === '' || $data['layout'] === '0') {
+        $data['sidebar_editor_display'] = 'none';
+    } else {
+        $data['sidebar_editor_display'] = 'block';
+    }
+
+    tem_set('wfpl_images_json', json_encode(admin_pages_get_images()));
+    tem_set('wfpl_image_width_full', WFPL_IMAGE_WIDTH_FULL);
+    tem_set('wfpl_image_width_small', WFPL_IMAGE_WIDTH_SMALL);
+    tem_set('wfpl_image_width_thumb', WFPL_IMAGE_WIDTH_THUMB);
+    tem_set('form', $data);
+    tem_set('$head'); # wysiwyg init goes in <head>
 }
index 5c6caad..fd764d2 100644 (file)
@@ -2,85 +2,85 @@
 
 <html lang="en">
 <head>
-       <meta charset="utf-8" />
-       <title><!--~$title show {~-->~$host~ Admin: Manage Accounts<!--~}~--></title>
+    <meta charset="utf-8" />
+    <title><!--~$title show {~-->~$host~ Admin: Manage Accounts<!--~}~--></title>
 </head>
 
 <body>
 <!--~$body show {~-->
 
-       <!--~form {~-->
-               <h1>~$host~ Admin Control Panel</h1>
-
-               <h2><!--~id unset {~-->Add a new account<!--~}~--><!--~id {~-->Edit account "~name html~"<!--~}~--></h2>
-
-               <form action="admin_users" method="post"><!--~id {~--><div style="display: none"><input type="hidden" name="edit_id" value="~id attr~"></div><!--~}~-->
-
-                       <div class="caption">Role</div>
-                       <div class="field"><select name="role"><!--~role options~--></select></div>
-
-                       <div class="caption">Name (optional)</div>
-                       <div class="field"><input type="text" name="name" value="~name attr~"></div>
-
-                       <div class="caption">Username</div>
-                       <div class="field_notes">This is used to log in. It is not case sensitive, and symbols/spaces/etc are ignored.</div>
-                       <div class="field~username_bad {~ field_error~}~"><input type="text" name="username" value="~username attr~"></div>
-
-                       <div class="caption">Password</div>
-                       <!--~id unset {~--><div class="field_notes">If this is left blank, the user will be unable to log in.</div><!--~}~-->
-                       <!--~id {~--><div class="field_notes">Leave this blank to leave the password unchanged.</div><!--~}~-->
-                       <div class="field_notes">Password suggestions: ~password_suggestions {~<code class="password_suggestion">~password_suggestions html~</code>~ sep {~ ~}~~}~</div>
-                       <div class="field~password_bad {~ field_error~}~">
-                               <input type="password" name="pass1" value=""><br>
-                               <input type="password" name="pass2" value="">
-                       </div>
-
-                       <div class="caption"></div>
-                       <div class="field"><input type="submit" name="save" value="Save"></div>
-
-               </form>
-
-               <div class="caption">&nbsp;</div>
-               <div class="field"><a href="admin_users~id {~?id=~id~~}~">Cancel</a></div>
-       <!--~}~-->
-
-       <!--~listings {~-->
-               <h1>~$host~ Admin Control Panel</h1>
-
-               <h2>Manage Accounts</h2>
-
-               <p>On this page you can manage who can log into this site, and what sort of things they have permission to do once logged in.</p>
-
-               <!--~rows once_if {~-->
-                       <p><a href="admin_users?new=1">[Add a new account]</a></p>
-
-                       <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
-                               <tr>
-                                       <th><a href="?sort=~sorting-by-role~role">Role</a></th>
-                                       <th><a href="?sort=~sorting-by-name~name">Name</a></th>
-                                       <th><a href="?sort=~sorting-by-username~username">Username</a></th>
-                                       <th><a href="?sort=~sorting-by-last_login~last_login">Last Login</a></th>
-                                       <th><a href="?sort=~sorting-by-last_active~last_active">Last Active</a></th>
-                                       <th>&nbsp;</th>
-                               </tr><!--~rows {~-->
-                               <tr>
-                                       <td class="listing"><a href="admin_users?edit_id=~id~">~role html~<!--~role empty {~--><em>(blank)</em><!--~}~--></a></td>
-                                       <td class="listing"><a href="admin_users?edit_id=~id~">~name html~<!--~name empty {~--><em>(blank)</em><!--~}~--></a></td>
-                                       <td class="listing"><a href="admin_users?edit_id=~id~">~username html~<!--~username empty {~--><em>(blank)</em><!--~}~--></a></td>
-                                       <td class="listing"><a href="admin_users?edit_id=~id~" class="unix_date">~last_login html~</a></td>
-                                       <td class="listing"><a href="admin_users?edit_id=~id~" class="unix_time">~last_active html~</a></td>
-                                       <td><a href="admin_users?admin_users_delete_id=~id~" onclick="return confirm('Permanently delete?')">[delete this account]</a></td>
-                               </tr><!--~}~-->
-
-                       </table>
-                       <p><a href="?download_csv=1">Download as CSV file</a></p>
-               <!--~}~-->
-               <!--~rows once_else {~-->
-                       <p>No accounts in database.</p>
-               <!--~}~-->
-
-               <p><a href="admin_users?new=1">[Add a new account]</a></p>
-       <!--~}~-->
+    <!--~form {~-->
+        <h1>~$host~ Admin Control Panel</h1>
+
+        <h2><!--~id unset {~-->Add a new account<!--~}~--><!--~id {~-->Edit account "~name html~"<!--~}~--></h2>
+
+        <form action="admin_users" method="post"><!--~id {~--><div style="display: none"><input type="hidden" name="edit_id" value="~id attr~"></div><!--~}~-->
+
+            <div class="caption">Role</div>
+            <div class="field"><select name="role"><!--~role options~--></select></div>
+
+            <div class="caption">Name (optional)</div>
+            <div class="field"><input type="text" name="name" value="~name attr~"></div>
+
+            <div class="caption">Username</div>
+            <div class="field_notes">This is used to log in. It is not case sensitive, and symbols/spaces/etc are ignored.</div>
+            <div class="field~username_bad {~ field_error~}~"><input type="text" name="username" value="~username attr~"></div>
+
+            <div class="caption">Password</div>
+            <!--~id unset {~--><div class="field_notes">If this is left blank, the user will be unable to log in.</div><!--~}~-->
+            <!--~id {~--><div class="field_notes">Leave this blank to leave the password unchanged.</div><!--~}~-->
+            <div class="field_notes">Password suggestions: ~password_suggestions {~<code class="password_suggestion">~password_suggestions html~</code>~ sep {~ ~}~~}~</div>
+            <div class="field~password_bad {~ field_error~}~">
+                <input type="password" name="pass1" value=""><br>
+                <input type="password" name="pass2" value="">
+            </div>
+
+            <div class="caption"></div>
+            <div class="field"><input type="submit" name="save" value="Save"></div>
+
+        </form>
+
+        <div class="caption">&nbsp;</div>
+        <div class="field"><a href="admin_users~id {~?id=~id~~}~">Cancel</a></div>
+    <!--~}~-->
+
+    <!--~listings {~-->
+        <h1>~$host~ Admin Control Panel</h1>
+
+        <h2>Manage Accounts</h2>
+
+        <p>On this page you can manage who can log into this site, and what sort of things they have permission to do once logged in.</p>
+
+        <!--~rows once_if {~-->
+            <p><a href="admin_users?new=1">[Add a new account]</a></p>
+
+            <table cellspacing="0" cellpadding="4" border="0" summary="" class="evenodd">
+                <tr>
+                    <th><a href="?sort=~sorting-by-role~role">Role</a></th>
+                    <th><a href="?sort=~sorting-by-name~name">Name</a></th>
+                    <th><a href="?sort=~sorting-by-username~username">Username</a></th>
+                    <th><a href="?sort=~sorting-by-last_login~last_login">Last Login</a></th>
+                    <th><a href="?sort=~sorting-by-last_active~last_active">Last Active</a></th>
+                    <th>&nbsp;</th>
+                </tr><!--~rows {~-->
+                <tr>
+                    <td class="listing"><a href="admin_users?edit_id=~id~">~role html~<!--~role empty {~--><em>(blank)</em><!--~}~--></a></td>
+                    <td class="listing"><a href="admin_users?edit_id=~id~">~name html~<!--~name empty {~--><em>(blank)</em><!--~}~--></a></td>
+                    <td class="listing"><a href="admin_users?edit_id=~id~">~username html~<!--~username empty {~--><em>(blank)</em><!--~}~--></a></td>
+                    <td class="listing"><a href="admin_users?edit_id=~id~" class="unix_date">~last_login html~</a></td>
+                    <td class="listing"><a href="admin_users?edit_id=~id~" class="unix_time">~last_active html~</a></td>
+                    <td><a href="admin_users?admin_users_delete_id=~id~" onclick="return confirm('Permanently delete?')">[delete this account]</a></td>
+                </tr><!--~}~-->
+
+            </table>
+            <p><a href="?download_csv=1">Download as CSV file</a></p>
+        <!--~}~-->
+        <!--~rows once_else {~-->
+            <p>No accounts in database.</p>
+        <!--~}~-->
+
+        <p><a href="admin_users?new=1">[Add a new account]</a></p>
+    <!--~}~-->
 
 <!--~}~-->
 </body>
index 9e4a753..1c17673 100644 (file)
@@ -20,170 +20,170 @@ define('ADMIN_USERS_DB_FIELDS', 'role,name,username,last_login,last_active');
 require_once(__DIR__.'/'.'inc/wfpl/format.php');
 
 $GLOBALS['admin_users_field_to_caption'] = array(
-       'name' => 'Name',
-       'role' => 'Role',
-       'username' => 'Username',
-       'password' => 'Password',
-       'last_login' => 'Last Login',
-       'last_active' => 'Last Active'
+    'name' => 'Name',
+    'role' => 'Role',
+    'username' => 'Username',
+    'password' => 'Password',
+    'last_login' => 'Last Login',
+    'last_active' => 'Last Active'
 );
 
 function admin_users_get_fields() {
-       $data = array();
+    $data = array();
 
-       $data['role'] = format_options(_REQUEST_cut('role'), 'role');
-       $data['name'] = format_oneline(trim(_REQUEST_cut('name')));
-       $data['username'] = format_auth_username(trim(_REQUEST_cut('username')));
-       $data['pass1'] = format_oneline(trim(_REQUEST_cut('pass1')));
-       $data['pass2'] = format_oneline(trim(_REQUEST_cut('pass2')));
+    $data['role'] = format_options(_REQUEST_cut('role'), 'role');
+    $data['name'] = format_oneline(trim(_REQUEST_cut('name')));
+    $data['username'] = format_auth_username(trim(_REQUEST_cut('username')));
+    $data['pass1'] = format_oneline(trim(_REQUEST_cut('pass1')));
+    $data['pass2'] = format_oneline(trim(_REQUEST_cut('pass2')));
 
-       return $data;
+    return $data;
 }
 
 
 function admin_users_main() {
-       session_auth_must('admin_users');
+    session_auth_must('admin_users');
 
-       $id = _REQUEST_cut('edit_id');
-       if ($id) {
-               return admin_users_main_form($id);
-       }
+    $id = _REQUEST_cut('edit_id');
+    if ($id) {
+        return admin_users_main_form($id);
+    }
 
-       $id = _REQUEST_cut('admin_users_delete_id');
-       if ($id) {
-               return admin_users_main_delete($id);
-       }
+    $id = _REQUEST_cut('admin_users_delete_id');
+    if ($id) {
+        return admin_users_main_delete($id);
+    }
 
-       if (_REQUEST_cut('new')) {
-               return admin_users_main_form();
-       }
+    if (_REQUEST_cut('new')) {
+        return admin_users_main_form();
+    }
 
-       if (_REQUEST_cut('list')) {
-               return admin_users_main_listing();
-       }
+    if (_REQUEST_cut('list')) {
+        return admin_users_main_listing();
+    }
 
-       if (_REQUEST_cut('download_csv')) {
-               return admin_users_csv_download();
-       }
+    if (_REQUEST_cut('download_csv')) {
+        return admin_users_csv_download();
+    }
 
-       if (isset($_POST['name'])) {
-               return admin_users_main_form();
-       }
+    if (isset($_POST['name'])) {
+        return admin_users_main_form();
+    }
 
-       # default action:
-       return admin_users_main_listing();
+    # default action:
+    return admin_users_main_listing();
 }
 
 function admin_users_main_delete($id) {
-       db_delete('users', 'where id=%i', $id);
-       message('Account deleted.');
-       return './admin_users';
+    db_delete('users', 'where id=%i', $id);
+    message('Account deleted.');
+    return './admin_users';
 }
 
 function admin_users_csv_download() {
-       require_once(__DIR__.'/'.'inc/wfpl/csv.php');
-       $rows = db_get_rows('users', 'id,'.ADMIN_USERS_DB_FIELDS, 'order by id');
-       $fields = explode(',', 'id,'.ADMIN_USERS_DB_FIELDS);
-       $header = array();
-       foreach ($fields as $field) {
-               if (isset($GLOBALS['admin_users_field_to_caption'][$field])) {
-                       $header[] = $GLOBALS['admin_users_field_to_caption'][$field];
-               } else {
-                       $header[] = $field;
-               }
-       }
-       array_unshift($rows, $header);
-       array2d_to_csv_download($rows, 'admin_users.csv');
+    require_once(__DIR__.'/'.'inc/wfpl/csv.php');
+    $rows = db_get_rows('users', 'id,'.ADMIN_USERS_DB_FIELDS, 'order by id');
+    $fields = explode(',', 'id,'.ADMIN_USERS_DB_FIELDS);
+    $header = array();
+    foreach ($fields as $field) {
+        if (isset($GLOBALS['admin_users_field_to_caption'][$field])) {
+            $header[] = $GLOBALS['admin_users_field_to_caption'][$field];
+        } else {
+            $header[] = $field;
+        }
+    }
+    array_unshift($rows, $header);
+    array2d_to_csv_download($rows, 'admin_users.csv');
 }
 
 function admin_users_main_listing() {
-       $data = array();
-       $desc = '';
-       $sort = _REQUEST_cut('sort');
-       if ($sort && substr($sort, 0, 1) === '-') {
-               $sort = substr($sort, 1);
-               $desc = ' DESC ';
-       } else {
-               $data["sorting-by-$sort"] = '-';
-       }
-       $legal_sorts = explode(',', ADMIN_USERS_DB_FIELDS);
-       if (!$sort || !in_array($sort, $legal_sorts)) {
-               $sort = 'role, name';
-       }
-
-       $data['rows'] = db_get_assocs('users', 'id,role,name,username,last_login,last_active', "order by $sort $desc limit 1000");
-       tem_set('listings', $data);
-       render_timestamps();
+    $data = array();
+    $desc = '';
+    $sort = _REQUEST_cut('sort');
+    if ($sort && substr($sort, 0, 1) === '-') {
+        $sort = substr($sort, 1);
+        $desc = ' DESC ';
+    } else {
+        $data["sorting-by-$sort"] = '-';
+    }
+    $legal_sorts = explode(',', ADMIN_USERS_DB_FIELDS);
+    if (!$sort || !in_array($sort, $legal_sorts)) {
+        $sort = 'role, name';
+    }
+
+    $data['rows'] = db_get_assocs('users', 'id,role,name,username,last_login,last_active', "order by $sort $desc limit 1000");
+    tem_set('listings', $data);
+    render_timestamps();
 }
 
 function admin_users_suggested_password() {
-       $character_set = "ABCDEFHJKLMNPQRTUWXY34789"; # removed all similar-looking characters
-       $code = "          ";
+    $character_set = "ABCDEFHJKLMNPQRTUWXY34789"; # removed all similar-looking characters
+    $code = "          ";
 
-       # PHP 4.2.0 and up seed the random number generator for you.
-       # Lets hope that it seeds with something harder to guess than the clock.
-       for($i = 0; $i < 10; ++$i) {
-               $code{$i} = $character_set{mt_rand(0, 24)}; # inclusive
-       }
+    # PHP 4.2.0 and up seed the random number generator for you.
+    # Lets hope that it seeds with something harder to guess than the clock.
+    for($i = 0; $i < 10; ++$i) {
+        $code{$i} = $character_set{mt_rand(0, 24)}; # inclusive
+    }
 
-       return $code;
+    return $code;
 }
 
 function admin_users_main_form($id = false) {
-       if ($id) {
-               tem_set('id', $id);
-       }
-
-       pulldown('role', [
-               ['admin', 'Site Administrator'],
-               ['disabled', 'Account Disabled']
-       ]);
-
-       if (isset($_POST['name'])) {
-               $data = admin_users_get_fields();
-
-               if (strlen($data['username']) < 1) {
-                       message("Oop, Username is required");
-                       $data['username_bad'] = true;
-               } elseif ($data['pass1'] !== $data['pass2']) {
-                       message("Oop, passwords didn't match. Please enter your desired password carefully (twice).");
-                       $data['password_bad'] = true;
-               } else {
-                       # password hash is slow, so only do it if we're really doing a db write
-                       if (isset($data['pass1']) && strlen($data['pass1']) > 0) {
-                               # hash password for db storage
-                               if (!function_exists('password_hash')) {
-                                       require_once(__DIR__.'/'.'inc/password_funcs_backported.php');
-                               }
-                               $data['password'] = password_hash($data['pass1'], PASSWORD_DEFAULT);
-                       }
-                       unset($data['pass1']);
-                       unset($data['pass2']);
-                       if ($id) {
-                               db_update_assoc('users', $data, 'where id=%i', $id);
-                               message('Account updated.');
-                       } else {
-                               db_insert_assoc('users', $data);
-                               message('Account saved.');
-                       }
-                       return './admin_users';
-               }
-               # else fall through to display the form again. Field values are in $data
-       } 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('users', ADMIN_USERS_DB_FIELDS, 'where id=%i', $id);
-       } else {
-               # form not submitted, you can set default values like so:
-               #$data = array('name' => 'Yes');
-               $data = array();
-       }
-
-       tem_set('password_suggestions', [
-               admin_users_suggested_password(),
-               admin_users_suggested_password(),
-               admin_users_suggested_password(),
-               admin_users_suggested_password(),
-               admin_users_suggested_password()
-       ]);
-       tem_set('form', $data);
+    if ($id) {
+        tem_set('id', $id);
+    }
+
+    pulldown('role', [
+        ['admin', 'Site Administrator'],
+        ['disabled', 'Account Disabled']
+    ]);
+
+    if (isset($_POST['name'])) {
+        $data = admin_users_get_fields();
+
+        if (strlen($data['username']) < 1) {
+            message("Oop, Username is required");
+            $data['username_bad'] = true;
+        } elseif ($data['pass1'] !== $data['pass2']) {
+            message("Oop, passwords didn't match. Please enter your desired password carefully (twice).");
+            $data['password_bad'] = true;
+        } else {
+            # password hash is slow, so only do it if we're really doing a db write
+            if (isset($data['pass1']) && strlen($data['pass1']) > 0) {
+                # hash password for db storage
+                if (!function_exists('password_hash')) {
+                    require_once(__DIR__.'/'.'inc/password_funcs_backported.php');
+                }
+                $data['password'] = password_hash($data['pass1'], PASSWORD_DEFAULT);
+            }
+            unset($data['pass1']);
+            unset($data['pass2']);
+            if ($id) {
+                db_update_assoc('users', $data, 'where id=%i', $id);
+                message('Account updated.');
+            } else {
+                db_insert_assoc('users', $data);
+                message('Account saved.');
+            }
+            return './admin_users';
+        }
+        # else fall through to display the form again. Field values are in $data
+    } 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('users', ADMIN_USERS_DB_FIELDS, 'where id=%i', $id);
+    } else {
+        # form not submitted, you can set default values like so:
+        #$data = array('name' => 'Yes');
+        $data = array();
+    }
+
+    tem_set('password_suggestions', [
+        admin_users_suggested_password(),
+        admin_users_suggested_password(),
+        admin_users_suggested_password(),
+        admin_users_suggested_password(),
+        admin_users_suggested_password()
+    ]);
+    tem_set('form', $data);
 }
index 0d3e667..8c98519 100644 (file)
@@ -4,72 +4,72 @@ require_once(__DIR__.'/'.'config.php');
 require_once(__DIR__.'/'.'inc/wfpl/upload.php');
 
 function cms_images_autoresize_main_abort_404() {
-       http_response_code('404');
-       header('HTTP/1.0 404 File Not Found');
-       header('Content-Type: text/plain');
-       print('404: File not found');
-       exit();
+    http_response_code('404');
+    header('HTTP/1.0 404 File Not Found');
+    header('Content-Type: text/plain');
+    print('404: File not found');
+    exit();
 }
 
 function cms_images_autoresize_main() {
-       # figure out what file was requested
-       $out_fn = $_SERVER['REDIRECT_URL'];
-       $out_fn = preg_replace('|[?].*|', '', $out_fn); # apache 2.4.17
-       $out_fn = preg_replace('|.*/|', '', $out_fn);
-       $matches = array();
-       if (!preg_match('/^([0-9a-f]+)w([0-9]+)[.](png|jpg)$/', $out_fn, $matches)) {
-               cms_images_autoresize_main_abort_404();
-       }
+    # figure out what file was requested
+    $out_fn = $_SERVER['REDIRECT_URL'];
+    $out_fn = preg_replace('|[?].*|', '', $out_fn); # apache 2.4.17
+    $out_fn = preg_replace('|.*/|', '', $out_fn);
+    $matches = array();
+    if (!preg_match('/^([0-9a-f]+)w([0-9]+)[.](png|jpg)$/', $out_fn, $matches)) {
+        cms_images_autoresize_main_abort_404();
+    }
 
-       $basename = $matches[1];
-       $width = (int)$matches[2];
-       $ext = $matches[3];
-       $in_fn = "$basename.$ext";
-       $in_path = __DIR__.'/'.'cms_images/' . $in_fn;
-       $out_path = __DIR__.'/'.'cms_images/' . $out_fn;
-       $lock_path = $out_path . '.lock';
+    $basename = $matches[1];
+    $width = (int)$matches[2];
+    $ext = $matches[3];
+    $in_fn = "$basename.$ext";
+    $in_path = __DIR__.'/'.'cms_images/' . $in_fn;
+    $out_path = __DIR__.'/'.'cms_images/' . $out_fn;
+    $lock_path = $out_path . '.lock';
 
-       if (!in_array($width, $GLOBALS['wfpl_image_widths'], true)) {
-               cms_images_autoresize_main_abort_404();
-       }
+    if (!in_array($width, $GLOBALS['wfpl_image_widths'], true)) {
+        cms_images_autoresize_main_abort_404();
+    }
 
-       if (!file_exists($in_path)) {
-               cms_images_autoresize_main_abort_404();
-       }
+    if (!file_exists($in_path)) {
+        cms_images_autoresize_main_abort_404();
+    }
 
-       @$lock = fopen($lock_path, 'x');
-       if (!$lock) {
-               # delete lock file if it's stale
-               $s = stat($lock_path);
-               if ($s && $s['mtime'] + 3 < time()) {
-                       unlink($lock_path);
-               } else {
-                       # if it's fresh, exit with temporary error
-                       header('HTTP/1.0 503 Service Unavailable');
-                       header('Content-Type: text/plain');
-                       header('Retry-After: 4');
-                       print("503 Service Unavailable (try again soon)\n");
-                       var_dump($s);
-                       var_dump(time());
-                       exit();
-               }
-       }
+    @$lock = fopen($lock_path, 'x');
+    if (!$lock) {
+        # delete lock file if it's stale
+        $s = stat($lock_path);
+        if ($s && $s['mtime'] + 3 < time()) {
+            unlink($lock_path);
+        } else {
+            # if it's fresh, exit with temporary error
+            header('HTTP/1.0 503 Service Unavailable');
+            header('Content-Type: text/plain');
+            header('Retry-After: 4');
+            print("503 Service Unavailable (try again soon)\n");
+            var_dump($s);
+            var_dump(time());
+            exit();
+        }
+    }
 
-       imagemagick_convert($in_path, $out_path,
-               '-geometry '
-               . $width
-               . 'x'
-               . ($width * 2)
-               . "'>'"
-       );
+    imagemagick_convert($in_path, $out_path,
+        '-geometry '
+        . $width
+        . 'x'
+        . ($width * 2)
+        . "'>'"
+    );
 
-       # done! kill the lock
-       fclose($lock);
-       unlink($lock_path);
+    # done! kill the lock
+    fclose($lock);
+    unlink($lock_path);
 
-       if (!headers_sent()) {
-               header('Content-Type: ' . ($ext = 'jpg' ? 'image/jpeg' : 'image/png'));
-               readfile($out_path);
-       }
+    if (!headers_sent()) {
+        header('Content-Type: ' . ($ext = 'jpg' ? 'image/jpeg' : 'image/png'));
+        readfile($out_path);
+    }
 }
 cms_images_autoresize_main();
index 8a2bc85..1c916a3 100644 (file)
@@ -15,9 +15,9 @@ define('WFPL_IMAGE_WIDTH_FULL',  WFPL_SITE_WIDTH);
 define('WFPL_IMAGE_WIDTH_SMALL', 250); # "sidebar_width" in style.styl
 define('WFPL_IMAGE_WIDTH_THUMB',  70);
 $GLOBALS['wfpl_image_widths'] = array(
-       WFPL_IMAGE_WIDTH_FULL,
-       WFPL_IMAGE_WIDTH_SMALL,
-       WFPL_IMAGE_WIDTH_THUMB
+    WFPL_IMAGE_WIDTH_FULL,
+    WFPL_IMAGE_WIDTH_SMALL,
+    WFPL_IMAGE_WIDTH_THUMB
 );
 
 # Enable features, auto-includes
@@ -38,23 +38,23 @@ db_upgrade();
 
 # paypal_ipn.php calls these when it receives a valid payment
 $GLOBALS['payment_handlers'] = [
-       # the key (below) must be the first word in the paypal variable "custom"
-       # the file will be run with wfpl's file_run()
-       # example:
-       #'membership' => __DIR__.'/'.'inc/payment_membership.php'
+    # the key (below) must be the first word in the paypal variable "custom"
+    # the file will be run with wfpl's file_run()
+    # example:
+    #'membership' => __DIR__.'/'.'inc/payment_membership.php'
 ];
 
 $GLOBALS['email_templates'] = [
-       'backend_bug' => [
-               'title' => "Notification for site programmer(s)",
-               'description' => "This email template is used if/when the back-end code of this site encounters an unusual/suspicious situation that it's not sure how to cope with.",
-               'variables' => [
-                       ['details', "details about the unusual/suspicious situation"]
-               ],
-               'subject' => "backend alert",
-               'content' => "Hi developer,\n\nPlease investigate the following debugging message from the site:\n\n~details~",
-               'from_addr' => 'noreply@example.com',
-               'to_addr' => 'fixme@example.com' # not all templates need this field
-       ]
-       # ...
+    'backend_bug' => [
+        'title' => "Notification for site programmer(s)",
+        'description' => "This email template is used if/when the back-end code of this site encounters an unusual/suspicious situation that it's not sure how to cope with.",
+        'variables' => [
+            ['details', "details about the unusual/suspicious situation"]
+        ],
+        'subject' => "backend alert",
+        'content' => "Hi developer,\n\nPlease investigate the following debugging message from the site:\n\n~details~",
+        'from_addr' => 'noreply@example.com',
+        'to_addr' => 'fixme@example.com' # not all templates need this field
+    ]
+    # ...
 ];
index 95d1412..714ab07 100644 (file)
@@ -2,28 +2,28 @@
 
 <html lang="en">
 <head>
-       <title></title>
+    <title></title>
 </head>
 
 <body>
 <!--~$body show {~-->
-       <!--~form {~-->
-               <form action="contact" method="post">
+    <!--~form {~-->
+        <form action="contact" method="post">
 
-                       <div class="caption">Name</div>
-                       <div class="field"><input type="text" name="name" value="~name attr~"></div>
+            <div class="caption">Name</div>
+            <div class="field"><input type="text" name="name" value="~name attr~"></div>
 
-                       <div class="caption">Email</div>
-                       <div class="field"><input type="hidden" name="fields" value="~robot_field attr~~email_field attr~"><input type="email" name="~robot_field attr~" value=""><input type="email" name="~email_field attr~" value="~email attr~"><script>document.write('<style>input[name="'+document.getElementsByName('fields')[0].value.substr(0, 16)+'"]{display:none}</style>')</script></div>
+            <div class="caption">Email</div>
+            <div class="field"><input type="hidden" name="fields" value="~robot_field attr~~email_field attr~"><input type="email" name="~robot_field attr~" value=""><input type="email" name="~email_field attr~" value="~email attr~"><script>document.write('<style>input[name="'+document.getElementsByName('fields')[0].value.substr(0, 16)+'"]{display:none}</style>')</script></div>
 
-                       <div class="caption">Message</div>
-                       <div class="field"><textarea style="box-sizing: border-box; width: 100%; height: 220px" name="comments">~comments html~</textarea></div>
+            <div class="caption">Message</div>
+            <div class="field"><textarea style="box-sizing: border-box; width: 100%; height: 220px" name="comments">~comments html~</textarea></div>
 
-                       <div class="caption"></div>
-                       <div class="field"><input type="submit" value="Send"></div>
+            <div class="caption"></div>
+            <div class="field"><input type="submit" value="Send"></div>
 
-               </form>
-       <!--~}~-->
+        </form>
+    <!--~}~-->
 <!--~}~-->
 </body>
 </html>
index 55077d9..ff5cb42 100644 (file)
@@ -16,105 +16,105 @@ require_once(__DIR__.'/'.'inc/wfpl/email.php');
 
 # generate a new random 16-character string
 function contact_new_field_key() {
-       $character_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
-       $id = "                ";
+    $character_set = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+    $id = "                ";
 
-       # PHP 4.2.0 and up seed the random number generator for you.
-       # Lets hope that it seeds with something harder to guess than the clock.
-       for($i = 0; $i < 16; ++$i) {
-               $id{$i} = $character_set{mt_rand(0, 61)};
-       }
+    # PHP 4.2.0 and up seed the random number generator for you.
+    # Lets hope that it seeds with something harder to guess than the clock.
+    for($i = 0; $i < 16; ++$i) {
+        $id{$i} = $character_set{mt_rand(0, 61)};
+    }
 
-       return $id;
+    return $id;
 }
 
 function contact_get_fields() {
-       $data = array();
+    $data = array();
 
 
-       $data['name'] = format_oneline(_REQUEST_cut('name'));
-       $data['comments'] = format_unix(_REQUEST_cut('comments'));
+    $data['name'] = format_oneline(_REQUEST_cut('name'));
+    $data['comments'] = format_unix(_REQUEST_cut('comments'));
 
-       $fields = _REQUEST_cut('fields');
-       if (preg_match('/^[a-zA-Z0-9]{32}$/', $fields)) {
-               $data['robot'] = format_oneline(_REQUEST_cut(substr($fields, 0, 16)));
-               $data['email'] = format_email(_REQUEST_cut(substr($fields, 16)));
-       }
+    $fields = _REQUEST_cut('fields');
+    if (preg_match('/^[a-zA-Z0-9]{32}$/', $fields)) {
+        $data['robot'] = format_oneline(_REQUEST_cut(substr($fields, 0, 16)));
+        $data['email'] = format_email(_REQUEST_cut(substr($fields, 16)));
+    }
 
-       return $data;
+    return $data;
 }
 
 
 function contact_main() {
-       return contact_main_form();
+    return contact_main_form();
 }
 
 function contact_main_form() {
-       if (isset($_POST['name'])) {
-               $data = contact_get_fields();
-               $host = this_host();
-
-               # gj robot, you did it ;)
-               if ($data['robot'] !== '') {
-                       return './contact_thanks';
-               }
-
-               if (!$data['name'] && !$data['email'] && !$data['comments']) {
-                       // message("you didn't fill anything out")
-               } elseif (!$data['email']) {
-                       message("Error: Please fill out the email field.");
-               } else {
-                       $error = false;
-                       if ($data['robot'] === '' && $GLOBALS['contact_to'] != 'fixme@example.com') {
-                               $to = $GLOBALS['contact_to'];
-                               if ($GLOBALS['contact_from'] === '') {
-                                       $from = "$host/contact <noreply@$host>";
-                               } else {
-                                       $from = $GLOBALS['contact_from'];
-                               }
-                               $reply_to = $to;
-                               if (isset($data['email']) and valid_email($data['email'])) {
-                                       $reply_to = $data['email'];
-                                       if ($data['name'] and preg_match('/^[a-zA-Z0-9_\'. -]*$/', $data['name']) !== false) {
-                                               $reply_to = "$data[name] <$reply_to>";
-                                       }
-                               }
-                               if ($GLOBALS['contact_subject'] === '') {
-                                       $subject = "Your message via $host/contact";
-                               } else {
-                                       $subject = $GLOBALS['contact_subject'];
-                               }
-                               $email_template = new tem();
-                               $email_template->load('contact.email.txt');
-                               $email_template->sets($data);
-                               $email_template->set('$host', $host);
-                               $message = $email_template->run();
-                               $cc = $GLOBALS['contact_cc'];
-                               $bcc = '';
-                               if (email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
-                                       message('Due to an internal error, your message could not be sent. Please try again later.');
-                                       $error = true;
-                               } else {
-                                       message('Message sent');
-                               }
-                       }
-                       if ($error !== true) {
-                               # FIXME create this page or change this to go elsewhere
-                               return './contact_thanks';
-                       }
-               }
-               # otherwise, we display the form again. We've got the form field
-               # values in $data and will put those back in the filds below. You
-               # should add some message asking people to fix their entry in
-               # whatever way you require.
-       } else {
-               # form not submitted, you can set default values like so:
-               #$data = array('name' => 'Yes');
-               $data = array();
-       }
-
-       $data['robot_field'] = contact_new_field_key();
-       $data['email_field'] = contact_new_field_key();
-
-       tem_set('form', $data);
+    if (isset($_POST['name'])) {
+        $data = contact_get_fields();
+        $host = this_host();
+
+        # gj robot, you did it ;)
+        if ($data['robot'] !== '') {
+            return './contact_thanks';
+        }
+
+        if (!$data['name'] && !$data['email'] && !$data['comments']) {
+            // message("you didn't fill anything out")
+        } elseif (!$data['email']) {
+            message("Error: Please fill out the email field.");
+        } else {
+            $error = false;
+            if ($data['robot'] === '' && $GLOBALS['contact_to'] != 'fixme@example.com') {
+                $to = $GLOBALS['contact_to'];
+                if ($GLOBALS['contact_from'] === '') {
+                    $from = "$host/contact <noreply@$host>";
+                } else {
+                    $from = $GLOBALS['contact_from'];
+                }
+                $reply_to = $to;
+                if (isset($data['email']) and valid_email($data['email'])) {
+                    $reply_to = $data['email'];
+                    if ($data['name'] and preg_match('/^[a-zA-Z0-9_\'. -]*$/', $data['name']) !== false) {
+                        $reply_to = "$data[name] <$reply_to>";
+                    }
+                }
+                if ($GLOBALS['contact_subject'] === '') {
+                    $subject = "Your message via $host/contact";
+                } else {
+                    $subject = $GLOBALS['contact_subject'];
+                }
+                $email_template = new tem();
+                $email_template->load('contact.email.txt');
+                $email_template->sets($data);
+                $email_template->set('$host', $host);
+                $message = $email_template->run();
+                $cc = $GLOBALS['contact_cc'];
+                $bcc = '';
+                if (email($from, $to, $subject, $message, $reply_to, $cc, $bcc)) {
+                    message('Due to an internal error, your message could not be sent. Please try again later.');
+                    $error = true;
+                } else {
+                    message('Message sent');
+                }
+            }
+            if ($error !== true) {
+                # FIXME create this page or change this to go elsewhere
+                return './contact_thanks';
+            }
+        }
+        # otherwise, we display the form again. We've got the form field
+        # values in $data and will put those back in the filds below. You
+        # should add some message asking people to fix their entry in
+        # whatever way you require.
+    } else {
+        # form not submitted, you can set default values like so:
+        #$data = array('name' => 'Yes');
+        $data = array();
+    }
+
+    $data['robot_field'] = contact_new_field_key();
+    $data['email_field'] = contact_new_field_key();
+
+    tem_set('form', $data);
 }
index c5e8269..3884061 100644 (file)
@@ -1,16 +1,16 @@
 <!DOCTYPE html>
 <html lang="en">
 <head>
-       <title>~$title show {~404: File Not Found~}~</title>
+    <title>~$title show {~404: File Not Found~}~</title>
 </head>
 <body>
-       <!--~$body show {~-->
-               <h1>404: File Not Found</h1>
+    <!--~$body show {~-->
+        <h1>404: File Not Found</h1>
 
-               <p>Oops, we don't have a page at <code>~path html~</code></p>
+        <p>Oops, we don't have a page at <code>~path html~</code></p>
 
-               <p>If you got here by clicking a link on this site, please let us know where we can find that broken link.</p>
-       <!--~}~-->
-       
+        <p>If you got here by clicking a link on this site, please let us know where we can find that broken link.</p>
+    <!--~}~-->
+    
 </body>
 </html>
index 9c9d958..dcb05bf 100644 (file)
@@ -1,5 +1,5 @@
 <?php
 
 function error_404_main() {
-       tem_set('path', $_SERVER['REQUEST_URI']);
+    tem_set('path', $_SERVER['REQUEST_URI']);
 }
index d7118e0..71b9cab 100644 (file)
@@ -4,94 +4,94 @@
 # called automatically by wfpl_main()
 
 function enc_css_str($str) {
-       $str = str_replace("\\", "\\00005c", $str);
-       return str_replace("\"", "\\000022", $str);
+    $str = str_replace("\\", "\\00005c", $str);
+    return str_replace("\"", "\\000022", $str);
 }
 
 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 &$item) {
-                       $item['basename'] = $item['filename']; # for nav-links as images
-                       if($item['filename'] == $basename) {
-                               $item['current'] = true;
-                       }
-                       if($item['filename'] == 'index') {
-                               $item['filename'] = './';
-                       }
-                       if($item['title'] == '') {
-                               $item['title'] = '(untitled)';
-                       }
-               }
-               $tem->set('$navbar_items', $nav_items);
-       }
+    $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 &$item) {
+            $item['basename'] = $item['filename']; # for nav-links as images
+            if($item['filename'] == $basename) {
+                $item['current'] = true;
+            }
+            if($item['filename'] == 'index') {
+                $item['filename'] = './';
+            }
+            if($item['title'] == '') {
+                $item['title'] = '(untitled)';
+            }
+        }
+        $tem->set('$navbar_items', $nav_items);
+    }
 
-       $header_image = persistent_get('wfplcms_header_image');
-       if ($header_image) {
-               $hi_css  = "\n<style>\n";
-               if ($header_image['width'] != WFPL_SITE_WIDTH) {
-                       $hi_css .= "#site_header {\n";
-                       $hi_css .=   'width: ' . $header_image['width'] . "px;\n";
-                       $hi_css .= "}\n";
-               }
-               $hi_css .= "#site_header:before {\n";
-               $hi_css .=   "content: \"\";\n";
-               $hi_css .=   'background-image: url(' . $header_image['url'] . ");\n";
-               $hi_css .=   'padding-top: ' . ($header_image['height'] / $header_image['width'] * 100) . "%;\n";
-               $hi_css .= "}\n";
-               if ($header_image['caption']) {
-                       $hi_css .= "#site_header:after {\n";
-                       $hi_css .=   "content: \"" . enc_css_str($header_image['caption']) . "\";\n";
-                       $hi_css .= "}\n";
-               }
-               $hi_css .= "</style>\n";
+    $header_image = persistent_get('wfplcms_header_image');
+    if ($header_image) {
+        $hi_css  = "\n<style>\n";
+        if ($header_image['width'] != WFPL_SITE_WIDTH) {
+            $hi_css .= "#site_header {\n";
+            $hi_css .=   'width: ' . $header_image['width'] . "px;\n";
+            $hi_css .= "}\n";
+        }
+        $hi_css .= "#site_header:before {\n";
+        $hi_css .=   "content: \"\";\n";
+        $hi_css .=   'background-image: url(' . $header_image['url'] . ");\n";
+        $hi_css .=   'padding-top: ' . ($header_image['height'] / $header_image['width'] * 100) . "%;\n";
+        $hi_css .= "}\n";
+        if ($header_image['caption']) {
+            $hi_css .= "#site_header:after {\n";
+            $hi_css .=   "content: \"" . enc_css_str($header_image['caption']) . "\";\n";
+            $hi_css .= "}\n";
+        }
+        $hi_css .= "</style>\n";
 
-               $tem->set('$cms_css', $hi_css);
-       }
+        $tem->set('$cms_css', $hi_css);
+    }
 
-       $cms_page = db_get_assoc('cms_pages', 'id,title,keywords,description,layout,content,sidebar_content', 'where filename=%"', $basename);
-       cms_display_content($tem, $cms_page);
+    $cms_page = db_get_assoc('cms_pages', 'id,title,keywords,description,layout,content,sidebar_content', 'where filename=%"', $basename);
+    cms_display_content($tem, $cms_page);
 
-       $footer = db_get_value('cms_pages', 'content', 'where filename="_footer"');
-       if ($footer) {
-               $tem->set('$cms_footer', $footer);
-       }
+    $footer = db_get_value('cms_pages', 'content', 'where filename="_footer"');
+    if ($footer) {
+        $tem->set('$cms_footer', $footer);
+    }
 
-       if(session_auth_can('admin_links')) {
-               $admin_links = array();
-               if($cms_page) {
-                       $admin_links['$edit_page_id'] = $cms_page['id'];
-               }
-               $tem->set('$admin_links', $admin_links);
-       }
+    if(session_auth_can('admin_links')) {
+        $admin_links = array();
+        if($cms_page) {
+            $admin_links['$edit_page_id'] = $cms_page['id'];
+        }
+        $tem->set('$admin_links', $admin_links);
+    }
 
-       if($cms_page) {
-               return true;
-       } else {
-               return false;
-       }
+    if($cms_page) {
+        return true;
+    } else {
+        return false;
+    }
 }
 
 function cms_display_content(&$tem, $row) {
-       if($row) {
-               $tem->set('$cms_title', $row['title']);
-               $tem->set('$meta_keywords', $row['keywords']);
-               $tem->set('$meta_description', $row['description']);
-               $tem->set('$cms_body', $row['content']);
-               if ($row['layout'] === '' || $row['layout'] === '0') {
-                       $tem->set('$layout_centerer_class', 'full');
-               } else {
-                       $tem->set('$layout_centerer_class', 'with_sidebar');
-                       if ($row['layout'] === '1') {
-                               $tem->set('$layout_sidebar_class', 'plain');
-                       } else {
-                               $tem->set('$layout_sidebar_class', 'bordered');
-                       }
-                       $tem->set('$cms_sidebar', $row['sidebar_content']);
-               }
-               return $row['id'];
-       } else {
-               $tem->set('$layout_centerer_class', 'full');
-       }
+    if($row) {
+        $tem->set('$cms_title', $row['title']);
+        $tem->set('$meta_keywords', $row['keywords']);
+        $tem->set('$meta_description', $row['description']);
+        $tem->set('$cms_body', $row['content']);
+        if ($row['layout'] === '' || $row['layout'] === '0') {
+            $tem->set('$layout_centerer_class', 'full');
+        } else {
+            $tem->set('$layout_centerer_class', 'with_sidebar');
+            if ($row['layout'] === '1') {
+                $tem->set('$layout_sidebar_class', 'plain');
+            } else {
+                $tem->set('$layout_sidebar_class', 'bordered');
+            }
+            $tem->set('$cms_sidebar', $row['sidebar_content']);
+        }
+        return $row['id'];
+    } else {
+        $tem->set('$layout_centerer_class', 'full');
+    }
 }
index c856fad..ea57afa 100644 (file)
 
 function db_upgrade_to_1() {
 db_send_query(<<<EOLsql
-       create table wfpl_sessions (
-               id int unique auto_increment,
-               session_key varchar(16),
-               idle_timeout int,
-               expires int,
-               expires_max int,
-               value text
-       ) CHARSET=utf8;
+    create table wfpl_sessions (
+        id int unique auto_increment,
+        session_key varchar(16),
+        idle_timeout int,
+        expires int,
+        expires_max int,
+        value text
+    ) CHARSET=utf8;
 EOLsql
 );
 db_send_query(<<<EOLsql
-       create table email_templates (
-               id int unique auto_increment,
-               slug varchar(200) binary not null default "",
-               notes text binary not null default "",
-               from_addr varchar(100) binary not null default "",
-               to_addr varchar(100) binary not null default "",
-               cc_addr varchar(100) binary not null default "",
-               bcc_addr varchar(100) binary not null default "",
-               subject varchar(200) binary not null default "",
-               content text binary not null default ""
-       ) CHARSET=utf8;
+    create table email_templates (
+        id int unique auto_increment,
+        slug varchar(200) binary not null default "",
+        notes text binary not null default "",
+        from_addr varchar(100) binary not null default "",
+        to_addr varchar(100) binary not null default "",
+        cc_addr varchar(100) binary not null default "",
+        bcc_addr varchar(100) binary not null default "",
+        subject varchar(200) binary not null default "",
+        content text binary not null default ""
+    ) CHARSET=utf8;
 EOLsql
 );
 db_send_query(<<<EOLsql
-       create table files (
-               id int unique auto_increment,
-               filename varchar(100) not null default "",
-               description varchar(200) not null default ""
-       );
+    create table files (
+        id int unique auto_increment,
+        filename varchar(100) not null default "",
+        description varchar(200) not null default ""
+    );
 EOLsql
 );
 db_send_query(<<<EOLsql
-       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 "",
-               created_at int not null default 0
-       );
+    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 "",
+        created_at int not null default 0
+    );
 EOLsql
 );
 db_send_query(<<<EOLsql
-       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,
-               layout int not null default 0,
-               content mediumtext not null default "",
-               sidebar_content mediumtext not null default "",
-               description text not null default "",
-               keywords text not null default ""
-       );
+    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,
+        layout int not null default 0,
+        content mediumtext not null default "",
+        sidebar_content mediumtext not null default "",
+        description text not null default "",
+        keywords text not null default ""
+    );
 EOLsql
 );
 db_send_query(<<<EOLsql
-       insert into cms_pages set
-               filename='index',
-               title='Home',
-               content='Under Construction',
-               navbar=1000000000;
+    insert into cms_pages set
+        filename='index',
+        title='Home',
+        content='Under Construction',
+        navbar=1000000000;
 EOLsql
 );
 db_send_query(<<<EOLsql
-       create table users (
-               id int unique auto_increment,
-               name varchar(200) binary not null default "",
-               username varchar(200) binary not null default "",
-               password varchar(255) binary not null default "",
-               role varchar(200) binary not null default "",
-               last_active int(11) not null default 0,
-               last_login int(11) not null default 0
-       ) CHARSET=utf8;
+    create table users (
+        id int unique auto_increment,
+        name varchar(200) binary not null default "",
+        username varchar(200) binary not null default "",
+        password varchar(255) binary not null default "",
+        role varchar(200) binary not null default "",
+        last_active int(11) not null default 0,
+        last_login int(11) not null default 0
+    ) CHARSET=utf8;
 EOLsql
 );
 db_send_query(<<<EOLsql
-       insert into users set
-               name="fixme",
-               username="fixme",
-               password="$2y$10$84xUpPFQFRYRwpGkt01YtObJZcRKGReM/5ywHXCbwDF2bja41CDZm",
-               role="admin";
+    insert into users set
+        name="fixme",
+        username="fixme",
+        password="$2y$10$84xUpPFQFRYRwpGkt01YtObJZcRKGReM/5ywHXCbwDF2bja41CDZm",
+        role="admin";
 EOLsql
 );
 db_send_query(<<<EOLsql
-       create table paypal_ipn (
-               id int unique auto_increment,
-               txn_id varchar(250) not null default "",
-               status varchar(250) not null default "",
-               ipn_at int(11) not null default 0,
-               txn_type varchar(100) not null default "",
-               subscr_id varchar(100) not null default "",
-               custom varchar(250) not null default "",
-               for_table_id int not null default 0,
-               for_row_id int not null default 0,
-               processed int(1) not null default 0,
-               item_name varchar(250) not null default "",
-               item_number varchar(250) not null default "",
-               needs_review int(1) not null default 0,
-               payment_status varchar(250) not null default "",
-               mc_gross varchar(250) not null default "",
-               mc_currency varchar(250) not null default "",
-               receiver_email varchar(250) not null default "",
-               payer_email varchar(250) not null default "",
-               log text not null default ""
-       ) CHARSET=utf8;
+    create table paypal_ipn (
+        id int unique auto_increment,
+        txn_id varchar(250) not null default "",
+        status varchar(250) not null default "",
+        ipn_at int(11) not null default 0,
+        txn_type varchar(100) not null default "",
+        subscr_id varchar(100) not null default "",
+        custom varchar(250) not null default "",
+        for_table_id int not null default 0,
+        for_row_id int not null default 0,
+        processed int(1) not null default 0,
+        item_name varchar(250) not null default "",
+        item_number varchar(250) not null default "",
+        needs_review int(1) not null default 0,
+        payment_status varchar(250) not null default "",
+        mc_gross varchar(250) not null default "",
+        mc_currency varchar(250) not null default "",
+        receiver_email varchar(250) not null default "",
+        payer_email varchar(250) not null default "",
+        log text not null default ""
+    ) CHARSET=utf8;
 EOLsql
 );
 }
 
 function db_upgrade_to_2() {
 db_send_query(<<<EOLsql
-       create table history_cms_pages (
-               history_id int unique auto_increment,
-               history_when int not null default 0,
-               history_user_id int not null default 0,
-               id int,
-               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,
-               layout int not null default 0,
-               content mediumtext not null default "",
-               sidebar_content mediumtext not null default "",
-               description text not null default "",
-               keywords text not null default ""
-       );
+    create table history_cms_pages (
+        history_id int unique auto_increment,
+        history_when int not null default 0,
+        history_user_id int not null default 0,
+        id int,
+        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,
+        layout int not null default 0,
+        content mediumtext not null default "",
+        sidebar_content mediumtext not null default "",
+        description text not null default "",
+        keywords text not null default ""
+    );
 EOLsql
 );
 db_send_query(<<<EOLsql
-       insert into history_cms_pages (
-               history_when,
-               history_user_id,
-               id,
-               filename,
-               title,
-               nav_title,
-               navbar,
-               layout,
-               content,
-               sidebar_content,
-               description,
-               keywords
-       ) select
-               0,
-               0,
-               id,
-               filename,
-               title,
-               nav_title,
-               navbar,
-               layout,
-               content,
-               sidebar_content,
-               description,
-               keywords
-       from cms_pages;
+    insert into history_cms_pages (
+        history_when,
+        history_user_id,
+        id,
+        filename,
+        title,
+        nav_title,
+        navbar,
+        layout,
+        content,
+        sidebar_content,
+        description,
+        keywords
+    ) select
+        0,
+        0,
+        id,
+        filename,
+        title,
+        nav_title,
+        navbar,
+        layout,
+        content,
+        sidebar_content,
+        description,
+        keywords
+    from cms_pages;
 EOLsql
 );
 }
index 0f3d23d..5244635 100644 (file)
@@ -4,55 +4,55 @@ require_once(__DIR__.'/'.'wfpl/email.php');
 
 # call this when you have class="unix_time" or class="unix_date"
 function render_timestamps() {
-       $GLOBALS['wfpl_main_template']->set('$render_timestamps');
+    $GLOBALS['wfpl_main_template']->set('$render_timestamps');
 }
 
 # helper for email_with_template() below
 function get_email_template($slug, $template_variables, $to_addr) {
-       # defaults
-       $out = array(
-               'subject' => $GLOBALS['email_templates'][$slug]['subject'],
-               'content' => $GLOBALS['email_templates'][$slug]['content'],
-               'from_addr' => $GLOBALS['email_templates'][$slug]['from_addr'],
-               'to_addr' => '',
-               'cc_addr' => '',
-               'bcc_addr' => ''
-       );
-       if (isset($GLOBALS['email_templates'][$slug]['to_addr'])) {
-               $out['to_addr'] = $GLOBALS['email_templates'][$slug]['to_addr'];
-       } else {
-               if ($to_addr == null) {
-                       die("ERROR: email_with_template(\"$slug\") needs a to_addr (put in \$GLOBALS['email_templates']['$slug'] or pass as argument)");
-               }
-       }
-       # override with DB (if it exists)
-       $row = db_get_assoc('email_templates', 'from_addr,to_addr,cc_addr,bcc_addr,subject,content', 'where slug=%"', $slug);
-       if ($row) {
-               foreach($row as $key => $value) {
-                       $out[$key] = $value;
-               }
-       }
-       # argument wins no matter what
-       if ($to_addr !== null) {
-               $out['to_addr'] = $to_addr;
-       }
-       if (strpos($out['content'], '~') !== false) {
-               $tem = new tem();
-               $tem->load_str($out['content']);
-               $tem->sets($template_variables);
-               $out['content'] = $tem->run();
-       }
-       if (strpos($out['subject'], '~') !== false) {
-               $tem = new tem();
-               $tem->load_str($out['subject']);
-               $tem->sets($template_variables);
-               $out['subject'] = $tem->run();
-       }
-       return $out;
+    # defaults
+    $out = array(
+        'subject' => $GLOBALS['email_templates'][$slug]['subject'],
+        'content' => $GLOBALS['email_templates'][$slug]['content'],
+        'from_addr' => $GLOBALS['email_templates'][$slug]['from_addr'],
+        'to_addr' => '',
+        'cc_addr' => '',
+        'bcc_addr' => ''
+    );
+    if (isset($GLOBALS['email_templates'][$slug]['to_addr'])) {
+        $out['to_addr'] = $GLOBALS['email_templates'][$slug]['to_addr'];
+    } else {
+        if ($to_addr == null) {
+            die("ERROR: email_with_template(\"$slug\") needs a to_addr (put in \$GLOBALS['email_templates']['$slug'] or pass as argument)");
+        }
+    }
+    # override with DB (if it exists)
+    $row = db_get_assoc('email_templates', 'from_addr,to_addr,cc_addr,bcc_addr,subject,content', 'where slug=%"', $slug);
+    if ($row) {
+        foreach($row as $key => $value) {
+            $out[$key] = $value;
+        }
+    }
+    # argument wins no matter what
+    if ($to_addr !== null) {
+        $out['to_addr'] = $to_addr;
+    }
+    if (strpos($out['content'], '~') !== false) {
+        $tem = new tem();
+        $tem->load_str($out['content']);
+        $tem->sets($template_variables);
+        $out['content'] = $tem->run();
+    }
+    if (strpos($out['subject'], '~') !== false) {
+        $tem = new tem();
+        $tem->load_str($out['subject']);
+        $tem->sets($template_variables);
+        $out['subject'] = $tem->run();
+    }
+    return $out;
 }
 
 # pass null as first arg if "to_addr" should come from the DB
 function email_with_template($to_addr, $template_slug, $template_vars, $reply_to = '') {
-       $t = get_email_template($template_slug, $template_vars, $to_addr);
-       return email($t['from_addr'], $t['to_addr'], $t['subject'], $t['content'], $reply_to, $t['cc_addr'], $t['bcc_addr']);
+    $t = get_email_template($template_slug, $template_vars, $to_addr);
+    return email($t['from_addr'], $t['to_addr'], $t['subject'], $t['content'], $reply_to, $t['cc_addr'], $t['bcc_addr']);
 }
index 9e49d37..5f25ffe 100644 (file)
@@ -2,86 +2,86 @@
 
 # normalize usernames (for case-insensitive etc. logins)
 function format_auth_username($str) {
-       $str = iconv('utf8', 'ascii//TRANSLIT', $str);
-       $str = strtolower(trim($str));
-       $str = preg_replace('/[^a-z0-9]/', '', $str);
-       return $str;
+    $str = iconv('utf8', 'ascii//TRANSLIT', $str);
+    $str = strtolower(trim($str));
+    $str = preg_replace('/[^a-z0-9]/', '', $str);
+    return $str;
 }
 
 # Called automatically by session_auth().
 # Only call if you've just verified that someone has logged in, or has clicked
 # a valid password reset link.
 function session_auth_init($id = false, $password_reset = false) {
-       $GLOBALS['wfpl_session_auth'] = [
-               'id' => null,
-               'role' => null,
-               'name' => null,
-               'username' => null,
-               'last_active' => null,
-               'password_reset' => null
-       ];
+    $GLOBALS['wfpl_session_auth'] = [
+        'id' => null,
+        'role' => null,
+        'name' => null,
+        'username' => null,
+        'last_active' => null,
+        'password_reset' => null
+    ];
 
-       if ($id) {
-               $user = db_get_assoc('users', 'role,name,username', 'where id=%i', $id);
-               $now = time();
-               db_update('users', 'last_active', $now, 'where id=%i', $id);
-               $GLOBALS['wfpl_session_auth']['id'] = $id;
-               $GLOBALS['wfpl_session_auth']['role'] = $user['role'];
-               $GLOBALS['wfpl_session_auth']['name'] = $user['name'];
-               $GLOBALS['wfpl_session_auth']['username'] = $user['username'];
-               $GLOBALS['wfpl_session_auth']['last_active'] = $now;
-       }
+    if ($id) {
+        $user = db_get_assoc('users', 'role,name,username', 'where id=%i', $id);
+        $now = time();
+        db_update('users', 'last_active', $now, 'where id=%i', $id);
+        $GLOBALS['wfpl_session_auth']['id'] = $id;
+        $GLOBALS['wfpl_session_auth']['role'] = $user['role'];
+        $GLOBALS['wfpl_session_auth']['name'] = $user['name'];
+        $GLOBALS['wfpl_session_auth']['username'] = $user['username'];
+        $GLOBALS['wfpl_session_auth']['last_active'] = $now;
+    }
 
-       if ($password_reset) {
-               $GLOBALS['wfpl_session_auth']['password_reset'] = true;
-               $GLOBALS['wfpl_session_auth']['id'] = session_get('auth_password_reset_id');
-       }
+    if ($password_reset) {
+        $GLOBALS['wfpl_session_auth']['password_reset'] = true;
+        $GLOBALS['wfpl_session_auth']['id'] = session_get('auth_password_reset_id');
+    }
 }
 
 # return an assoc containing info about the authenticated user, see session_auth_init
 function session_auth() {
-       if (!isset($GLOBALS['wfpl_session_auth'])) {
-               $id = false;
-               $reset = false;
-               if (session_exists()) {
-                       $id = session_get('auth_id');
-                       if (!$id) {
-                               $r = session_get('auth_password_reset');
-                               if (strlen($r)) {
-                                       $r = (int) format_int_0($r);
-                                       if (time() < $r) {
-                                               $reset = true;
-                                       } else {
-                                               message('Oops, your temporary access (to change your password) has expired');
-                                               session_clear('auth_password_reset');
-                                       }
-                               }
-                       }
-               }
-               session_auth_init($id, $reset);
-       }
-       return $GLOBALS['wfpl_session_auth'];
+    if (!isset($GLOBALS['wfpl_session_auth'])) {
+        $id = false;
+        $reset = false;
+        if (session_exists()) {
+            $id = session_get('auth_id');
+            if (!$id) {
+                $r = session_get('auth_password_reset');
+                if (strlen($r)) {
+                    $r = (int) format_int_0($r);
+                    if (time() < $r) {
+                        $reset = true;
+                    } else {
+                        message('Oops, your temporary access (to change your password) has expired');
+                        session_clear('auth_password_reset');
+                    }
+                }
+            }
+        }
+        session_auth_init($id, $reset);
+    }
+    return $GLOBALS['wfpl_session_auth'];
 }
 
 # return true if the logged in user is allowed to $priv
 # (false if they are not logged in, or aren't alowed to $priv)
 function session_auth_can($priv) {
-       $s = session_auth();
-       if ($s['role'] === 'admin') {
-               return true;
-       }
-       return false;
+    $s = session_auth();
+    if ($s['role'] === 'admin') {
+        return true;
+    }
+    return false;
 }
 
 # return ONLY IF the currently logged in user can $priv
 # otherwise, it displays the login page, and exit early
 function session_auth_must($priv) {
-       if (session_auth_can($priv)) {
-               return;
-       }
-       if (!isset($_REQUEST['after_login'])) {
-               $_REQUEST['after_login_url'] = this_url();
-       }
-       wfpl_main('login');
-       exit();
+    if (session_auth_can($priv)) {
+        return;
+    }
+    if (!isset($_REQUEST['after_login'])) {
+        $_REQUEST['after_login_url'] = this_url();
+    }
+    wfpl_main('login');
+    exit();
 }
index 6a3fbcf..149ffbd 100644 (file)
@@ -2,23 +2,23 @@
 
 <html>
 <head>
-       <title></title>
+    <title></title>
 </head>
 
 <body>
-       <!--~$body show {~-->
-               <!--~form {~-->
-                       <form action="login" method="post">
-                               <div class="caption">Username</div>
-                               <div class="field"><input type="text" name="username" value="~username attr~" autofocus></div>
+    <!--~$body show {~-->
+        <!--~form {~-->
+            <form action="login" method="post">
+                <div class="caption">Username</div>
+                <div class="field"><input type="text" name="username" value="~username attr~" autofocus></div>
 
-                               <div class="caption">Password (case sensitive)</div>
-                               <div class="field"><input type="password" name="password" value=""></div>
+                <div class="caption">Password (case sensitive)</div>
+                <div class="field"><input type="password" name="password" value=""></div>
 
-                               <div class="caption">&nbsp;</div>
-                               <div class="field"><input type="hidden" name="after_login_url" value="~after_login_url attr~"><input type="submit" value="Log in"></div>
-                       </form>
-               <!--~}~-->
-       <!--~}~-->
+                <div class="caption">&nbsp;</div>
+                <div class="field"><input type="hidden" name="after_login_url" value="~after_login_url attr~"><input type="submit" value="Log in"></div>
+            </form>
+        <!--~}~-->
+    <!--~}~-->
 </body>
 </html>
index 79a8f83..802b95e 100644 (file)
--- a/login.php
+++ b/login.php
@@ -2,69 +2,69 @@
 
 
 function login_get_fields() {
-       $data = array();
+    $data = array();
 
-       $data['after_login_url'] = format_oneline(_REQUEST_cut('after_login_url'));
-       $data['username'] = format_auth_username(trim(_REQUEST_cut('username')));
-       $data['password'] = format_oneline(trim(_REQUEST_cut('password')));
+    $data['after_login_url'] = format_oneline(_REQUEST_cut('after_login_url'));
+    $data['username'] = format_auth_username(trim(_REQUEST_cut('username')));
+    $data['password'] = format_oneline(trim(_REQUEST_cut('password')));
 
-       return $data;
+    return $data;
 }
 
 function login_main() {
-       $data = login_get_fields();
-       if (strlen($data['username']) && strlen($data['password'])) {
-               $row = db_get_assoc('users', 'id,name,role,password', 'where username=%"', $data['username']);
-               if ($row) # &&
-               if (strlen($row['password'])) {
-                       $needs_rehash = false;
-                       $password_good = false;
-                       if (substr($row['password'], 0, 5) === 'sha1:') {
-                               if (sha1($data['password']) === substr($row['password'], 5)) {
-                                       $password_good = true;
-                                       $needs_rehash = true;
-                               }
-                       } else {
-                               if (!function_exists('password_hash')) {
-                                       require_once(__DIR__.'/'.'inc/password_funcs_backported.php');
-                               }
-                               if (password_verify($data['password'], $row['password'])) {
-                                       $password_good = true;
-                                       if (password_needs_rehash($row['password'], PASSWORD_DEFAULT)) {
-                                               $needs_rehash = true;
-                                       }
-                               }
-                       }
-                       if ($password_good) {
-                               if ($needs_rehash) {
-                                       if (!function_exists('password_hash')) {
-                                               require_once(__DIR__.'/'.'inc/password_funcs_backported.php');
-                                       }
-                                       $hash = password_hash($data['password'], PASSWORD_DEFAULT);
-                                       db_update('users', 'password', $hash, 'where id=%i', $row['id']);
-                               }
+    $data = login_get_fields();
+    if (strlen($data['username']) && strlen($data['password'])) {
+        $row = db_get_assoc('users', 'id,name,role,password', 'where username=%"', $data['username']);
+        if ($row) # &&
+        if (strlen($row['password'])) {
+            $needs_rehash = false;
+            $password_good = false;
+            if (substr($row['password'], 0, 5) === 'sha1:') {
+                if (sha1($data['password']) === substr($row['password'], 5)) {
+                    $password_good = true;
+                    $needs_rehash = true;
+                }
+            } else {
+                if (!function_exists('password_hash')) {
+                    require_once(__DIR__.'/'.'inc/password_funcs_backported.php');
+                }
+                if (password_verify($data['password'], $row['password'])) {
+                    $password_good = true;
+                    if (password_needs_rehash($row['password'], PASSWORD_DEFAULT)) {
+                        $needs_rehash = true;
+                    }
+                }
+            }
+            if ($password_good) {
+                if ($needs_rehash) {
+                    if (!function_exists('password_hash')) {
+                        require_once(__DIR__.'/'.'inc/password_funcs_backported.php');
+                    }
+                    $hash = password_hash($data['password'], PASSWORD_DEFAULT);
+                    db_update('users', 'password', $hash, 'where id=%i', $row['id']);
+                }
 
-                               session_new();
-                               session_set('auth_id', $row['id']);
-                               # we're about to http redirect, so no need to update session_auth now
-                               db_update('users', 'last_login', time(), 'where id=%i', $row['id']);
-                               message("You are now logged in.");
-                               if(!$data['after_login_url']) {
-                                       if ($row['role'] == 'admin') {
-                                               $data['after_login_url'] = './admin';
-                                       } else {
-                                               $data['after_login_url'] = './';
-                                       }
-                               } elseif(strpos(':', $data['after_login_url']) !== false) {
-                                       $data['after_login_url'] = "./$data[url]";
-                               }
+                session_new();
+                session_set('auth_id', $row['id']);
+                # we're about to http redirect, so no need to update session_auth now
+                db_update('users', 'last_login', time(), 'where id=%i', $row['id']);
+                message("You are now logged in.");
+                if(!$data['after_login_url']) {
+                    if ($row['role'] == 'admin') {
+                        $data['after_login_url'] = './admin';
+                    } else {
+                        $data['after_login_url'] = './';
+                    }
+                } elseif(strpos(':', $data['after_login_url']) !== false) {
+                    $data['after_login_url'] = "./$data[url]";
+                }
 
-                               # redirect to the page they were trying to access:
-                               return $data['after_login_url'];
-                       }
-               }
-               message("Incorrect username and/or password");
-       }
-       $data['password'] = '';
-       tem_set('form', $data);
+                # redirect to the page they were trying to access:
+                return $data['after_login_url'];
+            }
+        }
+        message("Incorrect username and/or password");
+    }
+    $data['password'] = '';
+    tem_set('form', $data);
 }
index 9600c09..9e26b2f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 function logout_main() {
-       kill_session();
-       message('logged out successfully');
-       return './';
+    kill_session();
+    message('logged out successfully');
+    return './';
 }
index 0ef7334..85542ba 100644 (file)
@@ -7,135 +7,135 @@ require_once(__DIR__.'/'.'inc/wfpl/template.php');
 require_once(__DIR__.'/'.'inc/wfpl/format.php');
 
 function paypal_ipn_main() {
-       // read the post from PayPal system and add 'cmd'
-       $req = 'cmd=_notify-validate';
-       $log = 'Received IPN:';
+    // read the post from PayPal system and add 'cmd'
+    $req = 'cmd=_notify-validate';
+    $log = 'Received IPN:';
 
-       foreach ($_POST as $key => $value) {
-               $log .= "\n$key: $value";
-               $value = urlencode($value);
-               $req .= "&$key=$value";
-       }
+    foreach ($_POST as $key => $value) {
+        $log .= "\n$key: $value";
+        $value = urlencode($value);
+        $req .= "&$key=$value";
+    }
 
-       // assign posted variables to local variables
-       $item_name      = isset($_POST['item_name'])      ? $_POST['item_name']      : '';
-       $item_number    = isset($_POST['item_number'])    ? $_POST['item_number']    : '';
-       $payment_status = isset($_POST['payment_status']) ? $_POST['payment_status'] : '';
-       $mc_gross       = isset($_POST['mc_gross'])       ? $_POST['mc_gross']       : '';
-       $mc_currency    = isset($_POST['mc_currency'])    ? $_POST['mc_currency']    : '';
-       $txn_id         = isset($_POST['txn_id'])         ? $_POST['txn_id']         : '';
-       $receiver_email = isset($_POST['receiver_email']) ? $_POST['receiver_email'] : '';
-       $payer_email    = isset($_POST['payer_email'])    ? $_POST['payer_email']    : '';
-       $custom         = isset($_POST['custom'])         ? $_POST['custom']         : '';
-       $txn_type       = isset($_POST['txn_type'])       ? $_POST['txn_type']       : '';
-       $subscr_id      = isset($_POST['subscr_id'])      ? $_POST['subscr_id']      : '';
-       $needs_review = 1;
+    // assign posted variables to local variables
+    $item_name      = isset($_POST['item_name'])      ? $_POST['item_name']      : '';
+    $item_number    = isset($_POST['item_number'])    ? $_POST['item_number']    : '';
+    $payment_status = isset($_POST['payment_status']) ? $_POST['payment_status'] : '';
+    $mc_gross       = isset($_POST['mc_gross'])       ? $_POST['mc_gross']       : '';
+    $mc_currency    = isset($_POST['mc_currency'])    ? $_POST['mc_currency']    : '';
+    $txn_id         = isset($_POST['txn_id'])         ? $_POST['txn_id']         : '';
+    $receiver_email = isset($_POST['receiver_email']) ? $_POST['receiver_email'] : '';
+    $payer_email    = isset($_POST['payer_email'])    ? $_POST['payer_email']    : '';
+    $custom         = isset($_POST['custom'])         ? $_POST['custom']         : '';
+    $txn_type       = isset($_POST['txn_type'])       ? $_POST['txn_type']       : '';
+    $subscr_id      = isset($_POST['subscr_id'])      ? $_POST['subscr_id']      : '';
+    $needs_review = 1;
 
-       $status = 'unknown';
+    $status = 'unknown';
 
-       $ch = curl_init($GLOBALS['paypal_site'] . '/cgi-bin/webscr');
-       if ($ch == false) {
-               $status = 'curl_init failed';
-       } else {
-               curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
-               curl_setopt($ch, CURLOPT_POST, 1);
-               curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
-               curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
-               curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
-               curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
-               curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
-               curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
-               curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
-               $res = curl_exec($ch);
-               $curl_errno = curl_errno($ch);
-               curl_close($ch);
-               if ($curl_errno != 0) {
-                       $status = 'curl fail: ' . $curl_errno;
-               } else {
-                       // Split response headers and payload, a better way for strcmp
-                       $tokens = explode("\r\n\r\n", trim($res));
-                       $res = trim(end($tokens));
-                       $res_word = trim($tokens[count($tokens) - 1]);
-                       if ($res_word === 'VERIFIED') {
-                               $status = 'verified';
-                       } elseif ($res_word === 'INVALID') {
-                               $status = 'invalid';
-                       } else {
-                               $log .= "\n\nCan't figure out PayPal verify reply:\n" . $res;
-                       }
-               }
-       }
+    $ch = curl_init($GLOBALS['paypal_site'] . '/cgi-bin/webscr');
+    if ($ch == false) {
+        $status = 'curl_init failed';
+    } else {
+        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
+        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
+        $res = curl_exec($ch);
+        $curl_errno = curl_errno($ch);
+        curl_close($ch);
+        if ($curl_errno != 0) {
+            $status = 'curl fail: ' . $curl_errno;
+        } else {
+            // Split response headers and payload, a better way for strcmp
+            $tokens = explode("\r\n\r\n", trim($res));
+            $res = trim(end($tokens));
+            $res_word = trim($tokens[count($tokens) - 1]);
+            if ($res_word === 'VERIFIED') {
+                $status = 'verified';
+            } elseif ($res_word === 'INVALID') {
+                $status = 'invalid';
+            } else {
+                $log .= "\n\nCan't figure out PayPal verify reply:\n" . $res;
+            }
+        }
+    }
 
-       $row = [
-               'txn_id' =>            $txn_id,
-               'status' =>            $status,
-               'custom' =>            $custom,
-               'item_name' =>         $item_name,
-               'item_number' =>       $item_number,
-               'needs_review' =>      $needs_review,
-               'payment_status' =>    $payment_status,
-               'mc_gross' =>          $mc_gross,
-               'mc_currency' =>       $mc_currency,
-               'receiver_email' =>    $receiver_email,
-               'payer_email' =>       $payer_email,
-               'log' =>               $log,
-               'txn_type' =>          $txn_type,
-               'subscr_id' =>         $subscr_id,
-               'user_id' =>           $user_id,
-               'ipn_at' =>            time()
-       ];
+    $row = [
+        'txn_id' =>            $txn_id,
+        'status' =>            $status,
+        'custom' =>            $custom,
+        'item_name' =>         $item_name,
+        'item_number' =>       $item_number,
+        'needs_review' =>      $needs_review,
+        'payment_status' =>    $payment_status,
+        'mc_gross' =>          $mc_gross,
+        'mc_currency' =>       $mc_currency,
+        'receiver_email' =>    $receiver_email,
+        'payer_email' =>       $payer_email,
+        'log' =>               $log,
+        'txn_type' =>          $txn_type,
+        'subscr_id' =>         $subscr_id,
+        'user_id' =>           $user_id,
+        'ipn_at' =>            time()
+    ];
 
-       db_insert_assoc('paypal_ipn', $row);
-       $row['id'] = $ipn_id = db_auto_id();
+    db_insert_assoc('paypal_ipn', $row);
+    $row['id'] = $ipn_id = db_auto_id();
 
-       if($status !== 'verified') {    # it's really from PayPal
-               paypal_ipn_main_debug("status is not \"verified\" but is \"$status\"");
-       } elseif ($txn_type !== 'subscr_payment' && $txn_type !== 'web_accept') {
-               if ($txn_type !== 'subscr_signup' && $txn_type !== 'subscr_cancel' && $txn_type !== 'subscr_eot') {
-                       # subscr_cancel is sent when they cancel. After that:
-                       # subscr_eot is sent when their next payment would have been
-                       paypal_ipn_main_debug("txn_type is not \"subscr_payment\", \"subscr_signup\", \"subscr_cancel\", \"subscr_eot\" or \"web_accept\" but is \"$txn_type\"");
-               }
-       } elseif ($payment_status !== 'Completed') { # payment has completed
-               if ($payment_status !== 'Pending') {
-                       paypal_ipn_main_debug("payment_status is not \"Completed\" or \"Pending\", but is \"$payment_status\"");
-               }
-       } elseif ($receiver_email !== $GLOBALS['paypal_email']) {
-               paypal_ipn_main_debug("payment isn't to us ($GLOBALS[paypal_email]) but to \"$receiver_email\"");
-       } elseif ($mc_currency !== 'USD') {
-               paypal_ipn_main_debug("Currency isn't \"USD\" but is \"$mc_currency\"");
-       } else {
-               $custom_words = explode(' ', $custom);
-               if (!isset($GLOBALS['payment_handlers'][$custom_words[0]])) {
-                       paypal_ipn_main_debug("\$custom's first word isn't in GLOBALS[payment_handlers]. \$custom: \"$custom\"");
-               } else {
-                       $ret = file_run($GLOBALS['payment_handlers'][$custom_words[0]], $custom_words, $mc_gross, $row);
-                       if ($ret and is_array($ret) and isset($ret['success']) and $ret['success']) {
-                               $update = ['processed' => '1'];
-                               if (isset($ret['for_table_id']) and isset($ret['for_row_id'])) {
-                                       $tid = format_int_0((string)$ret['for_table_id']);
-                                       $rid = format_int_0((string)$ret['for_row_id']);
-                                       if ((int)$tid > 0 and (int)$rid > 0) {
-                                               $update['for_table_id'] = $tid;
-                                               $update['for_row_id'] = $rid;
-                                       }
-                               }
-                               db_update_assoc('paypal_ipn', $update);
-                       } else {
-                               paypal_ipn_main_debug($user, $old_date, $was_expired);
-                       }
-               }
-       }
+    if($status !== 'verified') {    # it's really from PayPal
+        paypal_ipn_main_debug("status is not \"verified\" but is \"$status\"");
+    } elseif ($txn_type !== 'subscr_payment' && $txn_type !== 'web_accept') {
+        if ($txn_type !== 'subscr_signup' && $txn_type !== 'subscr_cancel' && $txn_type !== 'subscr_eot') {
+            # subscr_cancel is sent when they cancel. After that:
+            # subscr_eot is sent when their next payment would have been
+            paypal_ipn_main_debug("txn_type is not \"subscr_payment\", \"subscr_signup\", \"subscr_cancel\", \"subscr_eot\" or \"web_accept\" but is \"$txn_type\"");
+        }
+    } elseif ($payment_status !== 'Completed') { # payment has completed
+        if ($payment_status !== 'Pending') {
+            paypal_ipn_main_debug("payment_status is not \"Completed\" or \"Pending\", but is \"$payment_status\"");
+        }
+    } elseif ($receiver_email !== $GLOBALS['paypal_email']) {
+        paypal_ipn_main_debug("payment isn't to us ($GLOBALS[paypal_email]) but to \"$receiver_email\"");
+    } elseif ($mc_currency !== 'USD') {
+        paypal_ipn_main_debug("Currency isn't \"USD\" but is \"$mc_currency\"");
+    } else {
+        $custom_words = explode(' ', $custom);
+        if (!isset($GLOBALS['payment_handlers'][$custom_words[0]])) {
+            paypal_ipn_main_debug("\$custom's first word isn't in GLOBALS[payment_handlers]. \$custom: \"$custom\"");
+        } else {
+            $ret = file_run($GLOBALS['payment_handlers'][$custom_words[0]], $custom_words, $mc_gross, $row);
+            if ($ret and is_array($ret) and isset($ret['success']) and $ret['success']) {
+                $update = ['processed' => '1'];
+                if (isset($ret['for_table_id']) and isset($ret['for_row_id'])) {
+                    $tid = format_int_0((string)$ret['for_table_id']);
+                    $rid = format_int_0((string)$ret['for_row_id']);
+                    if ((int)$tid > 0 and (int)$rid > 0) {
+                        $update['for_table_id'] = $tid;
+                        $update['for_row_id'] = $rid;
+                    }
+                }
+                db_update_assoc('paypal_ipn', $update);
+            } else {
+                paypal_ipn_main_debug($user, $old_date, $was_expired);
+            }
+        }
+    }
 }
 
 function paypal_ipn_main_debug($message) {
-       $message = this_host() . ' paypal payment failure ' . $_POST['ipn_track_id'] . "\n\n" . $message;
-       $message .= "\n\nDump of all info received:\n";
-       foreach ($_POST as $key => $value) {
-               $message .= "\t$key: $value\n";
-       }
-       $template_vars = ['details' => $message];
-       email_with_template(null, 'backend_debug', $template_vars);
+    $message = this_host() . ' paypal payment failure ' . $_POST['ipn_track_id'] . "\n\n" . $message;
+    $message .= "\n\nDump of all info received:\n";
+    foreach ($_POST as $key => $value) {
+        $message .= "\t$key: $value\n";
+    }
+    $template_vars = ['details' => $message];
+    email_with_template(null, 'backend_debug', $template_vars);
 }
 
 # this file is accessed directly from the paypal IPN system
index 9541cd5..9358bb0 100644 (file)
 <!DOCTYPE html>
 <html lang="en">
 <head>
-       <title>~$title html~~$cms_title html~</title>
-       <meta name="viewport" content="width=device-width, user-scalable=no" />
-       <link rel="stylesheet" href="css.css?m=~css.css mtime~" />
-       <!--~$meta_description nonempty {~--><meta name="description" content="~$meta_description attr~" /><!--~}~-->
-       <!--~$meta_keywords nonempty {~--><meta name="keywords" content="~$meta_keywords attr~" /><!--~}~-->
-       <!--~$cms_css~-->
-       <!--~$head~-->
+    <title>~$title html~~$cms_title html~</title>
+    <meta name="viewport" content="width=device-width, user-scalable=no" />
+    <link rel="stylesheet" href="css.css?m=~css.css mtime~" />
+    <!--~$meta_description nonempty {~--><meta name="description" content="~$meta_description attr~" /><!--~}~-->
+    <!--~$meta_keywords nonempty {~--><meta name="keywords" content="~$meta_keywords attr~" /><!--~}~-->
+    <!--~$cms_css~-->
+    <!--~$head~-->
 </head>
 
 <body id="~$basename~_body" class="real_body_tag">
-       <div class="centerer ~$layout_centerer_class~">
+    <div class="centerer ~$layout_centerer_class~">
 
-               <header id="site_header">
-                       <!--~$admin_links {~-->
-                               <div id="admin_links">You are logged in as an administrator. &nbsp; <a href="admin_pages?~$edit_page_history_id {~edit_history_id=~$edit_page_history_id~~}~~$edit_page_id {~edit_id=~$edit_page_id~~}~~$edit_page_id unset {~~$edit_page_history_id unset {~&amp;new=1&amp;new_filename=~$basename~~}~~}~">Edit this page</a> &mdash; <a href="admin">Control panel</a> &mdash; <a href="logout">Log out</a></div>
-                       <!--~}~-->
-                       <!--~$cms_header~-->
-               </header>
-               <!--~$navbar_items once_if {~-->
-                       <nav class="nav">
-                               <form action="#" method="get">
-                                       <label for="mobile_menu_check" id="mobile_menu_button">&#9776; Menu</label>
-                                       <input type="checkbox" name="mobile_menu_check" id="mobile_menu_check">
-                                       <div>
-                                               <ul><!--~$navbar_items {~-->
-                                                       <li><a href="~filename~">~title html~</a></li><!--~}~-->
-                                               </ul>
-                                       </div>
-                               </form>
-                       </nav>
-               <!--~}~-->
+        <header id="site_header">
+            <!--~$admin_links {~-->
+                <div id="admin_links">You are logged in as an administrator. &nbsp; <a href="admin_pages?~$edit_page_history_id {~edit_history_id=~$edit_page_history_id~~}~~$edit_page_id {~edit_id=~$edit_page_id~~}~~$edit_page_id unset {~~$edit_page_history_id unset {~&amp;new=1&amp;new_filename=~$basename~~}~~}~">Edit this page</a> &mdash; <a href="admin">Control panel</a> &mdash; <a href="logout">Log out</a></div>
+            <!--~}~-->
+            <!--~$cms_header~-->
+        </header>
+        <!--~$navbar_items once_if {~-->
+            <nav class="nav">
+                <form action="#" method="get">
+                    <label for="mobile_menu_check" id="mobile_menu_button">&#9776; Menu</label>
+                    <input type="checkbox" name="mobile_menu_check" id="mobile_menu_check">
+                    <div>
+                        <ul><!--~$navbar_items {~-->
+                            <li><a href="~filename~">~title html~</a></li><!--~}~-->
+                        </ul>
+                    </div>
+                </form>
+            </nav>
+        <!--~}~-->
 
-               <div class="main">
-                       <!--~$messages once_if {~-->
-                               <div id="wfpl_messages">
-                                       <!--~$messages {~-->
-                                               <p>~message htmlbrtab~</p>
-                                               <!--~ sep {~-->
-                                                       <hr>
-                                               <!--~}~-->
-                                       <!--~}~-->
-                               </div>
-                       <!--~}~-->
+        <div class="main">
+            <!--~$messages once_if {~-->
+                <div id="wfpl_messages">
+                    <!--~$messages {~-->
+                        <p>~message htmlbrtab~</p>
+                        <!--~ sep {~-->
+                            <hr>
+                        <!--~}~-->
+                    <!--~}~-->
+                </div>
+            <!--~}~-->
 
-                       <article>
-                               ~$cms_body~
+            <article>
+                ~$cms_body~
 
-                               ~$body~
-                       </article>
-               </div>
+                ~$body~
+            </article>
+        </div>
 
-               <!--~$cms_sidebar {~-->
-                       <aside class="sidebar ~$layout_sidebar_class~">
-                               <!--~$cms_sidebar~-->
-                       </aside>
+        <!--~$cms_sidebar {~-->
+            <aside class="sidebar ~$layout_sidebar_class~">
+                <!--~$cms_sidebar~-->
+            </aside>
 
-                       <div style="clear: both"></div>
-               <!--~}~-->
+            <div style="clear: both"></div>
+        <!--~}~-->
 
-               <footer id="site_footer">
-                       ~$cms_footer~
-               </footer>
-       </div>
-       <!--~$render_timestamps {~-->
-               <script>
-                       (function() {
-                               var i02 = function (i) { return i > 9 ? i : '0' + i; };
-                               var date_to_html = function (d, include_time) {
-                                       var hours = d.getHours()
-                                       var ret = '<span class="date_time">' +
-                                               i02(d.getMonth() + 1) + '/' +
-                                               i02(d.getDate()) + '/' +
-                                               d.getFullYear();
-                                       if (include_time) {
-                                               ret += ' ' + ((hours + 11) % 12 + 1) + ':' +
-                                                       i02(d.getMinutes()) +
-                                                       (hours < 12 ? 'am' : 'pm')
-                                       }
-                                       ret += '</span>';
-                                       return ret;
-                               }
-                               window.render_timestamps = function() {
-                                       var els = document.getElementsByClassName('unix_time');
-                                       var i, d, hours;
-                                       for (i in els) {
-                                               d = new Date(1000 * parseInt(els[i].innerHTML));
-                                               els[i].innerHTML = date_to_html(d, true);
-                                       }
-                                       els = document.getElementsByClassName('unix_date');
-                                       for (i in els) {
-                                               d = new Date(1000 * parseInt(els[i].innerHTML));
-                                               els[i].innerHTML = date_to_html(d, false);
-                                       }
-                               }
-                       }).call();
-                       render_timestamps();
-               </script>
-       <!--~}~-->
+        <footer id="site_footer">
+            ~$cms_footer~
+        </footer>
+    </div>
+    <!--~$render_timestamps {~-->
+        <script>
+            (function() {
+                var i02 = function (i) { return i > 9 ? i : '0' + i; };
+                var date_to_html = function (d, include_time) {
+                    var hours = d.getHours()
+                    var ret = '<span class="date_time">' +
+                        i02(d.getMonth() + 1) + '/' +
+                        i02(d.getDate()) + '/' +
+                        d.getFullYear();
+                    if (include_time) {
+                        ret += ' ' + ((hours + 11) % 12 + 1) + ':' +
+                            i02(d.getMinutes()) +
+                            (hours < 12 ? 'am' : 'pm')
+                    }
+                    ret += '</span>';
+                    return ret;
+                }
+                window.render_timestamps = function() {
+                    var els = document.getElementsByClassName('unix_time');
+                    var i, d, hours;
+                    for (i in els) {
+                        d = new Date(1000 * parseInt(els[i].innerHTML));
+                        els[i].innerHTML = date_to_html(d, true);
+                    }
+                    els = document.getElementsByClassName('unix_date');
+                    for (i in els) {
+                        d = new Date(1000 * parseInt(els[i].innerHTML));
+                        els[i].innerHTML = date_to_html(d, false);
+                    }
+                }
+            }).call();
+            render_timestamps();
+        </script>
+    <!--~}~-->
 </body>
 </html>