private function get_site_data($site_url, $max_depth = 1, $current_depth = 0) { $current_depth++; $this->load->library('crawler'); $site_data = array(); if ($this->crawler->set_url($site_url) !== false) { $site_data['title'] = $this->crawler->get_title(); $site_data['description'] = $this->crawler->get_description(); $site_data['keywords'] = $this->crawler->get_keywords(); $site_data['text'] = $this->crawler->get_text(); $site_data['links'] = $this->crawler->get_links(); if ($current_depth <= $max_depth) { foreach ($site_data['links'] as $link_key => &$link) { $link['data'] = get_site_data($link, $max_depth, $current_depth); } } return $site_data; } else { return false; } }
header('Content-Type: application/json'); $HTTPS_required = false; $authentication_required = false; $response = null; $api_response_code = array(0 => array('HTTP Response' => 400, 'Message' => 'Unknown Error'), 1 => array('HTTP Response' => 200, 'Message' => 'Success'), 2 => array('HTTP Response' => 403, 'Message' => 'HTTPS Required'), 3 => array('HTTP Response' => 401, 'Message' => 'Authentication Required'), 4 => array('HTTP Response' => 401, 'Message' => 'Authentication Failed'), 5 => array('HTTP Response' => 404, 'Message' => 'Invalid Request'), 6 => array('HTTP Response' => 400, 'Message' => 'Invalid Response Format')); if ($HTTPS_required && $_SERVER['HTTPS'] != 'on') { sendresponse($response, 2, false, $api_response_code); } if ($authentication_required == false) { $method = $_SERVER['REQUEST_METHOD']; switch ($method) { case 'GET': $sql_select = "SELECT * FROM site_content"; //site_content.greeting $site_content = false; $site_content = get_site_data($sql_select); if ($site_content == false) { sendresponse($response, 0, false, $api_response_code); } else { $response['data'] = $site_content; } break; case 'PUT': parse_str(file_get_contents('php://input'), $_PUT); $key = $_PUT['key']; $new_value = $_PUT['new_value']; $new_value = addslashes($new_value); if (empty($key) || empty($new_value)) { sendresponse($response, 6, false, $api_response_code); } $sql_select = "UPDATE site_content SET {$key} = '{$new_value}'";
$feedfile = 'data.json'; // message to display if viewed directly $message = 'This script collects real time weather data from publicly available data feeds. See <a href="kiting.html">this</a> page for further information. If this script is causing problems or for further information please <a href="kiting.html#contact">contact</a> the site administrator.'; // import data sources to use require_once 'data-sources.php'; // get the current data feed to compare with if ($feedstr = file_get_contents($feedfile)) { $feed = json_decode($feedstr, true); } // collect data for each site $latest = array(); foreach ($sites as $site) { $latest[] = get_site_data($site); } // compare latest data to feed and // update feed file if changes required if ($merged = merge_site_data($feed, $latest)) { // sort data array by name key foreach ($merged as $key => $row) { // array_multisort requires array of columns to sort by $name[$key] = $row['name']; } array_multisort($name, SORT_ASC, $merged); file_put_contents($feedfile, json_encode($merged)); if ($debug) { print "<h3>Data Feed Updated:</h3>"; print "<pre>" . print_r($merged, true) . "</pre>"; } else {