Beispiel #1
0
        $do200 = 'N';
    }
    $options['do200'] = $do200;
    if (function_exists('is_multisite') && is_multisite() && function_exists('kpg_pf_global_unsetup') && function_exists('kpg_pf_global_setup')) {
        if ($kpg_pf_mu == 'N') {
            kpg_pf_global_unsetup();
            switch_to_blog(1);
            update_option('kpg_permalinfinder_options', $options);
            restore_current_blog();
        } else {
            kpg_pf_global_setup();
        }
    }
    update_option('kpg_permalinfinder_options', $options);
    echo "<h2>Options Updated</h2>";
    $options = kpg_pf_get_options();
    extract($options);
}
?>
<div class="wrap">
  <h2>Permalink-Finder Options</h2>
  <h3>Version 2.3</h3>
  <h4><?php 
echo $totredir;
?>
 Permalinks redirected</h4>
  <?php 
if ($nobuy != 'Y') {
    ?>
  <div style="width:60%;background-color:ivory;border:#333333 medium groove;padding:4px;margin-left:4px;margin-left:auto;margin-right:auto;">
    <p>This plugin is free and I expect nothing in return. You can support me by donating a dollar or so.
Beispiel #2
0
function kpg_permalink_fixer()
{
    $options = kpg_pf_get_options();
    extract($options);
    // fix request_uri on IIS
    if (!array_key_exists('REQUEST_URI', $_SERVER)) {
        $_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
        if (isset($_SERVER['QUERY_STRING'])) {
            $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
        }
    }
    $plink = $_SERVER['REQUEST_URI'];
    $pulink = $plink;
    // keeping the query - there is a chance that there is a query variable that needs to be preserved.
    // possibly a search or an update has been bookmarked.
    if (strpos($plink, '/feed/') !== false) {
        return;
    }
    $query = '';
    if (strpos($plink, '?') !== false) {
        $query = substr($plink, strpos($plink, '?'));
        $plink = substr($plink, 0, strpos($plink, '?'));
    }
    // do not redirect search queries
    if (strpos('?' . $query, '?s=') !== false) {
        return;
    }
    if (strpos($query, '&s=') !== false) {
        return;
    }
    if (strpos($plink, '#') !== false) {
        $plink = substr($plink, 0, strpos($plink, '#'));
    }
    $plink = trim($plink, '/');
    $flink = $plink;
    // flink has the page that was 404'd - not the basename
    //$plink=basename($plink); // plink now is the permalink part of the request.
    // often I found this is wrong, I want to use the wholw taxonomy in the search
    $plink = kpg_pf_more_clean($plink);
    $plink = str_replace('index.html', '', $plink);
    $plink = str_replace('index.shtml', '', $plink);
    $plink = str_replace('index.htm', '', $plink);
    $plink = str_replace('index.asp', '', $plink);
    $plink = str_replace('.html', '', $plink);
    $plink = str_replace('.shtml', '', $plink);
    $plink = str_replace('.htm', '', $plink);
    $plink = str_replace('.asp', '', $plink);
    $plink = str_replace('.aspx', '', $plink);
    // set up stats
    // now get rid of the slashes
    $reason = $plink;
    $plink = trim($plink);
    $plink = trim($plink, '/');
    $plink = str_replace('--', '-', $plink);
    // had a problem with double dashes
    $plink = str_replace('/', '-', $plink);
    // this way the taxonomy becomes part of the search
    $plink = str_replace('%20', '-', $plink);
    // spaces are wrong
    $ref = '';
    if (array_key_exists('HTTP_REFERER', $_SERVER)) {
        $ref = $_SERVER['HTTP_REFERER'];
    }
    $ref = esc_url_raw($ref);
    $ref = strip_tags($ref);
    $ref = remove_accents($ref);
    $ref = kpg_pf_really_clean($ref);
    $agent = '';
    if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
        $agent = $_SERVER["HTTP_USER_AGENT"];
    }
    $agent = strip_tags($agent);
    $agent = remove_accents($agent);
    $agent = kpg_pf_really_clean($agent);
    $agent = htmlentities($agent);
    $request = $flink;
    $request = esc_url_raw($request);
    $request = strip_tags($request);
    $request = remove_accents($request);
    $request = kpg_pf_really_clean($request);
    $request = str_replace('http://', '', $request);
    // set up stats
    $r404 = array();
    $r404[0] = date('m/d/Y H:i:s', time() + get_option('gmt_offset') * 3600);
    $r404[1] = $pulink;
    $r404[2] = $ref;
    $r404[3] = $agent;
    $r404[4] = $_SERVER['REMOTE_ADDR'];
    $r404[6] = '';
    // testing an ignore for the category
    if (strpos($plink, "/category/") !== false) {
        $cnt404++;
        $options['cnt404'] = $cnt404;
        $r404[6] = '/category/ is not redirected.';
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        return;
    }
    // do not mess with robots trying to find wp-login.php and wp-signup.php
    if (strpos($plink . "\t", "/wp-login.php\t") !== false || strpos($plink . "\t", "/wp-signup.php\t") !== false || strpos($plink . "\t", "/feed\t") !== false) {
        $cnt404++;
        $options['cnt404'] = $cnt404;
        $r404[6] = '$plink is probably a robot looking for exploits.';
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        return;
    }
    // check for bypassed or generated files
    if ($chkrobots == 'Y' && strpos(strtolower($plink) . "\t", "robots.txt\t") !== false) {
        // looking for a robots.txt
        // header out the .txt file
        $cnt404++;
        $options['cnt404'] = $cnt404;
        $r404[6] = 'display tobots.txt';
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        header('HTTP/1.1 200 OK');
        header('Content-Type: text/plain');
        echo $robots;
        exit;
    }
    if ($chkcrossdomain == 'Y' && strpos(strtolower($plink) . "\t", "crossdomain.xml\t") !== false) {
        // looking for a robots.txt
        // header out the .txt file
        $cnt404++;
        $options['cnt404'] = $cnt404;
        $r404[6] = 'display crossdomain.xml';
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        header('HTTP/1.1 200 OK');
        header('Content-Type: application/xml');
        echo '<' . '?xml version="1.0"?' . ">\r\n";
        // because of ? and stuff need to echo this separate
        ?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="<?php 
        echo $_SERVER["HTTP_HOST"];
        ?>
" />
</cross-domain-policy>
		<?php 
        exit;
    }
    if ($chkicon == 'Y' && strpos(strtolower($plink) . "\t", "favicon.ico\t") !== false) {
        // this only works if the favicon.ico is being redirected to wordpress on a 404
        $f = dirname(__FILE__) . "/includes/favicon.ico";
        if (!file_exists($f)) {
            // can't find the icon file - what's up with this???
            $r404[6] = 'did not find favicon.ico';
            kpg_find_permalink_error_log($options, $e404, $r404, $stats);
            exit;
        }
        if (file_exists($f)) {
            //if (function_exists('header_remove')) header_remove();
            ini_set('zlib.output_compression', 'Off');
            header('HTTP/1.1 200 OK');
            $r404[6] = 'display favicon.ico';
            $cnt404++;
            $options['cnt404'] = $cnt404;
            kpg_find_permalink_error_log($options, $e404, $r404, $stats);
            header('Content-Type: image/vnd.microsoft.icon');
            header('Content-Disposition: attachment; filename="favicon.ico"');
            header('Content-Length: ' . filesize($f));
            readfile($f);
            exit;
        }
    }
    /*
    	apple-touch-icon-57x57-precomposed.png
    	apple-touch-icon-57x57.png
    	apple-touch-icon-precomposed.png
    	apple-touch-icon.png
    */
    if ($chkicon == 'Y' && (strpos(strtolower($plink) . "\t", "apple-touch-icon.png\t") !== false || strpos(strtolower($plink) . "\t", "apple-touch-icon-57x57.png\t") !== false || strpos(strtolower($plink) . "\t", "apple-touch-icon-precomposed.png\t") !== false || strpos(strtolower($plink) . "\t", "apple-touch-icon.png\t") !== false)) {
        // this only works if the favicon.ico is being redirected to wordpress on a 404
        $f = dirname(__FILE__) . "/includes/apple-touch-icon.png";
        if (file_exists($f)) {
            if (function_exists('header_remove')) {
                header_remove();
            }
            ini_set('zlib.output_compression', 'Off');
            $r404[6] = 'display apple-touch-icon.png';
            $cnt404++;
            $options['cnt404'] = $cnt404;
            kpg_find_permalink_error_log($options, $e404, $r404, $stats);
            header('HTTP/1.1 200 OK');
            header('Content-Type: image/png');
            readfile($f);
            exit;
        }
    }
    //	if anyone is asking for a feed that does not exist, send them the sitemap
    if (strpos(strtolower($plink) . "\t", "feed\t") !== false) {
        // if there is no sitemap, return the last 20 entries made
        $r404[6] = 'feed send sitemap.xml';
        $cnt404++;
        $options['cnt404'] = $cnt404;
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        header('HTTP/1.1 200 OK');
        header('Content-Type: application/xml');
        $sitemap = kpg_pf_sitemap();
        exit;
    }
    if ($chksitemap == 'Y' && strpos(strtolower($plink) . "\t", "sitemap.xml\t") !== false) {
        // if there is no sitemap, return the last 20 entries made
        $r404[6] = 'display sitemap.xml';
        $cnt404++;
        $options['cnt404'] = $cnt404;
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        header('HTTP/1.1 200 OK');
        header('Content-Type: application/xml');
        $sitemap = kpg_pf_sitemap();
        exit;
    }
    if ($chkdublin == 'Y' && strpos(strtolower($plink) . "\t", "dublin.rdf\t") !== false) {
        // dublin.rdf is a little used method for robots to get more info about your site
        $r404[6] = 'display dublin.rdf';
        $cnt404++;
        $options['cnt404'] = $cnt404;
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        header('HTTP/1.1 200 OK');
        header('Content-Type: application/xml');
        echo '<' . '?xml version="1.0"?' . '>';
        // because of ? and stuff need to echo this separate
        ?>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc= "http://purl.org/dc/elements/1.1/">
 <rdf:Description rdf:about="<?php 
        echo get_home_url();
        ?>
">
 <dc:contributor><?php 
        echo get_bloginfo('name');
        ?>
</dc:contributor>
 <dc:date><?php 
        echo date('Y-m-d', time() + get_option('gmt_offset') * 3600);
        ?>
</dc:date>
 <dc:description><?php 
        echo get_bloginfo('description');
        ?>
</dc:description>
 <dc:language><?php 
        echo get_bloginfo('language');
        ?>
</dc:language>
 <dc:publisher></dc:publisher>
 <dc:source><?php 
        echo get_home_url();
        ?>
</dc:source>
 </rdf:Description>
 </rdf:RDF>

	<?php 
        exit;
    }
    if ($chkopensearch == 'Y' && (strpos(strtolower($plink) . "\t", "opensearch.xml\t") !== false || strpos(strtolower($plink) . "\t", "search.xml\t") !== false)) {
        // search.xml may hel people search your site.
        $r404[6] = 'display opensearch.xml';
        $cnt404++;
        $options['cnt404'] = $cnt404;
        kpg_find_permalink_error_log($options, $e404, $r404, $stats);
        header('HTTP/1.1 200 OK');
        header('Content-Type: application/xml');
        echo '<' . '?xml version="1.0"?' . ">\r\n";
        // because of ? and stuff need to echo this separate
        ?>
 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
 <ShortName><?php 
        echo get_bloginfo('name');
        ?>
</ShortName>
 <Description>Search this site</Description>
 <Image>favicon.ico</Image>
 <Url type="text/html" template="<?php 
        echo get_home_url();
        ?>
/seach"/>
 </OpenSearchDescription>
 

	<?php 
        exit;
    }
    // some file types should not be included. these files are true 404s and Wordpress can't fix that.
    $ignoreTypes = array('jpg', 'gif', 'png', 'pdf', 'txt', 'asp', 'php', 'cfm', 'js', 'xml', 'php', 'mp3', 'wmv', 'css');
    foreach ($ignoreTypes as $it) {
        if (strpos(strtolower($plink) . "\t", '.' . $it . "\t") !== false) {
            $r404[6] = "request for non WP file:.{$it}";
            $cnt404++;
            $options['cnt404'] = $cnt404;
            kpg_find_permalink_error_log($options, $e404, $r404, $stats);
            return;
        }
    }
    // santize to get rid of all odd characters, including cross browser scripts.
    $plink = strtolower($plink);
    // make it case insensitive
    // do some more cleanup
    $plink = urldecode($plink);
    $plink = strip_tags($plink);
    $plink = remove_accents($plink);
    $plink = kpg_pf_really_clean($plink);
    $plink = str_replace('_', '-', $plink);
    $plink = str_replace(' ', '-', $plink);
    $plink = str_replace('%20', '-', $plink);
    $plink = str_replace('%22', '-', $plink);
    $plink = str_replace('/archive/', '-', $plink);
    $plink = sanitize_title_with_dashes($plink);
    // gets rid of some words that wordpress things are unimportant
    // check if the incoming line needs a blogger fix
    // for looking for recursive redirects
    $old_link = $_SERVER['REQUEST_URI'];
    if (empty($plink)) {
        // redirect back to siteurl
        $flink = home_url();
        // recursion check
        if ($flink == $old_link || $flink == $old_link . $query) {
            $r404[5] = $flink;
            $cntredir++;
            $options['cntredir'] = $cntredir;
            $totredir++;
            $options['totredir'] = $totredir;
            $r404[6] = "Recursive redirect on home url, returning to wordpress ";
            kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
            return;
        }
        $r404[5] = $flink;
        $cntredir++;
        $options['cntredir'] = $cntredir;
        $totredir++;
        $options['totredir'] = $totredir;
        $r404[6] = "empty search, send to home";
        kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
        wp_redirect($flink . $query, (int) $kpg_pf_301);
        // let wp do it - more compatable.
        exit;
    }
    if ($labels == 'Y') {
        if (strpos($flink, '/labels/') > 0) {
            if ($flink == $old_link || $flink == $old_link . $query) {
                $r404[5] = $flink;
                $cntredir++;
                $options['cntredir'] = $cntredir;
                $totredir++;
                $options['totredir'] = $totredir;
                $r404[6] = "Recursive redirect on label url, returning to wordpress ";
                kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
                return;
            }
            $flink = str_replace('/labels/', '/category/', $flink);
            $flink = str_replace('.html', '', $flink);
            // get dir of html and shtml at the end - don't need to search for these
            $flink = str_replace('.shtml', '', $flink);
            $flink = str_replace('.htm', '', $flink);
            $flink = str_replace('_', '-', $flink);
            // underscores should be dashes
            $flink = str_replace('.', '-', $flink);
            // periods should be dashes
            $flink = str_replace(' ', '-', $flink);
            // spaces are wrong
            $flink = str_replace('%20', '-', $flink);
            // spaces are wrong
            $flink = str_replace('%22', '-', $flink);
            // spaces are wrong
            $flink = str_replace('"', '-', $flink);
            // spaces are wrong
            $r404[5] = $flink;
            $r404[6] = "Redirect /label/ to /category/";
            $cntredir++;
            $options['cntredir'] = $cntredir;
            $totredir++;
            $options['totredir'] = $totredir;
            kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
            wp_redirect($flink . $query, (int) $kpg_pf_301);
            // let wp do it - more compatable.
            exit;
        }
    }
    // check to see if the user is coming in on a base default
    // now figure if we need to fix a permalink
    //echo "\r\n\r\n<!-- step 2 $find -->\r\n\r\n";
    if ($find > 0) {
        $plink = str_replace('.html', '', $plink);
        // get dir of html and shtml at the end - don't need to search for these
        $plink = str_replace('.shtml', '', $plink);
        $plink = str_replace('.htm', '', $plink);
        $plink = str_replace('.asp', '', $plink);
        // first check for the original slug - use the wordpress slug fixer on it.
        if (strpos(strtolower($flink) . "\t", "/index.html\t") !== false) {
            $flink = substr($flink . "\t", 0, strpos(strtolower($flink) . "\t", "/index.html\t"));
        }
        if (strpos(strtolower($flink) . "\t", "/index.htm\t") !== false) {
            $flink = substr($flink . "\t", 0, strpos(strtolower($flink) . "\t", "/index.htm\t"));
        }
        if (strpos(strtolower($flink) . "\t", "/index.shtml\t") !== false) {
            $flink = substr($flink . "\t", 0, strpos(strtolower($flink) . "\t", "/index.shtml\t"));
        }
        if (strpos(strtolower($flink) . "\t", "/default.asp\t") !== false) {
            $flink = substr($flink . "\t", 0, strpos(strtolower($flink) . "\t", "/default.asp\t"));
        }
        $flink = basename($flink);
        $flink = str_replace('.html', '', $flink);
        // get dir of html and shtml at the end - don't need to search for these
        $flink = str_replace('.shtml', '', $flink);
        $flink = str_replace('.htm', '', $flink);
        $flink = str_replace('_', '-', $flink);
        // underscores should be dashes
        $flink = str_replace('.', '-', $flink);
        // periods should be dashes
        $flink = str_replace(' ', '-', $flink);
        // spaces are wrong
        $flink = str_replace('%20', '-', $flink);
        // spaces are wrong
        $flink = str_replace('http://', '', $flink);
        $flink = str_replace('https://', '', $flink);
        $flink = sanitize_url($flink);
        $flink = str_replace('http://', '', $flink);
        $flink = str_replace('https://', '', $flink);
        $flink = str_replace('%22', '-', $flink);
        // spaces are wrong
        $flink = str_replace('"', '-', $flink);
        // spaces are wrong
        // check for matches to slugs
        // start with a check to category
        $ID = false;
        $cnt = 0;
        $reason = "working...";
        $cat = '';
        if ($chkcat == 'Y') {
            $cat = get_category_by_slug($flink);
            // if exact match on the category slug we can do a redirect right now.
            if (!empty($cat)) {
                // need to redirect to the category
                //echo "\r\n\r\n\r\n";
                //print_r($cat);
                $ID = $cat->cat_ID;
                //echo "\r\n\r\n\r\n";
                //exit();
            } else {
                $ID = false;
            }
        }
        if (empty($ID)) {
            $ID = false;
        }
        if ($ID === false) {
            $ID = kpg_find_permalink_post_direct($flink);
        }
        if (empty($ID)) {
            $ID = false;
        }
        if ($ID !== false) {
            // redirect directly to the link now
            $cnt = 1;
            $reason = "(1) exact match to slug {$plink} {$flink}";
            if (!empty($cat)) {
                $reason = "exact match to Category slug {$flink}";
            }
        }
        // check - exact matches on flink
        if ($ID === false) {
            $ansa = kpg_find_permalink_post_exact($flink, $find, $kpg_pf_numbs, $kpg_pf_common, $kpg_pf_short);
            $ID = $ansa[0];
            $cnt = $ansa[1];
            $reason = "Found {$cnt} exact word matches to slug {$plink} {$flink}";
            if (empty($ID)) {
                $ID = false;
            }
        }
        if ($ID === false && $chkloose == 'Y') {
            $ansa = kpg_find_permalink_post_loose($flink, $find, $kpg_pf_numbs, $kpg_pf_common, $kpg_pf_short);
            $ID = $ansa[0];
            $cnt = $ansa[1];
            $reason = "Found {$cnt} loose word matches to {$flink}";
            if (empty($ID)) {
                $ID = false;
            }
        }
        if ($ID === false && $chkfullurl == 'Y') {
            $ansa = kpg_find_permalink_post_exact($plink, $find, $kpg_pf_numbs, $kpg_pf_common, $kpg_pf_short);
            $ID = $ansa[0];
            $cnt = $ansa[1];
            $reason = "Found {$cnt} exact word matches to {$plink}";
            if (empty($ID)) {
                $ID = false;
            }
        }
        if ($ID === false && $chkloose == 'Y' && $chkfullurl == 'Y') {
            $ansa = kpg_find_permalink_post_loose($plink, $find, $kpg_pf_numbs, $kpg_pf_common, $kpg_pf_short);
            $ID = $ansa[0];
            $cnt = $ansa[1];
            $reason = "Found {$cnt} loose word matches to {$plink}";
            if (empty($ID)) {
                $ID = false;
            }
        }
        if ($ID === false && $chkmetaphone == 'Y') {
            // missed on regular words - try a metaphone search?? Only do it on original slug
            $ansa = kpg_find_permalink_post_metaphone($flink, $find, $kpg_pf_numbs, $kpg_pf_common, $kpg_pf_short);
            $ID = $ansa[0];
            $cnt = $ansa[1];
            if ($ID !== false) {
                $reason = "Found {$cnt} metaphone 'sounds-like' word matches to {$flink}";
            } else {
                $reason = "failed all searches";
            }
            if (empty($ID)) {
                $ID = false;
            }
        }
        if ($ID === false && $chkmetaphone == 'Y' && $chkfullurl == 'Y') {
            // missed on regular words - try a metaphone search?? Only do it on original slug
            $ansa = kpg_find_permalink_post_metaphone($plink, $find, $kpg_pf_numbs, $kpg_pf_common, $kpg_pf_short);
            $ID = $ansa[0];
            $cnt = $ansa[1];
            if ($ID !== false) {
                $reason = "Found {$cnt} metaphone 'sounds-like' word matches to {$plink}";
            } else {
                $reason = "failed all searches";
            }
            if (empty($ID)) {
                $ID = false;
            }
        }
        if ($ID !== false) {
            // got the page
            if (!empty($cat)) {
                $link = get_category_link($ID);
            } else {
                $link = get_permalink($ID);
            }
            if ($do200 == 'Y') {
                // here we display the page
                $r404[5] = $link;
                $r404[6] = $reason . " -page loaded direct '{$ID}'";
                $cntredir++;
                $options['cntredir'] = $cntredir;
                $totredir++;
                $options['totredir'] = $totredir;
                kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
                header("HTTP/1.1 200 Ok");
                if (kpg_pf_load_page($ID)) {
                    exit;
                }
                $r404[5] = $link;
                $r404[6] = $reason . " page not found '{$ID}'";
                $cntredir++;
                $options['cntredir'] = $cntredir;
                $totredir++;
                $options['totredir'] = $totredir;
                kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
            }
            if (!empty($link)) {
                if ($link == $old_link || $link == $old_link . $query) {
                    $r404[5] = $flink;
                    $cntredir++;
                    $options['cntredir'] = $cntredir;
                    $totredir++;
                    $options['totredir'] = $totredir;
                    $r404[6] = "Recursive redirect on url, returning to wordpress ";
                    kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
                    return;
                }
                $r404[5] = $_SERVER['REQUEST_URI'] . '/' . $link;
                $r404[6] = $reason;
                $cntredir++;
                $options['cntredir'] = $cntredir;
                $totredir++;
                $options['totredir'] = $totredir;
                kpg_find_permalink_fixed_log($options, $f404, $r404, $stats);
                wp_redirect($link . $query, (int) $kpg_pf_301);
                // let wp do it - more compatable.
                exit;
            }
        }
    }
    // still here, it must be a real 404, we should log it
    $reason = "Not found - slug:{$flink}, loose url:{$plink}";
    //echo "\r\n\r\n<!-- step 5 -->\r\n\r\n";
    $cnt404++;
    $options['cnt404'] = $cnt404;
    $r404[6] = $reason;
    kpg_find_permalink_error_log($options, $e404, $r404, $stats);
    return;
    // end of permalink fixer
}
function kpg_pf_html_filter($query)
{
    if (empty($query)) {
        return $query;
    }
    // see if the query ends in html, htm, shtml with or without a trailing slash
    // this does a very late get_option because we don't want to load options on every page.
    $fixhtml = '?';
    $fixup = array('/index.html/', '/index.shtml/', '/index.htm/', '/index.html', '/index.shtml', '/index.htm', '.html/', '.shtml/', '.htm/', '.html', '.shtml', '.htm');
    if (array_key_exists('pagename', $query->query_vars) && !empty($query->query_vars['pagename'])) {
        $pn = $query->query_vars['pagename'];
        foreach ($fixup as $f) {
            if (stripos($pn, $f) !== false) {
                // found something to fixup
                // first need to check if we really should be doing this.
                if ($fixhtml == '?') {
                    $options = kpg_pf_get_options();
                    // delay this until it is actually needed.
                    $fixhtml = $options['fixhtml'];
                }
                if ($fixhtml == 'Y') {
                    // fix it and break;
                    if (function_exists('str_ireplace')) {
                        // in case someone tries to run this on php4
                        $pn = str_ireplace($f, '', $pn);
                    } else {
                        $pn = str_replace($f, '', $pn);
                    }
                    if (substr($pn, -1) == '/') {
                        $pn = substr($pn, 0, -1);
                    }
                    // remove trailing slash
                    $query->query_vars['pagename'] = $pn;
                    if (function_exists('set_query_var')) {
                        set_query_var('pagename', $pn);
                    }
                    break;
                } else {
                    return $query;
                }
                // ain't sposd to be here
            }
        }
    }
    if (array_key_exists('name', $query->query_vars) && !empty($query->query_vars['name'])) {
        $pn = $query->query_vars['name'];
        foreach ($fixup as $f) {
            if (stripos($pn, $f) !== false) {
                if ($fixhtml == '?') {
                    $options = kpg_pf_get_options();
                    // delay this until it is actually needed.
                    $fixhtml = $options['fixhtml'];
                }
                if ($fixhtml == 'Y') {
                    // fix it and break;
                    if (function_exists('str_ireplace')) {
                        // in case someone tries to run this on php4
                        $pn = str_ireplace($f, '', $pn);
                    } else {
                        $pn = str_replace($f, '', $pn);
                    }
                    if (substr($pn, -1) == '/') {
                        $pn = substr($pn, 0, -1);
                    }
                    // remove trailing slash
                    $query->query_vars['name'] = $pn;
                    if (function_exists('set_query_var')) {
                        set_query_var('pagename', $pn);
                    }
                    break;
                } else {
                    return $query;
                }
            }
        }
    }
    if (isset($query->query_string)) {
        $pn = $query->query_string;
        foreach ($fixup as $f) {
            if (stripos($pn, $f) !== false) {
                if ($fixhtml == '?') {
                    $options = kpg_pf_get_options();
                    // delay this until it is actually needed.
                    $fixhtml = $options['fixhtml'];
                }
                if ($fixhtml == 'Y') {
                    // fix it and break;
                    if (function_exists('str_ireplace')) {
                        $pn = str_ireplace($f, '', $pn);
                    } else {
                        $pn = str_replace($f, '', $pn);
                        $query->query_string = $pn;
                        if (function_exists('set_query_var')) {
                            set_query_var('pagename', $pn);
                        }
                        break;
                    }
                } else {
                    return $query;
                }
            }
        }
    }
    if (isset($query->request)) {
        $pn = $query->request;
        foreach ($fixup as $f) {
            if (stripos($pn, $f) !== false) {
                if ($fixhtml == '?') {
                    $options = kpg_pf_get_options();
                    // delay this until it is actually needed.
                    $fixhtml = $options['fixhtml'];
                }
                if ($fixhtml == 'Y') {
                    // fix it and break;
                    if (function_exists('str_ireplace')) {
                        $pn = str_ireplace($f, '', $pn);
                    } else {
                        $pn = str_replace($f, '', $pn);
                        $query->{$query}->request = $pn;
                        if (function_exists('set_query_var')) {
                            set_query_var('pagename', $pn);
                        }
                        break;
                    }
                } else {
                    return $query;
                }
            }
        }
    }
    if (isset($query->matched_query)) {
        $pn = $query->matched_query;
        foreach ($fixup as $f) {
            if (stripos($pn, $f) !== false) {
                if ($fixhtml == '?') {
                    $options = kpg_pf_get_options();
                    // delay this until it is actually needed.
                    $fixhtml = $options['fixhtml'];
                }
                if ($fixhtml == 'Y') {
                    // fix it and break;
                    if (function_exists('str_ireplace')) {
                        $pn = str_ireplace($f, '', $pn);
                    } else {
                        $pn = str_replace($f, '', $pn);
                        $query->{$query}->matched_query = $pn;
                        if (function_exists('set_query_var')) {
                            set_query_var('pagename', $pn);
                        }
                        break;
                    }
                } else {
                    return $query;
                }
            }
        }
    }
    return $query;
}