I recently had a problem using PHP’s json_decode() with Twitter’s search API. The Twitpocalypse meant that the tweet status ids were being limited to 2147483647, and in my case, any new tweets weren’t being saved as the app thought they already existed.

To get around the problem of json_decode() limiting ints, I added a regex replace to change large numbers to strings by adding quote marks around them. json_decode() then sees the number as a string and parses it correctly.

An example search function with the fix is shown below:

function TwitterSearch($query) {
  $search_url = 'http://search.twitter.com/search.json?q='.$query;
  $ch = curl_init($search_url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $json = curl_exec($ch);
   
  // -- int-max fix - convert number to string
  $json = ereg_replace('([:])([0-9]{10})([,}])', '\\1"\\2"\\3', $json);
   
  $result = json_decode($json);
  curl_close($ch);
  return $result;
}

The regex here only looks for 10-digit numbers, but this can easily be changed for larger numbers by changing the {10} to say {10,16} to catch 10 to 16 digit numbers.

I recently installed Trac to replace a crawling WebSVN install, and wanted to keep the modified files diff links generated on the CCNet build report.

To enable this I changed the webUrlBuilder Url to…

<project name="MyProject.Trunk.Continuous">
  ...
  <sourcecontrol type="svn">
    ...
    <webUrlBuilder type="websvn">
      <url>http://trac.myserver.com/MyProject/changeset/{1}{0}</url>
    </webUrlBuilder>
  </sourcecontrol>
  ...
</project>

…which now matches the url required to show file differences in Trac.

I’ve just stumbled across a problem with using the AJAX $.post() wrapper in jQuery 1.2.6 and Firefox 3.

If you call…
$.post('/do/something.handler');
…jQuery doesn’t seem to generate a Content-Length header and causes IIS to return a HTTP/1.x 411 Length Required error.

To fix this, I’m adding an empty data array…
$.post('/do/something.handler', {});
…which now generates a Content-Length: 0 header and returns the correct response from IIS.

Not sure if this is fixed in jQuery 1.3+ or occurs in other versions of Firefox, but the above seems to fudge it in this scenario.

websnapr

30 April 2008

Website thumbnailer…

websnapr

Works with flash. Fantastic. I’m thinking of writing a WordPress plugin for this…

I had a big problem getting WordPress’s new-fandangled flash image uploader working on my Mac; the flash uploader button wouldn’t appear and I always saw the standard single image uploader button.

After a bit of research using the Safari Develop menu, I found that using a Windows user agent made it appear, and a Mac user agent would hide it.

After a quick delve into WordPress’s code I found this in /wp-admin/includes/media.php, lines 769-772…
769: // If Mac and mod_security, no Flash.
770: $flash = true;
771: if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), ‘mac’) && apache_mod_loaded(’mod_security’) )
772:     $flash = false;

…which turns off the flash uploader if you’re using a Mac and your website runs Apache and has the mod_security module loaded… mine does!

So, commenting out the bottom two lines…
769: // If Mac and mod_security, no Flash.
770: $flash = true;
771: // if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), ‘mac’) && apache_mod_loaded(’mod_security’) )
772: //     $flash = false;

…now forces WordPress to show the flash uploader regardless.

Hurrah :)