Archive for July, 2009

RSS Enclosures in WordPress Vs Content Protection (YM)

July 31st, 2009

I have just completed an email exchange with a YM client which lasted around 50 replies and a good month. More down to my hectic schedule than anything else but I, with Googles help, have just solved it.

As you well know I work with Tim Nash over at CNMS and between us we develop and sell the Your Members plugin. The plugin protects blog content based on member levels and then provides the means to pay for access using a variety of methods. </plug>

It’s pretty standard stuff. However… What happens if you want to add some sort of streaming media to the protected section in a blog post?

It doesn’t work is the answer! Ever helpful WordPress scans the post for the presence of certain HTML strings and adds post custom fields if it gets a hit. This is the case for podcasting and flash type plugins. Normally this would be a good thing, however, not when the Object in question is supposed to be protected. A pretty bit security hole in any content protection plugin.

At the most basic level the protection can be restored using the following code…

function delete_enclosure(){
    return '';
}

add_filter( 'get_enclosed', 'delete_enclosure' );
add_filter( 'rss_enclosure', 'delete_enclosure' );
add_filter( 'atom_enclosure', 'delete_enclosure' );

The code should be put into either a new plugin or more simply your functions.php file within your theme. Dead easy!

If you understand it, the code simply picks up on any filters and removes them. Problem solved.  For YM, the next step is not to remove the enlosure if the user should have access. Additionally we don’t want to remove the enclosure if the object is outside of the protected content area. However the function above will suffice for now :)

How to recursively remove .svn directories

July 23rd, 2009

Regular readers may have clocked onto the fact that I use Subversion. Well the way it works it to keep a hidden set of directories within your checked out repository. It uses this to track any changes etc.. Each directory is called ‘.svn’ and is within each and every directory and subdirectory you have.

The problem

Now I know I am not alone in saying that when you want to upload the files to a remote server you have to do one of two things

  • Upload the files and .svn directories to your server which is likely to take twice the time and twice the disk space
  • Make a separate local copy of your files and then remove the .svn directories one by one.

I prefer to take option two although in recent months I have taken on the former through sheer laziness. I decided to look for a solution and found my answer…

The answer

For windows machines you need to create a secondary copy of your files to upload, this means it won’t wipe out your local repository files (the ones you want to keep). Next, create a ‘.bat’ file (batch file for executable scripts). The simplest way to do this is to open notepad and doing File > Save as > remove_svn.bat after copying in the code below. It needs to be saved in the root directory of your repository copy. This is important if not it will recurse all directories below the one it is placed in.

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (
  rd /s /q "%%i"
)

I have done all the hard work for you on this one.
Just click the following link:
Remove SVN Files (Windows) (82 bytes)

For Macs and other Unix based machines you need to do something similar. This time we simply run a command on the shell (or create a shell script out of it). Again this must be placed in the directory you want to recurse through.

find . -name .svn -print0 | xargs -0 rm -rf

The Credit

Credit for these snippets goes to the following sites. Whether they were the original authors or not I don’t know but credit where credit is due etc..

Mac version – http://snipplr.com/view/201/remove-all-svn-directories/
Windows Version – http://bluespark.tumblr.com/post/23853870/remove-svn-subfolders-on-windows-xp-vista

SB Pay Me

July 22nd, 2009

No that isn’t a request although feel free if you like :)

SB Pay Me is a new plugin that I have written along the same lines as those ‘Donate’ plugins you see everywhere. Well I decided that plugins like ‘Buy Me Beer’ and other similar donation type things weren’t really very professional so I wrote my own.

Features

The SB Pay Me plugin is designed to use the WordPress shortcode API (using rather predictibly sb_pay_me as a hook) to provide a very simple to integrate payment form. It is fully templated so you can very easily decide how you want it to look. I have integrated a couple of Paypal images by default but you can add your own with no problems what so ever. The currency, payment amount and description are all configurable. The latter two can be setup to be edited by the user on your site instead of sending them to Paypal and getting them to do it there. The admin interface is fully commented and straightforward to allow even the most basic of users to be able to user it.

Example

Send Money
Just a working example of the plugin.
Amount GBP
Payment For

Screenshots

Default Template

Default Template

Modified Template

Modified Template

Admin Page

Admin Page

Download
I intend to release the plugin into the extend directory but at the time of writing it was down. Use this link to get the most recent version: SB Pay Me (10.27 kB)