if (count($td) < 2) { continue; } $artist = $td[0]->innertext; $title = $td[1]->innertext; if ($artist == '' || $title == '') { continue; } $toadd[] = array('title' => $title, 'artist' => $artist); } $html->clear(); unset($html); break; case 'rss': require_once INCLUDES_DIR . 'coreylib.inc.php'; $api = new clApi($url); $feed = $api->parse(); $counter = 0; foreach ($feed->get('item') as $entry) { if ($counter > INSERT_LIMIT) { break; } $feedt = $entry->get('title'); $bypos = strpos($feedt, ' by '); $title = substr($feedt, 0, $bypos); $artist = substr($feedt, $bypos + 4, strpos($feedt, ' from ') - ($bypos + 4)); $counter++; $toadd[] = array('title' => $title, 'artist' => $artist); } break; }
function set($cache_key, $value, $timeout = 0) { if (!$this->wpdb) { return false; } // make sure $timeout is valid if (($expires = self::time($timeout)) === false) { return false; } // if the value can be serialized if ($serialized = maybe_serialize($value)) { // prepare the SQL $sql = $this->wpdb->prepare("\n REPLACE INTO {$this->wpdb->coreylib} \n (`cache_key`, `created`, `expires`, `value`) \n VALUES \n (%s, %s, %s, %s)\n ", $cache_key, $created = date('Y/m/d H:i:s', self::time()), $expires = date('Y/m/d H:i:s', $expires), $serialized); // insert it! $this->wpdb->query($sql); if ($this->wpdb->query($sql)) { clApi::log("Stored content in {$this->wpdb->coreylib}[{$cache_key}]"); } else { clApi::log("Failed to store content in {$this->wpdb->coreylib}[{$cache_key}]", E_USER_WARNING); } return (object) array('expires' => $expires, 'created' => $created, 'value' => value); } else { clApi::log("Failed to serialize cache data [{$cache_key}]", E_USER_WARNING); return false; } }
require 'coreylib.php'; if ($distance >= 30) { $api = new clApi('https://api.sl.se/api2/realtimedepartures.xml?key=' . $api_key . '&siteid=' . $station . '&timewindow=60', false); //$api_buses = new clApi('https://api.trafiklab.se/sl/realtid/GetDpsDepartures.xml?&siteId='.station.'&key='.$api_key.'&timeWindow=60', false); } else { $api = new clApi('https://api.sl.se/api2/realtimedepartures.xml?key=' . $api_key . '&siteid=' . $station, false); //$api_buses = new clApi('https://api.trafiklab.se/sl/realtid/GetDpsDepartures.xml?&siteId='.station.'&key='.$api_key, false); } //$slbuses = $api_buses->parse(); //$api_metros = new clApi('https://api.trafiklab.se/sl/realtid/GetDepartures.xml?siteId='.station.'&key='.$api_key, false); //$slmetros = $api_metros->parse(); $sl1 = $api->parse(); $sl = $sl1->get('ResponseData'); if ($sl) { //$api_station = new clApi('https://api.trafiklab.se/sl/realtid/GetSite.xml?stationSearch='.station.'&key='.$api_key); $api_station = new clApi('https://api.sl.se/api2/typeahead.xml?searchstring=' . $station . '&maxresults=1&key=' . $site_key); $slstation1 = $api_station->parse(); $slstation = $slstation1->get('ResponseData'); $slbusesmetros = array(); foreach ($sl->get('Bus') as $bus) { $diff = strtotime($bus->get('ExpectedDateTime')) - mktime(date("s"), date("i"), date("h"), date("m"), date("d"), date("Y")); $years = floor($diff / (365 * 60 * 60 * 24)); $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24)); $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24)); $hours = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24) / (60 * 60)); $minutes = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60) / 60); $seconds = floor($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60 - $minutes * 60); if (intval($minutes) < 15 && !(strpos($not, "bus") !== false)) { array_push($slbusesmetros, array("transport" => $bus->get('TransportMode'), "name" => $bus->get('Destination'), "line" => $bus->get('LineNumber'), "departure" => $minutes)); } }