public function testBadParseLongRange() { $_ENV['office_lat'] = 53.3381985; $_ENV['office_lng'] = -6.2592576; $resource = fopen('test_assets/bad_customers.json', 'r'); $this->assertEquals(14, count(process_data($resource))); }
function mail_bodies($post_data, $orderid, $footer_email) { global $language; # convert the post-data to mail data $mail_data = process_data($post_data, $orderid); # get the telephone number $postal_code = \customer_registration\extract_postal_code($post_data); $footer_telephone = \telephone\product_dependent(@$post_data['productchoice_mazout'], @$post_data['productchoice_gas'], @$post_data['productchoice_elek'], $postal_code); # body comfort energy $comfort_energy = true; ob_start(); include dirname(__FILE__) . '/mail-template.php'; $body_comfort_energy = ob_get_contents(); ob_end_clean(); # body customer $comfort_energy = false; ob_start(); include dirname(__FILE__) . '/mail-template.php'; $body_customer = ob_get_contents(); ob_end_clean(); return array($body_comfort_energy, $body_customer); }
header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("invalid {$requestType}"); } } /***** Get user's input *****/ $user = sanitize_input($_GET['user']); // expects something like "instagram" (username) $media = sanitize_input($_GET['media']); // expects something like "mOFsFhAp4f" (shortcode) /***** set context *****/ $context = stream_context_create(array('http' => array('timeout' => 10))); /***** validate request type and return response *****/ // user, including last 20 media posts if (!empty($user) && empty($media)) { $requestType = "user"; $dataFile = @file_get_contents("http://instagram.com/" . $user, NULL, $context); echo process_data($dataFile, $requestType); } elseif (empty($user) && !empty($media)) { $requestType = "media"; $dataFile = @file_get_contents("http://instagram.com/p/" . $media, NULL, $context); echo process_data($dataFile, $requestType); } elseif (!empty($user) && !empty($media)) { header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("only one parameter allowed"); } elseif (empty($user) && empty($media)) { header("HTTP/1.0 400 BAD REQUEST"); header('Content-Type: text/html; charset=utf-8'); die("invalid parameters"); }
} } catch (customException $e) { echo $e->errorMessage(); } $url = 'http://www.motortrend.com/gas_prices/34/' . $zip; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); $result = curl_exec($curl); $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($httpCode == 404) { echo "404"; } else { $html = file_get_html($url); process_data($html); } class Station { public function setBrand($newBrand) { $this->brand = $newBrand; } public function setAddress($newAddress) { $this->address = $newAddress; } public function setPrice($newPrice) { $this->price = $newPrice; }
<?php if ($inc == 4138000013801) { $err_count = 0; $successMSG = 0; $msg; if (isset($_REQUEST['submitted'])) { validate_data(); if ($err_count != 0) { display_errors(); display_form(); } else { process_data(); display_form(); } } else { display_form(); } } else { header("location:../index.php"); } ?> <?php function display_form() { global $errors; global $err_count; global $successMSG; global $msg; $secKEY = random_string_generator(10);
$arg1 = $argv[1]; switch ($arg1) { case 'backup': process_data($cluster_id, "backups/all", "cmonapi"); break; case 'cluster': process_data($cluster_id, "clusters/info", "cmonapi"); break; case 'alarms-warning': process_data($cluster_id, "alarms/all", "cmonapi"); break; case 'alarms-critical': process_data($cluster_id, "alarms/all", "cmonapi", "critical"); break; case 'test': process_data($cluster_id, "clusters/all", "cmonapi"); break; default: echo 'Error: Unknown option. Supported option: test|backups|cluster|alarms-critical|alarms-warning'; break; } function process_data($cid, $arg, $method, $extra = 'warning') { if ($method == "cmonapi") { echo process_cmonapi($cid, $arg, $extra); } else { echo "Unknown calling method. Please either specify cmonapi or cmonrpc."; exit(1); } } function call_cmonapi($cid, $arg)
<?php require 'functions.php'; $_ENV['office_lat'] = 53.3381985; $_ENV['office_lng'] = -6.2592576; $line = 0; $customers_in_range = []; //read file $stdin = fopen('php://stdin', 'r'); $customers_in_range = process_data($stdin); //sort list ksort($customers_in_range); foreach ($customers_in_range as $customer) { echo $customer->user_id . ": {$customer->name} is {$customer->distance}km away \n"; }
function process_data($_POST, $err = "") { extract($_POST); if (isset($add) and strlen($add) > 0) { $list = "old"; } if (!isset($list) or strlen($list) < 1) { return "Invalid Use Of Module."; } db_connect(); if ($list == "new") { #remove any old list and generate new list $remove_old = "DELETE FROM email_groups WHERE email_group = '{$group}'"; $run_remove = db_exec($remove_old) or errDie("Unable to remove old email list."); switch ($group) { case "customers": #get all customer email addresses $get_custs = "SELECT * FROM customers WHERE length(email) > 0 AND div ='" . USER_DIV . "' ORDER BY surname"; $run_custs = db_exec($get_custs) or errDie("Unable to get customer group information."); if (pg_numrows($run_custs) > 0) { while ($carr = pg_fetch_array($run_custs)) { #add this cusomer to the database $insert_sql = "\n\t\t\t\t\t\t\tINSERT INTO email_groups (\n\t\t\t\t\t\t\t\temail_group, emailaddress, date_added\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'customers', '{$carr['email']}', 'now'\n\t\t\t\t\t\t\t)"; $run_insert = db_exec($insert_sql) or errDie("Unable to add customer to email list."); } } break; case "leads": db_conn("crm"); $get_cons = "SELECT * FROM leads WHERE length(email) > 0"; $run_cons = db_exec($get_cons) or errDie("Unable to get contact email addresses."); if (pg_numrows($run_cons) > 0) { while ($carr = pg_fetch_array($run_cons)) { $insert_sql = "\n\t\t\t\t\t\t\tINSERT INTO email_groups (\n\t\t\t\t\t\t\t\temail_group, emailaddress, date_added\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'leads', '{$carr['email']}', 'now'\n\t\t\t\t\t\t\t)"; $run_insert = db_exec($insert_sql) or errDie("Unable to add customer to email list."); } } break; case "contacts": $get_cons = "SELECT * FROM cons WHERE length(email) > 0"; $run_cons = db_exec($get_cons) or errDie("Unable to get contact email addresses."); if (pg_numrows($run_cons) > 0) { while ($carr = pg_fetch_array($run_cons)) { $insert_sql = "\n\t\t\t\t\t\t\tINSERT INTO email_groups (\n\t\t\t\t\t\t\t\temail_group, emailaddress, date_added\n\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t'contacts', '{$carr['email']}', 'now'\n\t\t\t\t\t\t\t)"; $run_insert = db_exec($insert_sql) or errDie("Unable to add customer to email list."); } } break; default: // return select_group (); } } else { #do nothing ... just use old list ... } db_connect(); #remove any entry if its been set if (isset($remove) and is_array($remove)) { foreach ($remove as $each) { $remove_sql = "DELETE FROM email_groups WHERE id = '{$each}'"; $run_remove = db_exec($remove_sql) or errDie("Unable to get remove selected email address."); } } if (isset($add) and strlen($add) > 0) { # validate input require_lib("validate"); $v = new validate(); $v->isOk($add, "email", 0, 50, "Invalid Email Address."); # Display errors, if any if ($v->isError()) { $confirm = ""; $errors = $v->getErrors(); foreach ($errors as $e) { $confirm .= "<li class='err'>{$e['msg']}</li>"; } #remove nasty entry and send error unset($_POST["add"]); return process_data($_POST, $confirm); } $add_sql = "\n\t\t\tINSERT INTO email_groups (\n\t\t\t\temail_group, emailaddress, date_added\n\t\t\t) VALUES (\n\t\t\t\t'{$group}', '{$add}', 'now'\n\t\t\t)"; $run_add = db_exec($add_sql) or errDie("Unable to add new email address."); } if (isset($search)) { $searchsql = "AND lower(emailaddress) LIKE lower('%{$search}%')"; } else { $searchsql = ""; } if (!isset($offset)) { $offset = 0; } if (isset($gonext) and strlen($gonext) > 0) { $offset = $offset + 15; } if (isset($goprev) and strlen($goprev) > 0) { $offset = $offset - 15; } if ($offset < 0) { $offset = 0; } #get a total $get_tot = "SELECT count(id) FROM email_groups WHERE email_group = '{$group}' {$searchsql}"; $run_tot = db_exec($get_tot) or errDie("Unable to get total email information."); if (pg_numrows($run_tot) < 1) { $tot = 0; } else { $tot = pg_fetch_result($run_tot, 0, 0); } #get list to use from the database ... $get_list = "SELECT * FROM email_groups WHERE email_group = '{$group}' {$searchsql} ORDER BY emailaddress OFFSET {$offset} LIMIT 25"; $run_list = db_exec($get_list) or errDie("Unable to get customer email list."); if (pg_numrows($run_list) < 1) { $listing = ""; $count = 0; } else { $listing = ""; $count = 0; while ($larr = pg_fetch_array($run_list)) { $listing .= "\n\t\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t\t<td>{$larr['emailaddress']}</td>\n\t\t\t\t\t<td><input id='{$larr['id']}' type='checkbox' name='remove[]' value='{$larr['id']}'></td>\n\t\t\t\t</tr>"; $count++; } } #handle previous ... if ($offset != 0) { $prev = TRUE; } else { $prev = FALSE; } if ($count == 15) { $next = TRUE; } else { $next = FALSE; } $buttons = ""; if ($prev or $next) { $show_prev = ""; $show_next = ""; if ($prev) { $show_prev = "<input type='submit' name='goprev' value='Previous'>"; } if ($next) { $show_next = "<input type='submit' name='gonext' value='Next'>"; } $buttons .= "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'>{$show_prev} {$show_next}</td>\n\t\t\t</tr>"; } $display = "\n\t\t<script>\n\t\t\tfunction checkAll(field) {\n\t\t\t\tvar_list = document.form1.getElementsByName ('remove[]');\n\t\t\t\tfor (var a = 0; a<var_list.length;a++){\n\t\t\t\t\talert (var_list[a]);\n\t\t\t\t}\n\t\t\t\tfor (i = 0; i < field.length; i++){\n\t\t\t\t\talert(field.length);\n\t\t\t\t\tfield[i].checked = true ;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction uncheckAll(field) {\n\t\t\t\tfor (i = 0; i < field.length; i++)\n\t\t\t\t\tfield[i].checked = false ;\n\t\t\t}\n\t\t</script>\n\t\t<h2>Email Listing</h2>\n\t\t{$err}\n\t\t<form action='" . SELF . "' method='POST' name='form1'>\n\t\t\t<input type='hidden' name='key' value='modify'>\n\t\t\t<input type='hidden' name='group' value='{$group}'>\n\t\t\t<input type='hidden' name='offset' value='{$offset}'>\n\t\t\t<input type='hidden' name='list' value='old'>\n\t\t\t<input type='hidden' name='' value=''>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<th>Search For Email Address</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><input type='text' size='35' name='search'> <input type='submit' value='Search'></td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<th>Add Email Address To List</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td><input type='text' size='35' name='add'> <input type='submit' value='Add'></td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<th>Sending Format</th>\n\t\t\t</tr>\n\t\t\t<tr class='" . bg_class() . "'>\n\t\t\t\t<td>\n\t\t\t\t\t<input type='radio' name='send_format' value='html' checked='yes'>HTML\n\t\t\t\t\t<input type='radio' name='send_format' value='plain'>Plain Text\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t" . TBL_BR . "\n\t\t</table>\n\t\t<table " . TMPL_tblDflts . ">\n\t\t\t<tr>\n\t\t\t\t<td colspan='2'><h3>Send Email To These {$tot} Email Addresses</h3></td>\n\t\t\t</tr>\n\t\t\t{$buttons}\n\t\t\t<tr>\n\t\t\t\t<th>Email Address</th>\n\t\t\t\t<th>Remove</th>\n\t\t\t</tr>\n\t\t\t{$listing}\n\t\t\t<tr>\n\t\t\t\t<td><input type='button' onClick='javascript:checkAll(document.form1.remove);' value='Check All'></td>\n\t\t\t</tr>\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right'><input type='submit' value='Remove Selected'></td>\n\t\t\t</tr>\n\t\t\t" . TBL_BR . "\n\t\t\t<tr>\n\t\t\t\t<td colspan='2' align='right'><input type='submit' name='done' value='Send Email'></td>\n\t\t\t</tr>\n\t\t</form>\n\t\t</table>"; return $display; }
// open saved file if (($handle = fopen($saved_file, "r")) !== FALSE) { // get the headers $cols = 0; // process each row while (($data = fgetcsv($handle)) !== FALSE) { $cols = count($data); for ($c = 0; $c < $cols; $c++) { $result .= $data[$c] . "<br />\n"; } if (preg_match('/^\\#/', $data[0])) { $comments++; continue; } $total_rows++; $rt = process_data($type, $references, $indicators, $validate_only, $data, $logfh); if (empty($rt['error'])) { $saved++; } else { $exceptions++; fwrite($logfh, "INDICATOR NAME: " . $data[0] . " :: " . $rt['error'] . "\n"); } } $result = "File " . $file_name . " saved as " . $saved_file . ".\n" . " Total " . $total_rows . " records in the file. Total " . $comments . " rows of comments.\n" . " Total " . $saved . " records been saved to the database or validated.\n" . " Total " . $exceptions . " rows errored with exceptions. Check " . $log_file . " for details.\n"; fwrite($logfh, $result); if ($total_rows == 0) { $error = "Only headers found in the file, please make sure the CSV file is saved in Windows format."; } fclose($handle); } else { echo json_encode(array('error' => "Cannot open file " . $saved_file . " for read.", 'msg' => $saved_file));
$skus[] = $matches[0]; } } } } return $skus; } // Include the library. require 'scraperwiki/simple_html_dom.php'; // The base URL. $base_url = "http://techmanual.yakima.com/"; $allowed_tags = "<br>,<strong>,<b>"; $active_skus = get_products("active"); $discontinued_skus = get_products("discontinued"); process_data($active_skus, 1); process_data($discontinued_skus, 0); // To process the data. function process_data($skus, $avail = 1) { global $allowed_tags; if (!empty($skus) && is_array($skus)) { foreach ($skus as $sku) { // Get the description. $description = strip_tags(get_description($sku), $allowed_tags); // Add it to an array. $record = array('sku' => $sku, 'avail' => $avail, 'desc' => $description); // Add it to the table. scraperwiki::save_sqlite(array('sku'), array($record), "techmanual", 2); } } }