function top($clientID, $limit, $start = false, $end = false) { $batchKeys = array('pages', 'entry_pages', 'exit_pages', 'exit_targets', 'hosts', 'referers', 'operating_systems', 'user_agents'); $batchWhat = array('document', 'entry_document', 'exit_document', 'exit_target', 'host', 'referer', 'operating_system', 'user_agent'); $batchResult = array(); // Loop through $batchKeys / $batchWhat for ($i = 0; $i < sizeof($batchKeys); $i++) { // Query Top <$limit> items of category <$batchWhat[$i]> $result = phpOpenTracker::get(array('client_id' => $clientID, 'api_call' => 'top', 'what' => $batchWhat[$i], 'start' => $start, 'end' => $end, 'limit' => $limit)); for ($j = 0; $j < sizeof($result['top_items']); $j++) { // Get item template $item = new MyTemplate('templates/item.htm'); // Fill in item template variables $item->setVar(array('rank', 'count', 'percent', 'string'), array($j + 1, $result['top_items'][$j]['count'], $result['top_items'][$j]['percent'], $result['top_items'][$j]['string'])); if (!isset($batchResult[$batchKeys[$i]]['top_items'])) { $batchResult[$batchKeys[$i]]['top_items'] = ''; } $batchResult[$batchKeys[$i]]['top_items'] .= $item->parse(); } $batchResult[$batchKeys[$i]]['unique_items'] = $result['unique_items']; } return $batchResult; }