1 Running dotMobi WordPress Mobile Pack on PHP 4

Nov 2nd, 2009   10:47 pm

If you, like me, are installing the dotMobi WordPress Mobile Pack on a server with PHP4 installed, and you enable the “Shrink images” feature under “Mobile Theme”, you will likely see just the header of a blog post being out put for mobile devices (and not the full content).

This feature reduces the image size (of any images in your WordPress post/page) to make it more bandwidth and screen friendly for mobile users. The problem is that it uses a PHP5-only call of file_put_contents(..), which fails without error, or logging, on my WordPress install.

To remedy the problem, I substituted the call, in 2 places, with the PHP4 equivalent calls. file_put_contents(..) is a shortcut convenience method which is the same as calling fopen(..), fwrite(..) and fclose(..).

As of version 1.1.3 of the plugin the code is under wp-content/plugins/wordpress-mobile-pack/plugins/wpmp_transcoder/ in your WordPress install directory. The 2 occurrences are in the file wpmp_transcoder.php on lines 431 and 448 respectively.

I changed

@file_put_contents($full_location, $data);

.. to ..

$fhout = @fopen($full_location, "w" );
@fwrite($fhout, $data);
@fclose( $fhout );

.. and ..

@file_put_contents("$full_location.meta", "< ?php $"."width='$width';$"."height='$height';$"."type='$type'; ?>");

.. to ..

$fhmeta = @fopen( "$full_location.meta", "w" );
@fwrite( $fhmeta, "< ?php $"."width='$width';$"."height='$height';$"."type='$type'; ?>");
@fclose( $fhmeta );

.. and all was well again.

You could also just not use the “Shrink images” feature to avoid having to mess with any code!

Comments:

Claudiu
Sep 10th, 2010   12:33 pm

Or, you could just add a snippet of code in the config file: if (!function_exists('file_put_contents')) { function file_put_contents($filename, $data) { $f = @fopen($filename, 'w'); if (!$f) { return false; } else { $bytes = fwrite($f, $data); fclose($f); return $bytes; } } } Just to make sure that you keep compatibility in case you get some updates/add-ons whatever that could insert a file_put_contents somewhere in the code. The same goes for any other PHP5 only function (most can be replicated in PHP4 as well)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

css.php