DropCash PHP Output

  • warning: Invalid argument supplied for foreach() in /home/locker/www/randomfoo.net/htdocs/code/modules/filter.module on line 592.
  • user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR format = 1' at line 1 query: SELECT * FROM filter_formats WHERE OR format = 1 in /home/locker/www/randomfoo.net/htdocs/code/includes/database.mysql.inc on line 108.
by lhl ( | | | | | )

I started my first Dropcash campaign today. and coded up a large custom "badge" for my campaign with a little bit of PHP glue.

If you're using PHP5 you'll probably want to use SimpleXML, which looks totally rockin', but for us less adventurous shlubs, give PEAR::XML_Serializer an install (you might need to -f for since it's still 'beta') and check this out:

<?php
  // Caching
  $cache = '/tmp/dropcash';
  $agelimit = 5 * 60; // 5 minutes
  $timestamp = @filemtime($cachefile);
  $age = time() - $timestamp;

  if($age > $agelimit || $_SERVER['QUERY_STRING'] == 'update') {
    $f = fopen($cache, 'w');
    fwrite($f, file_get_contents('http://www.dropcash.com/campaign/[user]/[campaign_name]/xml'));
  }

  $xml = file_get_contents($cache);

  require_once 'XML/Unserializer.php';
  $u = &new XML_Unserializer();
  $u->unserialize($xml);
  $dc = $u->getUnserializedData();

  $percent = $dc['percentage'];
  $percentpx = floor($percent * 4); // 400px bar
  $goal =  $dc['goal'];
  $collected = $dc['total_collected'];
?>

This will probably make more sense w/ the rest of the badge code since it's a bit style-based (for the percentpx).

AttachmentSize
dropcash.php.txt3.79 KB