function ted_controller() { global $mysqli, $redis, $user, $session, $route, $feed_settings; // Start by filtering by request path if ($route->action == 'post' && $route->format == 'text') { // Need to get the POST body $post = file_get_contents("php://input"); // Look for an activation POST if (startsWith($post, '<ted5000Activation>')) { // Get the gateway and unique values $gateway = extract_value($post, '<Gateway>', '</Gateway>'); $unique = extract_value($post, '<Unique>', '</Unique>'); // Make sure this is permitted and that the user set up the device // in emoncms. $session = check_device_key($unique); // Need to get values for the response if (isset($_SERVER['HTTP_X_FORWARDED_SERVER'])) { $server = server('HTTP_X_FORWARDED_SERVER'); } else { $server = server('HTTP_HOST'); } $url = server('SCRIPT_NAME'); $result = '<ted5000ActivationResponse>' . "<PostServer>{$server}</PostServer>" . '<UseSSL>F</UseSSL>' . '<PostPort>80</PostPort>' . '<PostURL>/ted/post.text</PostURL>' . "<AuthToken>{$unique}</AuthToken>" . '<PostRate>2</PostRate>' . '<HighPrec>T</HighPrec>' . '</ted5000ActivationResponse>'; } else { if (startsWith($post, '<ted5000 ')) { // Got data POST $nodeid = extract_value($post, 'GWID="', '"'); $unique = extract_value($post, 'auth="', '"'); $session = check_device_key($unique); $userid = $session['userid']; // Setup variable we need to insert data // Need to get correct files so that we can make inputs require_once "Modules/feed/feed_model.php"; $feed = new Feed($mysqli, $redis, $feed_settings); require_once "Modules/input/input_model.php"; $input = new Input($mysqli, $redis, $feed); require_once "Modules/process/process_model.php"; $process = new Process($mysqli, $input, $feed, $user->get_timezone($userid)); // Fetch the known inputs from the database $dbinputs = $input->get_inputs($userid); // Make sure we can save this data. if ($nodeid != $session['nodeid']) { header($_SERVER["SERVER_PROTOCOL"] . " 401 Unauthorized"); header('WWW-Authenticate: Bearer realm="Device KEY", error="invalid_nodeid", error_description="Invalid node"'); print "Invalid node({$nodeid}) for that device key({$unique})"; exit; } // Get the MTU values from the POST data $values = extract_mtu($post); $time = time(); // Actually insert data $tmp = array(); foreach ($values as $name => $value) { // Check if this is an existing field in this node or not if (!isset($dbinputs[$nodeid][$name])) { // New field. $inputid = $input->create_input($userid, $nodeid, $name); $dbinputs[$nodeid][$name] = true; $dbinputs[$nodeid][$name] = array('id' => $inputid, 'processList' => ''); $input->set_timevalue($dbinputs[$nodeid][$name]['id'], $time, $value); } else { // Existing field, just insert $input->set_timevalue($dbinputs[$nodeid][$name]['id'], $time, $value); // If there are processes listening to this field, we need // to pass the data to those as well if ($dbinputs[$nodeid][$name]['processList']) { $tmp[] = array('value' => $value, 'processList' => $dbinputs[$nodeid][$name]['processList'], 'opt' => array('sourcetype' => "WATTSUP", 'sourceid' => $dbinputs[$nodeid][$name]['id'])); } } } // Actually insert all of the data to the process foreach ($tmp as $i) { $process->input($time, $i['value'], $i['processList'], $i['opt']); } $result = 'ok'; } else { $result = 'Unknown'; } } } return array('content' => $result); }
?> > <td class="tcl" style="width:2%;text-align:right"><?php echo $rank; ?> </td> <td class="tc2"><?php echo '<a href="highscores.php?username='******'&show_group=' . $show_group . '&sort_by=' . $sort_by . '&sort_dir=' . strtoupper($sort_dir) . '&skill=' . $skill . '&country=' . $flag . '"><img src="img/flags/' . $flag . '.gif" alt="' . strtoupper($flag) . '" title=" ' . strtoupper($flag) . ' " /></a> <a href="char.php?user='******'user'] . '">' . pun_htmlspecialchars($char['username']) . '</a>'; ?> </td> <td class="tc3"><?php echo '<a href="profile.php?id=' . $char['owner'] . '">' . pun_htmlspecialchars($char['owner_username']) . '</a>'; ?> </td> <td class="tc3"><?php echo extract_value($char); ?> </td> <td class="tc3"><?php echo number_format($exp); ?> </td> <td class="tc3"><?php echo format_time($char['creation_date'], true); ?> </td> </tr> <?php } } else { echo "\t\t\t" . '<tr>' . "\n\t\t\t\t\t" . '<td class="tcl" colspan="6">Your search returned no hits.</td></tr>' . "\n";
function get_card_price($card_hash, $target_currency = false) { /* Get the market listing. */ $listing_url = 'http://steamcommunity.com/market/listings/753/' . rawurlencode($card_hash); $market_html = access_cached($listing_url, 'market_' . $card_hash . '.html'); /* Assessing the trading value of a card is difficult, we'll just go with the currently cheapest listing on the Community Market (fees excluded). */ /* Find the cheapest available listing and extract the price without fees. */ $delimiter_left = 'market_listing_price_without_fee">'; $delimiter_right = '</span>'; $price_string = extract_value($market_html, $delimiter_left, $delimiter_right); if ($price_string === false) { return false; } else { $price_string = trim($price_string); } /* Here is where we have to parse different currencies. The Market always returns the seller's native currency, so we have to do the conversion, if necessary. */ $currency = '?'; // default if (strpos($price_string, ' USD') !== false) { $currency = 'USD'; $amount = substr($price_string, 5, strpos($price_string, ' ') - 5); } if (strpos($price_string, '€') !== false) { $currency = 'EUR'; $amount = substr($price_string, 0, strpos($price_string, '€')); } if (strpos($price_string, '£') !== false) { $currency = 'GBP'; $amount = substr($price_string, strpos($price_string, '£') + 6); } if (strpos($price_string, 'pуб.') !== false) { $currency = 'RUB'; $amount = substr($price_string, 0, strpos($price_string, 'pуб.') - 1); } if (strpos($price_string, 'R$') !== false) { $currency = 'BRL'; $amount = substr($price_string, strpos($price_string, 'R$') + 10); } /* This is where the conversion happens. */ if ($target_currency) { /* Unify the decimal point. This is probably not a clean solution, but works for my test cases. */ $amount = str_replace(',', '.', $amount); $amount = floatval($amount); /* Get the exchange rates. */ $factorUSDto = array(); $factorUSDto['USD'] = 1.0; foreach (array('EUR', 'GBP', 'AUD', 'RUB', 'BRL') as $exchange_currency) { $exchange_rate_html = access_cached('http://www.bloomberg.com/quote/USD' . $exchange_currency . ':CUR', 'exchange_rate_' . $exchange_currency . '.html'); $delimiter_left = '<span class=" price">'; $delimiter_right = '<span class="currency_factor_description">'; $exchange_rate = extract_value($exchange_rate_html, $delimiter_left, $delimiter_right); if ($exchange_rate === false) { return false; } else { $exchange_rate = trim($exchange_rate); } $factorUSDto[$exchange_currency] = floatval($exchange_rate); } /* Convert to target currency and round to 2 digits after the seperator. */ $amount = $amount * $factorUSDto[$target_currency] / $factorUSDto[$currency]; $currency = $target_currency; $formatted_amount = number_format($amount, 2, '.', ''); // PHP can do fancy money formatting. TODO maybe do that here? } return array('amount' => $amount, 'formatted_amount' => $formatted_amount, 'currency' => $currency); }