Archive

Archive for the ‘PHP’ Category

Patch for the VastHTML Wordpress Forum Server

March 3rd, 2010

So, I’ve made a number of fixes to the VastHTML Wordpress forum server plugin. It has some pretty big bugs, and I don’t know if the project is being maintained anymore or not. At any rate, the fixes I’ve made should have been considered critical and should have been fixed long ago by whoever is maintaining it, but I digress…

I’m not going to support people trying to apply this patch. If you don’t know what a diff is and you don’t know what the patch command does, you’re probably out of luck. If you want me to fix all of the problems in this code and release it, pay me a bunch of money…

Also, the security problems in their code makes babies cry… but that’s for another day.

Lastly, to make the search actually work, you need to connect to your wordpress mysql database and issue this SQL statement:

alter table wp_forum_posts add fulltext key `text` (`text`);

Here's the patch: vasthtml-forum-server.diff

Here's what it fixes (in no particular order):

  • RSS feeds now contain the username of the poster instead of "feeds@r.us"
  • All & characters in the links have been properly changed to & as they should be
  • Page 2+ of your forums will work
  • Page 2+ of posts will work
  • The number of replies shown in the topic list is properly set to number of posts - 1
  • The title delimeter is changed from » to "|" (don't remember why i did this, but there ya go)
  • The search form/box uses HTTP GET instead of POST so your back button works without complaining about having to resubmit your request
  • You can press enter in the search box to submit
  • A $ followed by a number doesn't get filtered out
  • Apostrophes in posts/titles get their slashes properly stripped

I may have fixed other things in this patch and forgot about it. This works for me... your mileage may vary.

eric General, PHP , ,

Got a PS3? Want Hulu Back? Easy enough…

June 29th, 2009

Update Jan 6, 2010: Some users are reporting that they’re getting an error telling them they need to update Flash. I imagine we’re going to have to wait for Sony to update the PS3 firmware with a new Flash version.


Over the weekend Hulu stopped working for PS3 users. How did they block the PS3 users? With the dumbest method they could find. They test the User-Agent string in the HTTP request. Well, luckily, we can use a proxy server and just rewrite it. Windows users may want to look here

1. Install squid (”sudo apt-get install squid” for ubuntu users…. for Windows users, google for: squid windows)

2. Edit squid’s default config (/etc/squid/squid.conf on ubuntu) with these changes (or download my configuration: squid-hulu.conf):

Search for “acl localnet src” and set it to your internal network. You can remove the other localnet definitions if you’re not using them as shown here:

#acl localnet src 10.0.0.0/8
#acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16

Note: For 99.9999% of you, the correct line will be “acl localnet src 192.168.0.0/16″

After the “acl localnet src” line, add this:

acl hulu url_regex -i ^http://.*.hulu.com/.*

Search for “http_access allow localhost” and add “http_access allow localnet” as such:

http_access allow localnet
http_access allow localhost

Add the following two lines pretty much anywhere in the file (the end of the file works just fine):

header_access User-Agent deny hulu
header_replace User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)

3. Start squid (sudo /etc/init.d/squid start)

4. Go to PS3 Internet settings. Do manual configure. Go through the settings as normal (the defaults should be fine) until you get to proxy server. Set it to be your PC’s IP address port 3128.

Your PS3 is now a Windows machine running Firefox (as far as Hulu is concerned) and you can use Hulu again. What a dumb method of restricting access.

UPDATE – Jul 30 2009: To all of you guys out there saying “Why don’t you just use PlayOn or TVersity?” My response is:



from eric to MediaMall Support
date Mon, Jun 29, 2009 at 10:00 AM

I assume you're saying that there's no plan for a Linux version then?

from MediaMall Support to eric
date Mon, Jun 29, 2009 at 10:03 AM

Correct.


That was the response I received. TVersity is quite obviously intertwined with Windows and there is no hope there either. The users that support the invasive DRM (by using it) are responsible for open protocols not being available. If you want to know why DRM is successful, you need only look in the mirror.

UPDATED – Aug 10 2009: As requested in the comments, the instructions now make it so that only hulu will get the header replaced. Also, the comments section has tips and hints for Windows users and squid version 3.0+. See:

Some more Windows Info

Squid 3.0+ Info

eric GTFS, General, PHP, PlayStation3 , , ,

Categorizing Your Movie Collection with IMDB

June 17th, 2009

If you have a ton of movies like I do, scrolling through the full list on the PS3 is painful. After about 100 movies or so, you realize that you need a better method of doing it.

Well if you’re on Linux, you are in luck! As I started categorizing stuff by hand, I ran into another unrelated problem. While I was searching for the solution, I came across IMDB-to-MPEG. I had to hack around a bit in the PHP code to get it to work the way I wanted, but man did it save a lot of time. I fixed a number of things and submitted it back to the author, so hopefully we’ll see a new version soon.

Basically, you give it a movie name and it queries IMDB for the movie. Based on the IMDB Genres and Ratings, it creates your symlink tree for you. So in the PS3 XMB, when you go t your movie server you have all of your movies categorized by Genre so you can get a list of all Action movies, for example. Of course, since it’s all just symlinks, you can have the same movie covering multiple genres. So for a military crime drama — such as A Few Good Men — it would be listed under all 3 genres of Military, Crime, and Drama.

But it also had another interesting feature. It creates a MPEG video file that you can play from your uPnP client that gives you IMDB info, like the plot, the year, the ratings, etc.

This is what the original looked like: About Army of Darkness.m4v

This is what my latest version looks like: About Army of Darkness.m4v

And if you have an HTML 5 browser, here it is with the video tag (in Ogg Video format):

I wish I knew a good algorithm for making motion more fluid. The animation frames look jerky. I’m sure I need to blur or leave trails or something, but my attempts have all been failures.

eric General, PHP , ,

jsmin as a PHP extension – JavaScript Minify the Fast Way

June 11th, 2009

Yahoo’s performance docs and Google’s page speed best practices recommend that both external and inline javascript code is minified. Two popular tools for minifying JavaScript are JSMIN and YUI Compressor.

I needed to have an efficient solution that can minify javascript on the fly. Unfortunately these tools do not work because a process would need to be forked every time minification needed to be performed. In PHP, one possible solution is to use jsmin-php, but again this is a very slow option. jsmin-php is written in PHP code and parsing a JavaScript file in PHP is relatively slow.

So I decided to develop a php extension based on jsmin.c developed by Douglas Crockford. It creates a native PHP function included as a PHP extension (written in C as opposed to PHP). The speed and efficiency improvement over jsmin-php is over 25x!

Try it out!

Get it here

Install instructions (make sure you have development tools installed as well as PHP and its development components):
tar zxf php-jsmin-1.0.tgz
cd php-jsmin-1.0
phpize
sh ./configure
make
make install
(optional) in php.ini add the following line: extensions=jsmin.so

Sample code:

if (!extension_loaded('jsmin')) {
        dl('jsmin.so');
}
header('Content-Type: text/javascript');
echo jsmin(file_get_contents('my.js'));

I hope you find it useful.

igor General, PHP ,