JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix db_get_value after mysql->mysqli upgrade
[wfpl.git] / main.php
index f5be944..6e05009 100644 (file)
--- a/main.php
+++ b/main.php
@@ -1,10 +1,10 @@
 <?php  # Transitional; supports both template APIs
 
-# 2006 Public Domain
-#
-# This file was placed into the public domain on November 16th, 2008 by its
-# sole author Jason Woofenden, so that if you need similar behavior, you can
-# copy this file into your website, and change it as needed.
+# This program is in the public domain within the United States. Additionally,
+# we waive copyright and related rights in the work worldwide through the CC0
+# 1.0 Universal public domain dedication, which can be found at
+# http://creativecommons.org/publicdomain/zero/1.0/
+
 
 # This file is meant to run for every page view. It finds PHP and HTML files
 # that match the basename of the url, and loads/executes them. It also allows
@@ -40,7 +40,7 @@ function wfpl_main($dest = false) {
 
                # if it starts with './' then it's a relative URL, redirect
                if(substr($dest, 0, 2) == './') {
-                       redirect(ereg_replace('/[^/]*$', substr($dest, 1), this_url()));
+                       redirect(preg_replace('|/[^/]*$|', substr($dest, 1), this_url()));
                        exit();
                }
 
@@ -49,8 +49,9 @@ function wfpl_main($dest = false) {
 
        } else { # no dest arg
                $basename = $_SERVER['REDIRECT_URL'];
-               $basename = ereg_replace('.*/', '', $basename);
-               $basename = ereg_replace('\.html?$', '', $basename);
+               $basename = preg_replace('|[?].*|', '', $basename); # apache 2.4.17
+               $basename = preg_replace('|.*/|', '', $basename);
+               $basename = preg_replace('|\.html?$|', '', $basename);
                if($basename == '') {
                        $basename = 'index';
                }
@@ -121,12 +122,12 @@ function wfpl_main($dest = false) {
        }
 
        # Check for $GLOBALS['wfpl_template'] because it might have been set (or unset) by the php script.
-       if($GLOBALS['wfpl_template'] || $GLOBALS['wfpl_main_template']) {
-               if($GLOBALS['wfpl_main_template']) {
+       if(isset($GLOBALS['wfpl_template']) || isset($GLOBALS['wfpl_main_template'])) {
+               if(isset($GLOBALS['wfpl_main_template'])) {
                        # if there was a template for that page, and one for the whole
                        # site, copy all template sections that have been show()n to the
                        # site-wide template
-                       if($GLOBALS['wfpl_template']) {
+                       if(isset($GLOBALS['wfpl_template'])) {
                                $GLOBALS['wfpl_main_template']->merge($GLOBALS['wfpl_template']);
                        }