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; } $toadd = array_reverse($toadd);
/** * Given a collection of clNode objects, use $selector to query a set of nodes * from each, then (optionally) sort those nodes by one or more sorting filters. * Sorting filters should be specified <type>:<selector>, where <type> is one of * str, num, date, bool, or fx and <selector> is a valid node selector expression. * The value at <selector> in each node will be converted to <type>, and the * collection will then be sorted by those converted values. In the special case * of fx, <selector> should instead be a callable function. The function (a custom) * sorting rule, should be implemented as prescribed by the usort documentation, * and should handle node value selection internally. * @param mixed $apis array(clNode), an array of stdClass objects (the return value of clApi::exec), a single clNode instance, or a URL to query * @param string $selector * @param string $sort_by * @return array(clNode) A (sometimes) sorted collection of clNode objects * @see http://www.php.net/manual/en/function.usort.php */ static function &grep($nodes, $selector, $sort_by = null) { $args = func_get_args(); $nodes = @array_shift($args); if (!$nodes) { return false; } else { if (!is_array($nodes)) { if ($nodes instanceof clNode) { $nodes = array($nodes); } else { $api = new clApi((string) $nodes); if ($node = $api->parse()) { clApi::log("The URL [{$nodes}] did not parse, so clApi::grep fails.", E_USER_ERROR); return false; } $nodes = array($node); } } } $selector = @array_shift($args); if (!$selector) { clApi::log('clApi::grep requires $selector argument (arg #2)', E_USER_WARNING); return false; } $sort_by = array(); foreach ($args as $s) { if (preg_match('/(.*?)\\:(.*)/', $s, $matches)) { @(list($type, $order) = preg_split('/,\\s*/', $matches[1])); if (!$order) { $order = 'asc'; } $sort_by[] = (object) array('type' => $type, 'order' => strtolower($order), 'selector' => $matches[2]); } else { clApi::log("clApi::grep {$sort_by} arguments must be formatted <type>:<selector>: [{$s}] is invalid.", E_USER_WARNING); } } // build the node collection $grepd = array(); foreach ($nodes as $node) { // automatically detect clApi::exec results... if ($node instanceof stdClass) { if ($node->parsed) { $grepd = array_merge($grepd, $node->parsed->get($selector)->toArray()); } else { clApi::log(sprintf("clApi::grep can't sort failed parse on [%s]", $node->api->getUrl()), E_USER_WARNING); } } else { $grepd = array_merge($grepd, $node->get($selector)->toArray()); } } // sort the collection foreach ($sort_by as $s) { self::$sort_by = $s; usort($grepd, array('clApi', 'grep_sort')); if ($order == 'desc') { $grepd = array_reverse($grepd); } } return $grepd; }
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)); } } //print(($sl->get('Metros xmlns="http://sl.se/Departures.xsd"'));