$minDiggs) { echo $info['href']; } else { echo ''; } // This function builds and sends the request to the Digg API server. // $permalink is the link to the actual article that we're checking out function queryDigg($permalink) { ini_set('user_agent', 'WPConditionalDiggBadge/1.0'); $params = array(); $params['appkey'] = 'http://www.earn-web-cash.com'; $params['type'] = 'xml'; $params['count'] = '1'; $params['link'] = $permalink; $params['min_submit_date'] = 0; $params['max_submit_date'] = time(); $query = buildQuery($params); $baseurl = 'http://services.digg.com'; $endpoint = '/stories'; $url = $baseurl . $endpoint; $reqUrl = $url . $query; $file = file_get_contents($reqUrl); $xml = simplexml_load_string($file); $info = array(); // Get Diggs if story has been dugg, otherwise default to 0 if ($xml && (int) $xml['count'] > 0) { $info['href'] = (string) $xml->story['href']; $info['diggs'] = (int) $xml->story['diggs']; } else { $info['href'] = ''; $info['diggs'] = 0; } return $info; } // Takes an array of arguments and returns a query string // Each parameter's name is its key in the array function buildQuery ($args) { $query = '?'; foreach ($args as $key => $val) { if ($query != '?') { $query .= '&'; } $query .= $key . '=' . urlencode($val); } return $query; } ?>