Written on Monday, August 27th, 2007 by Jeremy Steele
A while back I wrote a post called, How To Stop WordPress From Auto-Creating A Htaccess File.
I figured out I messed up. I told you to comment out all 5 lines for this block of code:
generate_page_uri_index();
delete_option('rewrite_rules');
$this->wp_rewrite_rules();
if ( function_exists('save_mod_rewrite_rules') )
save_mod_rewrite_rules();
But i realized you only need to do this:
generate_page_uri_index();
delete_option('rewrite_rules');
$this->wp_rewrite_rules();
/*if ( function_exists('save_mod_rewrite_rules') )
save_mod_rewrite_rules();*/
I found this out earlier when I went to create a new page and couldn’t figure out why I kept getting 404 errors. Apparently the first few lines tell WordPress how it should handle rewrites, and the last two lines are the ones that actually write to .htaccess.
Whoops 
Written on Tuesday, August 7th, 2007 by Jeremy Steele
Just wanted to let you know I just uploaded Thiefinder 1.03. Some spelling mistakes were corrected and it now has support for ico and bmp files. Instructions were also added explaining how to keep Google, Live, and Yahoo image searches from being included.
Written on Wednesday, August 1st, 2007 by Jeremy Steele
A while back I wrote a post entitled “How To Redirect All Non-WWW Traffic To WWW“. I left out one important bit of info in that post for WordPress users.
If you update any info in the “General” options page, the redirection may no longer occur.
This happens because WordPress has a function called “flush_rules” which is called whenever you click Save in the General options page (not sure if it does it on other option pages). The function deletes the old rules then writes new ones in the .htaccess where your install is located. If you do what I did and made another htaccess there, it would simply be written over (and mucking around with permissions to prevent that is annoying and may not work, especially if your host runs PHP security extensions that run scripts under your user).
So, I looked around in the WordPress source and figured out how to prevent that from happening. The code is in the wp-includes/rewrite.php file. All I did was comment out the code inside the flush_rules() function by adding /* and */ before and after this code:
generate_page_uri_index();
delete_option('rewrite_rules');
$this->wp_rewrite_rules();
if ( function_exists('save_mod_rewrite_rules') )
save_mod_rewrite_rules();
Is now:
generate_page_uri_index();
delete_option('rewrite_rules');
$this->wp_rewrite_rules();
/*if ( function_exists('save_mod_rewrite_rules') )
save_mod_rewrite_rules();*/
I learned that you cannot comment out the first few lines, if you do you cannot create new pages, the last 2 lines are what save the data to .htaccess. Make sure you do not comment out the function declaration for flush_rules, or else you will get PHP errors.
This seemed to work perfectly for me, and now I don’t have to worry about WordPress’ “feature” becoming an annoyance.
Just a quick note: if you do this change and you want to change your blog’s URL, you should probably enable that code once more.
Written on Friday, July 20th, 2007 by Jeremy Steele
One cool effect that is popping up on a lot of sites is a nifty trick that will fade out the background then make a psuedo-window (I call it that, because it is really just a floating DIV) appear. Here is one way of doing that.
See it in action
Here in that page’s source
Here is a breakdown of the main pieces of the code.
The HTML
<div id="thewindow" style="display: none;width: 100%;height: 100%;position: absolute;left: 0px;top: 0px;">
That sets up the actual “window”, named thewindow, and sets it’s style (which can also be in an external CSS file if you’d like). Take note that it is hidden (display: none), and it has 100% height and width, and it is absolutely positioned to 0,0.
<div id="thewindowbackground" style="width: 100%;height: 100%;background-color: #000000;position: absolute;opacity: .5;filter: alpha(opacity=50);"></div>
This sets up the background section of the window, this is what fades-in (and makes the page itself appear to fade-out). It is the same size as the actual “window”, and it’s opacity can be set to whatever for now (the javascript takes care of that, so you can leave it out if you’d like to). The background shouldn’t have any content.
The opacity property is for mozilla, safari, etc, and the filter is for IE.
<div id="thewindowcontent" style="background-color: #000000;position: absolute;left: 50%;top: 50%;width: 250px; height: 250px; margin-left: -125px;margin-top: -125px;">
This is the window content. It is aligned in the center. I do that by setting left and top 50%, then setting the margin-left and top to -125px (half the width, half the height). This is where the actual content goes.
<form><input type="button" value="Close" onClick="hideWindow();"></form>
<div style="color: #ffffff;">
Hello!
</div>
A simple close button and some white text.
</div>
</div>
Don’t forget to close off thewindowcontent then thewindow!
<form><input type="button" value="Show Window" onClick="showWindow();"></form>
You can do whatever you’d like for this, but I decided to make it a button. All this does is call the Javascript function showWindow() upon a mouse click.
Now For The Javascript…
end_opacity = 50; //end opacity, 25 = 25%, 50 = 50%, 100 = 100%, etc.
increase_opacity_by = 10; //how much to increase by each time the timeout ends
timeout = 100; //timeout in milliseconds, 0 = instant fade-out
The first line is the ending opacity for thewindowbackground. I made it 50%, so it makes the page content looked grayed-out. The next line is how much the script should increase the opacity every time there is a timeout, I would recommend making this a multiple of end_opacity. Timeout is how long the script should go before increasing thewindowbackground’s opacity by increase_opacity_by.
win = document.getElementById('thewindow');
winbackground = document.getElementById('thewindowbackground');
wincontent = document.getElementById('thewindowcontent');
cur_opacity = 0;
var timer = null;
This just grabs the elements from the page, and creates the cur_opacity var. A timer object is also made, this is set every time setTimeout() is called, but it is never used. It would be useful for a “cancel” button.
function showWindow() {
if(timeout > 0) {
cur_opacity = 0;
winbackground.style.opacity = cur_opacity / 100;
winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
win.style.display = 'block';
wincontent.style.display = 'none';
timer = setTimeout("increase_opacity()",timeout);
}
else {
winbackground.style.opacity = end_opacity / 100;
winbackground.style.filter = "alpha(opacity=" + end_opacity + ")";
win.style.display = 'block';
wincontent.style.display = 'block';
}
}
That entire function is really simple. If timeout is an actual value the current opacity will be set to 0, and the background’s opacity will be set to 0. The window’s display is changed from none to block, but the window content’s display is now none (don’t want that to display until the fade is complete). The timeout is then started. If timeout is set to 0, the background is set to it’s end_opacity and the window is shown.
function increase_opacity() {
cur_opacity += increase_opacity_by;
winbackground.style.opacity = cur_opacity / 100;
winbackground.style.filter = "alpha(opacity=" + cur_opacity + ")";
if(cur_opacity < end_opacity) {
timer = setTimeout("increase_opacity()",timeout);
}
else {
wincontent.style.display = 'block';
}
}
This function will increase cur_opacity, set the background’s opacity, then figure out if we should run another timeout. Please take note that you must divide cur_opacity by 100 for the style.opacity property, which uses decimals.
function hideWindow() {
win.style.display = 'none';
}
For the close button.
Ways To Improve It
This script can pretty easily be improved. One way I can think of is to fade-in the content as well. Making the window moveable would also be pretty easy to do.
I tried this on IE 6 + 7, Firefox 2, Camino, Netscape, and Safari and it worked great on all of them.
Written on Wednesday, June 27th, 2007 by Jeremy Steele
Updated: 10/4/07 (View Change Log)
Thiefinder is a light-weight script that will log possible bandwidth theft. It is not a tool for preventing it, instead it is a tool you can use to find out who is stealing your bandwidth without looking through huge access logs.
Depending on your site’s configuration, installation can either be a breeze or a pain in the butt due to the fact you have to modify .htaccess files.
1) Get It - You can download the source code for Thiefinder here. Once downloaded change the extension to .php
2) Upload And Configure It - Generally speaking there is no real reason to change any of the settings unless you want a different log file name or if you want the log to contain more than 100 entries (the default). If you don’t know PHP don’t mess around with it too much.
Once configured, upload the script and make sure the log folder is writable. By default Thiefinder will store logs in the script’s directory. Contact your host for help setting up your permissions if you don’t know what to use.
3) Set Up .htaccess - I would recommend using code similar to this for your .htaccess files:
You can either use my .htaccess generator to get the code needed, or you can manually set it up:
RewriteEngine on
RewriteBase /
#Rewrite info for Thiefinder
#is the referer this site?
RewriteCond %{HTTP_REFERER} !^http(s)?://(.+\.)?example\.com [NC]
#is it blank?
RewriteCond %{HTTP_REFERER} !^$
#if another site is referring to this page, do rewrite magic
RewriteRule \.(jpg|jpeg|png|gif)$ /path/to/thiefinder.php [NC,L]
Replace example.com with your domain (and copy + paste and change the line to add other domains that are allowed to view your images), then change /path/to/thiefinder.php to the path to thiefinder. I highly recommend placing this .htaccess file in the directory were you store your pictures, instead of the root directory.
To keep Google, Live, and Yahoo image searches from being thrown in your log, put this code in your .htaccess file as well (above the “RewriteRule \.(jpg|jpeg|png|gif)$…” line):
RewriteCond %{HTTP_REFERER} !^https?://(.*\.)?google\.com [NC]
RewriteCond %{HTTP_REFERER} !^https?://(.*\.)?live\.com [NC]
RewriteCond %{HTTP_REFERER} !^https?://(.*\.)?yahoo\.com [NC]
4) Enjoy - As crazy as it might sound, it didn’t even take 3 seconds for my install of Thiefinder to start logging bandwidth theft on my server.
Oh yeah, if you find any bugs just let me know in the comments, and if you use this script why not show a lil’ love and link to this post?
5) WordPress Users, Read This! - If you use WordPress you may want to take a look at my article on how to keep WordPress from writing over the .htaccess file. Because it auto-creates the file when updating your blog’s preferences, Thiefinder may not load depending on how you have everything set up.
Want To Help?
If you want to help out with development, feel free to make changes to the source code and e-mail the modified source (with a list of changes) to me. I’ll review it and if the changes are useful, I will include them in the next release.
Everyone who helps out with development will be recognized in the credits and will get a link on this page. Oh, and don’t forget a warm fuzzy feeling.
If you are going to branch out and make a new project based off of Thiefinder, please leave my name in the credits and give credit where credit is due. Oh, and why not drop me an e-mail so I can list your project here?
Special Thanks
Special thanks to:
Lincoln and
Jonathan
for letting me know about bugs and helping to make Thiefinder even better!